918742e751f4e2d953e103cce70d28db93576c56
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.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"
37 namespace Inkscape {
38 namespace UI {
39 namespace Widget {
41 //===================================================
43 //---------------------------------------------------
47 //====================================================
49 RegisteredCheckButton::RegisteredCheckButton()
50 : _button(0)
51 {
52 }
54 RegisteredCheckButton::~RegisteredCheckButton()
55 {
56 _toggled_connection.disconnect();
57 if (_button) delete _button;
58 }
60 void
61 RegisteredCheckButton::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, Registry& wr, bool right)
62 {
63 _button = new Gtk::CheckButton;
64 _tt.set_tip (*_button, tip);
65 _button->add (*manage (new Gtk::Label (label)));
66 _button->set_alignment (right? 1.0 : 0.0, 0.5);
67 _key = key;
68 _wr = ≀
69 _toggled_connection = _button->signal_toggled().connect (sigc::mem_fun (*this, &RegisteredCheckButton::on_toggled));
70 }
72 void
73 RegisteredCheckButton::setActive (bool b)
74 {
75 _button->set_active (b);
76 }
78 void
79 RegisteredCheckButton::on_toggled()
80 {
81 if (_wr->isUpdating())
82 return;
84 SPDesktop *dt = SP_ACTIVE_DESKTOP;
85 if (!dt) {
86 return;
87 }
89 SPDocument *doc = SP_DT_DOCUMENT(dt);
91 Inkscape::XML::Node *repr = SP_OBJECT_REPR (SP_DT_NAMEDVIEW(dt));
92 _wr->setUpdating (true);
94 gboolean saved = sp_document_get_undo_sensitive (doc);
95 sp_document_set_undo_sensitive (doc, FALSE);
96 sp_repr_set_boolean(repr, _key.c_str(), _button->get_active());
97 doc->rroot->setAttribute("sodipodi:modified", "true");
98 sp_document_set_undo_sensitive (doc, saved);
99 sp_document_done (doc);
101 _wr->setUpdating (false);
102 }
104 RegisteredUnitMenu::RegisteredUnitMenu()
105 : _label(0), _sel(0)
106 {
107 }
109 RegisteredUnitMenu::~RegisteredUnitMenu()
110 {
111 _changed_connection.disconnect();
112 if (_label) delete _label;
113 if (_sel) delete _sel;
114 }
116 void
117 RegisteredUnitMenu::init (const Glib::ustring& label, const Glib::ustring& key, Registry& wr)
118 {
119 _label = new Gtk::Label (label, 1.0, 0.5);
120 _sel = new UnitMenu ();
121 _sel->setUnitType (UNIT_TYPE_LINEAR);
122 _wr = ≀
123 _key = key;
124 _changed_connection = _sel->signal_changed().connect (sigc::mem_fun (*this, &RegisteredUnitMenu::on_changed));
125 }
127 void
128 RegisteredUnitMenu::setUnit (const SPUnit* unit)
129 {
130 _sel->setUnit (sp_unit_get_abbreviation (unit));
131 }
133 void
134 RegisteredUnitMenu::on_changed()
135 {
136 if (_wr->isUpdating())
137 return;
139 SPDesktop *dt = SP_ACTIVE_DESKTOP;
140 if (!dt)
141 return;
143 Inkscape::SVGOStringStream os;
144 os << _sel->getUnitAbbr();
146 _wr->setUpdating (true);
148 SPDocument *doc = SP_DT_DOCUMENT(dt);
149 gboolean saved = sp_document_get_undo_sensitive (doc);
150 sp_document_set_undo_sensitive (doc, FALSE);
151 Inkscape::XML::Node *repr = SP_OBJECT_REPR (SP_DT_NAMEDVIEW(dt));
152 repr->setAttribute(_key.c_str(), os.str().c_str());
153 doc->rroot->setAttribute("sodipodi:modified", "true");
154 sp_document_set_undo_sensitive (doc, saved);
155 sp_document_done (doc);
157 _wr->setUpdating (false);
158 }
161 RegisteredScalarUnit::RegisteredScalarUnit()
162 : _widget(0), _um(0)
163 {
164 }
166 RegisteredScalarUnit::~RegisteredScalarUnit()
167 {
168 if (_widget) delete _widget;
169 _value_changed_connection.disconnect();
170 }
172 void
173 RegisteredScalarUnit::init (const Glib::ustring& label, const Glib::ustring& tip, const Glib::ustring& key, const RegisteredUnitMenu &rum, Registry& wr)
174 {
175 _widget = new ScalarUnit (label, tip, UNIT_TYPE_LINEAR, "", "", rum._sel);
176 _widget->initScalar (-1e6, 1e6);
177 _widget->setUnit (rum._sel->getUnitAbbr());
178 _widget->setDigits (2);
179 _key = key;
180 _um = rum._sel;
181 _value_changed_connection = _widget->signal_value_changed().connect (sigc::mem_fun (*this, &RegisteredScalarUnit::on_value_changed));
182 _wr = ≀
183 }
185 ScalarUnit*
186 RegisteredScalarUnit::getSU()
187 {
188 return _widget;
189 }
191 void
192 RegisteredScalarUnit::setValue (double val)
193 {
194 _widget->setValue (val);
195 on_value_changed();
196 }
198 void
199 RegisteredScalarUnit::on_value_changed()
200 {
201 if (_wr->isUpdating())
202 return;
204 SPDesktop *dt = SP_ACTIVE_DESKTOP;
205 if (!dt)
206 return;
208 Inkscape::SVGOStringStream os;
209 os << _widget->getValue("");
210 if (_um)
211 os << _um->getUnitAbbr();
213 _wr->setUpdating (true);
215 SPDocument *doc = SP_DT_DOCUMENT(dt);
216 gboolean saved = sp_document_get_undo_sensitive (doc);
217 sp_document_set_undo_sensitive (doc, FALSE);
218 Inkscape::XML::Node *repr = SP_OBJECT_REPR (SP_DT_NAMEDVIEW(dt));
219 repr->setAttribute(_key.c_str(), os.str().c_str());
220 doc->rroot->setAttribute("sodipodi:modified", "true");
221 sp_document_set_undo_sensitive (doc, saved);
222 sp_document_done (doc);
224 _wr->setUpdating (false);
225 }
227 RegisteredColorPicker::RegisteredColorPicker()
228 : _label(0), _cp(0)
229 {
230 }
232 RegisteredColorPicker::~RegisteredColorPicker()
233 {
234 _changed_connection.disconnect();
235 if (_cp) delete _cp;
236 if (_label) delete _label;
237 }
239 void
240 RegisteredColorPicker::init (const Glib::ustring& label, const Glib::ustring& title, const Glib::ustring& tip, const Glib::ustring& ckey, const Glib::ustring& akey, Registry& wr)
241 {
242 _label = new Gtk::Label (label, 1.0, 0.5);
243 _cp = new ColorPicker (title,tip,0,true);
244 _ckey = ckey;
245 _akey = akey;
246 _wr = ≀
247 _changed_connection = _cp->connectChanged (sigc::mem_fun (*this, &RegisteredColorPicker::on_changed));
248 }
250 void
251 RegisteredColorPicker::setRgba32 (guint32 rgba)
252 {
253 _cp->setRgba32 (rgba);
254 }
256 void
257 RegisteredColorPicker::closeWindow()
258 {
259 _cp->closeWindow();
260 }
262 void
263 RegisteredColorPicker::on_changed (guint32 rgba)
264 {
265 if (_wr->isUpdating() || !SP_ACTIVE_DESKTOP)
266 return;
268 _wr->setUpdating (true);
269 Inkscape::XML::Node *repr = SP_OBJECT_REPR(SP_DT_NAMEDVIEW(SP_ACTIVE_DESKTOP));
270 gchar c[32];
271 sp_svg_write_color(c, 32, rgba);
272 repr->setAttribute(_ckey.c_str(), c);
273 sp_repr_set_css_double(repr, _akey.c_str(), (rgba & 0xff) / 255.0);
274 _wr->setUpdating (false);
275 }
277 RegisteredSuffixedInteger::RegisteredSuffixedInteger()
278 : _label(0), _sb(0),
279 _adj(0.0,0.0,100.0,1.0,1.0,1.0),
280 _suffix(0)
281 {
282 }
284 RegisteredSuffixedInteger::~RegisteredSuffixedInteger()
285 {
286 _changed_connection.disconnect();
287 if (_label) delete _label;
288 if (_suffix) delete _suffix;
289 if (_sb) delete _sb;
290 }
292 void
293 RegisteredSuffixedInteger::init (const Glib::ustring& label, const Glib::ustring& suffix, const Glib::ustring& key, Registry& wr)
294 {
295 _key = key;
296 _label = new Gtk::Label (label);
297 _label->set_alignment (1.0, 0.5);
298 _sb = new Gtk::SpinButton (_adj, 1.0, 0);
299 _suffix = new Gtk::Label (suffix);
300 _hbox.pack_start (*_sb, true, true, 0);
301 _hbox.pack_start (*_suffix, false, false, 0);
303 _changed_connection = _adj.signal_value_changed().connect (sigc::mem_fun(*this, &RegisteredSuffixedInteger::on_value_changed));
304 _wr = ≀
305 }
307 void
308 RegisteredSuffixedInteger::setValue (int i)
309 {
310 _adj.set_value (i);
311 }
313 void
314 RegisteredSuffixedInteger::on_value_changed()
315 {
316 if (_wr->isUpdating() || !SP_ACTIVE_DESKTOP)
317 return;
319 _wr->setUpdating (true);
321 SPDesktop* dt = SP_ACTIVE_DESKTOP;
322 Inkscape::XML::Node *repr = SP_OBJECT_REPR(SP_DT_NAMEDVIEW(dt));
323 Inkscape::SVGOStringStream os;
324 int value = int(_adj.get_value());
325 os << value;
327 repr->setAttribute(_key.c_str(), os.str().c_str());
328 sp_document_done(SP_DT_DOCUMENT(dt));
330 _wr->setUpdating (false);
331 }
333 RegisteredRadioButtonPair::RegisteredRadioButtonPair()
334 : _hbox(0)
335 {
336 }
338 RegisteredRadioButtonPair::~RegisteredRadioButtonPair()
339 {
340 _changed_connection.disconnect();
341 }
343 void
344 RegisteredRadioButtonPair::init (const Glib::ustring& label,
345 const Glib::ustring& label1, const Glib::ustring& label2,
346 const Glib::ustring& tip1, const Glib::ustring& tip2,
347 const Glib::ustring& key, Registry& wr)
348 {
349 _hbox = new Gtk::HBox;
350 _hbox->add (*manage (new Gtk::Label (label)));
351 _rb1 = manage (new Gtk::RadioButton (label1));
352 _hbox->add (*_rb1);
353 Gtk::RadioButtonGroup group = _rb1->get_group();
354 _rb2 = manage (new Gtk::RadioButton (group, label2, false));
355 _hbox->add (*_rb2);
356 _rb2->set_active();
357 _tt.set_tip (*_rb1, tip1);
358 _tt.set_tip (*_rb2, tip2);
359 _key = key;
360 _wr = ≀
361 _changed_connection = _rb1->signal_toggled().connect (sigc::mem_fun (*this, &RegisteredRadioButtonPair::on_value_changed));
362 }
364 void
365 RegisteredRadioButtonPair::setValue (bool second)
366 {
367 if (second) _rb2->set_active();
368 else _rb1->set_active();
369 }
371 void
372 RegisteredRadioButtonPair::on_value_changed()
373 {
374 if (_wr->isUpdating())
375 return;
377 SPDesktop *dt = SP_ACTIVE_DESKTOP;
378 if (!dt)
379 return;
381 _wr->setUpdating (true);
383 bool second = _rb2->get_active();
384 SPDocument *doc = SP_DT_DOCUMENT(dt);
385 gboolean saved = sp_document_get_undo_sensitive (doc);
386 sp_document_set_undo_sensitive (doc, FALSE);
387 Inkscape::XML::Node *repr = SP_OBJECT_REPR (SP_DT_NAMEDVIEW(dt));
388 repr->setAttribute(_key.c_str(), second ? "true" : "false");
389 doc->rroot->setAttribute("sodipodi:modified", "true");
390 sp_document_set_undo_sensitive (doc, saved);
391 sp_document_done (doc);
393 _wr->setUpdating (false);
394 }
396 } // namespace Dialog
397 } // namespace UI
398 } // namespace Inkscape
400 /*
401 Local Variables:
402 mode:c++
403 c-file-style:"stroustrup"
404 c-file-offsets:((innamespace . 0)(inline-open . 0))
405 indent-tabs-mode:nil
406 fill-column:99
407 End:
408 */
409 // vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :