b4199c6784e205c9960efc802f5e802c7fc393b2
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 //---------------------------------------------------------------
93 //General snap options
94 _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr),
95 _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)"),
96 "inkscape:snap-guide", _wr),
97 _rcp_gui(_("Guide co_lor:"), _("Guideline color"), _("Color of guidelines"), "guidecolor", "guideopacity", _wr),
98 _rcp_hgui(_("_Highlight color:"), _("Highlighted guideline color"), _("Color of a guideline when it is under mouse"), "guidehicolor", "guidehiopacity", _wr),
99 //---------------------------------------------------------------
100 _rcbsg(_("_Enable snapping"), _("Toggle snapping on or off"), "inkscape:snap-global", _wr),
101 _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)"),
102 "inkscape:snap-bbox", _wr),
103 _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"),
104 "inkscape:snap-nodes", _wr),
105 //Options for snapping to objects
106 _rcbsnop(_("Snap to path_s"), _("Snap nodes to object paths"), "inkscape:object-paths", _wr),
107 _rcbsnon(_("Snap to n_odes"), _("Snap nodes and guides to object nodes"), "inkscape:object-nodes", _wr),
108 _rcbsnbbp(_("Snap to bounding bo_x edges"), _("Snap bounding box corners and guides to bounding box edges"), "inkscape:bbox-paths", _wr),
109 _rcbsnbbn(_("Snap to bounding box co_rners"), _("Snap bounding box corners to other bounding box corners"), "inkscape:bbox-nodes", _wr),
110 //---------------------------------------------------------------
111 //Applies to both nodes and guides, but not to bboxes, that's why its located here
112 _rcbic( _("Rotation _center"), _("Consider the rotation center of an object when snapping"), "inkscape:snap-center", _wr),
113 _rcbsigg(_("_Grid with guides"), _("Snap to grid-guide intersections"), "inkscape:snap-intersection-grid-guide", _wr),
114 _rcbsils(_("_Line segments"), _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
115 "inkscape:snap-intersection-line-segments", _wr),
116 //---------------------------------------------------------------
117 _grids_label_crea("", Gtk::ALIGN_LEFT),
118 //TRANSLATORS: In Grid|_New translate only the word _New. It ref to grid
119 _grids_button_new(Q_("Grid|_New"), _("Create new grid.")),
120 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
121 _grids_label_def("", Gtk::ALIGN_LEFT),
122 //---------------------------------------------------------------
123 _prefs_path("dialogs.documentoptions")
124 {
125 _tt.enable();
126 _getContents()->set_spacing (4);
127 _getContents()->pack_start(_notebook, true, true);
129 _notebook.append_page(_page_page, _("Page"));
130 _notebook.append_page(_page_guides, _("Guides"));
131 _notebook.append_page(_grids_vbox, _("Grids"));
132 _notebook.append_page(_page_snap, _("Snap"));
133 _notebook.append_page(_page_snap_dtls, _("Snap points"));
135 build_page();
136 build_guides();
137 build_gridspage();
138 build_snap();
139 build_snap_dtls();
141 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
142 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
144 signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
145 signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
146 signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
147 }
149 void
150 DocumentProperties::init()
151 {
152 update();
154 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
155 repr->addListener (&_repr_events, this);
156 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
157 root->addListener (&_repr_events, this);
159 show_all_children();
160 _grids_button_remove.hide();
161 }
163 DocumentProperties::~DocumentProperties()
164 {
165 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
166 repr->removeListenerByData (this);
167 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
168 root->removeListenerByData (this);
169 }
171 //========================================================================
173 /**
174 * Helper function that attaches widgets in a 3xn table. The widgets come in an
175 * array that has two entries per table row. The two entries code for four
176 * possible cases: (0,0) means insert space in first column; (0, non-0) means
177 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
178 * (non-0, non-0) means two widgets in columns 2 and 3.
179 **/
180 inline void
181 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
182 {
183 for (unsigned i = 0, r = start; i < n; i += 2)
184 {
185 if (arr[i] && arr[i+1])
186 {
187 table.attach(*arr[i], 1, 2, r, r+1,
188 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
189 table.attach(*arr[i+1], 2, 3, r, r+1,
190 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
191 }
192 else
193 {
194 if (arr[i+1])
195 table.attach(*arr[i+1], 1, 3, r, r+1,
196 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
197 else if (arr[i])
198 {
199 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
200 label.set_alignment (0.0);
201 table.attach (label, 0, 3, r, r+1,
202 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
203 }
204 else
205 {
206 Gtk::HBox *space = manage (new Gtk::HBox);
207 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
208 table.attach (*space, 0, 1, r, r+1,
209 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
210 }
211 }
212 ++r;
213 }
214 }
216 void
217 DocumentProperties::build_page()
218 {
219 _page_page.show();
221 _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
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>"));
229 _page_sizer.init (_wr);
231 Gtk::Widget *const widget_array[] =
232 {
233 label_gen, 0,
234 _rum_deflt._label, _rum_deflt._sel,
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);
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:nilu
656 fill-column:99
657 End:
658 */
659 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :