Code

Merge and cleanup of GSoC C++-ification project.
[inkscape.git] / src / ui / clipboard.cpp
index e050d69b4b81bc311080c46dfca05d70899aab8a..d405afb8f6ec9b33ce237247f37e1c82e9fa7924 100644 (file)
@@ -5,6 +5,7 @@
  *   Krzysztof KosiƄski <tweenk@o2.pl>
  *   Jon A. Cruz <jon@joncruz.org>
  *   Incorporates some code from selection-chemistry.cpp, see that file for more credits.
+ *   Abhishek Sharma
  *
  * Copyright (C) 2008 authors
  * Copyright (C) 2010 Jon A. Cruz
@@ -350,8 +351,7 @@ const gchar *ClipboardManagerImpl::getFirstObjectID()
         return NULL;
     }
 
-    Inkscape::XML::Node
-        *root = sp_document_repr_root(tempdoc);
+    Inkscape::XML::Node *root = tempdoc->getReprRoot();
 
     if (!root) {
         return NULL;
@@ -405,9 +405,8 @@ bool ClipboardManagerImpl::pasteStyle(SPDesktop *desktop)
         }
     }
 
-    Inkscape::XML::Node
-        *root = sp_document_repr_root(tempdoc),
-        *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1);
+    Inkscape::XML::Node *root = tempdoc->getReprRoot();
+    Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1);
 
     bool pasted = false;
 
@@ -455,7 +454,7 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a
     }
 
     // retrieve size ifomration from the clipboard
-    Inkscape::XML::Node *root = sp_document_repr_root(tempdoc);
+    Inkscape::XML::Node *root = tempdoc->getReprRoot();
     Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1);
     bool pasted = false;
     if (clipnode) {
@@ -509,7 +508,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop)
 
     SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg");
     if ( tempdoc ) {
-        Inkscape::XML::Node *root = sp_document_repr_root(tempdoc);
+        Inkscape::XML::Node *root = tempdoc->getReprRoot();
         Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1);
         if ( clipnode ) {
             gchar const *effectstack = clipnode->attribute("inkscape:path-effect");
@@ -544,9 +543,8 @@ Glib::ustring ClipboardManagerImpl::getPathParameter(SPDesktop* desktop)
         _userWarn(desktop, _("Nothing on the clipboard."));
         return "";
     }
-    Inkscape::XML::Node
-        *root = sp_document_repr_root(tempdoc),
-        *path = sp_repr_lookup_name(root, "svg:path", -1); // unlimited search depth
+    Inkscape::XML::Node *root = tempdoc->getReprRoot();
+    Inkscape::XML::Node *path = sp_repr_lookup_name(root, "svg:path", -1); // unlimited search depth
     if ( path == NULL ) {
         _userWarn(desktop, _("Clipboard does not contain a path."));
         tempdoc->doUnref();
@@ -568,7 +566,7 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop)
         _userWarn(desktop, _("Nothing on the clipboard."));
         return "";
     }
