1 /**
2 * \brief Scalar Widget - A labelled text box, with spin buttons and optional
3 * icon or suffix, for entering arbitrary number values.
4 *
5 * Authors:
6 * Carl Hetherington <inkscape@carlh.net>
7 * Derek P. Moore <derekm@hackunix.org>
8 * Bryce Harrington <bryce@bryceharrington.org>
9 *
10 * Copyright (C) 2004 Carl Hetherington
11 *
12 * Released under GNU GPL. Read the file 'COPYING' for more information.
13 */
15 #ifdef HAVE_CONFIG_H
16 # include <config.h>
17 #endif
20 #include "scalar.h"
22 namespace Inkscape {
23 namespace UI {
24 namespace Widget {
26 /**
27 * Construct a Scalar Widget.
28 *
29 * \param label Label.
30 * \param suffix Suffix, placed after the widget (defaults to "").
31 * \param icon Icon filename, placed before the label (defaults to "").
32 * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
33 * indicates the next character should be used for the
34 * mnemonic accelerator key (defaults to false).
35 */
36 Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip,
37 Glib::ustring const &suffix,
38 Glib::ustring const &icon,
39 bool mnemonic)
40 : Labelled(label, tooltip, new Gtk::SpinButton(), suffix, icon, mnemonic),
41 setProgrammatically(false)
42 {
43 static_cast<Gtk::SpinButton*>(_widget)->set_numeric();
44 }
46 /**
47 * Construct a Scalar Widget.
48 *
49 * \param label Label.
50 * \param digits Number of decimal digits to display.
51 * \param suffix Suffix, placed after the widget (defaults to "").
52 * \param icon Icon filename, placed before the label (defaults to "").
53 * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
54 * indicates the next character should be used for the
55 * mnemonic accelerator key (defaults to false).
56 */
57 Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip,
58 unsigned digits,
59 Glib::ustring const &suffix,
60 Glib::ustring const &icon,
61 bool mnemonic)
62 : Labelled(label, tooltip, new Gtk::SpinButton(0.0, digits), suffix, icon, mnemonic),
63 setProgrammatically(false)
64 {
65 static_cast<Gtk::SpinButton*>(_widget)->set_numeric();
66 }
68 /**
69 * Construct a Scalar Widget.
70 *
71 * \param label Label.
72 * \param adjust Adjustment to use for the SpinButton.
73 * \param digits Number of decimal digits to display (defaults to 0).
74 * \param suffix Suffix, placed after the widget (defaults to "").
75 * \param icon Icon filename, placed before the label (defaults to "").
76 * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
77 * indicates the next character should be used for the
78 * mnemonic accelerator key (defaults to true).
79 */
80 Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip,
81 Gtk::Adjustment &adjust,
82 unsigned digits,
83 Glib::ustring const &suffix,
84 Glib::ustring const &icon,
85 bool mnemonic)
86 : Labelled(label, tooltip, new Gtk::SpinButton(adjust, 0.0, digits), suffix, icon, mnemonic),
87 setProgrammatically(false)
88 {
89 static_cast<Gtk::SpinButton*>(_widget)->set_numeric();
90 }
92 /** Fetches the precision of the spin buton */
93 unsigned
94 Scalar::getDigits() const
95 {
96 g_assert(_widget != NULL);
97 return static_cast<Gtk::SpinButton*>(_widget)->get_digits();
98 }
100 /** Gets the current step ingrement used by the spin button */
101 double
102 Scalar::getStep() const
103 {
104 g_assert(_widget != NULL);
105 double step, page;
106 static_cast<Gtk::SpinButton*>(_widget)->get_increments(step, page);
107 return step;
108 }
110 /** Gets the current page increment used by the spin button */
111 double
112 Scalar::getPage() const
113 {
114 g_assert(_widget != NULL);
115 double step, page;
116 static_cast<Gtk::SpinButton*>(_widget)->get_increments(step, page);
117 return page;
118 }
120 /** Gets the minimum range value allowed for the spin button */
121 double
122 Scalar::getRangeMin() const
123 {
124 g_assert(_widget != NULL);
125 double min, max;
126 static_cast<Gtk::SpinButton*>(_widget)->get_range(min, max);
127 return min;
128 }
130 /** Gets the maximum range value allowed for the spin button */
131 double
132 Scalar::getRangeMax() const
133 {
134 g_assert(_widget != NULL);
135 double min, max;
136 static_cast<Gtk::SpinButton*>(_widget)->get_range(min, max);
137 return max;
138 }
140 /** Get the value in the spin_button . */
141 double
142 Scalar::getValue() const
143 {
144 g_assert(_widget != NULL);
145 return static_cast<Gtk::SpinButton*>(_widget)->get_value();
146 }
148 /** Get the value spin_button represented as an integer. */
149 int
150 Scalar::getValueAsInt() const
151 {
152 g_assert(_widget != NULL);
153 return static_cast<Gtk::SpinButton*>(_widget)->get_value_as_int();
154 }
157 /** Sets the precision to be displayed by the spin button */
158 void
159 Scalar::setDigits(unsigned digits)
160 {
161 g_assert(_widget != NULL);
162 static_cast<Gtk::SpinButton*>(_widget)->set_digits(digits);
163 }
165 /** Sets the step and page increments for the spin button */
166 void
167 Scalar::setIncrements(double step, double page)
168 {
169 g_assert(_widget != NULL);
170 static_cast<Gtk::SpinButton*>(_widget)->set_increments(step, page);
171 }
173 /** Sets the minimum and maximum range allowed for the spin button */
174 void
175 Scalar::setRange(double min, double max)
176 {
177 g_assert(_widget != NULL);
178 static_cast<Gtk::SpinButton*>(_widget)->set_range(min, max);
179 }
181 /** Sets the value of the spin button */
182 void
183 Scalar::setValue(double value)
184 {
185 g_assert(_widget != NULL);
186 setProgrammatically = true; // callback is supposed to reset back, if it cares
187 static_cast<Gtk::SpinButton*>(_widget)->set_value(value);
188 }
190 /** Manually forces an update of the spin button */
191 void
192 Scalar::update() {
193 g_assert(_widget != NULL);
194 static_cast<Gtk::SpinButton*>(_widget)->update();
195 }
199 /** Signal raised when the spin button's value changes */
200 Glib::SignalProxy0<void>
201 Scalar::signal_value_changed()
202 {
203 return static_cast<Gtk::SpinButton*>(_widget)->signal_value_changed();
204 }
207 } // namespace Widget
208 } // namespace UI
209 } // namespace Inkscape
211 /*
212 Local Variables:
213 mode:c++
214 c-file-style:"stroustrup"
215 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
216 indent-tabs-mode:nil
217 fill-column:99
218 End:
219 */
220 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :