~valavanisalex/ubuntu/precise/inkscape/fix-943984

« back to all changes in this revision

Viewing changes to inkscape-0.47pre1/src/ui/widget/scalar.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bryce Harrington
  • Date: 2009-07-02 17:09:45 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20090702170945-nn6d6zswovbwju1t
Tags: 0.47~pre1-0ubuntu1
* New upstream release.
  - Don't constrain maximization on small resolution devices (pre0)
    (LP: #348842)
  - Fixes segfault on startup (pre0)
    (LP: #391149)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 */
 
14
 
 
15
#ifdef HAVE_CONFIG_H
 
16
# include <config.h>
 
17
#endif
 
18
 
 
19
 
 
20
#include "scalar.h"
 
21
 
 
22
namespace Inkscape {
 
23
namespace UI {
 
24
namespace Widget {
 
25
 
 
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
}
 
45
 
 
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
}
 
67
 
 
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
}
 
91
 
 
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
}
 
99
 
 
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
}
 
109
 
 
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
}
 
119
 
 
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
}
 
129
 
 
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
}
 
139
 
 
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
}
 
147
 
 
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
}
 
155
 
 
156
 
 
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
}
 
164
 
 
165
/** Sets the step and page increments for the spin button
 
166
 * @todo Remove the second parameter - deprecated
 
167
 */
 
168
void
 
169
Scalar::setIncrements(double step, double /*page*/)
 
170
{
 
171
    g_assert(_widget != NULL);
 
172
    static_cast<Gtk::SpinButton*>(_widget)->set_increments(step, 0);
 
173
}
 
174
 
 
175
/** Sets the minimum and maximum range allowed for the spin button */
 
176
void
 
177
Scalar::setRange(double min, double max)
 
178
{
 
179
    g_assert(_widget != NULL);
 
180
    static_cast<Gtk::SpinButton*>(_widget)->set_range(min, max);
 
181
}
 
182
 
 
183
/** Sets the value of the spin button */
 
184
void
 
185
Scalar::setValue(double value)
 
186
{
 
187
    g_assert(_widget != NULL);
 
188
    setProgrammatically = true; // callback is supposed to reset back, if it cares
 
189
    static_cast<Gtk::SpinButton*>(_widget)->set_value(value);
 
190
}
 
191
 
 
192
/** Manually forces an update of the spin button */
 
193
void
 
194
Scalar::update() {
 
195
    g_assert(_widget != NULL);
 
196
    static_cast<Gtk::SpinButton*>(_widget)->update();
 
197
}
 
198
 
 
199
 
 
200
 
 
201
/** Signal raised when the spin button's value changes */
 
202
Glib::SignalProxy0<void>
 
203
Scalar::signal_value_changed()
 
204
{
 
205
    return static_cast<Gtk::SpinButton*>(_widget)->signal_value_changed();
 
206
}
 
207
 
 
208
 
 
209
} // namespace Widget
 
210
} // namespace UI
 
211
} // namespace Inkscape
 
212
 
 
213
/*
 
214
  Local Variables:
 
215
  mode:c++
 
216
  c-file-style:"stroustrup"
 
217
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
 
218
  indent-tabs-mode:nil
 
219
  fill-column:99
 
220
  End:
 
221
*/
 
222
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :