572f1ef7e974581b4b8f264caafa0a8c24108341
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-2008 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 //---------------------------------------------------------------
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 _rcbsg(_("_Enable snapping"), _("Toggle snapping on or off"), "inkscape:snap-global", _wr),
103 _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)"),
104 "inkscape:snap-bbox", _wr),
105 _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"),
106 "inkscape:snap-nodes", _wr),
107 //Options for snapping to objects
108 _rcbsnop(_("Snap to path_s"), _("Snap nodes to object paths"), "inkscape:object-paths", _wr),
109 _rcbsnon(_("Snap to n_odes"), _("Snap nodes and guides to object nodes"), "inkscape:object-nodes", _wr),
110 _rcbsnbbp(_("Snap to bounding bo_x edges"), _("Snap bounding box corners and guides to bounding box edges"), "inkscape:bbox-paths", _wr),
111 _rcbsnbbn(_("Snap to bounding box co_rners"), _("Snap bounding box corners to other bounding box corners"), "inkscape:bbox-nodes", _wr),
112 //---------------------------------------------------------------
113 //Applies to both nodes and guides, but not to bboxes, that's why its located here
114 _rcbic( _("Rotation _center"), _("Consider the rotation center of an object when snapping"), "inkscape:snap-center", _wr),
115 _rcbsigg(_("_Grid with guides"), _("Snap to grid-guide intersections"), "inkscape:snap-intersection-grid-guide", _wr),
116 _rcbsils(_("_Line segments"), _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
117 "inkscape:snap-intersection-line-segments", _wr),
118 //---------------------------------------------------------------
119 _grids_label_crea("", Gtk::ALIGN_LEFT),
120 //TRANSLATORS: In Grid|_New translate only the word _New. It ref to grid
121 _grids_button_new(Q_("Grid|_New"), _("Create new grid.")),
122 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
123 _grids_label_def("", Gtk::ALIGN_LEFT),
124 //---------------------------------------------------------------
125 _prefs_path("dialogs.documentoptions")
126 {
127 _tt.enable();
128 _getContents()->set_spacing (4);
129 _getContents()->pack_start(_notebook, true, true);
131 _notebook.append_page(_page_page, _("Page"));
132 _notebook.append_page(_page_guides, _("Guides"));
133 _notebook.append_page(_grids_vbox, _("Grids"));
134 _notebook.append_page(_page_snap, _("Snap"));
135 _notebook.append_page(_page_snap_dtls, _("Snap points"));
137 _page_sizer.init();
138 build_page();
139 build_guides();
140 build_gridspage();
141 build_snap();
142 build_snap_dtls();
144 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
145 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
147 signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
148 signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
149 signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
150 }
152 void
153 DocumentProperties::init()
154 {
155 update();
157 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
158 repr->addListener (&_repr_events, this);
159 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
160 root->addListener (&_repr_events, this);
162 show_all_children();
163 _grids_button_remove.hide();
164 }
166 DocumentProperties::~DocumentProperties()
167 {
168 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
169 repr->removeListenerByData (this);
170 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
171 root->removeListenerByData (this);
172 }
174 //========================================================================
176 /**
177 * Helper function that attaches widgets in a 3xn table. The widgets come in an
178 * array that has two entries per table row. The two entries code for four
179 * possible cases: (0,0) means insert space in first column; (0, non-0) means
180 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
181 * (non-0, non-0) means two widgets in columns 2 and 3.
182 **/
183 inline void
184 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
185 {
186 for (unsigned i = 0, r = start; i < n; i += 2)
187 {
188 if (arr[i] && arr[i+1])
189 {
190 table.attach(*arr[i], 1, 2, r, r+1,
191 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
192 table.attach(*arr[i+1], 2, 3, r, r+1,
193 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
194 }
195 else
196 {
197 if (arr[i+1])
198 table.attach(*arr[i+1], 1, 3, r, r+1,
199 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
200 else if (arr[i])
201 {
202 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
203 label.set_alignment (0.0);
204 table.attach (label, 0, 3, r, r+1,
205 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
206 }
207 else
208 {
209 Gtk::HBox *space = manage (new Gtk::HBox);
210 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
211 table.attach (*space, 0, 1, r, r+1,
212 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
213 }
214 }
215 ++r;
216 }
217 }
219 void
220 DocumentProperties::build_page()
221 {
222 _page_page.show();
224 Gtk::Label* label_gen = manage (new Gtk::Label);
225 label_gen->set_markup (_("<b>General</b>"));
226 Gtk::Label* label_bor = manage (new Gtk::Label);
227 label_bor->set_markup (_("<b>Border</b>"));
228 Gtk::Label *label_for = manage (new Gtk::Label);
229 label_for->set_markup (_("<b>Format</b>"));
231 Gtk::Widget *const widget_array[] =
232 {
233 label_gen, 0,
234 0, &_rum_deflt,
235 _rcp_bg._label, &_rcp_bg,
236 0, 0,
237 label_for, 0,
238 0, &_page_sizer,
239 0, 0,
240 label_bor, 0,
241 0, &_rcb_canb,
242 0, &_rcb_bord,
243 0, &_rcb_shad,
244 _rcp_bord._label, &_rcp_bord,
245 };
247 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
248 }
250 void
251 DocumentProperties::build_guides()
252 {
253 _page_guides.show();
255 Gtk::Label *label_gui = manage (new Gtk::Label);
256 label_gui->set_markup (_("<b>Guides</b>"));
258 Gtk::Widget *const widget_array[] =
259 {
260 label_gui, 0,
261 0, &_rcb_sgui,
262 _rcp_gui._label, &_rcp_gui,
263 _rcp_hgui._label, &_rcp_hgui,
264 0, &_rcbsng,
265 };
267 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
268 }
270 void
271 DocumentProperties::build_snap()
272 {
273 _page_snap.show();
275 _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"),
276 _("Snapping distance, in screen pixels, for snapping to objects"),
277 _("If set, objects only snap to another object when it's within the range specified below"),
278 "objecttolerance", _wr);
280 //Options for snapping to grids
281 _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"),
282 _("Snapping distance, in screen pixels, for snapping to grid"),
283 _("If set, objects only snap to a grid line when it's within the range specified below"),
284 "gridtolerance", _wr);
286 //Options for snapping to guides
287 _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"),
288 _("Snapping distance, in screen pixels, for snapping to guides"),
289 _("If set, objects only snap to a guide when it's within the range specified below"),
290 "guidetolerance", _wr);
292 //Other options to locate here: e.g. visual snapping indicators on/off
294 std::list<Gtk::Widget*> slaves;
295 slaves.push_back(&_rcbsnop);
296 slaves.push_back(&_rcbsnon);
297 _rcbsnn.setSlaveWidgets(slaves);
299 slaves.clear();
300 slaves.push_back(&_rcbsnbbp);
301 slaves.push_back(&_rcbsnbbn);
302 _rcbsnbb.setSlaveWidgets(slaves);
304 slaves.clear();
305 slaves.push_back(&_rcbsnn);
306 slaves.push_back(&_rcbsnbb);
308 _rcbsg.setSlaveWidgets(slaves);
310 Gtk::Label *label_g = manage (new Gtk::Label);
311 label_g->set_markup (_("<b>Snapping</b>"));
312 Gtk::Label *label_w = manage (new Gtk::Label);
313 label_w->set_markup (_("<b>What snaps</b>"));
314 Gtk::Label *label_o = manage (new Gtk::Label);
315 label_o->set_markup (_("<b>Snap to objects</b>"));
316 Gtk::Label *label_gr = manage (new Gtk::Label);
317 label_gr->set_markup (_("<b>Snap to grids</b>"));
318 Gtk::Label *label_gu = manage (new Gtk::Label);
319 label_gu->set_markup (_("<b>Snap to guides</b>"));
321 Gtk::Widget *const array[] =
322 {
323 label_g, 0,
324 0, &_rcbsg,
325 0, 0,
326 label_w, 0,
327 0, &_rcbsnn,
328 0, &_rcbsnbb,
329 0, 0,
330 label_o, 0,
331 0, &_rcbsnop,
332 0, &_rcbsnon,
333 0, &_rcbsnbbp,
334 0, &_rcbsnbbn,
335 0, _rsu_sno._vbox,
336 0, 0,
337 label_gr, 0,
338 0, _rsu_sn._vbox,
339 0, 0,
340 label_gu, 0,
341 0, _rsu_gusn._vbox
342 };
344 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
345 }
347 void
348 DocumentProperties::build_snap_dtls()
349 {
350 _page_snap_dtls.show();
352 //Other options to locate here: e.g. visual snapping indicators on/off
354 Gtk::Label *label_i= manage (new Gtk::Label);
355 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
356 Gtk::Label *label_m = manage (new Gtk::Label);
357 label_m->set_markup (_("<b>Snapping to special nodes</b>"));
359 Gtk::Widget *const array[] =
360 {
361 label_i, 0,
362 0, &_rcbsigg,
363 0, &_rcbsils,
364 0, 0,
365 label_m, 0,
366 0, &_rcbic,
367 };
369 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
370 }
372 /**
373 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
374 */
375 void
376 DocumentProperties::update_gridspage()
377 {
378 SPDesktop *dt = getDesktop();
379 SPNamedView *nv = sp_desktop_namedview(dt);
381 //remove all tabs
382 while (_grids_notebook.get_n_pages() != 0) {
383 _grids_notebook.remove_page(-1); // this also deletes the page.
384 }
386 //add tabs
387 bool grids_present = false;
388 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
389 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
390 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
391 Glib::ustring name(grid->repr->attribute("id"));
392 const char *icon = NULL;
393 switch (grid->getGridType()) {
394 case GRID_RECTANGULAR:
395 icon = INKSCAPE_ICON_GRID_XY;
396 break;
397 case GRID_AXONOMETRIC:
398 icon = INKSCAPE_ICON_GRID_AXONOM;
399 break;
400 default:
401 break;
402 }
403 _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
404 grids_present = true;
405 }
406 _grids_notebook.show_all();
408 if (grids_present)
409 _grids_button_remove.set_sensitive(true);
410 else
411 _grids_button_remove.set_sensitive(false);
412 }
414 /**
415 * Build grid page of dialog.
416 */
417 void
418 DocumentProperties::build_gridspage()
419 {
420 /// \todo FIXME: gray out snapping when grid is off.
421 /// Dissenting view: you want snapping without grid.
423 SPDesktop *dt = getDesktop();
424 SPNamedView *nv = sp_desktop_namedview(dt);
425 (void)nv;
427 _grids_label_crea.set_markup(_("<b>Creation</b>"));
428 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
429 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
430 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
432 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
433 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
434 }
435 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
437 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
439 _grids_vbox.set_spacing(4);
440 _grids_vbox.pack_start(_grids_label_crea, false, false);
441 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
442 _grids_vbox.pack_start(_grids_space, false, false);
443 _grids_vbox.pack_start(_grids_label_def, false, false);
444 _grids_vbox.pack_start(_grids_notebook, false, false);
445 _grids_vbox.pack_start(_grids_button_remove, false, false);
447 update_gridspage();
448 }
452 /**
453 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
454 */
455 void
456 DocumentProperties::update()
457 {
458 if (_wr.isUpdating()) return;
460 SPDesktop *dt = getDesktop();
461 SPNamedView *nv = sp_desktop_namedview(dt);
463 _wr.setUpdating (true);
464 set_sensitive (true);
466 //-----------------------------------------------------------page page
467 _rcp_bg.setRgba32 (nv->pagecolor);
468 _rcb_canb.setActive (nv->showborder);
469 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
470 _rcp_bord.setRgba32 (nv->bordercolor);
471 _rcb_shad.setActive (nv->showpageshadow);
473 if (nv->doc_units)
474 _rum_deflt.setUnit (nv->doc_units);
476 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
477 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
478 _page_sizer.setDim (doc_w_px, doc_h_px);
480 //-----------------------------------------------------------guide
481 _rcb_sgui.setActive (nv->showguides);
482 _rcp_gui.setRgba32 (nv->guidecolor);
483 _rcp_hgui.setRgba32 (nv->guidehicolor);
485 //-----------------------------------------------------------snap
487 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
488 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
489 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
490 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
491 _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
492 _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS());
493 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
494 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
495 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
496 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
497 _rsu_sno.setValue (nv->objecttolerance);
499 _rsu_sn.setValue (nv->gridtolerance);
501 _rsu_gusn.setValue (nv->guidetolerance);
503 _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally());
505 //-----------------------------------------------------------grids page
507 update_gridspage();
509 _wr.setUpdating (false);
510 }
512 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
513 Gtk::HBox&
514 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
515 {
516 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
517 _tab_label_box->set_spacing(4);
518 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
519 label_image)));
521 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
522 _tab_label_box->pack_start(*_tab_label);
523 _tab_label_box->show_all();
525 return *_tab_label_box;
526 }
528 //--------------------------------------------------------------------
530 void
531 DocumentProperties::on_response (int id)
532 {
533 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
534 {
535 _rcp_bg.closeWindow();
536 _rcp_bord.closeWindow();
537 _rcp_gui.closeWindow();
538 _rcp_hgui.closeWindow();
539 }
541 if (id == Gtk::RESPONSE_CLOSE)
542 hide();
543 }
545 void
546 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
547 {
548 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
549 repr->addListener(&_repr_events, this);
550 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
551 root->addListener(&_repr_events, this);
552 update();
553 }
555 void
556 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
557 {
558 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
559 repr->addListener(&_repr_events, this);
560 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
561 root->addListener(&_repr_events, this);
562 update();
563 }
565 void
566 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
567 {
568 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
569 repr->removeListenerByData(this);
570 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
571 root->removeListenerByData(this);
572 }
574 static void
575 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
576 {
577 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
578 dialog->update_gridspage();
579 }
581 static void
582 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
583 {
584 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
585 dialog->update_gridspage();
586 }
590 /**
591 * Called when XML node attribute changed; updates dialog widgets.
592 */
593 static void
594 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
595 {
596 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
597 dialog->update();
598 }
601 /*########################################################################
602 # BUTTON CLICK HANDLERS (callbacks)
603 ########################################################################*/
605 void
606 DocumentProperties::onNewGrid()
607 {
608 SPDesktop *dt = getDesktop();
609 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
610 SPDocument *doc = sp_desktop_document(dt);
612 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
613 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
615 // toggle grid showing to ON:
616 dt->showGrids(true);
617 }
620 void
621 DocumentProperties::onRemoveGrid()
622 {
623 gint pagenum = _grids_notebook.get_current_page();
624 if (pagenum == -1) // no pages
625 return;
627 SPDesktop *dt = getDesktop();
628 SPNamedView *nv = sp_desktop_namedview(dt);
629 Inkscape::CanvasGrid * found_grid = NULL;
630 int i = 0;
631 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
632 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
633 if (pagenum == i) {
634 found_grid = grid;
635 break; // break out of for-loop
636 }
637 }
638 if (found_grid) {
639 // delete the grid that corresponds with the selected tab
640 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
641 found_grid->repr->parent()->removeChild(found_grid->repr);
642 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
643 }
644 }
647 } // namespace Dialog
648 } // namespace UI
649 } // namespace Inkscape
651 /*
652 Local Variables:
653 mode:c++
654 c-file-style:"stroustrup"
655 c-file-offsets:((innamespace . 0)(inline-open . 0))
656 indent-tabs-mode:nil
657 fill-column:99
658 End:
659 */
660 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :