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), _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")
129 {
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));
152 }
154 void
155 DocumentProperties::init()
156 {
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();
166 }
168 DocumentProperties::~DocumentProperties()
169 {
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);
174 }
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)
187 {
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 table.attach(*arr[i+1], 1, 3, r, r+1,
201 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
202 else if (arr[i])
203 {
204 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
205 label.set_alignment (0.0);
206 table.attach (label, 0, 3, r, r+1,
207 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
208 }
209 else
210 {
211 Gtk::HBox *space = manage (new Gtk::HBox);
212 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
213 table.attach (*space, 0, 1, r, r+1,
214 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
215 }
216 }
217 ++r;
218 }
219 }
221 void
222 DocumentProperties::build_page()
223 {
224 _page_page.show();
226 Gtk::Label* label_gen = manage (new Gtk::Label);
227 label_gen->set_markup (_("<b>General</b>"));
228 Gtk::Label* label_bor = manage (new Gtk::Label);
229 label_bor->set_markup (_("<b>Border</b>"));
230 Gtk::Label *label_for = manage (new Gtk::Label);
231 label_for->set_markup (_("<b>Format</b>"));
232 _page_sizer.init();
234 Gtk::Widget *const widget_array[] =
235 {
236 label_gen, 0,
237 0, &_rum_deflt,
238 _rcp_bg._label, &_rcp_bg,
239 0, 0,
240 label_for, 0,
241 0, &_page_sizer,
242 0, 0,
243 label_bor, 0,
244 0, &_rcb_canb,
245 0, &_rcb_bord,
246 0, &_rcb_shad,
247 _rcp_bord._label, &_rcp_bord,
248 };
250 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
251 }
253 void
254 DocumentProperties::build_guides()
255 {
256 _page_guides.show();
258 Gtk::Label *label_gui = manage (new Gtk::Label);
259 label_gui->set_markup (_("<b>Guides</b>"));
261 Gtk::Widget *const widget_array[] =
262 {
263 label_gui, 0,
264 0, &_rcb_sgui,
265 _rcp_gui._label, &_rcp_gui,
266 _rcp_hgui._label, &_rcp_hgui,
267 0, &_rcbsng,
268 };
270 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
271 }
273 void
274 DocumentProperties::build_snap()
275 {
276 _page_snap.show();
278 _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"), _("Always snap"),
279 _("Snapping distance, in screen pixels, for snapping to objects"), _("Always snap to objects, regardless of their distance"),
280 _("If set, objects only snap to another object when it's within the range specified below"),
281 "objecttolerance", _wr);
283 //Options for snapping to grids
284 _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"), _("Always snap"),
285 _("Snapping distance, in screen pixels, for snapping to grid"), _("Always snap to grids, regardless of the distance"),
286 _("If set, objects only snap to a grid line when it's within the range specified below"),
287 "gridtolerance", _wr);
289 //Options for snapping to guides
290 _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"), _("Always snap"),
291 _("Snapping distance, in screen pixels, for snapping to guides"), _("Always snap to guides, regardless of the distance"),
292 _("If set, objects only snap to a guide when it's within the range specified below"),
293 "guidetolerance", _wr);
295 //Other options to locate here: e.g. visual snapping indicators on/off
297 std::list<Gtk::Widget*> slaves;
298 slaves.push_back(&_rcbsnop);
299 slaves.push_back(&_rcbsnon);
300 _rcbsnn.setSlaveWidgets(slaves);
302 slaves.clear();
303 slaves.push_back(&_rcbsnbbp);
304 slaves.push_back(&_rcbsnbbn);
305 _rcbsnbb.setSlaveWidgets(slaves);
307 slaves.clear();
308 slaves.push_back(&_rcbsnn);
309 slaves.push_back(&_rcbsnbb);
310 slaves.push_back(&_rcbsi);
312 _rcbs.setSlaveWidgets(slaves);
314 Gtk::Label *label_g = manage (new Gtk::Label);
315 label_g->set_markup (_("<b>Snapping</b>"));
316 Gtk::Label *label_w = manage (new Gtk::Label);
317 label_w->set_markup (_("<b>What snaps</b>"));
318 Gtk::Label *label_o = manage (new Gtk::Label);
319 label_o->set_markup (_("<b>Snap to objects</b>"));
320 Gtk::Label *label_gr = manage (new Gtk::Label);
321 label_gr->set_markup (_("<b>Snap to grids</b>"));
322 Gtk::Label *label_gu = manage (new Gtk::Label);
323 label_gu->set_markup (_("<b>Snap to guides</b>"));
325 Gtk::Widget *const array[] =
326 {
327 label_g, 0,
328 0, &_rcbs,
329 0, &_rcbsi,
330 0, 0,
331 label_w, 0,
332 0, &_rcbsnn,
333 0, &_rcbsnbb,
334 0, 0,
335 label_o, 0,
336 0, &_rcbsnop,
337 0, &_rcbsnon,
338 0, &_rcbsnbbp,
339 0, &_rcbsnbbn,
340 0, &_rcbsnpb,
341 0, _rsu_sno._vbox,
342 0, 0,
343 label_gr, 0,
344 0, _rsu_sn._vbox,
345 0, 0,
346 label_gu, 0,
347 0, _rsu_gusn._vbox
348 };
350 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
351 }
353 void
354 DocumentProperties::build_snap_dtls()
355 {
356 _page_snap_dtls.show();
358 //Other options to locate here: e.g. visual snapping indicators on/off
360 Gtk::Label *label_i= manage (new Gtk::Label);
361 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
362 Gtk::Label *label_m = manage (new Gtk::Label);
363 label_m->set_markup (_("<b>Special points to consider</b>"));
365 Gtk::Widget *const array[] =
366 {
367 label_i, 0,
368 0, &_rcbsigg,
369 0, &_rcbsils,
370 0, 0,
371 label_m, 0,
372 0, &_rcbic,
373 };
375 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
376 }
378 /**
379 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
380 */
381 void
382 DocumentProperties::update_gridspage()
383 {
384 SPDesktop *dt = getDesktop();
385 SPNamedView *nv = sp_desktop_namedview(dt);
387 //remove all tabs
388 while (_grids_notebook.get_n_pages() != 0) {
389 _grids_notebook.remove_page(-1); // this also deletes the page.
390 }
392 //add tabs
393 bool grids_present = false;
394 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
395 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
396 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
397 Glib::ustring name(grid->repr->attribute("id"));
398 const char *icon = NULL;
399 switch (grid->getGridType()) {
400 case GRID_RECTANGULAR:
401 icon = INKSCAPE_ICON_GRID_XY;
402 break;
403 case GRID_AXONOMETRIC:
404 icon = INKSCAPE_ICON_GRID_AXONOM;
405 break;
406 default:
407 break;
408 }
409 _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
410 grids_present = true;
411 }
412 _grids_notebook.show_all();
414 if (grids_present)
415 _grids_button_remove.set_sensitive(true);
416 else
417 _grids_button_remove.set_sensitive(false);
418 }
420 /**
421 * Build grid page of dialog.
422 */
423 void
424 DocumentProperties::build_gridspage()
425 {
426 /// \todo FIXME: gray out snapping when grid is off.
427 /// Dissenting view: you want snapping without grid.
429 SPDesktop *dt = getDesktop();
430 SPNamedView *nv = sp_desktop_namedview(dt);
431 (void)nv;
433 _grids_label_crea.set_markup(_("<b>Creation</b>"));
434 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
435 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
436 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
438 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
439 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
440 }
441 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
443 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
445 _grids_vbox.set_spacing(4);
446 _grids_vbox.pack_start(_grids_label_crea, false, false);
447 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
448 _grids_vbox.pack_start(_grids_space, false, false);
449 _grids_vbox.pack_start(_grids_label_def, false, false);
450 _grids_vbox.pack_start(_grids_notebook, false, false);
451 _grids_vbox.pack_start(_grids_button_remove, false, false);
453 update_gridspage();
454 }
458 /**
459 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
460 */
461 void
462 DocumentProperties::update()
463 {
464 if (_wr.isUpdating()) return;
466 SPDesktop *dt = getDesktop();
467 SPNamedView *nv = sp_desktop_namedview(dt);
469 _wr.setUpdating (true);
470 set_sensitive (true);
472 //-----------------------------------------------------------page page
473 _rcp_bg.setRgba32 (nv->pagecolor);
474 _rcb_canb.setActive (nv->showborder);
475 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
476 _rcp_bord.setRgba32 (nv->bordercolor);
477 _rcb_shad.setActive (nv->showpageshadow);
479 if (nv->doc_units)
480 _rum_deflt.setUnit (nv->doc_units);
482 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
483 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
484 _page_sizer.setDim (doc_w_px, doc_h_px);
486 //-----------------------------------------------------------guide
487 _rcb_sgui.setActive (nv->showguides);
488 _rcp_gui.setRgba32 (nv->guidecolor);
489 _rcp_hgui.setRgba32 (nv->guidehicolor);
491 //-----------------------------------------------------------snap
493 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
494 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
495 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
496 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
497 _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
498 _rcbsils.setActive (nv->snap_manager.getSnapIntersectionCS());
499 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
500 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
501 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
502 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
503 _rcbsnpb.setActive(nv->snap_manager.object.getSnapToPageBorder());
504 _rsu_sno.setValue (nv->objecttolerance);
506 _rsu_sn.setValue (nv->gridtolerance);
508 _rsu_gusn.setValue (nv->guidetolerance);
510 _rcbs.setActive (nv->snap_manager.getSnapEnabledGlobally());
511 _rcbsi.setActive (nv->snapindicator);
513 //-----------------------------------------------------------grids page
515 update_gridspage();
517 _wr.setUpdating (false);
518 }
520 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
521 Gtk::HBox&
522 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
523 {
524 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
525 _tab_label_box->set_spacing(4);
526 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
527 label_image)));
529 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
530 _tab_label_box->pack_start(*_tab_label);
531 _tab_label_box->show_all();
533 return *_tab_label_box;
534 }
536 //--------------------------------------------------------------------
538 void
539 DocumentProperties::on_response (int id)
540 {
541 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
542 {
543 _rcp_bg.closeWindow();
544 _rcp_bord.closeWindow();
545 _rcp_gui.closeWindow();
546 _rcp_hgui.closeWindow();
547 }
549 if (id == Gtk::RESPONSE_CLOSE)
550 hide();
551 }
553 void
554 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
555 {
556 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
557 repr->addListener(&_repr_events, this);
558 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
559 root->addListener(&_repr_events, this);
560 update();
561 }
563 void
564 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
565 {
566 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
567 repr->addListener(&_repr_events, this);
568 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
569 root->addListener(&_repr_events, this);
570 update();
571 }
573 void
574 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
575 {
576 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
577 repr->removeListenerByData(this);
578 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
579 root->removeListenerByData(this);
580 }
582 static void
583 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
584 {
585 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
586 dialog->update_gridspage();
587 }
589 static void
590 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
591 {
592 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
593 dialog->update_gridspage();
594 }
598 /**
599 * Called when XML node attribute changed; updates dialog widgets.
600 */
601 static void
602 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
603 {
604 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
605 dialog->update();
606 }
609 /*########################################################################
610 # BUTTON CLICK HANDLERS (callbacks)
611 ########################################################################*/
613 void
614 DocumentProperties::onNewGrid()
615 {
616 SPDesktop *dt = getDesktop();
617 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
618 SPDocument *doc = sp_desktop_document(dt);
620 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
621 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
623 // toggle grid showing to ON:
624 dt->showGrids(true);
625 }
628 void
629 DocumentProperties::onRemoveGrid()
630 {
631 gint pagenum = _grids_notebook.get_current_page();
632 if (pagenum == -1) // no pages
633 return;
635 SPDesktop *dt = getDesktop();
636 SPNamedView *nv = sp_desktop_namedview(dt);
637 Inkscape::CanvasGrid * found_grid = NULL;
638 int i = 0;
639 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
640 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
641 if (pagenum == i) {
642 found_grid = grid;
643 break; // break out of for-loop
644 }
645 }
646 if (found_grid) {
647 // delete the grid that corresponds with the selected tab
648 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
649 found_grid->repr->parent()->removeChild(found_grid->repr);
650 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
651 }
652 }
655 } // namespace Dialog
656 } // namespace UI
657 } // namespace Inkscape
659 /*
660 Local Variables:
661 mode:c++
662 c-file-style:"stroustrup"
663 c-file-offsets:((innamespace . 0)(inline-open . 0))
664 indent-tabs-mode:nil
665 fill-column:99
666 End:
667 */
668 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :