2 Copyright (C) 1999 Paul Barton-Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "gtkmm2ext/auto_spin.h"
23 #include "gtkmm2ext/keyboard.h"
25 using namespace Gtkmm2ext;
28 #define upper adjustment.get_upper()
29 #define lower adjustment.get_lower()
30 #define step_increment adjustment.get_step_increment()
31 #define page_increment adjustment.get_page_increment()
33 const unsigned int AutoSpin::initial_timer_interval = 500; /* msecs */
34 const unsigned int AutoSpin::timer_interval = 20; /* msecs */
35 const unsigned int AutoSpin::climb_timer_calls = 5; /* between climbing */
37 AutoSpin::AutoSpin (Gtk::Adjustment &adjr, gfloat cr, bool round_to_steps_yn)
42 initial = adjustment.get_value();
43 left_is_decrement = true;
48 round_to_steps = round_to_steps_yn;
52 AutoSpin::stop_timer ()
55 g_source_remove (timeout_tag);
61 AutoSpin::stop_spinning (GdkEventButton */*ev*/)
69 AutoSpin::button_press (GdkEventButton *ev)
73 bool with_decrement = false;
77 if (ev->state & Keyboard::TertiaryModifier) {
83 if (ev->state & Keyboard::PrimaryModifier) {
84 /* go to upper/lower bound on button1/button2 */
89 /* XXX should figure out which button is left/right */
94 set_value (left_is_decrement ? lower : upper);
97 if (left_is_decrement) {
98 with_decrement = true;
100 with_decrement = false;
114 set_value (left_is_decrement ? upper : lower);
121 adjust_value (shifted ? page_increment : step_increment);
130 adjust_value (shifted ? -page_increment : -step_increment);
138 start_spinning (with_decrement, shifted);
143 AutoSpin::start_spinning (bool decrement, bool page)
145 timer_increment = page ? page_increment : step_increment;
148 timer_increment = -timer_increment;
151 adjust_value (timer_increment);
155 timeout_tag = g_timeout_add (initial_timer_interval,
161 AutoSpin::_timer (void *arg)
163 return ((AutoSpin *) arg)->timer ();
167 AutoSpin::set_value (gfloat value)
170 adjustment.set_value (floor((value / step_increment) + 0.5f) * step_increment);
172 adjustment.set_value (value);
176 AutoSpin::adjust_value (gfloat increment)
181 val = adjustment.get_value();
192 } else if (val < lower) {
211 done = adjust_value (timer_increment);
215 /* we're in the initial call, which happened
216 after initial_timer_interval msecs. Now
217 request a much more frequent update.
220 timeout_tag = g_timeout_add (timer_interval,
226 /* cancel this initial timeout */
231 /* this is the regular "fast" call after each
232 timer_interval msecs.
235 if (timer_calls < climb_timer_calls) {
238 if (climb_rate > 0.0) {
239 if (timer_increment > 0) {
240 timer_increment += climb_rate;
242 timer_increment -= climb_rate;
257 AutoSpin::set_bounds (gfloat init, gfloat up, gfloat down, bool with_reset)
259 adjustment.set_upper(up);
260 adjustment.set_lower(down);
264 adjustment.changed ();
267 adjustment.set_value (init);