Code

Now users can design a font within inkscape, save it and then open the
[inkscape.git] / src / ui / dialog / document-properties.cpp
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       _rcbmp( _("_Midpoints"), _("Snap midpoints of straight line segments"), "inkscape:snap-midpoints", _wr),
123       _rcbsigg(_("_Grid with guides"), _("Snap to grid-guide intersections"), "inkscape:snap-intersection-grid-guide", _wr),
124       _rcbsils(_("_Paths"), _("Snap to intersections of paths ('snap to paths' must be enabled, see the previous tab)"),
125                 "inkscape:snap-intersection-paths", _wr),
126     //---------------------------------------------------------------
127       _grids_label_crea("", Gtk::ALIGN_LEFT),
128       //TRANSLATORS: In Grid|_New translate only the word _New. It ref to grid
129       _grids_button_new(Q_("Grid|_New"), _("Create new grid.")),
130       _grids_button_remove(_("_Remove"), _("Remove selected grid.")),
131       _grids_label_def("", Gtk::ALIGN_LEFT)
132     //---------------------------------------------------------------
134     _tt.enable();
135     _getContents()->set_spacing (4);
136     _getContents()->pack_start(_notebook, true, true);
138     _notebook.append_page(_page_page,      _("Page"));
139     _notebook.append_page(_page_guides,    _("Guides"));
140     _notebook.append_page(_grids_vbox,     _("Grids"));
141     _notebook.append_page(_page_snap,      _("Snap"));
142     _notebook.append_page(_page_snap_dtls, _("Snap points"));
143     _notebook.append_page(_page_cms, _("Color Management"));
145     build_page();
146     build_guides();
147     build_gridspage();
148     build_snap();
149     build_snap_dtls();
150 #if ENABLE_LCMS
151     build_cms();
152 #endif // ENABLE_LCMS
154     _grids_button_new.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onNewGrid));
155     _grids_button_remove.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::onRemoveGrid));
157     signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDocumentReplaced));
158     signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleActivateDesktop));
159     signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentProperties::_handleDeactivateDesktop));
162 void
163 DocumentProperties::init()
165     update();
167     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
168     repr->addListener (&_repr_events, this);
169     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
170     root->addListener (&_repr_events, this);
172     show_all_children();
173     _grids_button_remove.hide();
176 DocumentProperties::~DocumentProperties()
178     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
179     repr->removeListenerByData (this);
180     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(getDesktop())->root);
181     root->removeListenerByData (this);
184 //========================================================================
186 /**
187  * Helper function that attaches widgets in a 3xn table. The widgets come in an
188  * array that has two entries per table row. The two entries code for four
189  * possible cases: (0,0) means insert space in first column; (0, non-0) means
190  * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
191  * (non-0, non-0) means two widgets in columns 2 and 3.
192 **/
193 inline void
194 attach_all(Gtk::Table &table, Gtk::Widget *const arr[], unsigned const n, int start = 0)
196     for (unsigned i = 0, r = start; i < n; i += 2)
197     {
198         if (arr[i] && arr[i+1])
199         {
200             table.attach(*arr[i],   1, 2, r, r+1,
201                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
202             table.attach(*arr[i+1], 2, 3, r, r+1,
203                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
204         }
205         else
206         {
207             if (arr[i+1]) {
208                 Gtk::AttachOptions yoptions = (Gtk::AttachOptions)0;
209                 if (dynamic_cast<Inkscape::UI::Widget::PageSizer*>(arr[i+1])) {
210                     // only the PageSizer in Document Properties|Page should be stretched vertically
211                     yoptions = Gtk::FILL|Gtk::EXPAND;
212                 }
213                 table.attach(*arr[i+1], 1, 3, r, r+1,
214                       Gtk::FILL|Gtk::EXPAND, yoptions, 0,0);
215             }
216             else if (arr[i])
217             {
218                 Gtk::Label& label = reinterpret_cast<Gtk::Label&>(*arr[i]);
219                 label.set_alignment (0.0);
220                 table.attach (label, 0, 3, r, r+1,
221                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
222             }
223             else
224             {
225                 Gtk::HBox *space = manage (new Gtk::HBox);
226                 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
227                 table.attach (*space, 0, 1, r, r+1,
228                       (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
229             }
230         }
231         ++r;
232     }
235 void
236 DocumentProperties::build_page()
238     _page_page.show();
240     Gtk::Label* label_gen = manage (new Gtk::Label);
241     label_gen->set_markup (_("<b>General</b>"));
242     Gtk::Label* label_bor = manage (new Gtk::Label);
243     label_bor->set_markup (_("<b>Border</b>"));
244     Gtk::Label *label_for = manage (new Gtk::Label);
245     label_for->set_markup (_("<b>Format</b>"));
246     _page_sizer.init();
248     Gtk::Widget *const widget_array[] =
249     {
250         label_gen,         0,
251         0,                 &_rum_deflt,
252         _rcp_bg._label,    &_rcp_bg,
253         0,                 0,
254         label_for,         0,
255         0,                 &_page_sizer,
256         0,                 0,
257         label_bor,         0,
258         0,                 &_rcb_canb,
259         0,                 &_rcb_bord,
260         0,                 &_rcb_shad,
261         _rcp_bord._label,  &_rcp_bord,
262     };
264     attach_all(_page_page.table(), widget_array, G_N_ELEMENTS(widget_array));
267 void
268 DocumentProperties::build_guides()
270     _page_guides.show();
272     Gtk::Label *label_gui = manage (new Gtk::Label);
273     label_gui->set_markup (_("<b>Guides</b>"));
275     Gtk::Widget *const widget_array[] =
276     {
277         label_gui,        0,
278         0,                &_rcb_sgui,
279         _rcp_gui._label,  &_rcp_gui,
280         _rcp_hgui._label, &_rcp_hgui,
281         0,                &_rcbsng,
282     };
284     attach_all(_page_guides.table(), widget_array, G_N_ELEMENTS(widget_array));
287 void
288 DocumentProperties::build_snap()
290     _page_snap.show();
292     _rsu_sno.init (_("Snap _distance"), _("Snap only when _closer than:"), _("Always snap"),
293                   _("Snapping distance, in screen pixels, for snapping to objects"), _("Always snap to objects, regardless of their distance"),
294                   _("If set, objects only snap to another object when it's within the range specified below"),
295                   "objecttolerance", _wr);
297     //Options for snapping to grids
298     _rsu_sn.init (_("Snap d_istance"), _("Snap only when c_loser than:"), _("Always snap"),
299                   _("Snapping distance, in screen pixels, for snapping to grid"), _("Always snap to grids, regardless of the distance"),
300                   _("If set, objects only snap to a grid line when it's within the range specified below"),
301                   "gridtolerance", _wr);
303     //Options for snapping to guides
304     _rsu_gusn.init (_("Snap dist_ance"), _("Snap only when close_r than:"), _("Always snap"),
305                 _("Snapping distance, in screen pixels, for snapping to guides"), _("Always snap to guides, regardless of the distance"),
306                 _("If set, objects only snap to a guide when it's within the range specified below"),
307                 "guidetolerance", _wr);
309     //Other options to locate here: e.g. visual snapping indicators on/off
311     std::list<Gtk::Widget*> slaves;
312     slaves.push_back(&_rcbsnop);
313     slaves.push_back(&_rcbsnon);
314     _rcbsnn.setSlaveWidgets(slaves);
316     slaves.clear();
317     slaves.push_back(&_rcbsnbbp);
318     slaves.push_back(&_rcbsnbbn);
319     _rcbsnbb.setSlaveWidgets(slaves);
321     slaves.clear();
322     slaves.push_back(&_rcbsnn);
323     slaves.push_back(&_rcbsnbb);
324     _rcbs.setSlaveWidgets(slaves);
326     Gtk::Label *label_g = manage (new Gtk::Label);
327     label_g->set_markup (_("<b>Snapping</b>"));
328     Gtk::Label *label_w = manage (new Gtk::Label);
329     label_w->set_markup (_("<b>What snaps</b>"));
330     Gtk::Label *label_o = manage (new Gtk::Label);
331     label_o->set_markup (_("<b>Snap to objects</b>"));
332     Gtk::Label *label_gr = manage (new Gtk::Label);
333     label_gr->set_markup (_("<b>Snap to grids</b>"));
334     Gtk::Label *label_gu = manage (new Gtk::Label);
335     label_gu->set_markup (_("<b>Snap to guides</b>"));
337     Gtk::Widget *const array[] =
338     {
339         label_g,            0,
340         0,                  &_rcbs,
341         0,                  0,
342         label_w,            0,
343         0,                  &_rcbsnn,
344         0,                  &_rcbsnbb,
345         0,                  0,
346         label_o,            0,
347         0,                  &_rcbsnop,
348         0,                  &_rcbsnon,
349         0,                  &_rcbsnbbp,
350         0,                  &_rcbsnbbn,
351         0,                  &_rcbsnpb,
352         0,                  _rsu_sno._vbox,
353         0,                  0,
354         label_gr,           0,
355         0,                  _rsu_sn._vbox,
356         0,                  0,
357         label_gu,           0,
358         0,                  _rsu_gusn._vbox
359     };
361     attach_all(_page_snap.table(), array, G_N_ELEMENTS(array));
362  }
364 void
365 DocumentProperties::build_snap_dtls()
367     _page_snap_dtls.show();
369     //Other options to locate here: e.g. visual snapping indicators on/off
371     Gtk::Label *label_i= manage (new Gtk::Label);
372     label_i->set_markup (_("<b>Snapping intersections of</b>"));
373     Gtk::Label *label_m = manage (new Gtk::Label);
374     label_m->set_markup (_("<b>Special points to consider</b>"));
376     Gtk::Widget *const array[] =
377     {
378         label_i,            0,
379         0,                  &_rcbsigg,
380         0,                  &_rcbsils,
381         0,                  0,
382         label_m,            0,
383         0,                  &_rcbic,
384         0,                  &_rcbsm,
385         0,                  &_rcbmp
386     };
388     attach_all(_page_snap_dtls.table(), array, G_N_ELEMENTS(array));
391 #if ENABLE_LCMS
392 static void
393 lcms_profile_get_name (cmsHPROFILE   profile, const gchar **name)
395   if (profile)
396     {
397       *name = cmsTakeProductDesc (profile);
399       if (! *name)
400         *name = cmsTakeProductName (profile);
402       if (*name && ! g_utf8_validate (*name, -1, NULL))
403         *name = _("(invalid UTF-8 string)");
404     }
405   else
406     {
407       *name = _("None");
408     }
411 void
412 DocumentProperties::populate_available_profiles(){
413     Glib::ListHandle<Gtk::Widget*> children = _menu.get_children();
414     for ( Glib::ListHandle<Gtk::Widget*>::iterator it2 = children.begin(); it2 != children.end(); ++it2 ) {
415         _menu.remove(**it2);
416         delete(*it2);
417     }
419     std::list<Glib::ustring> sources = ColorProfile::getProfileDirs();
421     // Use this loop to iterate through a list of possible document locations.
422     for ( std::list<Glib::ustring>::const_iterator it = sources.begin(); it != sources.end(); ++it ) {
423         if ( Inkscape::IO::file_test( it->c_str(), G_FILE_TEST_EXISTS )
424              && Inkscape::IO::file_test( it->c_str(), G_FILE_TEST_IS_DIR )) {
425             GError *err = 0;
426             GDir *directory = g_dir_open(it->c_str(), 0, &err);
427             if (!directory) {
428                 gchar *safeDir = Inkscape::IO::sanitizeString(it->c_str());
429                 g_warning(_("Color profiles directory (%s) is unavailable."), safeDir);
430                 g_free(safeDir);
431             } else {
432                 gchar *filename = 0;
433                 while ((filename = (gchar *)g_dir_read_name(directory)) != NULL) {
434                     gchar* full = g_build_filename(it->c_str(), filename, NULL);
435                     if ( !Inkscape::IO::file_test( full, G_FILE_TEST_IS_DIR ) ) {
436                         cmsHPROFILE hProfile = cmsOpenProfileFromFile(full, "r");
437                         if (hProfile != NULL){
438                             const gchar* name;
439                             lcms_profile_get_name(hProfile, &name);
440                             Gtk::MenuItem* mi = manage(new Gtk::MenuItem());
441                             mi->set_data("filepath", g_strdup(full));
442                             mi->set_data("name", g_strdup(name));
443                             Gtk::HBox *hbox = manage(new Gtk::HBox());
444                             hbox->show();
445                             Gtk::Label* lbl = manage(new Gtk::Label(name));
446                             lbl->show();
447                             hbox->pack_start(*lbl, true, true, 0);
448                             mi->add(*hbox);
449                             mi->show_all();
450                             _menu.append(*mi);
451         //                    g_free((void*)name);
452                             cmsCloseProfile(hProfile);
453                         }
454                     }
455                     g_free(full);
456                 }
457                 g_dir_close(directory);
458             }
459         }
460     }
461     _menu.show_all();
464 void
465 DocumentProperties::linkSelectedProfile()
467 //store this profile in the SVG document (create <color-profile> element in the XML)
468     // TODO remove use of 'active' desktop
469     SPDesktop *desktop = SP_ACTIVE_DESKTOP;
470     if (!desktop){
471         g_warning("No active desktop");
472     } else {
473         Inkscape::XML::Document *xml_doc = sp_document_repr_doc(desktop->doc());
474         Inkscape::XML::Node *cprofRepr = xml_doc->createElement("svg:color-profile");
475         cprofRepr->setAttribute("name", (gchar*) _menu.get_active()->get_data("name"));
476         cprofRepr->setAttribute("xlink:href", (gchar*) _menu.get_active()->get_data("filepath"));
478         // Checks whether there is a defs element. Creates it when needed
479         Inkscape::XML::Node *defsRepr = sp_repr_lookup_name(xml_doc, "svg:defs");
480         if (!defsRepr){
481             defsRepr = xml_doc->createElement("svg:defs");
482             xml_doc->root()->addChild(defsRepr, NULL);
483         }
485         g_assert(SP_ROOT(desktop->doc()->root)->defs);
486         defsRepr->addChild(cprofRepr, NULL);
488         // TODO check if this next line was sometimes needed. It being there caused an assertion.
489         //Inkscape::GC::release(defsRepr);
491         // inform the document, so we can undo
492         sp_document_done(desktop->doc(), SP_VERB_EDIT_LINK_COLOR_PROFILE, _("Link Color Profile"));
494         populate_linked_profiles_box();
495     }
498 void
499 DocumentProperties::populate_linked_profiles_box()
501     _LinkedProfilesListStore->clear();
502     const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" );
503     if (current) _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
504     while ( current ) {
505         SPObject* obj = SP_OBJECT(current->data);
506         Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
507         Gtk::TreeModel::Row row = *(_LinkedProfilesListStore->append());
508         row[_LinkedProfilesListColumns.nameColumn] = prof->name;
509 //        row[_LinkedProfilesListColumns.previewColumn] = "Color Preview";
510         current = g_slist_next(current);
511     }
514 void DocumentProperties::linked_profiles_list_button_release(GdkEventButton* event)
516     if((event->type == GDK_BUTTON_RELEASE) && (event->button == 3)) {
517         _EmbProfContextMenu.popup(event->button, event->time);
518     }
521 void DocumentProperties::create_popup_menu(Gtk::Widget& parent, sigc::slot<void> rem)
523     Gtk::MenuItem* mi = Gtk::manage(new Gtk::ImageMenuItem(Gtk::Stock::REMOVE));
524     _EmbProfContextMenu.append(*mi);
525     mi->signal_activate().connect(rem);
526     mi->show();
527     _EmbProfContextMenu.accelerate(parent);
530 void DocumentProperties::removeSelectedProfile(){
531     Glib::ustring name;
532     if(_LinkedProfilesList.get_selection()) {
533         Gtk::TreeModel::iterator i = _LinkedProfilesList.get_selection()->get_selected();
535         if(i){
536             name = (*i)[_LinkedProfilesListColumns.nameColumn];
537         } else {
538             return;
539         }
540     }
542     const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "iccprofile" );
543     while ( current ) {
544         SPObject* obj = SP_OBJECT(current->data);
545         Inkscape::ColorProfile* prof = reinterpret_cast<Inkscape::ColorProfile*>(obj);
546         if (!name.compare(prof->name)){
547             sp_repr_unparent(obj->repr);
548             sp_document_done(SP_ACTIVE_DOCUMENT, SP_VERB_EDIT_REMOVE_COLOR_PROFILE, _("Remove linked color profile"));
549         }
550         current = g_slist_next(current);
551     }
553     populate_linked_profiles_box();
556 void
557 DocumentProperties::build_cms()
559     _page_cms.show();
561     Gtk::Label *label_link= manage (new Gtk::Label("", Gtk::ALIGN_LEFT));
562     label_link->set_markup (_("<b>Linked Color Profiles:</b>"));
563     Gtk::Label *label_avail = manage (new Gtk::Label("", Gtk::ALIGN_LEFT));
564     label_avail->set_markup (_("<b>Available Color Profiles:</b>"));
566     _link_btn.set_label(_("Link Profile"));
568     _page_cms.set_spacing(4);
569     gint row = 0;
571     label_link->set_alignment(0.0);
572     _page_cms.table().attach(*label_link, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
573     row++;
574     _page_cms.table().attach(_LinkedProfilesListScroller, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
575     row++;
577     Gtk::HBox* spacer = Gtk::manage(new Gtk::HBox());
578     spacer->set_size_request(SPACE_SIZE_X, SPACE_SIZE_Y);
579     _page_cms.table().attach(*spacer, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
580     row++;
582     label_avail->set_alignment(0.0);
583     _page_cms.table().attach(*label_avail, 0, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
584     row++;
585     _page_cms.table().attach(_combo_avail, 0, 2, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
586     _page_cms.table().attach(_link_btn, 2, 3, row, row + 1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0, 0, 0);
588     populate_available_profiles();
590     _combo_avail.set_menu(_menu);
591     _combo_avail.set_history(0);
592     _combo_avail.show_all();
594     //# Set up the Linked Profiles combo box
595     _LinkedProfilesListStore = Gtk::ListStore::create(_LinkedProfilesListColumns);
596     _LinkedProfilesList.set_model(_LinkedProfilesListStore);
597     _LinkedProfilesList.append_column(_("Profile Name"), _LinkedProfilesListColumns.nameColumn);
598 //    _LinkedProfilesList.append_column(_("Color Preview"), _LinkedProfilesListColumns.previewColumn);
599     _LinkedProfilesList.set_headers_visible(false);
600 // TODO restore?    _LinkedProfilesList.set_fixed_height_mode(true);
602     populate_linked_profiles_box();
604     _LinkedProfilesListScroller.add(_LinkedProfilesList);
605     _LinkedProfilesListScroller.set_shadow_type(Gtk::SHADOW_IN);
606     _LinkedProfilesListScroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
607     _LinkedProfilesListScroller.set_size_request(-1, 90);
609     _link_btn.signal_clicked().connect(sigc::mem_fun(*this, &DocumentProperties::linkSelectedProfile));
611     _LinkedProfilesList.signal_button_release_event().connect_notify(sigc::mem_fun(*this, &DocumentProperties::linked_profiles_list_button_release));
612     create_popup_menu(_LinkedProfilesList, sigc::mem_fun(*this, &DocumentProperties::removeSelectedProfile));
614     const GSList *current = sp_document_get_resource_list( SP_ACTIVE_DOCUMENT, "defs" );
615     if (current) {
616         _emb_profiles_observer.set(SP_OBJECT(current->data)->parent);
617     }
618     _emb_profiles_observer.signal_changed().connect(sigc::mem_fun(*this, &DocumentProperties::populate_linked_profiles_box));
620 #endif // ENABLE_LCMS
622 /**
623 * Called for _updating_ the dialog (e.g. when a new grid was manually added in XML)
624 */
625 void
626 DocumentProperties::update_gridspage()
628     SPDesktop *dt = getDesktop();
629     SPNamedView *nv = sp_desktop_namedview(dt);
631     //remove all tabs
632     while (_grids_notebook.get_n_pages() != 0) {
633         _grids_notebook.remove_page(-1); // this also deletes the page.
634     }
636     //add tabs
637     bool grids_present = false;
638     for (GSList const * l = nv->grids; l != NULL; l = l->next) {
639         Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
640         if (!grid->repr->attribute("id")) continue; // update_gridspage is called again when "id" is added
641         Glib::ustring name(grid->repr->attribute("id"));
642         const char *icon = NULL;
643         switch (grid->getGridType()) {
644             case GRID_RECTANGULAR:
645                 icon = INKSCAPE_ICON_GRID_XY;
646                 break;
647             case GRID_AXONOMETRIC:
648                 icon = INKSCAPE_ICON_GRID_AXONOM;
649                 break;
650             default:
651                 break;
652         }
653         _grids_notebook.append_page(*grid->newWidget(), _createPageTabLabel(name, icon));
654         grids_present = true;
655     }
656     _grids_notebook.show_all();
658     if (grids_present)
659         _grids_button_remove.set_sensitive(true);
660     else
661         _grids_button_remove.set_sensitive(false);
664 /**
665  * Build grid page of dialog.
666  */
667 void
668 DocumentProperties::build_gridspage()
670     /// \todo FIXME: gray out snapping when grid is off.
671     /// Dissenting view: you want snapping without grid.
673     SPDesktop *dt = getDesktop();
674     SPNamedView *nv = sp_desktop_namedview(dt);
675     (void)nv;
677     _grids_label_crea.set_markup(_("<b>Creation</b>"));
678     _grids_label_def.set_markup(_("<b>Defined grids</b>"));
679     _grids_hbox_crea.pack_start(_grids_combo_gridtype, true, true);
680     _grids_hbox_crea.pack_start(_grids_button_new, true, true);
682     for (gint t = 0; t <= GRID_MAXTYPENR; t++) {
683         _grids_combo_gridtype.append_text( CanvasGrid::getName( (GridType) t ) );
684     }
685     _grids_combo_gridtype.set_active_text( CanvasGrid::getName(GRID_RECTANGULAR) );
687     _grids_space.set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
689     _grids_vbox.set_spacing(4);
690     _grids_vbox.pack_start(_grids_label_crea, false, false);
691     _grids_vbox.pack_start(_grids_hbox_crea, false, false);
692     _grids_vbox.pack_start(_grids_space, false, false);
693     _grids_vbox.pack_start(_grids_label_def, false, false);
694     _grids_vbox.pack_start(_grids_notebook, false, false);
695     _grids_vbox.pack_start(_grids_button_remove, false, false);
697     update_gridspage();
702 /**
703  * Update dialog widgets from desktop. Also call updateWidget routines of the grids.
704  */
705 void
706 DocumentProperties::update()
708     if (_wr.isUpdating()) return;
710     SPDesktop *dt = getDesktop();
711     SPNamedView *nv = sp_desktop_namedview(dt);
713     _wr.setUpdating (true);
714     set_sensitive (true);
716     //-----------------------------------------------------------page page
717     _rcp_bg.setRgba32 (nv->pagecolor);
718     _rcb_canb.setActive (nv->showborder);
719     _rcb_bord.setActive (nv->borderlayer == SP_BORDER_LAYER_TOP);
720     _rcp_bord.setRgba32 (nv->bordercolor);
721     _rcb_shad.setActive (nv->showpageshadow);
723     if (nv->doc_units)
724         _rum_deflt.setUnit (nv->doc_units);
726     double const doc_w_px = sp_document_width(sp_desktop_document(dt));
727     double const doc_h_px = sp_document_height(sp_desktop_document(dt));
728     _page_sizer.setDim (doc_w_px, doc_h_px);
730     //-----------------------------------------------------------guide page
732     _rcb_sgui.setActive (nv->showguides);
733     _rcp_gui.setRgba32 (nv->guidecolor);
734     _rcp_hgui.setRgba32 (nv->guidehicolor);
736     //-----------------------------------------------------------snap page
738     _rcbsnbb.setActive (nv->snap_manager.snapprefs.getSnapModeBBox());
739     _rcbsnn.setActive (nv->snap_manager.snapprefs.getSnapModeNode());
740     _rcbsng.setActive (nv->snap_manager.snapprefs.getSnapModeGuide());
741     _rcbic.setActive (nv->snap_manager.snapprefs.getIncludeItemCenter());
742     _rcbsm.setActive (nv->snap_manager.snapprefs.getSnapSmoothNodes());
743     _rcbmp.setActive (nv->snap_manager.snapprefs.getSnapMidpoints());
744     _rcbsigg.setActive (nv->snap_manager.snapprefs.getSnapIntersectionGG());
745     _rcbsils.setActive (nv->snap_manager.snapprefs.getSnapIntersectionCS());
746     _rcbsnop.setActive(nv->snap_manager.object.getSnapToItemPath());
747     _rcbsnon.setActive(nv->snap_manager.object.getSnapToItemNode());
748     _rcbsnbbp.setActive(nv->snap_manager.object.getSnapToBBoxPath());
749     _rcbsnbbn.setActive(nv->snap_manager.object.getSnapToBBoxNode());
750     _rcbsnpb.setActive(nv->snap_manager.object.getSnapToPageBorder());
751     _rsu_sno.setValue (nv->objecttolerance);
753     _rsu_sn.setValue (nv->gridtolerance);
755     _rsu_gusn.setValue (nv->guidetolerance);
757     _rcbs.setActive (nv->snap_manager.snapprefs.getSnapEnabledGlobally());
759     //-----------------------------------------------------------grids page
761     update_gridspage();
763     //------------------------------------------------Color Management page
765 #if ENABLE_LCMS
766     populate_linked_profiles_box();
767     populate_available_profiles();
768 #endif // ENABLE_LCMS
770     _wr.setUpdating (false);
773 // TODO: copied from fill-and-stroke.cpp factor out into new ui/widget file?
774 Gtk::HBox&
775 DocumentProperties::_createPageTabLabel(const Glib::ustring& label, const char *label_image)
777     Gtk::HBox *_tab_label_box = manage(new Gtk::HBox(false, 0));
778     _tab_label_box->set_spacing(4);
779     _tab_label_box->pack_start(*Glib::wrap(sp_icon_new(Inkscape::ICON_SIZE_DECORATION,
780                                                        label_image)));
782     Gtk::Label *_tab_label = manage(new Gtk::Label(label, true));
783     _tab_label_box->pack_start(*_tab_label);
784     _tab_label_box->show_all();
786     return *_tab_label_box;
789 //--------------------------------------------------------------------
791 void
792 DocumentProperties::on_response (int id)
794     if (id == Gtk::RESPONSE_DELETE_EVENT || id == Gtk::RESPONSE_CLOSE)
795     {
796         _rcp_bg.closeWindow();
797         _rcp_bord.closeWindow();
798         _rcp_gui.closeWindow();
799         _rcp_hgui.closeWindow();
800     }
802     if (id == Gtk::RESPONSE_CLOSE)
803         hide();
806 void
807 DocumentProperties::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *document)
809     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
810     repr->addListener(&_repr_events, this);
811     Inkscape::XML::Node *root = SP_OBJECT_REPR(document->root);
812     root->addListener(&_repr_events, this);
813     update();
816 void
817 DocumentProperties::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
819     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
820     repr->addListener(&_repr_events, this);
821     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
822     root->addListener(&_repr_events, this);
823     update();
826 void
827 DocumentProperties::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
829     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
830     repr->removeListenerByData(this);
831     Inkscape::XML::Node *root = SP_OBJECT_REPR(sp_desktop_document(desktop)->root);
832     root->removeListenerByData(this);
835 static void
836 on_child_added(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
838     if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
839         dialog->update_gridspage();
842 static void
843 on_child_removed(Inkscape::XML::Node */*repr*/, Inkscape::XML::Node */*child*/, Inkscape::XML::Node */*ref*/, void *data)
845     if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
846         dialog->update_gridspage();
851 /**
852  * Called when XML node attribute changed; updates dialog widgets.
853  */
854 static void
855 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
857     if (DocumentProperties *dialog = static_cast<DocumentProperties *>(data))
858         dialog->update();
862 /*########################################################################
863 # BUTTON CLICK HANDLERS    (callbacks)
864 ########################################################################*/
866 void
867 DocumentProperties::onNewGrid()
869     SPDesktop *dt = getDesktop();
870     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(dt));
871     SPDocument *doc = sp_desktop_document(dt);
873     Glib::ustring typestring = _grids_combo_gridtype.get_active_text();
874     CanvasGrid::writeNewGridToRepr(repr, doc, CanvasGrid::getGridTypeFromName(typestring.c_str()));
876     // toggle grid showing to ON:
877     dt->showGrids(true);
881 void
882 DocumentProperties::onRemoveGrid()
884     gint pagenum = _grids_notebook.get_current_page();
885     if (pagenum == -1) // no pages
886       return;
888     SPDesktop *dt = getDesktop();
889     SPNamedView *nv = sp_desktop_namedview(dt);
890     Inkscape::CanvasGrid * found_grid = NULL;
891     int i = 0;
892     for (GSList const * l = nv->grids; l != NULL; l = l->next, i++) {  // not a very nice fix, but works.
893         Inkscape::CanvasGrid * grid = (Inkscape::CanvasGrid*) l->data;
894         if (pagenum == i) {
895             found_grid = grid;
896             break; // break out of for-loop
897         }
898     }
899     if (found_grid) {
900         // delete the grid that corresponds with the selected tab
901         // when the grid is deleted from SVG, the SPNamedview handler automatically deletes the object, so found_grid becomes an invalid pointer!
902         found_grid->repr->parent()->removeChild(found_grid->repr);
903         sp_document_done(sp_desktop_document(dt), SP_VERB_DIALOG_NAMEDVIEW, _("Remove grid"));
904     }
908 } // namespace Dialog
909 } // namespace UI
910 } // namespace Inkscape
912 /*
913   Local Variables:
914   mode:c++
915   c-file-style:"stroustrup"
916   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
917   indent-tabs-mode:nil
918   fill-column:99
919   End:
920 */
921 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :