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