From 800e1009dce786f914293fc2b6f324360deb58af Mon Sep 17 00:00:00 2001 From: johanengelen Date: Wed, 16 Jan 2008 19:03:48 +0000 Subject: [PATCH] No need to use pointers for the widgets of document-properties.cpp, so don't. Add easy upcast to gtk::widget to registered-widget.h --- src/ui/dialog/document-properties.cpp | 163 +++++++++++--------------- src/ui/dialog/document-properties.h | 17 ++- src/ui/widget/registered-widget.h | 3 + 3 files changed, 78 insertions(+), 105 deletions(-) diff --git a/src/ui/dialog/document-properties.cpp b/src/ui/dialog/document-properties.cpp index 1a1ba3689..293e6cf19 100644 --- a/src/ui/dialog/document-properties.cpp +++ b/src/ui/dialog/document-properties.cpp @@ -83,10 +83,38 @@ DocumentProperties::DocumentProperties() : UI::Widget::Panel ("", "dialogs.documentoptions", SP_VERB_DIALOG_NAMEDVIEW), _page_page(1, 1), _page_guides(1, 1), _page_snap(1, 1), _page_snap_dtls(1, 1), + //--------------------------------------------------------------- + _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false), + _rcb_bord(_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false), + _rcb_shad(_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false), + //--------------------------------------------------------------- + //General snap options + _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr), + _rcbsng(_("_Snap guides while dragging"), _("While dragging a guide, snap to object nodes or bounding box corners ('Snap to nodes' or 'snap to bounding box corners' must be enabled in the 'Snap' tab; only a small part of the guide near the cursor will snap)"), + "inkscape:snap-guide", _wr), + //--------------------------------------------------------------- + _rcbsg(_("_Enable snapping"), _("Toggle snapping on or off"), "inkscape:snap-global", _wr), + _rcbsnbb(_("_Bounding box corners"), _("Only available in the selector tool: snap bounding box corners to guides, to grids, and to other bounding boxes (but not to nodes or paths)"), + "inkscape:snap-bbox", _wr), + _rcbsnn(_("_Nodes"), _("Snap nodes (e.g. path nodes, special points in shapes, gradient handles, text base points, transformation origins, etc.) to guides, to grids, to paths and to other nodes"), + "inkscape:snap-nodes", _wr), + //Options for snapping to objects + _rcbsnop(_("Snap to path_s"), _("Snap nodes to object paths"), "inkscape:object-paths", _wr), + _rcbsnon(_("Snap to n_odes"), _("Snap nodes and guides to object nodes"), "inkscape:object-nodes", _wr), + _rcbsnbbn(_("Snap to bounding box co_rners"), _("Snap bounding box corners to other bounding box corners"), "inkscape:bbox-nodes", _wr), + _rcbsnbbp(_("Snap to bounding bo_x edges"), _("Snap bounding box corners and guides to bounding box edges"), "inkscape:bbox-paths", _wr), + //--------------------------------------------------------------- + //Applies to both nodes and guides, but not to bboxes, that's why its located here + _rcbic( _("Rotation _center"), _("Consider the rotation center of an object when snapping"), "inkscape:snap-center", _wr), + _rcbsigg(_("_Grid with guides"), _("Snap to grid-guide intersections"), "inkscape:snap-intersection-grid-guide", _wr), + _rcbsils(_("_Line segments"), _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"), + "inkscape:snap-intersection-line-segments", _wr), + //--------------------------------------------------------------- _grids_label_crea("", Gtk::ALIGN_LEFT), _grids_button_new(_("_New"), _("Create new grid.")), _grids_button_remove(_("_Remove"), _("Remove selected grid.")), _grids_label_def("", Gtk::ALIGN_LEFT), + //--------------------------------------------------------------- _prefs_path("dialogs.documentoptions") { _tt.enable(); @@ -185,24 +213,13 @@ DocumentProperties::build_page() { _page_page.show(); - _rcp_bg.init( - _("Back_ground:"), + _rcp_bg.init( _("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"), "pagecolor", "inkscape:pageopacity", _wr); - _rcb_canb = Gtk::manage( new RegisteredCheckButton( - _("Show page _border"), - _("If set, rectangular page border is shown"), "showborder", _wr, false) ); - _rcb_bord = Gtk::manage( new RegisteredCheckButton( - _("Border on _top of drawing"), - _("If set, border is always on top of the drawing"), "borderlayer", _wr, false) ); _rcp_bord.init (_("Border _color:"), _("Page border color"), _("Color of the page border"), "bordercolor", "borderopacity", _wr); - _rcb_shad = Gtk::manage( new RegisteredCheckButton( - _("_Show border shadow"), - _("If set, page border shows a shadow on its right and lower side"), - "inkscape:showpageshadow", _wr, false) ); _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr); Gtk::Label* label_gen = manage (new Gtk::Label); @@ -223,9 +240,9 @@ DocumentProperties::build_page() 0, &_page_sizer, 0, 0, label_bor, 0, - 0, _rcb_canb, - 0, _rcb_bord, - 0, _rcb_shad, + 0, &_rcb_canb, + 0, &_rcb_bord, + 0, &_rcb_shad, _rcp_bord._label, _rcp_bord._cp, }; @@ -237,29 +254,22 @@ DocumentProperties::build_guides() { _page_guides.show(); - _rcb_sgui = Gtk::manage( new RegisteredCheckButton( - _("Show _guides"), _("Show or hide guides"), "showguides", _wr) ); _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"), _("Color of guidelines"), "guidecolor", "guideopacity", _wr); _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"), _("Color of a guideline when it is under mouse"), "guidehicolor", "guidehiopacity", _wr); - _rcbsng = Gtk::manage( new RegisteredCheckButton( - _("_Snap guides while dragging"), - _("While dragging a guide, snap to object nodes or bounding box corners ('Snap to nodes' or 'snap to bounding box corners' must be enabled in the 'Snap' tab; only a small part of the guide near the cursor will snap)"), - "inkscape:snap-guide", _wr) ); - Gtk::Label *label_gui = manage (new Gtk::Label); label_gui->set_markup (_("Guides")); Gtk::Widget *const widget_array[] = { label_gui, 0, - 0, _rcb_sgui, + 0, &_rcb_sgui, _rcp_gui._label, _rcp_gui._cp, _rcp_hgui._label, _rcp_hgui._cp, - 0, _rcbsng, + 0, &_rcbsng, }; attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array)); @@ -269,30 +279,6 @@ void DocumentProperties::build_snap() { _page_snap.show(); - //General options - _rcbsg = Gtk::manage( new RegisteredCheckButton( _("_Enable snapping"), - _("Toggle snapping on or off"), - "inkscape:snap-global", _wr) ); - _rcbsnbb = Gtk::manage( new RegisteredCheckButton( _("_Bounding box corners"), - _("Only available in the selector tool: snap bounding box corners to guides, to grids, and to other bounding boxes (but not to nodes or paths)"), - "inkscape:snap-bbox", _wr) ); - _rcbsnn = Gtk::manage( new RegisteredCheckButton( _("_Nodes"), - _("Snap nodes (e.g. path nodes, special points in shapes, gradient handles, text base points, transformation origins, etc.) to guides, to grids, to paths and to other nodes"), - "inkscape:snap-nodes", _wr) ); - - //Options for snapping to objects - _rcbsnop = Gtk::manage( new RegisteredCheckButton( _("Snap to path_s"), - _("Snap nodes to object paths"), - "inkscape:object-paths", _wr) ); - _rcbsnon = Gtk::manage( new RegisteredCheckButton( _("Snap to n_odes"), - _("Snap nodes and guides to object nodes"), - "inkscape:object-nodes", _wr) ); - _rcbsnbbn = Gtk::manage( new RegisteredCheckButton( _("Snap to bounding box co_rners"), - _("Snap bounding box corners to other bounding box corners"), - "inkscape:bbox-nodes", _wr) ); - _rcbsnbbp = Gtk::manage( new RegisteredCheckButton( _("Snap to bounding bo_x edges"), - _("Snap bounding box corners and guides to bounding box edges"), - "inkscape:bbox-paths", _wr) ); _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"), _("Snapping distance, in screen pixels, for snapping to objects"), @@ -314,20 +300,20 @@ DocumentProperties::build_snap() //Other options to locate here: e.g. visual snapping indicators on/off std::list slaves; - slaves.push_back(_rcbsnop); - slaves.push_back(_rcbsnon); - _rcbsnn->setSlaveButton(slaves); + slaves.push_back(&_rcbsnop); + slaves.push_back(&_rcbsnon); + _rcbsnn.setSlaveButton(slaves); slaves.clear(); - slaves.push_back(_rcbsnbbp); - slaves.push_back(_rcbsnbbn); - _rcbsnbb->setSlaveButton(slaves); + slaves.push_back(&_rcbsnbbp); + slaves.push_back(&_rcbsnbbn); + _rcbsnbb.setSlaveButton(slaves); slaves.clear(); - slaves.push_back(_rcbsnn); - slaves.push_back(_rcbsnbb); + slaves.push_back(&_rcbsnn); + slaves.push_back(&_rcbsnbb); - _rcbsg->setSlaveButton(slaves); + _rcbsg.setSlaveButton(slaves); Gtk::Label *label_g = manage (new Gtk::Label); label_g->set_markup (_("Snapping")); @@ -343,17 +329,17 @@ DocumentProperties::build_snap() Gtk::Widget *const array[] = { label_g, 0, - 0, _rcbsg, + 0, &_rcbsg, 0, 0, label_w, 0, - 0, _rcbsnn, - 0, _rcbsnbb, + 0, &_rcbsnn, + 0, &_rcbsnbb, 0, 0, label_o, 0, - 0, _rcbsnop, - 0, _rcbsnon, - 0, _rcbsnbbp, - 0, _rcbsnbbn, + 0, &_rcbsnop, + 0, &_rcbsnon, + 0, &_rcbsnbbp, + 0, &_rcbsnbbn, 0, _rsu_sno._vbox, 0, 0, label_gr, 0, @@ -371,19 +357,6 @@ DocumentProperties::build_snap_dtls() { _page_snap_dtls.show(); - _rcbsigg = Gtk::manage( new RegisteredCheckButton( _("_Grid with guides"), - _("Snap to grid-guide intersections"), - "inkscape:snap-intersection-grid-guide", _wr) ); - - _rcbsils = Gtk::manage( new RegisteredCheckButton( _("_Line segments"), - _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"), - "inkscape:snap-intersection-line-segments", _wr) ); - - //Applies to both nodes and guides, but not to bboxes, that's why its located here - _rcbic = Gtk::manage( new RegisteredCheckButton( _("Rotation _center"), - _("Consider the rotation center of an object when snapping"), - "inkscape:snap-center", _wr) ); - //Other options to locate here: e.g. visual snapping indicators on/off Gtk::Label *label_i= manage (new Gtk::Label); @@ -394,11 +367,11 @@ DocumentProperties::build_snap_dtls() Gtk::Widget *const array[] = { label_i, 0, - 0, _rcbsigg, - 0, _rcbsils, + 0, &_rcbsigg, + 0, &_rcbsils, 0, 0, label_m, 0, - 0, _rcbic, + 0, &_rcbic, }; attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array)); @@ -500,10 +473,10 @@ DocumentProperties::update() //-----------------------------------------------------------page page _rcp_bg.setRgba32 (nv->pagecolor); - _rcb_canb->setActive (nv->showborder); - _rcb_bord->setActive (nv->borderlayer == SP_BORDER_LAYER_TOP); + _rcb_canb.setActive (nv->showborder); + _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP); _rcp_bord.setRgba32 (nv->bordercolor); - _rcb_shad->setActive (nv->showpageshadow); + _rcb_shad.setActive (nv->showpageshadow); if (nv->doc_units) _rum_deflt.setUnit (nv->doc_units); @@ -513,29 +486,29 @@ DocumentProperties::update() _page_sizer.setDim (doc_w_px, doc_h_px); //-----------------------------------------------------------guide - _rcb_sgui->setActive (nv->showguides); + _rcb_sgui.setActive (nv->showguides); _rcp_gui.setRgba32 (nv->guidecolor); _rcp_hgui.setRgba32 (nv->guidehicolor); //-----------------------------------------------------------snap - _rcbsnbb->setActive (nv->snap_manager.getSnapModeBBox()); - _rcbsnn->setActive (nv->snap_manager.getSnapModeNode()); - _rcbsng->setActive (nv->snap_manager.getSnapModeGuide()); - _rcbic->setActive (nv->snap_manager.getIncludeItemCenter()); - _rcbsigg->setActive (nv->snap_manager.getSnapIntersectionGG()); - _rcbsils->setActive (nv->snap_manager.getSnapIntersectionLS()); - _rcbsnop->setActive(nv->snap_manager.object.getSnapToItemPath()); - _rcbsnon->setActive(nv->snap_manager.object.getSnapToItemNode()); - _rcbsnbbp->setActive(nv->snap_manager.object.getSnapToBBoxPath()); - _rcbsnbbn->setActive(nv->snap_manager.object.getSnapToBBoxNode()); + _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox()); + _rcbsnn.setActive (nv->snap_manager.getSnapModeNode()); + _rcbsng.setActive (nv->snap_manager.getSnapModeGuide()); + _rcbic.setActive (nv->snap_manager.getIncludeItemCenter()); + _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG()); + _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS()); + _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath()); + _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode()); + _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath()); + _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode()); _rsu_sno.setValue (nv->objecttolerance); _rsu_sn.setValue (nv->gridtolerance); _rsu_gusn.setValue (nv->guidetolerance); - _rcbsg->setActive (nv->snap_manager.getSnapEnabledGlobally()); + _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally()); //-----------------------------------------------------------grids page diff --git a/src/ui/dialog/document-properties.h b/src/ui/dialog/document-properties.h index b23fbef9b..8f7625a2d 100644 --- a/src/ui/dialog/document-properties.h +++ b/src/ui/dialog/document-properties.h @@ -64,27 +64,25 @@ protected: NotebookPage _page_snap, _page_snap_dtls; Gtk::VBox _grids_vbox; + Registry _wr; //--------------------------------------------------------------- - RegisteredCheckButton *_rcb_canb, *_rcb_bord, *_rcb_shad; + RegisteredCheckButton _rcb_canb, _rcb_bord, _rcb_shad; RegisteredColorPicker _rcp_bg, _rcp_bord; RegisteredUnitMenu _rum_deflt; PageSizer _page_sizer; //--------------------------------------------------------------- - RegisteredCheckButton *_rcbgrid; - RegisteredUnitMenu _rums; - //--------------------------------------------------------------- - RegisteredCheckButton *_rcb_sgui, *_rcbsng; + RegisteredCheckButton _rcb_sgui, _rcbsng; RegisteredUnitMenu _rum_gusn; RegisteredColorPicker _rcp_gui, _rcp_hgui; //--------------------------------------------------------------- - RegisteredCheckButton *_rcbsg, *_rcbsnbb, *_rcbsnn, *_rcbsnop; - RegisteredCheckButton *_rcbsnon, *_rcbsnbbp, *_rcbsnbbn; + 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; + RegisteredCheckButton _rcbic; + RegisteredCheckButton _rcbsigg, _rcbsils; //--------------------------------------------------------------- Gtk::Notebook _grids_notebook; Gtk::HBox _grids_hbox_crea; @@ -97,7 +95,6 @@ protected: //--------------------------------------------------------------- gchar const *_prefs_path; - Registry _wr; Gtk::HBox& _createPageTabLabel(const Glib::ustring& label, const char *label_image); diff --git a/src/ui/widget/registered-widget.h b/src/ui/widget/registered-widget.h index 7c643715f..185d1e3b4 100644 --- a/src/ui/widget/registered-widget.h +++ b/src/ui/widget/registered-widget.h @@ -55,6 +55,9 @@ public: bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;} + // provide automatic 'upcast' for ease of use. (do it 'dynamic_cast' instead of 'static' because who knows what W is) + operator const Gtk::Widget () { return dynamic_cast(this); } + protected: RegisteredWidget() : W() { construct(); } template< typename A > -- 2.30.2