NO-OP; clean up script spacing and remove goto
[ardour.git] / gtk2_ardour / ardour_button.h
1 /*
2     Copyright (C) 2010 Paul 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
19 #ifndef __gtk2_ardour_ardour_button_h__
20 #define __gtk2_ardour_ardour_button_h__
21
22 #include <list>
23 #include <stdint.h>
24
25 #include <gtkmm/action.h>
26
27 #include "pbd/signals.h"
28 #include "gtkmm2ext/ardour_icon.h"
29 #include "gtkmm2ext/binding_proxy.h"
30 #include "gtkmm2ext/activatable.h"
31 #include "gtkmm2ext/cairo_widget.h"
32
33 class ArdourButton : public CairoWidget , public Gtkmm2ext::Activatable
34 {
35         public:
36         enum Element {
37                 Edge = 0x1,
38                 Body = 0x2,
39                 Text = 0x4,
40                 Indicator = 0x8,
41                 unused = 0x10,
42                 Menu = 0x20,
43                 Inactive = 0x40, // no _action is defined AND state is not used
44                 VectorIcon = 0x80,
45                 IconRenderCallback = 0x100,
46         };
47
48         typedef void (* rendercallback_t) (cairo_t*, int, int, uint32_t, void*);
49
50         static Element default_elements;
51         static Element led_default_elements;
52         static Element just_led_default_elements;
53
54         ArdourButton (Element e = default_elements);
55         ArdourButton (const std::string&, Element e = default_elements);
56         virtual ~ArdourButton ();
57
58         enum Tweaks {
59                 Square = 0x1,
60                 TrackHeader = 0x2,
61                 OccasionalText = 0x4,
62                 unused4 = 0x8,
63         };
64
65         Tweaks tweaks() const { return _tweaks; }
66         void set_tweaks (Tweaks);
67
68         void set_active_state (Gtkmm2ext::ActiveState);
69         void set_visual_state (Gtkmm2ext::VisualState);
70
71         void set_custom_led_color (const uint32_t c, const bool useit = true);
72
73         void set_act_on_release (bool onRelease) { _act_on_release = onRelease; }
74
75         Element elements() const { return _elements; }
76         void set_elements (Element);
77         void add_elements (Element);
78
79         Gtkmm2ext::ArdourIcon::Icon icon() const { return _icon; }
80         void set_icon (Gtkmm2ext::ArdourIcon::Icon);
81         void set_icon (rendercallback_t, void*);
82
83         void set_corner_radius (float);
84
85         void set_text (const std::string&, bool markup = false);
86         const std::string& get_text () { return _text; }
87         bool get_markup () const { return _markup; }
88         void set_angle (const double);
89         void set_alignment (const float, const float);
90         void get_alignment (float& xa, float& ya) {xa = _xalign; ya = _yalign;};
91
92         void set_led_left (bool yn);
93         void set_distinct_led_click (bool yn);
94
95         void set_layout_ellipsize_width (int w);
96         void set_layout_font (const Pango::FontDescription&);
97         void set_text_ellipsize (Pango::EllipsizeMode);
98
99     /* Sets the text used for size request computation. Pass an
100      * empty string to return to the default behavior which uses
101      * the currently displayed text for measurement. */
102         void set_sizing_text (const std::string&);
103         const std::string& get_sizing_text () {return _sizing_text;}
104
105         sigc::signal<void, GdkEventButton*> signal_led_clicked;
106         sigc::signal<void> signal_clicked;
107
108         boost::shared_ptr<PBD::Controllable> get_controllable() { return binding_proxy.get_controllable(); }
109         void set_controllable (boost::shared_ptr<PBD::Controllable> c);
110         void watch ();
111
112         void set_related_action (Glib::RefPtr<Gtk::Action>);
113
114         bool on_button_press_event (GdkEventButton*);
115         bool on_button_release_event (GdkEventButton*);
116
117         void set_image (const Glib::RefPtr<Gdk::Pixbuf>&);
118
119         void set_fixed_colors   (const uint32_t active_color, const uint32_t inactive_color);
120         void set_active_color   (const uint32_t active_color);
121         void set_inactive_color (const uint32_t inactive_color);
122
123         void set_fallthrough_to_parent(bool fall) { _fallthrough_to_parent = fall; }
124
125         unsigned int char_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_pixel_width; }
126         unsigned int char_pixel_height() { if (_char_pixel_height < 1) recalc_char_pixel_geometry() ; return _char_pixel_height; }
127         float char_avg_pixel_width() { if (_char_pixel_width < 1) recalc_char_pixel_geometry() ; return _char_avg_pixel_width; }
128
129         protected:
130         void render (cairo_t *, cairo_rectangle_t *);
131         void on_size_request (Gtk::Requisition* req);
132         void on_size_allocate (Gtk::Allocation&);
133         void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
134         void on_name_changed ();
135         void on_realize ();
136         bool on_enter_notify_event (GdkEventCrossing*);
137         bool on_leave_notify_event (GdkEventCrossing*);
138         bool on_grab_broken_event(GdkEventGrabBroken*);
139         bool on_focus_in_event (GdkEventFocus*);
140         bool on_focus_out_event (GdkEventFocus*);
141         bool on_key_release_event (GdkEventKey *);
142
143         void controllable_changed ();
144         PBD::ScopedConnection watch_connection;
145
146         protected:
147         Glib::RefPtr<Pango::Layout> _layout;
148         Glib::RefPtr<Gdk::Pixbuf>   _pixbuf;
149         std::string                 _text;
150         std::string                 _sizing_text;
151         bool                        _markup;
152         Element                     _elements;
153         Gtkmm2ext::ArdourIcon::Icon _icon;
154         rendercallback_t            _icon_render_cb;
155         void*                       _icon_render_cb_data;
156         Tweaks                      _tweaks;
157         BindingProxy                binding_proxy;
158
159         void set_text_internal ();
160         void recalc_char_pixel_geometry ();
161         unsigned int _char_pixel_width;
162         unsigned int _char_pixel_height;
163         float _char_avg_pixel_width;
164
165         int   _text_width;
166         int   _text_height;
167         float _diameter;
168         float _corner_radius;
169         int   _corner_mask;
170
171         double _angle;
172         float _xalign, _yalign;
173
174         uint32_t fill_inactive_color;
175         uint32_t fill_active_color;
176
177         uint32_t text_active_color;
178         uint32_t text_inactive_color;
179
180         uint32_t led_active_color;
181         uint32_t led_inactive_color;
182         uint32_t led_custom_color;
183         bool     use_custom_led_color;
184
185         cairo_pattern_t* convex_pattern;
186         cairo_pattern_t* concave_pattern;
187         cairo_pattern_t* led_inset_pattern;
188         cairo_rectangle_t* _led_rect;
189
190         bool _act_on_release;
191         bool _led_left;
192         bool _distinct_led_click;
193         bool _hovering;
194         bool _focused;
195         int  _fixed_colors_set;
196         bool _fallthrough_to_parent;
197         int _layout_ellipsize_width;
198         Pango::EllipsizeMode _ellipsis;
199         bool _update_colors;
200         int _pattern_height;
201
202         void setup_led_rect ();
203         void set_colors ();
204         void color_handler ();
205         void build_patterns ();
206         void ensure_layout ();
207
208         void action_toggled ();
209         void action_sensitivity_changed ();
210         void action_visibility_changed ();
211         void action_tooltip_changed ();
212 };
213
214 #endif /* __gtk2_ardour_ardour_button_h__ */