-    Inkscape::XML::Node *root = sp_document_repr_root(tempdoc);
+    Inkscape::XML::Node *root = tempdoc->getReprRoot();
 
     Inkscape::XML::Node *repr = sp_repr_lookup_name(root, "svg:path", -1); // unlimited search depth
     if ( repr == NULL ) {
@@ -653,23 +651,23 @@ void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection)
 void ClipboardManagerImpl::_copyUsedDefs(SPItem *item)
 {
     // copy fill and stroke styles (patterns and gradients)
-    SPStyle *style = SP_OBJECT_STYLE(item);
+    SPStyle *style = item->style;
 
     if (style && (style->fill.isPaintserver())) {
-        SPObject *server = SP_OBJECT_STYLE_FILL_SERVER(item);
-        if (SP_IS_LINEARGRADIENT(server) || SP_IS_RADIALGRADIENT(server)) {
+        SPPaintServer *server = item->style->getFillPaintServer();
+        if ( SP_IS_LINEARGRADIENT(server) || SP_IS_RADIALGRADIENT(server) ) {
             _copyGradient(SP_GRADIENT(server));
         }
-        if (SP_IS_PATTERN(server)) {
+        if ( SP_IS_PATTERN(server) ) {
             _copyPattern(SP_PATTERN(server));
         }
     }
     if (style && (style->stroke.isPaintserver())) {
-        SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER(item);
-        if (SP_IS_LINEARGRADIENT(server) || SP_IS_RADIALGRADIENT(server)) {
+        SPPaintServer *server = item->style->getStrokePaintServer();
+        if ( SP_IS_LINEARGRADIENT(server) || SP_IS_RADIALGRADIENT(server) ) {
             _copyGradient(SP_GRADIENT(server));
         }
-        if (SP_IS_PATTERN(server)) {
+        if ( SP_IS_PATTERN(server) ) {
             _copyPattern(SP_PATTERN(server));
         }
     }
@@ -702,7 +700,7 @@ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item)
     }
     // Copy text paths
     if (SP_IS_TEXT_TEXTPATH(item)) {
-        _copyTextPath(SP_TEXTPATH(SP_OBJECT(item)->first_child()));
+        _copyTextPath(SP_TEXTPATH(item->firstChild()));
     }
     // Copy clipping objects
     if (item->clip_ref->getObject()) {
@@ -759,7 +757,7 @@ void ClipboardManagerImpl::_copyPattern(SPPattern *pattern)
         _copyNode(SP_OBJECT_REPR(pattern), _doc, _defs);
 
         // items in the pattern may also use gradients and other patterns, so recurse
-        for (SPObject *child = SP_OBJECT(pattern)->first_child() ; child != NULL ; child = SP_OBJECT_NEXT(child) ) {
+        for ( SPObject *child = pattern->firstChild() ; child ; child = child->getNext() ) {
             if (!SP_IS_ITEM (child)) {
                 continue;
             }
@@ -814,10 +812,9 @@ Inkscape::XML::Node *ClipboardManagerImpl::_copyNode(Inkscape::XML::Node *node,
 void ClipboardManagerImpl::_pasteDocument(SPDesktop *desktop, SPDocument *clipdoc, bool in_place)
 {
     SPDocument *target_document = sp_desktop_document(desktop);
-    Inkscape::XML::Node
-        *root = sp_document_repr_root(clipdoc),
-        *target_parent = SP_OBJECT_REPR(desktop->currentLayer());
-    Inkscape::XML::Document *target_xmldoc = sp_document_repr_doc(target_document);
+    Inkscape::XML::Node *root = clipdoc->getReprRoot();
+    Inkscape::XML::Node *target_parent = SP_OBJECT_REPR(desktop->currentLayer());
+    Inkscape::XML::Document *target_xmldoc = target_document->getReprDoc();
 
     // copy definitions
     _pasteDefs(desktop, clipdoc);
@@ -851,7 +848,7 @@ void ClipboardManagerImpl::_pasteDocument(SPDesktop *desktop, SPDocument *clipdo
     sp_selection_apply_affine(selection, desktop->dt2doc() * doc2parent * desktop->doc2dt(), true, false);
 
     // Update (among other things) all curves in paths, for bounds() to work
-    target_document->ensure_up_to_date();
+    target_document->ensureUpToDate();
 
     // move selection either to original position (in_place) or to mouse pointer
     Geom::OptRect sel_bbox = selection->bounds();
@@ -875,6 +872,7 @@ void ClipboardManagerImpl::_pasteDocument(SPDesktop *desktop, SPDocument *clipdo
             // 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, sel_bbox->midpoint() + offset) + offset;
+            m.unSetup();
         }
 
         sp_selection_move_relative(selection, offset);
@@ -893,11 +891,10 @@ void ClipboardManagerImpl::_pasteDefs(SPDesktop *desktop, SPDocument *clipdoc)
 {
     // boilerplate vars copied from _pasteDocument
     SPDocument *target_document = sp_desktop_document(desktop);
-    Inkscape::XML::Node
-        *root = sp_document_repr_root(clipdoc),
-        *defs = sp_repr_lookup_name(root, "svg:defs", 1),
-        *target_defs = SP_OBJECT_REPR(SP_DOCUMENT_DEFS(target_document));
-    Inkscape::XML::Document *target_xmldoc = sp_document_repr_doc(target_document);
+    Inkscape::XML::Node *root = clipdoc->getReprRoot();
+    Inkscape::XML::Node *defs = sp_repr_lookup_name(root, "svg:defs", 1);
+    Inkscape::XML::Node *target_defs = SP_OBJECT_REPR(SP_DOCUMENT_DEFS(target_document));
+    Inkscape::XML::Document *target_xmldoc = target_document->getReprDoc();
 
     prevent_id_clashes(clipdoc, target_document);
 
@@ -1257,8 +1254,8 @@ void ClipboardManagerImpl::_createInternalClipboard()
         _clipboardSPDoc = SPDocument::createNewDoc(NULL, false, true);
         //g_assert( _clipboardSPDoc != NULL );
         _defs = SP_OBJECT_REPR(SP_DOCUMENT_DEFS(_clipboardSPDoc));
-        _doc = sp_document_repr_doc(_clipboardSPDoc);
-        _root = sp_document_repr_root(_clipboardSPDoc);
+        _doc = _clipboardSPDoc->getReprDoc();
+        _root = _clipboardSPDoc->getReprRoot();
 
         _clipnode = _doc->createElement("inkscape:clipboard");
         _root->appendChild(_clipnode);
@@ -1533,4 +1530,4 @@ ClipboardManager *ClipboardManager::get()
   fill-column:99
   End:
 */
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :