partial patch/partial by-hand merge of 2.X commits 3169&3170 to 3.X codebase
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / barcontroller.h
1 /*
2     Copyright (C) 2004 Paul Davis 
3     This program is free software; you can redistribute it and/or modify
4     it under the terms of the GNU General Public License as published by
5     the Free Software Foundation; either version 2 of the License, or
6     (at your option) any later version.
7
8     This program is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11     GNU General Public License for more details.
12
13     You should have received a copy of the GNU General Public License
14     along with this program; if not, write to the Free Software
15     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
16
17 */
18
19 #ifndef __gtkmm2ext_bar_controller_h__
20 #define __gtkmm2ext_bar_controller_h__
21
22 #include <gtkmm/frame.h>
23 #include <gtkmm/drawingarea.h>
24 #include <gtkmm2ext/binding_proxy.h>
25
26 namespace ARDOUR {
27         class Controllable;
28 }
29
30 namespace Gtkmm2ext {
31
32 class BarController : public Gtk::Frame
33 {
34   public:
35         typedef sigc::slot<void,char*,unsigned int> LabelCallback;
36
37         BarController (Gtk::Adjustment& adj, boost::shared_ptr<PBD::Controllable>, LabelCallback lc = LabelCallback());
38
39         virtual ~BarController () {}
40         
41         enum Style {
42                 LeftToRight,
43                 RightToLeft,
44                 Line,
45                 CenterOut,
46                 
47                 TopToBottom,
48                 BottomToTop
49         };
50
51         Style style() const { return _style; }
52         void set_style (Style);
53         void set_with_text (bool yn);
54         void set_use_parent (bool yn);
55
56         void set_sensitive (bool yn);
57
58         Gtk::SpinButton& get_spin_button() { return spinner; }
59
60         sigc::signal<void> StartGesture;
61         sigc::signal<void> StopGesture;
62
63         /* export this to allow direct connection to button events */
64
65         Gtk::Widget& event_widget() { return darea; }
66
67         boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
68         void set_controllable(boost::shared_ptr<PBD::Controllable> c) { binding_proxy.set_controllable(c); }
69
70   protected:
71         Gtk::Adjustment&    adjustment;
72         BindingProxy        binding_proxy;
73         Gtk::DrawingArea    darea;
74         LabelCallback       label_callback;
75         Glib::RefPtr<Pango::Layout> layout;
76         Style              _style;
77         bool                grabbed;
78         bool                switching;
79         bool                switch_on_release;
80         bool                with_text;
81         double              initial_value;
82         double              grab_x;
83         GdkWindow*          grab_window;
84         Gtk::SpinButton     spinner;
85         bool                use_parent;
86
87         virtual bool button_press (GdkEventButton *);
88         virtual bool button_release (GdkEventButton *);
89         virtual bool motion (GdkEventMotion *);
90         virtual bool expose (GdkEventExpose *);
91         virtual bool scroll (GdkEventScroll *);
92         virtual bool entry_focus_out (GdkEventFocus*);
93
94         gint mouse_control (double x, GdkWindow* w, double scaling);
95
96         gint switch_to_bar ();
97         gint switch_to_spinner ();
98
99         void entry_activated ();
100         void drop_grab ();
101 };
102
103
104 }; /* namespace */
105
106 #endif // __gtkmm2ext_bar_controller_h__