1 /** \file
2 * \brief
3 *
4 * Authors:
5 * Ralf Stephan <ralf@ark.in-berlin.de>
6 * Johan Engelen <j.b.c.engelen@utwente.nl>
7 *
8 * Copyright (C) 2005-2008 Authors
9 *
10 * Released under GNU GPL. Read the file 'COPYING' for more information.
11 */
13 #ifndef INKSCAPE_UI_WIDGET_REGISTERED_WIDGET__H_
14 #define INKSCAPE_UI_WIDGET_REGISTERED_WIDGET__H_
16 #include <gtkmm/box.h>
17 #include <gtkmm/adjustment.h>
18 #include <gtkmm/tooltips.h>
19 #include <gtkmm/togglebutton.h>
21 #include "xml/node.h"
22 #include "registry.h"
24 #include "ui/widget/point.h"
25 #include "ui/widget/random.h"
27 class SPUnit;
28 class SPDocument;
30 namespace Gtk {
31 class HScale;
32 class RadioButton;
33 class SpinButton;
34 }
36 namespace Inkscape {
37 namespace UI {
38 namespace Widget {
40 class ColorPicker;
41 class Registry;
42 class Scalar;
43 class ScalarUnit;
44 class UnitMenu;
46 template <class W>
47 class RegisteredWidget : public W {
48 public:
49 void set_undo_parameters(const unsigned int _event_type, Glib::ustring _event_description)
50 {
51 event_type = _event_type;
52 event_description = _event_description;
53 write_undo = true;
54 }
56 bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;}
58 // provide automatic 'upcast' for ease of use. (do it 'dynamic_cast' instead of 'static' because who knows what W is)
59 operator const Gtk::Widget () { return dynamic_cast<Gtk::Widget*>(this); }
61 protected:
62 RegisteredWidget() : W() { construct(); }
63 template< typename A >
64 explicit RegisteredWidget( A& a ): W( a ) { construct(); }
65 template< typename A, typename B >
66 RegisteredWidget( A& a, B& b ): W( a, b ) { construct(); }
67 template< typename A, typename B, typename C >
68 RegisteredWidget( A& a, B& b, C& c ): W( a, b, c ) { construct(); }
70 virtual ~RegisteredWidget() {};
72 void init_parent(const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
73 {
74 _wr = ≀
75 _key = key;
76 repr = repr_in;
77 doc = doc_in;
78 if (repr && !doc) // doc cannot be NULL when repr is not NULL
79 g_warning("Initialization of registered widget using defined repr but with doc==NULL");
80 }
82 void write_to_xml(const char * svgstr);
84 Registry * _wr;
85 Glib::ustring _key;
86 Inkscape::XML::Node * repr;
87 SPDocument * doc;
88 unsigned int event_type;
89 Glib::ustring event_description;
90 bool write_undo;
92 private:
93 void construct() {
94 _wr = NULL;
95 repr = NULL;
96 doc = NULL;
97 write_undo = false;
98 }
99 };
101 class RegisteredWdg {
102 public:
103 void set_undo_parameters(const unsigned int _event_type, Glib::ustring _event_description)
104 {
105 event_type = _event_type;
106 event_description = _event_description;
107 write_undo = true;
108 }
110 bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;}
112 protected:
113 RegisteredWdg()
114 {
115 _wr = NULL;
116 repr = NULL;
117 doc = NULL;
118 write_undo = false;
119 }
121 void init_parent(const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
122 {
123 _wr = ≀
124 _key = key;
125 repr = repr_in;
126 doc = doc_in;
127 if (repr && !doc) // doc cannot be NULL when repr is not NULL
128 g_warning("Initialization of registered widget using defined repr but with doc==NULL");
129 }
131 void write_to_xml(const char * svgstr);
133 Registry * _wr;
134 Glib::ustring _key;
135 Inkscape::XML::Node * repr;
136 SPDocument * doc;
137 unsigned int event_type;
138 Glib::ustring event_description;
139 bool write_undo;
140 };
142 //#######################################################
144 class RegisteredCheckButton : public RegisteredWidget<Gtk::CheckButton> {
145 public:
146 virtual ~RegisteredCheckButton();
147 RegisteredCheckButton (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right=true, Inkscape::XML::Node* repr_in=NULL, SPDocument *doc_in=NULL);
149 void setActive (bool);
151 std::list<Gtk::ToggleButton*> _slavebuttons;
153 // a slave button is only sensitive when the master button is active
154 // i.e. a slave button is greyed-out when the master button is not checked
156 void setSlaveButton(std::list<Gtk::ToggleButton*> btns) {
157 _slavebuttons = btns;
158 }
160 bool setProgrammatically; // true if the value was set by setActive, not changed by the user;
161 // if a callback checks it, it must reset it back to false
164 protected:
165 Gtk::Tooltips _tt;
166 sigc::connection _toggled_connection;
167 void on_toggled();
168 };
170 class RegisteredUnitMenu : public RegisteredWdg {
171 public:
172 RegisteredUnitMenu();
173 ~RegisteredUnitMenu();
174 void init ( const Glib::ustring& label,
175 const Glib::ustring& key,
176 Registry& wr,
177 Inkscape::XML::Node* repr_in,
178 SPDocument *doc_in);
179 inline void init ( const Glib::ustring& label,
180 const Glib::ustring& key,
181 Registry& wr)
182 { init(label, key, wr, NULL, NULL); };
184 void setUnit (const SPUnit*);
185 Gtk::Label *_label;
186 UnitMenu *_sel;
187 sigc::connection _changed_connection;
189 protected:
190 void on_changed();
191 };
193 class RegisteredScalarUnit : public RegisteredWdg {
194 public:
195 RegisteredScalarUnit();
196 ~RegisteredScalarUnit();
197 void init (const Glib::ustring& label,
198 const Glib::ustring& tip,
199 const Glib::ustring& key,
200 const RegisteredUnitMenu &rum,
201 Registry& wr,
202 Inkscape::XML::Node* repr_in,
203 SPDocument *doc_in);
204 inline void init ( const Glib::ustring& label,
205 const Glib::ustring& tip,
206 const Glib::ustring& key,
207 const RegisteredUnitMenu &rum,
208 Registry& wr)
209 { init(label, tip, key, rum, wr, NULL, NULL); };
211 ScalarUnit* getSU();
212 void setValue (double);
214 protected:
215 ScalarUnit *_widget;
216 sigc::connection _value_changed_connection;
217 UnitMenu *_um;
218 void on_value_changed();
219 };
221 class RegisteredScalar : public RegisteredWidget<Scalar> {
222 public:
223 virtual ~RegisteredScalar();
224 RegisteredScalar (const Glib::ustring& label,
225 const Glib::ustring& tip,
226 const Glib::ustring& key,
227 Registry& wr,
228 Inkscape::XML::Node* repr_in = NULL,
229 SPDocument *doc_in = NULL );
231 protected:
232 sigc::connection _value_changed_connection;
233 void on_value_changed();
234 };
236 class RegisteredColorPicker : public RegisteredWdg {
237 public:
238 RegisteredColorPicker();
239 ~RegisteredColorPicker();
240 void init (const Glib::ustring& label,
241 const Glib::ustring& title,
242 const Glib::ustring& tip,
243 const Glib::ustring& ckey,
244 const Glib::ustring& akey,
245 Registry& wr,
246 Inkscape::XML::Node* repr_in,
247 SPDocument *doc_in);
248 inline void init ( const Glib::ustring& label,
249 const Glib::ustring& title,
250 const Glib::ustring& tip,
251 const Glib::ustring& ckey,
252 const Glib::ustring& akey,
253 Registry& wr)
254 { init(label, title, tip, ckey, akey, wr, NULL, NULL); };
256 void setRgba32 (guint32);
257 void closeWindow();
259 Gtk::Label *_label;
260 ColorPicker *_cp;
262 protected:
263 Glib::ustring _ckey, _akey;
264 void on_changed (guint32);
265 sigc::connection _changed_connection;
266 };
268 class RegisteredSuffixedInteger : public RegisteredWdg {
269 public:
270 RegisteredSuffixedInteger();
271 ~RegisteredSuffixedInteger();
272 void init (const Glib::ustring& label1,
273 const Glib::ustring& label2,
274 const Glib::ustring& key,
275 Registry& wr,
276 Inkscape::XML::Node* repr_in,
277 SPDocument *doc_in);
278 inline void init ( const Glib::ustring& label1,
279 const Glib::ustring& label2,
280 const Glib::ustring& key,
281 Registry& wr)
282 { init(label1, label2, key, wr, NULL, NULL); };
284 void setValue (int);
285 Gtk::Label *_label;
286 Gtk::HBox _hbox;
287 bool setProgrammatically; // true if the value was set by setValue, not changed by the user;
288 // if a callback checks it, it must reset it back to false
290 protected:
291 Gtk::SpinButton *_sb;
292 Gtk::Adjustment _adj;
293 Gtk::Label *_suffix;
294 sigc::connection _changed_connection;
295 void on_value_changed();
296 };
298 class RegisteredRadioButtonPair : public RegisteredWdg {
299 public:
300 RegisteredRadioButtonPair();
301 ~RegisteredRadioButtonPair();
302 void init (const Glib::ustring& label,
303 const Glib::ustring& label1,
304 const Glib::ustring& label2,
305 const Glib::ustring& tip1,
306 const Glib::ustring& tip2,
307 const Glib::ustring& key,
308 Registry& wr,
309 Inkscape::XML::Node* repr_in,
310 SPDocument *doc_in);
311 inline void init ( const Glib::ustring& label,
312 const Glib::ustring& label1,
313 const Glib::ustring& label2,
314 const Glib::ustring& tip1,
315 const Glib::ustring& tip2,
316 const Glib::ustring& key,
317 Registry& wr)
318 { init(label, label1, label2, tip1, tip2, key, wr, NULL, NULL); };
320 void setValue (bool second);
321 Gtk::HBox *_hbox;
323 bool setProgrammatically; // true if the value was set by setValue, not changed by the user;
324 // if a callback checks it, it must reset it back to false
325 protected:
326 Gtk::RadioButton *_rb1, *_rb2;
327 Gtk::Tooltips _tt;
328 sigc::connection _changed_connection;
329 void on_value_changed();
330 };
332 class RegisteredPoint : public RegisteredWidget<Point> {
333 public:
334 virtual ~RegisteredPoint();
335 RegisteredPoint ( const Glib::ustring& label,
336 const Glib::ustring& tip,
337 const Glib::ustring& key,
338 Registry& wr,
339 Inkscape::XML::Node* repr_in = NULL,
340 SPDocument *doc_in = NULL );
342 protected:
343 sigc::connection _value_x_changed_connection;
344 sigc::connection _value_y_changed_connection;
345 void on_value_changed();
346 };
349 class RegisteredRandom : public RegisteredWidget<Random> {
350 public:
351 virtual ~RegisteredRandom();
352 RegisteredRandom ( const Glib::ustring& label,
353 const Glib::ustring& tip,
354 const Glib::ustring& key,
355 Registry& wr,
356 Inkscape::XML::Node* repr_in = NULL,
357 SPDocument *doc_in = NULL);
359 void setValue (double val, long startseed);
361 protected:
362 sigc::connection _value_changed_connection;
363 sigc::connection _reseeded_connection;
364 void on_value_changed();
365 };
367 } // namespace Widget
368 } // namespace UI
369 } // namespace Inkscape
371 #endif // INKSCAPE_UI_WIDGET_REGISTERED_WIDGET__H_
373 /*
374 Local Variables:
375 mode:c++
376 c-file-style:"stroustrup"
377 c-file-offsets:((innamespace . 0)(inline-open . 0))
378 indent-tabs-mode:nil
379 fill-column:99
380 End:
381 */
382 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :