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