Code

Mnemonics in "Input devices", and LPE dialogs (Bug 170765)
[inkscape.git] / src / ui / dialog / document-metadata.cpp
1 /** @file
2  * @brief Document metadata 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  *
11  * Copyright (C) 2000 - 2006 Authors
12  *
13  * Released under GNU GPL.  Read the file 'COPYING' for more information
14  */
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
20 #include "desktop.h"
21 #include "desktop-handles.h"
22 #include "inkscape.h"
23 #include "rdf.h"
24 #include "sp-namedview.h"
25 #include "ui/widget/entity-entry.h"
26 #include "verbs.h"
27 #include "xml/node-event-vector.h"
29 #include "document-metadata.h"
31 //using std::pair;
33 namespace Inkscape {
34 namespace UI {
35 namespace Dialog {
37 #define SPACE_SIZE_X 15
38 #define SPACE_SIZE_Y 15
40 //===================================================
42 //---------------------------------------------------
44 static void on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer);
46 static Inkscape::XML::NodeEventVector const _repr_events = {
47     NULL, /* child_added */
48     NULL, /* child_removed */
49     on_repr_attr_changed,
50     NULL, /* content_changed */
51     NULL  /* order_changed */
52 };
55 DocumentMetadata &
56 DocumentMetadata::getInstance()
57 {
58     DocumentMetadata &instance = *new DocumentMetadata();
59     instance.init();
60     return instance;
61 }
64 DocumentMetadata::DocumentMetadata()
65     : UI::Widget::Panel ("", "/dialogs/documentmetadata", SP_VERB_DIALOG_METADATA),
66       _page_metadata1(1, 1), _page_metadata2(1, 1)
67 {
68     hide();
69     _tt.enable();
70     _getContents()->set_spacing (4);
71     _getContents()->pack_start(_notebook, true, true);
73     _notebook.append_page(_page_metadata1, _("Metadata"));
74     _notebook.append_page(_page_metadata2, _("License"));
76     signalDocumentReplaced().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDocumentReplaced));
77     signalActivateDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleActivateDesktop));
78     signalDeactiveDesktop().connect(sigc::mem_fun(*this, &DocumentMetadata::_handleDeactivateDesktop));
80     build_metadata();
81 }
83 void
84 DocumentMetadata::init()
85 {
86     update();
88     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
89     repr->addListener (&_repr_events, this);
91     show_all_children();
92 }
94 DocumentMetadata::~DocumentMetadata()
95 {
96     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(getDesktop()));
97     repr->removeListenerByData (this);
99     for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); it++)
100         delete (*it);
103 //========================================================================
105 /**
106  * Helper function that attachs widgets in a 3xn table. The widgets come in an
107  * array that has two entries per table row. The two entries code for four
108  * possible cases: (0,0) means insert space in first column; (0, non-0) means
109  * widget in columns 2-3; (non-0, 0) means label in columns 1-3; and
110  * (non-0, non-0) means two widgets in columns 2 and 3.
111 **/
112 inline void
113 attach_all (Gtk::Table &table, const Gtk::Widget *arr[], unsigned size, int start = 0)
115     for (unsigned i=0, r=start; i<size/sizeof(Gtk::Widget*); i+=2)
116     {
117         if (arr[i] && arr[i+1])
118         {
119             table.attach (const_cast<Gtk::Widget&>(*arr[i]),   1, 2, r, r+1,
120                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
121             table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 2, 3, r, r+1,
122                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
123         }
124         else
125         {
126             if (arr[i+1])
127                 table.attach (const_cast<Gtk::Widget&>(*arr[i+1]), 1, 3, r, r+1,
128                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
129             else if (arr[i])
130             {
131                 Gtk::Label& label = static_cast<Gtk::Label&> (const_cast<Gtk::Widget&>(*arr[i]));
132                 label.set_alignment (0.0);
133                 table.attach (label, 0, 3, r, r+1,
134                       Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
135             }
136             else
137             {
138                 Gtk::HBox *space = manage (new Gtk::HBox);
139                 space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
140                 table.attach (*space, 0, 1, r, r+1,
141                       (Gtk::AttachOptions)0, (Gtk::AttachOptions)0,0,0);
142             }
143         }
144         ++r;
145     }
148 void
149 DocumentMetadata::build_metadata()
151     using Inkscape::UI::Widget::EntityEntry;
153     _page_metadata1.show();
155     Gtk::Label *label = manage (new Gtk::Label);
156     label->set_markup (_("<b>Dublin Core Entities</b>"));
157     label->set_alignment (0.0);
158     _page_metadata1.table().attach (*label, 0,3,0,1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
159      /* add generic metadata entry areas */
160     struct rdf_work_entity_t * entity;
161     int row = 1;
162     for (entity = rdf_work_entities; entity && entity->name; entity++, row++) {
163         if ( entity->editable == RDF_EDIT_GENERIC ) {
164             EntityEntry *w = EntityEntry::create (entity, _tt, _wr);
165             _rdflist.push_back (w);
166             Gtk::HBox *space = manage (new Gtk::HBox);
167             space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
168             _page_metadata1.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
169             _page_metadata1.table().attach (w->_label, 1,2, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
170             _page_metadata1.table().attach (*w->_packable, 2,3, row, row+1, Gtk::FILL|Gtk::EXPAND, (Gtk::AttachOptions)0,0,0);
171         }
172     }
174     _page_metadata2.show();
176     row = 0;
177     Gtk::Label *llabel = manage (new Gtk::Label);
178     llabel->set_markup (_("<b>License</b>"));
179     llabel->set_alignment (0.0);
180     _page_metadata2.table().attach (*llabel, 0,3, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
181     /* add license selector pull-down and URI */
182     ++row;
183     _licensor.init (_tt, _wr);
184     Gtk::HBox *space = manage (new Gtk::HBox);
185     space->set_size_request (SPACE_SIZE_X, SPACE_SIZE_Y);
186     _page_metadata2.table().attach (*space, 0,1, row, row+1, Gtk::FILL, (Gtk::AttachOptions)0,0,0);
187     _page_metadata2.table().attach (_licensor, 1,3, row, row+1, Gtk::EXPAND|Gtk::FILL, (Gtk::AttachOptions)0,0,0);
190 /**
191  * Update dialog widgets from desktop.
192  */
193 void
194 DocumentMetadata::update()
196     if (_wr.isUpdating()) return;
198     _wr.setUpdating (true);
199     set_sensitive (true);
201     //-----------------------------------------------------------meta pages
202     /* update the RDF entities */
203     for (RDElist::iterator it = _rdflist.begin(); it != _rdflist.end(); it++)
204         (*it)->update (SP_ACTIVE_DOCUMENT);
206     _licensor.update (SP_ACTIVE_DOCUMENT);
208     _wr.setUpdating (false);
211 void 
212 DocumentMetadata::_handleDocumentReplaced(SPDesktop* desktop, SPDocument *)
214     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
215     repr->addListener (&_repr_events, this);
216     update();
219 void 
220 DocumentMetadata::_handleActivateDesktop(Inkscape::Application *, SPDesktop *desktop)
222     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
223     repr->addListener(&_repr_events, this);
224     update();
227 void
228 DocumentMetadata::_handleDeactivateDesktop(Inkscape::Application *, SPDesktop *desktop)
230     Inkscape::XML::Node *repr = SP_OBJECT_REPR(sp_desktop_namedview(desktop));
231     repr->removeListenerByData(this);
234 //--------------------------------------------------------------------
236 /**
237  * Called when XML node attribute changed; updates dialog widgets.
238  */
239 static void
240 on_repr_attr_changed (Inkscape::XML::Node *, gchar const *, gchar const *, gchar const *, bool, gpointer data)
242     if (DocumentMetadata *dialog = static_cast<DocumentMetadata *>(data))
243         dialog->update();
246 } // namespace Dialog
247 } // namespace UI
248 } // namespace Inkscape
250 /*
251   Local Variables:
252   mode:c++
253   c-file-style:"stroustrup"
254   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
255   indent-tabs-mode:nil
256   fill-column:99
257   End:
258 */
259 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :