1 /** \file
2 * \brief
3 *
4 * Authors:
5 * Ralf Stephan <ralf@ark.in-berlin.de>
6 *
7 * Copyright (C) 2005 Authors
8 *
9 * Released under GNU GPL. Read the file 'COPYING' for more information.
10 */
12 #ifndef INKSCAPE_UI_WIDGET_REGISTERED_WIDGET__H_
13 #define INKSCAPE_UI_WIDGET_REGISTERED_WIDGET__H_
15 #include <gtkmm/box.h>
16 #include <gtkmm/adjustment.h>
17 #include <gtkmm/tooltips.h>
19 #include "xml/node.h"
20 #include "registry.h"
22 class SPUnit;
23 class SPDocument;
25 namespace Gtk {
26 class HScale;
27 class RadioButton;
28 class SpinButton;
29 class ToggleButton;
30 }
32 namespace Inkscape {
33 namespace UI {
34 namespace Widget {
36 class ColorPicker;
37 class Registry;
38 class Scalar;
39 class ScalarUnit;
40 class UnitMenu;
41 class Point;
42 class Random;
44 class RegisteredWidget {
45 public:
46 void set_undo_parameters(const unsigned int _event_type, Glib::ustring _event_description)
47 {
48 event_type = _event_type;
49 event_description = _event_description;
50 write_undo = true;
51 }
53 bool is_updating() {if (_wr) return _wr->isUpdating(); else return false;}
55 protected:
56 RegisteredWidget()
57 {
58 _wr = NULL;
59 repr = NULL;
60 doc = NULL;
61 write_undo = false;
62 }
64 void init_parent(const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in, SPDocument *doc_in)
65 {
66 _wr = ≀
67 _key = key;
68 repr = repr_in;
69 doc = doc_in;
70 if (repr && !doc) // doc cannot be NULL when repr is not NULL
71 g_warning("Initialization of registered widget using defined repr but with doc==NULL");
72 }
74 void write_to_xml(const char * svgstr);
76 Registry * _wr;
77 Glib::ustring _key;
78 Inkscape::XML::Node * repr;
79 SPDocument * doc;
80 unsigned int event_type;
81 Glib::ustring event_description;
82 bool write_undo;
83 };
85 //#######################################################
87 class RegisteredCheckButton : public RegisteredWidget {
88 public:
89 RegisteredCheckButton();
90 ~RegisteredCheckButton();
91 void init (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);
92 void setActive (bool);
94 Gtk::ToggleButton *_button;
95 std::list<Gtk::ToggleButton*> _slavebuttons;
97 // a slave button is only sensitive when the master button is active
98 // i.e. a slave button is greyed-out when the master button is not checked
100 void setSlaveButton(std::list<Gtk::ToggleButton*> btns) {
101 _slavebuttons = btns;
102 }
104 bool setProgrammatically; // true if the value was set by setValue, not changed by the user;
105 // if a callback checks it, it must reset it back to false
108 protected:
109 Gtk::Tooltips _tt;
110 sigc::connection _toggled_connection;
111 void on_toggled();
112 };
114 class RegisteredUnitMenu : public RegisteredWidget {
115 public:
116 RegisteredUnitMenu();
117 ~RegisteredUnitMenu();
118 void init ( const Glib::ustring& label,
119 const Glib::ustring& key,
120 Registry& wr,
121 Inkscape::XML::Node* repr_in,
122 SPDocument *doc_in);
123 inline void init ( const Glib::ustring& label,
124 const Glib::ustring& key,
125 Registry& wr)
126 { init(label, key, wr, NULL, NULL); };
128 void setUnit (const SPUnit*);
129 Gtk::Label *_label;
130 UnitMenu *_sel;
131 sigc::connection _changed_connection;
133 protected:
134 void on_changed();
135 };
137 class RegisteredScalarUnit : public RegisteredWidget {
138 public:
139 RegisteredScalarUnit();
140 ~RegisteredScalarUnit();
141 void init (const Glib::ustring& label,
142 const Glib::ustring& tip,
143 const Glib::ustring& key,
144 const RegisteredUnitMenu &rum,
145 Registry& wr,
146 Inkscape::XML::Node* repr_in,
147 SPDocument *doc_in);
148 inline void init ( const Glib::ustring& label,
149 const Glib::ustring& tip,
150 const Glib::ustring& key,
151 const RegisteredUnitMenu &rum,
152 Registry& wr)
153 { init(label, tip, key, rum, wr, NULL, NULL); };
155 ScalarUnit* getSU();
156 void setValue (double);
158 protected:
159 ScalarUnit *_widget;
160 sigc::connection _value_changed_connection;
161 UnitMenu *_um;
162 void on_value_changed();
163 };
165 class RegisteredScalar : public RegisteredWidget {
166 public:
167 RegisteredScalar();
168 ~RegisteredScalar();
169 void init (const Glib::ustring& label,
170 const Glib::ustring& tip,
171 const Glib::ustring& key,
172 Registry& wr,
173 Inkscape::XML::Node* repr_in,
174 SPDocument *doc_in);
175 inline void init ( const Glib::ustring& label,
176 const Glib::ustring& tip,
177 const Glib::ustring& key,
178 Registry& wr)
179 { init(label, tip, key, wr, NULL, NULL); };
181 Scalar* getS();
182 void setValue (double);
184 protected:
185 Scalar *_widget;
186 sigc::connection _value_changed_connection;
187 void on_value_changed();
188 };
190 class RegisteredColorPicker : public RegisteredWidget {
191 public:
192 RegisteredColorPicker();
193 ~RegisteredColorPicker();
194 void init (const Glib::ustring& label,
195 const Glib::ustring& title,
196 const Glib::ustring& tip,
197 const Glib::ustring& ckey,
198 const Glib::ustring& akey,
199 Registry& wr,
200 Inkscape::XML::Node* repr_in,
201 SPDocument *doc_in);
202 inline void init ( const Glib::ustring& label,
203 const Glib::ustring& title,
204 const Glib::ustring& tip,
205 const Glib::ustring& ckey,
206 const Glib::ustring& akey,
207 Registry& wr)
208 { init(label, title, tip, ckey, akey, wr, NULL, NULL); };
210 void setRgba32 (guint32);
211 void closeWindow();
213 Gtk::Label *_label;
214 ColorPicker *_cp;
216 protected:
217 Glib::ustring _ckey, _akey;
218 void on_changed (guint32);
219 sigc::connection _changed_connection;
220 };
222 class RegisteredSuffixedInteger : public RegisteredWidget {
223 public:
224 RegisteredSuffixedInteger();
225 ~RegisteredSuffixedInteger();
226 void init (const Glib::ustring& label1,
227 const Glib::ustring& label2,
228 const Glib::ustring& key,
229 Registry& wr,
230 Inkscape::XML::Node* repr_in,
231 SPDocument *doc_in);
232 inline void init ( const Glib::ustring& label1,
233 const Glib::ustring& label2,
234 const Glib::ustring& key,
235 Registry& wr)
236 { init(label1, label2, key, wr, NULL, NULL); };
238 void setValue (int);
239 Gtk::Label *_label;
240 Gtk::HBox _hbox;
241 bool setProgrammatically; // true if the value was set by setValue, not changed by the user;
242 // if a callback checks it, it must reset it back to false
244 protected:
245 Gtk::SpinButton *_sb;
246 Gtk::Adjustment _adj;
247 Gtk::Label *_suffix;
248 sigc::connection _changed_connection;
249 void on_value_changed();
250 };
252 class RegisteredRadioButtonPair : public RegisteredWidget {
253 public:
254 RegisteredRadioButtonPair();
255 ~RegisteredRadioButtonPair();
256 void init (const Glib::ustring& label,
257 const Glib::ustring& label1,
258 const Glib::ustring& label2,
259 const Glib::ustring& tip1,
260 const Glib::ustring& tip2,
261 const Glib::ustring& key,
262 Registry& wr,
263 Inkscape::XML::Node* repr_in,
264 SPDocument *doc_in);
265 inline void init ( const Glib::ustring& label,
266 const Glib::ustring& label1,
267 const Glib::ustring& label2,
268 const Glib::ustring& tip1,
269 const Glib::ustring& tip2,
270 const Glib::ustring& key,
271 Registry& wr)
272 { init(label, label1, label2, tip1, tip2, key, wr, NULL, NULL); };
274 void setValue (bool second);
275 Gtk::HBox *_hbox;
277 bool setProgrammatically; // true if the value was set by setValue, not changed by the user;
278 // if a callback checks it, it must reset it back to false
279 protected:
280 Gtk::RadioButton *_rb1, *_rb2;
281 Gtk::Tooltips _tt;
282 sigc::connection _changed_connection;
283 void on_value_changed();
284 };
286 class RegisteredPoint : public RegisteredWidget {
287 public:
288 RegisteredPoint();
289 ~RegisteredPoint();
290 void init (const Glib::ustring& label,
291 const Glib::ustring& tip,
292 const Glib::ustring& key,
293 Registry& wr,
294 Inkscape::XML::Node* repr_in,
295 SPDocument *doc_in);
296 inline void init ( const Glib::ustring& label,
297 const Glib::ustring& tip,
298 const Glib::ustring& key,
299 Registry& wr)
300 { init(label, tip, key, wr, NULL, NULL); };
302 Point* getPoint();
303 void setValue (double xval, double yval);
305 protected:
306 Point *_widget;
307 sigc::connection _value_x_changed_connection;
308 sigc::connection _value_y_changed_connection;
309 void on_value_changed();
310 };
312 class RegisteredRandom : public RegisteredWidget {
313 public:
314 RegisteredRandom();
315 ~RegisteredRandom();
316 void init (const Glib::ustring& label,
317 const Glib::ustring& tip,
318 const Glib::ustring& key,
319 Registry& wr,
320 Inkscape::XML::Node* repr_in,
321 SPDocument *doc_in);
322 inline void init ( const Glib::ustring& label,
323 const Glib::ustring& tip,
324 const Glib::ustring& key,
325 Registry& wr)
326 { init(label, tip, key, wr, NULL, NULL); };
328 Random* getR();
329 void setValue (double val, long startseed);
331 protected:
332 Random *_widget;
333 sigc::connection _value_changed_connection;
334 sigc::connection _reseeded_connection;
335 void on_value_changed();
336 };
338 } // namespace Widget
339 } // namespace UI
340 } // namespace Inkscape
342 #endif // INKSCAPE_UI_WIDGET_REGISTERED_WIDGET__H_
344 /*
345 Local Variables:
346 mode:c++
347 c-file-style:"stroustrup"
348 c-file-offsets:((innamespace . 0)(inline-open . 0))
349 indent-tabs-mode:nil
350 fill-column:99
351 End:
352 */
353 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :