4004e151cc59cc1240f5a50d220ff444efa9f323
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 build_page();
138 build_guides();
139 build_gridspage();
140 build_snap();
141 build_snap_dtls();
143 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
144 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
146 signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
147 signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
148 signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
149 }
151 void
152 DocumentProperties::init()
153 {
154 update();
156 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
157 repr->addListener (&_repr_events, this);
158 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
159 root->addListener (&_repr_events, this);
161 show_all_children();
162 _grids_button_remove.hide();
163 }
165 DocumentProperties::~DocumentProperties()
166 {
167 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
168 repr->removeListenerByData (this);
169 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
170 root->removeListenerByData (this);
171 }
173 //========================================================================
175 /**
176 * Helper function that attaches widgets in a 3xn table. The widgets come in an
177 * array that has two entries per table row. The two entries code for four
178 * possible cases: (0,0) means insert space in first column; (0, non-0) means
179 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
180 * (non-0, non-0) means two widgets in columns 2 and 3.
181 **/
182 inline void
183 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
184 {
185 for (unsigned i = 0, r = start; i < n; i += 2)
186 {
187 if (arr[i] && arr[i+1])
188 {
189 table.attach(*arr[i], 1, 2, r, r+1,
190 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
191 table.attach(*arr[i+1], 2, 3, r, r+1,
192 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
193 }
194 else
195 {
196 if (arr[i+1])
197 table.attach(*arr[i+1], 1, 3, r, r+1,
198 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
199 else if (arr[i])
200 {
201 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
202 label.set_alignment (0.0);
203 table.attach (label, 0, 3, r, r+1,
204 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
205 }
206 else
207 {
208 Gtk::HBox *space = manage (new Gtk::HBox);
209 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
210 table.attach (*space, 0, 1, r, r+1,
211 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
212 }
213 }
214 ++r;
215 }
216 }
218 void
219 DocumentProperties::build_page()
220 {
221 _page_page.show();
223 Gtk::Label* label_gen = manage (new Gtk::Label);
224 label_gen->set_markup (_("<b>General</b>"));
225 Gtk::Label* label_bor = manage (new Gtk::Label);
226 label_bor->set_markup (_("<b>Border</b>"));
227 Gtk::Label *label_for = manage (new Gtk::Label);
228 label_for->set_markup (_("<b>Format</b>"));
230 Gtk::Widget *const widget_array[] =
231 {
232 label_gen, 0,
233 0, &_rum_deflt,
234 _rcp_bg._label, &_rcp_bg,
235 0, 0,
236 label_for, 0,
237 0, &_page_sizer,
238 0, 0,
239 label_bor, 0,
240 0, &_rcb_canb,
241 0, &_rcb_bord,
242 0, &_rcb_shad,
243 _rcp_bord._label, &_rcp_bord,
244 };
246 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
247 }
249 void
250 DocumentProperties::build_guides()
251 {
252 _page_guides.show();
254 Gtk::Label *label_gui = manage (new Gtk::Label);
255 label_gui->set_markup (_("<b>Guides</b>"));
257 Gtk::Widget *const widget_array[] =
258 {
259 label_gui, 0,
260 0, &_rcb_sgui,
261 _rcp_gui._label, &_rcp_gui,
262 _rcp_hgui._label, &_rcp_hgui,
263 0, &_rcbsng,
264 };
266 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
267 }
269 void
270 DocumentProperties::build_snap()
271 {
272 _page_snap.show();
274 _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"),
275 _("Snapping distance, in screen pixels, for snapping to objects"),
276 _("If set, objects only snap to another object when it's within the range specified below"),
277 "objecttolerance", _wr);
279 //Options for snapping to grids
280 _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"),
281 _("Snapping distance, in screen pixels, for snapping to grid"),
282 _("If set, objects only snap to a grid line when it's within the range specified below"),
283 "gridtolerance", _wr);
285 //Options for snapping to guides
286 _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"),
287 _("Snapping distance, in screen pixels, for snapping to guides"),
288 _("If set, objects only snap to a guide when it's within the range specified below"),
289 "guidetolerance", _wr);
291 //Other options to locate here: e.g. visual snapping indicators on/off
293 std::list<Gtk::Widget*> slaves;
294 slaves.push_back(&_rcbsnop);
295 slaves.push_back(&_rcbsnon);
296 _rcbsnn.setSlaveWidgets(slaves);
298 slaves.clear();
299 slaves.push_back(&_rcbsnbbp);
300 slaves.push_back(&_rcbsnbbn);
301 _rcbsnbb.setSlaveWidgets(slaves);
303 slaves.clear();
304 slaves.push_back(&_rcbsnn);
305 slaves.push_back(&_rcbsnbb);
307 _rcbsg.setSlaveWidgets(slaves);
309 Gtk::Label *label_g = manage (new Gtk::Label);
310 label_g->set_markup (_("<b>Snapping</b>"));
311 Gtk::Label *label_w = manage (new Gtk::Label);
312 label_w->set_markup (_("<b>What snaps</b>"));
313 Gtk::Label *label_o = manage (new Gtk::Label);
314 label_o->set_markup (_("<b>Snap to objects</b>"));
315 Gtk::Label *label_gr = manage (new Gtk::Label);
316 label_gr->set_markup (_("<b>Snap to grids</b>"));
317 Gtk::Label *label_gu = manage (new Gtk::Label);
318 label_gu->set_markup (_("<b>Snap to guides</b>"));
320 Gtk::Widget *const array[] =
321 {
322 label_g, 0,
323 0, &_rcbsg,
324 0, 0,
325 label_w, 0,
326 0, &_rcbsnn,
327 0, &_rcbsnbb,
328 0, 0,
329 label_o, 0,
330 0, &_rcbsnop,
331 0, &_rcbsnon,
332 0, &_rcbsnbbp,
333 0, &_rcbsnbbn,
334 0, _rsu_sno._vbox,
335 0, 0,
336 label_gr, 0,
337 0, _rsu_sn._vbox,
338 0, 0,
339 label_gu, 0,
340 0, _rsu_gusn._vbox
341 };
343 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
344 }
346 void
347 DocumentProperties::build_snap_dtls()
348 {
349 _page_snap_dtls.show();
351 //Other options to locate here: e.g. visual snapping indicators on/off
353 Gtk::Label *label_i= manage (new Gtk::Label);
354 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
355 Gtk::Label *label_m = manage (new Gtk::Label);
356 label_m->set_markup (_("<b>Snapping to special nodes</b>"));
358 Gtk::Widget *const array[] =
359 {
360 label_i, 0,
361 0, &_rcbsigg,
362 0, &_rcbsils,
363 0, 0,
364 label_m, 0,
365 0, &_rcbic,
366 };
368 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
369 }
371 /**
372 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
373 */
374 void
375 DocumentProperties::update_gridspage()
376 {
377 SPDesktop *dt = getDesktop();
378 SPNamedView *nv = sp_desktop_namedview(dt);
380 //remove all tabs
381 while (_grids_notebook.get_n_pages() != 0) {
382 _grids_notebook.remove_page(-1); // this also deletes the page.
383 }
385 //add tabs
386 bool grids_present = false;
387 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
388 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
389 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
390 Glib::ustring name(grid->repr->attribute("id"));
391 const char *icon = NULL;
392 switch (grid->getGridType()) {
393 case GRID_RECTANGULAR:
394 icon = INKSCAPE_ICON_GRID_XY;
395 break;
396 case GRID_AXONOMETRIC:
397 icon = INKSCAPE_ICON_GRID_AXONOM;
398 break;
399 default:
400 break;
401 }
402 _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
403 grids_present = true;
404 }
405 _grids_notebook.show_all();
407 if (grids_present)
408 _grids_button_remove.set_sensitive(true);
409 else
410 _grids_button_remove.set_sensitive(false);
411 }
413 /**
414 * Build grid page of dialog.
415 */
416 void
417 DocumentProperties::build_gridspage()
418 {
419 /// \todo FIXME: gray out snapping when grid is off.
420 /// Dissenting view: you want snapping without grid.
422 SPDesktop *dt = getDesktop();
423 SPNamedView *nv = sp_desktop_namedview(dt);
424 (void)nv;
426 _grids_label_crea.set_markup(_("<b>Creation</b>"));
427 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
428 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
429 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
431 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
432 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
433 }
434 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
436 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
438 _grids_vbox.set_spacing(4);
439 _grids_vbox.pack_start(_grids_label_crea, false, false);
440 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
441 _grids_vbox.pack_start(_grids_space, false, false);
442 _grids_vbox.pack_start(_grids_label_def, false, false);
443 _grids_vbox.pack_start(_grids_notebook, false, false);
444 _grids_vbox.pack_start(_grids_button_remove, false, false);
446 update_gridspage();
447 }
451 /**
452 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
453 */
454 void
455 DocumentProperties::update()
456 {
457 if (_wr.isUpdating()) return;
459 SPDesktop *dt = getDesktop();
460 SPNamedView *nv = sp_desktop_namedview(dt);
462 _wr.setUpdating (true);
463 set_sensitive (true);
465 //-----------------------------------------------------------page page
466 _rcp_bg.setRgba32 (nv->pagecolor);
467 _rcb_canb.setActive (nv->showborder);
468 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
469 _rcp_bord.setRgba32 (nv->bordercolor);
470 _rcb_shad.setActive (nv->showpageshadow);
472 if (nv->doc_units)
473 _rum_deflt.setUnit (nv->doc_units);
475 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
476 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
477 _page_sizer.setDim (doc_w_px, doc_h_px);
479 //-----------------------------------------------------------guide
480 _rcb_sgui.setActive (nv->showguides);
481 _rcp_gui.setRgba32 (nv->guidecolor);
482 _rcp_hgui.setRgba32 (nv->guidehicolor);
484 //-----------------------------------------------------------snap
486 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
487 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
488 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
489 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
490 _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
491 _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS());
492 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
493 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
494 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
495 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
496 _rsu_sno.setValue (nv->objecttolerance);
498 _rsu_sn.setValue (nv->gridtolerance);
500 _rsu_gusn.setValue (nv->guidetolerance);
502 _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally());
504 //-----------------------------------------------------------grids page
506 update_gridspage();
508 _wr.setUpdating (false);
509 }
511 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
512 Gtk::HBox&
513 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
514 {
515 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
516 _tab_label_box->set_spacing(4);
517 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
518 label_image)));
520 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
521 _tab_label_box->pack_start(*_tab_label);
522 _tab_label_box->show_all();
524 return *_tab_label_box;
525 }
527 //--------------------------------------------------------------------
529 void
530 DocumentProperties::on_response (int id)
531 {
532 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
533 {
534 _rcp_bg.closeWindow();
535 _rcp_bord.closeWindow();
536 _rcp_gui.closeWindow();
537 _rcp_hgui.closeWindow();
538 }
540 if (id == Gtk::RESPONSE_CLOSE)
541 hide();
542 }
544 void
545 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
546 {
547 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
548 repr->addListener(&_repr_events, this);
549 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
550 root->addListener(&_repr_events, this);
551 update();
552 }
554 void
555 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
556 {
557 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
558 repr->addListener(&_repr_events, this);
559 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
560 root->addListener(&_repr_events, this);
561 update();
562 }
564 void
565 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
566 {
567 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
568 repr->removeListenerByData(this);
569 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
570 root->removeListenerByData(this);
571 }
573 static void
574 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
575 {
576 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
577 dialog->update_gridspage();
578 }
580 static void
581 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
582 {
583 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
584 dialog->update_gridspage();
585 }
589 /**
590 * Called when XML node attribute changed; updates dialog widgets.
591 */
592 static void
593 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
594 {
595 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
596 dialog->update();
597 }
600 /*########################################################################
601 # BUTTON CLICK HANDLERS (callbacks)
602 ########################################################################*/
604 void
605 DocumentProperties::onNewGrid()
606 {
607 SPDesktop *dt = getDesktop();
608 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
609 SPDocument *doc = sp_desktop_document(dt);
611 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
612 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
614 // toggle grid showing to ON:
615 dt->showGrids(true);
616 }
619 void
620 DocumentProperties::onRemoveGrid()
621 {
622 gint pagenum = _grids_notebook.get_current_page();
623 if (pagenum == -1) // no pages
624 return;
626 SPDesktop *dt = getDesktop();
627 SPNamedView *nv = sp_desktop_namedview(dt);
628 Inkscape::CanvasGrid * found_grid = NULL;
629 int i = 0;
630 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
631 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
632 if (pagenum == i) {
633 found_grid = grid;
634 break; // break out of for-loop
635 }
636 }
637 if (found_grid) {
638 // delete the grid that corresponds with the selected tab
639 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
640 found_grid->repr->parent()->removeChild(found_grid->repr);
641 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
642 }
643 }
646 } // namespace Dialog
647 } // namespace UI
648 } // namespace Inkscape
650 /*
651 Local Variables:
652 mode:c++
653 c-file-style:"stroustrup"
654 c-file-offsets:((innamespace . 0)(inline-open . 0))
655 indent-tabs-mode:nil
656 fill-column:99
657 End:
658 */
659 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :