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 *
12 * Copyright (C) 2006-2007 Johan Engelen <johan@shouraizou.nl>
13 * Copyright (C) 2000 - 2005 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 "prefs-utils.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), _page_guides(1, 1),
85 _page_snap(1, 1), _page_snap_dtls(1, 1),
86 _grids_label_crea("", Gtk::ALIGN_LEFT),
87 _grids_button_new(_("_New"), _("Create new grid.")),
88 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
89 _grids_label_def("", Gtk::ALIGN_LEFT),
90 _prefs_path("dialogs.documentoptions")
91 {
92 _tt.enable();
93 _getContents()->set_spacing (4);
94 _getContents()->pack_start(_notebook, true, true);
96 _notebook.append_page(_page_page, _("Page"));
97 _notebook.append_page(_page_guides, _("Guides"));
98 _notebook.append_page(_grids_vbox, _("Grids"));
99 _notebook.append_page(_page_snap, _("Snap"));
100 _notebook.append_page(_page_snap_dtls, _("Snap points"));
102 build_page();
103 build_guides();
104 build_gridspage();
105 build_snap();
106 build_snap_dtls();
108 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
109 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
111 signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
112 signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
113 signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
114 }
116 void
117 DocumentProperties::init()
118 {
119 update();
121 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
122 repr->addListener (&_repr_events, this);
123 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
124 root->addListener (&_repr_events, this);
126 show_all_children();
127 _grids_button_remove.hide();
128 }
130 DocumentProperties::~DocumentProperties()
131 {
132 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
133 repr->removeListenerByData (this);
134 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
135 root->removeListenerByData (this);
136 }
138 //========================================================================
140 /**
141 * Helper function that attaches widgets in a 3xn table. The widgets come in an
142 * array that has two entries per table row. The two entries code for four
143 * possible cases: (0,0) means insert space in first column; (0, non-0) means
144 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
145 * (non-0, non-0) means two widgets in columns 2 and 3.
146 **/
147 inline void
148 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
149 {
150 for (unsigned i = 0, r = start; i < n; i += 2)
151 {
152 if (arr[i] && arr[i+1])
153 {
154 table.attach(*arr[i], 1, 2, r, r+1,
155 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
156 table.attach(*arr[i+1], 2, 3, r, r+1,
157 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
158 }
159 else
160 {
161 if (arr[i+1])
162 table.attach(*arr[i+1], 1, 3, r, r+1,
163 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
164 else if (arr[i])
165 {
166 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
167 label.set_alignment (0.0);
168 table.attach (label, 0, 3, r, r+1,
169 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
170 }
171 else
172 {
173 Gtk::HBox *space = manage (new Gtk::HBox);
174 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
175 table.attach (*space, 0, 1, r, r+1,
176 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
177 }
178 }
179 ++r;
180 }
181 }
183 void
184 DocumentProperties::build_page()
185 {
186 _page_page.show();
188 _rcp_bg.init (_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"),
189 "pagecolor", "inkscape:pageopacity", _wr);
190 _rcb_canb.init (_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false);
191 _rcb_bord.init (_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false);
192 _rcp_bord.init (_("Border _color:"), _("Page border color"),
193 _("Color of the page border"),
194 "bordercolor", "borderopacity", _wr);
195 _rcb_shad.init (_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false);
196 _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
198 Gtk::Label* label_gen = manage (new Gtk::Label);
199 label_gen->set_markup (_("<b>General</b>"));
200 Gtk::Label* label_bor = manage (new Gtk::Label);
201 label_bor->set_markup (_("<b>Border</b>"));
202 Gtk::Label *label_for = manage (new Gtk::Label);
203 label_for->set_markup (_("<b>Format</b>"));
204 _page_sizer.init (_wr);
206 Gtk::Widget *const widget_array[] =
207 {
208 label_gen, 0,
209 _rum_deflt._label, _rum_deflt._sel,
210 _rcp_bg._label, _rcp_bg._cp,
211 0, 0,
212 label_for, 0,
213 0, &_page_sizer,
214 0, 0,
215 label_bor, 0,
216 0, _rcb_canb._button,
217 0, _rcb_bord._button,
218 0, _rcb_shad._button,
219 _rcp_bord._label, _rcp_bord._cp,
220 };
222 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
223 }
225 void
226 DocumentProperties::build_guides()
227 {
228 _page_guides.show();
230 _rcb_sgui.init (_("Show _guides"), _("Show or hide guides"), "showguides", _wr);
231 _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"),
232 _("Color of guidelines"), "guidecolor", "guideopacity", _wr);
233 _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"),
234 _("Color of a guideline when it is under mouse"),
235 "guidehicolor", "guidehiopacity", _wr);
237 _rcbsng.init (_("_Snap guides while dragging"),
238 _("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)"),
239 "inkscape:snap-guide", _wr);
241 Gtk::Label *label_gui = manage (new Gtk::Label);
242 label_gui->set_markup (_("<b>Guides</b>"));
244 Gtk::Widget *const widget_array[] =
245 {
246 label_gui, 0,
247 0, _rcb_sgui._button,
248 _rcp_gui._label, _rcp_gui._cp,
249 _rcp_hgui._label, _rcp_hgui._cp,
250 0, _rcbsng._button,
251 };
253 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
254 }
256 void
257 DocumentProperties::build_snap()
258 {
259 _page_snap.show();
260 //General options
261 _rcbsg.init (_("_Enable snapping"),
262 _("Toggle snapping on or off"),
263 "inkscape:snap-global", _wr);
264 _rcbsnbb.init (_("_Bounding box corners"),
265 _("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)"),
266 "inkscape:snap-bbox", _wr);
267 _rcbsnn.init (_("_Nodes"),
268 _("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"),
269 "inkscape:snap-nodes", _wr);
271 //Options for snapping to objects
272 _rcbsnop.init (_("Snap to path_s"),
273 _("Snap nodes to object paths"),
274 "inkscape:object-paths", _wr);
275 _rcbsnon.init (_("Snap to n_odes"),
276 _("Snap nodes and guides to object nodes"),
277 "inkscape:object-nodes", _wr);
278 _rcbsnbbn.init (_("Snap to bounding box co_rners"),
279 _("Snap bounding box corners to other bounding box corners"),
280 "inkscape:bbox-nodes", _wr);
281 _rcbsnbbp.init (_("Snap to bounding bo_x edges"),
282 _("Snap bounding box corners and guides to bounding box edges"),
283 "inkscape:bbox-paths", _wr);
285 _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"),
286 _("Snapping distance, in screen pixels, for snapping to objects"),
287 _("If set, objects only snap to another object when it's within the range specified below"),
288 "objecttolerance", _wr);
290 //Options for snapping to grids
291 _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"),
292 _("Snapping distance, in screen pixels, for snapping to grid"),
293 _("If set, objects only snap to a grid line when it's within the range specified below"),
294 "gridtolerance", _wr);
296 //Options for snapping to guides
297 _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"),
298 _("Snapping distance, in screen pixels, for snapping to guides"),
299 _("If set, objects only snap to a guide when it's within the range specified below"),
300 "guidetolerance", _wr);
302 //Other options to locate here: e.g. visual snapping indicators on/off
304 std::list<Gtk::ToggleButton*> slaves;
305 slaves.push_back(_rcbsnop._button);
306 slaves.push_back(_rcbsnon._button);
307 _rcbsnn.setSlaveButton(slaves);
309 slaves.clear();
310 slaves.push_back(_rcbsnbbp._button);
311 slaves.push_back(_rcbsnbbn._button);
312 _rcbsnbb.setSlaveButton(slaves);
314 slaves.clear();
315 slaves.push_back(_rcbsnn._button);
316 slaves.push_back(_rcbsnbb._button);
318 _rcbsg.setSlaveButton(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, _rcbsg._button,
335 0, 0,
336 label_w, 0,
337 0, _rcbsnn._button,
338 0, _rcbsnbb._button,
339 0, 0,
340 label_o, 0,
341 0, _rcbsnop._button,
342 0, _rcbsnon._button,
343 0, _rcbsnbbp._button,
344 0, _rcbsnbbn._button,
345 0, _rsu_sno._vbox,
346 0, 0,
347 label_gr, 0,
348 0, _rsu_sn._vbox,
349 0, 0,
350 label_gu, 0,
351 0, _rsu_gusn._vbox
352 };
354 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
355 }
357 void
358 DocumentProperties::build_snap_dtls()
359 {
360 _page_snap_dtls.show();
362 _rcbsigg.init (_("_Grid with guides"),
363 _("Snap to grid-guide intersections"),
364 "inkscape:snap-intersection-grid-guide", _wr);
366 _rcbsils.init (_("_Line segments"),
367 _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
368 "inkscape:snap-intersection-line-segments", _wr);
370 //Applies to both nodes and guides, but not to bboxes, that's why its located here
371 _rcbic.init (_("Rotation _center"),
372 _("Consider the rotation center of an object when snapping"),
373 "inkscape:snap-center", _wr);
375 //Other options to locate here: e.g. visual snapping indicators on/off
377 Gtk::Label *label_i= manage (new Gtk::Label);
378 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
379 Gtk::Label *label_m = manage (new Gtk::Label);
380 label_m->set_markup (_("<b>Snapping to special nodes</b>"));
382 Gtk::Widget *const array[] =
383 {
384 label_i, 0,
385 0, _rcbsigg._button,
386 0, _rcbsils._button,
387 0, 0,
388 label_m, 0,
389 0, _rcbic._button,
390 };
392 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
393 }
395 /**
396 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
397 */
398 void
399 DocumentProperties::update_gridspage()
400 {
401 SPDesktop *dt = getDesktop();
402 SPNamedView *nv = sp_desktop_namedview(dt);
404 //remove all tabs
405 while (_grids_notebook.get_current_page() != -1) {
406 _grids_notebook.remove_page(-1);
407 }
409 //add tabs
410 bool grids_present = false;
411 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
412 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
413 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
414 Glib::ustring name(grid->repr->attribute("id"));
415 const char *icon = NULL;
416 switch (grid->getGridType()) {
417 case GRID_RECTANGULAR:
418 icon = INKSCAPE_ICON_GRID_XY;
419 break;
420 case GRID_AXONOMETRIC:
421 icon = INKSCAPE_ICON_GRID_AXONOM;
422 break;
423 default:
424 break;
425 }
426 _grids_notebook.append_page(grid->getWidget(), _createPageTabLabel(name, icon));
427 grids_present = true;
428 }
429 _grids_notebook.show_all();
431 if (grids_present)
432 _grids_button_remove.show();
433 else
434 _grids_button_remove.hide();
435 }
437 /**
438 * Build grid page of dialog.
439 */
440 void
441 DocumentProperties::build_gridspage()
442 {
443 /// \todo FIXME: gray out snapping when grid is off.
444 /// Dissenting view: you want snapping without grid.
446 SPDesktop *dt = getDesktop();
447 SPNamedView *nv = sp_desktop_namedview(dt);
449 _grids_label_crea.set_markup(_("<b>Creation</b>"));
450 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
451 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
452 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
454 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
455 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
456 }
457 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
459 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
461 _grids_vbox.set_spacing(4);
462 _grids_vbox.pack_start(_grids_label_crea, false, false);
463 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
464 _grids_vbox.pack_start(_grids_space, false, false);
465 _grids_vbox.pack_start(_grids_label_def, false, false);
466 _grids_vbox.pack_start(_grids_notebook, false, false);
467 _grids_vbox.pack_start(_grids_button_remove, false, false);
468 _grids_button_remove.hide();
470 update_gridspage();
471 }
475 /**
476 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
477 */
478 void
479 DocumentProperties::update()
480 {
481 if (_wr.isUpdating()) return;
483 SPDesktop *dt = getDesktop();
484 SPNamedView *nv = sp_desktop_namedview(dt);
486 _wr.setUpdating (true);
487 set_sensitive (true);
489 //-----------------------------------------------------------page page
490 _rcp_bg.setRgba32 (nv->pagecolor);
491 _rcb_canb.setActive (nv->showborder);
492 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
493 _rcp_bord.setRgba32 (nv->bordercolor);
494 _rcb_shad.setActive (nv->showpageshadow);
496 if (nv->doc_units)
497 _rum_deflt.setUnit (nv->doc_units);
499 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
500 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
501 _page_sizer.setDim (doc_w_px, doc_h_px);
503 //-----------------------------------------------------------guide
504 _rcb_sgui.setActive (nv->showguides);
505 _rcp_gui.setRgba32 (nv->guidecolor);
506 _rcp_hgui.setRgba32 (nv->guidehicolor);
508 //-----------------------------------------------------------snap
510 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
511 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
512 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
513 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
514 _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
515 _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS());
516 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
517 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
518 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
519 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
520 _rsu_sno.setValue (nv->objecttolerance);
522 _rsu_sn.setValue (nv->gridtolerance);
524 _rsu_gusn.setValue (nv->guidetolerance);
526 _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally());
528 //-----------------------------------------------------------grids page
530 update_gridspage();
532 _wr.setUpdating (false);
533 }
535 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
536 Gtk::HBox&
537 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
538 {
539 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
540 _tab_label_box->set_spacing(4);
541 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
542 label_image)));
544 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
545 _tab_label_box->pack_start(*_tab_label);
546 _tab_label_box->show_all();
548 return *_tab_label_box;
549 }
551 //--------------------------------------------------------------------
553 void
554 DocumentProperties::on_response (int id)
555 {
556 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
557 {
558 _rcp_bg.closeWindow();
559 _rcp_bord.closeWindow();
560 _rcp_gui.closeWindow();
561 _rcp_hgui.closeWindow();
562 }
564 if (id == Gtk::RESPONSE_CLOSE)
565 hide();
566 }
568 void
569 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
570 {
571 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
572 repr->addListener(&_repr_events, this);
573 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
574 root->addListener(&_repr_events, this);
575 update();
576 }
578 void
579 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
580 {
581 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
582 repr->addListener(&_repr_events, this);
583 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
584 root->addListener(&_repr_events, this);
585 update();
586 }
588 void
589 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
590 {
591 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
592 repr->removeListenerByData(this);
593 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
594 root->removeListenerByData(this);
595 }
597 static void
598 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
599 {
600 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
601 dialog->update_gridspage();
602 }
604 static void
605 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
606 {
607 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
608 dialog->update_gridspage();
609 }
613 /**
614 * Called when XML node attribute changed; updates dialog widgets.
615 */
616 static void
617 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
618 {
619 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
620 dialog->update();
621 }
624 /*########################################################################
625 # BUTTON CLICK HANDLERS (callbacks)
626 ########################################################################*/
628 void
629 DocumentProperties::onNewGrid()
630 {
631 SPDesktop *dt = getDesktop();
632 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
633 SPDocument *doc = sp_desktop_document(dt);
635 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
636 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
638 // toggle grid showing to ON:
639 dt->showGrids(true);
640 }
643 void
644 DocumentProperties::onRemoveGrid()
645 {
646 gint pagenum = _grids_notebook.get_current_page();
647 if (pagenum == -1) // no pages
648 return;
650 SPDesktop *dt = getDesktop();
651 SPNamedView *nv = sp_desktop_namedview(dt);
652 Inkscape::CanvasGrid * found_grid = NULL;
653 int i = 0;
654 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
655 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
656 if (pagenum == i) {
657 found_grid = grid;
658 break; // break out of for-loop
659 }
660 }
661 if (found_grid) {
662 // delete the grid that corresponds with the selected tab
663 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
664 found_grid->repr->parent()->removeChild(found_grid->repr);
665 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
666 }
667 }
670 } // namespace Dialog
671 } // namespace UI
672 } // namespace Inkscape
674 /*
675 Local Variables:
676 mode:c++
677 c-file-style:"stroustrup"
678 c-file-offsets:((innamespace . 0)(inline-open . 0))
679 indent-tabs-mode:nilu
680 fill-column:99
681 End:
682 */
683 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :