68da2249a05ff4998cb2fce8307ca4364aabafef
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / auto_spin.h
1 /*
2     Copyright (C) 2000 Paul Barton-Davis 
3
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.
8
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.
13
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.
17
18     $Id$
19 */
20
21 #ifndef __gtkmm2ext_auto_spin_h__
22 #define __gtkmm2ext_auto_spin_h__
23
24 #include <gtkmm.h>
25
26 namespace Gtkmm2ext {
27
28 class AutoSpin 
29
30 {
31   public:
32         AutoSpin (Gtk::Adjustment &adj, gfloat cr = 0, bool round_to_steps_yn = false);
33
34         Gtk::Adjustment &get_adjustment() { return adjustment; }
35
36         void use_left_as_decrement (bool yn) { left_is_decrement = yn; }
37         void set_wrap (bool yn) { wrap = yn; }
38         void set_climb_rate (gfloat cr) { climb_rate = cr; }
39         void set_bounds (gfloat initial, gfloat low, gfloat high,
40                          bool with_reset = true);
41
42         gint button_press (GdkEventButton *);
43         gint stop_spinning (GdkEventButton *ignored_but_here_for_clicked);
44         void start_spinning (bool decrementing, bool use_page);
45
46   private:
47         Gtk::Adjustment &adjustment;
48         gfloat climb_rate;
49         gfloat timer_increment;
50         gfloat initial;
51         unsigned int timer_calls;
52         bool have_timer;
53         bool need_timer;
54         bool wrap;
55         gint timeout_tag;
56         bool left_is_decrement;
57         bool round_to_steps;
58
59         static const unsigned int initial_timer_interval;
60         static const unsigned int timer_interval;
61         static const unsigned int climb_timer_calls;
62
63         void stop_timer ();
64         static gint _timer (void *arg);
65         gint timer ();
66         bool adjust_value (gfloat increment);
67         void set_value (gfloat value);
68 };
69
70 } /* namespace */
71         
72 #endif /* __gtkmm2ext_auto_spin_h__ */