1 #define __SP_SELECTION_CHEMISTRY_C__
3 /*
4 * Miscellanous operations on selected items
5 *
6 * Authors:
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * Frank Felfe <innerspace@iname.com>
9 * MenTaLguY <mental@rydia.net>
10 * bulia byak <buliabyak@users.sf.net>
11 * Andrius R. <knutux@gmail.com>
12 *
13 * Copyright (C) 1999-2006 authors
14 * Copyright (C) 2001-2002 Ximian, Inc.
15 *
16 * Released under GNU GPL, read the file 'COPYING' for more information
17 */
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #endif
23 #include <gtkmm/clipboard.h>
25 #include "svg/svg.h"
26 #include "inkscape.h"
27 #include "desktop.h"
28 #include "desktop-style.h"
29 #include "selection.h"
30 #include "tools-switch.h"
31 #include "desktop-handles.h"
32 #include "message-stack.h"
33 #include "sp-item-transform.h"
34 #include "marker.h"
35 #include "sp-use.h"
36 #include "sp-textpath.h"
37 #include "sp-tspan.h"
38 #include "sp-tref.h"
39 #include "sp-flowtext.h"
40 #include "sp-flowregion.h"
41 #include "text-editing.h"
42 #include "text-context.h"
43 #include "connector-context.h"
44 #include "sp-path.h"
45 #include "sp-conn-end.h"
46 #include "dropper-context.h"
47 #include <glibmm/i18n.h>
48 #include "libnr/nr-matrix-rotate-ops.h"
49 #include "libnr/nr-matrix-translate-ops.h"
50 #include "libnr/nr-rotate-fns.h"
51 #include "libnr/nr-scale-ops.h"
52 #include "libnr/nr-scale-translate-ops.h"
53 #include "libnr/nr-translate-matrix-ops.h"
54 #include "libnr/nr-translate-scale-ops.h"
55 #include "xml/repr.h"
56 #include "style.h"
57 #include "document-private.h"
58 #include "sp-gradient.h"
59 #include "sp-gradient-reference.h"
60 #include "sp-linear-gradient-fns.h"
61 #include "sp-pattern.h"
62 #include "sp-radial-gradient-fns.h"
63 #include "sp-namedview.h"
64 #include "prefs-utils.h"
65 #include "sp-offset.h"
66 #include "sp-clippath.h"
67 #include "sp-mask.h"
68 #include "file.h"
69 #include "helper/png-write.h"
70 #include "layer-fns.h"
71 #include "context-fns.h"
72 #include <map>
73 #include "helper/units.h"
74 #include "sp-item.h"
75 #include "unit-constants.h"
76 #include "xml/simple-document.h"
77 #include "sp-filter-reference.h"
78 #include "gradient-drag.h"
80 using NR::X;
81 using NR::Y;
83 #include "selection-chemistry.h"
85 /* fixme: find a better place */
86 Inkscape::XML::Document *clipboard_document = NULL;
87 GSList *clipboard = NULL;
88 GSList *defs_clipboard = NULL;
89 SPCSSAttr *style_clipboard = NULL;
90 NR::Maybe<NR::Rect> size_clipboard;
92 static void sp_copy_stuff_used_by_item(GSList **defs_clip, SPItem *item, const GSList *items, Inkscape::XML::Document* xml_doc);
94 /**
95 * Copies repr and its inherited css style elements, along with the accumulated transform 'full_t',
96 * then prepends the copy to 'clip'.
97 */
98 void sp_selection_copy_one (Inkscape::XML::Node *repr, NR::Matrix full_t, GSList **clip, Inkscape::XML::Document* xml_doc)
99 {
100 Inkscape::XML::Node *copy = repr->duplicate(xml_doc);
102 // copy complete inherited style
103 SPCSSAttr *css = sp_repr_css_attr_inherited(repr, "style");
104 sp_repr_css_set(copy, css, "style");
105 sp_repr_css_attr_unref(css);
107 // write the complete accumulated transform passed to us
108 // (we're dealing with unattached repr, so we write to its attr
109 // instead of using sp_item_set_transform)
110 gchar *affinestr=sp_svg_transform_write(full_t);
111 copy->setAttribute("transform", affinestr);
112 g_free(affinestr);
114 *clip = g_slist_prepend(*clip, copy);
115 }
117 void sp_selection_copy_impl (const GSList *items, GSList **clip, GSList **defs_clip, SPCSSAttr **style_clip, Inkscape::XML::Document* xml_doc)
118 {
120 // Copy stuff referenced by all items to defs_clip:
121 if (defs_clip) {
122 for (GSList *i = (GSList *) items; i != NULL; i = i->next) {
123 sp_copy_stuff_used_by_item (defs_clip, SP_ITEM (i->data), items, xml_doc);
124 }
125 *defs_clip = g_slist_reverse(*defs_clip);
126 }
128 // Store style:
129 if (style_clip) {
130 SPItem *item = SP_ITEM (items->data); // take from the first selected item
131 *style_clip = take_style_from_item (item);
132 }
134 if (clip) {
135 // Sort items:
136 GSList *sorted_items = g_slist_copy ((GSList *) items);
137 sorted_items = g_slist_sort((GSList *) sorted_items, (GCompareFunc) sp_object_compare_position);
139 // Copy item reprs:
140 for (GSList *i = (GSList *) sorted_items; i != NULL; i = i->next) {
141 sp_selection_copy_one (SP_OBJECT_REPR (i->data), sp_item_i2doc_affine(SP_ITEM (i->data)), clip, xml_doc);
142 }
144 *clip = g_slist_reverse(*clip);
145 g_slist_free ((GSList *) sorted_items);
146 }
147 }
149 /**
150 * Add gradients/patterns/markers referenced by copied objects to defs.
151 * Iterates through 'defs_clip', and for each item it adds the data
152 * repr into the global defs.
153 */
154 void
155 paste_defs (GSList **defs_clip, SPDocument *doc)
156 {
157 if (!defs_clip)
158 return;
160 for (GSList *gl = *defs_clip; gl != NULL; gl = gl->next) {
161 SPDefs *defs= (SPDefs *) SP_DOCUMENT_DEFS(doc);
162 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) gl->data;
163 gchar const *id = repr->attribute("id");
164 if (!id || !doc->getObjectById(id)) {
165 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
166 Inkscape::XML::Node *copy = repr->duplicate(xml_doc);
167 SP_OBJECT_REPR(defs)->addChild(copy, NULL);
168 Inkscape::GC::release(copy);
169 }
170 }
171 }
173 GSList *sp_selection_paste_impl (SPDocument *doc, SPObject *parent, GSList **clip, GSList **defs_clip)
174 {
175 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
176 paste_defs (defs_clip, doc);
178 GSList *copied = NULL;
179 // add objects to document
180 for (GSList *l = *clip; l != NULL; l = l->next) {
181 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) l->data;
182 Inkscape::XML::Node *copy = repr->duplicate(xml_doc);
184 // premultiply the item transform by the accumulated parent transform in the paste layer
185 NR::Matrix local = sp_item_i2doc_affine(SP_ITEM(parent));
186 if (!local.test_identity()) {
187 gchar const *t_str = copy->attribute("transform");
188 NR::Matrix item_t (NR::identity());
189 if (t_str)
190 sp_svg_transform_read(t_str, &item_t);
191 item_t *= local.inverse();
192 // (we're dealing with unattached repr, so we write to its attr instead of using sp_item_set_transform)
193 gchar *affinestr=sp_svg_transform_write(item_t);
194 copy->setAttribute("transform", affinestr);
195 g_free(affinestr);
196 }
198 parent->appendChildRepr(copy);
199 copied = g_slist_prepend(copied, copy);
200 Inkscape::GC::release(copy);
201 }
202 return copied;
203 }
205 void sp_selection_delete_impl(const GSList *items, bool propagate=true, bool propagate_descendants=true)
206 {
207 for (const GSList *i = items ; i ; i = i->next ) {
208 sp_object_ref((SPObject *)i->data, NULL);
209 }
210 for (const GSList *i = items; i != NULL; i = i->next) {
211 SPItem *item = (SPItem *) i->data;
212 SP_OBJECT(item)->deleteObject(propagate, propagate_descendants);
213 sp_object_unref((SPObject *)item, NULL);
214 }
215 }
218 void sp_selection_delete()
219 {
220 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
221 if (desktop == NULL) {
222 return;
223 }
225 if (tools_isactive (desktop, TOOLS_TEXT))
226 if (sp_text_delete_selection(desktop->event_context)) {
227 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_TEXT,
228 _("Delete text"));
229 return;
230 }
232 Inkscape::Selection *selection = sp_desktop_selection(desktop);
234 // check if something is selected
235 if (selection->isEmpty()) {
236 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("<b>Nothing</b> was deleted."));
237 return;
238 }
240 const GSList *selected = g_slist_copy(const_cast<GSList *>(selection->itemList()));
241 selection->clear();
242 sp_selection_delete_impl (selected);
243 g_slist_free ((GSList *) selected);
245 /* a tool may have set up private information in it's selection context
246 * that depends on desktop items. I think the only sane way to deal with
247 * this currently is to reset the current tool, which will reset it's
248 * associated selection context. For example: deleting an object
249 * while moving it around the canvas.
250 */
251 tools_switch ( desktop, tools_active ( desktop ) );
253 sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_DELETE,
254 _("Delete"));
255 }
257 /* fixme: sequencing */
258 void sp_selection_duplicate()
259 {
260 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
261 if (desktop == NULL)
262 return;
264 Inkscape::XML::Document* xml_doc = sp_document_repr_doc(desktop->doc());
265 Inkscape::Selection *selection = sp_desktop_selection(desktop);
267 // check if something is selected
268 if (selection->isEmpty()) {
269 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to duplicate."));
270 return;
271 }
273 GSList *reprs = g_slist_copy((GSList *) selection->reprList());
275 selection->clear();
277 // sorting items from different parents sorts each parent's subset without possibly mixing them, just what we need
278 reprs = g_slist_sort(reprs, (GCompareFunc) sp_repr_compare_position);
280 GSList *newsel = NULL;
282 while (reprs) {
283 Inkscape::XML::Node *parent = ((Inkscape::XML::Node *) reprs->data)->parent();
284 Inkscape::XML::Node *copy = ((Inkscape::XML::Node *) reprs->data)->duplicate(xml_doc);
286 parent->appendChild(copy);
288 newsel = g_slist_prepend(newsel, copy);
289 reprs = g_slist_remove(reprs, reprs->data);
290 Inkscape::GC::release(copy);
291 }
293 sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_DUPLICATE,
294 _("Duplicate"));
296 selection->setReprList(newsel);
298 g_slist_free(newsel);
299 }
301 void sp_edit_clear_all()
302 {
303 SPDesktop *dt = SP_ACTIVE_DESKTOP;
304 if (!dt)
305 return;
307 SPDocument *doc = sp_desktop_document(dt);
308 sp_desktop_selection(dt)->clear();
310 g_return_if_fail(SP_IS_GROUP(dt->currentLayer()));
311 GSList *items = sp_item_group_item_list(SP_GROUP(dt->currentLayer()));
313 while (items) {
314 SP_OBJECT (items->data)->deleteObject();
315 items = g_slist_remove(items, items->data);
316 }
318 sp_document_done(doc, SP_VERB_EDIT_CLEAR_ALL,
319 _("Delete all"));
320 }
322 GSList *
323 get_all_items (GSList *list, SPObject *from, SPDesktop *desktop, bool onlyvisible, bool onlysensitive, const GSList *exclude)
324 {
325 for (SPObject *child = sp_object_first_child(SP_OBJECT(from)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
326 if (SP_IS_ITEM(child) &&
327 !desktop->isLayer(SP_ITEM(child)) &&
328 (!onlysensitive || !SP_ITEM(child)->isLocked()) &&
329 (!onlyvisible || !desktop->itemIsHidden(SP_ITEM(child))) &&
330 (!exclude || !g_slist_find ((GSList *) exclude, child))
331 )
332 {
333 list = g_slist_prepend (list, SP_ITEM(child));
334 }
336 if (SP_IS_ITEM(child) && desktop->isLayer(SP_ITEM(child))) {
337 list = get_all_items (list, child, desktop, onlyvisible, onlysensitive, exclude);
338 }
339 }
341 return list;
342 }
344 void sp_edit_select_all_full (bool force_all_layers, bool invert)
345 {
346 SPDesktop *dt = SP_ACTIVE_DESKTOP;
347 if (!dt)
348 return;
350 Inkscape::Selection *selection = sp_desktop_selection(dt);
352 g_return_if_fail(SP_IS_GROUP(dt->currentLayer()));
354 PrefsSelectionContext inlayer = (PrefsSelectionContext)prefs_get_int_attribute ("options.kbselection", "inlayer", PREFS_SELECTION_LAYER);
355 bool onlyvisible = prefs_get_int_attribute ("options.kbselection", "onlyvisible", 1);
356 bool onlysensitive = prefs_get_int_attribute ("options.kbselection", "onlysensitive", 1);
358 GSList *items = NULL;
360 const GSList *exclude = NULL;
361 if (invert) {
362 exclude = selection->itemList();
363 }
365 if (force_all_layers)
366 inlayer = PREFS_SELECTION_ALL;
368 switch (inlayer) {
369 case PREFS_SELECTION_LAYER: {
370 if ( (onlysensitive && SP_ITEM(dt->currentLayer())->isLocked()) ||
371 (onlyvisible && dt->itemIsHidden(SP_ITEM(dt->currentLayer()))) )
372 return;
374 GSList *all_items = sp_item_group_item_list(SP_GROUP(dt->currentLayer()));
376 for (GSList *i = all_items; i; i = i->next) {
377 SPItem *item = SP_ITEM (i->data);
379 if (item && (!onlysensitive || !item->isLocked())) {
380 if (!onlyvisible || !dt->itemIsHidden(item)) {
381 if (!dt->isLayer(item)) {
382 if (!invert || !g_slist_find ((GSList *) exclude, item)) {
383 items = g_slist_prepend (items, item); // leave it in the list
384 }
385 }
386 }
387 }
388 }
390 g_slist_free (all_items);
391 break;
392 }
393 case PREFS_SELECTION_LAYER_RECURSIVE: {
394 items = get_all_items (NULL, dt->currentLayer(), dt, onlyvisible, onlysensitive, exclude);
395 break;
396 }
397 default: {
398 items = get_all_items (NULL, dt->currentRoot(), dt, onlyvisible, onlysensitive, exclude);
399 break;
400 }
401 }
403 selection->setList (items);
405 if (items) {
406 g_slist_free (items);
407 }
408 }
410 void sp_edit_select_all ()
411 {
412 sp_edit_select_all_full (false, false);
413 }
415 void sp_edit_select_all_in_all_layers ()
416 {
417 sp_edit_select_all_full (true, false);
418 }
420 void sp_edit_invert ()
421 {
422 sp_edit_select_all_full (false, true);
423 }
425 void sp_edit_invert_in_all_layers ()
426 {
427 sp_edit_select_all_full (true, true);
428 }
430 void sp_selection_group()
431 {
432 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
433 if (desktop == NULL)
434 return;
436 SPDocument *doc = sp_desktop_document (desktop);
437 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
439 Inkscape::Selection *selection = sp_desktop_selection(desktop);
441 // Check if something is selected.
442 if (selection->isEmpty()) {
443 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>some objects</b> to group."));
444 return;
445 }
447 GSList const *l = (GSList *) selection->reprList();
449 GSList *p = g_slist_copy((GSList *) l);
451 selection->clear();
453 p = g_slist_sort(p, (GCompareFunc) sp_repr_compare_position);
455 // Remember the position and parent of the topmost object.
456 gint topmost = ((Inkscape::XML::Node *) g_slist_last(p)->data)->position();
457 Inkscape::XML::Node *topmost_parent = ((Inkscape::XML::Node *) g_slist_last(p)->data)->parent();
459 Inkscape::XML::Node *group = xml_doc->createElement("svg:g");
461 while (p) {
462 Inkscape::XML::Node *current = (Inkscape::XML::Node *) p->data;
464 if (current->parent() == topmost_parent) {
465 Inkscape::XML::Node *spnew = current->duplicate(xml_doc);
466 sp_repr_unparent(current);
467 group->appendChild(spnew);
468 Inkscape::GC::release(spnew);
469 topmost --; // only reduce count for those items deleted from topmost_parent
470 } else { // move it to topmost_parent first
471 GSList *temp_clip = NULL;
473 // At this point, current may already have no item, due to its being a clone whose original is already moved away
474 // So we copy it artificially calculating the transform from its repr->attr("transform") and the parent transform
475 gchar const *t_str = current->attribute("transform");
476 NR::Matrix item_t (NR::identity());
477 if (t_str)
478 sp_svg_transform_read(t_str, &item_t);
479 item_t *= sp_item_i2doc_affine(SP_ITEM(doc->getObjectByRepr(current->parent())));
480 //FIXME: when moving both clone and original from a transformed group (either by
481 //grouping into another parent, or by cut/paste) the transform from the original's
482 //parent becomes embedded into original itself, and this affects its clones. Fix
483 //this by remembering the transform diffs we write to each item into an array and
484 //then, if this is clone, looking up its original in that array and pre-multiplying
485 //it by the inverse of that original's transform diff.
487 sp_selection_copy_one (current, item_t, &temp_clip, xml_doc);
488 sp_repr_unparent(current);
490 // paste into topmost_parent (temporarily)
491 GSList *copied = sp_selection_paste_impl (doc, doc->getObjectByRepr(topmost_parent), &temp_clip, NULL);
492 if (temp_clip) g_slist_free (temp_clip);
493 if (copied) { // if success,
494 // take pasted object (now in topmost_parent)
495 Inkscape::XML::Node *in_topmost = (Inkscape::XML::Node *) copied->data;
496 // make a copy
497 Inkscape::XML::Node *spnew = in_topmost->duplicate(xml_doc);
498 // remove pasted
499 sp_repr_unparent(in_topmost);
500 // put its copy into group
501 group->appendChild(spnew);
502 Inkscape::GC::release(spnew);
503 g_slist_free (copied);
504 }
505 }
506 p = g_slist_remove(p, current);
507 }
509 // Add the new group to the topmost members' parent
510 topmost_parent->appendChild(group);
512 // Move to the position of the topmost, reduced by the number of items deleted from topmost_parent
513 group->setPosition(topmost + 1);
515 sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_GROUP,
516 _("Group"));
518 selection->set(group);
519 Inkscape::GC::release(group);
520 }
522 void sp_selection_ungroup()
523 {
524 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
525 if (desktop == NULL)
526 return;
528 Inkscape::Selection *selection = sp_desktop_selection(desktop);
530 if (selection->isEmpty()) {
531 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a <b>group</b> to ungroup."));
532 return;
533 }
535 GSList *items = g_slist_copy((GSList *) selection->itemList());
536 selection->clear();
538 // Get a copy of current selection.
539 GSList *new_select = NULL;
540 bool ungrouped = false;
541 for (GSList *i = items;
542 i != NULL;
543 i = i->next)
544 {
545 SPItem *group = (SPItem *) i->data;
547 // when ungrouping cloned groups with their originals, some objects that were selected may no more exist due to unlinking
548 if (!SP_IS_OBJECT(group)) {
549 continue;
550 }
552 /* We do not allow ungrouping <svg> etc. (lauris) */
553 if (strcmp(SP_OBJECT_REPR(group)->name(), "svg:g") && strcmp(SP_OBJECT_REPR(group)->name(), "svg:switch")) {
554 // keep the non-group item in the new selection
555 selection->add(group);
556 continue;
557 }
559 GSList *children = NULL;
560 /* This is not strictly required, but is nicer to rely on group ::destroy (lauris) */
561 sp_item_group_ungroup(SP_GROUP(group), &children, false);
562 ungrouped = true;
563 // Add ungrouped items to the new selection.
564 new_select = g_slist_concat(new_select, children);
565 }
567 if (new_select) { // Set new selection.
568 selection->addList(new_select);
569 g_slist_free(new_select);
570 }
571 if (!ungrouped) {
572 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No groups</b> to ungroup in the selection."));
573 }
575 g_slist_free(items);
577 sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_UNGROUP,
578 _("Ungroup"));
579 }
581 static SPGroup *
582 sp_item_list_common_parent_group(const GSList *items)
583 {
584 if (!items) {
585 return NULL;
586 }
587 SPObject *parent = SP_OBJECT_PARENT(items->data);
588 /* Strictly speaking this CAN happen, if user selects <svg> from Inkscape::XML editor */
589 if (!SP_IS_GROUP(parent)) {
590 return NULL;
591 }
592 for (items = items->next; items; items = items->next) {
593 if (SP_OBJECT_PARENT(items->data) != parent) {
594 return NULL;
595 }
596 }
598 return SP_GROUP(parent);
599 }
601 /** Finds out the minimum common bbox of the selected items
602 */
603 static NR::Maybe<NR::Rect>
604 enclose_items(const GSList *items)
605 {
606 g_assert(items != NULL);
608 NR::Maybe<NR::Rect> r = NR::Nothing();
609 for (GSList const *i = items; i; i = i->next) {
610 r = NR::union_bounds(r, sp_item_bbox_desktop((SPItem *) i->data));
611 }
612 return r;
613 }
615 SPObject *
616 prev_sibling(SPObject *child)
617 {
618 SPObject *parent = SP_OBJECT_PARENT(child);
619 if (!SP_IS_GROUP(parent)) {
620 return NULL;
621 }
622 for ( SPObject *i = sp_object_first_child(parent) ; i; i = SP_OBJECT_NEXT(i) ) {
623 if (i->next == child)
624 return i;
625 }
626 return NULL;
627 }
629 void
630 sp_selection_raise()
631 {
632 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
633 if (!desktop)
634 return;
636 Inkscape::Selection *selection = sp_desktop_selection(desktop);
638 GSList const *items = (GSList *) selection->itemList();
639 if (!items) {
640 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise."));
641 return;
642 }
644 SPGroup const *group = sp_item_list_common_parent_group(items);
645 if (!group) {
646 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>."));
647 return;
648 }
650 Inkscape::XML::Node *grepr = SP_OBJECT_REPR(group);
652 /* construct reverse-ordered list of selected children */
653 GSList *rev = g_slist_copy((GSList *) items);
654 rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position);
656 // find out the common bbox of the selected items
657 NR::Maybe<NR::Rect> selected = enclose_items(items);
659 // for all objects in the selection (starting from top)
660 if (selected) {
661 while (rev) {
662 SPObject *child = SP_OBJECT(rev->data);
663 // for each selected object, find the next sibling
664 for (SPObject *newref = child->next; newref; newref = newref->next) {
665 // if the sibling is an item AND overlaps our selection,
666 if (SP_IS_ITEM(newref)) {
667 NR::Maybe<NR::Rect> newref_bbox = sp_item_bbox_desktop(SP_ITEM(newref));
668 if ( newref_bbox && selected->intersects(*newref_bbox) ) {
669 // AND if it's not one of our selected objects,
670 if (!g_slist_find((GSList *) items, newref)) {
671 // move the selected object after that sibling
672 grepr->changeOrder(SP_OBJECT_REPR(child), SP_OBJECT_REPR(newref));
673 }
674 break;
675 }
676 }
677 }
678 rev = g_slist_remove(rev, child);
679 }
680 } else {
681 g_slist_free(rev);
682 }
684 sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_RAISE,
685 _("Raise"));
686 }
688 void sp_selection_raise_to_top()
689 {
690 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
691 if (desktop == NULL)
692 return;
694 SPDocument *document = sp_desktop_document(desktop);
695 Inkscape::Selection *selection = sp_desktop_selection(desktop);
697 if (selection->isEmpty()) {
698 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to raise to top."));
699 return;
700 }
702 GSList const *items = (GSList *) selection->itemList();
704 SPGroup const *group = sp_item_list_common_parent_group(items);
705 if (!group) {
706 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>."));
707 return;
708 }
710 GSList *rl = g_slist_copy((GSList *) selection->reprList());
711 rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position);
713 for (GSList *l = rl; l != NULL; l = l->next) {
714 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) l->data;
715 repr->setPosition(-1);
716 }
718 g_slist_free(rl);
720 sp_document_done(document, SP_VERB_SELECTION_TO_FRONT,
721 _("Raise to top"));
722 }
724 void
725 sp_selection_lower()
726 {
727 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
728 if (desktop == NULL)
729 return;
731 Inkscape::Selection *selection = sp_desktop_selection(desktop);
733 GSList const *items = (GSList *) selection->itemList();
734 if (!items) {
735 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower."));
736 return;
737 }
739 SPGroup const *group = sp_item_list_common_parent_group(items);
740 if (!group) {
741 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>."));
742 return;
743 }
745 Inkscape::XML::Node *grepr = SP_OBJECT_REPR(group);
747 // find out the common bbox of the selected items
748 NR::Maybe<NR::Rect> selected = enclose_items(items);
750 /* construct direct-ordered list of selected children */
751 GSList *rev = g_slist_copy((GSList *) items);
752 rev = g_slist_sort(rev, (GCompareFunc) sp_item_repr_compare_position);
753 rev = g_slist_reverse(rev);
755 // for all objects in the selection (starting from top)
756 if (selected) {
757 while (rev) {
758 SPObject *child = SP_OBJECT(rev->data);
759 // for each selected object, find the prev sibling
760 for (SPObject *newref = prev_sibling(child); newref; newref = prev_sibling(newref)) {
761 // if the sibling is an item AND overlaps our selection,
762 if (SP_IS_ITEM(newref)) {
763 NR::Maybe<NR::Rect> ref_bbox = sp_item_bbox_desktop(SP_ITEM(newref));
764 if ( ref_bbox && selected->intersects(*ref_bbox) ) {
765 // AND if it's not one of our selected objects,
766 if (!g_slist_find((GSList *) items, newref)) {
767 // move the selected object before that sibling
768 SPObject *put_after = prev_sibling(newref);
769 if (put_after)
770 grepr->changeOrder(SP_OBJECT_REPR(child), SP_OBJECT_REPR(put_after));
771 else
772 SP_OBJECT_REPR(child)->setPosition(0);
773 }
774 break;
775 }
776 }
777 }
778 rev = g_slist_remove(rev, child);
779 }
780 } else {
781 g_slist_free(rev);
782 }
784 sp_document_done(sp_desktop_document(desktop), SP_VERB_SELECTION_LOWER,
785 _("Lower"));
786 }
788 void sp_selection_lower_to_bottom()
789 {
790 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
791 if (desktop == NULL)
792 return;
794 SPDocument *document = sp_desktop_document(desktop);
795 Inkscape::Selection *selection = sp_desktop_selection(desktop);
797 if (selection->isEmpty()) {
798 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to lower to bottom."));
799 return;
800 }
802 GSList const *items = (GSList *) selection->itemList();
804 SPGroup const *group = sp_item_list_common_parent_group(items);
805 if (!group) {
806 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("You cannot raise/lower objects from <b>different groups</b> or <b>layers</b>."));
807 return;
808 }
810 GSList *rl;
811 rl = g_slist_copy((GSList *) selection->reprList());
812 rl = g_slist_sort(rl, (GCompareFunc) sp_repr_compare_position);
813 rl = g_slist_reverse(rl);
815 for (GSList *l = rl; l != NULL; l = l->next) {
816 gint minpos;
817 SPObject *pp, *pc;
818 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) l->data;
819 pp = document->getObjectByRepr(sp_repr_parent(repr));
820 minpos = 0;
821 g_assert(SP_IS_GROUP(pp));
822 pc = sp_object_first_child(pp);
823 while (!SP_IS_ITEM(pc)) {
824 minpos += 1;
825 pc = pc->next;
826 }
827 repr->setPosition(minpos);
828 }
830 g_slist_free(rl);
832 sp_document_done(document, SP_VERB_SELECTION_TO_BACK,
833 _("Lower to bottom"));
834 }
836 void
837 sp_undo(SPDesktop *desktop, SPDocument *)
838 {
839 if (!sp_document_undo(sp_desktop_document(desktop)))
840 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to undo."));
841 }
843 void
844 sp_redo(SPDesktop *desktop, SPDocument *)
845 {
846 if (!sp_document_redo(sp_desktop_document(desktop)))
847 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing to redo."));
848 }
850 void sp_selection_cut()
851 {
852 sp_selection_copy();
853 sp_selection_delete();
854 }
856 void sp_copy_gradient (GSList **defs_clip, SPGradient *gradient, Inkscape::XML::Document* xml_doc)
857 {
858 SPGradient *ref = gradient;
860 while (ref) {
861 // climb up the refs, copying each one in the chain
862 Inkscape::XML::Node *grad_repr = SP_OBJECT_REPR(ref)->duplicate(xml_doc);
863 *defs_clip = g_slist_prepend (*defs_clip, grad_repr);
865 ref = ref->ref->getObject();
866 }
867 }
869 void sp_copy_pattern (GSList **defs_clip, SPPattern *pattern, Inkscape::XML::Document* xml_doc)
870 {
871 SPPattern *ref = pattern;
873 while (ref) {
874 // climb up the refs, copying each one in the chain
875 Inkscape::XML::Node *pattern_repr = SP_OBJECT_REPR(ref)->duplicate(xml_doc);
876 *defs_clip = g_slist_prepend (*defs_clip, pattern_repr);
878 // items in the pattern may also use gradients and other patterns, so we need to recurse here as well
879 for (SPObject *child = sp_object_first_child(SP_OBJECT(ref)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
880 if (!SP_IS_ITEM (child))
881 continue;
882 sp_copy_stuff_used_by_item (defs_clip, (SPItem *) child, NULL, xml_doc);
883 }
885 ref = ref->ref->getObject();
886 }
887 }
889 void sp_copy_single (GSList **defs_clip, SPObject *thing, Inkscape::XML::Document* xml_doc)
890 {
891 Inkscape::XML::Node *duplicate_repr = SP_OBJECT_REPR(thing)->duplicate(xml_doc);
892 *defs_clip = g_slist_prepend (*defs_clip, duplicate_repr);
893 }
896 void sp_copy_textpath_path (GSList **defs_clip, SPTextPath *tp, const GSList *items, Inkscape::XML::Document* xml_doc)
897 {
898 SPItem *path = sp_textpath_get_path_item (tp);
899 if (!path)
900 return;
901 if (items && g_slist_find ((GSList *) items, path)) // do not copy it to defs if it is already in the list of items copied
902 return;
903 Inkscape::XML::Node *repr = SP_OBJECT_REPR(path)->duplicate(xml_doc);
904 *defs_clip = g_slist_prepend (*defs_clip, repr);
905 }
907 /**
908 * Copies things like patterns, markers, gradients, etc.
909 */
910 void sp_copy_stuff_used_by_item (GSList **defs_clip, SPItem *item, const GSList *items, Inkscape::XML::Document* xml_doc)
911 {
912 SPStyle *style = SP_OBJECT_STYLE (item);
914 if (style && (style->fill.isPaintserver())) {
915 SPObject *server = SP_OBJECT_STYLE_FILL_SERVER(item);
916 if (SP_IS_LINEARGRADIENT (server) || SP_IS_RADIALGRADIENT (server))
917 sp_copy_gradient (defs_clip, SP_GRADIENT(server), xml_doc);
918 if (SP_IS_PATTERN (server))
919 sp_copy_pattern (defs_clip, SP_PATTERN(server), xml_doc);
920 }
922 if (style && (style->stroke.isPaintserver())) {
923 SPObject *server = SP_OBJECT_STYLE_STROKE_SERVER(item);
924 if (SP_IS_LINEARGRADIENT (server) || SP_IS_RADIALGRADIENT (server))
925 sp_copy_gradient (defs_clip, SP_GRADIENT(server), xml_doc);
926 if (SP_IS_PATTERN (server))
927 sp_copy_pattern (defs_clip, SP_PATTERN(server), xml_doc);
928 }
930 // For shapes, copy all of the shape's markers into defs_clip
931 if (SP_IS_SHAPE (item)) {
932 SPShape *shape = SP_SHAPE (item);
933 for (int i = 0 ; i < SP_MARKER_LOC_QTY ; i++) {
934 if (shape->marker[i]) {
935 sp_copy_single (defs_clip, SP_OBJECT (shape->marker[i]), xml_doc);
936 }
937 }
939 // For shapes, also copy liveeffect if applicable
940 if (sp_shape_has_path_effect(shape)) {
941 sp_copy_single (defs_clip, SP_OBJECT(sp_shape_get_livepatheffectobject(shape)), xml_doc);
942 }
943 }
945 if (SP_IS_TEXT_TEXTPATH (item)) {
946 sp_copy_textpath_path (defs_clip, SP_TEXTPATH(sp_object_first_child(SP_OBJECT(item))), items, xml_doc);
947 }
949 if (item->clip_ref->getObject()) {
950 sp_copy_single (defs_clip, item->clip_ref->getObject(), xml_doc);
951 }
953 if (item->mask_ref->getObject()) {
954 SPObject *mask = item->mask_ref->getObject();
955 sp_copy_single (defs_clip, mask, xml_doc);
956 // recurse into the mask for its gradients etc.
957 for (SPObject *o = SP_OBJECT(mask)->children; o != NULL; o = o->next) {
958 if (SP_IS_ITEM(o))
959 sp_copy_stuff_used_by_item (defs_clip, SP_ITEM (o), items, xml_doc);
960 }
961 }
963 if (style->getFilter()) {
964 SPObject *filter = style->getFilter();
965 if (SP_IS_FILTER(filter)) {
966 sp_copy_single (defs_clip, filter, xml_doc);
967 }
968 }
970 // recurse
971 for (SPObject *o = SP_OBJECT(item)->children; o != NULL; o = o->next) {
972 if (SP_IS_ITEM(o))
973 sp_copy_stuff_used_by_item (defs_clip, SP_ITEM (o), items, xml_doc);
974 }
975 }
977 void
978 sp_set_style_clipboard (SPCSSAttr *css)
979 {
980 if (css != NULL) {
981 // clear style clipboard
982 if (style_clipboard) {
983 sp_repr_css_attr_unref (style_clipboard);
984 style_clipboard = NULL;
985 }
986 //sp_repr_css_print (css);
987 style_clipboard = css;
988 }
989 }
991 /**
992 * \pre item != NULL
993 */
994 SPCSSAttr *
995 take_style_from_item (SPItem *item)
996 {
997 // write the complete cascaded style, context-free
998 SPCSSAttr *css = sp_css_attr_from_object (SP_OBJECT(item), SP_STYLE_FLAG_ALWAYS);
999 if (css == NULL)
1000 return NULL;
1002 if ((SP_IS_GROUP(item) && SP_OBJECT(item)->children) ||
1003 (SP_IS_TEXT (item) && SP_OBJECT(item)->children && SP_OBJECT(item)->children->next == NULL)) {
1004 // if this is a text with exactly one tspan child, merge the style of that tspan as well
1005 // If this is a group, merge the style of its topmost (last) child with style
1006 for (SPObject *last_element = item->lastChild(); last_element != NULL; last_element = SP_OBJECT_PREV (last_element)) {
1007 if (SP_OBJECT_STYLE (last_element) != NULL) {
1008 SPCSSAttr *temp = sp_css_attr_from_object (last_element, SP_STYLE_FLAG_IFSET);
1009 if (temp) {
1010 sp_repr_css_merge (css, temp);
1011 sp_repr_css_attr_unref (temp);
1012 }
1013 break;
1014 }
1015 }
1016 }
1017 if (!(SP_IS_TEXT (item) || SP_IS_TSPAN (item) || SP_IS_TREF(item) || SP_IS_STRING (item))) {
1018 // do not copy text properties from non-text objects, it's confusing
1019 css = sp_css_attr_unset_text (css);
1020 }
1022 // FIXME: also transform gradient/pattern fills, by forking? NO, this must be nondestructive
1023 double ex = NR::expansion(sp_item_i2doc_affine(item));
1024 if (ex != 1.0) {
1025 css = sp_css_attr_scale (css, ex);
1026 }
1028 return css;
1029 }
1032 void sp_selection_copy()
1033 {
1034 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1035 if (desktop == NULL)
1036 return;
1038 if (!clipboard_document) {
1039 clipboard_document = new Inkscape::XML::SimpleDocument();
1040 }
1042 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1044 if (tools_isactive (desktop, TOOLS_DROPPER)) {
1045 sp_dropper_context_copy(desktop->event_context);
1046 return; // copied color under cursor, nothing else to do
1047 }
1049 if (desktop->event_context->get_drag() && desktop->event_context->get_drag()->copy()) {
1050 return; // copied selected stop(s), nothing else to do
1051 }
1053 // check if something is selected
1054 if (selection->isEmpty()) {
1055 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing was copied."));
1056 return;
1057 }
1059 const GSList *items = g_slist_copy ((GSList *) selection->itemList());
1061 // 0. Copy text to system clipboard
1062 // FIXME: for non-texts, put serialized Inkscape::XML as text to the clipboard;
1063 //for this sp_repr_write_stream needs to be rewritten with iostream instead of FILE
1064 Glib::ustring text;
1065 if (tools_isactive (desktop, TOOLS_TEXT)) {
1066 text = sp_text_get_selected_text(desktop->event_context);
1067 }
1069 if (text.empty()) {
1070 guint texts = 0;
1071 for (GSList *i = (GSList *) items; i; i = i->next) {
1072 SPItem *item = SP_ITEM (i->data);
1073 if (SP_IS_TEXT (item) || SP_IS_FLOWTEXT(item)) {
1074 if (texts > 0) // if more than one text object is copied, separate them by spaces
1075 text += " ";
1076 gchar *this_text = sp_te_get_string_multiline (item);
1077 if (this_text) {
1078 text += this_text;
1079 g_free(this_text);
1080 }
1081 texts++;
1082 }
1083 }
1084 }
1085 if (!text.empty()) {
1086 Glib::RefPtr<Gtk::Clipboard> refClipboard = Gtk::Clipboard::get();
1087 refClipboard->set_text(text);
1088 }
1090 // clear old defs clipboard
1091 while (defs_clipboard) {
1092 Inkscape::GC::release((Inkscape::XML::Node *) defs_clipboard->data);
1093 defs_clipboard = g_slist_remove (defs_clipboard, defs_clipboard->data);
1094 }
1096 // clear style clipboard
1097 if (style_clipboard) {
1098 sp_repr_css_attr_unref (style_clipboard);
1099 style_clipboard = NULL;
1100 }
1102 //clear main clipboard
1103 while (clipboard) {
1104 Inkscape::GC::release((Inkscape::XML::Node *) clipboard->data);
1105 clipboard = g_slist_remove(clipboard, clipboard->data);
1106 }
1108 sp_selection_copy_impl (items, &clipboard, &defs_clipboard, &style_clipboard, clipboard_document);
1110 if (tools_isactive (desktop, TOOLS_TEXT)) { // take style from cursor/text selection, overwriting the style just set by copy_impl
1111 SPStyle *const query = sp_style_new(SP_ACTIVE_DOCUMENT);
1112 if (sp_desktop_query_style_all (desktop, query)) {
1113 SPCSSAttr *css = sp_css_attr_from_style (query, SP_STYLE_FLAG_ALWAYS);
1114 sp_set_style_clipboard (css);
1115 }
1116 sp_style_unref(query);
1117 }
1119 size_clipboard = selection->bounds();
1121 g_slist_free ((GSList *) items);
1122 }
1124 void sp_selection_paste(bool in_place)
1125 {
1126 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1128 if (desktop == NULL) {
1129 return;
1130 }
1132 SPDocument *document = sp_desktop_document(desktop);
1134 if (Inkscape::have_viable_layer(desktop, desktop->messageStack()) == false) {
1135 return;
1136 }
1138 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1140 if (tools_isactive (desktop, TOOLS_TEXT)) {
1141 if (sp_text_paste_inline(desktop->event_context))
1142 return; // pasted from system clipboard into text, nothing else to do
1143 }
1145 // check if something is in the clipboard
1146 if (clipboard == NULL) {
1147 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing on the clipboard."));
1148 return;
1149 }
1151 GSList *copied = sp_selection_paste_impl(document, desktop->currentLayer(), &clipboard, &defs_clipboard);
1152 // add pasted objects to selection
1153 selection->setReprList((GSList const *) copied);
1154 g_slist_free (copied);
1156 if (!in_place) {
1157 sp_document_ensure_up_to_date(document);
1159 NR::Maybe<NR::Rect> sel_bbox = selection->bounds();
1160 NR::Point m( desktop->point() );
1161 if (sel_bbox) {
1162 m -= sel_bbox->midpoint();
1163 }
1165 /* Snap the offset of the new item(s) to the grid */
1166 SnapManager &sm = desktop->namedview->snap_manager;
1167 SnapManager::SnapperList gs = sm.getGridSnappers();
1168 m = sm.freeSnapAlways(Inkscape::Snapper::SNAPPOINT_NODE, m, NULL, gs).getPoint();
1169 sp_selection_move_relative(selection, m);
1170 }
1172 sp_document_done(document, SP_VERB_EDIT_PASTE,
1173 _("Paste"));
1174 }
1176 void sp_selection_paste_style()
1177 {
1178 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1179 if (desktop == NULL) return;
1181 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1183 // check if something is in the clipboard
1184 if (style_clipboard == NULL) {
1185 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing on the style clipboard."));
1186 return;
1187 }
1189 // check if something is selected
1190 if (selection->isEmpty()) {
1191 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to paste style to."));
1192 return;
1193 }
1195 paste_defs (&defs_clipboard, sp_desktop_document(desktop));
1197 sp_desktop_set_style (desktop, style_clipboard);
1199 sp_document_done(sp_desktop_document (desktop), SP_VERB_EDIT_PASTE_STYLE,
1200 _("Paste style"));
1201 }
1203 void sp_selection_paste_livepatheffect()
1204 {
1205 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1206 if (desktop == NULL) return;
1208 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1210 // check if something is in the clipboard
1211 if (clipboard == NULL) {
1212 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing on the clipboard."));
1213 return;
1214 }
1216 // check if something is selected
1217 if (selection->isEmpty()) {
1218 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to paste live path effect to."));
1219 return;
1220 }
1222 paste_defs (&defs_clipboard, sp_desktop_document(desktop));
1224 Inkscape::XML::Node *repr = (Inkscape::XML::Node *) clipboard->data;
1225 const char * effectstr = repr->attribute("inkscape:path-effect");
1226 if (!effectstr) {
1227 SP_ACTIVE_DESKTOP->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Clipboard does not contain a live path effect."));
1228 return;
1229 }
1231 for ( GSList const *itemlist = selection->itemList(); itemlist != NULL; itemlist = g_slist_next(itemlist) ) {
1232 SPItem *item = reinterpret_cast<SPItem*>(itemlist->data);
1233 if ( item && SP_IS_SHAPE(item) ) {
1234 Inkscape::XML::Node *selrepr = (Inkscape::XML::Node *) SP_OBJECT_REPR(item);
1235 selrepr->setAttribute("inkscape:path-effect", effectstr);
1237 // set inkscape:original-d for paths. the other shapes don't need this.
1238 if ( SP_IS_PATH(item) ) {
1239 Inkscape::XML::Node *pathrepr = SP_OBJECT_REPR(item);
1240 if ( ! pathrepr->attribute("inkscape:original-d") ) {
1241 pathrepr->setAttribute("inkscape:original-d", pathrepr->attribute("d"));
1242 }
1243 }
1244 }
1245 }
1247 sp_document_done(sp_desktop_document (desktop), SP_VERB_EDIT_PASTE_LIVEPATHEFFECT,
1248 _("Paste live path effect"));
1249 }
1251 void sp_selection_paste_size (bool apply_x, bool apply_y)
1252 {
1253 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1254 if (desktop == NULL) return;
1256 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1258 // check if something is in the clipboard
1259 if (!size_clipboard) {
1260 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing on the clipboard."));
1261 return;
1262 }
1264 // check if something is selected
1265 if (selection->isEmpty()) {
1266 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to paste size to."));
1267 return;
1268 }
1270 NR::Maybe<NR::Rect> current = selection->bounds();
1271 if ( !current || current->isEmpty() ) {
1272 return;
1273 }
1275 double scale_x = size_clipboard->extent(NR::X) / current->extent(NR::X);
1276 double scale_y = size_clipboard->extent(NR::Y) / current->extent(NR::Y);
1278 sp_selection_scale_relative (selection, current->midpoint(),
1279 NR::scale(
1280 apply_x? scale_x : (desktop->isToolboxButtonActive ("lock")? scale_y : 1.0),
1281 apply_y? scale_y : (desktop->isToolboxButtonActive ("lock")? scale_x : 1.0)));
1283 sp_document_done(sp_desktop_document (desktop), SP_VERB_EDIT_PASTE_SIZE,
1284 _("Paste size"));
1285 }
1287 void sp_selection_paste_size_separately (bool apply_x, bool apply_y)
1288 {
1289 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1290 if (desktop == NULL) return;
1292 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1294 // check if something is in the clipboard
1295 if ( !size_clipboard ) {
1296 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Nothing on the clipboard."));
1297 return;
1298 }
1300 // check if something is selected
1301 if (selection->isEmpty()) {
1302 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to paste size to."));
1303 return;
1304 }
1306 for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
1307 SPItem *item = SP_ITEM(l->data);
1309 NR::Maybe<NR::Rect> current = sp_item_bbox_desktop(item);
1310 if ( !current || current->isEmpty() ) {
1311 continue;
1312 }
1314 double scale_x = size_clipboard->extent(NR::X) / current->extent(NR::X);
1315 double scale_y = size_clipboard->extent(NR::Y) / current->extent(NR::Y);
1317 sp_item_scale_rel (item,
1318 NR::scale(
1319 apply_x? scale_x : (desktop->isToolboxButtonActive ("lock")? scale_y : 1.0),
1320 apply_y? scale_y : (desktop->isToolboxButtonActive ("lock")? scale_x : 1.0)));
1322 }
1324 sp_document_done(sp_desktop_document (desktop), SP_VERB_EDIT_PASTE_SIZE_SEPARATELY,
1325 _("Paste size separately"));
1326 }
1328 void sp_selection_to_next_layer ()
1329 {
1330 SPDesktop *dt = SP_ACTIVE_DESKTOP;
1332 Inkscape::Selection *selection = sp_desktop_selection(dt);
1334 // check if something is selected
1335 if (selection->isEmpty()) {
1336 dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to move to the layer above."));
1337 return;
1338 }
1340 const GSList *items = g_slist_copy ((GSList *) selection->itemList());
1342 bool no_more = false; // Set to true, if no more layers above
1343 SPObject *next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer());
1344 if (next) {
1345 GSList *temp_clip = NULL;
1346 sp_selection_copy_impl (items, &temp_clip, NULL, NULL, sp_document_repr_doc(dt->doc())); // we're in the same doc, so no need to copy defs
1347 sp_selection_delete_impl (items, false, false);
1348 next=Inkscape::next_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers
1349 GSList *copied;
1350 if(next) {
1351 copied = sp_selection_paste_impl (sp_desktop_document (dt), next, &temp_clip, NULL);
1352 } else {
1353 copied = sp_selection_paste_impl (sp_desktop_document (dt), dt->currentLayer(), &temp_clip, NULL);
1354 no_more = true;
1355 }
1356 selection->setReprList((GSList const *) copied);
1357 g_slist_free (copied);
1358 if (temp_clip) g_slist_free (temp_clip);
1359 if (next) dt->setCurrentLayer(next);
1360 sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_NEXT,
1361 _("Raise to next layer"));
1362 } else {
1363 no_more = true;
1364 }
1366 if (no_more) {
1367 dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers above."));
1368 }
1370 g_slist_free ((GSList *) items);
1371 }
1373 void sp_selection_to_prev_layer ()
1374 {
1375 SPDesktop *dt = SP_ACTIVE_DESKTOP;
1377 Inkscape::Selection *selection = sp_desktop_selection(dt);
1379 // check if something is selected
1380 if (selection->isEmpty()) {
1381 dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to move to the layer below."));
1382 return;
1383 }
1385 const GSList *items = g_slist_copy ((GSList *) selection->itemList());
1387 bool no_more = false; // Set to true, if no more layers below
1388 SPObject *next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer());
1389 if (next) {
1390 GSList *temp_clip = NULL;
1391 sp_selection_copy_impl (items, &temp_clip, NULL, NULL, sp_document_repr_doc(dt->doc())); // we're in the same doc, so no need to copy defs
1392 sp_selection_delete_impl (items, false, false);
1393 next=Inkscape::previous_layer(dt->currentRoot(), dt->currentLayer()); // Fixes bug 1482973: crash while moving layers
1394 GSList *copied;
1395 if(next) {
1396 copied = sp_selection_paste_impl (sp_desktop_document (dt), next, &temp_clip, NULL);
1397 } else {
1398 copied = sp_selection_paste_impl (sp_desktop_document (dt), dt->currentLayer(), &temp_clip, NULL);
1399 no_more = true;
1400 }
1401 selection->setReprList((GSList const *) copied);
1402 g_slist_free (copied);
1403 if (temp_clip) g_slist_free (temp_clip);
1404 if (next) dt->setCurrentLayer(next);
1405 sp_document_done(sp_desktop_document (dt), SP_VERB_LAYER_MOVE_TO_PREV,
1406 _("Lower to previous layer"));
1407 } else {
1408 no_more = true;
1409 }
1411 if (no_more) {
1412 dt->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("No more layers below."));
1413 }
1415 g_slist_free ((GSList *) items);
1416 }
1418 bool
1419 selection_contains_original (SPItem *item, Inkscape::Selection *selection)
1420 {
1421 bool contains_original = false;
1423 bool is_use = SP_IS_USE(item);
1424 SPItem *item_use = item;
1425 SPItem *item_use_first = item;
1426 while (is_use && item_use && !contains_original)
1427 {
1428 item_use = sp_use_get_original (SP_USE(item_use));
1429 contains_original |= selection->includes(item_use);
1430 if (item_use == item_use_first)
1431 break;
1432 is_use = SP_IS_USE(item_use);
1433 }
1435 // If it's a tref, check whether the object containing the character
1436 // data is part of the selection
1437 if (!contains_original && SP_IS_TREF(item)) {
1438 contains_original = selection->includes(SP_TREF(item)->getObjectReferredTo());
1439 }
1441 return contains_original;
1442 }
1445 bool
1446 selection_contains_both_clone_and_original (Inkscape::Selection *selection)
1447 {
1448 bool clone_with_original = false;
1449 for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
1450 SPItem *item = SP_ITEM(l->data);
1451 clone_with_original |= selection_contains_original(item, selection);
1452 if (clone_with_original)
1453 break;
1454 }
1455 return clone_with_original;
1456 }
1459 /** Apply matrix to the selection. \a set_i2d is normally true, which means objects are in the
1460 original transform, synced with their reprs, and need to jump to the new transform in one go. A
1461 value of set_i2d==false is only used by seltrans when it's dragging objects live (not outlines); in
1462 that case, items are already in the new position, but the repr is in the old, and this function
1463 then simply updates the repr from item->transform.
1464 */
1465 void sp_selection_apply_affine(Inkscape::Selection *selection, NR::Matrix const &affine, bool set_i2d)
1466 {
1467 if (selection->isEmpty())
1468 return;
1470 for (GSList const *l = selection->itemList(); l != NULL; l = l->next) {
1471 SPItem *item = SP_ITEM(l->data);
1473 NR::Point old_center(0,0);
1474 if (set_i2d && item->isCenterSet())
1475 old_center = item->getCenter();
1477 #if 0 /* Re-enable this once persistent guides have a graphical indication.
1478 At the time of writing, this is the only place to re-enable. */
1479 sp_item_update_cns(*item, selection->desktop());
1480 #endif
1482 // we're moving both a clone and its original or any ancestor in clone chain?
1483 bool transform_clone_with_original = selection_contains_original(item, selection);
1484 // ...both a text-on-path and its path?
1485 bool transform_textpath_with_path = (SP_IS_TEXT_TEXTPATH(item) && selection->includes( sp_textpath_get_path_item (SP_TEXTPATH(sp_object_first_child(SP_OBJECT(item)))) ));
1486 // ...both a flowtext and its frame?
1487 bool transform_flowtext_with_frame = (SP_IS_FLOWTEXT(item) && selection->includes( SP_FLOWTEXT(item)->get_frame (NULL))); // (only the first frame is checked so far)
1488 // ...both an offset and its source?
1489 bool transform_offset_with_source = (SP_IS_OFFSET(item) && SP_OFFSET (item)->sourceHref) && selection->includes( sp_offset_get_source (SP_OFFSET(item)) );
1491 // If we're moving a connector, we want to detach it
1492 // from shapes that aren't part of the selection, but
1493 // leave it attached if they are
1494 if (cc_item_is_connector(item)) {
1495 SPItem *attItem[2];
1496 SP_PATH(item)->connEndPair.getAttachedItems(attItem);
1498 for (int n = 0; n < 2; ++n) {
1499 if (!selection->includes(attItem[n])) {
1500 sp_conn_end_detach(item, n);
1501 }
1502 }
1503 }
1505 // "clones are unmoved when original is moved" preference
1506 int compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
1507 bool prefs_unmoved = (compensation == SP_CLONE_COMPENSATION_UNMOVED);
1508 bool prefs_parallel = (compensation == SP_CLONE_COMPENSATION_PARALLEL);
1510 // If this is a clone and it's selected along with its original, do not move it; it will feel the
1511 // transform of its original and respond to it itself. Without this, a clone is doubly
1512 // transformed, very unintuitive.
1513 // Same for textpath if we are also doing ANY transform to its path: do not touch textpath,
1514 // letters cannot be squeezed or rotated anyway, they only refill the changed path.
1515 // Same for linked offset if we are also moving its source: do not move it.
1516 if (transform_textpath_with_path || transform_offset_with_source) {
1517 // restore item->transform field from the repr, in case it was changed by seltrans
1518 sp_object_read_attr (SP_OBJECT (item), "transform");
1520 } else if (transform_flowtext_with_frame) {
1521 // apply the inverse of the region's transform to the <use> so that the flow remains
1522 // the same (even though the output itself gets transformed)
1523 for (SPObject *region = item->firstChild() ; region ; region = SP_OBJECT_NEXT(region)) {
1524 if (!SP_IS_FLOWREGION(region) && !SP_IS_FLOWREGIONEXCLUDE(region))
1525 continue;
1526 for (SPObject *use = region->firstChild() ; use ; use = SP_OBJECT_NEXT(use)) {
1527 if (!SP_IS_USE(use)) continue;
1528 sp_item_write_transform(SP_USE(use), SP_OBJECT_REPR(use), item->transform.inverse(), NULL);
1529 }
1530 }
1531 } else if (transform_clone_with_original) {
1532 // We are transforming a clone along with its original. The below matrix juggling is
1533 // necessary to ensure that they transform as a whole, i.e. the clone's induced
1534 // transform and its move compensation are both cancelled out.
1536 // restore item->transform field from the repr, in case it was changed by seltrans
1537 sp_object_read_attr (SP_OBJECT (item), "transform");
1539 // calculate the matrix we need to apply to the clone to cancel its induced transform from its original
1540 NR::Matrix parent_transform = sp_item_i2root_affine(SP_ITEM(SP_OBJECT_PARENT (item)));
1541 NR::Matrix t = parent_transform * matrix_to_desktop (matrix_from_desktop (affine, item), item) * parent_transform.inverse();
1542 NR::Matrix t_inv =parent_transform * matrix_to_desktop (matrix_from_desktop (affine.inverse(), item), item) * parent_transform.inverse();
1543 NR::Matrix result = t_inv * item->transform * t;
1545 if ((prefs_parallel || prefs_unmoved) && affine.is_translation()) {
1546 // we need to cancel out the move compensation, too
1548 // find out the clone move, same as in sp_use_move_compensate
1549 NR::Matrix parent = sp_use_get_parent_transform (SP_USE(item));
1550 NR::Matrix clone_move = parent.inverse() * t * parent;
1552 if (prefs_parallel) {
1553 NR::Matrix move = result * clone_move * t_inv;
1554 sp_item_write_transform(item, SP_OBJECT_REPR(item), move, &move);
1556 } else if (prefs_unmoved) {
1557 //if (SP_IS_USE(sp_use_get_original(SP_USE(item))))
1558 // clone_move = NR::identity();
1559 NR::Matrix move = result * clone_move;
1560 sp_item_write_transform(item, SP_OBJECT_REPR(item), move, &t);
1561 }
1563 } else {
1564 // just apply the result
1565 sp_item_write_transform(item, SP_OBJECT_REPR(item), result, &t);
1566 }
1568 } else {
1569 if (set_i2d) {
1570 sp_item_set_i2d_affine(item, sp_item_i2d_affine(item) * affine);
1571 }
1572 sp_item_write_transform(item, SP_OBJECT_REPR(item), item->transform, NULL);
1573 }
1575 // if we're moving the actual object, not just updating the repr, we can transform the
1576 // center by the same matrix (only necessary for non-translations)
1577 if (set_i2d && item->isCenterSet() && !affine.is_translation()) {
1578 item->setCenter(old_center * affine);
1579 SP_OBJECT(item)->updateRepr();
1580 }
1581 }
1582 }
1584 void sp_selection_remove_transform()
1585 {
1586 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1587 if (desktop == NULL)
1588 return;
1590 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1592 GSList const *l = (GSList *) selection->reprList();
1593 while (l != NULL) {
1594 sp_repr_set_attr((Inkscape::XML::Node*)l->data, "transform", NULL);
1595 l = l->next;
1596 }
1598 sp_document_done(sp_desktop_document(desktop), SP_VERB_OBJECT_FLATTEN,
1599 _("Remove transform"));
1600 }
1602 void
1603 sp_selection_scale_absolute(Inkscape::Selection *selection,
1604 double const x0, double const x1,
1605 double const y0, double const y1)
1606 {
1607 if (selection->isEmpty())
1608 return;
1610 NR::Maybe<NR::Rect> const bbox(selection->bounds());
1611 if ( !bbox || bbox->isEmpty() ) {
1612 return;
1613 }
1615 NR::translate const p2o(-bbox->min());
1617 NR::scale const newSize(x1 - x0,
1618 y1 - y0);
1619 NR::scale const scale( newSize / NR::scale(bbox->dimensions()) );
1620 NR::translate const o2n(x0, y0);
1621 NR::Matrix const final( p2o * scale * o2n );
1623 sp_selection_apply_affine(selection, final);
1624 }
1627 void sp_selection_scale_relative(Inkscape::Selection *selection, NR::Point const &align, NR::scale const &scale)
1628 {
1629 if (selection->isEmpty())
1630 return;
1632 NR::Maybe<NR::Rect> const bbox(selection->bounds());
1634 if ( !bbox || bbox->isEmpty() ) {
1635 return;
1636 }
1638 // FIXME: ARBITRARY LIMIT: don't try to scale above 1 Mpx, it won't display properly and will crash sooner or later anyway
1639 if ( bbox->extent(NR::X) * scale[NR::X] > 1e6 ||
1640 bbox->extent(NR::Y) * scale[NR::Y] > 1e6 )
1641 {
1642 return;
1643 }
1645 NR::translate const n2d(-align);
1646 NR::translate const d2n(align);
1647 NR::Matrix const final( n2d * scale * d2n );
1648 sp_selection_apply_affine(selection, final);
1649 }
1651 void
1652 sp_selection_rotate_relative(Inkscape::Selection *selection, NR::Point const ¢er, gdouble const angle_degrees)
1653 {
1654 NR::translate const d2n(center);
1655 NR::translate const n2d(-center);
1656 NR::rotate const rotate(rotate_degrees(angle_degrees));
1657 NR::Matrix const final( NR::Matrix(n2d) * rotate * d2n );
1658 sp_selection_apply_affine(selection, final);
1659 }
1661 void
1662 sp_selection_skew_relative(Inkscape::Selection *selection, NR::Point const &align, double dx, double dy)
1663 {
1664 NR::translate const d2n(align);
1665 NR::translate const n2d(-align);
1666 NR::Matrix const skew(1, dy,
1667 dx, 1,
1668 0, 0);
1669 NR::Matrix const final( n2d * skew * d2n );
1670 sp_selection_apply_affine(selection, final);
1671 }
1673 void sp_selection_move_relative(Inkscape::Selection *selection, NR::Point const &move)
1674 {
1675 sp_selection_apply_affine(selection, NR::Matrix(NR::translate(move)));
1676 }
1678 void sp_selection_move_relative(Inkscape::Selection *selection, double dx, double dy)
1679 {
1680 sp_selection_apply_affine(selection, NR::Matrix(NR::translate(dx, dy)));
1681 }
1684 /**
1685 * \brief sp_selection_rotate_90
1686 *
1687 * This function rotates selected objects 90 degrees clockwise.
1688 *
1689 */
1691 void sp_selection_rotate_90_cw()
1692 {
1693 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1695 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1697 if (selection->isEmpty())
1698 return;
1700 GSList const *l = selection->itemList();
1701 NR::rotate const rot_neg_90(NR::Point(0, -1));
1702 for (GSList const *l2 = l ; l2 != NULL ; l2 = l2->next) {
1703 SPItem *item = SP_ITEM(l2->data);
1704 sp_item_rotate_rel(item, rot_neg_90);
1705 }
1707 sp_document_done(sp_desktop_document(desktop), SP_VERB_OBJECT_ROTATE_90_CCW,
1708 _("Rotate 90° CW"));
1709 }
1712 /**
1713 * \brief sp_selection_rotate_90_ccw
1714 *
1715 * This function rotates selected objects 90 degrees counter-clockwise.
1716 *
1717 */
1719 void sp_selection_rotate_90_ccw()
1720 {
1721 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1723 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1725 if (selection->isEmpty())
1726 return;
1728 GSList const *l = selection->itemList();
1729 NR::rotate const rot_neg_90(NR::Point(0, 1));
1730 for (GSList const *l2 = l ; l2 != NULL ; l2 = l2->next) {
1731 SPItem *item = SP_ITEM(l2->data);
1732 sp_item_rotate_rel(item, rot_neg_90);
1733 }
1735 sp_document_done(sp_desktop_document(desktop), SP_VERB_OBJECT_ROTATE_90_CW,
1736 _("Rotate 90° CCW"));
1737 }
1739 void
1740 sp_selection_rotate(Inkscape::Selection *selection, gdouble const angle_degrees)
1741 {
1742 if (selection->isEmpty())
1743 return;
1745 NR::Maybe<NR::Point> center = selection->center();
1746 if (!center) {
1747 return;
1748 }
1750 sp_selection_rotate_relative(selection, *center, angle_degrees);
1752 sp_document_maybe_done(sp_desktop_document(selection->desktop()),
1753 ( ( angle_degrees > 0 )
1754 ? "selector:rotate:ccw"
1755 : "selector:rotate:cw" ),
1756 SP_VERB_CONTEXT_SELECT,
1757 _("Rotate"));
1758 }
1760 /**
1761 \param angle the angle in "angular pixels", i.e. how many visible pixels must move the outermost point of the rotated object
1762 */
1763 void
1764 sp_selection_rotate_screen(Inkscape::Selection *selection, gdouble angle)
1765 {
1766 if (selection->isEmpty())
1767 return;
1769 NR::Maybe<NR::Rect> const bbox(selection->bounds());
1770 NR::Maybe<NR::Point> center = selection->center();
1772 if ( !bbox || !center ) {
1773 return;
1774 }
1776 gdouble const zoom = selection->desktop()->current_zoom();
1777 gdouble const zmove = angle / zoom;
1778 gdouble const r = NR::L2(bbox->cornerFarthestFrom(*center) - *center);
1780 gdouble const zangle = 180 * atan2(zmove, r) / M_PI;
1782 sp_selection_rotate_relative(selection, *center, zangle);
1784 sp_document_maybe_done(sp_desktop_document(selection->desktop()),
1785 ( (angle > 0)
1786 ? "selector:rotate:ccw"
1787 : "selector:rotate:cw" ),
1788 SP_VERB_CONTEXT_SELECT,
1789 _("Rotate by pixels"));
1790 }
1792 void
1793 sp_selection_scale(Inkscape::Selection *selection, gdouble grow)
1794 {
1795 if (selection->isEmpty())
1796 return;
1798 NR::Maybe<NR::Rect> const bbox(selection->bounds());
1799 if (!bbox) {
1800 return;
1801 }
1803 NR::Point const center(bbox->midpoint());
1805 // you can't scale "do nizhe pola" (below zero)
1806 double const max_len = bbox->maxExtent();
1807 if ( max_len + grow <= 1e-3 ) {
1808 return;
1809 }
1811 double const times = 1.0 + grow / max_len;
1812 sp_selection_scale_relative(selection, center, NR::scale(times, times));
1814 sp_document_maybe_done(sp_desktop_document(selection->desktop()),
1815 ( (grow > 0)
1816 ? "selector:scale:larger"
1817 : "selector:scale:smaller" ),
1818 SP_VERB_CONTEXT_SELECT,
1819 _("Scale"));
1820 }
1822 void
1823 sp_selection_scale_screen(Inkscape::Selection *selection, gdouble grow_pixels)
1824 {
1825 sp_selection_scale(selection,
1826 grow_pixels / selection->desktop()->current_zoom());
1827 }
1829 void
1830 sp_selection_scale_times(Inkscape::Selection *selection, gdouble times)
1831 {
1832 if (selection->isEmpty())
1833 return;
1835 NR::Maybe<NR::Rect> sel_bbox = selection->bounds();
1837 if (!sel_bbox) {
1838 return;
1839 }
1841 NR::Point const center(sel_bbox->midpoint());
1842 sp_selection_scale_relative(selection, center, NR::scale(times, times));
1843 sp_document_done(sp_desktop_document(selection->desktop()), SP_VERB_CONTEXT_SELECT,
1844 _("Scale by whole factor"));
1845 }
1847 void
1848 sp_selection_move(gdouble dx, gdouble dy)
1849 {
1850 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1851 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1852 if (selection->isEmpty()) {
1853 return;
1854 }
1856 sp_selection_move_relative(selection, dx, dy);
1858 if (dx == 0) {
1859 sp_document_maybe_done(sp_desktop_document(desktop), "selector:move:vertical", SP_VERB_CONTEXT_SELECT,
1860 _("Move vertically"));
1861 } else if (dy == 0) {
1862 sp_document_maybe_done(sp_desktop_document(desktop), "selector:move:horizontal", SP_VERB_CONTEXT_SELECT,
1863 _("Move horizontally"));
1864 } else {
1865 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_SELECT,
1866 _("Move"));
1867 }
1868 }
1870 void
1871 sp_selection_move_screen(gdouble dx, gdouble dy)
1872 {
1873 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1875 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1876 if (selection->isEmpty()) {
1877 return;
1878 }
1880 // same as sp_selection_move but divide deltas by zoom factor
1881 gdouble const zoom = desktop->current_zoom();
1882 gdouble const zdx = dx / zoom;
1883 gdouble const zdy = dy / zoom;
1884 sp_selection_move_relative(selection, zdx, zdy);
1886 if (dx == 0) {
1887 sp_document_maybe_done(sp_desktop_document(desktop), "selector:move:vertical", SP_VERB_CONTEXT_SELECT,
1888 _("Move vertically by pixels"));
1889 } else if (dy == 0) {
1890 sp_document_maybe_done(sp_desktop_document(desktop), "selector:move:horizontal", SP_VERB_CONTEXT_SELECT,
1891 _("Move horizontally by pixels"));
1892 } else {
1893 sp_document_done(sp_desktop_document(desktop), SP_VERB_CONTEXT_SELECT,
1894 _("Move"));
1895 }
1896 }
1898 namespace {
1900 template <typename D>
1901 SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root,
1902 bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive);
1904 template <typename D>
1905 SPItem *next_item_from_list(SPDesktop *desktop, GSList const *items, SPObject *root,
1906 bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive);
1908 struct Forward {
1909 typedef SPObject *Iterator;
1911 static Iterator children(SPObject *o) { return sp_object_first_child(o); }
1912 static Iterator siblings_after(SPObject *o) { return SP_OBJECT_NEXT(o); }
1913 static void dispose(Iterator i) {}
1915 static SPObject *object(Iterator i) { return i; }
1916 static Iterator next(Iterator i) { return SP_OBJECT_NEXT(i); }
1917 };
1919 struct Reverse {
1920 typedef GSList *Iterator;
1922 static Iterator children(SPObject *o) {
1923 return make_list(o->firstChild(), NULL);
1924 }
1925 static Iterator siblings_after(SPObject *o) {
1926 return make_list(SP_OBJECT_PARENT(o)->firstChild(), o);
1927 }
1928 static void dispose(Iterator i) {
1929 g_slist_free(i);
1930 }
1932 static SPObject *object(Iterator i) {
1933 return reinterpret_cast<SPObject *>(i->data);
1934 }
1935 static Iterator next(Iterator i) { return i->next; }
1937 private:
1938 static GSList *make_list(SPObject *object, SPObject *limit) {
1939 GSList *list=NULL;
1940 while ( object != limit ) {
1941 list = g_slist_prepend(list, object);
1942 object = SP_OBJECT_NEXT(object);
1943 }
1944 return list;
1945 }
1946 };
1948 }
1950 void
1951 sp_selection_item_next(void)
1952 {
1953 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1954 g_return_if_fail(desktop != NULL);
1955 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1957 PrefsSelectionContext inlayer = (PrefsSelectionContext)prefs_get_int_attribute ("options.kbselection", "inlayer", PREFS_SELECTION_LAYER);
1958 bool onlyvisible = prefs_get_int_attribute ("options.kbselection", "onlyvisible", 1);
1959 bool onlysensitive = prefs_get_int_attribute ("options.kbselection", "onlysensitive", 1);
1961 SPObject *root;
1962 if (PREFS_SELECTION_ALL != inlayer) {
1963 root = selection->activeContext();
1964 } else {
1965 root = desktop->currentRoot();
1966 }
1968 SPItem *item=next_item_from_list<Forward>(desktop, selection->itemList(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive);
1970 if (item) {
1971 selection->set(item, PREFS_SELECTION_LAYER_RECURSIVE == inlayer);
1972 if ( SP_CYCLING == SP_CYCLE_FOCUS ) {
1973 scroll_to_show_item(desktop, item);
1974 }
1975 }
1976 }
1978 void
1979 sp_selection_item_prev(void)
1980 {
1981 SPDocument *document = SP_ACTIVE_DOCUMENT;
1982 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
1983 g_return_if_fail(document != NULL);
1984 g_return_if_fail(desktop != NULL);
1985 Inkscape::Selection *selection = sp_desktop_selection(desktop);
1987 PrefsSelectionContext inlayer = (PrefsSelectionContext)prefs_get_int_attribute ("options.kbselection", "inlayer", PREFS_SELECTION_LAYER);
1988 bool onlyvisible = prefs_get_int_attribute ("options.kbselection", "onlyvisible", 1);
1989 bool onlysensitive = prefs_get_int_attribute ("options.kbselection", "onlysensitive", 1);
1991 SPObject *root;
1992 if (PREFS_SELECTION_ALL != inlayer) {
1993 root = selection->activeContext();
1994 } else {
1995 root = desktop->currentRoot();
1996 }
1998 SPItem *item=next_item_from_list<Reverse>(desktop, selection->itemList(), root, SP_CYCLING == SP_CYCLE_VISIBLE, inlayer, onlyvisible, onlysensitive);
2000 if (item) {
2001 selection->set(item, PREFS_SELECTION_LAYER_RECURSIVE == inlayer);
2002 if ( SP_CYCLING == SP_CYCLE_FOCUS ) {
2003 scroll_to_show_item(desktop, item);
2004 }
2005 }
2006 }
2008 namespace {
2010 template <typename D>
2011 SPItem *next_item_from_list(SPDesktop *desktop, GSList const *items,
2012 SPObject *root, bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive)
2013 {
2014 SPObject *current=root;
2015 while (items) {
2016 SPItem *item=SP_ITEM(items->data);
2017 if ( root->isAncestorOf(item) &&
2018 ( !only_in_viewport || desktop->isWithinViewport(item) ) )
2019 {
2020 current = item;
2021 break;
2022 }
2023 items = items->next;
2024 }
2026 GSList *path=NULL;
2027 while ( current != root ) {
2028 path = g_slist_prepend(path, current);
2029 current = SP_OBJECT_PARENT(current);
2030 }
2032 SPItem *next;
2033 // first, try from the current object
2034 next = next_item<D>(desktop, path, root, only_in_viewport, inlayer, onlyvisible, onlysensitive);
2035 g_slist_free(path);
2037 if (!next) { // if we ran out of objects, start over at the root
2038 next = next_item<D>(desktop, NULL, root, only_in_viewport, inlayer, onlyvisible, onlysensitive);
2039 }
2041 return next;
2042 }
2044 template <typename D>
2045 SPItem *next_item(SPDesktop *desktop, GSList *path, SPObject *root,
2046 bool only_in_viewport, PrefsSelectionContext inlayer, bool onlyvisible, bool onlysensitive)
2047 {
2048 typename D::Iterator children;
2049 typename D::Iterator iter;
2051 SPItem *found=NULL;
2053 if (path) {
2054 SPObject *object=reinterpret_cast<SPObject *>(path->data);
2055 g_assert(SP_OBJECT_PARENT(object) == root);
2056 if (desktop->isLayer(object)) {
2057 found = next_item<D>(desktop, path->next, object, only_in_viewport, inlayer, onlyvisible, onlysensitive);
2058 }
2059 iter = children = D::siblings_after(object);
2060 } else {
2061 iter = children = D::children(root);
2062 }
2064 while ( iter && !found ) {
2065 SPObject *object=D::object(iter);
2066 if (desktop->isLayer(object)) {
2067 if (PREFS_SELECTION_LAYER != inlayer) { // recurse into sublayers
2068 found = next_item<D>(desktop, NULL, object, only_in_viewport, inlayer, onlyvisible, onlysensitive);
2069 }
2070 } else if ( SP_IS_ITEM(object) &&
2071 ( !only_in_viewport || desktop->isWithinViewport(SP_ITEM(object)) ) &&
2072 ( !onlyvisible || !desktop->itemIsHidden(SP_ITEM(object))) &&
2073 ( !onlysensitive || !SP_ITEM(object)->isLocked()) &&
2074 !desktop->isLayer(SP_ITEM(object)) )
2075 {
2076 found = SP_ITEM(object);
2077 }
2078 iter = D::next(iter);
2079 }
2081 D::dispose(children);
2083 return found;
2084 }
2086 }
2088 /**
2089 * If \a item is not entirely visible then adjust visible area to centre on the centre on of
2090 * \a item.
2091 */
2092 void scroll_to_show_item(SPDesktop *desktop, SPItem *item)
2093 {
2094 NR::Rect dbox = desktop->get_display_area();
2095 NR::Maybe<NR::Rect> sbox = sp_item_bbox_desktop(item);
2097 if ( sbox && dbox.contains(*sbox) == false ) {
2098 NR::Point const s_dt = sbox->midpoint();
2099 NR::Point const s_w = desktop->d2w(s_dt);
2100 NR::Point const d_dt = dbox.midpoint();
2101 NR::Point const d_w = desktop->d2w(d_dt);
2102 NR::Point const moved_w( d_w - s_w );
2103 gint const dx = (gint) moved_w[X];
2104 gint const dy = (gint) moved_w[Y];
2105 desktop->scroll_world(dx, dy);
2106 }
2107 }
2110 void
2111 sp_selection_clone()
2112 {
2113 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
2114 if (desktop == NULL)
2115 return;
2117 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2119 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
2121 // check if something is selected
2122 if (selection->isEmpty()) {
2123 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object</b> to clone."));
2124 return;
2125 }
2127 GSList *reprs = g_slist_copy((GSList *) selection->reprList());
2129 selection->clear();
2131 // sorting items from different parents sorts each parent's subset without possibly mixing them, just what we need
2132 reprs = g_slist_sort(reprs, (GCompareFunc) sp_repr_compare_position);
2134 GSList *newsel = NULL;
2136 while (reprs) {
2137 Inkscape::XML::Node *sel_repr = (Inkscape::XML::Node *) reprs->data;
2138 Inkscape::XML::Node *parent = sp_repr_parent(sel_repr);
2140 Inkscape::XML::Node *clone = xml_doc->createElement("svg:use");
2141 sp_repr_set_attr(clone, "x", "0");
2142 sp_repr_set_attr(clone, "y", "0");
2143 sp_repr_set_attr(clone, "xlink:href", g_strdup_printf("#%s", sel_repr->attribute("id")));
2145 sp_repr_set_attr(clone, "inkscape:transform-center-x", sel_repr->attribute("inkscape:transform-center-x"));
2146 sp_repr_set_attr(clone, "inkscape:transform-center-y", sel_repr->attribute("inkscape:transform-center-y"));
2148 // add the new clone to the top of the original's parent
2149 parent->appendChild(clone);
2151 newsel = g_slist_prepend(newsel, clone);
2152 reprs = g_slist_remove(reprs, sel_repr);
2153 Inkscape::GC::release(clone);
2154 }
2156 // TRANSLATORS: only translate "string" in "context|string".
2157 // For more details, see http://developer.gnome.org/doc/API/2.0/glib/glib-I18N.html#Q-:CAPS
2158 sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_CLONE,
2159 Q_("action|Clone"));
2161 selection->setReprList(newsel);
2163 g_slist_free(newsel);
2164 }
2166 void
2167 sp_selection_unlink()
2168 {
2169 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
2170 if (!desktop)
2171 return;
2173 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2175 if (selection->isEmpty()) {
2176 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select a <b>clone</b> to unlink."));
2177 return;
2178 }
2180 // Get a copy of current selection.
2181 GSList *new_select = NULL;
2182 bool unlinked = false;
2183 for (GSList *items = g_slist_copy((GSList *) selection->itemList());
2184 items != NULL;
2185 items = items->next)
2186 {
2187 SPItem *item = (SPItem *) items->data;
2189 if (SP_IS_TEXT(item)) {
2190 SPObject *tspan = sp_tref_convert_to_tspan(SP_OBJECT(item));
2192 if (tspan) {
2193 SP_OBJECT(item)->requestDisplayUpdate(SP_OBJECT_MODIFIED_FLAG);
2194 }
2196 // Set unlink to true, and fall into the next if which
2197 // will include this text item in the new selection
2198 unlinked = true;
2199 }
2201 if (!(SP_IS_USE(item) || SP_IS_TREF(item))) {
2202 // keep the non-use item in the new selection
2203 new_select = g_slist_prepend(new_select, item);
2204 continue;
2205 }
2207 SPItem *unlink;
2208 if (SP_IS_USE(item)) {
2209 unlink = sp_use_unlink(SP_USE(item));
2210 } else /*if (SP_IS_TREF(use))*/ {
2211 unlink = SP_ITEM(sp_tref_convert_to_tspan(SP_OBJECT(item)));
2212 }
2214 unlinked = true;
2215 // Add ungrouped items to the new selection.
2216 new_select = g_slist_prepend(new_select, unlink);
2217 }
2219 if (new_select) { // set new selection
2220 selection->clear();
2221 selection->setList(new_select);
2222 g_slist_free(new_select);
2223 }
2224 if (!unlinked) {
2225 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No clones to unlink</b> in the selection."));
2226 }
2228 sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_UNLINK_CLONE,
2229 _("Unlink clone"));
2230 }
2232 void
2233 sp_select_clone_original()
2234 {
2235 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
2236 if (desktop == NULL)
2237 return;
2239 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2241 SPItem *item = selection->singleItem();
2243 const gchar *error = _("Select a <b>clone</b> to go to its original. Select a <b>linked offset</b> to go to its source. Select a <b>text on path</b> to go to the path. Select a <b>flowed text</b> to go to its frame.");
2245 // Check if other than two objects are selected
2246 if (g_slist_length((GSList *) selection->itemList()) != 1 || !item) {
2247 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, error);
2248 return;
2249 }
2251 SPItem *original = NULL;
2252 if (SP_IS_USE(item)) {
2253 original = sp_use_get_original (SP_USE(item));
2254 } else if (SP_IS_OFFSET(item) && SP_OFFSET (item)->sourceHref) {
2255 original = sp_offset_get_source (SP_OFFSET(item));
2256 } else if (SP_IS_TEXT_TEXTPATH(item)) {
2257 original = sp_textpath_get_path_item (SP_TEXTPATH(sp_object_first_child(SP_OBJECT(item))));
2258 } else if (SP_IS_FLOWTEXT(item)) {
2259 original = SP_FLOWTEXT(item)->get_frame (NULL); // first frame only
2260 } else { // it's an object that we don't know what to do with
2261 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, error);
2262 return;
2263 }
2265 if (!original) {
2266 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>Cannot find</b> the object to select (orphaned clone, offset, textpath, flowed text?)"));
2267 return;
2268 }
2270 for (SPObject *o = original; o && !SP_IS_ROOT(o); o = SP_OBJECT_PARENT (o)) {
2271 if (SP_IS_DEFS (o)) {
2272 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("The object you're trying to select is <b>not visible</b> (it is in <defs>)"));
2273 return;
2274 }
2275 }
2277 if (original) {
2278 selection->clear();
2279 selection->set(original);
2280 if (SP_CYCLING == SP_CYCLE_FOCUS) {
2281 scroll_to_show_item(desktop, original);
2282 }
2283 }
2284 }
2287 void sp_selection_to_marker(bool apply)
2288 {
2289 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
2290 if (desktop == NULL)
2291 return;
2293 SPDocument *doc = sp_desktop_document(desktop);
2294 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
2296 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2298 // check if something is selected
2299 if (selection->isEmpty()) {
2300 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to marker."));
2301 return;
2302 }
2304 sp_document_ensure_up_to_date(doc);
2305 NR::Maybe<NR::Rect> r = selection->bounds();
2306 if ( !r || r->isEmpty() ) {
2307 return;
2308 }
2310 // calculate the transform to be applied to objects to move them to 0,0
2311 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));
2312 move_p[NR::Y] = -move_p[NR::Y];
2313 NR::Matrix move = NR::Matrix (NR::translate (move_p));
2315 GSList *items = g_slist_copy((GSList *) selection->itemList());
2317 items = g_slist_sort (items, (GCompareFunc) sp_object_compare_position);
2319 // bottommost object, after sorting
2320 SPObject *parent = SP_OBJECT_PARENT (items->data);
2322 NR::Matrix parent_transform = sp_item_i2root_affine(SP_ITEM(parent));
2324 // remember the position of the first item
2325 gint pos = SP_OBJECT_REPR (items->data)->position();
2327 // create a list of duplicates
2328 GSList *repr_copies = NULL;
2329 for (GSList *i = items; i != NULL; i = i->next) {
2330 Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(xml_doc);
2331 repr_copies = g_slist_prepend (repr_copies, dup);
2332 }
2334 NR::Rect bounds(desktop->dt2doc(r->min()), desktop->dt2doc(r->max()));
2336 if (apply) {
2337 // delete objects so that their clones don't get alerted; this object will be restored shortly
2338 for (GSList *i = items; i != NULL; i = i->next) {
2339 SPObject *item = SP_OBJECT (i->data);
2340 item->deleteObject (false);
2341 }
2342 }
2344 // Hack: Temporarily set clone compensation to unmoved, so that we can move clone-originals
2345 // without disturbing clones.
2346 // See ActorAlign::on_button_click() in src/ui/dialog/align-and-distribute.cpp
2347 int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
2348 prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
2350 const gchar *mark_id = generate_marker (repr_copies, bounds, doc,
2351 NR::Matrix(NR::translate(desktop->dt2doc(NR::Point(r->min()[NR::X], r->max()[NR::Y])))) * parent_transform.inverse(), parent_transform * move);
2353 // restore compensation setting
2354 prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
2357 g_slist_free (items);
2359 sp_document_done (doc, SP_VERB_EDIT_SELECTION_2_MARKER,
2360 _("Objects to marker"));
2361 }
2363 void
2364 sp_selection_tile(bool apply)
2365 {
2366 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
2367 if (desktop == NULL)
2368 return;
2370 SPDocument *doc = sp_desktop_document(desktop);
2371 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
2373 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2375 // check if something is selected
2376 if (selection->isEmpty()) {
2377 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to convert to pattern."));
2378 return;
2379 }
2381 sp_document_ensure_up_to_date(doc);
2382 NR::Maybe<NR::Rect> r = selection->bounds();
2383 if ( !r || r->isEmpty() ) {
2384 return;
2385 }
2387 // calculate the transform to be applied to objects to move them to 0,0
2388 NR::Point move_p = NR::Point(0, sp_document_height(doc)) - (r->min() + NR::Point (0, r->extent(NR::Y)));
2389 move_p[NR::Y] = -move_p[NR::Y];
2390 NR::Matrix move = NR::Matrix (NR::translate (move_p));
2392 GSList *items = g_slist_copy((GSList *) selection->itemList());
2394 items = g_slist_sort (items, (GCompareFunc) sp_object_compare_position);
2396 // bottommost object, after sorting
2397 SPObject *parent = SP_OBJECT_PARENT (items->data);
2399 NR::Matrix parent_transform = sp_item_i2root_affine(SP_ITEM(parent));
2401 // remember the position of the first item
2402 gint pos = SP_OBJECT_REPR (items->data)->position();
2404 // create a list of duplicates
2405 GSList *repr_copies = NULL;
2406 for (GSList *i = items; i != NULL; i = i->next) {
2407 Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(xml_doc);
2408 repr_copies = g_slist_prepend (repr_copies, dup);
2409 }
2411 NR::Rect bounds(desktop->dt2doc(r->min()), desktop->dt2doc(r->max()));
2413 if (apply) {
2414 // delete objects so that their clones don't get alerted; this object will be restored shortly
2415 for (GSList *i = items; i != NULL; i = i->next) {
2416 SPObject *item = SP_OBJECT (i->data);
2417 item->deleteObject (false);
2418 }
2419 }
2421 // Hack: Temporarily set clone compensation to unmoved, so that we can move clone-originals
2422 // without disturbing clones.
2423 // See ActorAlign::on_button_click() in src/ui/dialog/align-and-distribute.cpp
2424 int saved_compensation = prefs_get_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
2425 prefs_set_int_attribute("options.clonecompensation", "value", SP_CLONE_COMPENSATION_UNMOVED);
2427 const gchar *pat_id = pattern_tile (repr_copies, bounds, doc,
2428 NR::Matrix(NR::translate(desktop->dt2doc(NR::Point(r->min()[NR::X], r->max()[NR::Y])))) * parent_transform.inverse(), parent_transform * move);
2430 // restore compensation setting
2431 prefs_set_int_attribute("options.clonecompensation", "value", saved_compensation);
2433 if (apply) {
2434 Inkscape::XML::Node *rect = xml_doc->createElement("svg:rect");
2435 rect->setAttribute("style", g_strdup_printf("stroke:none;fill:url(#%s)", pat_id));
2437 NR::Point min = bounds.min() * parent_transform.inverse();
2438 NR::Point max = bounds.max() * parent_transform.inverse();
2440 sp_repr_set_svg_double(rect, "width", max[NR::X] - min[NR::X]);
2441 sp_repr_set_svg_double(rect, "height", max[NR::Y] - min[NR::Y]);
2442 sp_repr_set_svg_double(rect, "x", min[NR::X]);
2443 sp_repr_set_svg_double(rect, "y", min[NR::Y]);
2445 // restore parent and position
2446 SP_OBJECT_REPR (parent)->appendChild(rect);
2447 rect->setPosition(pos > 0 ? pos : 0);
2448 SPItem *rectangle = (SPItem *) sp_desktop_document (desktop)->getObjectByRepr(rect);
2450 Inkscape::GC::release(rect);
2452 selection->clear();
2453 selection->set(rectangle);
2454 }
2456 g_slist_free (items);
2458 sp_document_done (doc, SP_VERB_EDIT_TILE,
2459 _("Objects to pattern"));
2460 }
2462 void
2463 sp_selection_untile()
2464 {
2465 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
2466 if (desktop == NULL)
2467 return;
2469 SPDocument *doc = sp_desktop_document(desktop);
2470 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
2472 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2474 // check if something is selected
2475 if (selection->isEmpty()) {
2476 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select an <b>object with pattern fill</b> to extract objects from."));
2477 return;
2478 }
2480 GSList *new_select = NULL;
2482 bool did = false;
2484 for (GSList *items = g_slist_copy((GSList *) selection->itemList());
2485 items != NULL;
2486 items = items->next) {
2488 SPItem *item = (SPItem *) items->data;
2490 SPStyle *style = SP_OBJECT_STYLE (item);
2492 if (!style || !style->fill.isPaintserver())
2493 continue;
2495 SPObject *server = SP_OBJECT_STYLE_FILL_SERVER(item);
2497 if (!SP_IS_PATTERN(server))
2498 continue;
2500 did = true;
2502 SPPattern *pattern = pattern_getroot (SP_PATTERN (server));
2504 NR::Matrix pat_transform = pattern_patternTransform (SP_PATTERN (server));
2505 pat_transform *= item->transform;
2507 for (SPObject *child = sp_object_first_child(SP_OBJECT(pattern)) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
2508 Inkscape::XML::Node *copy = SP_OBJECT_REPR(child)->duplicate(xml_doc);
2509 SPItem *i = SP_ITEM (desktop->currentLayer()->appendChildRepr(copy));
2511 // FIXME: relink clones to the new canvas objects
2512 // use SPObject::setid when mental finishes it to steal ids of
2514 // this is needed to make sure the new item has curve (simply requestDisplayUpdate does not work)
2515 sp_document_ensure_up_to_date (doc);
2517 NR::Matrix transform( i->transform * pat_transform );
2518 sp_item_write_transform(i, SP_OBJECT_REPR(i), transform);
2520 new_select = g_slist_prepend(new_select, i);
2521 }
2523 SPCSSAttr *css = sp_repr_css_attr_new ();
2524 sp_repr_css_set_property (css, "fill", "none");
2525 sp_repr_css_change (SP_OBJECT_REPR (item), css, "style");
2526 }
2528 if (!did) {
2529 desktop->messageStack()->flash(Inkscape::ERROR_MESSAGE, _("<b>No pattern fills</b> in the selection."));
2530 } else {
2531 sp_document_done(sp_desktop_document(desktop), SP_VERB_EDIT_UNTILE,
2532 _("Pattern to objects"));
2533 selection->setList(new_select);
2534 }
2535 }
2537 void
2538 sp_selection_get_export_hints (Inkscape::Selection *selection, const char **filename, float *xdpi, float *ydpi)
2539 {
2540 if (selection->isEmpty()) {
2541 return;
2542 }
2544 const GSList * reprlst = selection->reprList();
2545 bool filename_search = TRUE;
2546 bool xdpi_search = TRUE;
2547 bool ydpi_search = TRUE;
2549 for(; reprlst != NULL &&
2550 filename_search &&
2551 xdpi_search &&
2552 ydpi_search;
2553 reprlst = reprlst->next) {
2554 const gchar * dpi_string;
2555 Inkscape::XML::Node * repr = (Inkscape::XML::Node *)reprlst->data;
2557 if (filename_search) {
2558 *filename = repr->attribute("inkscape:export-filename");
2559 if (*filename != NULL)
2560 filename_search = FALSE;
2561 }
2563 if (xdpi_search) {
2564 dpi_string = NULL;
2565 dpi_string = repr->attribute("inkscape:export-xdpi");
2566 if (dpi_string != NULL) {
2567 *xdpi = atof(dpi_string);
2568 xdpi_search = FALSE;
2569 }
2570 }
2572 if (ydpi_search) {
2573 dpi_string = NULL;
2574 dpi_string = repr->attribute("inkscape:export-ydpi");
2575 if (dpi_string != NULL) {
2576 *ydpi = atof(dpi_string);
2577 ydpi_search = FALSE;
2578 }
2579 }
2580 }
2581 }
2583 void
2584 sp_document_get_export_hints (SPDocument * doc, const char **filename, float *xdpi, float *ydpi)
2585 {
2586 Inkscape::XML::Node * repr = sp_document_repr_root(doc);
2587 const gchar * dpi_string;
2589 *filename = repr->attribute("inkscape:export-filename");
2591 dpi_string = NULL;
2592 dpi_string = repr->attribute("inkscape:export-xdpi");
2593 if (dpi_string != NULL) {
2594 *xdpi = atof(dpi_string);
2595 }
2597 dpi_string = NULL;
2598 dpi_string = repr->attribute("inkscape:export-ydpi");
2599 if (dpi_string != NULL) {
2600 *ydpi = atof(dpi_string);
2601 }
2602 }
2604 void
2605 sp_selection_create_bitmap_copy ()
2606 {
2607 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
2608 if (desktop == NULL)
2609 return;
2611 SPDocument *document = sp_desktop_document(desktop);
2612 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(document);
2614 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2616 // check if something is selected
2617 if (selection->isEmpty()) {
2618 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to make a bitmap copy."));
2619 return;
2620 }
2622 // Get the bounding box of the selection
2623 NRRect bbox;
2624 sp_document_ensure_up_to_date (document);
2625 selection->bounds(&bbox);
2626 if (NR_RECT_DFLS_TEST_EMPTY(&bbox)) {
2627 return; // exceptional situation, so not bother with a translatable error message, just quit quietly
2628 }
2630 // List of the items to show; all others will be hidden
2631 GSList *items = g_slist_copy ((GSList *) selection->itemList());
2633 // Sort items so that the topmost comes last
2634 items = g_slist_sort(items, (GCompareFunc) sp_item_repr_compare_position);
2636 // Generate a random value from the current time (you may create bitmap from the same object(s)
2637 // multiple times, and this is done so that they don't clash)
2638 GTimeVal cu;
2639 g_get_current_time (&cu);
2640 guint current = (int) (cu.tv_sec * 1000000 + cu.tv_usec) % 1024;
2642 // Create the filename
2643 gchar *filename = g_strdup_printf ("%s-%s-%u.png", document->name, SP_OBJECT_REPR(items->data)->attribute("id"), current);
2644 // Imagemagick is known not to handle spaces in filenames, so we replace anything but letters,
2645 // digits, and a few other chars, with "_"
2646 filename = g_strcanon (filename, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.=+~$#@^&!?", '_');
2647 // Build the complete path by adding document->base if set
2648 gchar *filepath = g_build_filename (document->base?document->base:"", filename, NULL);
2650 //g_print ("%s\n", filepath);
2652 // Remember parent and z-order of the topmost one
2653 gint pos = SP_OBJECT_REPR(g_slist_last(items)->data)->position();
2654 SPObject *parent_object = SP_OBJECT_PARENT(g_slist_last(items)->data);
2655 Inkscape::XML::Node *parent = SP_OBJECT_REPR(parent_object);
2657 // Calculate resolution
2658 double res;
2659 int const prefs_res = prefs_get_int_attribute ("options.createbitmap", "resolution", 0);
2660 int const prefs_min = prefs_get_int_attribute ("options.createbitmap", "minsize", 0);
2661 if (0 < prefs_res) {
2662 // If it's given explicitly in prefs, take it
2663 res = prefs_res;
2664 } else if (0 < prefs_min) {
2665 // If minsize is given, look up minimum bitmap size (default 250 pixels) and calculate resolution from it
2666 res = PX_PER_IN * prefs_min / MIN ((bbox.x1 - bbox.x0), (bbox.y1 - bbox.y0));
2667 } else {
2668 float hint_xdpi = 0, hint_ydpi = 0;
2669 const char *hint_filename;
2670 // take resolution hint from the selected objects
2671 sp_selection_get_export_hints (selection, &hint_filename, &hint_xdpi, &hint_ydpi);
2672 if (hint_xdpi != 0) {
2673 res = hint_xdpi;
2674 } else {
2675 // take resolution hint from the document
2676 sp_document_get_export_hints (document, &hint_filename, &hint_xdpi, &hint_ydpi);
2677 if (hint_xdpi != 0) {
2678 res = hint_xdpi;
2679 } else {
2680 // if all else fails, take the default 90 dpi
2681 res = PX_PER_IN;
2682 }
2683 }
2684 }
2686 // The width and height of the bitmap in pixels
2687 unsigned width = (unsigned) floor ((bbox.x1 - bbox.x0) * res / PX_PER_IN);
2688 unsigned height =(unsigned) floor ((bbox.y1 - bbox.y0) * res / PX_PER_IN);
2690 // Find out if we have to run a filter
2691 const gchar *run = NULL;
2692 const gchar *filter = prefs_get_string_attribute ("options.createbitmap", "filter");
2693 if (filter) {
2694 // filter command is given;
2695 // see if we have a parameter to pass to it
2696 const gchar *param1 = prefs_get_string_attribute ("options.createbitmap", "filter_param1");
2697 if (param1) {
2698 if (param1[strlen(param1) - 1] == '%') {
2699 // if the param string ends with %, interpret it as a percentage of the image's max dimension
2700 gchar p1[256];
2701 g_ascii_dtostr (p1, 256, ceil (g_ascii_strtod (param1, NULL) * MAX(width, height) / 100));
2702 // the first param is always the image filename, the second is param1
2703 run = g_strdup_printf ("%s \"%s\" %s", filter, filepath, p1);
2704 } else {
2705 // otherwise pass the param1 unchanged
2706 run = g_strdup_printf ("%s \"%s\" %s", filter, filepath, param1);
2707 }
2708 } else {
2709 // run without extra parameter
2710 run = g_strdup_printf ("%s \"%s\"", filter, filepath);
2711 }
2712 }
2714 // Calculate the matrix that will be applied to the image so that it exactly overlaps the source objects
2715 NR::Matrix eek = sp_item_i2d_affine (SP_ITEM(parent_object));
2716 NR::Matrix t;
2718 double shift_x = bbox.x0;
2719 double shift_y = bbox.y1;
2720 if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid
2721 shift_x = round (shift_x);
2722 shift_y = -round (-shift_y); // this gets correct rounding despite coordinate inversion, remove the negations when the inversion is gone
2723 }
2724 t = NR::scale(1, -1) * NR::translate (shift_x, shift_y) * eek.inverse();
2726 // Do the export
2727 sp_export_png_file(document, filepath,
2728 bbox.x0, bbox.y0, bbox.x1, bbox.y1,
2729 width, height, res, res,
2730 (guint32) 0xffffff00,
2731 NULL, NULL,
2732 true, /*bool force_overwrite,*/
2733 items);
2735 g_slist_free (items);
2737 // Run filter, if any
2738 if (run) {
2739 g_print ("Running external filter: %s\n", run);
2740 system (run);
2741 }
2743 // Import the image back
2744 GdkPixbuf *pb = gdk_pixbuf_new_from_file (filepath, NULL);
2745 if (pb) {
2746 // Create the repr for the image
2747 Inkscape::XML::Node * repr = xml_doc->createElement("svg:image");
2748 repr->setAttribute("xlink:href", filename);
2749 repr->setAttribute("sodipodi:absref", filepath);
2750 if (res == PX_PER_IN) { // for default 90 dpi, snap it to pixel grid
2751 sp_repr_set_svg_double(repr, "width", width);
2752 sp_repr_set_svg_double(repr, "height", height);
2753 } else {
2754 sp_repr_set_svg_double(repr, "width", (bbox.x1 - bbox.x0));
2755 sp_repr_set_svg_double(repr, "height", (bbox.y1 - bbox.y0));
2756 }
2758 // Write transform
2759 gchar *c=sp_svg_transform_write(t);
2760 repr->setAttribute("transform", c);
2761 g_free(c);
2763 // add the new repr to the parent
2764 parent->appendChild(repr);
2766 // move to the saved position
2767 repr->setPosition(pos > 0 ? pos + 1 : 1);
2769 // Set selection to the new image
2770 selection->clear();
2771 selection->add(repr);
2773 // Clean up
2774 Inkscape::GC::release(repr);
2775 gdk_pixbuf_unref (pb);
2777 // Complete undoable transaction
2778 sp_document_done (document, SP_VERB_SELECTION_CREATE_BITMAP,
2779 _("Create bitmap"));
2780 }
2782 g_free (filename);
2783 g_free (filepath);
2784 }
2786 /**
2787 * \brief sp_selection_set_mask
2788 *
2789 * This function creates a mask or clipPath from selection
2790 * Two different modes:
2791 * if applyToLayer, all selection is moved to DEFS as mask/clippath
2792 * and is applied to current layer
2793 * otherwise, topmost object is used as mask for other objects
2794 * If \a apply_clip_path parameter is true, clipPath is created, otherwise mask
2795 *
2796 */
2797 void
2798 sp_selection_set_mask(bool apply_clip_path, bool apply_to_layer)
2799 {
2800 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
2801 if (desktop == NULL)
2802 return;
2804 SPDocument *doc = sp_desktop_document(desktop);
2805 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
2807 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2809 // check if something is selected
2810 bool is_empty = selection->isEmpty();
2811 if ( apply_to_layer && is_empty) {
2812 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to create clippath or mask from."));
2813 return;
2814 } else if (!apply_to_layer && ( is_empty || NULL == selection->itemList()->next )) {
2815 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select mask object and <b>object(s)</b> to apply clippath or mask to."));
2816 return;
2817 }
2819 // FIXME: temporary patch to prevent crash!
2820 // Remove this when bboxes are fixed to not blow up on an item clipped/masked with its own clone
2821 bool clone_with_original = selection_contains_both_clone_and_original (selection);
2822 if (clone_with_original) {
2823 return; // in this version, you cannot clip/mask an object with its own clone
2824 }
2825 // /END FIXME
2827 sp_document_ensure_up_to_date(doc);
2829 GSList *items = g_slist_copy((GSList *) selection->itemList());
2831 items = g_slist_sort (items, (GCompareFunc) sp_object_compare_position);
2833 // create a list of duplicates
2834 GSList *mask_items = NULL;
2835 GSList *apply_to_items = NULL;
2836 GSList *items_to_delete = NULL;
2837 bool topmost = prefs_get_int_attribute ("options.maskobject", "topmost", 1);
2838 bool remove_original = prefs_get_int_attribute ("options.maskobject", "remove", 1);
2840 if (apply_to_layer) {
2841 // all selected items are used for mask, which is applied to a layer
2842 apply_to_items = g_slist_prepend (apply_to_items, desktop->currentLayer());
2844 for (GSList *i = items; i != NULL; i = i->next) {
2845 Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(xml_doc);
2846 mask_items = g_slist_prepend (mask_items, dup);
2848 if (remove_original) {
2849 SPObject *item = SP_OBJECT (i->data);
2850 items_to_delete = g_slist_prepend (items_to_delete, item);
2851 }
2852 }
2853 } else if (!topmost) {
2854 // topmost item is used as a mask, which is applied to other items in a selection
2855 GSList *i = items;
2856 Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(xml_doc);
2857 mask_items = g_slist_prepend (mask_items, dup);
2859 if (remove_original) {
2860 SPObject *item = SP_OBJECT (i->data);
2861 items_to_delete = g_slist_prepend (items_to_delete, item);
2862 }
2864 for (i = i->next; i != NULL; i = i->next) {
2865 apply_to_items = g_slist_prepend (apply_to_items, i->data);
2866 }
2867 } else {
2868 GSList *i = NULL;
2869 for (i = items; NULL != i->next; i = i->next) {
2870 apply_to_items = g_slist_prepend (apply_to_items, i->data);
2871 }
2873 Inkscape::XML::Node *dup = (SP_OBJECT_REPR (i->data))->duplicate(xml_doc);
2874 mask_items = g_slist_prepend (mask_items, dup);
2876 if (remove_original) {
2877 SPObject *item = SP_OBJECT (i->data);
2878 items_to_delete = g_slist_prepend (items_to_delete, item);
2879 }
2880 }
2882 g_slist_free (items);
2883 items = NULL;
2885 gchar const* attributeName = apply_clip_path ? "clip-path" : "mask";
2886 for (GSList *i = apply_to_items; NULL != i; i = i->next) {
2887 SPItem *item = reinterpret_cast<SPItem *>(i->data);
2888 // inverted object transform should be applied to a mask object,
2889 // as mask is calculated in user space (after applying transform)
2890 NR::Matrix maskTransform (item->transform.inverse());
2892 GSList *mask_items_dup = NULL;
2893 for (GSList *mask_item = mask_items; NULL != mask_item; mask_item = mask_item->next) {
2894 Inkscape::XML::Node *dup = reinterpret_cast<Inkscape::XML::Node *>(mask_item->data)->duplicate(xml_doc);
2895 mask_items_dup = g_slist_prepend (mask_items_dup, dup);
2896 }
2898 const gchar *mask_id = NULL;
2899 if (apply_clip_path) {
2900 mask_id = sp_clippath_create(mask_items_dup, doc, &maskTransform);
2901 } else {
2902 mask_id = sp_mask_create(mask_items_dup, doc, &maskTransform);
2903 }
2905 g_slist_free (mask_items_dup);
2906 mask_items_dup = NULL;
2908 SP_OBJECT_REPR(i->data)->setAttribute(attributeName, g_strdup_printf("url(#%s)", mask_id));
2909 }
2911 g_slist_free (mask_items);
2912 g_slist_free (apply_to_items);
2914 for (GSList *i = items_to_delete; NULL != i; i = i->next) {
2915 SPObject *item = SP_OBJECT (i->data);
2916 item->deleteObject (false);
2917 }
2918 g_slist_free (items_to_delete);
2920 if (apply_clip_path)
2921 sp_document_done (doc, SP_VERB_OBJECT_SET_CLIPPATH, _("Set clipping path"));
2922 else
2923 sp_document_done (doc, SP_VERB_OBJECT_SET_MASK, _("Set mask"));
2924 }
2926 void sp_selection_unset_mask(bool apply_clip_path) {
2927 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
2928 if (desktop == NULL)
2929 return;
2931 SPDocument *doc = sp_desktop_document(desktop);
2932 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc);
2933 Inkscape::Selection *selection = sp_desktop_selection(desktop);
2935 // check if something is selected
2936 if (selection->isEmpty()) {
2937 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to remove clippath or mask from."));
2938 return;
2939 }
2941 bool remove_original = prefs_get_int_attribute ("options.maskobject", "remove", 1);
2942 sp_document_ensure_up_to_date(doc);
2944 gchar const* attributeName = apply_clip_path ? "clip-path" : "mask";
2945 std::map<SPObject*,SPItem*> referenced_objects;
2946 for (GSList const*i = selection->itemList(); NULL != i; i = i->next) {
2947 if (remove_original) {
2948 // remember referenced mask/clippath, so orphaned masks can be moved back to document
2949 SPItem *item = reinterpret_cast<SPItem *>(i->data);
2950 Inkscape::URIReference *uri_ref = NULL;
2952 if (apply_clip_path) {
2953 uri_ref = item->clip_ref;
2954 } else {
2955 uri_ref = item->mask_ref;
2956 }
2958 // collect distinct mask object (and associate with item to apply transform)
2959 if (NULL != uri_ref && NULL != uri_ref->getObject()) {
2960 referenced_objects[uri_ref->getObject()] = item;
2961 }
2962 }
2964 SP_OBJECT_REPR(i->data)->setAttribute(attributeName, "none");
2965 }
2967 // restore mask objects into a document
2968 for ( std::map<SPObject*,SPItem*>::iterator it = referenced_objects.begin() ; it != referenced_objects.end() ; ++it) {
2969 SPObject *obj = (*it).first;
2970 GSList *items_to_move = NULL;
2971 for (SPObject *child = sp_object_first_child(obj) ; child != NULL; child = SP_OBJECT_NEXT(child) ) {
2972 Inkscape::XML::Node *copy = SP_OBJECT_REPR(child)->duplicate(xml_doc);
2973 items_to_move = g_slist_prepend (items_to_move, copy);
2974 }
2976 if (!obj->isReferenced()) {
2977 // delete from defs if no other object references this mask
2978 obj->deleteObject(false);
2979 }
2981 // remember parent and position of the item to which the clippath/mask was applied
2982 Inkscape::XML::Node *parent = SP_OBJECT_REPR((*it).second)->parent();
2983 gint pos = SP_OBJECT_REPR((*it).second)->position();
2985 for (GSList *i = items_to_move; NULL != i; i = i->next) {
2986 Inkscape::XML::Node *repr = (Inkscape::XML::Node *)i->data;
2988 // insert into parent, restore pos
2989 parent->appendChild(repr);
2990 repr->setPosition((pos + 1) > 0 ? (pos + 1) : 0);
2992 SPItem *mask_item = (SPItem *) sp_desktop_document (desktop)->getObjectByRepr(repr);
2993 selection->add(repr);
2995 // transform mask, so it is moved the same spot where mask was applied
2996 NR::Matrix transform (mask_item->transform);
2997 transform *= (*it).second->transform;
2998 sp_item_write_transform(mask_item, SP_OBJECT_REPR(mask_item), transform);
2999 }
3001 g_slist_free (items_to_move);
3002 }
3004 if (apply_clip_path)
3005 sp_document_done (doc, SP_VERB_OBJECT_UNSET_CLIPPATH, _("Release clipping path"));
3006 else
3007 sp_document_done (doc, SP_VERB_OBJECT_UNSET_MASK, _("Release mask"));
3008 }
3010 void fit_canvas_to_selection(SPDesktop *desktop) {
3011 g_return_if_fail(desktop != NULL);
3012 SPDocument *doc = sp_desktop_document(desktop);
3014 g_return_if_fail(doc != NULL);
3015 g_return_if_fail(desktop->selection != NULL);
3017 if (desktop->selection->isEmpty()) {
3018 desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, _("Select <b>object(s)</b> to fit canvas to."));
3019 return;
3020 }
3021 NR::Maybe<NR::Rect> const bbox(desktop->selection->bounds());
3022 if (bbox && !bbox->isEmpty()) {
3023 doc->fitToRect(*bbox);
3024 }
3025 };
3027 void fit_canvas_to_drawing(SPDocument *doc) {
3028 g_return_if_fail(doc != NULL);
3030 sp_document_ensure_up_to_date(doc);
3031 SPItem const *const root = SP_ITEM(doc->root);
3032 NR::Maybe<NR::Rect> const bbox(root->getBounds(sp_item_i2r_affine(root)));
3033 if (bbox && !bbox->isEmpty()) {
3034 doc->fitToRect(*bbox);
3035 }
3036 };
3038 void fit_canvas_to_selection_or_drawing(SPDesktop *desktop) {
3039 g_return_if_fail(desktop != NULL);
3040 SPDocument *doc = sp_desktop_document(desktop);
3042 g_return_if_fail(doc != NULL);
3043 g_return_if_fail(desktop->selection != NULL);
3045 if (desktop->selection->isEmpty()) {
3046 fit_canvas_to_drawing(doc);
3047 } else {
3048 fit_canvas_to_selection(desktop);
3049 }
3051 sp_document_done(doc, SP_VERB_FIT_CANVAS_TO_DRAWING,
3052 _("Fit page to selection"));
3053 };
3055 static void itemtree_map(void (*f)(SPItem *, SPDesktop *), SPObject *root, SPDesktop *desktop) {
3056 // don't operate on layers
3057 if (SP_IS_ITEM(root) && !desktop->isLayer(SP_ITEM(root))) {
3058 f(SP_ITEM(root), desktop);
3059 }
3060 for ( SPObject::SiblingIterator iter = root->firstChild() ; iter ; ++iter ) {
3061 //don't recurse into locked layers
3062 if (!(SP_IS_ITEM(&*iter) && desktop->isLayer(SP_ITEM(&*iter)) && SP_ITEM(&*iter)->isLocked())) {
3063 itemtree_map(f, iter, desktop);
3064 }
3065 }
3066 }
3068 static void unlock(SPItem *item, SPDesktop *desktop) {
3069 if (item->isLocked()) {
3070 item->setLocked(FALSE);
3071 }
3072 }
3074 static void unhide(SPItem *item, SPDesktop *desktop) {
3075 if (desktop->itemIsHidden(item)) {
3076 item->setExplicitlyHidden(FALSE);
3077 }
3078 }
3080 static void process_all(void (*f)(SPItem *, SPDesktop *), SPDesktop *dt, bool layer_only) {
3081 if (!dt) return;
3083 SPObject *root;
3084 if (layer_only) {
3085 root = dt->currentLayer();
3086 } else {
3087 root = dt->currentRoot();
3088 }
3090 itemtree_map(f, root, dt);
3091 }
3093 void unlock_all(SPDesktop *dt) {
3094 process_all(&unlock, dt, true);
3095 }
3097 void unlock_all_in_all_layers(SPDesktop *dt) {
3098 process_all(&unlock, dt, false);
3099 }
3101 void unhide_all(SPDesktop *dt) {
3102 process_all(&unhide, dt, true);
3103 }
3105 void unhide_all_in_all_layers(SPDesktop *dt) {
3106 process_all(&unhide, dt, false);
3107 }
3110 GSList * sp_selection_get_clipboard() {
3111 return clipboard;
3112 }
3114 /*
3115 Local Variables:
3116 mode:c++
3117 c-file-style:"stroustrup"
3118 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
3119 indent-tabs-mode:nil
3120 fill-column:99
3121 End:
3122 */
3123 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :