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 ComboBoxEnum<E> * cb = combobox();
59 if (cb)
60 cb->set_active_by_id(id);
61 };
63 void set_active_by_key (const Glib::ustring& key) {
64 ComboBoxEnum<E> * cb = combobox();
65 if (cb)
66 cb->set_active_by_key(key);
67 }
69 inline const Util::EnumData<E>* get_active_data() {
70 ComboBoxEnum<E> * cb = combobox();
71 if (cb)
72 return cb->get_active_data();
73 else
74 return NULL;
75 }
77 ComboBoxEnum<E> * combobox() {
78 if (labelled) {
79 return labelled->getCombobox();
80 } else {
81 return NULL;
82 }
83 }
85 LabelledComboBoxEnum<E> * labelled;
86 sigc::connection _changed_connection;
88 protected:
89 void on_changed() {
90 if (combobox()->setProgrammatically) {
91 combobox()->setProgrammatically = false;
92 return;
93 }
95 if (_wr->isUpdating())
96 return;
97 _wr->setUpdating (true);
99 const Util::EnumData<E>* data = combobox()->get_active_data();
100 if (data) {
101 write_to_xml(data->key.c_str());
102 }
104 _wr->setUpdating (false);
105 }
106 };
108 }
109 }
110 }
112 #endif
114 /*
115 Local Variables:
116 mode:c++
117 c-file-style:"stroustrup"
118 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
119 indent-tabs-mode:nil
120 fill-column:99
121 End:
122 */
123 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :