Code

Remove double unreffing of pointer in pdf-cairo.cpp. Fixes Bug #178985 with the...
[inkscape.git] / src / selection-chemistry.cpp
index 07b79b2596047c4fac865df8a49de8c8453105a4..62f5c57e2e80c1be0677597912b01ec41609a871 100644 (file)
 #include "live_effects/parameter/path.h"
 #include "libnr/nr-convert2geom.h"
 
+// For clippath editing
+#include "tools-switch.h"
+#include "shape-editor.h"
+#include "node-context.h"
+#include "nodepath.h"
+
 using NR::X;
 using NR::Y;
 
@@ -948,6 +954,11 @@ void sp_copy_stuff_used_by_item (GSList **defs_clip, SPItem *item, GSList const
         }
     }
 
+    // For 3D boxes copy perspectives
+    if (SP_IS_BOX3D(item)) {
+        sp_copy_single (defs_clip, SP_OBJECT(box3d_get_perspective(SP_BOX3D(item))), xml_doc);
+    }
+
     if (SP_IS_TEXT_TEXTPATH (item)) {
         sp_copy_textpath_path (defs_clip, SP_TEXTPATH(sp_object_first_child(SP_OBJECT(item))), items, xml_doc);
     }
@@ -2130,6 +2141,50 @@ void sp_selection_next_patheffect_param(SPDesktop * dt)
     }
 }
 
+void sp_selection_edit_clip_or_mask(SPDesktop * dt, bool clip)
+{
+    if (!dt) return;
+
+    Inkscape::Selection *selection = sp_desktop_selection(dt);
+    if ( selection && !selection->isEmpty() ) {
+        SPItem *item = selection->singleItem();
+        if ( item ) {
+            SPObject *obj = NULL;
+            if (clip)
+                obj = item->clip_ref ? SP_OBJECT(item->clip_ref->getObject()) : NULL;
+            else
+                obj = item->mask_ref ? SP_OBJECT(item->mask_ref->getObject()) : NULL;
+
+            if (obj) {
+                // obj is a group object, the children are the actual clippers
+                for ( SPObject *child = obj->children ; child ; child = child->next ) {
+                    if ( SP_IS_ITEM(child) ) {
+                        // If not already in nodecontext, goto it!
+                        if (!tools_isactive(dt, TOOLS_NODES)) {
+                            tools_switch_current(TOOLS_NODES);
+                        }
+
+                        ShapeEditor * shape_editor = SP_NODE_CONTEXT( dt->event_context )->shape_editor;
+                        shape_editor->set_item(SP_ITEM(child));
+                        Inkscape::NodePath::Path *np = shape_editor->get_nodepath();
+                        if (np) {
+                            np->helperpath_rgba = clip ? 0x0000ffff : 0x800080ff;
+                            np->helperpath_width = 1.0;
+                            sp_nodepath_show_helperpath(np, true);
+                        }
+                        break; // break out of for loop after 1st encountered item
+                    }
+                }
+            } else if (clip) {
+                dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("The selection has no applied clip path."));
+            } else {
+                dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("The selection has no applied mask."));
+            }
+        }
+    }
+}
+
+
 namespace {
 
 template <typename D>
@@ -2428,12 +2483,13 @@ void sp_selection_to_marker(bool apply)
 
     sp_document_ensure_up_to_date(doc);
     NR::Maybe<NR::Rect> r = selection->bounds();
-    if ( !r || r->isEmpty() ) {
+    NR::Maybe<NR::Point> c = selection->center();
+    if ( !r || !c || r->isEmpty() ) {
         return;
     }
 
     // calculate the transform to be applied to objects to move them to 0,0
-    NR::Point move_p = NR::Point(0, sp_document_height(doc)) - (r->min() + NR::Point ((r->extent(NR::X))/2, (r->extent(NR::Y))/2));
+    NR::Point move_p = NR::Point(0, sp_document_height(doc)) - *c;
     move_p[NR::Y] = -move_p[NR::Y];
     NR::Matrix move = NR::Matrix (NR::translate (move_p));