Code

Filter effects dialog:
[inkscape.git] / src / selection-chemistry.cpp
index f8548cdc4eda0fb199276a687c923b59de6597b8..dd6ab6eb80a689d40350e9de84490c09a7ae51e6 100644 (file)
@@ -35,6 +35,7 @@
 #include "sp-use.h"
 #include "sp-textpath.h"
 #include "sp-tspan.h"
+#include "sp-tref.h"
 #include "sp-flowtext.h"
 #include "sp-flowregion.h"
 #include "text-editing.h"
@@ -73,6 +74,7 @@
 #include "sp-item.h"
 #include "unit-constants.h"
 #include "xml/simple-document.h"
+#include "sp-filter-reference.h"
 
 using NR::X;
 using NR::Y;
@@ -952,8 +954,8 @@ void sp_copy_stuff_used_by_item (GSList **defs_clip, SPItem *item, const GSList
         }
     }
 
-    if (style->filter.filter) {
-        SPObject *filter = style->filter.filter;
+    if (style->getFilter()) {
+        SPObject *filter = style->getFilter();
         if (SP_IS_FILTER(filter)) {
             sp_copy_single (defs_clip, filter, xml_doc);
         }
@@ -992,7 +994,7 @@ take_style_from_item (SPItem *item)
             }
         }
     }
-    if (!(SP_IS_TEXT (item) || SP_IS_TSPAN (item) || SP_IS_STRING (item))) {
+    if (!(SP_IS_TEXT (item) || SP_IS_TSPAN (item) || SP_IS_TREF(item) || SP_IS_STRING (item))) {
         // do not copy text properties from non-text objects, it's confusing
         css = sp_css_attr_unset_text (css);
     }
@@ -1082,7 +1084,7 @@ void sp_selection_copy()
     sp_selection_copy_impl (items, &clipboard, &defs_clipboard, &style_clipboard, clipboard_document);
 
     if (tools_isactive (desktop, TOOLS_TEXT)) { // take style from cursor/text selection, overwriting the style just set by copy_impl
-        SPStyle *const query = sp_style_new();
+        SPStyle *const query = sp_style_new(SP_ACTIVE_DOCUMENT);
         if (sp_desktop_query_style_all (desktop, query)) {
             SPCSSAttr *css = sp_css_attr_from_style (query, SP_STYLE_FLAG_ALWAYS);
             if (css != NULL) {
@@ -1095,7 +1097,7 @@ void sp_selection_copy()
                 style_clipboard = css;
             }
         }
-        g_free (query);
+        sp_style_unref(query);
     }
 
     size_clipboard = selection->bounds();
@@ -1145,12 +1147,9 @@ void sp_selection_paste(bool in_place)
         }
 
         /* Snap the offset of the new item(s) to the grid */
-        /* FIXME: this gridsnap fiddling is a hack. */
-        Inkscape::GridSnapper &s = desktop->namedview->snap_manager.grid;
-        gdouble const curr_gridsnap = s.getDistance();
-        s.setDistance(NR_HUGE);
-        m = s.freeSnap(Inkscape::Snapper::SNAP_POINT, m, NULL).getPoint();
-        s.setDistance(curr_gridsnap);
+        SnapManager &sm = desktop->namedview->snap_manager;
+        SnapManager::SnapperList gs = sm.getGridSnappers();
+        m = sm.freeSnapAlways(Inkscape::Snapper::SNAP_POINT, m, NULL, gs).getPoint();
         sp_selection_move_relative(selection, m);
     }
 
@@ -1356,6 +1355,7 @@ bool
 selection_contains_original (SPItem *item, Inkscape::Selection *selection)
 {
     bool contains_original = false;
+    
     bool is_use = SP_IS_USE(item);
     SPItem *item_use = item;
     SPItem *item_use_first = item;
@@ -1366,7 +1366,14 @@ selection_contains_original (SPItem *item, Inkscape::Selection *selection)
         if (item_use == item_use_first)
             break;
         is_use = SP_IS_USE(item_use);
-    }   
+    }
+    
+    // If it's a tref, check whether the object containing the character
+    // data is part of the selection
+    if (!contains_original && SP_IS_TREF(item)) {
+        contains_original = selection->includes(SP_TREF(item)->getObjectReferredTo());
+    }
+       
     return contains_original;
 }
 
@@ -2082,6 +2089,8 @@ sp_selection_clone()
         Inkscape::GC::release(clone);
     }
     
+    // TRANSLATORS: only translate "string" in "context|string".
+    // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
     sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_CLONE, 
                      Q_("action|Clone"));
 
@@ -2111,15 +2120,21 @@ sp_selection_unlink()
          items != NULL;
          items = items->next)
     {
-        SPItem *use = (SPItem *) items->data;
+        SPItem *item = (SPItem *) items->data;
 
-        if (!SP_IS_USE(use)) {
-            // keep the non-yse item in the new selection
-            new_select = g_slist_prepend(new_select, use);
+        if (!(SP_IS_USE(item) || SP_IS_TREF(item))) {
+            // keep the non-use item in the new selection
+            new_select = g_slist_prepend(new_select, item);
             continue;
         }
 
-        SPItem *unlink = sp_use_unlink(SP_USE(use));
+        SPItem *unlink;
+        if (SP_IS_USE(item)) { 
+            unlink = sp_use_unlink(SP_USE(item));
+        } else /*if (SP_IS_TREF(use))*/ {
+            unlink = SP_ITEM(sp_tref_convert_to_tspan(SP_TREF(item)));
+        }
+        
         unlinked = true;
         // Add ungrouped items to the new selection.
         new_select = g_slist_prepend(new_select, unlink);
@@ -2846,23 +2861,21 @@ void fit_canvas_to_selection(SPDesktop *desktop) {
     g_return_if_fail(doc != NULL);
     g_return_if_fail(desktop->selection != NULL);
     g_return_if_fail(!desktop->selection->isEmpty());
-    NRRect bbox(0, 0, 0, 0);
 
-    desktop->selection->bounds(&bbox);
-    if (!nr_rect_d_test_empty(&bbox)) {
-        doc->fitToRect(bbox);
+    NR::Maybe<NR::Rect> const bbox(desktop->selection->bounds());
+    if (bbox && !bbox->isEmpty()) {
+        doc->fitToRect(*bbox);
     }
 };
 
 void fit_canvas_to_drawing(SPDocument *doc) {
     g_return_if_fail(doc != NULL);
-    NRRect bbox(0, 0, 0, 0);
 
-    sp_document_ensure_up_to_date (doc);
-    sp_item_invoke_bbox(SP_ITEM(doc->root), &bbox, sp_item_i2r_affine(SP_ITEM(doc->root)), TRUE);
-
-    if (!nr_rect_d_test_empty(&bbox)) {
-        doc->fitToRect(bbox);
+    sp_document_ensure_up_to_date(doc);
+    SPItem const *const root = SP_ITEM(doc->root);
+    NR::Maybe<NR::Rect> const bbox(root->getBounds(sp_item_i2r_affine(root)));
+    if (bbox && !bbox->isEmpty()) {
+        doc->fitToRect(*bbox);
     }
 };