293e6cf191b6d7756fdb6950b567b9fff64d35a4
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 //---------------------------------------------------------------
91 //General snap options
92 _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr),
93 _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)"),
94 "inkscape:snap-guide", _wr),
95 //---------------------------------------------------------------
96 _rcbsg(_("_Enable snapping"), _("Toggle snapping on or off"), "inkscape:snap-global", _wr),
97 _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)"),
98 "inkscape:snap-bbox", _wr),
99 _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"),
100 "inkscape:snap-nodes", _wr),
101 //Options for snapping to objects
102 _rcbsnop(_("Snap to path_s"), _("Snap nodes to object paths"), "inkscape:object-paths", _wr),
103 _rcbsnon(_("Snap to n_odes"), _("Snap nodes and guides to object nodes"), "inkscape:object-nodes", _wr),
104 _rcbsnbbn(_("Snap to bounding box co_rners"), _("Snap bounding box corners to other bounding box corners"), "inkscape:bbox-nodes", _wr),
105 _rcbsnbbp(_("Snap to bounding bo_x edges"), _("Snap bounding box corners and guides to bounding box edges"), "inkscape:bbox-paths", _wr),
106 //---------------------------------------------------------------
107 //Applies to both nodes and guides, but not to bboxes, that's why its located here
108 _rcbic( _("Rotation _center"), _("Consider the rotation center of an object when snapping"), "inkscape:snap-center", _wr),
109 _rcbsigg(_("_Grid with guides"), _("Snap to grid-guide intersections"), "inkscape:snap-intersection-grid-guide", _wr),
110 _rcbsils(_("_Line segments"), _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
111 "inkscape:snap-intersection-line-segments", _wr),
112 //---------------------------------------------------------------
113 _grids_label_crea("", Gtk::ALIGN_LEFT),
114 _grids_button_new(_("_New"), _("Create new grid.")),
115 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
116 _grids_label_def("", Gtk::ALIGN_LEFT),
117 //---------------------------------------------------------------
118 _prefs_path("dialogs.documentoptions")
119 {
120 _tt.enable();
121 _getContents()->set_spacing (4);
122 _getContents()->pack_start(_notebook, true, true);
124 _notebook.append_page(_page_page, _("Page"));
125 _notebook.append_page(_page_guides, _("Guides"));
126 _notebook.append_page(_grids_vbox, _("Grids"));
127 _notebook.append_page(_page_snap, _("Snap"));
128 _notebook.append_page(_page_snap_dtls, _("Snap points"));
130 build_page();
131 build_guides();
132 build_gridspage();
133 build_snap();
134 build_snap_dtls();
136 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
137 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
139 signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
140 signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
141 signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
142 }
144 void
145 DocumentProperties::init()
146 {
147 update();
149 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
150 repr->addListener (&_repr_events, this);
151 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
152 root->addListener (&_repr_events, this);
154 show_all_children();
155 _grids_button_remove.hide();
156 }
158 DocumentProperties::~DocumentProperties()
159 {
160 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
161 repr->removeListenerByData (this);
162 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
163 root->removeListenerByData (this);
164 }
166 //========================================================================
168 /**
169 * Helper function that attaches widgets in a 3xn table. The widgets come in an
170 * array that has two entries per table row. The two entries code for four
171 * possible cases: (0,0) means insert space in first column; (0, non-0) means
172 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
173 * (non-0, non-0) means two widgets in columns 2 and 3.
174 **/
175 inline void
176 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
177 {
178 for (unsigned i = 0, r = start; i < n; i += 2)
179 {
180 if (arr[i] && arr[i+1])
181 {
182 table.attach(*arr[i], 1, 2, r, r+1,
183 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
184 table.attach(*arr[i+1], 2, 3, r, r+1,
185 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
186 }
187 else
188 {
189 if (arr[i+1])
190 table.attach(*arr[i+1], 1, 3, r, r+1,
191 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
192 else if (arr[i])
193 {
194 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
195 label.set_alignment (0.0);
196 table.attach (label, 0, 3, r, r+1,
197 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
198 }
199 else
200 {
201 Gtk::HBox *space = manage (new Gtk::HBox);
202 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
203 table.attach (*space, 0, 1, r, r+1,
204 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
205 }
206 }
207 ++r;
208 }
209 }
211 void
212 DocumentProperties::build_page()
213 {
214 _page_page.show();
216 _rcp_bg.init( _("Back_ground:"),
217 _("Background color"),
218 _("Color and transparency of the page background (also used for bitmap export)"),
219 "pagecolor", "inkscape:pageopacity", _wr);
220 _rcp_bord.init (_("Border _color:"), _("Page border color"),
221 _("Color of the page border"),
222 "bordercolor", "borderopacity", _wr);
223 _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
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 (_wr);
233 Gtk::Widget *const widget_array[] =
234 {
235 label_gen, 0,
236 _rum_deflt._label, _rum_deflt._sel,
237 _rcp_bg._label, _rcp_bg._cp,
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._cp,
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 _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"),
258 _("Color of guidelines"), "guidecolor", "guideopacity", _wr);
259 _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"),
260 _("Color of a guideline when it is under mouse"),
261 "guidehicolor", "guidehiopacity", _wr);
263 Gtk::Label *label_gui = manage (new Gtk::Label);
264 label_gui->set_markup (_("<b>Guides</b>"));
266 Gtk::Widget *const widget_array[] =
267 {
268 label_gui, 0,
269 0, &_rcb_sgui,
270 _rcp_gui._label, _rcp_gui._cp,
271 _rcp_hgui._label, _rcp_hgui._cp,
272 0, &_rcbsng,
273 };
275 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
276 }
278 void
279 DocumentProperties::build_snap()
280 {
281 _page_snap.show();
283 _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"),
284 _("Snapping distance, in screen pixels, for snapping to objects"),
285 _("If set, objects only snap to another object when it's within the range specified below"),
286 "objecttolerance", _wr);
288 //Options for snapping to grids
289 _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"),
290 _("Snapping distance, in screen pixels, for snapping to grid"),
291 _("If set, objects only snap to a grid line when it's within the range specified below"),
292 "gridtolerance", _wr);
294 //Options for snapping to guides
295 _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"),
296 _("Snapping distance, in screen pixels, for snapping to guides"),
297 _("If set, objects only snap to a guide when it's within the range specified below"),
298 "guidetolerance", _wr);
300 //Other options to locate here: e.g. visual snapping indicators on/off
302 std::list<Gtk::ToggleButton*> slaves;
303 slaves.push_back(&_rcbsnop);
304 slaves.push_back(&_rcbsnon);
305 _rcbsnn.setSlaveButton(slaves);
307 slaves.clear();
308 slaves.push_back(&_rcbsnbbp);
309 slaves.push_back(&_rcbsnbbn);
310 _rcbsnbb.setSlaveButton(slaves);
312 slaves.clear();
313 slaves.push_back(&_rcbsnn);
314 slaves.push_back(&_rcbsnbb);
316 _rcbsg.setSlaveButton(slaves);
318 Gtk::Label *label_g = manage (new Gtk::Label);
319 label_g->set_markup (_("<b>Snapping</b>"));
320 Gtk::Label *label_w = manage (new Gtk::Label);
321 label_w->set_markup (_("<b>What snaps</b>"));
322 Gtk::Label *label_o = manage (new Gtk::Label);
323 label_o->set_markup (_("<b>Snap to objects</b>"));
324 Gtk::Label *label_gr = manage (new Gtk::Label);
325 label_gr->set_markup (_("<b>Snap to grids</b>"));
326 Gtk::Label *label_gu = manage (new Gtk::Label);
327 label_gu->set_markup (_("<b>Snap to guides</b>"));
329 Gtk::Widget *const array[] =
330 {
331 label_g, 0,
332 0, &_rcbsg,
333 0, 0,
334 label_w, 0,
335 0, &_rcbsnn,
336 0, &_rcbsnbb,
337 0, 0,
338 label_o, 0,
339 0, &_rcbsnop,
340 0, &_rcbsnon,
341 0, &_rcbsnbbp,
342 0, &_rcbsnbbn,
343 0, _rsu_sno._vbox,
344 0, 0,
345 label_gr, 0,
346 0, _rsu_sn._vbox,
347 0, 0,
348 label_gu, 0,
349 0, _rsu_gusn._vbox
350 };
352 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
353 }
355 void
356 DocumentProperties::build_snap_dtls()
357 {
358 _page_snap_dtls.show();
360 //Other options to locate here: e.g. visual snapping indicators on/off
362 Gtk::Label *label_i= manage (new Gtk::Label);
363 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
364 Gtk::Label *label_m = manage (new Gtk::Label);
365 label_m->set_markup (_("<b>Snapping to special nodes</b>"));
367 Gtk::Widget *const array[] =
368 {
369 label_i, 0,
370 0, &_rcbsigg,
371 0, &_rcbsils,
372 0, 0,
373 label_m, 0,
374 0, &_rcbic,
375 };
377 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
378 }
380 /**
381 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
382 */
383 void
384 DocumentProperties::update_gridspage()
385 {
386 SPDesktop *dt = getDesktop();
387 SPNamedView *nv = sp_desktop_namedview(dt);
389 //remove all tabs
390 while (_grids_notebook.get_n_pages() != 0) {
391 _grids_notebook.remove_page(-1); // this also deletes the page.
392 }
394 //add tabs
395 bool grids_present = false;
396 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
397 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
398 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
399 Glib::ustring name(grid->repr->attribute("id"));
400 const char *icon = NULL;
401 switch (grid->getGridType()) {
402 case GRID_RECTANGULAR:
403 icon = INKSCAPE_ICON_GRID_XY;
404 break;
405 case GRID_AXONOMETRIC:
406 icon = INKSCAPE_ICON_GRID_AXONOM;
407 break;
408 default:
409 break;
410 }
411 _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
412 grids_present = true;
413 }
414 _grids_notebook.show_all();
416 if (grids_present)
417 _grids_button_remove.show();
418 else
419 _grids_button_remove.hide();
420 }
422 /**
423 * Build grid page of dialog.
424 */
425 void
426 DocumentProperties::build_gridspage()
427 {
428 /// \todo FIXME: gray out snapping when grid is off.
429 /// Dissenting view: you want snapping without grid.
431 SPDesktop *dt = getDesktop();
432 SPNamedView *nv = sp_desktop_namedview(dt);
434 _grids_label_crea.set_markup(_("<b>Creation</b>"));
435 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
436 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
437 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
439 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
440 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
441 }
442 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
444 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
446 _grids_vbox.set_spacing(4);
447 _grids_vbox.pack_start(_grids_label_crea, false, false);
448 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
449 _grids_vbox.pack_start(_grids_space, false, false);
450 _grids_vbox.pack_start(_grids_label_def, false, false);
451 _grids_vbox.pack_start(_grids_notebook, false, false);
452 _grids_vbox.pack_start(_grids_button_remove, false, false);
453 _grids_button_remove.hide();
455 update_gridspage();
456 }
460 /**
461 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
462 */
463 void
464 DocumentProperties::update()
465 {
466 if (_wr.isUpdating()) return;
468 SPDesktop *dt = getDesktop();
469 SPNamedView *nv = sp_desktop_namedview(dt);
471 _wr.setUpdating (true);
472 set_sensitive (true);
474 //-----------------------------------------------------------page page
475 _rcp_bg.setRgba32 (nv->pagecolor);
476 _rcb_canb.setActive (nv->showborder);
477 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
478 _rcp_bord.setRgba32 (nv->bordercolor);
479 _rcb_shad.setActive (nv->showpageshadow);
481 if (nv->doc_units)
482 _rum_deflt.setUnit (nv->doc_units);
484 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
485 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
486 _page_sizer.setDim (doc_w_px, doc_h_px);
488 //-----------------------------------------------------------guide
489 _rcb_sgui.setActive (nv->showguides);
490 _rcp_gui.setRgba32 (nv->guidecolor);
491 _rcp_hgui.setRgba32 (nv->guidehicolor);
493 //-----------------------------------------------------------snap
495 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
496 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
497 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
498 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
499 _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
500 _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS());
501 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
502 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
503 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
504 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
505 _rsu_sno.setValue (nv->objecttolerance);
507 _rsu_sn.setValue (nv->gridtolerance);
509 _rsu_gusn.setValue (nv->guidetolerance);
511 _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally());
513 //-----------------------------------------------------------grids page
515 update_gridspage();
517 _wr.setUpdating (false);
518 }
520 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
521 Gtk::HBox&
522 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
523 {
524 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
525 _tab_label_box->set_spacing(4);
526 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
527 label_image)));
529 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
530 _tab_label_box->pack_start(*_tab_label);
531 _tab_label_box->show_all();
533 return *_tab_label_box;
534 }
536 //--------------------------------------------------------------------
538 void
539 DocumentProperties::on_response (int id)
540 {
541 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
542 {
543 _rcp_bg.closeWindow();
544 _rcp_bord.closeWindow();
545 _rcp_gui.closeWindow();
546 _rcp_hgui.closeWindow();
547 }
549 if (id == Gtk::RESPONSE_CLOSE)
550 hide();
551 }
553 void
554 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
555 {
556 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
557 repr->addListener(&_repr_events, this);
558 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
559 root->addListener(&_repr_events, this);
560 update();
561 }
563 void
564 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
565 {
566 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
567 repr->addListener(&_repr_events, this);
568 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
569 root->addListener(&_repr_events, this);
570 update();
571 }
573 void
574 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
575 {
576 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
577 repr->removeListenerByData(this);
578 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
579 root->removeListenerByData(this);
580 }
582 static void
583 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
584 {
585 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
586 dialog->update_gridspage();
587 }
589 static void
590 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
591 {
592 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
593 dialog->update_gridspage();
594 }
598 /**
599 * Called when XML node attribute changed; updates dialog widgets.
600 */
601 static void
602 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
603 {
604 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
605 dialog->update();
606 }
609 /*########################################################################
610 # BUTTON CLICK HANDLERS (callbacks)
611 ########################################################################*/
613 void
614 DocumentProperties::onNewGrid()
615 {
616 SPDesktop *dt = getDesktop();
617 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
618 SPDocument *doc = sp_desktop_document(dt);
620 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
621 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
623 // toggle grid showing to ON:
624 dt->showGrids(true);
625 }
628 void
629 DocumentProperties::onRemoveGrid()
630 {
631 gint pagenum = _grids_notebook.get_current_page();
632 if (pagenum == -1) // no pages
633 return;
635 SPDesktop *dt = getDesktop();
636 SPNamedView *nv = sp_desktop_namedview(dt);
637 Inkscape::CanvasGrid * found_grid = NULL;
638 int i = 0;
639 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
640 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
641 if (pagenum == i) {
642 found_grid = grid;
643 break; // break out of for-loop
644 }
645 }
646 if (found_grid) {
647 // delete the grid that corresponds with the selected tab
648 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
649 found_grid->repr->parent()->removeChild(found_grid->repr);
650 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
651 }
652 }
655 } // namespace Dialog
656 } // namespace UI
657 } // namespace Inkscape
659 /*
660 Local Variables:
661 mode:c++
662 c-file-style:"stroustrup"
663 c-file-offsets:((innamespace . 0)(inline-open . 0))
664 indent-tabs-mode:nilu
665 fill-column:99
666 End:
667 */
668 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :