Code

6dfa48b7af18adf1485ca29e0796a07319b9cf93
[inkscape.git] / src / ui / widget / registered-enums.h
1 /**
2  * \brief Simplified management of enumerations in the UI as combobox.
3  *
4  * Authors:
5  *   Johan Engelen <j.b.c.engelen@ewi.utwente.nl>
6  *
7  * Copyright (C) 2007 Authors
8  *
9  * Released under GNU GPL.  Read the file 'COPYING' for more information.
10  */
12 #ifndef INKSCAPE_UI_WIDGET_REGISTERED_ENUMS_H
13 #define INKSCAPE_UI_WIDGET_REGISTERED_ENUMS_H
15 #include "ui/widget/combo-enums.h"
16 #include "ui/widget/registered-widget.h"
18 namespace Inkscape {
19 namespace UI {
20 namespace Widget {
22 template<typename E> class RegisteredEnum : public RegisteredWidget
23 {
24 public:
25     RegisteredEnum() {
26         labelled = NULL;
27     }
29     ~RegisteredEnum() {
30         _changed_connection.disconnect();
31         if (labelled)
32             delete labelled;
33     }
35     void init ( const Glib::ustring& label,
36                 const Glib::ustring& tip,
37                 const Glib::ustring& key,
38                 const Util::EnumDataConverter<E>& c,
39                 Registry& wr,
40                 Inkscape::XML::Node* repr_in,
41                 SPDocument *doc_in)
42     {
43         init_parent(key, wr, repr_in, doc_in);
45         labelled = new LabelledComboBoxEnum<E> (label, tip, c);
47         _changed_connection = combobox()->signal_changed().connect (sigc::mem_fun (*this, &RegisteredEnum::on_changed));
48     }
50     inline void init ( const Glib::ustring& label,
51                        const Glib::ustring& key,
52                        Registry& wr)
53     {
54         init(label, key, wr, NULL, NULL);
55     }
57     void set_active_by_id (E id) {
58         combobox()->set_active_by_id(id);
59     };
61     void set_active_by_key (const Glib::ustring& key) {
62         combobox()->set_active_by_key(key);
63     }
65     inline const Util::EnumData<E>* get_active_data() {
66         return combobox()->get_active_data();
67     }
69     ComboBoxEnum<E> * combobox() {
70         if (labelled) {
71             return labelled->getCombobox();
72         } else {
73             return NULL;
74         }
75     }
77     LabelledComboBoxEnum<E> * labelled;
78     sigc::connection _changed_connection;
80 protected:
81     void on_changed() {
82         if (combobox()->setProgrammatically) {
83             combobox()->setProgrammatically = false;
84             return;
85         }
87         if (_wr->isUpdating())
88             return;
89         _wr->setUpdating (true);
91         const Util::EnumData<E>* data = combobox()->get_active_data();
92         if (data) {
93             write_to_xml(data->key.c_str());
94         }
96         _wr->setUpdating (false);
97     }
98 };
104 #endif
106 /*
107   Local Variables:
108   mode:c++
109   c-file-style:"stroustrup"
110   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
111   indent-tabs-mode:nil
112   fill-column:99
113   End:
114 */
115 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :