Code

convert almost all libnrtype to Geom::
[inkscape.git] / src / ui / dialog / document-properties.cpp
1 /** \file
2  *
3  * Document properties dialog, Gtkmm-style
4  *
5  * Authors:
6  *   bulia byak <buliabyak@users.sf.net>
7  *   Bryce W. Harrington <bryce@bryceharrington.org>
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *   Jon Phillips <jon@rejon.org>
10  *   Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
11  *   Diederik van Lierop <mail@diedenrezi.nl>
12  *
13  * Copyright (C) 2006-2008 Johan Engelen  <johan@shouraizou.nl>
14  * Copyright (C) 2000 - 2008 Authors
15  *
16  * Released under GNU GPL.  Read the file 'COPYING' for more information
17  */
19 #ifdef HAVE_CONFIG_H
20 # include <config.h>
21 #endif
25 #include <gtkmm.h>
26 #include "ui/widget/color-picker.h"
27 #include "ui/widget/scalar-unit.h"
29 #include "xml/node-event-vector.h"
30 #include "helper/units.h"
31 #include "prefs-utils.h"
33 #include "inkscape.h"
34 #include "verbs.h"
35 #include "document.h"
36 #include "desktop-handles.h"
37 #include "desktop.h"
38 #include "sp-namedview.h"
39 #include "widgets/icon.h"
40 #include "document-properties.h"
42 #include "display/canvas-grid.h"
44 using std::pair;
46 namespace Inkscape {
47 namespace UI {
48 namespace Dialog {
50 #define SPACE_SIZE_X 15
51 #define SPACE_SIZE_Y 10
53 #define INKSCAPE_ICON_GRID_XY     "grid_xy"
54 #define INKSCAPE_ICON_GRID_AXONOM "grid_axonom"
57 //===================================================
59 //---------------------------------------------------
61 static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
62 static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
63 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
65 static Inkscape::XML::NodeEventVector const _repr_events = {
66     on_child_added, /* child_added */
67     on_child_removed, /* child_removed */
68     on_repr_attr_changed,
69     NULL, /* content_changed */
70     NULL  /* order_changed */
71 };
74 DocumentProperties &
75 DocumentProperties::getInstance()
76 {
77     DocumentProperties &instance = *new DocumentProperties();
78     instance.init();
80     return instance;
81 }
83 DocumentProperties::DocumentProperties()
84     : UI::Widget::Panel ("", "dialogs.documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
85       _page_page(1, 1, true, true), _page_guides(1, 1),
86       _page_snap(1, 1), _page_snap_dtls(1, 1),
87     //---------------------------------------------------------------
88       _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false),
89       _rcb_bord(_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false),
90       _rcb_shad(_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false),
91       _rcp_bg(_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"), "pagecolor", "inkscape:pageopacity", _wr),
92       _rcp_bord(_("Border _color:"), _("Page border color"), _("Color of the page border"), "bordercolor", "borderopacity", _wr),
93       _rum_deflt(_("Default _units:"), "inkscape:document-units", _wr),
94       _page_sizer(_wr),
95     //---------------------------------------------------------------
96       //General snap options
97       _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr),
98       _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)"),
99                   "inkscape:snap-guide", _wr),
100       _rcp_gui(_("Guide co_lor:"), _("Guideline color"), _("Color of guidelines"), "guidecolor", "guideopacity", _wr),
101       _rcp_hgui(_("_Highlight color:"), _("Highlighted guideline color"), _("Color of a guideline when it is under mouse"), "guidehicolor", "guidehiopacity", _wr),
102     //---------------------------------------------------------------
103       _rcbs(_("_Enable snapping"), _("Toggle snapping on or off"), "inkscape:snap-global", _wr),
104       _rcbsi(_("_Enable snap indicator"), _("After snapping, a symbol is drawn at the point that has snapped"), "inkscape:snap-indicator", _wr),
105       _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)"),
106                   "inkscape:snap-bbox", _wr),
107       _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"),
108                 "inkscape:snap-nodes", _wr),
109       //Options for snapping to objects
110       _rcbsnop(_("Snap to path_s"), _("Snap nodes to object paths"), "inkscape:object-paths", _wr),
111       _rcbsnon(_("Snap to n_odes"), _("Snap nodes and guides to object nodes"), "inkscape:object-nodes", _wr),
112       _rcbsnbbp(_("Snap to bounding bo_x edges"), _("Snap bounding box corners and guides to bounding box edges"), "inkscape:bbox-paths", _wr),
113       _rcbsnbbn(_("Snap to bounding box co_rners"), _("Snap bounding box corners to other bounding box corners"), "inkscape:bbox-nodes", _wr),
114       _rcbsnpb(_("Snap to page border"), _("Snap bounding box corners and nodes to the page border"), "inkscape:snap-page", _wr),
115     //---------------------------------------------------------------
116        //Applies to both nodes and guides, but not to bboxes, that's why its located here
117       _rcbic( _("Rotation _center"), _("Consider the rotation center of an object when snapping"), "inkscape:snap-center", _wr),
118       _rcbsigg(_("_Grid with guides"), _("Snap to grid-guide intersections"), "inkscape:snap-intersection-grid-guide", _wr),
119       _rcbsils(_("_Paths"), _("Snap to intersections of paths ('snap to paths' must be enabled, see the previous tab)"),
120                 "inkscape:snap-intersection-paths", _wr),
121     //---------------------------------------------------------------
122       _grids_label_crea("", Gtk::ALIGN_LEFT),
123       //TRANSLATORS: In Grid|_New translate only the word _New. It ref to grid
124       _grids_button_new(Q_("Grid|_New"), _("Create new grid.")),
125       _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
126       _grids_label_def("", Gtk::ALIGN_LEFT),
127     //---------------------------------------------------------------
128       _prefs_path("dialogs.documentoptions")
130     _tt.enable();
131     _getContents()->set_spacing (4);
132     _getContents()->pack_start(_notebook, true, true);
134     _notebook.append_page(_page_page,      _("Page"));
135     _notebook.append_page(_page_guides,    _("Guides"));
136     _notebook.append_page(_grids_vbox,     _("Grids"));
137     _notebook.append_page(_page_snap,      _("Snap"));
138     _notebook.append_page(_page_snap_dtls, _("Snap points"));
140     build_page();
141     build_guides();
142     build_gridspage();
143     build_snap();
144     build_snap_dtls();
146     _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
147     _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
149     signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
150     signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
151     signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
154 void
155 DocumentProperties::init()
157     update();
159     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
160     repr->addListener (&_repr_events, this);
161     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
162     root->addListener (&_repr_events, this);
164     show_all_children();
165     _grids_button_remove.hide();
168 DocumentProperties::~DocumentProperties()
170     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
171     repr->removeListenerByData (this);
172     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
173     root->removeListenerByData (this);
176 //========================================================================
178 /**
179  * Helper function that attaches widgets in a 3xn table. The widgets come in an
180  * array that has two entries per table row. The two entries code for four
181  * possible cases: (0,0) means insert space in first column; (0, non-0) means
182  * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
183  * (non-0, non-0) means two widgets in columns 2 and 3.
184 **/
185 inline void
186 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
188     for (unsigned i = 0, r = start; i < n; i += 2)
189     {
190         if (arr[i] && arr[i+1])
191         {
192             table.attach(*arr[i],   1, 2, r, r+1,
193                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
194             table.attach(*arr[i+1], 2, 3, r, r+1,
195                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
196         }
197         else
198         {
199             if (arr[i+1]) {
200                 Gtk::AttachOptions yoptions = (Gtk::AttachOptions)0;
201                 if (dynamic_cast<Inkscape::UI::Widget::PageSizer*>(arr[i+1])) {
202                     // only the PageSizer in Document Properties|Page should be stretched vertically
203                     yoptions = Gtk::FILL|Gtk::EXPAND;
204                 }
205                 table.attach(*arr[i+1], 1, 3, r, r+1,
206                       Gtk::FILL|Gtk::EXPAND, yoptions, 0,0);
207             }
208             else if (arr[i])
209             {
210                 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
211                 label.set_alignment (0.0);
212                 table.attach (label, 0, 3, r, r+1,
213                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
214             }
215             else
216             {
217                 Gtk::HBox *space = manage (new Gtk::HBox);
218                 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
219                 table.attach (*space, 0, 1, r, r+1,
220                       (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
221             }
222         }
223         ++r;
224     }
227 void
228 DocumentProperties::build_page()
230     _page_page.show();
232     Gtk::Label* label_gen = manage (new Gtk::Label);
233     label_gen->set_markup (_("<b>General</b>"));
234     Gtk::Label* label_bor = manage (new Gtk::Label);
235     label_bor->set_markup (_("<b>Border</b>"));
236     Gtk::Label *label_for = manage (new Gtk::Label);
237     label_for->set_markup (_("<b>Format</b>"));
238     _page_sizer.init();
240     Gtk::Widget *const widget_array[] =
241     {
242         label_gen,         0,
243         0,                 &_rum_deflt,
244         _rcp_bg._label,    &_rcp_bg,
245         0,                 0,
246         label_for,         0,
247         0,                 &_page_sizer,
248         0,                 0,
249         label_bor,         0,
250         0,                 &_rcb_canb,
251         0,                 &_rcb_bord,
252         0,                 &_rcb_shad,
253         _rcp_bord._label,  &_rcp_bord,
254     };
256     attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
259 void
260 DocumentProperties::build_guides()
262     _page_guides.show();
264     Gtk::Label *label_gui = manage (new Gtk::Label);
265     label_gui->set_markup (_("<b>Guides</b>"));
267     Gtk::Widget *const widget_array[] =
268     {
269         label_gui,        0,
270         0,                &_rcb_sgui,
271         _rcp_gui._label,  &_rcp_gui,
272         _rcp_hgui._label, &_rcp_hgui,
273         0,                &_rcbsng,
274     };
276     attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
279 void
280 DocumentProperties::build_snap()
282     _page_snap.show();
284     _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"), _("Always snap"),
285                   _("Snapping distance, in screen pixels, for snapping to objects"), _("Always snap to objects, regardless of their distance"),
286                   _("If set, objects only snap to another object when it's within the range specified below"),
287                   "objecttolerance", _wr);
289     //Options for snapping to grids
290     _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"), _("Always snap"),
291                   _("Snapping distance, in screen pixels, for snapping to grid"), _("Always snap to grids, regardless of the distance"),
292                   _("If set, objects only snap to a grid line when it's within the range specified below"),
293                   "gridtolerance", _wr);
295     //Options for snapping to guides
296     _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"), _("Always snap"),
297                 _("Snapping distance, in screen pixels, for snapping to guides"), _("Always snap to guides, regardless of the distance"),
298                 _("If set, objects only snap to a guide when it's within the range specified below"),
299                 "guidetolerance", _wr);
301     //Other options to locate here: e.g. visual snapping indicators on/off
303     std::list<Gtk::Widget*> slaves;
304     slaves.push_back(&_rcbsnop);
305     slaves.push_back(&_rcbsnon);
306     _rcbsnn.setSlaveWidgets(slaves);
308     slaves.clear();
309     slaves.push_back(&_rcbsnbbp);
310     slaves.push_back(&_rcbsnbbn);
311     _rcbsnbb.setSlaveWidgets(slaves);
313     slaves.clear();
314     slaves.push_back(&_rcbsnn);
315     slaves.push_back(&_rcbsnbb);
316     slaves.push_back(&_rcbsi);
318     _rcbs.setSlaveWidgets(slaves);
320     Gtk::Label *label_g = manage (new Gtk::Label);
321     label_g->set_markup (_("<b>Snapping</b>"));
322     Gtk::Label *label_w = manage (new Gtk::Label);
323     label_w->set_markup (_("<b>What snaps</b>"));
324     Gtk::Label *label_o = manage (new Gtk::Label);
325     label_o->set_markup (_("<b>Snap to objects</b>"));
326     Gtk::Label *label_gr = manage (new Gtk::Label);
327     label_gr->set_markup (_("<b>Snap to grids</b>"));
328     Gtk::Label *label_gu = manage (new Gtk::Label);
329     label_gu->set_markup (_("<b>Snap to guides</b>"));
331     Gtk::Widget *const array[] =
332     {
333         label_g,            0,
334         0,                  &_rcbs,
335         0,                  &_rcbsi,
336         0,                  0,
337         label_w,            0,
338         0,                  &_rcbsnn,
339         0,                  &_rcbsnbb,
340         0,                  0,
341         label_o,            0,
342         0,                  &_rcbsnop,
343         0,                  &_rcbsnon,
344         0,                  &_rcbsnbbp,
345         0,                  &_rcbsnbbn,
346         0,                  &_rcbsnpb,
347         0,                  _rsu_sno._vbox,
348         0,                  0,
349         label_gr,           0,
350         0,                  _rsu_sn._vbox,
351         0,                  0,
352         label_gu,           0,
353         0,                  _rsu_gusn._vbox
354     };
356     attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
357  }
359 void
360 DocumentProperties::build_snap_dtls()
362     _page_snap_dtls.show();
364     //Other options to locate here: e.g. visual snapping indicators on/off
366     Gtk::Label *label_i= manage (new Gtk::Label);
367     label_i->set_markup (_("<b>Snapping to intersections of</b>"));
368     Gtk::Label *label_m = manage (new Gtk::Label);
369     label_m->set_markup (_("<b>Special points to consider</b>"));
371     Gtk::Widget *const array[] =
372     {
373         label_i,            0,
374         0,                  &_rcbsigg,
375         0,                  &_rcbsils,
376         0,                  0,
377         label_m,            0,
378         0,                  &_rcbic,
379     };
381     attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
384 /**
385 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
386 */
387 void
388 DocumentProperties::update_gridspage()
390     SPDesktop *dt = getDesktop();
391     SPNamedView *nv = sp_desktop_namedview(dt);
393     //remove all tabs
394     while (_grids_notebook.get_n_pages() != 0) {
395         _grids_notebook.remove_page(-1); // this also deletes the page.
396     }
398     //add tabs
399     bool grids_present = false;
400     for (GSList const * l = nv->grids; l != NULL; l = l->next) {
401         Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
402         if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
403         Glib::ustring name(grid->repr->attribute("id"));
404         const char *icon = NULL;
405         switch (grid->getGridType()) {
406             case GRID_RECTANGULAR:
407                 icon = INKSCAPE_ICON_GRID_XY;
408                 break;
409             case GRID_AXONOMETRIC:
410                 icon = INKSCAPE_ICON_GRID_AXONOM;
411                 break;
412             default:
413                 break;
414         }
415         _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
416         grids_present = true;
417     }
418     _grids_notebook.show_all();
420     if (grids_present)
421         _grids_button_remove.set_sensitive(true);
422     else
423         _grids_button_remove.set_sensitive(false);
426 /**
427  * Build grid page of dialog.
428  */
429 void
430 DocumentProperties::build_gridspage()
432     /// \todo FIXME: gray out snapping when grid is off.
433     /// Dissenting view: you want snapping without grid.
435     SPDesktop *dt = getDesktop();
436     SPNamedView *nv = sp_desktop_namedview(dt);
437     (void)nv;
439     _grids_label_crea.set_markup(_("<b>Creation</b>"));
440     _grids_label_def.set_markup(_("<b>Defined grids</b>"));
441     _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
442     _grids_hbox_crea.pack_start(_grids_button_new, true, true);
444     for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
445         _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
446     }
447     _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
449     _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
451     _grids_vbox.set_spacing(4);
452     _grids_vbox.pack_start(_grids_label_crea, false, false);
453     _grids_vbox.pack_start(_grids_hbox_crea, false, false);
454     _grids_vbox.pack_start(_grids_space, false, false);
455     _grids_vbox.pack_start(_grids_label_def, false, false);
456     _grids_vbox.pack_start(_grids_notebook, false, false);
457     _grids_vbox.pack_start(_grids_button_remove, false, false);
459     update_gridspage();
464 /**
465  * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
466  */
467 void
468 DocumentProperties::update()
470     if (_wr.isUpdating()) return;
472     SPDesktop *dt = getDesktop();
473     SPNamedView *nv = sp_desktop_namedview(dt);
475     _wr.setUpdating (true);
476     set_sensitive (true);
478     //-----------------------------------------------------------page page
479     _rcp_bg.setRgba32 (nv->pagecolor);
480     _rcb_canb.setActive (nv->showborder);
481     _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
482     _rcp_bord.setRgba32 (nv->bordercolor);
483     _rcb_shad.setActive (nv->showpageshadow);
485     if (nv->doc_units)
486         _rum_deflt.setUnit (nv->doc_units);
488     double const doc_w_px = sp_document_width(sp_desktop_document(dt));
489     double const doc_h_px = sp_document_height(sp_desktop_document(dt));
490     _page_sizer.setDim (doc_w_px, doc_h_px);
492     //-----------------------------------------------------------guide
493     _rcb_sgui.setActive (nv->showguides);
494     _rcp_gui.setRgba32 (nv->guidecolor);
495     _rcp_hgui.setRgba32 (nv->guidehicolor);
497     //-----------------------------------------------------------snap
499     _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
500     _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
501     _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
502     _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
503     _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
504     _rcbsils.setActive (nv->snap_manager.getSnapIntersectionCS());
505     _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
506     _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
507     _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
508     _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
509     _rcbsnpb.setActive(nv->snap_manager.object.getSnapToPageBorder());
510     _rsu_sno.setValue (nv->objecttolerance);
512     _rsu_sn.setValue (nv->gridtolerance);
514     _rsu_gusn.setValue (nv->guidetolerance);
516     _rcbs.setActive (nv->snap_manager.getSnapEnabledGlobally());
517     _rcbsi.setActive (nv->snapindicator);
519     //-----------------------------------------------------------grids page
521     update_gridspage();
523     _wr.setUpdating (false);
526 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
527 Gtk::HBox&
528 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
530     Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
531     _tab_label_box->set_spacing(4);
532     _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
533                                                        label_image)));
535     Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
536     _tab_label_box->pack_start(*_tab_label);
537     _tab_label_box->show_all();
539     return *_tab_label_box;
542 //--------------------------------------------------------------------
544 void
545 DocumentProperties::on_response (int id)
547     if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
548     {
549         _rcp_bg.closeWindow();
550         _rcp_bord.closeWindow();
551         _rcp_gui.closeWindow();
552         _rcp_hgui.closeWindow();
553     }
555     if (id == Gtk::RESPONSE_CLOSE)
556         hide();
559 void
560 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
562     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
563     repr->addListener(&_repr_events, this);
564     Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
565     root->addListener(&_repr_events, this);
566     update();
569 void
570 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
572     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
573     repr->addListener(&_repr_events, this);
574     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
575     root->addListener(&_repr_events, this);
576     update();
579 void
580 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
582     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
583     repr->removeListenerByData(this);
584     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
585     root->removeListenerByData(this);
588 static void
589 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
591     if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
592         dialog->update_gridspage();
595 static void
596 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
598     if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
599         dialog->update_gridspage();
604 /**
605  * Called when XML node attribute changed; updates dialog widgets.
606  */
607 static void
608 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
610     if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
611         dialog->update();
615 /*########################################################################
616 # BUTTON CLICK HANDLERS    (callbacks)
617 ########################################################################*/
619 void
620 DocumentProperties::onNewGrid()
622     SPDesktop *dt = getDesktop();
623     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
624     SPDocument *doc = sp_desktop_document(dt);
626     Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
627     CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
629     // toggle grid showing to ON:
630     dt->showGrids(true);
634 void
635 DocumentProperties::onRemoveGrid()
637     gint pagenum = _grids_notebook.get_current_page();
638     if (pagenum == -1) // no pages
639       return;
641     SPDesktop *dt = getDesktop();
642     SPNamedView *nv = sp_desktop_namedview(dt);
643     Inkscape::CanvasGrid * found_grid = NULL;
644     int i = 0;
645     for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) {  // not a very nice fix, but works.
646         Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
647         if (pagenum == i) {
648             found_grid = grid;
649             break; // break out of for-loop
650         }
651     }
652     if (found_grid) {
653         // delete the grid that corresponds with the selected tab
654         // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
655         found_grid->repr->parent()->removeChild(found_grid->repr);
656         sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
657     }
661 } // namespace Dialog
662 } // namespace UI
663 } // namespace Inkscape
665 /*
666   Local Variables:
667   mode:c++
668   c-file-style:"stroustrup"
669   c-file-offsets:((innamespace . 0)(inline-open . 0))
670   indent-tabs-mode:nil
671   fill-column:99
672   End:
673 */
674 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :