7869a1f72da94d39fee074628b9455b54a01f02d
1 /** \file
2 *
3 *
4 * Authors:
5 * bulia byak <buliabyak@users.sf.net>
6 * Bryce W. Harrington <bryce@bryceharrington.org>
7 * Lauris Kaplinski <lauris@kaplinski.com>
8 * Jon Phillips <jon@rejon.org>
9 * Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
10 *
11 * Copyright (C) 2000 - 2005 Authors
12 *
13 * Released under GNU GPL. Read the file 'COPYING' for more information
14 */
16 #ifdef HAVE_CONFIG_H
17 # include <config.h>
18 #endif
21 #include "ui/widget/color-picker.h"
22 #include "ui/widget/registry.h"
23 #include "ui/widget/scalar-unit.h"
25 #include "helper/units.h"
26 #include "xml/repr.h"
27 #include "svg/svg-color.h"
28 #include "svg/stringstream.h"
30 #include "inkscape.h"
31 #include "document.h"
32 #include "desktop-handles.h"
33 #include "sp-namedview.h"
35 #include "registered-widget.h"
36 #include "verbs.h"
38 namespace Inkscape {
39 namespace UI {
40 namespace Widget {
42 //===================================================
44 //---------------------------------------------------
48 //====================================================
50 RegisteredCheckButton::RegisteredCheckButton()
51 : _button(0)
52 {
53 }
55 RegisteredCheckButton::~RegisteredCheckButton()
56 {
57 _toggled_connection.disconnect();
58 if (_button) delete _button;
59 }
61 void
62 RegisteredCheckButton::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right, Inkscape::XML::Node* repr_in)
63 {
64 _button = new Gtk::CheckButton;
65 _tt.set_tip (*_button, tip);
66 Gtk::Label *l = new Gtk::Label (label);
67 l->set_use_underline (true);
68 _button->add (*manage (l));
69 _button->set_alignment (right? 1.0 : 0.0, 0.5);
70 _key = key;
71 _wr = ≀
72 _toggled_connection = _button->signal_toggled().connect (sigc::mem_fun (*this, &RegisteredCheckButton::on_toggled));
74 repr = repr_in;
75 }
77 void
78 RegisteredCheckButton::setActive (bool b)
79 {
80 _button->set_active (b);
81 }
83 void
84 RegisteredCheckButton::on_toggled()
85 {
86 if (_wr->isUpdating())
87 return;
89 SPDesktop *dt = SP_ACTIVE_DESKTOP;
90 if (!dt) {
91 return;
92 }
94 SPDocument *doc = sp_desktop_document(dt);
96 if (!repr)
97 repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
99 _wr->setUpdating (true);
101 bool saved = sp_document_get_undo_sensitive (doc);
102 sp_document_set_undo_sensitive (doc, false);
103 sp_repr_set_boolean(repr, _key.c_str(), _button->get_active());
104 doc->rroot->setAttribute("sodipodi:modified", "true");
105 sp_document_set_undo_sensitive (doc, saved);
106 sp_document_done (doc, SP_VERB_NONE,
107 /* TODO: annotate */ "registered-widget.cpp:103");
109 _wr->setUpdating (false);
110 }
112 RegisteredUnitMenu::RegisteredUnitMenu()
113 : _label(0), _sel(0)
114 {
115 }
117 RegisteredUnitMenu::~RegisteredUnitMenu()
118 {
119 _changed_connection.disconnect();
120 if (_label) delete _label;
121 if (_sel) delete _sel;
122 }
124 void
125 RegisteredUnitMenu::init (const Glib::ustring& label, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in)
126 {
127 _label = new Gtk::Label (label, 1.0, 0.5);
128 _label->set_use_underline (true);
129 _sel = new UnitMenu ();
130 _label->set_mnemonic_widget (*_sel);
131 _sel->setUnitType (UNIT_TYPE_LINEAR);
132 _wr = ≀
133 _key = key;
134 _changed_connection = _sel->signal_changed().connect (sigc::mem_fun (*this, &RegisteredUnitMenu::on_changed));
136 repr = repr_in;
137 }
139 void
140 RegisteredUnitMenu::setUnit (const SPUnit* unit)
141 {
142 _sel->setUnit (sp_unit_get_abbreviation (unit));
143 }
145 void
146 RegisteredUnitMenu::on_changed()
147 {
148 if (_wr->isUpdating())
149 return;
151 SPDesktop *dt = SP_ACTIVE_DESKTOP;
152 if (!dt)
153 return;
155 Inkscape::SVGOStringStream os;
156 os << _sel->getUnitAbbr();
158 _wr->setUpdating (true);
160 SPDocument *doc = sp_desktop_document(dt);
161 bool saved = sp_document_get_undo_sensitive (doc);
162 sp_document_set_undo_sensitive (doc, false);
163 if (!repr)
164 repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
165 repr->setAttribute(_key.c_str(), os.str().c_str());
166 doc->rroot->setAttribute("sodipodi:modified", "true");
167 sp_document_set_undo_sensitive (doc, saved);
168 sp_document_done (doc, SP_VERB_NONE,
169 /* TODO: annotate */ "registered-widget.cpp:162");
171 _wr->setUpdating (false);
172 }
175 RegisteredScalarUnit::RegisteredScalarUnit()
176 : _widget(0), _um(0)
177 {
178 }
180 RegisteredScalarUnit::~RegisteredScalarUnit()
181 {
182 if (_widget) delete _widget;
183 _value_changed_connection.disconnect();
184 }
186 void
187 RegisteredScalarUnit::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr, Inkscape::XML::Node* repr_in)
188 {
189 _widget = new ScalarUnit (label, tip, UNIT_TYPE_LINEAR, "", "", rum._sel);
190 _widget->initScalar (-1e6, 1e6);
191 _widget->setUnit (rum._sel->getUnitAbbr());
192 _widget->setDigits (2);
193 _key = key;
194 _um = rum._sel;
195 _value_changed_connection = _widget->signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredScalarUnit::on_value_changed));
196 _wr = ≀
198 repr = repr_in;
199 }
201 ScalarUnit*
202 RegisteredScalarUnit::getSU()
203 {
204 return _widget;
205 }
207 void
208 RegisteredScalarUnit::setValue (double val)
209 {
210 _widget->setValue (val);
211 on_value_changed();
212 }
214 void
215 RegisteredScalarUnit::on_value_changed()
216 {
217 if (_wr->isUpdating())
218 return;
220 SPDesktop *dt = SP_ACTIVE_DESKTOP;
221 if (!dt)
222 return;
224 Inkscape::SVGOStringStream os;
225 os << _widget->getValue("");
226 if (_um)
227 os << _um->getUnitAbbr();
229 _wr->setUpdating (true);
231 SPDocument *doc = sp_desktop_document(dt);
232 bool saved = sp_document_get_undo_sensitive (doc);
233 sp_document_set_undo_sensitive (doc, false);
234 if (!repr)
235 repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
236 repr->setAttribute(_key.c_str(), os.str().c_str());
237 doc->rroot->setAttribute("sodipodi:modified", "true");
238 sp_document_set_undo_sensitive (doc, saved);
239 sp_document_done (doc, SP_VERB_NONE,
240 /* TODO: annotate */ "registered-widget.cpp:230");
242 _wr->setUpdating (false);
243 }
245 RegisteredColorPicker::RegisteredColorPicker()
246 : _label(0), _cp(0)
247 {
248 }
250 RegisteredColorPicker::~RegisteredColorPicker()
251 {
252 _changed_connection.disconnect();
253 if (_cp) delete _cp;
254 if (_label) delete _label;
255 }
257 void
258 RegisteredColorPicker::init (const Glib::ustring& label, const Glib::ustring& title, const Glib::ustring& tip, const Glib::ustring& ckey, const Glib::ustring& akey, Registry& wr, Inkscape::XML::Node* repr_in)
259 {
260 _label = new Gtk::Label (label, 1.0, 0.5);
261 _label->set_use_underline (true);
262 _cp = new ColorPicker (title,tip,0,true);
263 _label->set_mnemonic_widget (*_cp);
264 _ckey = ckey;
265 _akey = akey;
266 _wr = ≀
267 _changed_connection = _cp->connectChanged (sigc::mem_fun (*this, &RegisteredColorPicker::on_changed));
269 repr = repr_in;
270 }
272 void
273 RegisteredColorPicker::setRgba32 (guint32 rgba)
274 {
275 _cp->setRgba32 (rgba);
276 }
278 void
279 RegisteredColorPicker::closeWindow()
280 {
281 _cp->closeWindow();
282 }
284 void
285 RegisteredColorPicker::on_changed (guint32 rgba)
286 {
287 if (_wr->isUpdating() || !SP_ACTIVE_DESKTOP)
288 return;
290 _wr->setUpdating (true);
291 if (!repr)
292 repr = SP_OBJECT_REPR (sp_desktop_namedview(SP_ACTIVE_DESKTOP));
293 gchar c[32];
294 sp_svg_write_color(c, 32, rgba);
295 repr->setAttribute(_ckey.c_str(), c);
296 sp_repr_set_css_double(repr, _akey.c_str(), (rgba & 0xff) / 255.0);
297 _wr->setUpdating (false);
298 }
300 RegisteredSuffixedInteger::RegisteredSuffixedInteger()
301 : _label(0), _sb(0),
302 _adj(0.0,0.0,100.0,1.0,1.0,1.0),
303 _suffix(0)
304 {
305 }
307 RegisteredSuffixedInteger::~RegisteredSuffixedInteger()
308 {
309 _changed_connection.disconnect();
310 if (_label) delete _label;
311 if (_suffix) delete _suffix;
312 if (_sb) delete _sb;
313 }
315 void
316 RegisteredSuffixedInteger::init (const Glib::ustring& label, const Glib::ustring& suffix, const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in)
317 {
318 _key = key;
319 _label = new Gtk::Label (label);
320 _label->set_alignment (1.0, 0.5);
321 _label->set_use_underline();
322 _sb = new Gtk::SpinButton (_adj, 1.0, 0);
323 _label->set_mnemonic_widget (*_sb);
324 _suffix = new Gtk::Label (suffix);
325 _hbox.pack_start (*_sb, true, true, 0);
326 _hbox.pack_start (*_suffix, false, false, 0);
328 _changed_connection = _adj.signal_value_changed().connect (sigc::mem_fun(*this, &RegisteredSuffixedInteger::on_value_changed));
329 _wr = ≀
331 repr = repr_in;
332 }
334 void
335 RegisteredSuffixedInteger::setValue (int i)
336 {
337 _adj.set_value (i);
338 }
340 void
341 RegisteredSuffixedInteger::on_value_changed()
342 {
343 if (_wr->isUpdating() || !SP_ACTIVE_DESKTOP)
344 return;
346 _wr->setUpdating (true);
348 SPDesktop* dt = SP_ACTIVE_DESKTOP;
349 if (!repr)
350 repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
351 Inkscape::SVGOStringStream os;
352 int value = int(_adj.get_value());
353 os << value;
355 repr->setAttribute(_key.c_str(), os.str().c_str());
356 sp_document_done(sp_desktop_document(dt), SP_VERB_NONE,
357 /* TODO: annotate */ "registered-widget.cpp:341");
359 _wr->setUpdating (false);
360 }
362 RegisteredRadioButtonPair::RegisteredRadioButtonPair()
363 : _hbox(0)
364 {
365 }
367 RegisteredRadioButtonPair::~RegisteredRadioButtonPair()
368 {
369 _changed_connection.disconnect();
370 }
372 void
373 RegisteredRadioButtonPair::init (const Glib::ustring& label,
374 const Glib::ustring& label1, const Glib::ustring& label2,
375 const Glib::ustring& tip1, const Glib::ustring& tip2,
376 const Glib::ustring& key, Registry& wr, Inkscape::XML::Node* repr_in)
377 {
378 _hbox = new Gtk::HBox;
379 _hbox->add (*manage (new Gtk::Label (label)));
380 _rb1 = manage (new Gtk::RadioButton (label1, true));
381 _hbox->add (*_rb1);
382 Gtk::RadioButtonGroup group = _rb1->get_group();
383 _rb2 = manage (new Gtk::RadioButton (group, label2, true));
384 _hbox->add (*_rb2);
385 _rb2->set_active();
386 _tt.set_tip (*_rb1, tip1);
387 _tt.set_tip (*_rb2, tip2);
388 _key = key;
389 _wr = ≀
390 _changed_connection = _rb1->signal_toggled().connect (sigc::mem_fun (*this, &RegisteredRadioButtonPair::on_value_changed));
392 repr = repr_in;
393 }
395 void
396 RegisteredRadioButtonPair::setValue (bool second)
397 {
398 if (second) _rb2->set_active();
399 else _rb1->set_active();
400 }
402 void
403 RegisteredRadioButtonPair::on_value_changed()
404 {
405 if (_wr->isUpdating())
406 return;
408 SPDesktop *dt = SP_ACTIVE_DESKTOP;
409 if (!dt)
410 return;
412 _wr->setUpdating (true);
414 bool second = _rb2->get_active();
415 SPDocument *doc = sp_desktop_document(dt);
416 bool saved = sp_document_get_undo_sensitive (doc);
417 sp_document_set_undo_sensitive (doc, false);
418 if (!repr)
419 repr = SP_OBJECT_REPR (sp_desktop_namedview(dt));
420 repr->setAttribute(_key.c_str(), second ? "true" : "false");
421 doc->rroot->setAttribute("sodipodi:modified", "true");
422 sp_document_set_undo_sensitive (doc, saved);
423 sp_document_done (doc, SP_VERB_NONE,
424 /* TODO: annotate */ "registered-widget.cpp:405");
426 _wr->setUpdating (false);
427 }
429 } // namespace Dialog
430 } // namespace UI
431 } // namespace Inkscape
433 /*
434 Local Variables:
435 mode:c++
436 c-file-style:"stroustrup"
437 c-file-offsets:((innamespace . 0)(inline-open . 0))
438 indent-tabs-mode:nil
439 fill-column:99
440 End:
441 */
442 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :