Logo Search packages:      
Sourcecode: inkscape version File versions

void Inkscape::UI::ClipboardManagerImpl::_pasteDocument ( SPDocument clipdoc,
bool  in_place 
) [private]

Paste the contents of a document into the active desktop.

clipdoc The document to paste
in_place Whether to paste the selection where it was when copied
clipdoc is not empty and items can be added to the current layer

Definition at line 772 of file clipboard.cpp.

References _copyNode(), _pasteDefs(), Inkscape::Selection::bounds(), SPDesktop::currentLayer(), SPDesktop::doc2dt(), SPDesktop::dt2doc(), Inkscape::XML::Node::firstChild(), Geom::Matrix::inverse(), SnapManager::multipleOfGridPitch(), SPDesktop::namedview, Inkscape::XML::Node::next(), SPDesktop::point(), Inkscape::Selection::setReprList(), SnapManager::setup(), sp_document_ensure_up_to_date(), sp_item_i2doc_affine(), sp_repr_lookup_name(), and sp_selection_apply_affine().

Referenced by paste().

    SPDesktop *desktop = SP_ACTIVE_DESKTOP;
    SPDocument *target_document = sp_desktop_document(desktop);
        *root = sp_document_repr_root(clipdoc),
        *target_parent = SP_OBJECT_REPR(desktop->currentLayer());
    Inkscape::XML::Document *target_xmldoc = sp_document_repr_doc(target_document);

    // copy definitions

    // copy objects
    GSList *pasted_objects = NULL;
    for (Inkscape::XML::Node *obj = root->firstChild() ; obj ; obj = obj->next()) {
        // Don't copy metadata, defs, named views and internal clipboard contents to the document
        if (!strcmp(obj->name(), "svg:defs")) continue;
        if (!strcmp(obj->name(), "svg:metadata")) continue;
        if (!strcmp(obj->name(), "sodipodi:namedview")) continue;
        if (!strcmp(obj->name(), "inkscape:clipboard")) continue;
        Inkscape::XML::Node *obj_copy = _copyNode(obj, target_xmldoc, target_parent);
        pasted_objects = g_slist_prepend(pasted_objects, (gpointer) obj_copy);

    // Change the selection to the freshly pasted objects
    Inkscape::Selection *selection = sp_desktop_selection(desktop);

    // invers apply parent transform
    Geom::Matrix doc2parent = sp_item_i2doc_affine(SP_ITEM(desktop->currentLayer())).inverse();
    sp_selection_apply_affine(selection, desktop->dt2doc() * doc2parent * desktop->doc2dt(), true, false);

    // Update (among other things) all curves in paths, for bounds() to work

    // move selection either to original position (in_place) or to mouse pointer
    Geom::OptRect sel_bbox = selection->bounds();
    if (sel_bbox) {
        // get offset of selection to original position of copied elements
        Geom::Point pos_original;
        Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1);
        if (clipnode) {
            Geom::Point min, max;
            sp_repr_get_point(clipnode, "min", &min);
            sp_repr_get_point(clipnode, "max", &max);
            pos_original = Geom::Point(min[Geom::X], max[Geom::Y]);
        Geom::Point offset = pos_original - sel_bbox->corner(3);

        if (!in_place) {
            SnapManager &m = desktop->namedview->snap_manager;
            m.setup(desktop, false); // Don't display the snapindicator

            // get offset from mouse pointer to bbox center, snap to grid if enabled
            Geom::Point mouse_offset = desktop->point() - sel_bbox->midpoint();
            offset = m.multipleOfGridPitch(mouse_offset - offset) + offset;

        sp_selection_move_relative(selection, offset);


Generated by  Doxygen 1.6.0   Back to index