summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c28b128)
raw | patch | inline | side by side (parent: c28b128)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Fri, 6 Jul 2007 16:43:38 +0000 (16:43 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Fri, 6 Jul 2007 16:43:38 +0000 (16:43 +0000) |
diff --git a/src/desktop.cpp b/src/desktop.cpp
index 03373b59e9d22ba605bcfe8ebabb50357936c16d..859e15bd830280b45628042f99930dc393721f63 100644 (file)
--- a/src/desktop.cpp
+++ b/src/desktop.cpp
} 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));
}
index 311c56f4497fa331d8c73ae34977e36b03875857..17fa97281da8f44c7b5d205f81dc5a9b16753758 100644 (file)
@@ -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[] =
{
index 0eaf914de01f41d981275c73178aac69bee76c2e..157982416a2c58fe9572d6969d2848ad0faf5cf0 100644 (file)
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);
index e1cafb1fd6df240102481ce4d013c3d4a876f3e8..6c97e260594936025172c46e88a9d06fc6c62374 100644 (file)
@@ -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);
}
* writes an <inkscape:grid> 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;
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[] =
{
index 046653df2e3ae98e20cb153e2afab9b3dcf757bd..f3ffd7137f10f044e7a5193ab2fc7d209828eed7 100644 (file)
struct SPDesktop;
struct SPNamedView;
+class SPDocument;
namespace Inkscape {
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);
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);
virtual Gtk::Widget & getWidget() = 0;
Inkscape::XML::Node * repr;
+ SPDocument *doc;
Inkscape::Snapper* snapper;
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 02783207ea104ae0f29744e4070a82f1ecdd8fe0..52d2f1189d3b9c2be4fece48c51bd3a40274d31a 100644 (file)
--- 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<SPDesktop*>(nv->views->data));
+ grid = Inkscape::CanvasGrid::NewGrid(nv, repr, doc, gridtype);
nv->grids = g_slist_append(nv->grids, grid);
}
index 9bf2d761d2c9eb9278079365c17c7aa8012fe010..0817b06aba7418c8e5cb774cf6fcf2ed1fdd5f4c 100644 (file)
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()));
}
// 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"));
}
}
index 45ff46dc6ab37f6d759c3f46e437e4fe13df577b..86c76b2361fd230ca6aa5635d05357b6d25602a0 100644 (file)
}
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);
_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
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);
}
}
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);
_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
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);
}
}
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*
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("");
_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);
}
}
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
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);
}
}
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
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);
}
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)));
_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
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);
}
index 2b92d204d5be640f609d3c6ffb668aac49351ca3..43588a8314c268ec13f6ba8a5d514d47caa7831e 100644 (file)
#include <gtkmm/adjustment.h>
class SPUnit;
+class SPDocument;
namespace Gtk {
class HScale;
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;
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;
Registry *_wr;
Glib::ustring _key;
Inkscape::XML::Node *repr;
+ SPDocument *doc;
};
class RegisteredScalarUnit {
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);
Glib::ustring _key;
void on_value_changed();
Inkscape::XML::Node *repr;
+ SPDocument *doc;
};
class RegisteredColorPicker {
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();
void on_changed (guint32);
sigc::connection _changed_connection;
Inkscape::XML::Node *repr;
+ SPDocument *doc;
};
class RegisteredSuffixedInteger {
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;
sigc::connection _changed_connection;
void on_value_changed();
Inkscape::XML::Node *repr;
+ SPDocument *doc;
};
class RegisteredRadioButtonPair {
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;
sigc::connection _changed_connection;
void on_value_changed();
Inkscape::XML::Node *repr;
+ SPDocument *doc;
};