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