From c099a73a820051490fe3afe6cd0b5731b8057e92 Mon Sep 17 00:00:00 2001 From: johanengelen Date: Fri, 6 Jul 2007 16:43:38 +0000 Subject: [PATCH] Fix #1740146. --- src/desktop.cpp | 2 +- src/display/canvas-axonomgrid.cpp | 22 +-- src/display/canvas-axonomgrid.h | 2 +- src/display/canvas-grid.cpp | 45 +++--- src/display/canvas-grid.h | 10 +- src/sp-namedview.cpp | 7 +- src/ui/dialog/document-properties.cpp | 8 +- src/ui/widget/registered-widget.cpp | 214 +++++++++++++++++--------- src/ui/widget/registered-widget.h | 23 ++- 9 files changed, 212 insertions(+), 121 deletions(-) diff --git a/src/desktop.cpp b/src/desktop.cpp index 03373b59e..859e15bd8 100644 --- a/src/desktop.cpp +++ b/src/desktop.cpp @@ -1154,7 +1154,7 @@ void SPDesktop::toggleGrid() } else { //there is no grid present at the moment. add a rectangular grid and make it visible Inkscape::XML::Node *repr = SP_OBJECT_REPR(namedview); - Inkscape::CanvasGrid::writeNewGridToRepr(repr, Inkscape::GRID_RECTANGULAR); + Inkscape::CanvasGrid::writeNewGridToRepr(repr, sp_desktop_document(this), Inkscape::GRID_RECTANGULAR); grids_visible = true; sp_canvas_item_show(SP_CANVAS_ITEM(gridgroup)); } diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index 311c56f44..17fa97281 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -195,8 +195,8 @@ attach_all (Gtk::Table &table, const Gtk::Widget *arr[], unsigned size, int star } } -CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr) - : CanvasGrid(nv, in_repr), table(1, 1) +CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc) + : CanvasGrid(nv, in_repr, in_doc), table(1, 1) { origin[NR::X] = origin[NR::Y] = 0.0; @@ -223,23 +223,23 @@ CanvasAxonomGrid::CanvasAxonomGrid (SPNamedView * nv, Inkscape::XML::Node * in_r table.set_spacings(2); vbox.pack_start(table, false, false, 0); - _rumg.init (_("Grid _units:"), "units", _wr, repr); + _rumg.init (_("Grid _units:"), "units", _wr, repr, doc); _rsu_ox.init (_("_Origin X:"), _("X coordinate of grid origin"), - "originx", _rumg, _wr, repr); + "originx", _rumg, _wr, repr, doc); _rsu_oy.init (_("O_rigin Y:"), _("Y coordinate of grid origin"), - "originy", _rumg, _wr, repr); + "originy", _rumg, _wr, repr, doc); _rsu_sy.init (_("Spacing _Y:"), _("Base length of z-axis"), - "spacingy", _rumg, _wr, repr); + "spacingy", _rumg, _wr, repr, doc); _rsu_ax.init (_("Angle X:"), _("Angle of x-axis"), - "gridanglex", _rumg, _wr, repr); + "gridanglex", _rumg, _wr, repr, doc); _rsu_az.init (_("Angle Z:"), _("Angle of z-axis"), - "gridanglez", _rumg, _wr, repr); + "gridanglez", _rumg, _wr, repr, doc); _rcp_gcol.init (_("Grid line _color:"), _("Grid line color"), - _("Color of grid lines"), "color", "opacity", _wr, repr); + _("Color of grid lines"), "color", "opacity", _wr, repr, doc); _rcp_gmcol.init (_("Ma_jor grid line color:"), _("Major grid line color"), _("Color of the major (highlighted) grid lines"), - "empcolor", "empopacity", _wr, repr); - _rsi.init (_("_Major grid line every:"), _("lines"), "empspacing", _wr, repr); + "empcolor", "empopacity", _wr, repr, doc); + _rsi.init (_("_Major grid line every:"), _("lines"), "empspacing", _wr, repr, doc); const Gtk::Widget* widget_array[] = { diff --git a/src/display/canvas-axonomgrid.h b/src/display/canvas-axonomgrid.h index 0eaf914de..157982416 100644 --- a/src/display/canvas-axonomgrid.h +++ b/src/display/canvas-axonomgrid.h @@ -33,7 +33,7 @@ namespace Inkscape { class CanvasAxonomGrid : public CanvasGrid { public: - CanvasAxonomGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr); + CanvasAxonomGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc); ~CanvasAxonomGrid(); void Update (NR::Matrix const &affine, unsigned int flags); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index e1cafb1fd..6c97e2605 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -150,9 +150,10 @@ grid_canvasitem_update (SPCanvasItem *item, NR::Matrix const &affine, unsigned i NULL /* order_changed */ }; -CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr) +CanvasGrid::CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc) { repr = in_repr; + doc = in_doc; if (repr) { repr->addListener (&_repr_events, this); } @@ -216,37 +217,41 @@ CanvasGrid::getGridTypeFromName(const char * typestr) * writes an child to repr. */ void -CanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, GridType gridtype) +CanvasGrid::writeNewGridToRepr(Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype) { if (!repr) return; if (gridtype > GRID_MAXTYPENR) return; // first create the child xml node, then hook it to repr. This order is important, to not set off listeners to repr before the new node is complete. - SPDocument *current_document = sp_desktop_document(SP_ACTIVE_DESKTOP); - Inkscape::XML::Document *xml_doc = sp_document_repr_doc(current_document); + Inkscape::XML::Document *xml_doc = sp_document_repr_doc(doc); Inkscape::XML::Node *newnode; newnode = xml_doc->createElement("inkscape:grid"); newnode->setAttribute("type", getSVGName(gridtype)); repr->appendChild(newnode); +// Inkscape::GC::release(repr); FIX THIS. THIS SHOULD BE HERE!!! - sp_document_done(current_document, SP_VERB_DIALOG_NAMEDVIEW, _("Create new grid")); + sp_document_done(doc, SP_VERB_DIALOG_NAMEDVIEW, _("Create new grid")); } /* * Creates a new CanvasGrid object of type gridtype */ CanvasGrid* -CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, GridType gridtype) +CanvasGrid::NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype) { - if (!in_repr) return NULL; + if (!repr) return NULL; + if (!doc) { + g_error("CanvasGrid::NewGrid - doc==NULL"); + return NULL; + } switch (gridtype) { case GRID_RECTANGULAR: - return (CanvasGrid*) new CanvasXYGrid(nv, in_repr); + return (CanvasGrid*) new CanvasXYGrid(nv, repr, doc); case GRID_AXONOMETRIC: - return (CanvasGrid*) new CanvasAxonomGrid(nv, in_repr); + return (CanvasGrid*) new CanvasAxonomGrid(nv, repr, doc); } return NULL; @@ -342,8 +347,8 @@ attach_all (Gtk::Table &table, const Gtk::Widget *arr[], unsigned size, int star } } -CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr) - : CanvasGrid(nv, in_repr), table(1, 1) +CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc) + : CanvasGrid(nv, in_repr, in_doc), table(1, 1) { origin[NR::X] = origin[NR::Y] = 0.0; color = DEFAULTGRIDCOLOR; @@ -360,24 +365,24 @@ CanvasXYGrid::CanvasXYGrid (SPNamedView * nv, Inkscape::XML::Node * in_repr) table.set_spacings(2); vbox.pack_start(table, false, false, 0); - _rumg.init (_("Grid _units:"), "units", _wr, repr); + _rumg.init (_("Grid _units:"), "units", _wr, repr, doc); _rsu_ox.init (_("_Origin X:"), _("X coordinate of grid origin"), - "originx", _rumg, _wr, repr); + "originx", _rumg, _wr, repr, doc); _rsu_oy.init (_("O_rigin Y:"), _("Y coordinate of grid origin"), - "originy", _rumg, _wr, repr); + "originy", _rumg, _wr, repr, doc); _rsu_sx.init (_("Spacing _X:"), _("Distance between vertical grid lines"), - "spacingx", _rumg, _wr, repr); + "spacingx", _rumg, _wr, repr, doc); _rsu_sy.init (_("Spacing _Y:"), _("Distance between horizontal grid lines"), - "spacingy", _rumg, _wr, repr); + "spacingy", _rumg, _wr, repr, doc); _rcp_gcol.init (_("Grid line _color:"), _("Grid line color"), - _("Color of grid lines"), "color", "opacity", _wr, repr); + _("Color of grid lines"), "color", "opacity", _wr, repr, doc); _rcp_gmcol.init (_("Ma_jor grid line color:"), _("Major grid line color"), _("Color of the major (highlighted) grid lines"), - "empcolor", "empopacity", _wr, repr); - _rsi.init (_("_Major grid line every:"), _("lines"), "empspacing", _wr, repr); + "empcolor", "empopacity", _wr, repr, doc); + _rsi.init (_("_Major grid line every:"), _("lines"), "empspacing", _wr, repr, doc); _rcb_dotted.init ( _("_Show dots instead of lines"), _("If set, displays dots at gridpoints instead of gridlines"), - "dotted", _wr, false, repr); + "dotted", _wr, false, repr, doc); const Gtk::Widget* widget_array[] = { diff --git a/src/display/canvas-grid.h b/src/display/canvas-grid.h index 046653df2..f3ffd7137 100644 --- a/src/display/canvas-grid.h +++ b/src/display/canvas-grid.h @@ -31,6 +31,7 @@ struct SPDesktop; struct SPNamedView; +class SPDocument; namespace Inkscape { @@ -66,7 +67,7 @@ GtkType grid_canvasitem_get_type (void); class CanvasGrid { public: - CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr); + CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc); virtual ~CanvasGrid(); static const char * getName(GridType type); @@ -74,8 +75,8 @@ public: static GridType getGridTypeFromSVGName(const char * typestr); static GridType getGridTypeFromName(const char * typestr); - static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, GridType gridtype); - static void writeNewGridToRepr(Inkscape::XML::Node * repr, GridType gridtype); + static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument *doc, GridType gridtype); + static void writeNewGridToRepr(Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype); GridCanvasItem * createCanvasItem(SPDesktop * desktop); @@ -88,6 +89,7 @@ public: virtual Gtk::Widget & getWidget() = 0; Inkscape::XML::Node * repr; + SPDocument *doc; Inkscape::Snapper* snapper; @@ -109,7 +111,7 @@ private: class CanvasXYGrid : public CanvasGrid { public: - CanvasXYGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr); + CanvasXYGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc); ~CanvasXYGrid(); void Update (NR::Matrix const &affine, unsigned int flags); diff --git a/src/sp-namedview.cpp b/src/sp-namedview.cpp index 02783207e..52d2f1189 100644 --- a/src/sp-namedview.cpp +++ b/src/sp-namedview.cpp @@ -431,7 +431,12 @@ sp_namedview_add_grid(SPNamedView *nv, Inkscape::XML::Node *repr, SPDesktop *des if (!grid) { //create grid object Inkscape::GridType gridtype = Inkscape::CanvasGrid::getGridTypeFromSVGName(repr->attribute("type")); - grid = Inkscape::CanvasGrid::NewGrid(nv, repr, gridtype); + SPDocument *doc = NULL; + if (desktop) + doc = sp_desktop_document(desktop); + else + doc = sp_desktop_document(static_cast(nv->views->data)); + grid = Inkscape::CanvasGrid::NewGrid(nv, repr, doc, gridtype); nv->grids = g_slist_append(nv->grids, grid); } diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 9bf2d761d..0817b06ab 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -529,10 +529,12 @@ on_doc_replaced (SPDesktop* dt, SPDocument* doc) void DocumentProperties::onNewGrid() { - Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP)); + SPDesktop *dt = SP_ACTIVE_DESKTOP; + Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt)); + SPDocument *doc = sp_desktop_document(dt); Glib::ustring typestring = _grids_combo_gridtype.get_active_text(); - CanvasGrid::writeNewGridToRepr(repr, CanvasGrid::getGridTypeFromName(typestring.c_str())); + CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str())); } @@ -564,7 +566,7 @@ DocumentProperties::onRemoveGrid() // delete the grid that corresponds with the selected tab // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer! found_grid->repr->parent()->removeChild(found_grid->repr); - sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid")); + sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid")); } } diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index 45ff46dc6..86c76b236 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -59,7 +59,7 @@ RegisteredCheckButton::~RegisteredCheckButton() } void -RegisteredCheckButton::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right, Inkscape::XML::Node* repr_in) +RegisteredCheckButton::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right, Inkscape::XML::Node* repr_in, SPDocument *doc_in) { _button = new Gtk::CheckButton; _tt.set_tip (*_button, tip); @@ -72,6 +72,9 @@ RegisteredCheckButton::init (const Glib::ustring& label, const Glib::ustring& ti _toggled_connection = _button->signal_toggled().connect (sigc::mem_fun (*this, &RegisteredCheckButton::on_toggled)); repr = repr_in; + doc = doc_in; + if (repr && !doc) // doc cannot be NULL when repr is not NULL + g_error("Initialization of registered widget using defined repr but with doc==NULL"); } void @@ -86,27 +89,28 @@ RegisteredCheckButton::on_toggled() if (_wr->isUpdating()) return; - SPDesktop *dt = SP_ACTIVE_DESKTOP; - if (!dt) { - return; + // Use local repr here. When repr is specified, use that one, but + // if repr==NULL, get the repr of namedview of active desktop. + Inkscape::XML::Node *local_repr = repr; + SPDocument *local_doc = doc; + if (!local_repr) { + // no repr specified, use active desktop's namedview's repr + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (!dt) + return; + local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); + local_doc = sp_desktop_document(dt); } - SPDocument *doc = sp_desktop_document(dt); - - //always get the obj.repr. of the current view, as the focus - //might have changed when multiple documents are open. Never - //use the old value of "repr" here - repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); - _wr->setUpdating (true); - bool saved = sp_document_get_undo_sensitive (doc); - sp_document_set_undo_sensitive (doc, false); - sp_repr_set_boolean(repr, _key.c_str(), _button->get_active()); - doc->rroot->setAttribute("sodipodi:modified", "true"); - sp_document_set_undo_sensitive (doc, saved); - sp_document_done (doc, SP_VERB_NONE, - /* TODO: annotate */ "registered-widget.cpp:103"); + bool saved = sp_document_get_undo_sensitive (local_doc); + sp_document_set_undo_sensitive (local_doc, false); + sp_repr_set_boolean(local_repr, _key.c_str(), _button->get_active()); + local_doc->rroot->setAttribute("sodipodi:modified", "true"); + sp_document_set_undo_sensitive (local_doc, saved); + sp_document_done (local_doc, SP_VERB_NONE, + /* TODO: annotate */ "registered-widget.cpp: RegisteredCheckButton::on_toggled"); _wr->setUpdating (false); } @@ -124,7 +128,7 @@ RegisteredUnitMenu::~RegisteredUnitMenu() } void -RegisteredUnitMenu::init (const Glib::ustring& label, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in) +RegisteredUnitMenu::init (const Glib::ustring& label, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) { _label = new Gtk::Label (label, 1.0, 0.5); _label->set_use_underline (true); @@ -136,6 +140,9 @@ RegisteredUnitMenu::init (const Glib::ustring& label, const Glib::ustring& key, _changed_connection = _sel->signal_changed().connect (sigc::mem_fun (*this, &RegisteredUnitMenu::on_changed)); repr = repr_in; + doc = doc_in; + if (repr && !doc) // doc cannot be NULL when repr is not NULL + g_warning("Initialization of registered widget using defined repr but with doc==NULL"); } void @@ -150,25 +157,31 @@ RegisteredUnitMenu::on_changed() if (_wr->isUpdating()) return; - SPDesktop *dt = SP_ACTIVE_DESKTOP; - if (!dt) - return; + // Use local repr here. When repr is specified, use that one, but + // if repr==NULL, get the repr of namedview of active desktop. + Inkscape::XML::Node *local_repr = repr; + SPDocument *local_doc = doc; + if (!local_repr) { + // no repr specified, use active desktop's namedview's repr + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (!dt) + return; + local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); + local_doc = sp_desktop_document(dt); + } Inkscape::SVGOStringStream os; os << _sel->getUnitAbbr(); _wr->setUpdating (true); - SPDocument *doc = sp_desktop_document(dt); - bool saved = sp_document_get_undo_sensitive (doc); - sp_document_set_undo_sensitive (doc, false); - if (!repr) - repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); - repr->setAttribute(_key.c_str(), os.str().c_str()); - doc->rroot->setAttribute("sodipodi:modified", "true"); - sp_document_set_undo_sensitive (doc, saved); - sp_document_done (doc, SP_VERB_NONE, - /* TODO: annotate */ "registered-widget.cpp:162"); + bool saved = sp_document_get_undo_sensitive (local_doc); + sp_document_set_undo_sensitive (local_doc, false); + local_repr->setAttribute(_key.c_str(), os.str().c_str()); + local_doc->rroot->setAttribute("sodipodi:modified", "true"); + sp_document_set_undo_sensitive (local_doc, saved); + sp_document_done (local_doc, SP_VERB_NONE, + /* TODO: annotate */ "registered-widget.cpp: RegisteredUnitMenu::on_changed"); _wr->setUpdating (false); } @@ -186,7 +199,7 @@ RegisteredScalarUnit::~RegisteredScalarUnit() } void -RegisteredScalarUnit::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr, Inkscape::XML::Node* repr_in) +RegisteredScalarUnit::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) { _widget = new ScalarUnit (label, tip, UNIT_TYPE_LINEAR, "", "", rum._sel); _widget->initScalar (-1e6, 1e6); @@ -198,6 +211,9 @@ RegisteredScalarUnit::init (const Glib::ustring& label, const Glib::ustring& tip _wr = ≀ repr = repr_in; + doc = doc_in; + if (repr && !doc) // doc cannot be NULL when repr is not NULL + g_warning("Initialization of registered widget using defined repr but with doc==NULL"); } ScalarUnit* @@ -219,9 +235,18 @@ RegisteredScalarUnit::on_value_changed() if (_wr->isUpdating()) return; - SPDesktop *dt = SP_ACTIVE_DESKTOP; - if (!dt) - return; + // Use local repr here. When repr is specified, use that one, but + // if repr==NULL, get the repr of namedview of active desktop. + Inkscape::XML::Node *local_repr = repr; + SPDocument *local_doc = doc; + if (!local_repr) { + // no repr specified, use active desktop's namedview's repr + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (!dt) + return; + local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); + local_doc = sp_desktop_document(dt); + } Inkscape::SVGOStringStream os; os << _widget->getValue(""); @@ -230,16 +255,13 @@ RegisteredScalarUnit::on_value_changed() _wr->setUpdating (true); - SPDocument *doc = sp_desktop_document(dt); - bool saved = sp_document_get_undo_sensitive (doc); - sp_document_set_undo_sensitive (doc, false); - if (!repr) - repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); - repr->setAttribute(_key.c_str(), os.str().c_str()); - doc->rroot->setAttribute("sodipodi:modified", "true"); - sp_document_set_undo_sensitive (doc, saved); - sp_document_done (doc, SP_VERB_NONE, - /* TODO: annotate */ "registered-widget.cpp:230"); + bool saved = sp_document_get_undo_sensitive (local_doc); + sp_document_set_undo_sensitive (local_doc, false); + local_repr->setAttribute(_key.c_str(), os.str().c_str()); + local_doc->rroot->setAttribute("sodipodi:modified", "true"); + sp_document_set_undo_sensitive (local_doc, saved); + sp_document_done (local_doc, SP_VERB_NONE, + /* TODO: annotate */ "registered-widget.cpp: RegisteredScalarUnit::on_value_changed"); _wr->setUpdating (false); } @@ -257,7 +279,7 @@ RegisteredColorPicker::~RegisteredColorPicker() } void -RegisteredColorPicker::init (const Glib::ustring& label, const Glib::ustring& title, const Glib::ustring& tip, const Glib::ustring& ckey, const Glib::ustring& akey, Registry& wr, Inkscape::XML::Node* repr_in) +RegisteredColorPicker::init (const Glib::ustring& label, const Glib::ustring& title, const Glib::ustring& tip, const Glib::ustring& ckey, const Glib::ustring& akey, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) { _label = new Gtk::Label (label, 1.0, 0.5); _label->set_use_underline (true); @@ -269,6 +291,9 @@ RegisteredColorPicker::init (const Glib::ustring& label, const Glib::ustring& ti _changed_connection = _cp->connectChanged (sigc::mem_fun (*this, &RegisteredColorPicker::on_changed)); repr = repr_in; + doc = doc_in; + if (repr && !doc) // doc cannot be NULL when repr is not NULL + g_warning("Initialization of registered widget using defined repr but with doc==NULL"); } void @@ -286,16 +311,35 @@ RegisteredColorPicker::closeWindow() void RegisteredColorPicker::on_changed (guint32 rgba) { - if (_wr->isUpdating() || !SP_ACTIVE_DESKTOP) + if (_wr->isUpdating()) return; _wr->setUpdating (true); - if (!repr) - repr = SP_OBJECT_REPR (sp_desktop_namedview(SP_ACTIVE_DESKTOP)); + + // Use local repr here. When repr is specified, use that one, but + // if repr==NULL, get the repr of namedview of active desktop. + Inkscape::XML::Node *local_repr = repr; + SPDocument *local_doc = doc; + if (!local_repr) { + // no repr specified, use active desktop's namedview's repr + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (!dt) + return; + local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); + local_doc = sp_desktop_document(dt); + } + gchar c[32]; sp_svg_write_color(c, 32, rgba); - repr->setAttribute(_ckey.c_str(), c); - sp_repr_set_css_double(repr, _akey.c_str(), (rgba & 0xff) / 255.0); + bool saved = sp_document_get_undo_sensitive (local_doc); + sp_document_set_undo_sensitive (local_doc, false); + local_repr->setAttribute(_ckey.c_str(), c); + sp_repr_set_css_double(local_repr, _akey.c_str(), (rgba & 0xff) / 255.0); + local_doc->rroot->setAttribute("sodipodi:modified", "true"); + sp_document_set_undo_sensitive (local_doc, saved); + sp_document_done (local_doc, SP_VERB_NONE, + /* TODO: annotate */ "registered-widget.cpp: RegisteredColorPicker::on_changed"); + _wr->setUpdating (false); } @@ -315,7 +359,7 @@ RegisteredSuffixedInteger::~RegisteredSuffixedInteger() } void -RegisteredSuffixedInteger::init (const Glib::ustring& label, const Glib::ustring& suffix, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in) +RegisteredSuffixedInteger::init (const Glib::ustring& label, const Glib::ustring& suffix, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) { _key = key; _label = new Gtk::Label (label); @@ -331,6 +375,9 @@ RegisteredSuffixedInteger::init (const Glib::ustring& label, const Glib::ustring _wr = ≀ repr = repr_in; + doc = doc_in; + if (repr && !doc) // doc cannot be NULL when repr is not NULL + g_warning("Initialization of registered widget using defined repr but with doc==NULL"); } void @@ -342,21 +389,31 @@ RegisteredSuffixedInteger::setValue (int i) void RegisteredSuffixedInteger::on_value_changed() { - if (_wr->isUpdating() || !SP_ACTIVE_DESKTOP) + if (_wr->isUpdating()) return; _wr->setUpdating (true); - SPDesktop* dt = SP_ACTIVE_DESKTOP; - if (!repr) - repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); + // Use local repr here. When repr is specified, use that one, but + // if repr==NULL, get the repr of namedview of active desktop. + Inkscape::XML::Node *local_repr = repr; + SPDocument *local_doc = doc; + if (!local_repr) { + // no repr specified, use active desktop's namedview's repr + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (!dt) + return; + local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); + local_doc = sp_desktop_document(dt); + } + Inkscape::SVGOStringStream os; int value = int(_adj.get_value()); os << value; - repr->setAttribute(_key.c_str(), os.str().c_str()); - sp_document_done(sp_desktop_document(dt), SP_VERB_NONE, - /* TODO: annotate */ "registered-widget.cpp:341"); + local_repr->setAttribute(_key.c_str(), os.str().c_str()); + sp_document_done(local_doc, SP_VERB_NONE, + /* TODO: annotate */ "registered-widget.cpp: RegisteredSuffixedInteger::on_value_changed"); _wr->setUpdating (false); } @@ -375,7 +432,7 @@ void RegisteredRadioButtonPair::init (const Glib::ustring& label, const Glib::ustring& label1, const Glib::ustring& label2, const Glib::ustring& tip1, const Glib::ustring& tip2, -const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in) +const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) { _hbox = new Gtk::HBox; _hbox->add (*manage (new Gtk::Label (label))); @@ -392,6 +449,9 @@ const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in) _changed_connection = _rb1->signal_toggled().connect (sigc::mem_fun (*this, &RegisteredRadioButtonPair::on_value_changed)); repr = repr_in; + doc = doc_in; + if (repr && !doc) // doc cannot be NULL when repr is not NULL + g_error("Initialization of registered widget using defined repr but with doc==NULL"); } void @@ -407,23 +467,29 @@ RegisteredRadioButtonPair::on_value_changed() if (_wr->isUpdating()) return; - SPDesktop *dt = SP_ACTIVE_DESKTOP; - if (!dt) - return; + // Use local repr here. When repr is specified, use that one, but + // if repr==NULL, get the repr of namedview of active desktop. + Inkscape::XML::Node *local_repr = repr; + SPDocument *local_doc = doc; + if (!local_repr) { + // no repr specified, use active desktop's namedview's repr + SPDesktop *dt = SP_ACTIVE_DESKTOP; + if (!dt) + return; + local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); + local_doc = sp_desktop_document(dt); + } _wr->setUpdating (true); bool second = _rb2->get_active(); - SPDocument *doc = sp_desktop_document(dt); - bool saved = sp_document_get_undo_sensitive (doc); - sp_document_set_undo_sensitive (doc, false); - if (!repr) - repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); - repr->setAttribute(_key.c_str(), second ? "true" : "false"); - doc->rroot->setAttribute("sodipodi:modified", "true"); - sp_document_set_undo_sensitive (doc, saved); - sp_document_done (doc, SP_VERB_NONE, - /* TODO: annotate */ "registered-widget.cpp:405"); + bool saved = sp_document_get_undo_sensitive (local_doc); + sp_document_set_undo_sensitive (local_doc, false); + local_repr->setAttribute(_key.c_str(), second ? "true" : "false"); + local_doc->rroot->setAttribute("sodipodi:modified", "true"); + sp_document_set_undo_sensitive (local_doc, saved); + sp_document_done (local_doc, SP_VERB_NONE, + /* TODO: annotate */ "registered-widget.cpp: RegisteredRadioButtonPair::on_value_changed"); _wr->setUpdating (false); } diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 2b92d204d..43588a831 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -16,6 +16,7 @@ #include class SPUnit; +class SPDocument; namespace Gtk { class HScale; @@ -37,7 +38,7 @@ class RegisteredCheckButton { public: RegisteredCheckButton(); ~RegisteredCheckButton(); - void init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right=true, Inkscape::XML::Node* repr_in=NULL); + void init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right=true, Inkscape::XML::Node* repr_in=NULL, SPDocument *doc_in=NULL); void setActive (bool); Gtk::ToggleButton *_button; @@ -49,13 +50,14 @@ protected: Glib::ustring _key; void on_toggled(); Inkscape::XML::Node *repr; + SPDocument *doc; }; class RegisteredUnitMenu { public: RegisteredUnitMenu(); ~RegisteredUnitMenu(); - void init (const Glib::ustring& label, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in=NULL); + void init (const Glib::ustring& label, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in=NULL, SPDocument *doc_in=NULL); void setUnit (const SPUnit*); Gtk::Label *_label; UnitMenu *_sel; @@ -66,6 +68,7 @@ protected: Registry *_wr; Glib::ustring _key; Inkscape::XML::Node *repr; + SPDocument *doc; }; class RegisteredScalarUnit { @@ -77,7 +80,8 @@ public: const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr, - Inkscape::XML::Node* repr_in=NULL); + Inkscape::XML::Node* repr_in=NULL, + SPDocument *doc_in=NULL); ScalarUnit* getSU(); void setValue (double); @@ -89,6 +93,7 @@ protected: Glib::ustring _key; void on_value_changed(); Inkscape::XML::Node *repr; + SPDocument *doc; }; class RegisteredColorPicker { @@ -101,7 +106,8 @@ public: const Glib::ustring& ckey, const Glib::ustring& akey, Registry& wr, - Inkscape::XML::Node* repr_in=NULL); + Inkscape::XML::Node* repr_in=NULL, + SPDocument *doc_in=NULL); void setRgba32 (guint32); void closeWindow(); @@ -114,6 +120,7 @@ protected: void on_changed (guint32); sigc::connection _changed_connection; Inkscape::XML::Node *repr; + SPDocument *doc; }; class RegisteredSuffixedInteger { @@ -124,7 +131,8 @@ public: const Glib::ustring& label2, const Glib::ustring& key, Registry& wr, - Inkscape::XML::Node* repr_in=NULL); + Inkscape::XML::Node* repr_in=NULL, + SPDocument *doc_in=NULL); void setValue (int); Gtk::Label *_label; Gtk::HBox _hbox; @@ -138,6 +146,7 @@ protected: sigc::connection _changed_connection; void on_value_changed(); Inkscape::XML::Node *repr; + SPDocument *doc; }; class RegisteredRadioButtonPair { @@ -151,7 +160,8 @@ public: const Glib::ustring& tip2, const Glib::ustring& key, Registry& wr, - Inkscape::XML::Node* repr_in=NULL); + Inkscape::XML::Node* repr_in=NULL, + SPDocument *doc_in=NULL); void setValue (bool second); Gtk::HBox *_hbox; @@ -163,6 +173,7 @@ protected: sigc::connection _changed_connection; void on_value_changed(); Inkscape::XML::Node *repr; + SPDocument *doc; }; -- 2.30.2