Code

UI generalisation
[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< LabelledComboBoxEnum<E> >
23 {
24 public:
25     virtual ~RegisteredEnum() {
26         _changed_connection.disconnect();
27     }
29     RegisteredEnum ( const Glib::ustring& label,
30                 const Glib::ustring& tip,
31                 const Glib::ustring& key,
32                 const Util::EnumDataConverter<E>& c,
33                 Registry& wr,
34                 Inkscape::XML::Node* repr_in = NULL,
35                 SPDocument *doc_in = NULL )
36         : RegisteredWidget< LabelledComboBoxEnum<E> >(label, tip, c)
37     {
38         RegisteredWidget< LabelledComboBoxEnum<E> >::init_parent(key, wr, repr_in, doc_in);
40         _changed_connection = combobox()->signal_changed().connect (sigc::mem_fun (*this, &RegisteredEnum::on_changed));
41     }
43     void set_active_by_id (E id) {
44         combobox()->set_active_by_id(id);
45     };
47     void set_active_by_key (const Glib::ustring& key) {
48         combobox()->set_active_by_key(key);
49     }
51     inline const Util::EnumData<E>* get_active_data() {
52         combobox()->get_active_data();
53     }
55     ComboBoxEnum<E> * combobox() {
56         return LabelledComboBoxEnum<E>::getCombobox();
57     }
59     sigc::connection _changed_connection;
61 protected:
62     void on_changed() {
63         if (combobox()->setProgrammatically) {
64             combobox()->setProgrammatically = false;
65             return;
66         }
68         if (RegisteredWidget< LabelledComboBoxEnum<E> >::_wr->isUpdating())
69             return;
71         RegisteredWidget< LabelledComboBoxEnum<E> >::_wr->setUpdating (true);
73         const Util::EnumData<E>* data = combobox()->get_active_data();
74         if (data) {
75             RegisteredWidget< LabelledComboBoxEnum<E> >::write_to_xml(data->key.c_str());
76         }
78         RegisteredWidget< LabelledComboBoxEnum<E> >::_wr->setUpdating (false);
79     }
80 };
82 }
83 }
84 }
86 #endif
88 /*
89   Local Variables:
90   mode:c++
91   c-file-style:"stroustrup"
92   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
93   indent-tabs-mode:nil
94   fill-column:99
95   End:
96 */
97 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :