From a6fa3b454bdcef9b23e0a3107b6de6b4c6a477a0 Mon Sep 17 00:00:00 2001 From: johnce Date: Wed, 5 Aug 2009 05:56:35 +0000 Subject: SPDocument->Document (bzr r8405) --- src/ui/clipboard.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 7e41006be..e7e8a29dc 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -126,13 +126,13 @@ private: void _copyTextPath(SPTextPath *); Inkscape::XML::Node *_copyNode(Inkscape::XML::Node *, Inkscape::XML::Document *, Inkscape::XML::Node *); - void _pasteDocument(SPDocument *, bool in_place); - void _pasteDefs(SPDocument *); + void _pasteDocument(Document *, bool in_place); + void _pasteDefs(Document *); bool _pasteImage(); bool _pasteText(); SPCSSAttr *_parseColor(const Glib::ustring &); void _applyPathEffect(SPItem *, gchar const *); - SPDocument *_retrieveClipboard(Glib::ustring = ""); + Document *_retrieveClipboard(Glib::ustring = ""); // clipboard callbacks void _onGet(Gtk::SelectionData &, guint); @@ -149,7 +149,7 @@ private: void _userWarn(SPDesktop *, char const *); // private properites - SPDocument *_clipboardSPDoc; ///< Document that stores the clipboard until someone requests it + Document *_clipboardSPDoc; ///< Document that stores the clipboard until someone requests it Inkscape::XML::Node *_defs; ///< Reference to the clipboard document's defs node Inkscape::XML::Node *_root; ///< Reference to the clipboard's root node Inkscape::XML::Node *_clipnode; ///< The node that holds extra information @@ -311,7 +311,7 @@ bool ClipboardManagerImpl::paste(bool in_place) if ( target == CLIPBOARD_TEXT_TARGET ) return _pasteText(); // otherwise, use the import extensions - SPDocument *tempdoc = _retrieveClipboard(target); + Document *tempdoc = _retrieveClipboard(target); if ( tempdoc == NULL ) { _userWarn(desktop, _("Nothing on the clipboard.")); return false; @@ -328,7 +328,7 @@ bool ClipboardManagerImpl::paste(bool in_place) */ const gchar *ClipboardManagerImpl::getFirstObjectID() { - SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); + Document *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc == NULL ) { return NULL; } @@ -373,7 +373,7 @@ bool ClipboardManagerImpl::pasteStyle() return false; } - SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); + Document *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc == NULL ) { // no document, but we can try _text_style if (_text_style) { @@ -425,7 +425,7 @@ bool ClipboardManagerImpl::pasteSize(bool separately, bool apply_x, bool apply_y } // FIXME: actually, this should accept arbitrary documents - SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); + Document *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc == NULL ) { _userWarn(desktop, _("No size on the clipboard.")); return false; @@ -482,7 +482,7 @@ bool ClipboardManagerImpl::pastePathEffect() return false; } - SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); + Document *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc ) { Inkscape::XML::Node *root = sp_document_repr_root(tempdoc); Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1); @@ -513,7 +513,7 @@ bool ClipboardManagerImpl::pastePathEffect() */ Glib::ustring ClipboardManagerImpl::getPathParameter() { - SPDocument *tempdoc = _retrieveClipboard(); // any target will do here + Document *tempdoc = _retrieveClipboard(); // any target will do here if ( tempdoc == NULL ) { _userWarn(SP_ACTIVE_DESKTOP, _("Nothing on the clipboard.")); return ""; @@ -537,7 +537,7 @@ Glib::ustring ClipboardManagerImpl::getPathParameter() */ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId() { - SPDocument *tempdoc = _retrieveClipboard(); // any target will do here + Document *tempdoc = _retrieveClipboard(); // any target will do here if ( tempdoc == NULL ) { _userWarn(SP_ACTIVE_DESKTOP, _("Nothing on the clipboard.")); return ""; @@ -769,10 +769,10 @@ Inkscape::XML::Node *ClipboardManagerImpl::_copyNode(Inkscape::XML::Node *node, * @param in_place Whether to paste the selection where it was when copied * @pre @c clipdoc is not empty and items can be added to the current layer */ -void ClipboardManagerImpl::_pasteDocument(SPDocument *clipdoc, bool in_place) +void ClipboardManagerImpl::_pasteDocument(Document *clipdoc, bool in_place) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SPDocument *target_document = sp_desktop_document(desktop); + Document *target_document = sp_desktop_document(desktop); Inkscape::XML::Node *root = sp_document_repr_root(clipdoc), *target_parent = SP_OBJECT_REPR(desktop->currentLayer()); @@ -839,11 +839,11 @@ void ClipboardManagerImpl::_pasteDocument(SPDocument *clipdoc, bool in_place) * @param clipdoc The document to paste * @pre @c clipdoc != NULL and pasting into the active document is possible */ -void ClipboardManagerImpl::_pasteDefs(SPDocument *clipdoc) +void ClipboardManagerImpl::_pasteDefs(Document *clipdoc) { // boilerplate vars copied from _pasteDocument SPDesktop *desktop = SP_ACTIVE_DESKTOP; - SPDocument *target_document = sp_desktop_document(desktop); + Document *target_document = sp_desktop_document(desktop); Inkscape::XML::Node *root = sp_document_repr_root(clipdoc), *defs = sp_repr_lookup_name(root, "svg:defs", 1), @@ -863,7 +863,7 @@ void ClipboardManagerImpl::_pasteDefs(SPDocument *clipdoc) */ bool ClipboardManagerImpl::_pasteImage() { - SPDocument *doc = SP_ACTIVE_DOCUMENT; + Document *doc = SP_ACTIVE_DOCUMENT; if ( doc == NULL ) return false; // retrieve image data @@ -993,9 +993,9 @@ void ClipboardManagerImpl::_applyPathEffect(SPItem *item, gchar const *effect) /** * @brief Retrieve the clipboard contents as a document - * @return Clipboard contents converted to SPDocument, or NULL if no suitable content was present + * @return Clipboard contents converted to Document, or NULL if no suitable content was present */ -SPDocument *ClipboardManagerImpl::_retrieveClipboard(Glib::ustring required_target) +Document *ClipboardManagerImpl::_retrieveClipboard(Glib::ustring required_target) { Glib::ustring best_target; if ( required_target == "" ) @@ -1061,7 +1061,7 @@ SPDocument *ClipboardManagerImpl::_retrieveClipboard(Glib::ustring required_targ if ( in == inlist.end() ) return NULL; // this shouldn't happen unless _getBestTarget returns something bogus - SPDocument *tempdoc = NULL; + Document *tempdoc = NULL; try { tempdoc = (*in)->open(filename); } catch (...) { -- cgit v1.2.3 From 51c2905fd3e99955db2d823b79abb763d8097028 Mon Sep 17 00:00:00 2001 From: Maximilian Albert Date: Thu, 6 Aug 2009 14:17:17 +0000 Subject: Revert recent refactoring changes by johnce because they break the build, which cannot be fixed easily. (bzr r8422) --- src/ui/clipboard.cpp | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index e7e8a29dc..7e41006be 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -126,13 +126,13 @@ private: void _copyTextPath(SPTextPath *); Inkscape::XML::Node *_copyNode(Inkscape::XML::Node *, Inkscape::XML::Document *, Inkscape::XML::Node *); - void _pasteDocument(Document *, bool in_place); - void _pasteDefs(Document *); + void _pasteDocument(SPDocument *, bool in_place); + void _pasteDefs(SPDocument *); bool _pasteImage(); bool _pasteText(); SPCSSAttr *_parseColor(const Glib::ustring &); void _applyPathEffect(SPItem *, gchar const *); - Document *_retrieveClipboard(Glib::ustring = ""); + SPDocument *_retrieveClipboard(Glib::ustring = ""); // clipboard callbacks void _onGet(Gtk::SelectionData &, guint); @@ -149,7 +149,7 @@ private: void _userWarn(SPDesktop *, char const *); // private properites - Document *_clipboardSPDoc; ///< Document that stores the clipboard until someone requests it + SPDocument *_clipboardSPDoc; ///< Document that stores the clipboard until someone requests it Inkscape::XML::Node *_defs; ///< Reference to the clipboard document's defs node Inkscape::XML::Node *_root; ///< Reference to the clipboard's root node Inkscape::XML::Node *_clipnode; ///< The node that holds extra information @@ -311,7 +311,7 @@ bool ClipboardManagerImpl::paste(bool in_place) if ( target == CLIPBOARD_TEXT_TARGET ) return _pasteText(); // otherwise, use the import extensions - Document *tempdoc = _retrieveClipboard(target); + SPDocument *tempdoc = _retrieveClipboard(target); if ( tempdoc == NULL ) { _userWarn(desktop, _("Nothing on the clipboard.")); return false; @@ -328,7 +328,7 @@ bool ClipboardManagerImpl::paste(bool in_place) */ const gchar *ClipboardManagerImpl::getFirstObjectID() { - Document *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); + SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc == NULL ) { return NULL; } @@ -373,7 +373,7 @@ bool ClipboardManagerImpl::pasteStyle() return false; } - Document *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); + SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc == NULL ) { // no document, but we can try _text_style if (_text_style) { @@ -425,7 +425,7 @@ bool ClipboardManagerImpl::pasteSize(bool separately, bool apply_x, bool apply_y } // FIXME: actually, this should accept arbitrary documents - Document *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); + SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc == NULL ) { _userWarn(desktop, _("No size on the clipboard.")); return false; @@ -482,7 +482,7 @@ bool ClipboardManagerImpl::pastePathEffect() return false; } - Document *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); + SPDocument *tempdoc = _retrieveClipboard("image/x-inkscape-svg"); if ( tempdoc ) { Inkscape::XML::Node *root = sp_document_repr_root(tempdoc); Inkscape::XML::Node *clipnode = sp_repr_lookup_name(root, "inkscape:clipboard", 1); @@ -513,7 +513,7 @@ bool ClipboardManagerImpl::pastePathEffect() */ Glib::ustring ClipboardManagerImpl::getPathParameter() { - Document *tempdoc = _retrieveClipboard(); // any target will do here + SPDocument *tempdoc = _retrieveClipboard(); // any target will do here if ( tempdoc == NULL ) { _userWarn(SP_ACTIVE_DESKTOP, _("Nothing on the clipboard.")); return ""; @@ -537,7 +537,7 @@ Glib::ustring ClipboardManagerImpl::getPathParameter() */ Glib::ustring ClipboardManagerImpl::getShapeOrTextObjectId() { - Document *tempdoc = _retrieveClipboard(); // any target will do here + SPDocument *tempdoc = _retrieveClipboard(); // any target will do here if ( tempdoc == NULL ) { _userWarn(SP_ACTIVE_DESKTOP, _("Nothing on the clipboard.")); return ""; @@ -769,10 +769,10 @@ Inkscape::XML::Node *ClipboardManagerImpl::_copyNode(Inkscape::XML::Node *node, * @param in_place Whether to paste the selection where it was when copied * @pre @c clipdoc is not empty and items can be added to the current layer */ -void ClipboardManagerImpl::_pasteDocument(Document *clipdoc, bool in_place) +void ClipboardManagerImpl::_pasteDocument(SPDocument *clipdoc, bool in_place) { SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Document *target_document = sp_desktop_document(desktop); + SPDocument *target_document = sp_desktop_document(desktop); Inkscape::XML::Node *root = sp_document_repr_root(clipdoc), *target_parent = SP_OBJECT_REPR(desktop->currentLayer()); @@ -839,11 +839,11 @@ void ClipboardManagerImpl::_pasteDocument(Document *clipdoc, bool in_place) * @param clipdoc The document to paste * @pre @c clipdoc != NULL and pasting into the active document is possible */ -void ClipboardManagerImpl::_pasteDefs(Document *clipdoc) +void ClipboardManagerImpl::_pasteDefs(SPDocument *clipdoc) { // boilerplate vars copied from _pasteDocument SPDesktop *desktop = SP_ACTIVE_DESKTOP; - Document *target_document = sp_desktop_document(desktop); + SPDocument *target_document = sp_desktop_document(desktop); Inkscape::XML::Node *root = sp_document_repr_root(clipdoc), *defs = sp_repr_lookup_name(root, "svg:defs", 1), @@ -863,7 +863,7 @@ void ClipboardManagerImpl::_pasteDefs(Document *clipdoc) */ bool ClipboardManagerImpl::_pasteImage() { - Document *doc = SP_ACTIVE_DOCUMENT; + SPDocument *doc = SP_ACTIVE_DOCUMENT; if ( doc == NULL ) return false; // retrieve image data @@ -993,9 +993,9 @@ void ClipboardManagerImpl::_applyPathEffect(SPItem *item, gchar const *effect) /** * @brief Retrieve the clipboard contents as a document - * @return Clipboard contents converted to Document, or NULL if no suitable content was present + * @return Clipboard contents converted to SPDocument, or NULL if no suitable content was present */ -Document *ClipboardManagerImpl::_retrieveClipboard(Glib::ustring required_target) +SPDocument *ClipboardManagerImpl::_retrieveClipboard(Glib::ustring required_target) { Glib::ustring best_target; if ( required_target == "" ) @@ -1061,7 +1061,7 @@ Document *ClipboardManagerImpl::_retrieveClipboard(Glib::ustring required_target if ( in == inlist.end() ) return NULL; // this shouldn't happen unless _getBestTarget returns something bogus - Document *tempdoc = NULL; + SPDocument *tempdoc = NULL; try { tempdoc = (*in)->open(filename); } catch (...) { -- cgit v1.2.3 From 7b3237cbf5257dd132588e41fc86585d9cb26de3 Mon Sep 17 00:00:00 2001 From: Josh Andler Date: Mon, 14 Sep 2009 05:02:10 +0000 Subject: Patch from Diedrik for 296778 (bzr r8590) --- src/ui/clipboard.cpp | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'src/ui/clipboard.cpp') diff --git a/src/ui/clipboard.cpp b/src/ui/clipboard.cpp index 7e41006be..af0ec0129 100644 --- a/src/ui/clipboard.cpp +++ b/src/ui/clipboard.cpp @@ -148,6 +148,8 @@ private: void _setClipboardColor(guint32); void _userWarn(SPDesktop *, char const *); + void _inkscape_wait_for_targets(std::list &); + // private properites SPDocument *_clipboardSPDoc; ///< Document that stores the clipboard until someone requests it Inkscape::XML::Node *_defs; ///< Reference to the clipboard document's defs node @@ -1226,7 +1228,9 @@ Geom::Scale ClipboardManagerImpl::_getScale(Geom::Point const &min, Geom::Point */ Glib::ustring ClipboardManagerImpl::_getBestTarget() { - std::list targets = _clipboard->wait_for_targets(); + // GTKmm's wait_for_targets() is broken, see the comment in _inkscape_wait_for_targets() + std::list targets; // = _clipboard->wait_for_targets(); + _inkscape_wait_for_targets(targets); // clipboard target debugging snippet /* @@ -1365,6 +1369,35 @@ void ClipboardManagerImpl::_userWarn(SPDesktop *desktop, char const *msg) } +// GTKMM's clipboard::wait_for_targets is buggy and might return bogus, see +// +// https://bugs.launchpad.net/inkscape/+bug/296778 +// http://mail.gnome.org/archives/gtk-devel-list/2009-June/msg00062.html +// +// for details. Until this has been fixed upstream we will use our own implementation +// of this method, as copied from /gtkmm-2.16.0/gtk/gtkmm/clipboard.cc. +void ClipboardManagerImpl::_inkscape_wait_for_targets(std::list &listTargets) +{ + //Get a newly-allocated array of atoms: + GdkAtom* targets = 0; + gint n_targets = 0; + gboolean test = gtk_clipboard_wait_for_targets( gtk_clipboard_get(GDK_SELECTION_CLIPBOARD), &targets, &n_targets ); + if(!test) + n_targets = 0; //otherwise it will be -1. + + //Add the targets to the C++ container: + for(int i = 0; i < n_targets; i++) + { + //Convert the atom to a string: + gchar* const atom_name = gdk_atom_name(targets[i]); + + Glib::ustring target; + if(atom_name) + target = Glib::ScopedPtr(atom_name).get(); //This frees the gchar*. + + listTargets.push_back(target); + } +} /* ####################################### ClipboardManager class -- cgit v1.2.3