7c738c5033e28333f95d713adcc6508af8e7091f
1 /** @file
2 * @brief Document properties dialog, Gtkmm-style
3 */
4 /* Authors:
5 * bulia byak <buliabyak@users.sf.net>
6 * Bryce W. Harrington <bryce@bryceharrington.org>
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * Jon Phillips <jon@rejon.org>
9 * Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
10 * Diederik van Lierop <mail@diedenrezi.nl>
11 *
12 * Copyright (C) 2006-2008 Johan Engelen <johan@shouraizou.nl>
13 * Copyright (C) 2000 - 2008 Authors
14 *
15 * Released under GNU GPL. Read the file 'COPYING' for more information
16 */
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
24 #include <gtkmm.h>
25 #include "ui/widget/color-picker.h"
26 #include "ui/widget/scalar-unit.h"
28 #include "xml/node-event-vector.h"
29 #include "helper/units.h"
30 #include "preferences.h"
32 #include "inkscape.h"
33 #include "verbs.h"
34 #include "document.h"
35 #include "desktop-handles.h"
36 #include "desktop.h"
37 #include "sp-namedview.h"
38 #include "widgets/icon.h"
39 #include "document-properties.h"
41 #include "display/canvas-grid.h"
43 using std::pair;
45 namespace Inkscape {
46 namespace UI {
47 namespace Dialog {
49 #define SPACE_SIZE_X 15
50 #define SPACE_SIZE_Y 10
52 #define INKSCAPE_ICON_GRID_XY "grid_xy"
53 #define INKSCAPE_ICON_GRID_AXONOM "grid_axonom"
56 //===================================================
58 //---------------------------------------------------
60 static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
61 static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
62 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
64 static Inkscape::XML::NodeEventVector const _repr_events = {
65 on_child_added, /* child_added */
66 on_child_removed, /* child_removed */
67 on_repr_attr_changed,
68 NULL, /* content_changed */
69 NULL /* order_changed */
70 };
73 DocumentProperties &
74 DocumentProperties::getInstance()
75 {
76 DocumentProperties &instance = *new DocumentProperties();
77 instance.init();
79 return instance;
80 }
82 DocumentProperties::DocumentProperties()
83 : UI::Widget::Panel ("", "/dialogs/documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
84 _page_page(1, 1, true, true), _page_guides(1, 1),
85 _page_snap(1, 1), _page_snap_dtls(1, 1),
86 //---------------------------------------------------------------
87 _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false),
88 _rcb_bord(_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false),
89 _rcb_shad(_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false),
90 _rcp_bg(_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"), "pagecolor", "inkscape:pageopacity", _wr),
91 _rcp_bord(_("Border _color:"), _("Page border color"), _("Color of the page border"), "bordercolor", "borderopacity", _wr),
92 _rum_deflt(_("Default _units:"), "inkscape:document-units", _wr),
93 _page_sizer(_wr),
94 //---------------------------------------------------------------
95 //General snap options
96 _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr),
97 _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)"),
98 "inkscape:snap-guide", _wr),
99 _rcp_gui(_("Guide co_lor:"), _("Guideline color"), _("Color of guidelines"), "guidecolor", "guideopacity", _wr),
100 _rcp_hgui(_("_Highlight color:"), _("Highlighted guideline color"), _("Color of a guideline when it is under mouse"), "guidehicolor", "guidehiopacity", _wr),
101 //---------------------------------------------------------------
102 _rcbs(_("_Enable snapping"), _("Toggle snapping on or off"), "inkscape:snap-global", _wr),
103 _rcbsi(_("_Enable snap indicator"), _("After snapping, a symbol is drawn at the point that has snapped"), "inkscape:snap-indicator", _wr),
104 _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)"),
105 "inkscape:snap-bbox", _wr),
106 _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"),
107 "inkscape:snap-nodes", _wr),
108 //Options for snapping to objects
109 _rcbsnop(_("Snap to path_s"), _("Snap nodes to object paths"), "inkscape:object-paths", _wr),
110 _rcbsnon(_("Snap to n_odes"), _("Snap nodes and guides to object nodes"), "inkscape:object-nodes", _wr),
111 _rcbsnbbp(_("Snap to bounding bo_x edges"), _("Snap bounding box corners and guides to bounding box edges"), "inkscape:bbox-paths", _wr),
112 _rcbsnbbn(_("Snap to bounding box co_rners"), _("Snap bounding box corners to other bounding box corners"), "inkscape:bbox-nodes", _wr),
113 _rcbsnpb(_("Snap to page border"), _("Snap bounding box corners and nodes to the page border"), "inkscape:snap-page", _wr),
114 //---------------------------------------------------------------
115 //Applies to both nodes and guides, but not to bboxes, that's why its located here
116 _rcbic( _("Rotation _center"), _("Consider the rotation center of an object when snapping"), "inkscape:snap-center", _wr),
117 _rcbsm( _("_Smooth nodes"), _("Snap to smooth nodes too, instead of only snapping to cusp nodes"), "inkscape:snap-smooth-nodes", _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 {
129 _tt.enable();
130 _getContents()->set_spacing (4);
131 _getContents()->pack_start(_notebook, true, true);
133 _notebook.append_page(_page_page, _("Page"));
134 _notebook.append_page(_page_guides, _("Guides"));
135 _notebook.append_page(_grids_vbox, _("Grids"));
136 _notebook.append_page(_page_snap, _("Snap"));
137 _notebook.append_page(_page_snap_dtls, _("Snap points"));
139 build_page();
140 build_guides();
141 build_gridspage();
142 build_snap();
143 build_snap_dtls();
145 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
146 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
148 signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
149 signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
150 signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
151 }
153 void
154 DocumentProperties::init()
155 {
156 update();
158 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
159 repr->addListener (&_repr_events, this);
160 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
161 root->addListener (&_repr_events, this);
163 show_all_children();
164 _grids_button_remove.hide();
165 }
167 DocumentProperties::~DocumentProperties()
168 {
169 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
170 repr->removeListenerByData (this);
171 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
172 root->removeListenerByData (this);
173 }
175 //========================================================================
177 /**
178 * Helper function that attaches widgets in a 3xn table. The widgets come in an
179 * array that has two entries per table row. The two entries code for four
180 * possible cases: (0,0) means insert space in first column; (0, non-0) means
181 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
182 * (non-0, non-0) means two widgets in columns 2 and 3.
183 **/
184 inline void
185 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
186 {
187 for (unsigned i = 0, r = start; i < n; i += 2)
188 {
189 if (arr[i] && arr[i+1])
190 {
191 table.attach(*arr[i], 1, 2, r, r+1,
192 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
193 table.attach(*arr[i+1], 2, 3, r, r+1,
194 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
195 }
196 else
197 {
198 if (arr[i+1]) {
199 Gtk::AttachOptions yoptions = (Gtk::AttachOptions)0;
200 if (dynamic_cast<Inkscape::UI::Widget::PageSizer*>(arr[i+1])) {
201 // only the PageSizer in Document Properties|Page should be stretched vertically
202 yoptions = Gtk::FILL|Gtk::EXPAND;
203 }
204 table.attach(*arr[i+1], 1, 3, r, r+1,
205 Gtk::FILL|Gtk::EXPAND, yoptions, 0,0);
206 }
207 else if (arr[i])
208 {
209 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
210 label.set_alignment (0.0);
211 table.attach (label, 0, 3, r, r+1,
212 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
213 }
214 else
215 {
216 Gtk::HBox *space = manage (new Gtk::HBox);
217 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
218 table.attach (*space, 0, 1, r, r+1,
219 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
220 }
221 }
222 ++r;
223 }
224 }
226 void
227 DocumentProperties::build_page()
228 {
229 _page_page.show();
231 Gtk::Label* label_gen = manage (new Gtk::Label);
232 label_gen->set_markup (_("<b>General</b>"));
233 Gtk::Label* label_bor = manage (new Gtk::Label);
234 label_bor->set_markup (_("<b>Border</b>"));
235 Gtk::Label *label_for = manage (new Gtk::Label);
236 label_for->set_markup (_("<b>Format</b>"));
237 _page_sizer.init();
239 Gtk::Widget *const widget_array[] =
240 {
241 label_gen, 0,
242 0, &_rum_deflt,
243 _rcp_bg._label, &_rcp_bg,
244 0, 0,
245 label_for, 0,
246 0, &_page_sizer,
247 0, 0,
248 label_bor, 0,
249 0, &_rcb_canb,
250 0, &_rcb_bord,
251 0, &_rcb_shad,
252 _rcp_bord._label, &_rcp_bord,
253 };
255 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
256 }
258 void
259 DocumentProperties::build_guides()
260 {
261 _page_guides.show();
263 Gtk::Label *label_gui = manage (new Gtk::Label);
264 label_gui->set_markup (_("<b>Guides</b>"));
266 Gtk::Widget *const widget_array[] =
267 {
268 label_gui, 0,
269 0, &_rcb_sgui,
270 _rcp_gui._label, &_rcp_gui,
271 _rcp_hgui._label, &_rcp_hgui,
272 0, &_rcbsng,
273 };
275 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
276 }
278 void
279 DocumentProperties::build_snap()
280 {
281 _page_snap.show();
283 _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"), _("Always snap"),
284 _("Snapping distance, in screen pixels, for snapping to objects"), _("Always snap to objects, regardless of their distance"),
285 _("If set, objects only snap to another object when it's within the range specified below"),
286 "objecttolerance", _wr);
288 //Options for snapping to grids
289 _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"), _("Always snap"),
290 _("Snapping distance, in screen pixels, for snapping to grid"), _("Always snap to grids, regardless of the distance"),
291 _("If set, objects only snap to a grid line when it's within the range specified below"),
292 "gridtolerance", _wr);
294 //Options for snapping to guides
295 _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"), _("Always snap"),
296 _("Snapping distance, in screen pixels, for snapping to guides"), _("Always snap to guides, regardless of the distance"),
297 _("If set, objects only snap to a guide when it's within the range specified below"),
298 "guidetolerance", _wr);
300 //Other options to locate here: e.g. visual snapping indicators on/off
302 std::list<Gtk::Widget*> slaves;
303 slaves.push_back(&_rcbsnop);
304 slaves.push_back(&_rcbsnon);
305 _rcbsnn.setSlaveWidgets(slaves);
307 slaves.clear();
308 slaves.push_back(&_rcbsnbbp);
309 slaves.push_back(&_rcbsnbbn);
310 _rcbsnbb.setSlaveWidgets(slaves);
312 slaves.clear();
313 slaves.push_back(&_rcbsnn);
314 slaves.push_back(&_rcbsnbb);
315 slaves.push_back(&_rcbsi);
317 _rcbs.setSlaveWidgets(slaves);
319 Gtk::Label *label_g = manage (new Gtk::Label);
320 label_g->set_markup (_("<b>Snapping</b>"));
321 Gtk::Label *label_w = manage (new Gtk::Label);
322 label_w->set_markup (_("<b>What snaps</b>"));
323 Gtk::Label *label_o = manage (new Gtk::Label);
324 label_o->set_markup (_("<b>Snap to objects</b>"));
325 Gtk::Label *label_gr = manage (new Gtk::Label);
326 label_gr->set_markup (_("<b>Snap to grids</b>"));
327 Gtk::Label *label_gu = manage (new Gtk::Label);
328 label_gu->set_markup (_("<b>Snap to guides</b>"));
330 Gtk::Widget *const array[] =
331 {
332 label_g, 0,
333 0, &_rcbs,
334 0, &_rcbsi,
335 0, 0,
336 label_w, 0,
337 0, &_rcbsnn,
338 0, &_rcbsnbb,
339 0, 0,
340 label_o, 0,
341 0, &_rcbsnop,
342 0, &_rcbsnon,
343 0, &_rcbsnbbp,
344 0, &_rcbsnbbn,
345 0, &_rcbsnpb,
346 0, _rsu_sno._vbox,
347 0, 0,
348 label_gr, 0,
349 0, _rsu_sn._vbox,
350 0, 0,
351 label_gu, 0,
352 0, _rsu_gusn._vbox
353 };
355 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
356 }
358 void
359 DocumentProperties::build_snap_dtls()
360 {
361 _page_snap_dtls.show();
363 //Other options to locate here: e.g. visual snapping indicators on/off
365 Gtk::Label *label_i= manage (new Gtk::Label);
366 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
367 Gtk::Label *label_m = manage (new Gtk::Label);
368 label_m->set_markup (_("<b>Special points to consider</b>"));
370 Gtk::Widget *const array[] =
371 {
372 label_i, 0,
373 0, &_rcbsigg,
374 0, &_rcbsils,
375 0, 0,
376 label_m, 0,
377 0, &_rcbic,
378 0, &_rcbsm
379 };
381 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
382 }
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()
389 {
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);
424 }
426 /**
427 * Build grid page of dialog.
428 */
429 void
430 DocumentProperties::build_gridspage()
431 {
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();
460 }
464 /**
465 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
466 */
467 void
468 DocumentProperties::update()
469 {
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.snapprefs.getSnapModeBBox());
500 _rcbsnn.setActive (nv->snap_manager.snapprefs.getSnapModeNode());
501 _rcbsng.setActive (nv->snap_manager.snapprefs.getSnapModeGuide());
502 _rcbic.setActive (nv->snap_manager.snapprefs.getIncludeItemCenter());
503 _rcbsm.setActive (nv->snap_manager.snapprefs.getSnapSmoothNodes());
504 _rcbsigg.setActive (nv->snap_manager.snapprefs.getSnapIntersectionGG());
505 _rcbsils.setActive (nv->snap_manager.snapprefs.getSnapIntersectionCS());
506 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
507 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
508 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
509 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
510 _rcbsnpb.setActive(nv->snap_manager.object.getSnapToPageBorder());
511 _rsu_sno.setValue (nv->objecttolerance);
513 _rsu_sn.setValue (nv->gridtolerance);
515 _rsu_gusn.setValue (nv->guidetolerance);
517 _rcbs.setActive (nv->snap_manager.snapprefs.getSnapEnabledGlobally());
518 _rcbsi.setActive (nv->snapindicator);
520 //-----------------------------------------------------------grids page
522 update_gridspage();
524 _wr.setUpdating (false);
525 }
527 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
528 Gtk::HBox&
529 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
530 {
531 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
532 _tab_label_box->set_spacing(4);
533 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
534 label_image)));
536 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
537 _tab_label_box->pack_start(*_tab_label);
538 _tab_label_box->show_all();
540 return *_tab_label_box;
541 }
543 //--------------------------------------------------------------------
545 void
546 DocumentProperties::on_response (int id)
547 {
548 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
549 {
550 _rcp_bg.closeWindow();
551 _rcp_bord.closeWindow();
552 _rcp_gui.closeWindow();
553 _rcp_hgui.closeWindow();
554 }
556 if (id == Gtk::RESPONSE_CLOSE)
557 hide();
558 }
560 void
561 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
562 {
563 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
564 repr->addListener(&_repr_events, this);
565 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
566 root->addListener(&_repr_events, this);
567 update();
568 }
570 void
571 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
572 {
573 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
574 repr->addListener(&_repr_events, this);
575 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
576 root->addListener(&_repr_events, this);
577 update();
578 }
580 void
581 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
582 {
583 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
584 repr->removeListenerByData(this);
585 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
586 root->removeListenerByData(this);
587 }
589 static void
590 on_child_added(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 }
596 static void
597 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
598 {
599 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
600 dialog->update_gridspage();
601 }
605 /**
606 * Called when XML node attribute changed; updates dialog widgets.
607 */
608 static void
609 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
610 {
611 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
612 dialog->update();
613 }
616 /*########################################################################
617 # BUTTON CLICK HANDLERS (callbacks)
618 ########################################################################*/
620 void
621 DocumentProperties::onNewGrid()
622 {
623 SPDesktop *dt = getDesktop();
624 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
625 SPDocument *doc = sp_desktop_document(dt);
627 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
628 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
630 // toggle grid showing to ON:
631 dt->showGrids(true);
632 }
635 void
636 DocumentProperties::onRemoveGrid()
637 {
638 gint pagenum = _grids_notebook.get_current_page();
639 if (pagenum == -1) // no pages
640 return;
642 SPDesktop *dt = getDesktop();
643 SPNamedView *nv = sp_desktop_namedview(dt);
644 Inkscape::CanvasGrid * found_grid = NULL;
645 int i = 0;
646 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
647 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
648 if (pagenum == i) {
649 found_grid = grid;
650 break; // break out of for-loop
651 }
652 }
653 if (found_grid) {
654 // delete the grid that corresponds with the selected tab
655 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
656 found_grid->repr->parent()->removeChild(found_grid->repr);
657 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
658 }
659 }
662 } // namespace Dialog
663 } // namespace UI
664 } // namespace Inkscape
666 /*
667 Local Variables:
668 mode:c++
669 c-file-style:"stroustrup"
670 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
671 indent-tabs-mode:nil
672 fill-column:99
673 End:
674 */
675 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :