From 1636c1dd1651780d01759676b194312529f211f7 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Sat, 25 Jun 2016 22:24:26 +0200 Subject: Moved next functions, added namespace, renamed range functions (bzr r14954.1.10) --- src/ui/clipboard.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index d581dbf7e..b1a946db2 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -522,7 +522,7 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (item) { @@ -578,7 +578,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) desktop->doc()->importDefs(tempdoc); // make sure all selected items are converted to paths first (i.e. rectangles) sp_selected_to_lpeitems(desktop); - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; _applyPathEffect(item, effectstack); @@ -661,7 +661,7 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) { // copy the defs used by all items - std::vector itemlist=selection->itemList(); + std::vector itemlist= selection->items(); cloned_elements.clear(); for(std::vector::const_iterator i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; -- cgit v1.2.3 From d1947e768272c703674129d5c583204ff2b59251 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 13 Jul 2016 13:36:19 +0200 Subject: Second part of new SPObject children list (bzr r14954.1.19) --- src/ui/clipboard.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 9871804f5..75c6c5bcc 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -894,8 +894,8 @@ void ClipboardManagerImpl::_copyPattern(SPPattern *pattern) _copyNode(pattern->getRepr(), _doc, _defs); // items in the pattern may also use gradients and other patterns, so recurse - for ( SPObject *child = pattern->firstChild() ; child ; child = child->getNext() ) { - SPItem *childItem = dynamic_cast(child); + for (auto& child: pattern->_children) { + SPItem *childItem = dynamic_cast(&child); if (childItem) { _copyUsedDefs(childItem); } -- cgit v1.2.3 From 9e210a6d1333c3366681547e3e81593ef69ff73e Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 14 Jul 2016 12:56:49 +0200 Subject: Last part of new SPObject children list (bzr r14954.1.20) --- src/ui/clipboard.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 75c6c5bcc..48d53857b 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -839,8 +839,8 @@ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item) SPObject *mask = item->mask_ref->getObject(); _copyNode(mask->getRepr(), _doc, _defs); // recurse into the mask for its gradients etc. - for (SPObject *o = mask->children ; o != NULL ; o = o->next) { - SPItem *childItem = dynamic_cast(o); + for(auto& o: mask->_children) { + SPItem *childItem = dynamic_cast(&o); if (childItem) { _copyUsedDefs(childItem); } @@ -857,8 +857,8 @@ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item) } // recurse - for (SPObject *o = item->children ; o != NULL ; o = o->next) { - SPItem *childItem = dynamic_cast(o); + for(auto& o: item->_children) { + SPItem *childItem = dynamic_cast(&o); if (childItem) { _copyUsedDefs(childItem); } -- cgit v1.2.3 From 24d3f50003ca3cec6a03a7f5267cc4fe5588c69f Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 14 Jul 2016 13:17:21 +0200 Subject: Renamed children list in SPObject (bzr r14954.1.21) --- src/ui/clipboard.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 48d53857b..b25a70b15 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -839,7 +839,7 @@ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item) SPObject *mask = item->mask_ref->getObject(); _copyNode(mask->getRepr(), _doc, _defs); // recurse into the mask for its gradients etc. - for(auto& o: mask->_children) { + for(auto& o: mask->children) { SPItem *childItem = dynamic_cast(&o); if (childItem) { _copyUsedDefs(childItem); @@ -857,7 +857,7 @@ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item) } // recurse - for(auto& o: item->_children) { + for(auto& o: item->children) { SPItem *childItem = dynamic_cast(&o); if (childItem) { _copyUsedDefs(childItem); @@ -894,7 +894,7 @@ void ClipboardManagerImpl::_copyPattern(SPPattern *pattern) _copyNode(pattern->getRepr(), _doc, _defs); // items in the pattern may also use gradients and other patterns, so recurse - for (auto& child: pattern->_children) { + for (auto& child: pattern->children) { SPItem *childItem = dynamic_cast(&child); if (childItem) { _copyUsedDefs(childItem); -- cgit v1.2.3 From ff4fbbc93f67afd6cbf851691833a50d6c76b350 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 27 Jul 2016 12:19:03 +0200 Subject: Renamed some functions, fixed tests (bzr r14954.1.28) --- src/ui/clipboard.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index b25a70b15..504a5e2ce 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -539,8 +539,8 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a else { Geom::OptRect sel_size = selection->visualBounds(); if ( sel_size ) { - sp_selection_scale_relative(selection, sel_size->midpoint(), - _getScale(desktop, min, max, *sel_size, apply_x, apply_y)); + sp_object_set_scale_relative(selection, sel_size->midpoint(), + _getScale(desktop, min, max, *sel_size, apply_x, apply_y)); } } pasted = true; -- cgit v1.2.3 From f35bb1f74a0ffeb5c6477a25e3c4cde87a97bcf1 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 12:06:06 +0200 Subject: Removed unused includes, decrease compilation time (bzr r15025) --- src/ui/clipboard.cpp | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index d581dbf7e..09ba9a1a9 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -27,9 +27,6 @@ // TODO: reduce header bloat if possible #include "file.h" // for file_import, used in _pasteImage -#include -#include -#include #include #include // for g_file_set_contents etc., used in _onGet and paste #include "inkgc/gc-core.h" @@ -41,7 +38,6 @@ #include "desktop-style.h" // for sp_desktop_set_style, used in _pasteStyle #include "document.h" #include "document-private.h" -#include "selection.h" #include "message-stack.h" #include "context-fns.h" #include "ui/tools/dropper-tool.h" // used in copy() @@ -50,17 +46,13 @@ #include "extension/input.h" #include "extension/output.h" #include "selection-chemistry.h" -#include <2geom/rect.h> #include <2geom/transforms.h> #include "box3d.h" #include "gradient-drag.h" #include "sp-marker.h" -#include "sp-item.h" #include "sp-item-transform.h" // for sp_item_scale_rel, used in _pasteSize #include "sp-path.h" #include "sp-pattern.h" -#include "sp-shape.h" -#include "sp-gradient.h" #include "sp-gradient-reference.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" @@ -68,8 +60,6 @@ #include "sp-mask.h" #include "sp-textpath.h" #include "sp-rect.h" -#include "sp-use.h" -#include "sp-symbol.h" #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" #include "live_effects/parameter/path.h" @@ -83,9 +73,7 @@ #include "helper/png-write.h" #include "svg/svg-color.h" #include "sp-namedview.h" -#include "snap.h" #include "persp3d.h" -#include "preferences.h" /// Made up mimetype to represent Gdk::Pixbuf clipboard contents. #define CLIPBOARD_GDK_PIXBUF_TARGET "image/x-gdk-pixbuf" -- cgit v1.2.3 From 43b49e325db73cc19b1731db6c69545664ee8fbe Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Thu, 28 Jul 2016 13:26:17 +0200 Subject: Reverted changes to r15024 after many building problems (bzr r15027) --- src/ui/clipboard.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 09ba9a1a9..d581dbf7e 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -27,6 +27,9 @@ // TODO: reduce header bloat if possible #include "file.h" // for file_import, used in _pasteImage +#include +#include +#include #include #include // for g_file_set_contents etc., used in _onGet and paste #include "inkgc/gc-core.h" @@ -38,6 +41,7 @@ #include "desktop-style.h" // for sp_desktop_set_style, used in _pasteStyle #include "document.h" #include "document-private.h" +#include "selection.h" #include "message-stack.h" #include "context-fns.h" #include "ui/tools/dropper-tool.h" // used in copy() @@ -46,13 +50,17 @@ #include "extension/input.h" #include "extension/output.h" #include "selection-chemistry.h" +#include <2geom/rect.h> #include <2geom/transforms.h> #include "box3d.h" #include "gradient-drag.h" #include "sp-marker.h" +#include "sp-item.h" #include "sp-item-transform.h" // for sp_item_scale_rel, used in _pasteSize #include "sp-path.h" #include "sp-pattern.h" +#include "sp-shape.h" +#include "sp-gradient.h" #include "sp-gradient-reference.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" @@ -60,6 +68,8 @@ #include "sp-mask.h" #include "sp-textpath.h" #include "sp-rect.h" +#include "sp-use.h" +#include "sp-symbol.h" #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" #include "live_effects/parameter/path.h" @@ -73,7 +83,9 @@ #include "helper/png-write.h" #include "svg/svg-color.h" #include "sp-namedview.h" +#include "snap.h" #include "persp3d.h" +#include "preferences.h" /// Made up mimetype to represent Gdk::Pixbuf clipboard contents. #define CLIPBOARD_GDK_PIXBUF_TARGET "image/x-gdk-pixbuf" -- cgit v1.2.3 From dcd91f59f597ab4af07cee5929ce0e2e1f9104d5 Mon Sep 17 00:00:00 2001 From: Alex Valavanis Date: Thu, 28 Jul 2016 16:16:18 +0100 Subject: Drop remaining GTKMM 2 fallback support (bzr r15023.2.7) --- src/ui/clipboard.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index d581dbf7e..6b24c5a2d 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -1300,11 +1300,7 @@ Geom::Scale ClipboardManagerImpl::_getScale(SPDesktop *desktop, Geom::Point cons */ Glib::ustring ClipboardManagerImpl::_getBestTarget() { -#if WITH_GTKMM_3_0 - std::vector targets = _clipboard->wait_for_targets(); -#else - std::list targets = _clipboard->wait_for_targets(); -#endif + auto targets = _clipboard->wait_for_targets(); // clipboard target debugging snippet /* @@ -1363,12 +1359,7 @@ void ClipboardManagerImpl::_setClipboardTargets() { Inkscape::Extension::DB::OutputList outlist; Inkscape::Extension::db.get_output_list(outlist); - -#if WITH_GTKMM_3_0 std::vector target_list; -#else - std::list target_list; -#endif bool plaintextSet = false; for (Inkscape::Extension::DB::OutputList::const_iterator out = outlist.begin() ; out != outlist.end() ; ++out) { -- cgit v1.2.3 From 35830f456cadaecf8b8e3944e3031a1a93f6cb41 Mon Sep 17 00:00:00 2001 From: Adrian Boguszewski Date: Wed, 3 Aug 2016 15:29:38 +0200 Subject: Removed unused includes, decreased compilation time. Once again (bzr r15034) --- src/ui/clipboard.cpp | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index d581dbf7e..09ba9a1a9 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -27,9 +27,6 @@ // TODO: reduce header bloat if possible #include "file.h" // for file_import, used in _pasteImage -#include -#include -#include #include #include // for g_file_set_contents etc., used in _onGet and paste #include "inkgc/gc-core.h" @@ -41,7 +38,6 @@ #include "desktop-style.h" // for sp_desktop_set_style, used in _pasteStyle #include "document.h" #include "document-private.h" -#include "selection.h" #include "message-stack.h" #include "context-fns.h" #include "ui/tools/dropper-tool.h" // used in copy() @@ -50,17 +46,13 @@ #include "extension/input.h" #include "extension/output.h" #include "selection-chemistry.h" -#include <2geom/rect.h> #include <2geom/transforms.h> #include "box3d.h" #include "gradient-drag.h" #include "sp-marker.h" -#include "sp-item.h" #include "sp-item-transform.h" // for sp_item_scale_rel, used in _pasteSize #include "sp-path.h" #include "sp-pattern.h" -#include "sp-shape.h" -#include "sp-gradient.h" #include "sp-gradient-reference.h" #include "sp-linear-gradient.h" #include "sp-radial-gradient.h" @@ -68,8 +60,6 @@ #include "sp-mask.h" #include "sp-textpath.h" #include "sp-rect.h" -#include "sp-use.h" -#include "sp-symbol.h" #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" #include "live_effects/parameter/path.h" @@ -83,9 +73,7 @@ #include "helper/png-write.h" #include "svg/svg-color.h" #include "sp-namedview.h" -#include "snap.h" #include "persp3d.h" -#include "preferences.h" /// Made up mimetype to represent Gdk::Pixbuf clipboard contents. #define CLIPBOARD_GDK_PIXBUF_TARGET "image/x-gdk-pixbuf" -- cgit v1.2.3 From 532f77b14a76fc04e6bdeca3625f9a55b5f11bdf Mon Sep 17 00:00:00 2001 From: Marc Jeanmougin Date: Tue, 25 Oct 2016 00:58:43 +0200 Subject: CPPification: almost all sp_object_set_whatever and sp_selection_whatever global functions are now methods of ObjectSet*, with these additional benefits: - They can now act on any SelectionSet, not just the current selection; - Whenever possible, they don't need a desktop anymore and can run if called from GUI. I hope I did not break too many things in the process. *: So instead of callink sp_selection_move(desktop,x,y), you call myobjectset->move(x,y) (bzr r15189) --- src/ui/clipboard.cpp | 187 ++++++++++++++++++++++++++------------------------- 1 file changed, 94 insertions(+), 93 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 66b13ed9d..0a671cc8a 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -74,6 +74,7 @@ #include "svg/svg-color.h" #include "sp-namedview.h" #include "persp3d.h" +#include "object-set.h" /// Made up mimetype to represent Gdk::Pixbuf clipboard contents. #define CLIPBOARD_GDK_PIXBUF_TARGET "image/x-gdk-pixbuf" @@ -93,13 +94,13 @@ namespace UI { */ class ClipboardManagerImpl : public ClipboardManager { public: - virtual void copy(SPDesktop *desktop); + virtual void copy(ObjectSet *set); virtual void copyPathParameter(Inkscape::LivePathEffect::PathParam *); virtual void copySymbol(Inkscape::XML::Node* symbol, gchar const* style, bool user_symbol); virtual bool paste(SPDesktop *desktop, bool in_place); - virtual bool pasteStyle(SPDesktop *desktop); - virtual bool pasteSize(SPDesktop *desktop, bool separately, bool apply_x, bool apply_y); - virtual bool pastePathEffect(SPDesktop *desktop); + virtual bool pasteStyle(ObjectSet *set); + virtual bool pasteSize(ObjectSet *set, bool separately, bool apply_x, bool apply_y); + virtual bool pastePathEffect(ObjectSet *set); virtual Glib::ustring getPathParameter(SPDesktop* desktop); virtual Glib::ustring getShapeOrTextObjectId(SPDesktop *desktop); virtual const gchar *getFirstObjectID(); @@ -108,7 +109,7 @@ public: ~ClipboardManagerImpl(); private: - void _copySelection(Inkscape::Selection *); + void _copySelection(ObjectSet *); void _copyUsedDefs(SPItem *); void _copyGradient(SPGradient *); void _copyPattern(SPPattern *); @@ -183,76 +184,74 @@ ClipboardManagerImpl::~ClipboardManagerImpl() {} /** * Copy selection contents to the clipboard. */ -void ClipboardManagerImpl::copy(SPDesktop *desktop) +void ClipboardManagerImpl::copy(ObjectSet *set) { - if ( desktop == NULL ) { - return; - } - Inkscape::Selection *selection = desktop->getSelection(); + if ( set->desktop() ) { + SPDesktop *desktop = set->desktop(); + + // Special case for when the gradient dragger is active - copies gradient color + if (desktop->event_context->get_drag()) { + GrDrag *drag = desktop->event_context->get_drag(); + if (drag->hasSelection()) { + guint32 col = drag->getColor(); + + // set the color as clipboard content (text in RRGGBBAA format) + _setClipboardColor(col); + + // create a style with this color on fill and opacity in master opacity, so it can be + // pasted on other stops or objects + if (_text_style) { + sp_repr_css_attr_unref(_text_style); + _text_style = NULL; + } + _text_style = sp_repr_css_attr_new(); + // print and set properties + gchar color_str[16]; + g_snprintf(color_str, 16, "#%06x", col >> 8); + sp_repr_css_set_property(_text_style, "fill", color_str); + float opacity = SP_RGBA32_A_F(col); + if (opacity > 1.0) { + opacity = 1.0; // safeguard + } + Inkscape::CSSOStringStream opcss; + opcss << opacity; + sp_repr_css_set_property(_text_style, "opacity", opcss.str().data()); - // Special case for when the gradient dragger is active - copies gradient color - if (desktop->event_context->get_drag()) { - GrDrag *drag = desktop->event_context->get_drag(); - if (drag->hasSelection()) { - guint32 col = drag->getColor(); + _discardInternalClipboard(); + return; + } + } - // set the color as clipboard content (text in RRGGBBAA format) - _setClipboardColor(col); + // Special case for when the color picker ("dropper") is active - copies color under cursor + if (tools_isactive(desktop, TOOLS_DROPPER)) { + //_setClipboardColor(sp_dropper_context_get_color(desktop->event_context)); + _setClipboardColor(SP_DROPPER_CONTEXT(desktop->event_context)->get_color()); + _discardInternalClipboard(); + return; + } - // create a style with this color on fill and opacity in master opacity, so it can be - // pasted on other stops or objects + // Special case for when the text tool is active - if some text is selected, copy plain text, + // not the object that holds it; also copy the style at cursor into + if (tools_isactive(desktop, TOOLS_TEXT)) { + _discardInternalClipboard(); + Glib::ustring selected_text = Inkscape::UI::Tools::sp_text_get_selected_text(desktop->event_context); + _clipboard->set_text(selected_text); if (_text_style) { sp_repr_css_attr_unref(_text_style); _text_style = NULL; } - _text_style = sp_repr_css_attr_new(); - // print and set properties - gchar color_str[16]; - g_snprintf(color_str, 16, "#%06x", col >> 8); - sp_repr_css_set_property(_text_style, "fill", color_str); - float opacity = SP_RGBA32_A_F(col); - if (opacity > 1.0) { - opacity = 1.0; // safeguard - } - Inkscape::CSSOStringStream opcss; - opcss << opacity; - sp_repr_css_set_property(_text_style, "opacity", opcss.str().data()); - - _discardInternalClipboard(); + _text_style = Inkscape::UI::Tools::sp_text_get_style_at_cursor(desktop->event_context); return; } } - - // Special case for when the color picker ("dropper") is active - copies color under cursor - if (tools_isactive(desktop, TOOLS_DROPPER)) { - //_setClipboardColor(sp_dropper_context_get_color(desktop->event_context)); - _setClipboardColor(SP_DROPPER_CONTEXT(desktop->event_context)->get_color()); - _discardInternalClipboard(); - return; - } - - // Special case for when the text tool is active - if some text is selected, copy plain text, - // not the object that holds it; also copy the style at cursor into - if (tools_isactive(desktop, TOOLS_TEXT)) { - _discardInternalClipboard(); - Glib::ustring selected_text = Inkscape::UI::Tools::sp_text_get_selected_text(desktop->event_context); - _clipboard->set_text(selected_text); - if (_text_style) { - sp_repr_css_attr_unref(_text_style); - _text_style = NULL; - } - _text_style = Inkscape::UI::Tools::sp_text_get_style_at_cursor(desktop->event_context); - return; - } - - if (selection->isEmpty()) { // check whether something is selected - _userWarn(desktop, _("Nothing was copied.")); + if (set->isEmpty()) { // check whether something is selected + _userWarn(set->desktop(), _("Nothing was copied.")); return; } _discardInternalClipboard(); _createInternalClipboard(); // construct a new clipboard document - _copySelection(selection); // copy all items in the selection to the internal clipboard + _copySelection(set); // copy all items in the selection to the internal clipboard fit_canvas_to_drawing(_clipboardSPDoc); _setClipboardTargets(); @@ -426,16 +425,15 @@ const gchar *ClipboardManagerImpl::getFirstObjectID() /** * Implements the Paste Style action. */ -bool ClipboardManagerImpl::pasteStyle(SPDesktop *desktop) +bool ClipboardManagerImpl::pasteStyle(ObjectSet *set) { - if (desktop == NULL) { + if (set->desktop() == NULL) { return false; } // check whether something is selected - Inkscape::Selection *selection = desktop->getSelection(); - if (selection->isEmpty()) { - _userWarn(desktop, _("Select object(s) to paste style to.")); + if (set->isEmpty()) { + _userWarn(set->desktop(), _("Select object(s) to paste style to.")); return false; } @@ -443,10 +441,10 @@ bool ClipboardManagerImpl::pasteStyle(SPDesktop *desktop) if ( tempdoc == NULL ) { // no document, but we can try _text_style if (_text_style) { - sp_desktop_set_style(desktop, _text_style); + sp_desktop_set_style(set, set->desktop(), _text_style); return true; } else { - _userWarn(desktop, _("No style on the clipboard.")); + _userWarn(set->desktop(), _("No style on the clipboard.")); return false; } } @@ -457,13 +455,13 @@ bool ClipboardManagerImpl::pasteStyle(SPDesktop *desktop) bool pasted = false; if (clipnode) { - desktop->doc()->importDefs(tempdoc); + set->document()->importDefs(tempdoc); SPCSSAttr *style = sp_repr_css_attr(clipnode, "style"); - sp_desktop_set_style(desktop, style); + sp_desktop_set_style(set, set->desktop(), style); pasted = true; } else { - _userWarn(desktop, _("No style on the clipboard.")); + _userWarn(set->desktop(), _("No style on the clipboard.")); } tempdoc->doUnref(); @@ -477,29 +475,31 @@ bool ClipboardManagerImpl::pasteStyle(SPDesktop *desktop) * @param apply_x Whether to scale the width of objects / selection * @param apply_y Whether to scale the height of objects / selection */ -bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool apply_x, bool apply_y) +bool ClipboardManagerImpl::pasteSize(ObjectSet *set, bool separately, bool apply_x, bool apply_y) { if (!apply_x && !apply_y) { return false; // pointless parameters } - if ( desktop == NULL ) { +/* if ( desktop == NULL ) { return false; } - Inkscape::Selection *selection = desktop->getSelection(); - if (selection->isEmpty()) { - _userWarn(desktop, _("Select object(s) to paste size to.")); + Inkscape::Selection *selection = desktop->getSelection();*/ + if (set->isEmpty()) { + if(set->desktop()) + _userWarn(set->desktop(), _("Select object(s) to paste size to.")); return false; } // FIXME: actually, this should accept arbitrary documents SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc == NULL ) { - _userWarn(desktop, _("No size on the clipboard.")); + if(set->desktop()) + _userWarn(set->desktop(), _("No size on the clipboard.")); return false; } - // retrieve size ifomration from the clipboard + // retrieve size information from the clipboard Inkscape::XML::Node *root = tempdoc->getReprRoot(); Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1); bool pasted = false; @@ -510,13 +510,13 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a // resize each object in the selection if (separately) { - auto itemlist= selection->items(); + auto itemlist= set->items(); for(auto i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; if (item) { Geom::OptRect obj_size = item->desktopVisualBounds(); if ( obj_size ) { - sp_item_scale_rel(item, _getScale(desktop, min, max, *obj_size, apply_x, apply_y)); + sp_item_scale_rel(item, _getScale(set->desktop(), min, max, *obj_size, apply_x, apply_y)); } } else { g_assert_not_reached(); @@ -525,10 +525,10 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a } // resize the selection as a whole else { - Geom::OptRect sel_size = selection->visualBounds(); + Geom::OptRect sel_size = set->visualBounds(); if ( sel_size ) { - sp_object_set_scale_relative(selection, sel_size->midpoint(), - _getScale(desktop, min, max, *sel_size, apply_x, apply_y)); + set->setScaleRelative(sel_size->midpoint(), + _getScale(set->desktop(), min, max, *sel_size, apply_x, apply_y)); } } pasted = true; @@ -541,18 +541,18 @@ bool ClipboardManagerImpl::pasteSize(SPDesktop *desktop, bool separately, bool a /** * Applies a path effect from the clipboard to the selected path. */ -bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) +bool ClipboardManagerImpl::pastePathEffect(ObjectSet *set) { /** @todo FIXME: pastePathEffect crashes when moving the path with the applied effect, segfaulting in fork_private_if_necessary(). */ - if ( desktop == NULL ) { + if ( set->desktop() == NULL ) { return false; } - Inkscape::Selection *selection = desktop->getSelection(); - if (!selection || selection->isEmpty()) { - _userWarn(desktop, _("Select object(s) to paste live path effect to.")); + //Inkscape::Selection *selection = desktop->getSelection(); + if (!set || set->isEmpty()) { + _userWarn(set->desktop(), _("Select object(s) to paste live path effect to.")); return false; } @@ -563,10 +563,10 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) if ( clipnode ) { gchar const *effectstack = clipnode->attribute("inkscape:path-effect"); if ( effectstack ) { - desktop->doc()->importDefs(tempdoc); + set->document()->importDefs(tempdoc); // make sure all selected items are converted to paths first (i.e. rectangles) - sp_selected_to_lpeitems(desktop); - auto itemlist= selection->items(); + set->toLPEItems(); + auto itemlist= set->items(); for(auto i=itemlist.begin();i!=itemlist.end();++i){ SPItem *item = *i; _applyPathEffect(item, effectstack); @@ -578,7 +578,7 @@ bool ClipboardManagerImpl::pastePathEffect(SPDesktop *desktop) } // no_effect: - _userWarn(desktop, _("No effect on the clipboard.")); + _userWarn(set->desktop(), _("No effect on the clipboard.")); return false; } @@ -646,7 +646,7 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) /** * Iterate over a list of items and copy them to the clipboard. */ -void ClipboardManagerImpl::_copySelection(Inkscape::Selection *selection) +void ClipboardManagerImpl::_copySelection(ObjectSet *selection) { // copy the defs used by all items auto itemlist= selection->items(); @@ -1270,7 +1270,7 @@ Geom::Scale ClipboardManagerImpl::_getScale(SPDesktop *desktop, Geom::Point cons } // If the "lock aspect ratio" button is pressed and we paste only a single coordinate, // resize the second one by the same ratio too - if (desktop->isToolboxButtonActive("lock")) { + if (desktop && desktop->isToolboxButtonActive("lock")) { if (apply_x && !apply_y) { scale_y = scale_x; } @@ -1432,7 +1432,8 @@ void ClipboardManagerImpl::_setClipboardColor(guint32 color) */ void ClipboardManagerImpl::_userWarn(SPDesktop *desktop, char const *msg) { - desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, msg); + if(desktop) + desktop->messageStack()->flash(Inkscape::WARNING_MESSAGE, msg); } /* ####################################### -- cgit v1.2.3 From e7eeaf23639692c87f9cd772b8cdbfb7e54ceea6 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 5 Nov 2016 14:49:05 +0100 Subject: Fix a bug on duplicate item with multiples LPE on it. previously the LPE become "clones" if more than 1 LPE on the item. Also wee need to discuss what happends on LPE copied what are inside a group, fork them or clone, currently are cloned This can be a feature or a bug in the same user with diferent works. My proposal is fork it and add a item in paste LPEs to allow cloned LPE on paste (bzr r15213) --- src/ui/clipboard.cpp | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 0a671cc8a..ef00e11b3 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -688,7 +688,23 @@ void ClipboardManagerImpl::_copySelection(ObjectSet *selection) else obj_copy = _copyNode(obj, _doc, _clipnode); - + // For lpe items, copy lpe stack if applicable + SPLPEItem *lpeitem = dynamic_cast(item); + if (lpeitem) { + Inkscape::SVGOStringStream os; + if (lpeitem->hasPathEffect()) { + for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); ++it) + { + LivePathEffectObject *lpeobj = (*it)->lpeobject; + if (lpeobj) { + Inkscape::XML::Node * lpeobjcopy = _copyNode(lpeobj->getRepr(), _doc, _defs); + lpeobjcopy->setAttribute("id",lpeobj->getRepr()->attribute("id")); + os << "#" << lpeobj->getRepr()->attribute("id") << ";"; + } + } + } + obj_copy->setAttribute("inkscape:path-effect", os.str().c_str()); + } // copy complete inherited style SPCSSAttr *css = sp_repr_css_attr_inherited(obj, "style"); sp_repr_css_set(obj_copy, css, "style"); @@ -720,14 +736,6 @@ void ClipboardManagerImpl::_copySelection(ObjectSet *selection) sp_repr_css_set(_clipnode, style, "style"); sp_repr_css_attr_unref(style); } - - // copy path effect from the first path - if (object) { - gchar const *effect =object->getRepr()->attribute("inkscape:path-effect"); - if (effect) { - _clipnode->setAttribute("inkscape:path-effect", effect); - } - } } Geom::OptRect size = selection->visualBounds(); @@ -784,20 +792,6 @@ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item) } } - // For lpe items, copy lpe stack if applicable - SPLPEItem *lpeitem = dynamic_cast(item); - if (lpeitem) { - if (lpeitem->hasPathEffect()) { - for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); ++it) - { - LivePathEffectObject *lpeobj = (*it)->lpeobject; - if (lpeobj) { - _copyNode(lpeobj->getRepr(), _doc, _defs); - } - } - } - } - // For 3D boxes, copy perspectives { SPBox3D *box = dynamic_cast(item); -- cgit v1.2.3 From 046b9d9b4d20894231127a6d00d327302ffd0474 Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Cenoz Date: Sat, 5 Nov 2016 17:45:28 +0100 Subject: Fix last commit not working, LPE are cloned on copies (bzr r15214) --- src/ui/clipboard.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index ef00e11b3..a8e708597 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -60,6 +60,7 @@ #include "sp-mask.h" #include "sp-textpath.h" #include "sp-rect.h" +#include "sp-object.h" #include "live_effects/lpeobject.h" #include "live_effects/lpeobject-reference.h" #include "live_effects/parameter/path.h" @@ -698,8 +699,10 @@ void ClipboardManagerImpl::_copySelection(ObjectSet *selection) LivePathEffectObject *lpeobj = (*it)->lpeobject; if (lpeobj) { Inkscape::XML::Node * lpeobjcopy = _copyNode(lpeobj->getRepr(), _doc, _defs); - lpeobjcopy->setAttribute("id",lpeobj->getRepr()->attribute("id")); - os << "#" << lpeobj->getRepr()->attribute("id") << ";"; + gchar *new_conflict_id = sp_object_get_unique_id(lpeobj, lpeobj->getAttribute("id")); + lpeobjcopy->setAttribute("id", new_conflict_id); + g_free(new_conflict_id); + os << "#" << lpeobjcopy->attribute("id") << ";"; } } } -- cgit v1.2.3 From bfcc1fb5a5142a71469834cac2d507f15626a8b5 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Wed, 4 Jan 2017 03:32:40 +0200 Subject: Extract some common code into a routine. (bzr r15369.1.8) --- src/ui/clipboard.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index a8e708597..73b632a2c 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -76,6 +76,7 @@ #include "sp-namedview.h" #include "persp3d.h" #include "object-set.h" +#include "extension/find_extension_by_mime.h" /// Made up mimetype to represent Gdk::Pixbuf clipboard contents. #define CLIPBOARD_GDK_PIXBUF_TARGET "image/x-gdk-pixbuf" @@ -945,15 +946,7 @@ bool ClipboardManagerImpl::_pasteImage(SPDocument *doc) return false; } - // TODO unify with interface.cpp's sp_ui_drag_data_received() - // AARGH stupid - Inkscape::Extension::DB::InputList o; - Inkscape::Extension::db.get_input_list(o); - Inkscape::Extension::DB::InputList::const_iterator i = o.begin(); - while (i != o.end() && strcmp( (*i)->get_mimetype(), "image/png" ) != 0) { - ++i; - } - Inkscape::Extension::Extension *png = *i; + Inkscape::Extension::Extension *png = Inkscape::Extension::find_by_mime("image/png"); Inkscape::Preferences *prefs = Inkscape::Preferences::get(); Glib::ustring attr_saved = prefs->getString("/dialogs/import/link"); bool ask_saved = prefs->getBool("/dialogs/import/ask"); -- cgit v1.2.3 From 8907ced418b6c40782d2d2c0f3f944edcb3c08df Mon Sep 17 00:00:00 2001 From: Jabiertxof Date: Fri, 20 Jan 2017 20:19:49 +0100 Subject: Fixes bugs in copy LPE's. #1656093:Paste path effect doesn't work on 0.92 and #1656527:Copy & paste of group with shaped path corrupts it, in v0.92 Fixed bugs: - https://launchpad.net/bugs/1656093 - https://launchpad.net/bugs/1656527 (bzr r15426) --- src/ui/clipboard.cpp | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index a8e708597..c1e824c1e 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -643,7 +643,6 @@ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId(SPDesktop *desktop) return svgd; } - /** * Iterate over a list of items and copy them to the clipboard. */ @@ -689,25 +688,6 @@ void ClipboardManagerImpl::_copySelection(ObjectSet *selection) else obj_copy = _copyNode(obj, _doc, _clipnode); - // For lpe items, copy lpe stack if applicable - SPLPEItem *lpeitem = dynamic_cast(item); - if (lpeitem) { - Inkscape::SVGOStringStream os; - if (lpeitem->hasPathEffect()) { - for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); ++it) - { - LivePathEffectObject *lpeobj = (*it)->lpeobject; - if (lpeobj) { - Inkscape::XML::Node * lpeobjcopy = _copyNode(lpeobj->getRepr(), _doc, _defs); - gchar *new_conflict_id = sp_object_get_unique_id(lpeobj, lpeobj->getAttribute("id")); - lpeobjcopy->setAttribute("id", new_conflict_id); - g_free(new_conflict_id); - os << "#" << lpeobjcopy->attribute("id") << ";"; - } - } - } - obj_copy->setAttribute("inkscape:path-effect", os.str().c_str()); - } // copy complete inherited style SPCSSAttr *css = sp_repr_css_attr_inherited(obj, "style"); sp_repr_css_set(obj_copy, css, "style"); @@ -739,6 +719,13 @@ void ClipboardManagerImpl::_copySelection(ObjectSet *selection) sp_repr_css_set(_clipnode, style, "style"); sp_repr_css_attr_unref(style); } + // copy path effect from the first path + if (object) { + gchar const *effect =object->getRepr()->attribute("inkscape:path-effect"); + if (effect) { + _clipnode->setAttribute("inkscape:path-effect", effect); + } + } } Geom::OptRect size = selection->visualBounds(); @@ -841,6 +828,19 @@ void ClipboardManagerImpl::_copyUsedDefs(SPItem *item) } } + // For lpe items, copy lpe stack if applicable + SPLPEItem *lpeitem = dynamic_cast(item); + if (lpeitem) { + if (lpeitem->hasPathEffect()) { + for (PathEffectList::iterator it = lpeitem->path_effect_list->begin(); it != lpeitem->path_effect_list->end(); ++it){ + LivePathEffectObject *lpeobj = (*it)->lpeobject; + if (lpeobj) { + _copyNode(lpeobj->getRepr(), _doc, _defs); + } + } + } + } + // recurse for(auto& o: item->children) { SPItem *childItem = dynamic_cast(&o); -- cgit v1.2.3 From 0fad68e35604556b9a3af81b90d8cc6b89e817b8 Mon Sep 17 00:00:00 2001 From: Alexandru-Daniel Roman Date: Tue, 28 Feb 2017 13:48:29 +0200 Subject: This patch adds the copy-paste formated text functionality to the text tool. It doesn't retain the font-size and font-style properties. (bzr r15553) --- src/ui/clipboard.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index c1e824c1e..038711861 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -143,6 +143,11 @@ private: Inkscape::XML::Node *_clipnode; ///< The node that holds extra information Inkscape::XML::Document *_doc; ///< Reference to the clipboard's Inkscape::XML::Document std::set cloned_elements; + std::vector te_selected_style; + std::vector te_selected_style_positions; + int nr_blocks = 0; + unsigned copied_style_length = 0; + // we need a way to copy plain text AND remember its style; // the standard _clipnode is only available in an SVG tree, hence this special storage @@ -241,6 +246,9 @@ void ClipboardManagerImpl::copy(ObjectSet *set) sp_repr_css_attr_unref(_text_style); _text_style = NULL; } + te_selected_style.clear(); + te_selected_style_positions.clear(); + te_selected_style = Inkscape::UI::Tools::sp_text_get_selected_style(desktop->event_context, &copied_style_length, &nr_blocks, &te_selected_style_positions); _text_style = Inkscape::UI::Tools::sp_text_get_style_at_cursor(desktop->event_context); return; } @@ -983,7 +991,42 @@ bool ClipboardManagerImpl::_pasteText(SPDesktop *desktop) // if the text editing tool is active, paste the text into the active text object if (tools_isactive(desktop, TOOLS_TEXT)) { - return Inkscape::UI::Tools::sp_text_paste_inline(desktop->event_context); + if(Inkscape::UI::Tools::sp_text_paste_inline(desktop->event_context) == false) + return false; + //apply the saved style to pasted text + Glib::RefPtr refClipboard = Gtk::Clipboard::get(); + Glib::ustring const clip_text = refClipboard->wait_for_text(); + Glib::ustring text(clip_text); + if(text.length() == copied_style_length) + { + Inkscape::UI::Tools::TextTool *tc = SP_TEXT_CONTEXT(desktop->event_context); + Inkscape::Text::Layout const *layout = te_get_layout(tc->text); + Inkscape::Text::Layout::iterator it_next; + Inkscape::Text::Layout::iterator it = tc->text_sel_end; + + SPCSSAttr *css = take_style_from_item(tc->text); + for (int i = 0; i < nr_blocks; ++i) + { + gchar const *w = sp_repr_css_property(css, "font-size", "40px"); + if (w) + sp_repr_css_set_property(te_selected_style[i], "font-size", w); + } + + for (int i = 0; i < text.length(); ++i) + it.prevCharacter(); + it_next = layout->charIndexToIterator(layout->iteratorToCharIndex(it)); + + for (int i = 0; i < nr_blocks; ++i) + { + for (int j = te_selected_style_positions[i]; j < te_selected_style_positions[i+1]; ++j) + it_next.nextCharacter(); + sp_te_apply_style(tc->text, it, it_next, te_selected_style[i]); + te_update_layout_now_recursive(tc->text); + for (int j = te_selected_style_positions[i]; j < te_selected_style_positions[i+1]; ++j) + it.nextCharacter(); + } + } + return true; } // try to parse the text as a color and, if successful, apply it as the current style -- cgit v1.2.3 From 6b96232d171b4ba04567c096dbe9e65402eaa68f Mon Sep 17 00:00:00 2001 From: Alvin Penner Date: Sat, 22 Apr 2017 14:21:49 -0400 Subject: avoid double transform of element during copy. (Bug 1679428) Fixed bugs: - https://launchpad.net/bugs/1679428 (bzr r15631) --- src/ui/clipboard.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 734640584..3cc8ac098 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -708,7 +708,7 @@ void ClipboardManagerImpl::_copySelection(ObjectSet *selection) // (we're dealing with unattached representations, so we write to their attributes // instead of using sp_item_set_transform) SPUse *use=dynamic_cast(item); - if( use && selection->includes(use->get_original()) ){//we are copying something whose parent is also copied (!) + if( use && use->get_original() && use->get_original()->parent ){//we are copying something whose parent is also copied (!) transform = ((SPItem*)(use->get_original()->parent))->i2doc_affine().inverse() * transform; } gchar *transform_str = sp_svg_transform_write(transform ); -- cgit v1.2.3