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 }
45 /**
46 * Construct a Scalar Widget.
47 *
48 * \param label Label.
49 * \param digits Number of decimal digits to display.
50 * \param suffix Suffix, placed after the widget (defaults to "").
51 * \param icon Icon filename, placed before the label (defaults to "").
52 * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
53 * indicates the next character should be used for the
54 * mnemonic accelerator key (defaults to false).
55 */
56 Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip,
57 unsigned digits,
58 Glib::ustring const &suffix,
59 Glib::ustring const &icon,
60 bool mnemonic)
61 : Labelled(label, tooltip, new Gtk::SpinButton(0.0, digits), suffix, icon, mnemonic),
62 setProgrammatically(false)
63 {
64 }
66 /**
67 * Construct a Scalar Widget.
68 *
69 * \param label Label.
70 * \param adjust Adjustment to use for the SpinButton.
71 * \param digits Number of decimal digits to display (defaults to 0).
72 * \param suffix Suffix, placed after the widget (defaults to "").
73 * \param icon Icon filename, placed before the label (defaults to "").
74 * \param mnemonic Mnemonic toggle; if true, an underscore (_) in the label
75 * indicates the next character should be used for the
76 * mnemonic accelerator key (defaults to true).
77 */
78 Scalar::Scalar(Glib::ustring const &label, Glib::ustring const &tooltip,
79 Gtk::Adjustment &adjust,
80 unsigned digits,
81 Glib::ustring const &suffix,
82 Glib::ustring const &icon,
83 bool mnemonic)
84 : Labelled(label, tooltip, new Gtk::SpinButton(adjust, 0.0, digits), suffix, icon, mnemonic),
85 setProgrammatically(false)
86 {
87 }
89 /** Fetches the precision of the spin buton */
90 unsigned
91 Scalar::getDigits() const
92 {
93 g_assert(_widget != NULL);
94 return static_cast<Gtk::SpinButton*>(_widget)->get_digits();
95 }
97 /** Gets the current step ingrement used by the spin button */
98 double
99 Scalar::getStep() const
100 {
101 g_assert(_widget != NULL);
102 double step, page;
103 static_cast<Gtk::SpinButton*>(_widget)->get_increments(step, page);
104 return step;
105 }
107 /** Gets the current page increment used by the spin button */
108 double
109 Scalar::getPage() const
110 {
111 g_assert(_widget != NULL);
112 double step, page;
113 static_cast<Gtk::SpinButton*>(_widget)->get_increments(step, page);
114 return page;
115 }
117 /** Gets the minimum range value allowed for the spin button */
118 double
119 Scalar::getRangeMin() const
120 {
121 g_assert(_widget != NULL);
122 double min, max;
123 static_cast<Gtk::SpinButton*>(_widget)->get_range(min, max);
124 return min;
125 }
127 /** Gets the maximum range value allowed for the spin button */
128 double
129 Scalar::getRangeMax() const
130 {
131 g_assert(_widget != NULL);
132 double min, max;
133 static_cast<Gtk::SpinButton*>(_widget)->get_range(min, max);
134 return max;
135 }
137 /** Get the value in the spin_button . */
138 double
139 Scalar::getValue() const
140 {
141 g_assert(_widget != NULL);
142 return static_cast<Gtk::SpinButton*>(_widget)->get_value();
143 }
145 /** Get the value spin_button represented as an integer. */
146 int
147 Scalar::getValueAsInt() const
148 {
149 g_assert(_widget != NULL);
150 return static_cast<Gtk::SpinButton*>(_widget)->get_value_as_int();
151 }
154 /** Sets the precision to be displayed by the spin button */
155 void
156 Scalar::setDigits(unsigned digits)
157 {
158 g_assert(_widget != NULL);
159 static_cast<Gtk::SpinButton*>(_widget)->set_digits(digits);
160 }
162 /** Sets the step and page increments for the spin button */
163 void
164 Scalar::setIncrements(double step, double page)
165 {
166 g_assert(_widget != NULL);
167 static_cast<Gtk::SpinButton*>(_widget)->set_increments(step, page);
168 }
170 /** Sets the minimum and maximum range allowed for the spin button */
171 void
172 Scalar::setRange(double min, double max)
173 {
174 g_assert(_widget != NULL);
175 static_cast<Gtk::SpinButton*>(_widget)->set_range(min, max);
176 }
178 /** Sets the value of the spin button */
179 void
180 Scalar::setValue(double value)
181 {
182 g_assert(_widget != NULL);
183 setProgrammatically = true; // callback is supposed to reset back, if it cares
184 static_cast<Gtk::SpinButton*>(_widget)->set_value(value);
185 }
187 /** Manually forces an update of the spin button */
188 void
189 Scalar::update() {
190 g_assert(_widget != NULL);
191 static_cast<Gtk::SpinButton*>(_widget)->update();
192 }
196 /** Signal raised when the spin button's value changes */
197 Glib::SignalProxy0<void>
198 Scalar::signal_value_changed()
199 {
200 return static_cast<Gtk::SpinButton*>(_widget)->signal_value_changed();
201 }
204 } // namespace Widget
205 } // namespace UI
206 } // namespace Inkscape
208 /*
209 Local Variables:
210 mode:c++
211 c-file-style:"stroustrup"
212 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
213 indent-tabs-mode:nil
214 fill-column:99
215 End:
216 */
217 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :