1a1ba3689a21848f1fe61f270b07faee01e42d53
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 _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(
189 _("Back_ground:"),
190 _("Background color"),
191 _("Color and transparency of the page background (also used for bitmap export)"),
192 "pagecolor", "inkscape:pageopacity", _wr);
193 _rcb_canb = Gtk::manage( new RegisteredCheckButton(
194 _("Show page _border"),
195 _("If set, rectangular page border is shown"), "showborder", _wr, false) );
196 _rcb_bord = Gtk::manage( new RegisteredCheckButton(
197 _("Border on _top of drawing"),
198 _("If set, border is always on top of the drawing"), "borderlayer", _wr, false) );
199 _rcp_bord.init (_("Border _color:"), _("Page border color"),
200 _("Color of the page border"),
201 "bordercolor", "borderopacity", _wr);
202 _rcb_shad = Gtk::manage( new RegisteredCheckButton(
203 _("_Show border shadow"),
204 _("If set, page border shows a shadow on its right and lower side"),
205 "inkscape:showpageshadow", _wr, false) );
206 _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
208 Gtk::Label* label_gen = manage (new Gtk::Label);
209 label_gen->set_markup (_("<b>General</b>"));
210 Gtk::Label* label_bor = manage (new Gtk::Label);
211 label_bor->set_markup (_("<b>Border</b>"));
212 Gtk::Label *label_for = manage (new Gtk::Label);
213 label_for->set_markup (_("<b>Format</b>"));
214 _page_sizer.init (_wr);
216 Gtk::Widget *const widget_array[] =
217 {
218 label_gen, 0,
219 _rum_deflt._label, _rum_deflt._sel,
220 _rcp_bg._label, _rcp_bg._cp,
221 0, 0,
222 label_for, 0,
223 0, &_page_sizer,
224 0, 0,
225 label_bor, 0,
226 0, _rcb_canb,
227 0, _rcb_bord,
228 0, _rcb_shad,
229 _rcp_bord._label, _rcp_bord._cp,
230 };
232 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
233 }
235 void
236 DocumentProperties::build_guides()
237 {
238 _page_guides.show();
240 _rcb_sgui = Gtk::manage( new RegisteredCheckButton(
241 _("Show _guides"), _("Show or hide guides"), "showguides", _wr) );
242 _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"),
243 _("Color of guidelines"), "guidecolor", "guideopacity", _wr);
244 _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"),
245 _("Color of a guideline when it is under mouse"),
246 "guidehicolor", "guidehiopacity", _wr);
248 _rcbsng = Gtk::manage( new RegisteredCheckButton(
249 _("_Snap guides while dragging"),
250 _("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)"),
251 "inkscape:snap-guide", _wr) );
253 Gtk::Label *label_gui = manage (new Gtk::Label);
254 label_gui->set_markup (_("<b>Guides</b>"));
256 Gtk::Widget *const widget_array[] =
257 {
258 label_gui, 0,
259 0, _rcb_sgui,
260 _rcp_gui._label, _rcp_gui._cp,
261 _rcp_hgui._label, _rcp_hgui._cp,
262 0, _rcbsng,
263 };
265 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
266 }
268 void
269 DocumentProperties::build_snap()
270 {
271 _page_snap.show();
272 //General options
273 _rcbsg = Gtk::manage( new RegisteredCheckButton( _("_Enable snapping"),
274 _("Toggle snapping on or off"),
275 "inkscape:snap-global", _wr) );
276 _rcbsnbb = Gtk::manage( new RegisteredCheckButton( _("_Bounding box corners"),
277 _("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)"),
278 "inkscape:snap-bbox", _wr) );
279 _rcbsnn = Gtk::manage( new RegisteredCheckButton( _("_Nodes"),
280 _("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"),
281 "inkscape:snap-nodes", _wr) );
283 //Options for snapping to objects
284 _rcbsnop = Gtk::manage( new RegisteredCheckButton( _("Snap to path_s"),
285 _("Snap nodes to object paths"),
286 "inkscape:object-paths", _wr) );
287 _rcbsnon = Gtk::manage( new RegisteredCheckButton( _("Snap to n_odes"),
288 _("Snap nodes and guides to object nodes"),
289 "inkscape:object-nodes", _wr) );
290 _rcbsnbbn = Gtk::manage( new RegisteredCheckButton( _("Snap to bounding box co_rners"),
291 _("Snap bounding box corners to other bounding box corners"),
292 "inkscape:bbox-nodes", _wr) );
293 _rcbsnbbp = Gtk::manage( new RegisteredCheckButton( _("Snap to bounding bo_x edges"),
294 _("Snap bounding box corners and guides to bounding box edges"),
295 "inkscape:bbox-paths", _wr) );
297 _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"),
298 _("Snapping distance, in screen pixels, for snapping to objects"),
299 _("If set, objects only snap to another object when it's within the range specified below"),
300 "objecttolerance", _wr);
302 //Options for snapping to grids
303 _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"),
304 _("Snapping distance, in screen pixels, for snapping to grid"),
305 _("If set, objects only snap to a grid line when it's within the range specified below"),
306 "gridtolerance", _wr);
308 //Options for snapping to guides
309 _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"),
310 _("Snapping distance, in screen pixels, for snapping to guides"),
311 _("If set, objects only snap to a guide when it's within the range specified below"),
312 "guidetolerance", _wr);
314 //Other options to locate here: e.g. visual snapping indicators on/off
316 std::list<Gtk::ToggleButton*> slaves;
317 slaves.push_back(_rcbsnop);
318 slaves.push_back(_rcbsnon);
319 _rcbsnn->setSlaveButton(slaves);
321 slaves.clear();
322 slaves.push_back(_rcbsnbbp);
323 slaves.push_back(_rcbsnbbn);
324 _rcbsnbb->setSlaveButton(slaves);
326 slaves.clear();
327 slaves.push_back(_rcbsnn);
328 slaves.push_back(_rcbsnbb);
330 _rcbsg->setSlaveButton(slaves);
332 Gtk::Label *label_g = manage (new Gtk::Label);
333 label_g->set_markup (_("<b>Snapping</b>"));
334 Gtk::Label *label_w = manage (new Gtk::Label);
335 label_w->set_markup (_("<b>What snaps</b>"));
336 Gtk::Label *label_o = manage (new Gtk::Label);
337 label_o->set_markup (_("<b>Snap to objects</b>"));
338 Gtk::Label *label_gr = manage (new Gtk::Label);
339 label_gr->set_markup (_("<b>Snap to grids</b>"));
340 Gtk::Label *label_gu = manage (new Gtk::Label);
341 label_gu->set_markup (_("<b>Snap to guides</b>"));
343 Gtk::Widget *const array[] =
344 {
345 label_g, 0,
346 0, _rcbsg,
347 0, 0,
348 label_w, 0,
349 0, _rcbsnn,
350 0, _rcbsnbb,
351 0, 0,
352 label_o, 0,
353 0, _rcbsnop,
354 0, _rcbsnon,
355 0, _rcbsnbbp,
356 0, _rcbsnbbn,
357 0, _rsu_sno._vbox,
358 0, 0,
359 label_gr, 0,
360 0, _rsu_sn._vbox,
361 0, 0,
362 label_gu, 0,
363 0, _rsu_gusn._vbox
364 };
366 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
367 }
369 void
370 DocumentProperties::build_snap_dtls()
371 {
372 _page_snap_dtls.show();
374 _rcbsigg = Gtk::manage( new RegisteredCheckButton( _("_Grid with guides"),
375 _("Snap to grid-guide intersections"),
376 "inkscape:snap-intersection-grid-guide", _wr) );
378 _rcbsils = Gtk::manage( new RegisteredCheckButton( _("_Line segments"),
379 _("Snap to intersections of line segments ('snap to paths' must be enabled, see the previous tab)"),
380 "inkscape:snap-intersection-line-segments", _wr) );
382 //Applies to both nodes and guides, but not to bboxes, that's why its located here
383 _rcbic = Gtk::manage( new RegisteredCheckButton( _("Rotation _center"),
384 _("Consider the rotation center of an object when snapping"),
385 "inkscape:snap-center", _wr) );
387 //Other options to locate here: e.g. visual snapping indicators on/off
389 Gtk::Label *label_i= manage (new Gtk::Label);
390 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
391 Gtk::Label *label_m = manage (new Gtk::Label);
392 label_m->set_markup (_("<b>Snapping to special nodes</b>"));
394 Gtk::Widget *const array[] =
395 {
396 label_i, 0,
397 0, _rcbsigg,
398 0, _rcbsils,
399 0, 0,
400 label_m, 0,
401 0, _rcbic,
402 };
404 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
405 }
407 /**
408 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
409 */
410 void
411 DocumentProperties::update_gridspage()
412 {
413 SPDesktop *dt = getDesktop();
414 SPNamedView *nv = sp_desktop_namedview(dt);
416 //remove all tabs
417 while (_grids_notebook.get_n_pages() != 0) {
418 _grids_notebook.remove_page(-1); // this also deletes the page.
419 }
421 //add tabs
422 bool grids_present = false;
423 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
424 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
425 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
426 Glib::ustring name(grid->repr->attribute("id"));
427 const char *icon = NULL;
428 switch (grid->getGridType()) {
429 case GRID_RECTANGULAR:
430 icon = INKSCAPE_ICON_GRID_XY;
431 break;
432 case GRID_AXONOMETRIC:
433 icon = INKSCAPE_ICON_GRID_AXONOM;
434 break;
435 default:
436 break;
437 }
438 _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
439 grids_present = true;
440 }
441 _grids_notebook.show_all();
443 if (grids_present)
444 _grids_button_remove.show();
445 else
446 _grids_button_remove.hide();
447 }
449 /**
450 * Build grid page of dialog.
451 */
452 void
453 DocumentProperties::build_gridspage()
454 {
455 /// \todo FIXME: gray out snapping when grid is off.
456 /// Dissenting view: you want snapping without grid.
458 SPDesktop *dt = getDesktop();
459 SPNamedView *nv = sp_desktop_namedview(dt);
461 _grids_label_crea.set_markup(_("<b>Creation</b>"));
462 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
463 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
464 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
466 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
467 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
468 }
469 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
471 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
473 _grids_vbox.set_spacing(4);
474 _grids_vbox.pack_start(_grids_label_crea, false, false);
475 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
476 _grids_vbox.pack_start(_grids_space, false, false);
477 _grids_vbox.pack_start(_grids_label_def, false, false);
478 _grids_vbox.pack_start(_grids_notebook, false, false);
479 _grids_vbox.pack_start(_grids_button_remove, false, false);
480 _grids_button_remove.hide();
482 update_gridspage();
483 }
487 /**
488 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
489 */
490 void
491 DocumentProperties::update()
492 {
493 if (_wr.isUpdating()) return;
495 SPDesktop *dt = getDesktop();
496 SPNamedView *nv = sp_desktop_namedview(dt);
498 _wr.setUpdating (true);
499 set_sensitive (true);
501 //-----------------------------------------------------------page page
502 _rcp_bg.setRgba32 (nv->pagecolor);
503 _rcb_canb->setActive (nv->showborder);
504 _rcb_bord->setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
505 _rcp_bord.setRgba32 (nv->bordercolor);
506 _rcb_shad->setActive (nv->showpageshadow);
508 if (nv->doc_units)
509 _rum_deflt.setUnit (nv->doc_units);
511 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
512 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
513 _page_sizer.setDim (doc_w_px, doc_h_px);
515 //-----------------------------------------------------------guide
516 _rcb_sgui->setActive (nv->showguides);
517 _rcp_gui.setRgba32 (nv->guidecolor);
518 _rcp_hgui.setRgba32 (nv->guidehicolor);
520 //-----------------------------------------------------------snap
522 _rcbsnbb->setActive (nv->snap_manager.getSnapModeBBox());
523 _rcbsnn->setActive (nv->snap_manager.getSnapModeNode());
524 _rcbsng->setActive (nv->snap_manager.getSnapModeGuide());
525 _rcbic->setActive (nv->snap_manager.getIncludeItemCenter());
526 _rcbsigg->setActive (nv->snap_manager.getSnapIntersectionGG());
527 _rcbsils->setActive (nv->snap_manager.getSnapIntersectionLS());
528 _rcbsnop->setActive(nv->snap_manager.object.getSnapToItemPath());
529 _rcbsnon->setActive(nv->snap_manager.object.getSnapToItemNode());
530 _rcbsnbbp->setActive(nv->snap_manager.object.getSnapToBBoxPath());
531 _rcbsnbbn->setActive(nv->snap_manager.object.getSnapToBBoxNode());
532 _rsu_sno.setValue (nv->objecttolerance);
534 _rsu_sn.setValue (nv->gridtolerance);
536 _rsu_gusn.setValue (nv->guidetolerance);
538 _rcbsg->setActive (nv->snap_manager.getSnapEnabledGlobally());
540 //-----------------------------------------------------------grids page
542 update_gridspage();
544 _wr.setUpdating (false);
545 }
547 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
548 Gtk::HBox&
549 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
550 {
551 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
552 _tab_label_box->set_spacing(4);
553 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
554 label_image)));
556 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
557 _tab_label_box->pack_start(*_tab_label);
558 _tab_label_box->show_all();
560 return *_tab_label_box;
561 }
563 //--------------------------------------------------------------------
565 void
566 DocumentProperties::on_response (int id)
567 {
568 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
569 {
570 _rcp_bg.closeWindow();
571 _rcp_bord.closeWindow();
572 _rcp_gui.closeWindow();
573 _rcp_hgui.closeWindow();
574 }
576 if (id == Gtk::RESPONSE_CLOSE)
577 hide();
578 }
580 void
581 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
582 {
583 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
584 repr->addListener(&_repr_events, this);
585 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
586 root->addListener(&_repr_events, this);
587 update();
588 }
590 void
591 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
592 {
593 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
594 repr->addListener(&_repr_events, this);
595 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
596 root->addListener(&_repr_events, this);
597 update();
598 }
600 void
601 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
602 {
603 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
604 repr->removeListenerByData(this);
605 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
606 root->removeListenerByData(this);
607 }
609 static void
610 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
611 {
612 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
613 dialog->update_gridspage();
614 }
616 static void
617 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
618 {
619 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
620 dialog->update_gridspage();
621 }
625 /**
626 * Called when XML node attribute changed; updates dialog widgets.
627 */
628 static void
629 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
630 {
631 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
632 dialog->update();
633 }
636 /*########################################################################
637 # BUTTON CLICK HANDLERS (callbacks)
638 ########################################################################*/
640 void
641 DocumentProperties::onNewGrid()
642 {
643 SPDesktop *dt = getDesktop();
644 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
645 SPDocument *doc = sp_desktop_document(dt);
647 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
648 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
650 // toggle grid showing to ON:
651 dt->showGrids(true);
652 }
655 void
656 DocumentProperties::onRemoveGrid()
657 {
658 gint pagenum = _grids_notebook.get_current_page();
659 if (pagenum == -1) // no pages
660 return;
662 SPDesktop *dt = getDesktop();
663 SPNamedView *nv = sp_desktop_namedview(dt);
664 Inkscape::CanvasGrid * found_grid = NULL;
665 int i = 0;
666 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
667 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
668 if (pagenum == i) {
669 found_grid = grid;
670 break; // break out of for-loop
671 }
672 }
673 if (found_grid) {
674 // delete the grid that corresponds with the selected tab
675 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
676 found_grid->repr->parent()->removeChild(found_grid->repr);
677 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
678 }
679 }
682 } // namespace Dialog
683 } // namespace UI
684 } // namespace Inkscape
686 /*
687 Local Variables:
688 mode:c++
689 c-file-style:"stroustrup"
690 c-file-offsets:((innamespace . 0)(inline-open . 0))
691 indent-tabs-mode:nilu
692 fill-column:99
693 End:
694 */
695 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :