3f84c18089f1e0b88a016808330dfd19a6197fdb
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 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"
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 //===================================================
54 //---------------------------------------------------
56 static DocumentProperties *_instance = 0;
58 static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
59 static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
60 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
61 static void on_doc_replaced (SPDesktop* dt, SPDocument* doc);
62 static void on_activate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
63 static void on_deactivate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
65 static Inkscape::XML::NodeEventVector const _repr_events = {
66 on_child_added, /* child_added */
67 on_child_removed, /* child_removed */
68 on_repr_attr_changed,
69 NULL, /* content_changed */
70 NULL /* order_changed */
71 };
74 DocumentProperties*
75 DocumentProperties::create()
76 {
77 if (_instance) return _instance;
78 _instance = new DocumentProperties;
79 _instance->init();
80 return _instance;
81 }
83 void
84 DocumentProperties::destroy()
85 {
86 if (_instance)
87 {
88 delete _instance;
89 _instance = 0;
90 }
91 }
93 DocumentProperties::DocumentProperties()
94 : Dialog ("dialogs.documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
95 _page_page(1, 1), _page_grid(1, 1), _page_guides(1, 1),
96 _page_snap(1, 1), _page_grids(1, 1),
97 _grids_button_new(_("_New"), _("Create new grid.")),
98 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
99 _prefs_path("dialogs.documentoptions")
100 {
101 set_resizable (false);
102 _tt.enable();
103 get_vbox()->set_spacing (4);
104 get_vbox()->pack_start (_notebook, true, true);
106 _notebook.append_page(_page_page, _("Page"));
107 _notebook.append_page(_page_grid, _("Grid/Guides"));
108 _notebook.append_page(_page_snap, _("Snap"));
109 _notebook.append_page(_page_grids, _("Grids setup"));
111 build_page();
112 build_grid();
113 build_snap();
114 build_gridspage();
116 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
117 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
118 }
120 void
121 DocumentProperties::init()
122 {
123 update();
125 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
126 repr->addListener (&_repr_events, this);
127 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
128 root->addListener (&_repr_events, this);
130 _doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
132 g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
133 G_CALLBACK(on_activate_desktop), 0);
135 g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop",
136 G_CALLBACK(on_deactivate_desktop), 0);
138 show_all_children();
140 present();
141 }
143 DocumentProperties::~DocumentProperties()
144 {
145 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
146 repr->removeListenerByData (this);
147 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
148 root->removeListenerByData (this);
149 _doc_replaced_connection.disconnect();
150 }
152 //========================================================================
154 /**
155 * Helper function that attachs widgets in a 3xn table. The widgets come in an
156 * array that has two entries per table row. The two entries code for four
157 * possible cases: (0,0) means insert space in first column; (0, non-0) means
158 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
159 * (non-0, non-0) means two widgets in columns 2 and 3.
160 **/
161 inline void
162 attach_all (Gtk::Table &table, const Gtk::Widget *arr[], unsigned size, int start = 0)
163 {
164 for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2)
165 {
166 if (arr[i] && arr[i+1])
167 {
168 table.attach (const_cast<Gtk::Widget&>(*arr[i]), 1, 2, r, r+1,
169 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
170 table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1,
171 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
172 }
173 else
174 {
175 if (arr[i+1])
176 table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1,
177 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
178 else if (arr[i])
179 {
180 Gtk::Label& label = reinterpret_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
181 label.set_alignment (0.0);
182 table.attach (label, 0, 3, r, r+1,
183 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
184 }
185 else
186 {
187 Gtk::HBox *space = manage (new Gtk::HBox);
188 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
189 table.attach (*space, 0, 1, r, r+1,
190 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
191 }
192 }
193 ++r;
194 }
195 }
197 void
198 DocumentProperties::build_page()
199 {
200 _page_page.show();
202 _rcp_bg.init (_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"),
203 "pagecolor", "inkscape:pageopacity", _wr);
204 _rcb_canb.init (_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false);
205 _rcb_bord.init (_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false);
206 _rcp_bord.init (_("Border _color:"), _("Page border color"),
207 _("Color of the page border"),
208 "bordercolor", "borderopacity", _wr);
209 _rcb_shad.init (_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false);
210 _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
212 Gtk::Label* label_gen = manage (new Gtk::Label);
213 label_gen->set_markup (_("<b>General</b>"));
214 Gtk::Label* label_bor = manage (new Gtk::Label);
215 label_bor->set_markup (_("<b>Border</b>"));
216 Gtk::Label *label_for = manage (new Gtk::Label);
217 label_for->set_markup (_("<b>Format</b>"));
218 _page_sizer.init (_wr);
220 const Gtk::Widget* widget_array[] =
221 {
222 label_gen, 0,
223 _rum_deflt._label, _rum_deflt._sel,
224 _rcp_bg._label, _rcp_bg._cp,
225 0, 0,
226 label_for, 0,
227 0, &_page_sizer,
228 0, 0,
229 label_bor, 0,
230 0, _rcb_canb._button,
231 0, _rcb_bord._button,
232 0, _rcb_shad._button,
233 _rcp_bord._label, _rcp_bord._cp,
234 };
236 attach_all (_page_page.table(), widget_array, sizeof(widget_array));
237 }
239 void
240 DocumentProperties::build_grid()
241 {
242 _page_grid.show();
244 /// \todo FIXME: gray out snapping when grid is off.
245 /// Dissenting view: you want snapping without grid.
247 _rcbgrid.init (_("_Show grid"), _("Show or hide grid"), "showgrid", _wr);
249 _rumg.init (_("Grid _units:"), "grid_units", _wr);
250 _rsu_ox.init (_("_Origin X:"), _("X coordinate of grid origin"),
251 "gridoriginx", _rumg, _wr);
252 _rsu_oy.init (_("O_rigin Y:"), _("Y coordinate of grid origin"),
253 "gridoriginy", _rumg, _wr);
254 _rsu_sx.init (_("Spacing _X:"), _("Distance between vertical grid lines"),
255 "gridspacingx", _rumg, _wr);
256 _rsu_sy.init (_("Spacing _Y:"), _("Distance between horizontal grid lines"),
257 "gridspacingy", _rumg, _wr);
258 _rcp_gcol.init (_("Grid line _color:"), _("Grid line color"),
259 _("Color of grid lines"), "gridcolor", "gridopacity", _wr);
260 _rcp_gmcol.init (_("Ma_jor grid line color:"), _("Major grid line color"),
261 _("Color of the major (highlighted) grid lines"),
262 "gridempcolor", "gridempopacity", _wr);
263 _rsi.init (_("_Major grid line every:"), _("lines"), "gridempspacing", _wr);
264 _rcb_sgui.init (_("Show _guides"), _("Show or hide guides"), "showguides", _wr);
265 _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"),
266 _("Color of guidelines"), "guidecolor", "guideopacity", _wr);
267 _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"),
268 _("Color of a guideline when it is under mouse"),
269 "guidehicolor", "guidehiopacity", _wr);
270 Gtk::Label *label_grid = manage (new Gtk::Label);
271 label_grid->set_markup (_("<b>Grid</b>"));
272 Gtk::Label *label_gui = manage (new Gtk::Label);
273 label_gui->set_markup (_("<b>Guides</b>"));
275 const Gtk::Widget* widget_array[] =
276 {
277 label_grid, 0,
278 0, _rcbgrid._button,
279 _rumg._label, _rumg._sel,
280 0, _rsu_ox.getSU(),
281 0, _rsu_oy.getSU(),
282 0, _rsu_sx.getSU(),
283 0, _rsu_sy.getSU(),
284 _rcp_gcol._label, _rcp_gcol._cp,
285 0, 0,
286 _rcp_gmcol._label, _rcp_gmcol._cp,
287 _rsi._label, &_rsi._hbox,
288 0, 0,
289 label_gui, 0,
290 0, _rcb_sgui._button,
291 _rcp_gui._label, _rcp_gui._cp,
292 _rcp_hgui._label, _rcp_hgui._cp,
293 };
295 attach_all (_page_grid.table(), widget_array, sizeof(widget_array));
296 }
298 void
299 DocumentProperties::build_snap()
300 {
301 _page_snap.show();
303 _rcbsnbo.init (_("_Snap bounding boxes to objects"),
304 _("Snap the edges of the object bounding boxes to other objects"),
305 "inkscape:object-bbox", _wr);
306 _rcbsnnob.init (_("Snap nodes _to objects"),
307 _("Snap the nodes of objects to other objects"),
308 "inkscape:object-points", _wr);
309 _rcbsnop.init (_("Snap to object _paths"),
310 _("Snap to other object paths"),
311 "inkscape:object-paths", _wr);
312 _rcbsnon.init (_("Snap to object _nodes"),
313 _("Snap to other object nodes"),
314 "inkscape:object-nodes", _wr);
315 _rsu_sno.init (_("Snap s_ensitivity:"), _("Always snap"),
316 _("Snapping distance, in screen pixels, for snapping to objects"),
317 _("If set, objects snap to the nearest object, regardless of distance"),
318 "objecttolerance", _wr);
319 _rcbsnbb.init (_("Snap _bounding boxes to grid"),
320 _("Snap the edges of the object bounding boxes"),
321 "inkscape:grid-bbox", _wr);
322 _rcbsnnod.init (_("Snap nodes to _grid"),
323 _("Snap path nodes, text baselines, ellipse centers, etc."),
324 "inkscape:grid-points", _wr);
325 _rsu_sn.init (_("Snap sens_itivity:"), _("Always snap"),
326 _("Snapping distance, in screen pixels, for snapping to grid"),
327 _("If set, objects snap to the nearest grid line, regardless of distance"),
328 "gridtolerance", _wr);
329 _rcb_snpgui.init (_("Snap bounding boxes to g_uides"),
330 _("Snap the edges of the object bounding boxes"),
331 "inkscape:guide-bbox", _wr);
332 _rcb_snbgui.init (_("Snap p_oints to guides"),
333 _("Snap path nodes, text baselines, ellipse centers, etc."),
334 "inkscape:guide-points", _wr);
335 _rsu_gusn.init (_("Snap sensiti_vity:"), _("Always snap"),
336 _("Snapping distance, in screen pixels, for snapping to guides"),
337 _("If set, objects snap to the nearest guide, regardless of distance"),
338 "guidetolerance", _wr);
339 Gtk::Label *label_o = manage (new Gtk::Label);
340 label_o->set_markup (_("<b>Object Snapping</b>"));
341 Gtk::Label *label_gr = manage (new Gtk::Label);
342 label_gr->set_markup (_("<b>Grid Snapping</b>"));
343 Gtk::Label *label_gu = manage (new Gtk::Label);
344 label_gu->set_markup (_("<b>Guide Snapping</b>"));
346 const Gtk::Widget* array[] =
347 {
348 label_o, 0,
349 0, _rcbsnbo._button,
350 0, _rcbsnnob._button,
351 0, _rcbsnop._button,
352 0, _rcbsnon._button,
353 0, _rsu_sno._vbox,
354 0, 0,
355 label_gr, 0,
356 0, _rcbsnbb._button,
357 0, _rcbsnnod._button,
358 0, _rsu_sn._vbox,
359 0, 0,
360 label_gu, 0,
361 0, _rcb_snpgui._button,
362 0, _rcb_snbgui._button,
363 0, _rsu_gusn._vbox,
364 };
366 attach_all (_page_snap.table(), array, sizeof(array));
367 }
369 /**
370 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
371 */
372 void
373 DocumentProperties::update_gridspage()
374 {
375 SPDesktop *dt = SP_ACTIVE_DESKTOP;
376 SPNamedView *nv = sp_desktop_namedview(dt);
378 //remove all tabs
379 while (_grids_notebook.get_current_page() != -1) {
380 _grids_notebook.remove_page(-1);
381 }
383 //add tabs
384 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
385 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
386 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
388 }
389 _grids_notebook.show_all();
391 const Gtk::Widget* widget_array[] =
392 {
393 (Gtk::Widget*) &_grids_notebook, 0
394 };
395 attach_all (_page_grids.table(), widget_array, sizeof(widget_array),3); // FIXME: a hack to let GTK show all tabs, otherwise XML manually added grids setting widgets do no show.
396 }
398 /**
399 * Build grid page of dialog.
400 */
401 void
402 DocumentProperties::build_gridspage()
403 {
404 _page_grids.show();
406 SPDesktop *dt = SP_ACTIVE_DESKTOP;
407 SPNamedView *nv = sp_desktop_namedview(dt);
409 Gtk::Label* label_crea = manage (new Gtk::Label);
410 label_crea->set_markup (_("<b>Creation</b>"));
411 Gtk::Label* label_crea_type = manage (new Gtk::Label);
412 label_crea_type->set_markup (_("Gridtype"));
414 _grids_combo_gridtype.append_text(Glib::ustring("xygrid"));
415 _grids_combo_gridtype.append_text(Glib::ustring("axonometric"));
416 _grids_combo_gridtype.set_active_text(Glib::ustring("xygrid"));
418 Gtk::Label* label_def = manage (new Gtk::Label);
419 label_def->set_markup (_("<b>Defined grids</b>"));
421 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
422 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
423 _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
424 }
426 const Gtk::Widget* widget_array[] =
427 {
428 label_crea, 0,
429 label_crea_type, (Gtk::Widget*) &_grids_combo_gridtype,
430 (Gtk::Widget*) &_grids_button_new, (Gtk::Widget*) &_grids_button_remove,
431 label_def, 0,
432 (Gtk::Widget*) &_grids_notebook, 0
433 };
435 attach_all (_page_grids.table(), widget_array, sizeof(widget_array));
436 }
440 /**
441 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
442 */
443 void
444 DocumentProperties::update()
445 {
446 if (_wr.isUpdating()) return;
448 SPDesktop *dt = SP_ACTIVE_DESKTOP;
449 SPNamedView *nv = sp_desktop_namedview(dt);
451 _wr.setUpdating (true);
452 set_sensitive (true);
454 //-----------------------------------------------------------page page
455 _rcp_bg.setRgba32 (nv->pagecolor);
456 _rcb_canb.setActive (nv->showborder);
457 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
458 _rcp_bord.setRgba32 (nv->bordercolor);
459 _rcb_shad.setActive (nv->showpageshadow);
461 if (nv->doc_units)
462 _rum_deflt.setUnit (nv->doc_units);
464 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
465 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
466 _page_sizer.setDim (doc_w_px, doc_h_px);
468 //-----------------------------------------------------------grid page
469 _rcbgrid.setActive (nv->showgrid);
470 _rumg.setUnit (nv->gridunit);
472 gdouble val;
473 val = nv->gridorigin[NR::X];
474 val = sp_pixels_get_units (val, *(nv->gridunit));
475 _rsu_ox.setValue (val);
476 val = nv->gridorigin[NR::Y];
477 val = sp_pixels_get_units (val, *(nv->gridunit));
478 _rsu_oy.setValue (val);
479 val = nv->gridspacing[NR::X];
480 double gridx = sp_pixels_get_units (val, *(nv->gridunit));
481 _rsu_sx.setValue (gridx);
482 val = nv->gridspacing[NR::Y];
483 double gridy = sp_pixels_get_units (val, *(nv->gridunit));
484 _rsu_sy.setValue (gridy);
486 _rcp_gcol.setRgba32 (nv->gridcolor);
487 _rcp_gmcol.setRgba32 (nv->gridempcolor);
488 _rsi.setValue (nv->gridempspacing);
490 //-----------------------------------------------------------guide
491 _rcb_sgui.setActive (nv->showguides);
492 _rcp_gui.setRgba32 (nv->guidecolor);
493 _rcp_hgui.setRgba32 (nv->guidehicolor);
495 //-----------------------------------------------------------snap
496 _rcbsnbo.setActive (nv->snap_manager.object.getSnapTo(Inkscape::Snapper::BBOX_POINT));
497 _rcbsnnob.setActive (nv->snap_manager.object.getSnapTo(Inkscape::Snapper::SNAP_POINT));
498 _rcbsnop.setActive (nv->snap_manager.object.getSnapToPaths());
499 _rcbsnop.setActive (nv->snap_manager.object.getSnapToNodes());
500 _rsu_sno.setValue (nv->objecttolerance);
502 _rcbsnbb.setActive (nv->snap_manager.grid.getSnapTo(Inkscape::Snapper::BBOX_POINT));
503 _rcbsnnod.setActive (nv->snap_manager.grid.getSnapTo(Inkscape::Snapper::SNAP_POINT));
504 _rsu_sn.setValue (nv->gridtolerance);
506 _rcb_snpgui.setActive (nv->snap_manager.guide.getSnapTo(Inkscape::Snapper::BBOX_POINT));
507 _rcb_snbgui.setActive (nv->snap_manager.guide.getSnapTo(Inkscape::Snapper::SNAP_POINT));
508 _rsu_gusn.setValue (nv->guidetolerance);
510 //-----------------------------------------------------------grids page
512 update_gridspage();
514 _wr.setUpdating (false);
515 }
517 //--------------------------------------------------------------------
519 void
520 DocumentProperties::on_response (int id)
521 {
522 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
523 {
524 _rcp_bg.closeWindow();
525 _rcp_bord.closeWindow();
526 _rcp_gcol.closeWindow();
527 _rcp_gmcol.closeWindow();
528 _rcp_gui.closeWindow();
529 _rcp_hgui.closeWindow();
530 }
532 if (id == Gtk::RESPONSE_CLOSE)
533 hide();
534 }
538 static void
539 on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data)
540 {
541 if (!_instance)
542 return;
544 _instance->update_gridspage();
545 }
547 static void
548 on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data)
549 {
550 if (!_instance)
551 return;
553 _instance->update_gridspage();
554 }
558 /**
559 * Called when XML node attribute changed; updates dialog widgets.
560 */
561 static void
562 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer)
563 {
564 if (!_instance)
565 return;
567 _instance->update();
568 }
570 static void
571 on_activate_desktop (Inkscape::Application *, SPDesktop* dt, void*)
572 {
573 if (!_instance)
574 return;
576 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
577 repr->addListener (&_repr_events, _instance);
578 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
579 root->addListener (&_repr_events, _instance);
580 _instance->_doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
581 _instance->update();
582 }
584 static void
585 on_deactivate_desktop (Inkscape::Application *, SPDesktop* dt, void*)
586 {
587 if (!_instance)
588 return;
590 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
591 repr->removeListenerByData (_instance);
592 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
593 root->removeListenerByData (_instance);
594 _instance->_doc_replaced_connection.disconnect();
595 }
597 static void
598 on_doc_replaced (SPDesktop* dt, SPDocument* doc)
599 {
600 if (!_instance)
601 return;
603 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
604 repr->addListener (&_repr_events, _instance);
605 Inkscape::XML::Node *root = SP_OBJECT_REPR(doc->root);
606 root->addListener (&_repr_events, _instance);
607 _instance->update();
608 }
613 /*########################################################################
614 # BUTTON CLICK HANDLERS (callbacks)
615 ########################################################################*/
617 void
618 DocumentProperties::onNewGrid()
619 {
620 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
622 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
623 CanvasGrid::writeNewGridToRepr(repr, typestring.c_str()); // FIXME ofcourse user should supply choice for gridtype
624 }
627 void
628 DocumentProperties::onRemoveGrid()
629 {
630 gint pagenum = _grids_notebook.get_current_page();
631 if (pagenum == -1) // no pages
632 return;
634 Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
635 if (!page) return;
637 Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
639 // find the grid with name tabtext (it's id) and delete that one.
640 SPDesktop *dt = SP_ACTIVE_DESKTOP;
641 SPNamedView *nv = sp_desktop_namedview(dt);
642 Inkscape::CanvasGrid * found_grid = NULL;
643 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
644 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
645 gchar const *idtext = grid->repr->attribute("id");
646 if ( !strcmp(tabtext.c_str(), idtext) ) {
647 found_grid = grid;
648 break; // break out of for-loop
649 }
650 }
651 if (found_grid) {
652 // delete the grid that corresponds with the selected tab
653 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
654 found_grid->repr->parent()->removeChild(found_grid->repr);
655 }
656 }
659 } // namespace Dialog
660 } // namespace UI
661 } // namespace Inkscape
663 /*
664 Local Variables:
665 mode:c++
666 c-file-style:"stroustrup"
667 c-file-offsets:((innamespace . 0)(inline-open . 0))
668 indent-tabs-mode:nilu
669 fill-column:99
670 End:
671 */
672 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :