Code

39b3e36b40b3d8ff71d6fa0c92ae97701eb1cd61
[inkscape.git] / src / ui / dialog / document-properties.cpp
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"
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")
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));
120 void
121 DocumentProperties::init()
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();
143 DocumentProperties::~DocumentProperties()
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();
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)
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     }
197 void
198 DocumentProperties::build_page()
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));
239 void
240 DocumentProperties::build_grid()
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));
298 void
299 DocumentProperties::build_snap()
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()
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     _page_grids.table().resize_children();
394 /**
395  * Build grid page of dialog.
396  */
397 void
398 DocumentProperties::build_gridspage()
400     _page_grids.show();
402     SPDesktop *dt = SP_ACTIVE_DESKTOP;
403     SPNamedView *nv = sp_desktop_namedview(dt);
405     Gtk::Label* label_crea = manage (new Gtk::Label);
406     label_crea->set_markup (_("<b>Creation</b>"));
407     Gtk::Label* label_crea_type = manage (new Gtk::Label);
408     label_crea_type->set_markup (_("Gridtype"));
409     
410     _grids_combo_gridtype.append_text(Glib::ustring("xygrid"));
411     _grids_combo_gridtype.append_text(Glib::ustring("axonometric"));
412     _grids_combo_gridtype.set_active_text(Glib::ustring("xygrid"));
413     
414     Gtk::Label* label_def = manage (new Gtk::Label);
415     label_def->set_markup (_("<b>Defined grids</b>"));
417     for (GSList const * l = nv->grids; l != NULL; l = l->next) {
418         Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
419         _grids_notebook.append_page(grid->getWidget(), grid->repr->attribute("id"));
420     }
422     const Gtk::Widget* widget_array[] =
423     {
424         label_crea, 0,
425         label_crea_type, (Gtk::Widget*) &_grids_combo_gridtype,
426         (Gtk::Widget*) &_grids_button_new,         (Gtk::Widget*) &_grids_button_remove, 
427         label_def,         0,
428         (Gtk::Widget*) &_grids_notebook, 0
429     };
431     attach_all (_page_grids.table(), widget_array, sizeof(widget_array));
436 /**
437  * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
438  */
439 void
440 DocumentProperties::update()
442     if (_wr.isUpdating()) return;
444     SPDesktop *dt = SP_ACTIVE_DESKTOP;
445     SPNamedView *nv = sp_desktop_namedview(dt);
447     _wr.setUpdating (true);
448     set_sensitive (true);
450     //-----------------------------------------------------------page page
451     _rcp_bg.setRgba32 (nv->pagecolor);
452     _rcb_canb.setActive (nv->showborder);
453     _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
454     _rcp_bord.setRgba32 (nv->bordercolor);
455     _rcb_shad.setActive (nv->showpageshadow);
457     if (nv->doc_units)
458         _rum_deflt.setUnit (nv->doc_units);
460     double const doc_w_px = sp_document_width(sp_desktop_document(dt));
461     double const doc_h_px = sp_document_height(sp_desktop_document(dt));
462     _page_sizer.setDim (doc_w_px, doc_h_px);
464     //-----------------------------------------------------------grid page
465     _rcbgrid.setActive (nv->showgrid);
466     _rumg.setUnit (nv->gridunit);
468     gdouble val;
469     val = nv->gridorigin[NR::X];
470     val = sp_pixels_get_units (val, *(nv->gridunit));
471     _rsu_ox.setValue (val);
472     val = nv->gridorigin[NR::Y];
473     val = sp_pixels_get_units (val, *(nv->gridunit));
474     _rsu_oy.setValue (val);
475     val = nv->gridspacing[NR::X];
476     double gridx = sp_pixels_get_units (val, *(nv->gridunit));
477     _rsu_sx.setValue (gridx);
478     val = nv->gridspacing[NR::Y];
479     double gridy = sp_pixels_get_units (val, *(nv->gridunit));
480     _rsu_sy.setValue (gridy);
482     _rcp_gcol.setRgba32 (nv->gridcolor);
483     _rcp_gmcol.setRgba32 (nv->gridempcolor);
484     _rsi.setValue (nv->gridempspacing);
486     //-----------------------------------------------------------guide
487     _rcb_sgui.setActive (nv->showguides);
488     _rcp_gui.setRgba32 (nv->guidecolor);
489     _rcp_hgui.setRgba32 (nv->guidehicolor);
491     //-----------------------------------------------------------snap
492     //_rcbsnbo.setActive (nv->snap_manager.object.getSnapTo(Inkscape::Snapper::BBOX_POINT));
493     //_rcbsnnob.setActive (nv->snap_manager.object.getSnapTo(Inkscape::Snapper::SNAP_POINT));
494     _rcbsnop.setActive (nv->snap_manager.object.getSnapToPaths());
495     _rcbsnon.setActive (nv->snap_manager.object.getSnapToNodes());
496     _rsu_sno.setValue (nv->objecttolerance);
498     //_rcbsnbb.setActive (nv->snap_manager.grid.getSnapTo(Inkscape::Snapper::BBOX_POINT));
499     //_rcbsnnod.setActive (nv->snap_manager.grid.getSnapTo(Inkscape::Snapper::SNAP_POINT));
500     _rsu_sn.setValue (nv->gridtolerance);
502     //_rcb_snpgui.setActive (nv->snap_manager.guide.getSnapTo(Inkscape::Snapper::BBOX_POINT));
503     //_rcb_snbgui.setActive (nv->snap_manager.guide.getSnapTo(Inkscape::Snapper::SNAP_POINT));
504     _rsu_gusn.setValue (nv->guidetolerance);
506     //-----------------------------------------------------------grids page
508     update_gridspage();
510     _wr.setUpdating (false);
513 //--------------------------------------------------------------------
515 void
516 DocumentProperties::on_response (int id)
518     if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
519     {
520         _rcp_bg.closeWindow();
521         _rcp_bord.closeWindow();
522         _rcp_gcol.closeWindow();
523         _rcp_gmcol.closeWindow();
524         _rcp_gui.closeWindow();
525         _rcp_hgui.closeWindow();
526     }
528     if (id == Gtk::RESPONSE_CLOSE)
529         hide();
534 static void
535 on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data)
537     if (!_instance)
538         return;
540     _instance->update_gridspage();
543 static void
544 on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data)
546     if (!_instance)
547         return;
549     _instance->update_gridspage();
554 /**
555  * Called when XML node attribute changed; updates dialog widgets.
556  */
557 static void
558 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer)
560     if (!_instance)
561         return;
563     _instance->update();
566 static void
567 on_activate_desktop (Inkscape::Application *, SPDesktop* dt, void*)
569     if (!_instance)
570         return;
572     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
573     repr->addListener (&_repr_events, _instance);
574     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
575     root->addListener (&_repr_events, _instance);
576     _instance->_doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
577     _instance->update();
580 static void
581 on_deactivate_desktop (Inkscape::Application *, SPDesktop* dt, void*)
583     if (!_instance)
584         return;
586     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
587     repr->removeListenerByData (_instance);
588     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(SP_ACTIVE_DESKTOP)->root);
589     root->removeListenerByData (_instance);
590     _instance->_doc_replaced_connection.disconnect();
593 static void
594 on_doc_replaced (SPDesktop* dt, SPDocument* doc)
596     if (!_instance)
597         return;
599     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
600     repr->addListener (&_repr_events, _instance);
601     Inkscape::XML::Node *root = SP_OBJECT_REPR(doc->root);
602     root->addListener (&_repr_events, _instance);
603     _instance->update();
609 /*########################################################################
610 # BUTTON CLICK HANDLERS    (callbacks)
611 ########################################################################*/
613 void
614 DocumentProperties::onNewGrid()
616     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(SP_ACTIVE_DESKTOP));
618     Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
619     CanvasGrid::writeNewGridToRepr(repr, typestring.c_str());
623 void
624 DocumentProperties::onRemoveGrid()
626     gint pagenum = _grids_notebook.get_current_page();
627     if (pagenum == -1) // no pages
628       return;
629       
630     Gtk::Widget *page = _grids_notebook.get_nth_page(pagenum);
631     if (!page) return;
632     
633     Glib::ustring tabtext = _grids_notebook.get_tab_label_text(*page);
634     
635     // find the grid with name tabtext (it's id) and delete that one.
636     SPDesktop *dt = SP_ACTIVE_DESKTOP;
637     SPNamedView *nv = sp_desktop_namedview(dt);
638     Inkscape::CanvasGrid * found_grid = NULL;
639     for (GSList const * l = nv->grids; l != NULL; l = l->next) {
640         Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
641         gchar const *idtext = grid->repr->attribute("id");
642         if ( !strcmp(tabtext.c_str(), idtext) ) {
643             found_grid = grid;
644             break; // break out of for-loop
645         }
646     }
647     if (found_grid) {
648         // delete the grid that corresponds with the selected tab
649         // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
650         found_grid->repr->parent()->removeChild(found_grid->repr);
651     }
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 :