03cef543a733f963cefb40b6cf236396508a0158
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) 2000 - 2005 Authors
13 *
14 * Released under GNU GPL. Read the file 'COPYING' for more information
15 */
17 #ifdef HAVE_CONFIG_H
18 # include <config.h>
19 #endif
23 #include "ui/widget/color-picker.h"
24 #include "ui/widget/scalar-unit.h"
26 #include "xml/node-event-vector.h"
27 #include "helper/units.h"
29 #include "inkscape.h"
30 #include "verbs.h"
31 #include "document.h"
32 #include "desktop-handles.h"
33 #include "desktop.h"
34 #include "sp-namedview.h"
36 #include "document-properties.h"
38 using std::pair;
40 namespace Inkscape {
41 namespace UI {
42 namespace Dialog {
44 #define SPACE_SIZE_X 15
45 #define SPACE_SIZE_Y 10
47 //===================================================
49 //---------------------------------------------------
51 static DocumentProperties *_instance = 0;
53 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
54 static void on_doc_replaced (SPDesktop* dt, SPDocument* doc);
55 static void on_activate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
56 static void on_deactivate_desktop (Inkscape::Application *, SPDesktop* dt, void*);
58 static Inkscape::XML::NodeEventVector const _repr_events = {
59 NULL, /* child_added */
60 NULL, /* child_removed */
61 on_repr_attr_changed,
62 NULL, /* content_changed */
63 NULL /* order_changed */
64 };
67 DocumentProperties*
68 DocumentProperties::create()
69 {
70 if (_instance) return _instance;
71 _instance = new DocumentProperties;
72 _instance->init();
73 return _instance;
74 }
76 void
77 DocumentProperties::destroy()
78 {
79 if (_instance)
80 {
81 delete _instance;
82 _instance = 0;
83 }
84 }
86 DocumentProperties::DocumentProperties()
87 : Dialog ("dialogs.documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
88 _page_page(1, 1), _page_grid(1, 1), _page_guides(1, 1),
89 _page_snap(1, 1),
90 _prefs_path("dialogs.documentoptions")
91 {
92 hide();
93 set_resizable (false);
94 _tt.enable();
95 get_vbox()->set_spacing (4);
96 get_vbox()->pack_start (_notebook, true, true);
98 _notebook.append_page(_page_page, _("Page"));
99 _notebook.append_page(_page_grid, _("Grid/Guides"));
100 _notebook.append_page(_page_snap, _("Snap"));
102 build_page();
103 build_grid();
104 build_snap();
105 }
107 void
108 DocumentProperties::init()
109 {
110 update();
112 Inkscape::XML::Node *repr = SP_OBJECT_REPR(SP_DT_NAMEDVIEW(SP_ACTIVE_DESKTOP));
113 repr->addListener (&_repr_events, this);
115 _doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
117 g_signal_connect(G_OBJECT(INKSCAPE), "activate_desktop",
118 G_CALLBACK(on_activate_desktop), 0);
120 g_signal_connect(G_OBJECT(INKSCAPE), "deactivate_desktop",
121 G_CALLBACK(on_deactivate_desktop), 0);
123 show_all_children();
124 present();
125 }
127 DocumentProperties::~DocumentProperties()
128 {
129 Inkscape::XML::Node *repr = SP_OBJECT_REPR(SP_DT_NAMEDVIEW(SP_ACTIVE_DESKTOP));
130 repr->removeListenerByData (this);
131 _doc_replaced_connection.disconnect();
132 }
134 //========================================================================
136 /**
137 * Helper function that attachs widgets in a 3xn table. The widgets come in an
138 * array that has two entries per table row. The two entries code for four
139 * possible cases: (0,0) means insert space in first column; (0, non-0) means
140 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
141 * (non-0, non-0) means two widgets in columns 2 and 3.
142 **/
143 inline void
144 attach_all (Gtk::Table &table, const Gtk::Widget *arr[], unsigned size, int start = 0)
145 {
146 for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2)
147 {
148 if (arr[i] && arr[i+1])
149 {
150 table.attach (const_cast<Gtk::Widget&>(*arr[i]), 1, 2, r, r+1,
151 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
152 table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1,
153 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
154 }
155 else
156 {
157 if (arr[i+1])
158 table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1,
159 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
160 else if (arr[i])
161 {
162 Gtk::Label& label = reinterpret_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
163 label.set_alignment (0.0);
164 table.attach (label, 0, 3, r, r+1,
165 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
166 }
167 else
168 {
169 Gtk::HBox *space = manage (new Gtk::HBox);
170 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
171 table.attach (*space, 0, 1, r, r+1,
172 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
173 }
174 }
175 ++r;
176 }
177 }
179 void
180 DocumentProperties::build_page()
181 {
182 _page_page.show();
184 _rcp_bg.init (_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"),
185 "pagecolor", "inkscape:pageopacity", _wr);
186 _rcb_canb.init (_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false);
187 _rcb_bord.init (_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false);
188 _rcp_bord.init (_("Border _color:"), _("Page border color"),
189 _("Color of the page border"),
190 "bordercolor", "borderopacity", _wr);
191 _rcb_shad.init (_("_Show border shadow"), "If set, page border shows a shadow on its right and lower side", "inkscape:showpageshadow", _wr, false);
192 _rum_deflt.init (_("Default _units:"), "inkscape:document-units", _wr);
193 Gtk::Label* label_gen = manage (new Gtk::Label);
194 label_gen->set_markup (_("<b>General</b>"));
195 Gtk::Label* label_bor = manage (new Gtk::Label);
196 label_bor->set_markup (_("<b>Border</b>"));
197 Gtk::Label *label_for = manage (new Gtk::Label);
198 label_for->set_markup (_("<b>Format</b>"));
199 _page_sizer.init (_wr);
201 const Gtk::Widget* widget_array[] =
202 {
203 label_gen, 0,
204 _rum_deflt._label, _rum_deflt._sel,
205 _rcp_bg._label, _rcp_bg._cp,
206 0, 0,
207 label_for, 0,
208 0, &_page_sizer,
209 0, 0,
210 label_bor, 0,
211 0, _rcb_canb._button,
212 0, _rcb_bord._button,
213 0, _rcb_shad._button,
214 _rcp_bord._label, _rcp_bord._cp,
215 };
217 attach_all (_page_page.table(), widget_array, sizeof(widget_array));
218 }
220 void
221 DocumentProperties::build_grid()
222 {
223 _page_grid.show();
225 /// \todo FIXME: gray out snapping when grid is off.
226 /// Dissenting view: you want snapping without grid.
228 _rcbgrid.init (_("_Show grid"), _("Show or hide grid"), "showgrid", _wr);
229 _rumg.init (_("Grid _units:"), "grid_units", _wr);
230 _rsu_ox.init (_("_Origin X:"), _("X coordinate of grid origin"),
231 "gridoriginx", _rumg, _wr);
232 _rsu_oy.init (_("O_rigin Y:"), _("Y coordinate of grid origin"),
233 "gridoriginy", _rumg, _wr);
234 _rsu_sx.init (_("Spacing _X:"), _("Distance of vertical grid lines"),
235 "gridspacingx", _rumg, _wr);
236 _rsu_sy.init (_("Spacing _Y:"), _("Distance of horizontal grid lines"),
237 "gridspacingy", _rumg, _wr);
238 _rcp_gcol.init (_("Grid line _color:"), _("Grid line color"),
239 _("Color of grid lines"), "gridcolor", "gridopacity", _wr);
240 _rcp_gmcol.init (_("Ma_jor grid line color:"), _("Major grid line color"),
241 _("Color of the major (highlighted) grid lines"),
242 "gridempcolor", "gridempopacity", _wr);
243 _rsi.init (_("_Major grid line every:"), _("lines"), "gridempspacing", _wr);
244 _rcb_sgui.init (_("Show _guides"), _("Show or hide guides"), "showguides", _wr);
245 _rcp_gui.init (_("Guide co_lor:"), _("Guideline color"),
246 _("Color of guidelines"), "guidecolor", "guideopacity", _wr);
247 _rcp_hgui.init (_("_Highlight color:"), _("Highlighted guideline color"),
248 _("Color of a guideline when it is under mouse"),
249 "guidehicolor", "guidehiopacity", _wr);
250 Gtk::Label *label_grid = manage (new Gtk::Label);
251 label_grid->set_markup (_("<b>Grid</b>"));
252 Gtk::Label *label_gui = manage (new Gtk::Label);
253 label_gui->set_markup (_("<b>Guides</b>"));
255 const Gtk::Widget* widget_array[] =
256 {
257 label_grid, 0,
258 0, _rcbgrid._button,
259 _rumg._label, _rumg._sel,
260 0, _rsu_ox.getSU(),
261 0, _rsu_oy.getSU(),
262 0, _rsu_sx.getSU(),
263 0, _rsu_sy.getSU(),
264 _rcp_gcol._label, _rcp_gcol._cp,
265 0, 0,
266 _rcp_gmcol._label, _rcp_gmcol._cp,
267 _rsi._label, &_rsi._hbox,
268 0, 0,
269 label_gui, 0,
270 0, _rcb_sgui._button,
271 _rcp_gui._label, _rcp_gui._cp,
272 _rcp_hgui._label, _rcp_hgui._cp,
273 };
275 attach_all (_page_grid.table(), widget_array, sizeof(widget_array));
276 }
278 void
279 DocumentProperties::build_snap()
280 {
281 _page_snap.show();
283 _rcbsnbo.init (_("_Snap bounding boxes to objects"),
284 _("Snap the edges of the object bounding boxes to other objects"),
285 "inkscape:object-bbox", _wr);
286 _rcbsnnob.init (_("Snap nodes _to objects"),
287 _("Snap the nodes of objects to other objects"),
288 "inkscape:object-points", _wr);
289 _rcbsnop.init (_("Snap to object _paths"),
290 _("Snap to other object paths"),
291 "inkscape:object-paths", _wr);
292 _rcbsnon.init (_("Snap to object _nodes"),
293 _("Snap to other object nodes"),
294 "inkscape:object-nodes", _wr);
295 _rsu_sno.init (_("Snap s_ensitivity:"), _("Always snap"),
296 _("Controls max. snapping distance from object"),
297 _("If set, objects snap to the nearest object when moved, regardless of distance"),
298 "objecttolerance", _wr);
299 _rcbsnbb.init (_("Snap _bounding boxes to grid"),
300 _("Snap the edges of the object bounding boxes"),
301 "inkscape:grid-bbox", _wr);
302 _rcbsnnod.init (_("Snap nodes to _grid"),
303 _("Snap path nodes, text baselines, ellipse centers, etc."),
304 "inkscape:grid-points", _wr);
305 _rsu_sn.init (_("Snap sens_itivity:"), _("Always snap"),
306 _("Controls max. snapping distance from grid"),
307 _("If set, objects snap to the nearest grid line when moved, regardless of distance"),
308 "gridtolerance", _wr);
309 _rcb_snpgui.init (_("Snap bounding boxes to g_uides"),
310 _("Snap the edges of the object bounding boxes"),
311 "inkscape:guide-bbox", _wr);
312 _rcb_snbgui.init (_("Snap p_oints to guides"),
313 _("Snap path nodes, text baselines, ellipse centers, etc."),
314 "inkscape:guide-points", _wr);
315 _rsu_gusn.init (_("Snap sensiti_vity:"), _("Always snap"),
316 _("Controls max. snapping distance from guides"),
317 _("If set, objects snap to the nearest guide when moved, regardless of distance"),
318 "guidetolerance", _wr);
319 // _rrb_pix.init (_("Sensitivity:"), _("S_creen pixels"), _("p_x units"),
320 // _("Sensitivity is always the same, regardless of zoom."),
321 // _("Sensitivity changes with zoom; zooming in will enlarge max. snapping distance."),
322 // _("inkscape:has_abs_tolerance"), _wr);
323 Gtk::Label *label_o = manage (new Gtk::Label);
324 label_o->set_markup (_("<b>Object Snapping</b>"));
325 Gtk::Label *label_gr = manage (new Gtk::Label);
326 label_gr->set_markup (_("<b>Grid Snapping</b>"));
327 Gtk::Label *label_gu = manage (new Gtk::Label);
328 label_gu->set_markup (_("<b>Guide Snapping</b>"));
330 const Gtk::Widget* array[] =
331 {
332 label_o, 0,
333 0, _rcbsnbo._button,
334 0, _rcbsnnob._button,
335 0, _rcbsnop._button,
336 0, _rcbsnon._button,
337 0, _rsu_sno._vbox,
338 0, 0,
339 label_gr, 0,
340 0, _rcbsnbb._button,
341 0, _rcbsnnod._button,
342 0, _rsu_sn._vbox,
343 0, 0,
344 label_gu, 0,
345 0, _rcb_snpgui._button,
346 0, _rcb_snbgui._button,
347 0, _rsu_gusn._vbox,
348 // 0, 0,
349 // 0, _rrb_pix._hbox,
350 };
352 attach_all (_page_snap.table(), array, sizeof(array));
353 }
355 /**
356 * Update dialog widgets from desktop.
357 */
358 void
359 DocumentProperties::update()
360 {
361 if (_wr.isUpdating()) return;
363 SPDesktop *dt = SP_ACTIVE_DESKTOP;
364 SPNamedView *nv = SP_DT_NAMEDVIEW(dt);
365 _wr.setUpdating (true);
366 set_sensitive (true);
368 //-----------------------------------------------------------page page
369 _rcp_bg.setRgba32 (nv->pagecolor);
370 _rcb_canb.setActive (nv->showborder);
371 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
372 _rcp_bord.setRgba32 (nv->bordercolor);
373 _rcb_shad.setActive (nv->showpageshadow);
375 if (nv->doc_units)
376 _rum_deflt.setUnit (nv->doc_units);
378 double const doc_w_px = sp_document_width(SP_DT_DOCUMENT(dt));
379 double const doc_h_px = sp_document_height(SP_DT_DOCUMENT(dt));
380 _page_sizer.setDim (doc_w_px, doc_h_px);
382 //-----------------------------------------------------------grid page
383 _rcbgrid.setActive (nv->showgrid);
384 _rumg.setUnit (nv->gridunit);
386 gdouble val;
387 val = nv->gridorigin[NR::X];
388 val = sp_pixels_get_units (val, *(nv->gridunit));
389 _rsu_ox.setValue (val);
390 val = nv->gridorigin[NR::Y];
391 val = sp_pixels_get_units (val, *(nv->gridunit));
392 _rsu_oy.setValue (val);
393 val = nv->gridspacing[NR::X];
394 double gridx = sp_pixels_get_units (val, *(nv->gridunit));
395 _rsu_sx.setValue (gridx);
396 val = nv->gridspacing[NR::Y];
397 double gridy = sp_pixels_get_units (val, *(nv->gridunit));
398 _rsu_sy.setValue (gridy);
400 _rcp_gcol.setRgba32 (nv->gridcolor);
401 _rcp_gmcol.setRgba32 (nv->gridempcolor);
402 _rsi.setValue (nv->gridempspacing);
404 //-----------------------------------------------------------guide
405 _rcb_sgui.setActive (nv->showguides);
406 _rcp_gui.setRgba32 (nv->guidecolor);
407 _rcp_hgui.setRgba32 (nv->guidehicolor);
409 //-----------------------------------------------------------snap
410 _rcbsnbo.setActive (nv->snap_object_bbox);
411 _rcbsnnob.setActive (nv->snap_object_point);
412 _rcbsnop.setActive (nv->snap_object_paths);
413 _rcbsnop.setActive (nv->snap_object_nodes);
414 _rsu_sno.setValue (nv->objecttolerance, nv->has_abs_tolerance);
416 _rcbsnbb.setActive (nv->snap_grid_bbox);
417 _rcbsnnod.setActive (nv->snap_grid_point);
418 _rsu_sn.setValue (nv->gridtolerance, nv->has_abs_tolerance);
420 _rcb_snpgui.setActive (nv->snap_guide_bbox);
421 _rcb_snbgui.setActive (nv->snap_guide_point);
422 _rsu_gusn.setValue (nv->guidetolerance, nv->has_abs_tolerance);
423 // _rrb_pix.setValue (true);
425 _wr.setUpdating (false);
426 }
428 //--------------------------------------------------------------------
430 void
431 DocumentProperties::on_response (int id)
432 {
433 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
434 {
435 _rcp_bg.closeWindow();
436 _rcp_bord.closeWindow();
437 _rcp_gcol.closeWindow();
438 _rcp_gmcol.closeWindow();
439 _rcp_gui.closeWindow();
440 _rcp_hgui.closeWindow();
441 }
443 if (id == Gtk::RESPONSE_CLOSE)
444 hide();
445 }
447 /**
448 * Called when XML node attribute changed; updates dialog widgets.
449 */
450 static void
451 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer)
452 {
453 if (!_instance)
454 return;
456 _instance->update();
457 }
459 static void
460 on_activate_desktop (Inkscape::Application *, SPDesktop* dt, void*)
461 {
462 if (!_instance)
463 return;
465 Inkscape::XML::Node *repr = SP_OBJECT_REPR(SP_DT_NAMEDVIEW(SP_ACTIVE_DESKTOP));
466 repr->addListener (&_repr_events, _instance);
467 _instance->_doc_replaced_connection = SP_ACTIVE_DESKTOP->connectDocumentReplaced (sigc::ptr_fun (on_doc_replaced));
468 _instance->update();
469 }
471 static void
472 on_deactivate_desktop (Inkscape::Application *, SPDesktop* dt, void*)
473 {
474 if (!_instance)
475 return;
477 Inkscape::XML::Node *repr = SP_OBJECT_REPR(SP_DT_NAMEDVIEW(SP_ACTIVE_DESKTOP));
478 repr->removeListenerByData (_instance);
479 _instance->_doc_replaced_connection.disconnect();
480 }
482 static void
483 on_doc_replaced (SPDesktop* dt, SPDocument* doc)
484 {
485 if (!_instance)
486 return;
488 Inkscape::XML::Node *repr = SP_OBJECT_REPR(SP_DT_NAMEDVIEW(dt));
489 repr->addListener (&_repr_events, _instance);
490 _instance->update();
491 }
494 } // namespace Dialog
495 } // namespace UI
496 } // namespace Inkscape
498 /*
499 Local Variables:
500 mode:c++
501 c-file-style:"stroustrup"
502 c-file-offsets:((innamespace . 0)(inline-open . 0))
503 indent-tabs-mode:nil
504 fill-column:99
505 End:
506 */
507 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :