cb2bf6997650f4fda19ef6216eba15926f54a5cf
1 /** @file
2 * @brief Document properties dialog, Gtkmm-style
3 */
4 /* Authors:
5 * bulia byak <buliabyak@users.sf.net>
6 * Bryce W. Harrington <bryce@bryceharrington.org>
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * Jon Phillips <jon@rejon.org>
9 * Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
10 * Diederik van Lierop <mail@diedenrezi.nl>
11 *
12 * Copyright (C) 2006-2008 Johan Engelen <johan@shouraizou.nl>
13 * Copyright (C) 2000 - 2008 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
22 #include "display/canvas-grid.h"
23 #include "document-properties.h"
24 #include "document.h"
25 #include "desktop-handles.h"
26 #include "desktop.h"
27 #include <gtkmm.h>
28 #include "helper/units.h"
29 #include "inkscape.h"
30 #include "io/sys.h"
31 #include "preferences.h"
32 #include "sp-namedview.h"
33 #include "sp-object-repr.h"
34 #include "sp-root.h"
35 #include "ui/widget/color-picker.h"
36 #include "ui/widget/scalar-unit.h"
37 #include "verbs.h"
38 #include "widgets/icon.h"
39 #include "xml/node-event-vector.h"
40 #include "xml/repr.h"
42 #if ENABLE_LCMS
43 #include <lcms.h>
44 //#include "color-profile-fns.h"
45 #include "color-profile.h"
46 #endif // ENABLE_LCMS
48 using std::pair;
50 namespace Inkscape {
51 namespace UI {
52 namespace Dialog {
54 #define SPACE_SIZE_X 15
55 #define SPACE_SIZE_Y 10
57 #define INKSCAPE_ICON_GRID_XY "grid_xy"
58 #define INKSCAPE_ICON_GRID_AXONOM "grid_axonom"
61 //===================================================
63 //---------------------------------------------------
65 static void on_child_added(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
66 static void on_child_removed(Inkscape::XML::Node *repr, Inkscape::XML::Node *child, Inkscape::XML::Node *ref, void * data);
67 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
69 static Inkscape::XML::NodeEventVector const _repr_events = {
70 on_child_added, // child_added
71 on_child_removed, // child_removed
72 on_repr_attr_changed,
73 NULL, // content_changed
74 NULL // order_changed
75 };
78 DocumentProperties &
79 DocumentProperties::getInstance()
80 {
81 DocumentProperties &instance = *new DocumentProperties();
82 instance.init();
84 return instance;
85 }
87 DocumentProperties::DocumentProperties()
88 : UI::Widget::Panel ("", "/dialogs/documentoptions", SP_VERB_DIALOG_NAMEDVIEW),
89 _page_page(1, 1, true, true), _page_guides(1, 1),
90 _page_snap(1, 1), _page_snap_dtls(1, 1), _page_cms(1, 1),
91 //---------------------------------------------------------------
92 _rcb_canb(_("Show page _border"), _("If set, rectangular page border is shown"), "showborder", _wr, false),
93 _rcb_bord(_("Border on _top of drawing"), _("If set, border is always on top of the drawing"), "borderlayer", _wr, false),
94 _rcb_shad(_("_Show border shadow"), _("If set, page border shows a shadow on its right and lower side"), "inkscape:showpageshadow", _wr, false),
95 _rcp_bg(_("Back_ground:"), _("Background color"), _("Color and transparency of the page background (also used for bitmap export)"), "pagecolor", "inkscape:pageopacity", _wr),
96 _rcp_bord(_("Border _color:"), _("Page border color"), _("Color of the page border"), "bordercolor", "borderopacity", _wr),
97 _rum_deflt(_("Default _units:"), "inkscape:document-units", _wr),
98 _page_sizer(_wr),
99 //---------------------------------------------------------------
100 //General snap options
101 _rcb_sgui(_("Show _guides"), _("Show or hide guides"), "showguides", _wr),
102 _rcbsng(_("_Snap guides while dragging"), _("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)"),
103 "inkscape:snap-guide", _wr),
104 _rcp_gui(_("Guide co_lor:"), _("Guideline color"), _("Color of guidelines"), "guidecolor", "guideopacity", _wr),
105 _rcp_hgui(_("_Highlight color:"), _("Highlighted guideline color"), _("Color of a guideline when it is under mouse"), "guidehicolor", "guidehiopacity", _wr),
106 //---------------------------------------------------------------
107 _rcbs(_("_Enable snapping"), _("Toggle snapping on or off"), "inkscape:snap-global", _wr),
108 _rcbsnbb(_("_Bounding box corners"), _("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)"),
109 "inkscape:snap-bbox", _wr),
110 _rcbsnn(_("_Nodes"), _("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"),
111 "inkscape:snap-nodes", _wr),
112 //Options for snapping to objects
113 _rcbsnop(_("Snap to path_s"), _("Snap nodes to object paths"), "inkscape:object-paths", _wr),
114 _rcbsnon(_("Snap to n_odes"), _("Snap nodes and guides to object nodes"), "inkscape:object-nodes", _wr),
115 _rcbsnbbp(_("Snap to bounding bo_x edges"), _("Snap bounding box corners and guides to bounding box edges"), "inkscape:bbox-paths", _wr),
116 _rcbsnbbn(_("Snap to bounding box co_rners"), _("Snap bounding box corners to other bounding box corners"), "inkscape:bbox-nodes", _wr),
117 _rcbsnpb(_("Snap to page border"), _("Snap bounding box corners and nodes to the page border"), "inkscape:snap-page", _wr),
118 //---------------------------------------------------------------
119 //Applies to both nodes and guides, but not to bboxes, that's why its located here
120 _rcbic( _("Rotation _center"), _("Consider the rotation center of an object when snapping"), "inkscape:snap-center", _wr),
121 _rcbsm( _("_Smooth nodes"), _("Snap to smooth nodes too, instead of only snapping to cusp nodes"), "inkscape:snap-smooth-nodes", _wr),
122 _rcbsigg(_("_Grid with guides"), _("Snap to grid-guide intersections"), "inkscape:snap-intersection-grid-guide", _wr),
123 _rcbsils(_("_Paths"), _("Snap to intersections of paths ('snap to paths' must be enabled, see the previous tab)"),
124 "inkscape:snap-intersection-paths", _wr),
125 //---------------------------------------------------------------
126 _grids_label_crea("", Gtk::ALIGN_LEFT),
127 //TRANSLATORS: In Grid|_New translate only the word _New. It ref to grid
128 _grids_button_new(Q_("Grid|_New"), _("Create new grid.")),
129 _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
130 _grids_label_def("", Gtk::ALIGN_LEFT)
131 //---------------------------------------------------------------
132 {
133 _tt.enable();
134 _getContents()->set_spacing (4);
135 _getContents()->pack_start(_notebook, true, true);
137 _notebook.append_page(_page_page, _("Page"));
138 _notebook.append_page(_page_guides, _("Guides"));
139 _notebook.append_page(_grids_vbox, _("Grids"));
140 _notebook.append_page(_page_snap, _("Snap"));
141 _notebook.append_page(_page_snap_dtls, _("Snap points"));
142 _notebook.append_page(_page_cms, _("Color Management"));
144 build_page();
145 build_guides();
146 build_gridspage();
147 build_snap();
148 build_snap_dtls();
149 #if ENABLE_LCMS
150 build_cms();
151 #endif // ENABLE_LCMS
153 _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
154 _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
156 signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
157 signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
158 signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
159 }
161 void
162 DocumentProperties::init()
163 {
164 update();
166 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
167 repr->addListener (&_repr_events, this);
168 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
169 root->addListener (&_repr_events, this);
171 show_all_children();
172 _grids_button_remove.hide();
173 }
175 DocumentProperties::~DocumentProperties()
176 {
177 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
178 repr->removeListenerByData (this);
179 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
180 root->removeListenerByData (this);
181 }
183 //========================================================================
185 /**
186 * Helper function that attaches widgets in a 3xn table. The widgets come in an
187 * array that has two entries per table row. The two entries code for four
188 * possible cases: (0,0) means insert space in first column; (0, non-0) means
189 * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
190 * (non-0, non-0) means two widgets in columns 2 and 3.
191 **/
192 inline void
193 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
194 {
195 for (unsigned i = 0, r = start; i < n; i += 2)
196 {
197 if (arr[i] && arr[i+1])
198 {
199 table.attach(*arr[i], 1, 2, r, r+1,
200 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
201 table.attach(*arr[i+1], 2, 3, r, r+1,
202 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
203 }
204 else
205 {
206 if (arr[i+1]) {
207 Gtk::AttachOptions yoptions = (Gtk::AttachOptions)0;
208 if (dynamic_cast<Inkscape::UI::Widget::PageSizer*>(arr[i+1])) {
209 // only the PageSizer in Document Properties|Page should be stretched vertically
210 yoptions = Gtk::FILL|Gtk::EXPAND;
211 }
212 table.attach(*arr[i+1], 1, 3, r, r+1,
213 Gtk::FILL|Gtk::EXPAND, yoptions, 0,0);
214 }
215 else if (arr[i])
216 {
217 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
218 label.set_alignment (0.0);
219 table.attach (label, 0, 3, r, r+1,
220 Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
221 }
222 else
223 {
224 Gtk::HBox *space = manage (new Gtk::HBox);
225 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
226 table.attach (*space, 0, 1, r, r+1,
227 (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
228 }
229 }
230 ++r;
231 }
232 }
234 void
235 DocumentProperties::build_page()
236 {
237 _page_page.show();
239 Gtk::Label* label_gen = manage (new Gtk::Label);
240 label_gen->set_markup (_("<b>General</b>"));
241 Gtk::Label* label_bor = manage (new Gtk::Label);
242 label_bor->set_markup (_("<b>Border</b>"));
243 Gtk::Label *label_for = manage (new Gtk::Label);
244 label_for->set_markup (_("<b>Format</b>"));
245 _page_sizer.init();
247 Gtk::Widget *const widget_array[] =
248 {
249 label_gen, 0,
250 0, &_rum_deflt,
251 _rcp_bg._label, &_rcp_bg,
252 0, 0,
253 label_for, 0,
254 0, &_page_sizer,
255 0, 0,
256 label_bor, 0,
257 0, &_rcb_canb,
258 0, &_rcb_bord,
259 0, &_rcb_shad,
260 _rcp_bord._label, &_rcp_bord,
261 };
263 attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
264 }
266 void
267 DocumentProperties::build_guides()
268 {
269 _page_guides.show();
271 Gtk::Label *label_gui = manage (new Gtk::Label);
272 label_gui->set_markup (_("<b>Guides</b>"));
274 Gtk::Widget *const widget_array[] =
275 {
276 label_gui, 0,
277 0, &_rcb_sgui,
278 _rcp_gui._label, &_rcp_gui,
279 _rcp_hgui._label, &_rcp_hgui,
280 0, &_rcbsng,
281 };
283 attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
284 }
286 void
287 DocumentProperties::build_snap()
288 {
289 _page_snap.show();
291 _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"), _("Always snap"),
292 _("Snapping distance, in screen pixels, for snapping to objects"), _("Always snap to objects, regardless of their distance"),
293 _("If set, objects only snap to another object when it's within the range specified below"),
294 "objecttolerance", _wr);
296 //Options for snapping to grids
297 _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"), _("Always snap"),
298 _("Snapping distance, in screen pixels, for snapping to grid"), _("Always snap to grids, regardless of the distance"),
299 _("If set, objects only snap to a grid line when it's within the range specified below"),
300 "gridtolerance", _wr);
302 //Options for snapping to guides
303 _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"), _("Always snap"),
304 _("Snapping distance, in screen pixels, for snapping to guides"), _("Always snap to guides, regardless of the distance"),
305 _("If set, objects only snap to a guide when it's within the range specified below"),
306 "guidetolerance", _wr);
308 //Other options to locate here: e.g. visual snapping indicators on/off
310 std::list<Gtk::Widget*> slaves;
311 slaves.push_back(&_rcbsnop);
312 slaves.push_back(&_rcbsnon);
313 _rcbsnn.setSlaveWidgets(slaves);
315 slaves.clear();
316 slaves.push_back(&_rcbsnbbp);
317 slaves.push_back(&_rcbsnbbn);
318 _rcbsnbb.setSlaveWidgets(slaves);
320 slaves.clear();
321 slaves.push_back(&_rcbsnn);
322 slaves.push_back(&_rcbsnbb);
323 _rcbs.setSlaveWidgets(slaves);
325 Gtk::Label *label_g = manage (new Gtk::Label);
326 label_g->set_markup (_("<b>Snapping</b>"));
327 Gtk::Label *label_w = manage (new Gtk::Label);
328 label_w->set_markup (_("<b>What snaps</b>"));
329 Gtk::Label *label_o = manage (new Gtk::Label);
330 label_o->set_markup (_("<b>Snap to objects</b>"));
331 Gtk::Label *label_gr = manage (new Gtk::Label);
332 label_gr->set_markup (_("<b>Snap to grids</b>"));
333 Gtk::Label *label_gu = manage (new Gtk::Label);
334 label_gu->set_markup (_("<b>Snap to guides</b>"));
336 Gtk::Widget *const array[] =
337 {
338 label_g, 0,
339 0, &_rcbs,
340 0, 0,
341 label_w, 0,
342 0, &_rcbsnn,
343 0, &_rcbsnbb,
344 0, 0,
345 label_o, 0,
346 0, &_rcbsnop,
347 0, &_rcbsnon,
348 0, &_rcbsnbbp,
349 0, &_rcbsnbbn,
350 0, &_rcbsnpb,
351 0, _rsu_sno._vbox,
352 0, 0,
353 label_gr, 0,
354 0, _rsu_sn._vbox,
355 0, 0,
356 label_gu, 0,
357 0, _rsu_gusn._vbox
358 };
360 attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
361 }
363 void
364 DocumentProperties::build_snap_dtls()
365 {
366 _page_snap_dtls.show();
368 //Other options to locate here: e.g. visual snapping indicators on/off
370 Gtk::Label *label_i= manage (new Gtk::Label);
371 label_i->set_markup (_("<b>Snapping to intersections of</b>"));
372 Gtk::Label *label_m = manage (new Gtk::Label);
373 label_m->set_markup (_("<b>Special points to consider</b>"));
375 Gtk::Widget *const array[] =
376 {
377 label_i, 0,
378 0, &_rcbsigg,
379 0, &_rcbsils,
380 0, 0,
381 label_m, 0,
382 0, &_rcbic,
383 0, &_rcbsm
384 };
386 attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
387 }
389 // Very simple observer that just emits a signal if anything happens to a node
390 DocumentProperties::SignalObserver::SignalObserver()
391 : _oldsel(0)
392 {}
394 // Add this observer to the SPObject and remove it from any previous object
395 void
396 DocumentProperties::SignalObserver::set(SPObject* o)
397 {
398 if(_oldsel && _oldsel->repr)
399 _oldsel->repr->removeObserver(*this);
400 if(o && o->repr)
401 o->repr->addObserver(*this);
402 _oldsel = o;
403 }
405 void DocumentProperties::SignalObserver::notifyChildAdded(XML::Node&, XML::Node&, XML::Node*)
406 { signal_changed()(); }
408 void DocumentProperties::SignalObserver::notifyChildRemoved(XML::Node&, XML::Node&, XML::Node*)
409 { signal_changed()(); }
411 void DocumentProperties::SignalObserver::notifyChildOrderChanged(XML::Node&, XML::Node&, XML::Node*, XML::Node*)
412 { signal_changed()(); }
414 void DocumentProperties::SignalObserver::notifyContentChanged(XML::Node&, Util::ptr_shared<char>, Util::ptr_shared<char>)
415 {}
417 void DocumentProperties::SignalObserver::notifyAttributeChanged(XML::Node&, GQuark, Util::ptr_shared<char>, Util::ptr_shared<char>)
418 { signal_changed()(); }
420 sigc::signal<void>& DocumentProperties::SignalObserver::signal_changed()
421 {
422 return _signal_changed;
423 }
425 #if ENABLE_LCMS
426 static void
427 lcms_profile_get_name (cmsHPROFILE profile, const gchar **name)
428 {
429 if (profile)
430 {
431 *name = cmsTakeProductDesc (profile);
433 if (! *name)
434 *name = cmsTakeProductName (profile);
436 if (*name && ! g_utf8_validate (*name, -1, NULL))
437 *name = _("(invalid UTF-8 string)");
438 }
439 else
440 {
441 *name = _("None");
442 }
443 }
445 void
446 DocumentProperties::populate_available_profiles(){
447 Glib::ListHandle<Gtk::Widget*> children = _menu.get_children();
448 for ( Glib::ListHandle<Gtk::Widget*>::iterator it2 = children.begin(); it2 != children.end(); ++it2 ) {
449 _menu.remove(**it2);
450 delete(*it2);
451 }
453 std::list<Glib::ustring> sources = ColorProfile::getProfileDirs();
455 // Use this loop to iterate through a list of possible document locations.
456 for ( std::list<Glib::ustring>::const_iterator it = sources.begin(); it != sources.end(); ++it ) {
457 if ( Inkscape::IO::file_test( it->c_str(), G_FILE_TEST_EXISTS )
458 && Inkscape::IO::file_test( it->c_str(), G_FILE_TEST_IS_DIR )) {
459 GError *err = 0;
460 GDir *directory = g_dir_open(it->c_str(), 0, &err);
461 if (!directory) {
462 gchar *safeDir = Inkscape::IO::sanitizeString(it->c_str());
463 g_warning(_("Color profiles directory (%s) is unavailable."), safeDir);
464 g_free(safeDir);
465 } else {
466 gchar *filename = 0;
467 while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
468 gchar* full = g_build_filename(it->c_str(), filename, NULL);
469 if ( !Inkscape::IO::file_test( full, G_FILE_TEST_IS_DIR ) ) {
470 cmsHPROFILE hProfile = cmsOpenProfileFromFile(full, "r");
471 if (hProfile != NULL){
472 const gchar* name;
473 lcms_profile_get_name(hProfile, &name);
474 Gtk::MenuItem* mi = manage(new Gtk::MenuItem());
475 mi->set_data("filepath", g_strdup(full));
476 mi->set_data("name", g_strdup(name));
477 Gtk::HBox *hbox = manage(new Gtk::HBox());
478 hbox->show();
479 Gtk::Label* lbl = manage(new Gtk::Label(name));
480 lbl->show();
481 hbox->pack_start(*lbl, true, true, 0);
482 mi->add(*hbox);
483 mi->show_all();
484 _menu.append(*mi);
485 // g_free((void*)name);
486 cmsCloseProfile(hProfile);
487 }
488 }
489 g_free(full);
490 }
491 g_dir_close(directory);
492 }
493 }
494 }
495 _menu.show_all();
496 }
498 void
499 DocumentProperties::onEmbedProfile()
500 {
501 //store this profile in the SVG document (create <color-profile> element in the XML)
502 // TODO remove use of 'active' desktop
503 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
504 if (!desktop){
505 g_warning("No active desktop");
506 } else {
507 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
508 Inkscape::XML::Node *cprofRepr = xml_doc->createElement("svg:color-profile");
509 cprofRepr->setAttribute("name", (gchar*) _menu.get_active()->get_data("name"));
510 cprofRepr->setAttribute("xlink:href", (gchar*) _menu.get_active()->get_data("filepath"));
512 // Checks whether there is a defs element. Creates it when needed
513 Inkscape::XML::Node *defsRepr = sp_repr_lookup_name(xml_doc, "svg:defs");
514 if (!defsRepr){
515 defsRepr = xml_doc->createElement("svg:defs");
516 xml_doc->root()->addChild(defsRepr, NULL);
517 }
519 g_assert(SP_ROOT(desktop->doc()->root)->defs);
520 defsRepr->addChild(cprofRepr, NULL);
522 // TODO check if this next line was sometimes needed. It being there caused an assertion.
523 //Inkscape::GC::release(defsRepr);
525 // inform the document, so we can undo
526 sp_document_done(desktop->doc(), SP_VERB_EDIT_EMBED_COLOR_PROFILE, _("Embed Color Profile"));
528 populate_embedded_profiles_box();
529 }
530 }
532 void
533 DocumentProperties::populate_embedded_profiles_box()
534 {
535 _EmbeddedProfilesListStore->clear();
536 const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" );
537 if (current) _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
538 while ( current ) {
539 SPObject* obj = SP_OBJECT(current->data);
540 Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
541 Gtk::TreeModel::Row row = *(_EmbeddedProfilesListStore->append());
542 row[_EmbeddedProfilesListColumns.nameColumn] = prof->name;
543 // row[_EmbeddedProfilesListColumns.previewColumn] = "Color Preview";
544 current = g_slist_next(current);
545 }
546 }
548 void DocumentProperties::embedded_profiles_list_button_release(GdkEventButton* event)
549 {
550 if((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {
551 _EmbProfContextMenu.popup(event->button, event->time);
552 }
553 }
555 void DocumentProperties::create_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem)
556 {
557 Gtk::MenuItem* mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));
558 _EmbProfContextMenu.append(*mi);
559 mi->signal_activate().connect(rem);
560 mi->show();
561 _EmbProfContextMenu.accelerate(parent);
562 }
564 void DocumentProperties::remove_profile(){
565 Glib::ustring name;
566 if(_EmbeddedProfilesList.get_selection()) {
567 Gtk::TreeModel::iterator i = _EmbeddedProfilesList.get_selection()->get_selected();
569 if(i){
570 name = (*i)[_EmbeddedProfilesListColumns.nameColumn];
571 } else {
572 return;
573 }
574 }
576 const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" );
577 while ( current ) {
578 SPObject* obj = SP_OBJECT(current->data);
579 Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
580 if (!name.compare(prof->name)){
581 sp_repr_unparent(obj->repr);
582 sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_COLOR_PROFILE, _("Remove embedded color profile"));
583 }
584 current = g_slist_next(current);
585 }
587 populate_embedded_profiles_box();
588 }
590 void
591 DocumentProperties::build_cms()
592 {
593 _page_cms.show();
595 Gtk::Label *label_embed= manage (new Gtk::Label("", Gtk::ALIGN_LEFT));
596 label_embed->set_markup (_("<b>Embedded Color Profiles:</b>"));
597 Gtk::Label *label_avail = manage (new Gtk::Label("", Gtk::ALIGN_LEFT));
598 label_avail->set_markup (_("<b>Available Color Profiles:</b>"));
600 _embed_btn.set_label(_("Embed Profile"));
602 _page_cms.set_spacing(4);
603 gint row = 0;
605 label_embed->set_alignment(0.0);
606 _page_cms.table().attach(*label_embed, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
607 row++;
608 _page_cms.table().attach(_EmbeddedProfilesListScroller, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
609 row++;
611 Gtk::HBox* spacer = Gtk::manage(new Gtk::HBox());
612 spacer->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
613 _page_cms.table().attach(*spacer, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
614 row++;
616 label_avail->set_alignment(0.0);
617 _page_cms.table().attach(*label_avail, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
618 row++;
619 _page_cms.table().attach(_combo_avail, 0, 2, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
620 _page_cms.table().attach(_embed_btn, 2, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
622 populate_available_profiles();
624 _combo_avail.set_menu(_menu);
625 _combo_avail.set_history(0);
626 _combo_avail.show_all();
628 //# Set up the Embedded Profiles combo box
629 _EmbeddedProfilesListStore = Gtk::ListStore::create(_EmbeddedProfilesListColumns);
630 _EmbeddedProfilesList.set_model(_EmbeddedProfilesListStore);
631 _EmbeddedProfilesList.append_column(_("Profile Name"), _EmbeddedProfilesListColumns.nameColumn);
632 // _EmbeddedProfilesList.append_column(_("Color Preview"), _EmbeddedProfilesListColumns.previewColumn);
633 _EmbeddedProfilesList.set_headers_visible(false);
634 // TODO restore? _EmbeddedProfilesList.set_fixed_height_mode(true);
636 populate_embedded_profiles_box();
638 _EmbeddedProfilesListScroller.add(_EmbeddedProfilesList);
639 _EmbeddedProfilesListScroller.set_shadow_type(Gtk::SHADOW_IN);
640 _EmbeddedProfilesListScroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
641 _EmbeddedProfilesListScroller.set_size_request(-1, 90);
643 _embed_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onEmbedProfile));
645 _EmbeddedProfilesList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &DocumentProperties::embedded_profiles_list_button_release));
646 create_popup_menu(_EmbeddedProfilesList, sigc::mem_fun(*this, &DocumentProperties::remove_profile));
648 const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "defs" );
649 if (current) {
650 _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
651 }
652 _emb_profiles_observer.signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::populate_embedded_profiles_box));
653 }
654 #endif // ENABLE_LCMS
656 /**
657 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
658 */
659 void
660 DocumentProperties::update_gridspage()
661 {
662 SPDesktop *dt = getDesktop();
663 SPNamedView *nv = sp_desktop_namedview(dt);
665 //remove all tabs
666 while (_grids_notebook.get_n_pages() != 0) {
667 _grids_notebook.remove_page(-1); // this also deletes the page.
668 }
670 //add tabs
671 bool grids_present = false;
672 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
673 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
674 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
675 Glib::ustring name(grid->repr->attribute("id"));
676 const char *icon = NULL;
677 switch (grid->getGridType()) {
678 case GRID_RECTANGULAR:
679 icon = INKSCAPE_ICON_GRID_XY;
680 break;
681 case GRID_AXONOMETRIC:
682 icon = INKSCAPE_ICON_GRID_AXONOM;
683 break;
684 default:
685 break;
686 }
687 _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
688 grids_present = true;
689 }
690 _grids_notebook.show_all();
692 if (grids_present)
693 _grids_button_remove.set_sensitive(true);
694 else
695 _grids_button_remove.set_sensitive(false);
696 }
698 /**
699 * Build grid page of dialog.
700 */
701 void
702 DocumentProperties::build_gridspage()
703 {
704 /// \todo FIXME: gray out snapping when grid is off.
705 /// Dissenting view: you want snapping without grid.
707 SPDesktop *dt = getDesktop();
708 SPNamedView *nv = sp_desktop_namedview(dt);
709 (void)nv;
711 _grids_label_crea.set_markup(_("<b>Creation</b>"));
712 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
713 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
714 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
716 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
717 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
718 }
719 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
721 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
723 _grids_vbox.set_spacing(4);
724 _grids_vbox.pack_start(_grids_label_crea, false, false);
725 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
726 _grids_vbox.pack_start(_grids_space, false, false);
727 _grids_vbox.pack_start(_grids_label_def, false, false);
728 _grids_vbox.pack_start(_grids_notebook, false, false);
729 _grids_vbox.pack_start(_grids_button_remove, false, false);
731 update_gridspage();
732 }
736 /**
737 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
738 */
739 void
740 DocumentProperties::update()
741 {
742 if (_wr.isUpdating()) return;
744 SPDesktop *dt = getDesktop();
745 SPNamedView *nv = sp_desktop_namedview(dt);
747 _wr.setUpdating (true);
748 set_sensitive (true);
750 //-----------------------------------------------------------page page
751 _rcp_bg.setRgba32 (nv->pagecolor);
752 _rcb_canb.setActive (nv->showborder);
753 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
754 _rcp_bord.setRgba32 (nv->bordercolor);
755 _rcb_shad.setActive (nv->showpageshadow);
757 if (nv->doc_units)
758 _rum_deflt.setUnit (nv->doc_units);
760 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
761 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
762 _page_sizer.setDim (doc_w_px, doc_h_px);
764 //-----------------------------------------------------------guide page
766 _rcb_sgui.setActive (nv->showguides);
767 _rcp_gui.setRgba32 (nv->guidecolor);
768 _rcp_hgui.setRgba32 (nv->guidehicolor);
770 //-----------------------------------------------------------snap page
772 _rcbsnbb.setActive (nv->snap_manager.snapprefs.getSnapModeBBox());
773 _rcbsnn.setActive (nv->snap_manager.snapprefs.getSnapModeNode());
774 _rcbsng.setActive (nv->snap_manager.snapprefs.getSnapModeGuide());
775 _rcbic.setActive (nv->snap_manager.snapprefs.getIncludeItemCenter());
776 _rcbsm.setActive (nv->snap_manager.snapprefs.getSnapSmoothNodes());
777 _rcbsigg.setActive (nv->snap_manager.snapprefs.getSnapIntersectionGG());
778 _rcbsils.setActive (nv->snap_manager.snapprefs.getSnapIntersectionCS());
779 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
780 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
781 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
782 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
783 _rcbsnpb.setActive(nv->snap_manager.object.getSnapToPageBorder());
784 _rsu_sno.setValue (nv->objecttolerance);
786 _rsu_sn.setValue (nv->gridtolerance);
788 _rsu_gusn.setValue (nv->guidetolerance);
790 _rcbs.setActive (nv->snap_manager.snapprefs.getSnapEnabledGlobally());
792 //-----------------------------------------------------------grids page
794 update_gridspage();
796 //------------------------------------------------Color Management page
798 #if ENABLE_LCMS
799 populate_embedded_profiles_box();
800 populate_available_profiles();
801 #endif // ENABLE_LCMS
803 _wr.setUpdating (false);
804 }
806 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
807 Gtk::HBox&
808 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
809 {
810 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
811 _tab_label_box->set_spacing(4);
812 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
813 label_image)));
815 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
816 _tab_label_box->pack_start(*_tab_label);
817 _tab_label_box->show_all();
819 return *_tab_label_box;
820 }
822 //--------------------------------------------------------------------
824 void
825 DocumentProperties::on_response (int id)
826 {
827 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
828 {
829 _rcp_bg.closeWindow();
830 _rcp_bord.closeWindow();
831 _rcp_gui.closeWindow();
832 _rcp_hgui.closeWindow();
833 }
835 if (id == Gtk::RESPONSE_CLOSE)
836 hide();
837 }
839 void
840 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
841 {
842 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
843 repr->addListener(&_repr_events, this);
844 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
845 root->addListener(&_repr_events, this);
846 update();
847 }
849 void
850 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
851 {
852 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
853 repr->addListener(&_repr_events, this);
854 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
855 root->addListener(&_repr_events, this);
856 update();
857 }
859 void
860 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
861 {
862 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
863 repr->removeListenerByData(this);
864 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
865 root->removeListenerByData(this);
866 }
868 static void
869 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
870 {
871 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
872 dialog->update_gridspage();
873 }
875 static void
876 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
877 {
878 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
879 dialog->update_gridspage();
880 }
884 /**
885 * Called when XML node attribute changed; updates dialog widgets.
886 */
887 static void
888 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
889 {
890 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
891 dialog->update();
892 }
895 /*########################################################################
896 # BUTTON CLICK HANDLERS (callbacks)
897 ########################################################################*/
899 void
900 DocumentProperties::onNewGrid()
901 {
902 SPDesktop *dt = getDesktop();
903 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
904 SPDocument *doc = sp_desktop_document(dt);
906 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
907 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
909 // toggle grid showing to ON:
910 dt->showGrids(true);
911 }
914 void
915 DocumentProperties::onRemoveGrid()
916 {
917 gint pagenum = _grids_notebook.get_current_page();
918 if (pagenum == -1) // no pages
919 return;
921 SPDesktop *dt = getDesktop();
922 SPNamedView *nv = sp_desktop_namedview(dt);
923 Inkscape::CanvasGrid * found_grid = NULL;
924 int i = 0;
925 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
926 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
927 if (pagenum == i) {
928 found_grid = grid;
929 break; // break out of for-loop
930 }
931 }
932 if (found_grid) {
933 // delete the grid that corresponds with the selected tab
934 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
935 found_grid->repr->parent()->removeChild(found_grid->repr);
936 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
937 }
938 }
941 } // namespace Dialog
942 } // namespace UI
943 } // namespace Inkscape
945 /*
946 Local Variables:
947 mode:c++
948 c-file-style:"stroustrup"
949 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
950 indent-tabs-mode:nil
951 fill-column:99
952 End:
953 */
954 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :