From: johanengelen Date: Wed, 27 Feb 2008 09:35:01 +0000 (+0000) Subject: Convert remaining old RegisteredWdg's to RegisteredWidget's. Removed RegisteredWdg. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a00d0714a57eef2a5d1c5dcc7d4c57885b393180;p=inkscape.git Convert remaining old RegisteredWdg's to RegisteredWidget's. Removed RegisteredWdg. --- diff --git a/src/display/canvas-axonomgrid.cpp b/src/display/canvas-axonomgrid.cpp index f53125731..f48648d18 100644 --- a/src/display/canvas-axonomgrid.cpp +++ b/src/display/canvas-axonomgrid.cpp @@ -386,10 +386,14 @@ CanvasAxonomGrid::newSpecificWidget() _wr.setUpdating (true); - Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = new Inkscape::UI::Widget::RegisteredUnitMenu(); - Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = new Inkscape::UI::Widget::RegisteredScalarUnit(); - Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = new Inkscape::UI::Widget::RegisteredScalarUnit(); - Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = new Inkscape::UI::Widget::RegisteredScalarUnit(); + Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu( + _("Grid _units:"), "units", _wr, repr, doc) ); + Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( + _("_Origin X:"), _("X coordinate of grid origin"), "originx", *_rumg, _wr, repr, doc) ); + Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( + _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", *_rumg, _wr, repr, doc) ); + Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( + _("Spacing _Y:"), _("Base length of z-axis"), "spacingy", *_rumg, _wr, repr, doc) ); Inkscape::UI::Widget::RegisteredScalar *_rsu_ax = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( _("Angle X:"), _("Angle of x-axis"), "gridanglex", _wr, repr, doc ) ); Inkscape::UI::Widget::RegisteredScalar *_rsu_az = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalar( @@ -406,39 +410,31 @@ _wr.setUpdating (true); _("Color of the major (highlighted) grid lines"), "empcolor", "empopacity", _wr, repr, doc)); - Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = new Inkscape::UI::Widget::RegisteredSuffixedInteger(); - - Inkscape::UI::Widget::ScalarUnit * sutemp = NULL; - _rumg->init (_("Grid _units:"), "units", _wr, repr, doc); - _rsu_ox->init (_("_Origin X:"), _("X coordinate of grid origin"), - "originx", *_rumg, _wr, repr, doc); - sutemp = _rsu_ox->getSU(); - sutemp->setDigits(4); - sutemp->setIncrements(0.1, 1.0); - _rsu_oy->init (_("O_rigin Y:"), _("Y coordinate of grid origin"), - "originy", *_rumg, _wr, repr, doc); - sutemp = _rsu_oy->getSU(); - sutemp->setDigits(4); - sutemp->setIncrements(0.1, 1.0); - _rsu_sy->init (_("Spacing _Y:"), _("Base length of z-axis"), - "spacingy", *_rumg, _wr, repr, doc); - sutemp = _rsu_sy->getSU(); - sutemp->setDigits(4); - sutemp->setIncrements(0.1, 1.0); - _rsi->init (_("_Major grid line every:"), _("lines"), "empspacing", _wr, repr, doc); + Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = Gtk::manage( new Inkscape::UI::Widget::RegisteredSuffixedInteger( + _("_Major grid line every:"), _(""), _("lines"), "empspacing", _wr, repr, doc ) ); + + _rsu_ox->setDigits(4); + _rsu_ox->setIncrements(0.1, 1.0); + + _rsu_oy->setDigits(4); + _rsu_oy->setIncrements(0.1, 1.0); + + _rsu_sy->setDigits(4); + _rsu_sy->setIncrements(0.1, 1.0); + _wr.setUpdating (false); Gtk::Widget const *const widget_array[] = { - _rumg->_label, _rumg->_sel, - 0, _rsu_ox->getSU(), - 0, _rsu_oy->getSU(), - 0, _rsu_sy->getSU(), + 0, _rumg, + 0, _rsu_ox, + 0, _rsu_oy, + 0, _rsu_sy, 0, _rsu_ax, 0, _rsu_az, _rcp_gcol->_label, _rcp_gcol, 0, 0, _rcp_gmcol->_label, _rcp_gmcol, - _rsi->_label, &_rsi->_hbox, + 0, _rsi, }; attach_all (*table, widget_array, sizeof(widget_array)); diff --git a/src/display/canvas-grid.cpp b/src/display/canvas-grid.cpp index 245c78eca..6ac2b4f0e 100644 --- a/src/display/canvas-grid.cpp +++ b/src/display/canvas-grid.cpp @@ -652,11 +652,16 @@ CanvasXYGrid::newSpecificWidget() { Gtk::Table * table = Gtk::manage( new Gtk::Table(1,1) ); - Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = new Inkscape::UI::Widget::RegisteredUnitMenu(); - Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = new Inkscape::UI::Widget::RegisteredScalarUnit(); - Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = new Inkscape::UI::Widget::RegisteredScalarUnit(); - Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sx = new Inkscape::UI::Widget::RegisteredScalarUnit(); - Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = new Inkscape::UI::Widget::RegisteredScalarUnit(); + Inkscape::UI::Widget::RegisteredUnitMenu *_rumg = Gtk::manage( new Inkscape::UI::Widget::RegisteredUnitMenu( + _("Grid _units:"), "units", _wr, repr, doc) ); + Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_ox = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( + _("_Origin X:"), _("X coordinate of grid origin"), "originx", *_rumg, _wr, repr, doc) ); + Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_oy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( + _("O_rigin Y:"), _("Y coordinate of grid origin"), "originy", *_rumg, _wr, repr, doc) ); + Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sx = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( + _("Spacing _X:"), _("Distance between vertical grid lines"), "spacingx", *_rumg, _wr, repr, doc) ); + Inkscape::UI::Widget::RegisteredScalarUnit *_rsu_sy = Gtk::manage( new Inkscape::UI::Widget::RegisteredScalarUnit( + _("Spacing _Y:"), _("Distance between horizontal grid lines"), "spacingy", *_rumg, _wr, repr, doc) ); Inkscape::UI::Widget::RegisteredColorPicker *_rcp_gcol = Gtk::manage( new Inkscape::UI::Widget::RegisteredColorPicker( @@ -669,54 +674,41 @@ CanvasXYGrid::newSpecificWidget() _("Color of the major (highlighted) grid lines"), "empcolor", "empopacity", _wr, repr, doc)); - Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = new Inkscape::UI::Widget::RegisteredSuffixedInteger(); + Inkscape::UI::Widget::RegisteredSuffixedInteger *_rsi = Gtk::manage( new Inkscape::UI::Widget::RegisteredSuffixedInteger( + _("_Major grid line every:"), _(""), _("lines"), "empspacing", _wr, repr, doc) ); - // initialize widgets: table->set_spacings(2); _wr.setUpdating (true); - Inkscape::UI::Widget::ScalarUnit * sutemp; - _rumg->init (_("Grid _units:"), "units", _wr, repr, doc); - _rsu_ox->init (_("_Origin X:"), _("X coordinate of grid origin"), - "originx", *_rumg, _wr, repr, doc); - sutemp = _rsu_ox->getSU(); - sutemp->setDigits(4); - sutemp->setIncrements(0.1, 1.0); - _rsu_oy->init (_("O_rigin Y:"), _("Y coordinate of grid origin"), - "originy", *_rumg, _wr, repr, doc); - sutemp = _rsu_oy->getSU(); - sutemp->setDigits(4); - sutemp->setIncrements(0.1, 1.0); - _rsu_sx->init (_("Spacing _X:"), _("Distance between vertical grid lines"), - "spacingx", *_rumg, _wr, repr, doc); - sutemp = _rsu_sx->getSU(); - sutemp->setDigits(4); - sutemp->setIncrements(0.1, 1.0); - _rsu_sy->init (_("Spacing _Y:"), _("Distance between horizontal grid lines"), - "spacingy", *_rumg, _wr, repr, doc); - sutemp = _rsu_sy->getSU(); - sutemp->setDigits(4); - sutemp->setIncrements(0.1, 1.0); - - _rsi->init (_("_Major grid line every:"), _("lines"), "empspacing", _wr, repr, doc); + + _rsu_ox->setDigits(4); + _rsu_ox->setIncrements(0.1, 1.0); + + _rsu_oy->setDigits(4); + _rsu_oy->setIncrements(0.1, 1.0); + + _rsu_sx->setDigits(4); + _rsu_sx->setIncrements(0.1, 1.0); + + _rsu_sy->setDigits(4); + _rsu_sy->setIncrements(0.1, 1.0); Inkscape::UI::Widget::RegisteredCheckButton * _rcb_dotted = Gtk::manage( new Inkscape::UI::Widget::RegisteredCheckButton( _("_Show dots instead of lines"), _("If set, displays dots at gridpoints instead of gridlines"), - "dotted", _wr, false, repr, doc) - ); + "dotted", _wr, false, repr, doc) ); _wr.setUpdating (false); Gtk::Widget const *const widget_array[] = { - _rumg->_label, _rumg->_sel, - 0, _rsu_ox->getSU(), - 0, _rsu_oy->getSU(), - 0, _rsu_sx->getSU(), - 0, _rsu_sy->getSU(), + 0, _rumg, + 0, _rsu_ox, + 0, _rsu_oy, + 0, _rsu_sx, + 0, _rsu_sy, _rcp_gcol->_label, _rcp_gcol, 0, 0, _rcp_gmcol->_label, _rcp_gmcol, - _rsi->_label, &_rsi->_hbox, + 0, _rsi, 0, _rcb_dotted, }; diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 66b1ddf56..4004e151c 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -89,6 +89,8 @@ DocumentProperties::DocumentProperties() _rcb_shad(_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false), _rcp_bg(_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"), "pagecolor", "inkscape:pageopacity", _wr), _rcp_bord(_("Border _color:"), _("Page border color"), _("Color of the page border"), "bordercolor", "borderopacity", _wr), + _rum_deflt(_("Default _units:"), "inkscape:document-units", _wr), + _page_sizer(_wr), //--------------------------------------------------------------- //General snap options _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr), @@ -218,20 +220,17 @@ DocumentProperties::build_page() { _page_page.show(); - _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr); - Gtk::Label* label_gen = manage (new Gtk::Label); label_gen->set_markup (_("General")); Gtk::Label* label_bor = manage (new Gtk::Label); label_bor->set_markup (_("Border")); Gtk::Label *label_for = manage (new Gtk::Label); label_for->set_markup (_("Format")); - _page_sizer.init (_wr); Gtk::Widget *const widget_array[] = { label_gen, 0, - _rum_deflt._label, _rum_deflt._sel, + 0, &_rum_deflt, _rcp_bg._label, &_rcp_bg, 0, 0, label_for, 0, diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index 8f7625a2d..d2509d8a4 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -72,14 +72,11 @@ protected: PageSizer _page_sizer; //--------------------------------------------------------------- RegisteredCheckButton _rcb_sgui, _rcbsng; - RegisteredUnitMenu _rum_gusn; RegisteredColorPicker _rcp_gui, _rcp_hgui; //--------------------------------------------------------------- RegisteredCheckButton _rcbsg, _rcbsnbb, _rcbsnn, _rcbsnop; RegisteredCheckButton _rcbsnon, _rcbsnbbp, _rcbsnbbn; - RegisteredUnitMenu _rumso; ToleranceSlider _rsu_sno, _rsu_sn, _rsu_gusn; - RegisteredRadioButtonPair _rrb_pix; //--------------------------------------------------------------- RegisteredCheckButton _rcbic; RegisteredCheckButton _rcbsigg, _rcbsils; diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp index 7b0fea5f5..40f3addcf 100644 --- a/src/ui/widget/page-sizer.cpp +++ b/src/ui/widget/page-sizer.cpp @@ -185,10 +185,13 @@ static const SPUnit _px_unit = sp_unit_get_by_id (SP_UNIT_PX); /** * Constructor */ -PageSizer::PageSizer() : Gtk::VBox(false,4) +PageSizer::PageSizer(Registry & _wr) + : Gtk::VBox(false,4), + _dimensionUnits( _("U_nits:"), "units", _wr ), + _dimensionWidth( _("_Width:"), _("Width of paper"), "width", _dimensionUnits, _wr ), + _dimensionHeight( _("_Height:"), _("Height of paper"), "height", _dimensionUnits, _wr ), + _widgetRegistry(&_wr) { - - //# Set up the Paper Size combo box _paperSizeListStore = Gtk::ListStore::create(_paperSizeListColumns); _paperSizeList.set_model(_paperSizeListStore); @@ -259,15 +262,15 @@ PageSizer::PageSizer() : Gtk::VBox(false,4) _customTable.set_border_width (4); _customTable.set_row_spacings (4); _customTable.set_col_spacings (4); + _customTable.attach(_dimensionWidth, 0,1,0,1); + _customTable.attach(_dimensionUnits, 1,2,0,1); + _customTable.attach(_dimensionHeight, 0,1,1,2); + _customTable.attach(_fitPageButton, 1,2,1,2); _customFrame.add(_customTable); _fitPageButton.set_use_underline(); _fitPageButton.set_label(_("_Fit page to selection")); - _tips.set_tip(_fitPageButton, - _("Resize the page to fit the current selection, or the entire drawing if there is no selection")); - - - + _tips.set_tip(_fitPageButton, _("Resize the page to fit the current selection, or the entire drawing if there is no selection")); } @@ -284,43 +287,15 @@ PageSizer::~PageSizer() * Initialize or reset this widget */ void -PageSizer::init (Registry& reg) +PageSizer::init () { - - /* - Note that the registered widgets can only be placed onto a - container after they have been init()-ed. That is why some - of the widget creation is in the constructor, and the rest is - here. - */ - - _widgetRegistry = ® - - _dimensionUnits.init (_("U_nits:"), "units", - *_widgetRegistry); - _dimensionWidth.init (_("_Width:"), _("Width of paper"), "width", - _dimensionUnits, *_widgetRegistry); - _dimensionHeight.init (_("_Height:"), _("Height of paper"), "height", - _dimensionUnits, *_widgetRegistry); - - _customTable.attach(*(_dimensionWidth.getSU()), 0,1,0,1); - _customTable.attach(*(_dimensionUnits._sel), 1,2,0,1); - _customTable.attach(*(_dimensionHeight.getSU()), 0,1,1,2); - _customTable.attach(_fitPageButton, 1,2,1,2); - - _landscape_connection = _landscapeButton.signal_toggled().connect ( - sigc::mem_fun (*this, &PageSizer::on_landscape)); - _portrait_connection = _portraitButton.signal_toggled().connect ( - sigc::mem_fun (*this, &PageSizer::on_portrait)); - _changedw_connection = _dimensionWidth.getSU()->signal_value_changed().connect ( - sigc::mem_fun (*this, &PageSizer::on_value_changed)); - _changedh_connection = _dimensionHeight.getSU()->signal_value_changed().connect ( - sigc::mem_fun (*this, &PageSizer::on_value_changed)); - _fitPageButton.signal_clicked().connect( - sigc::mem_fun(*this, &PageSizer::fire_fit_canvas_to_selection_or_drawing)); + _landscape_connection = _landscapeButton.signal_toggled().connect (sigc::mem_fun (*this, &PageSizer::on_landscape)); + _portrait_connection = _portraitButton.signal_toggled().connect (sigc::mem_fun (*this, &PageSizer::on_portrait)); + _changedw_connection = _dimensionWidth.signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_value_changed)); + _changedh_connection = _dimensionHeight.signal_value_changed().connect (sigc::mem_fun (*this, &PageSizer::on_value_changed)); + _fitPageButton.signal_clicked().connect(sigc::mem_fun(*this, &PageSizer::fire_fit_canvas_to_selection_or_drawing)); show_all_children(); - } @@ -366,7 +341,7 @@ PageSizer::setDim (double w, double h, bool changeList) _paperSizeListSelection->select(row); } - Unit const& unit = _dimensionUnits._sel->getUnit(); + Unit const& unit = _dimensionUnits.getUnit(); _dimensionWidth.setValue (w / unit.factor); _dimensionHeight.setValue (h / unit.factor); @@ -487,8 +462,8 @@ PageSizer::on_portrait() { if (!_portraitButton.get_active()) return; - double w = _dimensionWidth.getSU()->getValue ("px"); - double h = _dimensionHeight.getSU()->getValue ("px"); + double w = _dimensionWidth.getValue ("px"); + double h = _dimensionHeight.getValue ("px"); if (h < w) setDim (h, w); } @@ -502,8 +477,8 @@ PageSizer::on_landscape() { if (!_landscapeButton.get_active()) return; - double w = _dimensionWidth.getSU()->getValue ("px"); - double h = _dimensionHeight.getSU()->getValue ("px"); + double w = _dimensionWidth.getValue ("px"); + double h = _dimensionHeight.getValue ("px"); if (w < h) setDim (h, w); } @@ -516,8 +491,8 @@ PageSizer::on_value_changed() { if (_widgetRegistry->isUpdating()) return; - setDim (_dimensionWidth.getSU()->getValue("px"), - _dimensionHeight.getSU()->getValue("px")); + setDim (_dimensionWidth.getValue("px"), + _dimensionHeight.getValue("px")); } diff --git a/src/ui/widget/page-sizer.h b/src/ui/widget/page-sizer.h index e3d10f578..f970afe44 100644 --- a/src/ui/widget/page-sizer.h +++ b/src/ui/widget/page-sizer.h @@ -124,7 +124,7 @@ public: /** * Constructor */ - PageSizer(); + PageSizer(Registry & _wr); /** * Destructor @@ -134,7 +134,7 @@ public: /** * Set up or reset this widget */ - void init (Registry& reg); + void init (); /** * Set the page size to the given dimensions. If 'changeList' is diff --git a/src/ui/widget/registered-widget.cpp b/src/ui/widget/registered-widget.cpp index f8abecdbe..3b36ea6bc 100644 --- a/src/ui/widget/registered-widget.cpp +++ b/src/ui/widget/registered-widget.cpp @@ -41,33 +41,6 @@ namespace Inkscape { namespace UI { namespace Widget { -void -RegisteredWdg::write_to_xml(const char * svgstr) -{ - // 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; - local_repr = SP_OBJECT_REPR (sp_desktop_namedview(dt)); - local_doc = sp_desktop_document(dt); - } - - bool saved = sp_document_get_undo_sensitive (local_doc); - sp_document_set_undo_sensitive (local_doc, false); - if (!write_undo) local_repr->setAttribute(_key.c_str(), svgstr); - sp_document_set_undo_sensitive (local_doc, saved); - - local_doc->setModifiedSinceSave(); - if (write_undo) { - local_repr->setAttribute(_key.c_str(), svgstr); - sp_document_done (local_doc, event_type, event_description); - } -} - - /*######################################### * Registered CHECKBUTTON */ @@ -130,35 +103,24 @@ RegisteredCheckButton::on_toggled() * Registered UNITMENU */ -RegisteredUnitMenu::RegisteredUnitMenu() -: _label(0), _sel(0) -{ -} - RegisteredUnitMenu::~RegisteredUnitMenu() { _changed_connection.disconnect(); - if (_label) delete _label; - if (_sel) delete _sel; } -void -RegisteredUnitMenu::init (const Glib::ustring& label, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) +RegisteredUnitMenu::RegisteredUnitMenu (const Glib::ustring& label, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) + : RegisteredWidget (label, "" /*tooltip*/, new UnitMenu()) { init_parent(key, wr, repr_in, doc_in); - _label = new Gtk::Label (label, 1.0, 0.5); - _label->set_use_underline (true); - _sel = new UnitMenu (); - _label->set_mnemonic_widget (*_sel); - _sel->setUnitType (UNIT_TYPE_LINEAR); - _changed_connection = _sel->signal_changed().connect (sigc::mem_fun (*this, &RegisteredUnitMenu::on_changed)); + getUnitMenu()->setUnitType (UNIT_TYPE_LINEAR); + _changed_connection = getUnitMenu()->signal_changed().connect (sigc::mem_fun (*this, &RegisteredUnitMenu::on_changed)); } void RegisteredUnitMenu::setUnit (const SPUnit* unit) { - _sel->setUnit (sp_unit_get_abbreviation (unit)); + getUnitMenu()->setUnit (sp_unit_get_abbreviation (unit)); } void @@ -168,7 +130,7 @@ RegisteredUnitMenu::on_changed() return; Inkscape::SVGOStringStream os; - os << _sel->getUnitAbbr(); + os << getUnitMenu()->getUnitAbbr(); _wr->setUpdating (true); @@ -182,48 +144,30 @@ RegisteredUnitMenu::on_changed() * Registered SCALARUNIT */ -RegisteredScalarUnit::RegisteredScalarUnit() -: _widget(0), _um(0) -{ -} - RegisteredScalarUnit::~RegisteredScalarUnit() { - if (_widget) delete _widget; _value_changed_connection.disconnect(); } -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, SPDocument *doc_in) +RegisteredScalarUnit::RegisteredScalarUnit (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) + : RegisteredWidget(label, tip, UNIT_TYPE_LINEAR, "", "", rum.getUnitMenu()), + _um(0) { init_parent(key, wr, repr_in, doc_in); - _widget = new ScalarUnit (label, tip, UNIT_TYPE_LINEAR, "", "", rum._sel); - _widget->initScalar (-1e6, 1e6); - _widget->setUnit (rum._sel->getUnitAbbr()); - _widget->setDigits (2); - _um = rum._sel; - _value_changed_connection = _widget->signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredScalarUnit::on_value_changed)); -} - -ScalarUnit* -RegisteredScalarUnit::getSU() -{ - return _widget; + initScalar (-1e6, 1e6); + setUnit (rum.getUnitMenu()->getUnitAbbr()); + setDigits (2); + _um = rum.getUnitMenu(); + _value_changed_connection = signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredScalarUnit::on_value_changed)); } -void -RegisteredScalarUnit::setValue (double val) -{ - if (_widget) - _widget->setValue (val); -} void RegisteredScalarUnit::on_value_changed() { - if (_widget->setProgrammatically) { - _widget->setProgrammatically = false; + if (setProgrammatically) { + setProgrammatically = false; return; } @@ -233,7 +177,7 @@ RegisteredScalarUnit::on_value_changed() _wr->setUpdating (true); Inkscape::SVGOStringStream os; - os << _widget->getValue(""); + os << getValue(""); if (_um) os << _um->getUnitAbbr(); @@ -371,46 +315,22 @@ RegisteredColorPicker::on_changed (guint32 rgba) * Registered SUFFIXEDINTEGER */ -RegisteredSuffixedInteger::RegisteredSuffixedInteger() -: _label(0), - setProgrammatically(false), - _sb(0), - _adj(0.0,0.0,100.0,1.0,1.0,1.0), - _suffix(0) -{ -} - RegisteredSuffixedInteger::~RegisteredSuffixedInteger() { _changed_connection.disconnect(); - if (_label) delete _label; - if (_suffix) delete _suffix; - if (_sb) delete _sb; } -void -RegisteredSuffixedInteger::init (const Glib::ustring& label, const Glib::ustring& suffix, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) +RegisteredSuffixedInteger::RegisteredSuffixedInteger (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& suffix, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) + : RegisteredWidget(label, tip, 0, suffix), + setProgrammatically(false) { init_parent(key, wr, repr_in, doc_in); - _label = new Gtk::Label (label); - _label->set_alignment (1.0, 0.5); - _label->set_use_underline(); - _sb = new Gtk::SpinButton (_adj, 1.0, 0); - _sb->set_numeric(); - _label->set_mnemonic_widget (*_sb); - _suffix = new Gtk::Label (suffix); - _hbox.pack_start (*_sb, true, true, 0); - _hbox.pack_start (*_suffix, false, false, 0); - - _changed_connection = _adj.signal_value_changed().connect (sigc::mem_fun(*this, &RegisteredSuffixedInteger::on_value_changed)); -} + setRange (0, 1e6); + setDigits (0); + setIncrements(1, 10); -void -RegisteredSuffixedInteger::setValue (int i) -{ - setProgrammatically = true; - _adj.set_value (i); + _changed_connection = signal_value_changed().connect (sigc::mem_fun(*this, &RegisteredSuffixedInteger::on_value_changed)); } void @@ -427,8 +347,7 @@ RegisteredSuffixedInteger::on_value_changed() _wr->setUpdating (true); Inkscape::SVGOStringStream os; - int value = int(_adj.get_value()); - os << value; + os << getValue(); write_to_xml(os.str().c_str()); @@ -440,32 +359,29 @@ RegisteredSuffixedInteger::on_value_changed() * Registered RADIOBUTTONPAIR */ -RegisteredRadioButtonPair::RegisteredRadioButtonPair() -: _hbox(0), - setProgrammatically(false) -{ -} - RegisteredRadioButtonPair::~RegisteredRadioButtonPair() { _changed_connection.disconnect(); } -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, SPDocument *doc_in) +RegisteredRadioButtonPair::RegisteredRadioButtonPair (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, SPDocument *doc_in) + : RegisteredWidget(), + _rb1(NULL), + _rb2(NULL) { init_parent(key, wr, repr_in, doc_in); - _hbox = new Gtk::HBox; - _hbox->add (*manage (new Gtk::Label (label))); + setProgrammatically = false; + + add (*manage (new Gtk::Label (label))); _rb1 = manage (new Gtk::RadioButton (label1, true)); - _hbox->add (*_rb1); + add (*_rb1); Gtk::RadioButtonGroup group = _rb1->get_group(); _rb2 = manage (new Gtk::RadioButton (group, label2, true)); - _hbox->add (*_rb2); + add (*_rb2); _rb2->set_active(); _tt.set_tip (*_rb1, tip1); _tt.set_tip (*_rb2, tip2); diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 42bcf62d7..a3b04575e 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -21,8 +21,11 @@ #include "xml/node.h" #include "registry.h" +#include "ui/widget/scalar.h" +#include "ui/widget/scalar-unit.h" #include "ui/widget/point.h" #include "ui/widget/random.h" +#include "ui/widget/unit-menu.h" #include "ui/widget/color-picker.h" #include "inkscape.h" @@ -44,9 +47,6 @@ namespace UI { namespace Widget { class Registry; -class Scalar; -class ScalarUnit; -class UnitMenu; template class RegisteredWidget : public W { @@ -70,9 +70,13 @@ protected: template< typename A, typename B > RegisteredWidget( A& a, B& b ): W( a, b ) { construct(); } template< typename A, typename B, typename C > + RegisteredWidget( A& a, B& b, C* c ): W( a, b, c ) { construct(); } + template< typename A, typename B, typename C > RegisteredWidget( A& a, B& b, C& c ): W( a, b, c ) { construct(); } template< typename A, typename B, typename C, typename D > RegisteredWidget( A& a, B& b, C c, D d ): W( a, b, c, d ) { construct(); } + template< typename A, typename B, typename C, typename D, typename E , typename F> + RegisteredWidget( A& a, B& b, C c, D& d, E& e, F* f): W( a, b, c, d, e, f) { construct(); } virtual ~RegisteredWidget() {}; @@ -129,47 +133,6 @@ private: } }; -class RegisteredWdg { -public: - void set_undo_parameters(const unsigned int _event_type, Glib::ustring _event_description) - { - event_type = _event_type; - event_description = _event_description; - write_undo = true; - } - - bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;} - -protected: - RegisteredWdg() - { - _wr = NULL; - repr = NULL; - doc = NULL; - write_undo = false; - } - - void init_parent(const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in) - { - _wr = ≀ - _key = key; - 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 write_to_xml(const char * svgstr); - - Registry * _wr; - Glib::ustring _key; - Inkscape::XML::Node * repr; - SPDocument * doc; - unsigned int event_type; - Glib::ustring event_description; - bool write_undo; -}; - //####################################################### class RegisteredCheckButton : public RegisteredWidget { @@ -191,59 +154,42 @@ public: bool setProgrammatically; // true if the value was set by setActive, not changed by the user; // if a callback checks it, it must reset it back to false - protected: Gtk::Tooltips _tt; sigc::connection _toggled_connection; void on_toggled(); }; -class RegisteredUnitMenu : public RegisteredWdg { +class RegisteredUnitMenu : public RegisteredWidget { public: - RegisteredUnitMenu(); ~RegisteredUnitMenu(); - void init ( const Glib::ustring& label, - const Glib::ustring& key, - Registry& wr, - Inkscape::XML::Node* repr_in, - SPDocument *doc_in); - inline void init ( const Glib::ustring& label, - const Glib::ustring& key, - Registry& wr) - { init(label, key, wr, NULL, NULL); }; + RegisteredUnitMenu ( 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; + Unit getUnit() const { return static_cast(_widget)->getUnit(); }; + UnitMenu* getUnitMenu() const { return static_cast(_widget); }; sigc::connection _changed_connection; protected: void on_changed(); }; -class RegisteredScalarUnit : public RegisteredWdg { +class RegisteredScalarUnit : public RegisteredWidget { public: - RegisteredScalarUnit(); ~RegisteredScalarUnit(); - void 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); - inline void init ( const Glib::ustring& label, - const Glib::ustring& tip, - const Glib::ustring& key, - const RegisteredUnitMenu &rum, - Registry& wr) - { init(label, tip, key, rum, wr, NULL, NULL); }; - - ScalarUnit* getSU(); - void setValue (double); + RegisteredScalarUnit ( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& key, + const RegisteredUnitMenu &rum, + Registry& wr, + Inkscape::XML::Node* repr_in = NULL, + SPDocument *doc_in = NULL ); protected: - ScalarUnit *_widget; sigc::connection _value_changed_connection; UnitMenu *_um; void on_value_changed(); @@ -288,60 +234,39 @@ protected: sigc::connection _changed_connection; }; -class RegisteredSuffixedInteger : public RegisteredWdg { +class RegisteredSuffixedInteger : public RegisteredWidget { public: - RegisteredSuffixedInteger(); - ~RegisteredSuffixedInteger(); - void init (const Glib::ustring& label1, - const Glib::ustring& label2, - const Glib::ustring& key, - Registry& wr, - Inkscape::XML::Node* repr_in, - SPDocument *doc_in); - inline void init ( const Glib::ustring& label1, - const Glib::ustring& label2, - const Glib::ustring& key, - Registry& wr) - { init(label1, label2, key, wr, NULL, NULL); }; + virtual ~RegisteredSuffixedInteger(); + RegisteredSuffixedInteger ( const Glib::ustring& label, + const Glib::ustring& tip, + const Glib::ustring& suffix, + const Glib::ustring& key, + Registry& wr, + Inkscape::XML::Node* repr_in = NULL, + SPDocument *doc_in = NULL ); - void setValue (int); - Gtk::Label *_label; - Gtk::HBox _hbox; bool setProgrammatically; // true if the value was set by setValue, not changed by the user; // if a callback checks it, it must reset it back to false protected: - Gtk::SpinButton *_sb; - Gtk::Adjustment _adj; - Gtk::Label *_suffix; sigc::connection _changed_connection; void on_value_changed(); }; -class RegisteredRadioButtonPair : public RegisteredWdg { +class RegisteredRadioButtonPair : public RegisteredWidget { public: - RegisteredRadioButtonPair(); - ~RegisteredRadioButtonPair(); - void 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, - SPDocument *doc_in); - inline void 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) - { init(label, label1, label2, tip1, tip2, key, wr, NULL, NULL); }; + virtual ~RegisteredRadioButtonPair(); + RegisteredRadioButtonPair ( 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 = NULL, + SPDocument *doc_in = NULL ); void setValue (bool second); - Gtk::HBox *_hbox; bool setProgrammatically; // true if the value was set by setValue, not changed by the user; // if a callback checks it, it must reset it back to false