6396a61038bf865e13193dfa63bf7f29bbac2099
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 _rcbsg(_("_Enable snapping"), _("Toggle snapping on or off"), "inkscape:snap-global", _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 _rcbsigg(_("_Grid with guides"), _("Snap to grid-guide intersections"), "inkscape:snap-intersection-grid-guide", _wr),
118 _rcbsils(_("_Line segments"), _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
119 "inkscape:snap-intersection-line-segments", _wr),
120 //---------------------------------------------------------------
121 _grids_label_crea("", Gtk::ALIGN_LEFT),
122 //TRANSLATORS: In Grid|_New translate only the word _New. It ref to grid
123 _grids_button_new(Q_("Grid|_New"), _("Create new grid.")),
124 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
125 _grids_label_def("", Gtk::ALIGN_LEFT),
126 //---------------------------------------------------------------
127 _prefs_path("dialogs.documentoptions")
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 table.attach(*arr[i+1], 1, 3, r, r+1,
200 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
201 else if (arr[i])
202 {
203 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
204 label.set_alignment (0.0);
205 table.attach (label, 0, 3, r, r+1,
206 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
207 }
208 else
209 {
210 Gtk::HBox *space = manage (new Gtk::HBox);
211 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
212 table.attach (*space, 0, 1, r, r+1,
213 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
214 }
215 }
216 ++r;
217 }
218 }
220 void
221 DocumentProperties::build_page()
222 {
223 _page_page.show();
225 Gtk::Label* label_gen = manage (new Gtk::Label);
226 label_gen->set_markup (_("<b>General</b>"));
227 Gtk::Label* label_bor = manage (new Gtk::Label);
228 label_bor->set_markup (_("<b>Border</b>"));
229 Gtk::Label *label_for = manage (new Gtk::Label);
230 label_for->set_markup (_("<b>Format</b>"));
231 _page_sizer.init();
233 Gtk::Widget *const widget_array[] =
234 {
235 label_gen, 0,
236 0, &_rum_deflt,
237 _rcp_bg._label, &_rcp_bg,
238 0, 0,
239 label_for, 0,
240 0, &_page_sizer,
241 0, 0,
242 label_bor, 0,
243 0, &_rcb_canb,
244 0, &_rcb_bord,
245 0, &_rcb_shad,
246 _rcp_bord._label, &_rcp_bord,
247 };
249 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
250 }
252 void
253 DocumentProperties::build_guides()
254 {
255 _page_guides.show();
257 Gtk::Label *label_gui = manage (new Gtk::Label);
258 label_gui->set_markup (_("<b>Guides</b>"));
260 Gtk::Widget *const widget_array[] =
261 {
262 label_gui, 0,
263 0, &_rcb_sgui,
264 _rcp_gui._label, &_rcp_gui,
265 _rcp_hgui._label, &_rcp_hgui,
266 0, &_rcbsng,
267 };
269 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
270 }
272 void
273 DocumentProperties::build_snap()
274 {
275 _page_snap.show();
277 _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"), _("Always snap"),
278 _("Snapping distance, in screen pixels, for snapping to objects"), _("Always snap to objects, regardless of their distance"),
279 _("If set, objects only snap to another object when it's within the range specified below"),
280 "objecttolerance", _wr);
282 //Options for snapping to grids
283 _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"), _("Always snap"),
284 _("Snapping distance, in screen pixels, for snapping to grid"), _("Always snap to grids, regardless of the distance"),
285 _("If set, objects only snap to a grid line when it's within the range specified below"),
286 "gridtolerance", _wr);
288 //Options for snapping to guides
289 _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"), _("Always snap"),
290 _("Snapping distance, in screen pixels, for snapping to guides"), _("Always snap to guides, regardless of the distance"),
291 _("If set, objects only snap to a guide when it's within the range specified below"),
292 "guidetolerance", _wr);
294 //Other options to locate here: e.g. visual snapping indicators on/off
296 std::list<Gtk::Widget*> slaves;
297 slaves.push_back(&_rcbsnop);
298 slaves.push_back(&_rcbsnon);
299 _rcbsnn.setSlaveWidgets(slaves);
301 slaves.clear();
302 slaves.push_back(&_rcbsnbbp);
303 slaves.push_back(&_rcbsnbbn);
304 _rcbsnbb.setSlaveWidgets(slaves);
306 slaves.clear();
307 slaves.push_back(&_rcbsnn);
308 slaves.push_back(&_rcbsnbb);
310 _rcbsg.setSlaveWidgets(slaves);
312 Gtk::Label *label_g = manage (new Gtk::Label);
313 label_g->set_markup (_("<b>Snapping</b>"));
314 Gtk::Label *label_w = manage (new Gtk::Label);
315 label_w->set_markup (_("<b>What snaps</b>"));
316 Gtk::Label *label_o = manage (new Gtk::Label);
317 label_o->set_markup (_("<b>Snap to objects</b>"));
318 Gtk::Label *label_gr = manage (new Gtk::Label);
319 label_gr->set_markup (_("<b>Snap to grids</b>"));
320 Gtk::Label *label_gu = manage (new Gtk::Label);
321 label_gu->set_markup (_("<b>Snap to guides</b>"));
323 Gtk::Widget *const array[] =
324 {
325 label_g, 0,
326 0, &_rcbsg,
327 0, 0,
328 label_w, 0,
329 0, &_rcbsnn,
330 0, &_rcbsnbb,
331 0, 0,
332 label_o, 0,
333 0, &_rcbsnop,
334 0, &_rcbsnon,
335 0, &_rcbsnbbp,
336 0, &_rcbsnbbn,
337 0, &_rcbsnpb,
338 0, _rsu_sno._vbox,
339 0, 0,
340 label_gr, 0,
341 0, _rsu_sn._vbox,
342 0, 0,
343 label_gu, 0,
344 0, _rsu_gusn._vbox
345 };
347 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
348 }
350 void
351 DocumentProperties::build_snap_dtls()
352 {
353 _page_snap_dtls.show();
355 //Other options to locate here: e.g. visual snapping indicators on/off
357 Gtk::Label *label_i= manage (new Gtk::Label);
358 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
359 Gtk::Label *label_m = manage (new Gtk::Label);
360 label_m->set_markup (_("<b>Special points to consider</b>"));
362 Gtk::Widget *const array[] =
363 {
364 label_i, 0,
365 0, &_rcbsigg,
366 0, &_rcbsils,
367 0, 0,
368 label_m, 0,
369 0, &_rcbic,
370 };
372 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
373 }
375 /**
376 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
377 */
378 void
379 DocumentProperties::update_gridspage()
380 {
381 SPDesktop *dt = getDesktop();
382 SPNamedView *nv = sp_desktop_namedview(dt);
384 //remove all tabs
385 while (_grids_notebook.get_n_pages() != 0) {
386 _grids_notebook.remove_page(-1); // this also deletes the page.
387 }
389 //add tabs
390 bool grids_present = false;
391 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
392 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
393 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
394 Glib::ustring name(grid->repr->attribute("id"));
395 const char *icon = NULL;
396 switch (grid->getGridType()) {
397 case GRID_RECTANGULAR:
398 icon = INKSCAPE_ICON_GRID_XY;
399 break;
400 case GRID_AXONOMETRIC:
401 icon = INKSCAPE_ICON_GRID_AXONOM;
402 break;
403 default:
404 break;
405 }
406 _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
407 grids_present = true;
408 }
409 _grids_notebook.show_all();
411 if (grids_present)
412 _grids_button_remove.set_sensitive(true);
413 else
414 _grids_button_remove.set_sensitive(false);
415 }
417 /**
418 * Build grid page of dialog.
419 */
420 void
421 DocumentProperties::build_gridspage()
422 {
423 /// \todo FIXME: gray out snapping when grid is off.
424 /// Dissenting view: you want snapping without grid.
426 SPDesktop *dt = getDesktop();
427 SPNamedView *nv = sp_desktop_namedview(dt);
428 (void)nv;
430 _grids_label_crea.set_markup(_("<b>Creation</b>"));
431 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
432 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
433 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
435 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
436 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
437 }
438 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
440 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
442 _grids_vbox.set_spacing(4);
443 _grids_vbox.pack_start(_grids_label_crea, false, false);
444 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
445 _grids_vbox.pack_start(_grids_space, false, false);
446 _grids_vbox.pack_start(_grids_label_def, false, false);
447 _grids_vbox.pack_start(_grids_notebook, false, false);
448 _grids_vbox.pack_start(_grids_button_remove, false, false);
450 update_gridspage();
451 }
455 /**
456 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
457 */
458 void
459 DocumentProperties::update()
460 {
461 if (_wr.isUpdating()) return;
463 SPDesktop *dt = getDesktop();
464 SPNamedView *nv = sp_desktop_namedview(dt);
466 _wr.setUpdating (true);
467 set_sensitive (true);
469 //-----------------------------------------------------------page page
470 _rcp_bg.setRgba32 (nv->pagecolor);
471 _rcb_canb.setActive (nv->showborder);
472 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
473 _rcp_bord.setRgba32 (nv->bordercolor);
474 _rcb_shad.setActive (nv->showpageshadow);
476 if (nv->doc_units)
477 _rum_deflt.setUnit (nv->doc_units);
479 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
480 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
481 _page_sizer.setDim (doc_w_px, doc_h_px);
483 //-----------------------------------------------------------guide
484 _rcb_sgui.setActive (nv->showguides);
485 _rcp_gui.setRgba32 (nv->guidecolor);
486 _rcp_hgui.setRgba32 (nv->guidehicolor);
488 //-----------------------------------------------------------snap
490 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
491 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
492 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
493 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
494 _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
495 _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS());
496 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
497 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
498 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
499 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
500 _rcbsnpb.setActive(nv->snap_manager.object.getSnapToPageBorder());
501 _rsu_sno.setValue (nv->objecttolerance);
503 _rsu_sn.setValue (nv->gridtolerance);
505 _rsu_gusn.setValue (nv->guidetolerance);
507 _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally());
509 //-----------------------------------------------------------grids page
511 update_gridspage();
513 _wr.setUpdating (false);
514 }
516 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
517 Gtk::HBox&
518 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
519 {
520 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
521 _tab_label_box->set_spacing(4);
522 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
523 label_image)));
525 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
526 _tab_label_box->pack_start(*_tab_label);
527 _tab_label_box->show_all();
529 return *_tab_label_box;
530 }
532 //--------------------------------------------------------------------
534 void
535 DocumentProperties::on_response (int id)
536 {
537 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
538 {
539 _rcp_bg.closeWindow();
540 _rcp_bord.closeWindow();
541 _rcp_gui.closeWindow();
542 _rcp_hgui.closeWindow();
543 }
545 if (id == Gtk::RESPONSE_CLOSE)
546 hide();
547 }
549 void
550 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
551 {
552 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
553 repr->addListener(&_repr_events, this);
554 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
555 root->addListener(&_repr_events, this);
556 update();
557 }
559 void
560 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
561 {
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(sp_desktop_document(desktop)->root);
565 root->addListener(&_repr_events, this);
566 update();
567 }
569 void
570 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
571 {
572 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
573 repr->removeListenerByData(this);
574 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
575 root->removeListenerByData(this);
576 }
578 static void
579 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
580 {
581 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
582 dialog->update_gridspage();
583 }
585 static void
586 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
587 {
588 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
589 dialog->update_gridspage();
590 }
594 /**
595 * Called when XML node attribute changed; updates dialog widgets.
596 */
597 static void
598 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
599 {
600 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
601 dialog->update();
602 }
605 /*########################################################################
606 # BUTTON CLICK HANDLERS (callbacks)
607 ########################################################################*/
609 void
610 DocumentProperties::onNewGrid()
611 {
612 SPDesktop *dt = getDesktop();
613 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
614 SPDocument *doc = sp_desktop_document(dt);
616 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
617 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
619 // toggle grid showing to ON:
620 dt->showGrids(true);
621 }
624 void
625 DocumentProperties::onRemoveGrid()
626 {
627 gint pagenum = _grids_notebook.get_current_page();
628 if (pagenum == -1) // no pages
629 return;
631 SPDesktop *dt = getDesktop();
632 SPNamedView *nv = sp_desktop_namedview(dt);
633 Inkscape::CanvasGrid * found_grid = NULL;
634 int i = 0;
635 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
636 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
637 if (pagenum == i) {
638 found_grid = grid;
639 break; // break out of for-loop
640 }
641 }
642 if (found_grid) {
643 // delete the grid that corresponds with the selected tab
644 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
645 found_grid->repr->parent()->removeChild(found_grid->repr);
646 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
647 }
648 }
651 } // namespace Dialog
652 } // namespace UI
653 } // namespace Inkscape
655 /*
656 Local Variables:
657 mode:c++
658 c-file-style:"stroustrup"
659 c-file-offsets:((innamespace . 0)(inline-open . 0))
660 indent-tabs-mode:nil
661 fill-column:99
662 End:
663 */
664 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :