fix merge conflict from master
[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 #include <cairo.h>
26
27
28 namespace Gtkmm2ext {
29
30 class BarController : public Gtk::Frame
31 {
32   public:
33         BarController (Gtk::Adjustment& adj, boost::shared_ptr<PBD::Controllable>);
34
35         virtual ~BarController ();
36
37         enum barStyle {
38                 LeftToRight,
39                 RightToLeft,
40                 Line,
41                 Blob,
42                 CenterOut,
43                 
44                 TopToBottom,
45                 BottomToTop
46         };
47
48         barStyle style() const { return _style; }
49         void set_style (barStyle);
50         void set_use_parent (bool yn);
51
52         void set_sensitive (bool yn);
53         
54         void set_logarithmic (bool yn) { logarithmic = yn; }
55
56         sigc::signal<void> StartGesture;
57         sigc::signal<void> StopGesture;
58
59         /* export this to allow direct connection to button events */
60
61         Gtk::Widget& event_widget() { return darea; }
62
63         boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
64         void set_controllable(boost::shared_ptr<PBD::Controllable> c) { binding_proxy.set_controllable(c); }
65
66         /** Emitted when the adjustment spinner is activated or deactivated;
67          *  the parameter is true on activation, false on deactivation.
68          */
69         sigc::signal<void, bool> SpinnerActive;
70
71   protected:
72         Gtk::Adjustment&    adjustment;
73         BindingProxy        binding_proxy;
74         Gtk::DrawingArea    darea;
75         Glib::RefPtr<Pango::Layout> layout;
76         barStyle              _style;
77         bool                grabbed;
78         bool                switching;
79         bool                switch_on_release;
80         double              initial_value;
81         double              grab_x;
82         GdkWindow*          grab_window;
83         Gtk::SpinButton     spinner;
84         bool                use_parent;
85         bool                logarithmic;
86         sigc::slot<std::string> _label_slot;
87         bool                    _use_slot;
88
89         virtual std::string get_label (double& /*x*/) {
90                 return "";
91         }
92         
93         void create_patterns();
94         Cairo::RefPtr<Cairo::Pattern> pattern;
95         Cairo::RefPtr<Cairo::Pattern> shine_pattern;
96
97         virtual bool button_press (GdkEventButton *);
98         virtual bool button_release (GdkEventButton *);
99         virtual bool motion (GdkEventMotion *);
100         virtual bool expose (GdkEventExpose *);
101         virtual bool scroll (GdkEventScroll *);
102         virtual bool entry_focus_out (GdkEventFocus*);
103
104         gint mouse_control (double x, GdkWindow* w, double scaling);
105
106         gint switch_to_bar ();
107         gint switch_to_spinner ();
108
109         void entry_activated ();
110         void drop_grab ();
111         
112         int entry_input (double* new_value);
113         bool entry_output ();
114 };
115
116
117 }; /* namespace */
118
119 #endif // __gtkmm2ext_bar_controller_h__