7bbafcea0271678551286670555865b2f789dd48
1 /** \file
2 *
3 * Document properties dialog, Gtkmm-style
4 *
5 * Authors:
6 * bulia byak <buliabyak@users.sf.net>
7 * Bryce W. Harrington <bryce@bryceharrington.org>
8 * Lauris Kaplinski <lauris@kaplinski.com>
9 * Jon Phillips <jon@rejon.org>
10 * Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
11 *
12 * Copyright (C) 2006-2007 Johan Engelen <johan@shouraizou.nl>
13 * Copyright (C) 2000 - 2005 Authors
14 *
15 * Released under GNU GPL. Read the file 'COPYING' for more information
16 */
18 #ifdef HAVE_CONFIG_H
19 # include <config.h>
20 #endif
24 #include <gtkmm.h>
25 #include "ui/widget/color-picker.h"
26 #include "ui/widget/scalar-unit.h"
28 #include "xml/node-event-vector.h"
29 #include "helper/units.h"
30 #include "prefs-utils.h"
32 #include "inkscape.h"
33 #include "verbs.h"
34 #include "document.h"
35 #include "desktop-handles.h"
36 #include "desktop.h"
37 #include "sp-namedview.h"
38 #include "widgets/icon.h"
39 #include "document-properties.h"
41 #include "display/canvas-grid.h"
43 using std::pair;
45 namespace Inkscape {
46 namespace UI {
47 namespace Dialog {
49 #define SPACE_SIZE_X 15
50 #define SPACE_SIZE_Y 10
52 #define INKSCAPE_ICON_GRID_XY "grid_xy"
53 #define INKSCAPE_ICON_GRID_AXONOM "grid_axonom"
56 //===================================================
58 //---------------------------------------------------
60 static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
61 static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
62 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
64 static Inkscape::XML::NodeEventVector const _repr_events = {
65 on_child_added, /* child_added */
66 on_child_removed, /* child_removed */
67 on_repr_attr_changed,
68 NULL, /* content_changed */
69 NULL /* order_changed */
70 };
73 DocumentProperties &
74 DocumentProperties::getInstance()
75 {
76 DocumentProperties &instance = *new DocumentProperties();
77 instance.init();
79 return instance;
80 }
82 DocumentProperties::DocumentProperties()
83 : UI::Widget::Panel ("", "dialogs.documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
84 _page_page(1, 1), _page_guides(1, 1),
85 _page_snap(1, 1), _page_snap_dtls(1, 1),
86 _grids_label_crea("", Gtk::ALIGN_LEFT),
87 _grids_button_new(_("_New"), _("Create new grid.")),
88 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
89 _grids_label_def("", Gtk::ALIGN_LEFT),
90 _prefs_path("dialogs.documentoptions")
91 {
92 _tt.enable();
93 _getContents()->set_spacing (4);
94 _getContents()->pack_start(_notebook, true, true);
96 _notebook.append_page(_page_page, _("Page"));
97 _notebook.append_page(_page_guides, _("Guides"));
98 _notebook.append_page(_grids_vbox, _("Grids"));
99 _notebook.append_page(_page_snap, _("Snap"));
100 _notebook.append_page(_page_snap_dtls, _("Snap points"));
102 build_page();
103 build_guides();
104 build_gridspage();
105 build_snap();
106 build_snap_dtls();
108 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
109 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
111 signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
112 signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
113 signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
114 }
116 void
117 DocumentProperties::init()
118 {
119 update();
121 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
122 repr->addListener (&_repr_events, this);
123 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
124 root->addListener (&_repr_events, this);
126 show_all_children();
127 _grids_button_remove.hide();
128 }
130 DocumentProperties::~DocumentProperties()
131 {
132 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
133 repr->removeListenerByData (this);
134 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
135 root->removeListenerByData (this);
136 }
138 //========================================================================
140 /**
141 * Helper function that attaches widgets in a 3xn table. The widgets come in an
142 * array that has two entries per table row. The two entries code for four
143 * possible cases: (0,0) means insert space in first column; (0, non-0) means
144 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
145 * (non-0, non-0) means two widgets in columns 2 and 3.
146 **/
147 inline void
148 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
149 {
150 for (unsigned i = 0, r = start; i < n; i += 2)
151 {
152 if (arr[i] && arr[i+1])
153 {
154 table.attach(*arr[i], 1, 2, r, r+1,
155 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
156 table.attach(*arr[i+1], 2, 3, r, r+1,
157 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
158 }
159 else
160 {
161 if (arr[i+1])
162 table.attach(*arr[i+1], 1, 3, r, r+1,
163 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
164 else if (arr[i])
165 {
166 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
167 label.set_alignment (0.0);
168 table.attach (label, 0, 3, r, r+1,
169 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
170 }
171 else
172 {
173 Gtk::HBox *space = manage (new Gtk::HBox);
174 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
175 table.attach (*space, 0, 1, r, r+1,
176 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
177 }
178 }
179 ++r;
180 }
181 }
183 void
184 DocumentProperties::build_page()
185 {
186 _page_page.show();
188 _rcp_bg.init (_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"),
189 "pagecolor", "inkscape:pageopacity", _wr);
190 _rcb_canb.init (_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false);
191 _rcb_bord.init (_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false);
192 _rcp_bord.init (_("Border _color:"), _("Page border color"),
193 _("Color of the page border"),
194 "bordercolor", "borderopacity", _wr);
195 _rcb_shad.init (_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false);
196 _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
198 Gtk::Label* label_gen = manage (new Gtk::Label);
199 label_gen->set_markup (_("<b>General</b>"));
200 Gtk::Label* label_bor = manage (new Gtk::Label);
201 label_bor->set_markup (_("<b>Border</b>"));
202 Gtk::Label *label_for = manage (new Gtk::Label);
203 label_for->set_markup (_("<b>Format</b>"));
204 _page_sizer.init (_wr);
206 Gtk::Widget *const widget_array[] =
207 {
208 label_gen, 0,
209 _rum_deflt._label, _rum_deflt._sel,
210 _rcp_bg._label, _rcp_bg._cp,
211 0, 0,
212 label_for, 0,
213 0, &_page_sizer,
214 0, 0,
215 label_bor, 0,
216 0, _rcb_canb._button,
217 0, _rcb_bord._button,
218 0, _rcb_shad._button,
219 _rcp_bord._label, _rcp_bord._cp,
220 };
222 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
223 }
225 void
226 DocumentProperties::build_guides()
227 {
228 _page_guides.show();
230 _rcb_sgui.init (_("Show _guides"), _("Show or hide guides"), "showguides", _wr);
231 _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"),
232 _("Color of guidelines"), "guidecolor", "guideopacity", _wr);
233 _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"),
234 _("Color of a guideline when it is under mouse"),
235 "guidehicolor", "guidehiopacity", _wr);
237 _rcbsng.init (_("_Snap guides while dragging"),
238 _("While dragging a guide, snap to object nodes or bounding box corners ('Snap to nodes' or 'snap to bounding box corners' must be enabled in the 'Snap' tab)"),
239 "inkscape:snap-guide", _wr);
241 Gtk::Label *label_gui = manage (new Gtk::Label);
242 label_gui->set_markup (_("<b>Guides</b>"));
244 Gtk::Widget *const widget_array[] =
245 {
246 label_gui, 0,
247 0, _rcb_sgui._button,
248 _rcp_gui._label, _rcp_gui._cp,
249 _rcp_hgui._label, _rcp_hgui._cp,
250 0, _rcbsng._button,
251 };
253 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
254 }
256 void
257 DocumentProperties::build_snap()
258 {
259 _page_snap.show();
260 //General options
261 _rcbsg.init (_("Enable snapping"),
262 _("Toggle snapping on or off"),
263 "inkscape:snap-global", _wr);
264 _rcbsnbb.init (_("_Bounding box corners"),
265 _("Snap bounding box corners to grid lines, to guides, and to other bounding boxes (Snapping of bounding boxes is only available in the selector tool)"),
266 "inkscape:snap-bbox", _wr);
267 _rcbsnn.init (_("_Nodes"),
268 _("Snap nodes to grid lines, to guides, to paths, and to other nodes"),
269 "inkscape:snap-nodes", _wr);
271 //Options for snapping to objects
272 _rcbsnop.init (_("Snap to pat_hs"),
273 _("Snap nodes to object paths"),
274 "inkscape:object-paths", _wr);
275 _rcbsnon.init (_("Snap to n_odes"),
276 _("Snap nodes and guides to object nodes"),
277 "inkscape:object-nodes", _wr);
278 _rcbsnbbn.init (_("Snap to bounding box co_rners"),
279 _("Snap bounding box corners to other bounding box corners"),
280 "inkscape:bbox-nodes", _wr);
281 _rcbsnbbp.init (_("Snap to bounding box _edges"),
282 _("Snap bounding box corners and guides to bounding box edges"),
283 "inkscape:bbox-paths", _wr);
285 _rsu_sno.init (_("Snap _distance"), _("Snap at specified d_istance"),
286 _("Snapping distance, in screen pixels, for snapping to objects"),
287 _("If set, objects only snap to another object when it's within the range specified below"),
288 "objecttolerance", _wr);
290 //Options for snapping to grids
291 _rsu_sn.init (_("Snap di_stance"), _("Snap at specified dis_tance"),
292 _("Snapping distance, in screen pixels, for snapping to grid"),
293 _("If set, objects only snap to a grid line when it's within the range specified below"),
294 "gridtolerance", _wr);
296 //Options for snapping to guides
297 _rsu_gusn.init (_("Snap dist_ance"), _("Snap at specified distan_ce"),
298 _("Snapping distance, in screen pixels, for snapping to guides"),
299 _("If set, objects only snap to a guide when it's within the range specified below"),
300 "guidetolerance", _wr);
302 //Other options to locate here: e.g. visual snapping indicators on/off
304 std::list<Gtk::ToggleButton*> slaves;
305 slaves.push_back(_rcbsnop._button);
306 slaves.push_back(_rcbsnon._button);
307 _rcbsnn.setSlaveButton(slaves);
309 slaves.clear();
310 slaves.push_back(_rcbsnbbp._button);
311 slaves.push_back(_rcbsnbbn._button);
312 _rcbsnbb.setSlaveButton(slaves);
314 slaves.clear();
315 slaves.push_back(_rcbsnn._button);
316 slaves.push_back(_rcbsnbb._button);
318 _rcbsg.setSlaveButton(slaves);
320 Gtk::Label *label_g = manage (new Gtk::Label);
321 label_g->set_markup (_("<b>Snapping</b>"));
322 Gtk::Label *label_w = manage (new Gtk::Label);
323 label_w->set_markup (_("<b>What snaps</b>"));
324 Gtk::Label *label_o = manage (new Gtk::Label);
325 label_o->set_markup (_("<b>Snap to objects</b>"));
326 Gtk::Label *label_gr = manage (new Gtk::Label);
327 label_gr->set_markup (_("<b>Snap to grids</b>"));
328 Gtk::Label *label_gu = manage (new Gtk::Label);
329 label_gu->set_markup (_("<b>Snap to guides</b>"));
331 Gtk::Widget *const array[] =
332 {
333 label_g, 0,
334 0, _rcbsg._button,
335 0, 0,
336 label_w, 0,
337 0, _rcbsnn._button,
338 0, _rcbsnbb._button,
339 0, 0,
340 label_o, 0,
341 0, _rcbsnop._button,
342 0, _rcbsnon._button,
343 0, _rcbsnbbp._button,
344 0, _rcbsnbbn._button,
345 0, _rsu_sno._vbox,
346 0, 0,
347 label_gr, 0,
348 0, _rsu_sn._vbox,
349 0, 0,
350 label_gu, 0,
351 0, _rsu_gusn._vbox
352 };
354 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
355 }
357 void
358 DocumentProperties::build_snap_dtls()
359 {
360 _page_snap_dtls.show();
362 _rcbsigg.init (_("_Grid with guides"),
363 _("Snap to grid-guide intersections"),
364 "inkscape:snap-intersection-grid-guide", _wr);
366 _rcbsils.init (_("_Line segments"),
367 _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
368 "inkscape:snap-intersection-line-segments", _wr);
370 //Applies to both nodes and guides, but not to bboxes, that's why its located here
371 _rcbic.init (_("_Include the object's rotation center"),
372 _("Also snap the rotation center of an object when snapping nodes or guides"),
373 "inkscape:snap-center", _wr);
375 //Other options to locate here: e.g. visual snapping indicators on/off
377 Gtk::Label *label_i= manage (new Gtk::Label);
378 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
379 Gtk::Label *label_m = manage (new Gtk::Label);
380 label_m->set_markup (_("<b>Miscellaneous</b>"));
382 Gtk::Widget *const array[] =
383 {
384 label_i, 0,
385 0, _rcbsigg._button,
386 0, _rcbsils._button,
387 0, 0,
388 label_m, 0,
389 0, _rcbic._button,
390 };
392 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
393 }
395 /**
396 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
397 */
398 void
399 DocumentProperties::update_gridspage()
400 {
401 SPDesktop *dt = getDesktop();
402 SPNamedView *nv = sp_desktop_namedview(dt);
404 //remove all tabs
405 while (_grids_notebook.get_current_page() != -1) {
406 _grids_notebook.remove_page(-1);
407 }
409 //add tabs
410 bool grids_present = false;
411 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
412 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
413 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
414 Glib::ustring name(grid->repr->attribute("id"));
415 const char *icon = NULL;
416 switch (grid->getGridType()) {
417 case GRID_RECTANGULAR:
418 icon = INKSCAPE_ICON_GRID_XY;
419 break;
420 case GRID_AXONOMETRIC:
421 icon = INKSCAPE_ICON_GRID_AXONOM;
422 break;
423 default:
424 break;
425 }
426 _grids_notebook.append_page(grid->getWidget(), _createPageTabLabel(name, icon));
427 grids_present = true;
428 }
429 _grids_notebook.show_all();
431 if (grids_present)
432 _grids_button_remove.show();
433 else
434 _grids_button_remove.hide();
435 }
437 /**
438 * Build grid page of dialog.
439 */
440 void
441 DocumentProperties::build_gridspage()
442 {
443 /// \todo FIXME: gray out snapping when grid is off.
444 /// Dissenting view: you want snapping without grid.
446 SPDesktop *dt = getDesktop();
447 SPNamedView *nv = sp_desktop_namedview(dt);
449 _grids_label_crea.set_markup(_("<b>Creation</b>"));
450 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
451 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
452 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
454 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
455 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
456 }
457 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
459 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
460 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
461 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
462 }
464 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
466 _grids_vbox.set_spacing(4);
467 _grids_vbox.pack_start(_grids_label_crea, false, false);
468 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
469 _grids_vbox.pack_start(_grids_space, false, false);
470 _grids_vbox.pack_start(_grids_label_def, false, false);
471 _grids_vbox.pack_start(_grids_notebook, false, false);
472 _grids_vbox.pack_start(_grids_button_remove, false, false);
473 _grids_button_remove.hide();
474 }
478 /**
479 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
480 */
481 void
482 DocumentProperties::update()
483 {
484 if (_wr.isUpdating()) return;
486 SPDesktop *dt = getDesktop();
487 SPNamedView *nv = sp_desktop_namedview(dt);
489 _wr.setUpdating (true);
490 set_sensitive (true);
492 //-----------------------------------------------------------page page
493 _rcp_bg.setRgba32 (nv->pagecolor);
494 _rcb_canb.setActive (nv->showborder);
495 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
496 _rcp_bord.setRgba32 (nv->bordercolor);
497 _rcb_shad.setActive (nv->showpageshadow);
499 if (nv->doc_units)
500 _rum_deflt.setUnit (nv->doc_units);
502 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
503 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
504 _page_sizer.setDim (doc_w_px, doc_h_px);
506 //-----------------------------------------------------------guide
507 _rcb_sgui.setActive (nv->showguides);
508 _rcp_gui.setRgba32 (nv->guidecolor);
509 _rcp_hgui.setRgba32 (nv->guidehicolor);
511 //-----------------------------------------------------------snap
513 _rcbsnbb.setActive (nv->snap_manager.getSnapModeBBox());
514 _rcbsnn.setActive (nv->snap_manager.getSnapModeNode());
515 _rcbsng.setActive (nv->snap_manager.getSnapModeGuide());
516 _rcbic.setActive (nv->snap_manager.getIncludeItemCenter());
517 _rcbsigg.setActive (nv->snap_manager.getSnapIntersectionGG());
518 _rcbsils.setActive (nv->snap_manager.getSnapIntersectionLS());
519 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
520 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
521 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
522 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
523 _rsu_sno.setValue (nv->objecttolerance);
525 _rsu_sn.setValue (nv->gridtolerance);
527 _rsu_gusn.setValue (nv->guidetolerance);
529 _rcbsg.setActive (nv->snap_manager.getSnapEnabledGlobally());
531 //-----------------------------------------------------------grids page
533 update_gridspage();
535 _wr.setUpdating (false);
536 }
538 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
539 Gtk::HBox&
540 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
541 {
542 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
543 _tab_label_box->set_spacing(4);
544 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
545 label_image)));
547 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
548 _tab_label_box->pack_start(*_tab_label);
549 _tab_label_box->show_all();
551 return *_tab_label_box;
552 }
554 //--------------------------------------------------------------------
556 void
557 DocumentProperties::on_response (int id)
558 {
559 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
560 {
561 _rcp_bg.closeWindow();
562 _rcp_bord.closeWindow();
563 _rcp_gui.closeWindow();
564 _rcp_hgui.closeWindow();
565 }
567 if (id == Gtk::RESPONSE_CLOSE)
568 hide();
569 }
571 void
572 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
573 {
574 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
575 repr->addListener(&_repr_events, this);
576 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
577 root->addListener(&_repr_events, this);
578 update();
579 }
581 void
582 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
583 {
584 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
585 repr->addListener(&_repr_events, this);
586 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
587 root->addListener(&_repr_events, this);
588 update();
589 }
591 void
592 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
593 {
594 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
595 repr->removeListenerByData(this);
596 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
597 root->removeListenerByData(this);
598 }
600 static void
601 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
602 {
603 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
604 dialog->update_gridspage();
605 }
607 static void
608 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
609 {
610 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
611 dialog->update_gridspage();
612 }
616 /**
617 * Called when XML node attribute changed; updates dialog widgets.
618 */
619 static void
620 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
621 {
622 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
623 dialog->update();
624 }
627 /*########################################################################
628 # BUTTON CLICK HANDLERS (callbacks)
629 ########################################################################*/
631 void
632 DocumentProperties::onNewGrid()
633 {
634 SPDesktop *dt = getDesktop();
635 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
636 SPDocument *doc = sp_desktop_document(dt);
638 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
639 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
640 }
643 void
644 DocumentProperties::onRemoveGrid()
645 {
646 gint pagenum = _grids_notebook.get_current_page();
647 if (pagenum == -1) // no pages
648 return;
650 Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
651 if (!page) return;
653 Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
655 // find the grid with name tabtext (it's id) and delete that one.
656 SPDesktop *dt = getDesktop();
657 SPNamedView *nv = sp_desktop_namedview(dt);
658 Inkscape::CanvasGrid * found_grid = NULL;
659 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
660 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
661 gchar const *idtext = grid->repr->attribute("id");
662 if ( !strcmp(tabtext.c_str(), idtext) ) {
663 found_grid = grid;
664 break; // break out of for-loop
665 }
666 }
667 if (found_grid) {
668 // delete the grid that corresponds with the selected tab
669 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
670 found_grid->repr->parent()->removeChild(found_grid->repr);
671 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
672 }
673 }
676 } // namespace Dialog
677 } // namespace UI
678 } // namespace Inkscape
680 /*
681 Local Variables:
682 mode:c++
683 c-file-style:"stroustrup"
684 c-file-offsets:((innamespace . 0)(inline-open . 0))
685 indent-tabs-mode:nilu
686 fill-column:99
687 End:
688 */
689 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :