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(){
448 std::list<gchar *> sources;
449 sources.push_back( profile_path("color/icc") );
450 //sources.push_back( g_strdup(INKSCAPE_COLORPROFILESDIR) );
452 int index = 1;
454 // Use this loop to iterate through a list of possible document locations.
455 while (!sources.empty()) {
456 gchar *dirname = sources.front();
458 if ( Inkscape::IO::file_test( dirname, G_FILE_TEST_EXISTS )
459 && Inkscape::IO::file_test( dirname, G_FILE_TEST_IS_DIR )) {
460 GError *err = 0;
461 GDir *directory = g_dir_open(dirname, 0, &err);
462 if (!directory) {
463 gchar *safeDir = Inkscape::IO::sanitizeString(dirname);
464 g_warning(_("Color profiles directory (%s) is unavailable."), safeDir);
465 g_free(safeDir);
466 } else {
467 gchar *filename = 0;
468 while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
469 gchar* lower = g_ascii_strdown( filename, -1 );
470 gchar* full = g_build_filename(dirname, filename, NULL);
471 if ( !Inkscape::IO::file_test( full, G_FILE_TEST_IS_DIR ) ) {
472 cmsHPROFILE hProfile = cmsOpenProfileFromFile(full, "r");
473 if (hProfile != NULL){
474 const gchar* name;
475 lcms_profile_get_name(hProfile, &name);
476 Gtk::MenuItem* mi = new Gtk::MenuItem();
477 mi->set_data("filepath", g_strdup(full));
478 mi->set_data("name", g_strdup(name));
479 Gtk::HBox *hbox = new Gtk::HBox();
480 hbox->show();
481 Gtk::Label* lbl = manage(new Gtk::Label(name));
482 lbl->show();
483 hbox->pack_start(*lbl, true, true, 0);
484 mi->add(*hbox);
485 mi->show_all();
486 _menu.append(*mi);
487 // g_free((void*)name);
488 }
489 cmsCloseProfile(hProfile);
490 index++;
491 }
492 g_free(full);
493 g_free(lower);
494 }
495 g_dir_close(directory);
496 }
497 }
499 // toss the dirname
500 g_free(dirname);
501 sources.pop_front();
502 }
503 _menu.show_all();
504 }
506 void
507 DocumentProperties::onEmbedProfile()
508 {
509 //store this profile in the SVG document (create <color-profile> element in the XML)
510 SPDesktop *desktop = SP_ACTIVE_DESKTOP;
511 if (!desktop){
512 g_warning("No active desktop");
513 return;
514 }
515 Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
516 Inkscape::XML::Node *cprofRepr = xml_doc->createElement("svg:color-profile");
517 cprofRepr->setAttribute("name", (gchar*) _menu.get_active()->get_data("name"));
518 cprofRepr->setAttribute("xlink:href", (gchar*) _menu.get_active()->get_data("filepath"));
520 /* Checks whether there is a defs element. Creates it when needed */
521 Inkscape::XML::Node *defsRepr = sp_repr_lookup_name(xml_doc, "svg:defs");
522 if (!defsRepr){
523 defsRepr = xml_doc->createElement("svg:defs");
524 xml_doc->root()->addChild(defsRepr, NULL);
525 }
527 g_assert(SP_ROOT(desktop->doc()->root)->defs);
528 defsRepr->addChild(cprofRepr, NULL);
530 Inkscape::GC::release(defsRepr);
532 // inform the document, so we can undo
533 sp_document_done(desktop->doc(), SP_VERB_EDIT_EMBED_COLOR_PROFILE, _("Embed Color Profile"));
535 populate_embedded_profiles_box();
536 }
538 void
539 DocumentProperties::populate_embedded_profiles_box()
540 {
541 _EmbeddedProfilesListStore->clear();
542 const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" );
543 if (current) _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
544 while ( current ) {
545 SPObject* obj = SP_OBJECT(current->data);
546 Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
547 Gtk::TreeModel::Row row = *(_EmbeddedProfilesListStore->append());
548 row[_EmbeddedProfilesListColumns.nameColumn] = prof->name;
549 // row[_EmbeddedProfilesListColumns.previewColumn] = "Color Preview";
550 current = g_slist_next(current);
551 }
552 }
554 void DocumentProperties::embedded_profiles_list_button_release(GdkEventButton* event)
555 {
556 if((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {
557 _EmbProfContextMenu.popup(event->button, event->time);
558 }
559 }
561 void DocumentProperties::create_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem)
562 {
563 Gtk::MenuItem* mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));
564 _EmbProfContextMenu.append(*mi);
565 mi->signal_activate().connect(rem);
566 mi->show();
567 _EmbProfContextMenu.accelerate(parent);
568 }
570 void DocumentProperties::remove_profile(){
571 Glib::ustring name;
572 if(_EmbeddedProfilesList.get_selection()) {
573 Gtk::TreeModel::iterator i = _EmbeddedProfilesList.get_selection()->get_selected();
575 if(i){
576 name = (*i)[_EmbeddedProfilesListColumns.nameColumn];
577 } else {
578 return;
579 }
580 }
582 const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" );
583 while ( current ) {
584 SPObject* obj = SP_OBJECT(current->data);
585 Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
586 if (!name.compare(prof->name)){
587 sp_repr_unparent(obj->repr);
588 sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_COLOR_PROFILE, _("Remove embedded color profile"));
589 }
590 current = g_slist_next(current);
591 }
593 populate_embedded_profiles_box();
594 }
596 void
597 DocumentProperties::build_cms()
598 {
599 _page_cms.show();
601 Gtk::Label *label_embed= manage (new Gtk::Label("", Gtk::ALIGN_LEFT));
602 label_embed->set_markup (_("<b>Embedded Color Profiles:</b>"));
603 Gtk::Label *label_avail = manage (new Gtk::Label("", Gtk::ALIGN_LEFT));
604 label_avail->set_markup (_("<b>Available Color Profiles:</b>"));
606 _embed_btn.set_label(_("Embed Profile"));
608 _page_cms.set_spacing(4);
609 gint row = 0;
611 label_embed->set_alignment(0.0);
612 _page_cms.table().attach(*label_embed, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
613 row++;
614 _page_cms.table().attach(_EmbeddedProfilesListScroller, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
615 row++;
617 Gtk::HBox* spacer = Gtk::manage(new Gtk::HBox());
618 spacer->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
619 _page_cms.table().attach(*spacer, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
620 row++;
622 label_avail->set_alignment(0.0);
623 _page_cms.table().attach(*label_avail, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
624 row++;
625 _page_cms.table().attach(_combo_avail, 0, 2, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
626 _page_cms.table().attach(_embed_btn, 2, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
628 populate_available_profiles();
630 _combo_avail.set_menu(_menu);
631 _combo_avail.set_history(0);
632 _combo_avail.show_all();
634 //# Set up the Embedded Profiles combo box
635 _EmbeddedProfilesListStore = Gtk::ListStore::create(_EmbeddedProfilesListColumns);
636 _EmbeddedProfilesList.set_model(_EmbeddedProfilesListStore);
637 _EmbeddedProfilesList.append_column(_("Profile Name"), _EmbeddedProfilesListColumns.nameColumn);
638 // _EmbeddedProfilesList.append_column(_("Color Preview"), _EmbeddedProfilesListColumns.previewColumn);
639 _EmbeddedProfilesList.set_headers_visible(false);
640 // TODO restore? _EmbeddedProfilesList.set_fixed_height_mode(true);
642 populate_embedded_profiles_box();
644 _EmbeddedProfilesListScroller.add(_EmbeddedProfilesList);
645 _EmbeddedProfilesListScroller.set_shadow_type(Gtk::SHADOW_IN);
646 _EmbeddedProfilesListScroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
647 _EmbeddedProfilesListScroller.set_size_request(-1, 90);
649 _embed_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onEmbedProfile));
651 _EmbeddedProfilesList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &DocumentProperties::embedded_profiles_list_button_release));
652 create_popup_menu(_EmbeddedProfilesList, sigc::mem_fun(*this, &DocumentProperties::remove_profile));
654 const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "defs" );
655 if (current) {
656 _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
657 }
658 _emb_profiles_observer.signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::populate_embedded_profiles_box));
659 }
660 #endif // ENABLE_LCMS
662 /**
663 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
664 */
665 void
666 DocumentProperties::update_gridspage()
667 {
668 SPDesktop *dt = getDesktop();
669 SPNamedView *nv = sp_desktop_namedview(dt);
671 //remove all tabs
672 while (_grids_notebook.get_n_pages() != 0) {
673 _grids_notebook.remove_page(-1); // this also deletes the page.
674 }
676 //add tabs
677 bool grids_present = false;
678 for (GSList const * l = nv->grids; l != NULL; l = l->next) {
679 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
680 if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
681 Glib::ustring name(grid->repr->attribute("id"));
682 const char *icon = NULL;
683 switch (grid->getGridType()) {
684 case GRID_RECTANGULAR:
685 icon = INKSCAPE_ICON_GRID_XY;
686 break;
687 case GRID_AXONOMETRIC:
688 icon = INKSCAPE_ICON_GRID_AXONOM;
689 break;
690 default:
691 break;
692 }
693 _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
694 grids_present = true;
695 }
696 _grids_notebook.show_all();
698 if (grids_present)
699 _grids_button_remove.set_sensitive(true);
700 else
701 _grids_button_remove.set_sensitive(false);
702 }
704 /**
705 * Build grid page of dialog.
706 */
707 void
708 DocumentProperties::build_gridspage()
709 {
710 /// \todo FIXME: gray out snapping when grid is off.
711 /// Dissenting view: you want snapping without grid.
713 SPDesktop *dt = getDesktop();
714 SPNamedView *nv = sp_desktop_namedview(dt);
715 (void)nv;
717 _grids_label_crea.set_markup(_("<b>Creation</b>"));
718 _grids_label_def.set_markup(_("<b>Defined grids</b>"));
719 _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
720 _grids_hbox_crea.pack_start(_grids_button_new, true, true);
722 for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
723 _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
724 }
725 _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
727 _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
729 _grids_vbox.set_spacing(4);
730 _grids_vbox.pack_start(_grids_label_crea, false, false);
731 _grids_vbox.pack_start(_grids_hbox_crea, false, false);
732 _grids_vbox.pack_start(_grids_space, false, false);
733 _grids_vbox.pack_start(_grids_label_def, false, false);
734 _grids_vbox.pack_start(_grids_notebook, false, false);
735 _grids_vbox.pack_start(_grids_button_remove, false, false);
737 update_gridspage();
738 }
742 /**
743 * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
744 */
745 void
746 DocumentProperties::update()
747 {
748 if (_wr.isUpdating()) return;
750 SPDesktop *dt = getDesktop();
751 SPNamedView *nv = sp_desktop_namedview(dt);
753 _wr.setUpdating (true);
754 set_sensitive (true);
756 //-----------------------------------------------------------page page
757 _rcp_bg.setRgba32 (nv->pagecolor);
758 _rcb_canb.setActive (nv->showborder);
759 _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
760 _rcp_bord.setRgba32 (nv->bordercolor);
761 _rcb_shad.setActive (nv->showpageshadow);
763 if (nv->doc_units)
764 _rum_deflt.setUnit (nv->doc_units);
766 double const doc_w_px = sp_document_width(sp_desktop_document(dt));
767 double const doc_h_px = sp_document_height(sp_desktop_document(dt));
768 _page_sizer.setDim (doc_w_px, doc_h_px);
770 //-----------------------------------------------------------guide page
772 _rcb_sgui.setActive (nv->showguides);
773 _rcp_gui.setRgba32 (nv->guidecolor);
774 _rcp_hgui.setRgba32 (nv->guidehicolor);
776 //-----------------------------------------------------------snap page
778 _rcbsnbb.setActive (nv->snap_manager.snapprefs.getSnapModeBBox());
779 _rcbsnn.setActive (nv->snap_manager.snapprefs.getSnapModeNode());
780 _rcbsng.setActive (nv->snap_manager.snapprefs.getSnapModeGuide());
781 _rcbic.setActive (nv->snap_manager.snapprefs.getIncludeItemCenter());
782 _rcbsm.setActive (nv->snap_manager.snapprefs.getSnapSmoothNodes());
783 _rcbsigg.setActive (nv->snap_manager.snapprefs.getSnapIntersectionGG());
784 _rcbsils.setActive (nv->snap_manager.snapprefs.getSnapIntersectionCS());
785 _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
786 _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
787 _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
788 _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
789 _rcbsnpb.setActive(nv->snap_manager.object.getSnapToPageBorder());
790 _rsu_sno.setValue (nv->objecttolerance);
792 _rsu_sn.setValue (nv->gridtolerance);
794 _rsu_gusn.setValue (nv->guidetolerance);
796 _rcbs.setActive (nv->snap_manager.snapprefs.getSnapEnabledGlobally());
798 //-----------------------------------------------------------grids page
800 update_gridspage();
802 //------------------------------------------------Color Management page
804 #if ENABLE_LCMS
805 populate_embedded_profiles_box();
806 populate_available_profiles();
807 #endif // ENABLE_LCMS
809 _wr.setUpdating (false);
810 }
812 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
813 Gtk::HBox&
814 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
815 {
816 Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
817 _tab_label_box->set_spacing(4);
818 _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
819 label_image)));
821 Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
822 _tab_label_box->pack_start(*_tab_label);
823 _tab_label_box->show_all();
825 return *_tab_label_box;
826 }
828 //--------------------------------------------------------------------
830 void
831 DocumentProperties::on_response (int id)
832 {
833 if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
834 {
835 _rcp_bg.closeWindow();
836 _rcp_bord.closeWindow();
837 _rcp_gui.closeWindow();
838 _rcp_hgui.closeWindow();
839 }
841 if (id == Gtk::RESPONSE_CLOSE)
842 hide();
843 }
845 void
846 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
847 {
848 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
849 repr->addListener(&_repr_events, this);
850 Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
851 root->addListener(&_repr_events, this);
852 update();
853 }
855 void
856 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
857 {
858 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
859 repr->addListener(&_repr_events, this);
860 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
861 root->addListener(&_repr_events, this);
862 update();
863 }
865 void
866 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
867 {
868 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
869 repr->removeListenerByData(this);
870 Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
871 root->removeListenerByData(this);
872 }
874 static void
875 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
876 {
877 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
878 dialog->update_gridspage();
879 }
881 static void
882 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
883 {
884 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
885 dialog->update_gridspage();
886 }
890 /**
891 * Called when XML node attribute changed; updates dialog widgets.
892 */
893 static void
894 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
895 {
896 if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
897 dialog->update();
898 }
901 /*########################################################################
902 # BUTTON CLICK HANDLERS (callbacks)
903 ########################################################################*/
905 void
906 DocumentProperties::onNewGrid()
907 {
908 SPDesktop *dt = getDesktop();
909 Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
910 SPDocument *doc = sp_desktop_document(dt);
912 Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
913 CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
915 // toggle grid showing to ON:
916 dt->showGrids(true);
917 }
920 void
921 DocumentProperties::onRemoveGrid()
922 {
923 gint pagenum = _grids_notebook.get_current_page();
924 if (pagenum == -1) // no pages
925 return;
927 SPDesktop *dt = getDesktop();
928 SPNamedView *nv = sp_desktop_namedview(dt);
929 Inkscape::CanvasGrid * found_grid = NULL;
930 int i = 0;
931 for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) { // not a very nice fix, but works.
932 Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
933 if (pagenum == i) {
934 found_grid = grid;
935 break; // break out of for-loop
936 }
937 }
938 if (found_grid) {
939 // delete the grid that corresponds with the selected tab
940 // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
941 found_grid->repr->parent()->removeChild(found_grid->repr);
942 sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
943 }
944 }
947 } // namespace Dialog
948 } // namespace UI
949 } // namespace Inkscape
951 /*
952 Local Variables:
953 mode:c++
954 c-file-style:"stroustrup"
955 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
956 indent-tabs-mode:nil
957 fill-column:99
958 End:
959 */
960 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :