ardour
cairo_widget.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2009 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 
20 #ifndef __gtk2_ardour_cairo_widget_h__
21 #define __gtk2_ardour_cairo_widget_h__
22 
23 #include <cairomm/surface.h>
24 #include <gtkmm/eventbox.h>
25 
26 #include "gtkmm2ext/visibility.h"
27 #include "gtkmm2ext/widget_state.h"
28 
32 class LIBGTKMM2EXT_API CairoWidget : public Gtk::EventBox
33 {
34 public:
35  CairoWidget ();
36  virtual ~CairoWidget ();
37 
38  void set_dirty ();
39 
40  Gtkmm2ext::ActiveState active_state() const { return _active_state; }
41  Gtkmm2ext::VisualState visual_state() const { return _visual_state; }
42 
43  /* derived widgets can override these two to catch
44  changes in active & visual state
45  */
46 
47  virtual void set_active_state (Gtkmm2ext::ActiveState);
48  virtual void set_visual_state (Gtkmm2ext::VisualState);
49 
50  void unset_active_state () { set_active_state (Gtkmm2ext::Off); }
51  void unset_visual_state () { set_visual_state (Gtkmm2ext::NoVisualState); }
52 
53  /* this is an API simplification for widgets
54  that only use the Active and Normal active states.
55  */
56  void set_active (bool);
57  bool get_active () { return active_state() != Gtkmm2ext::Off; }
58 
59  /* widgets can be told to only draw their "foreground, and thus leave
60  in place whatever background is drawn by their parent. the default
61  is that the widget will fill its event window with the background
62  color of the parent container.
63  */
64 
65  void set_draw_background (bool yn);
66 
67  sigc::signal<void> StateChanged;
68 
69  static void provide_background_for_cairo_widget (Gtk::Widget& w, const Gdk::Color& bg);
70 
71  virtual void render (cairo_t *, cairo_rectangle_t*) = 0;
72 
73  static void set_flat_buttons (bool yn);
74  static bool flat_buttons() { return _flat_buttons; }
75 
76  static void set_widget_prelight (bool yn);
77  static bool widget_prelight() { return _widget_prelight; }
78 
79  static void set_source_rgb_a( cairo_t* cr, Gdk::Color, float a=1.0 );
80 
81  /* set_focus_handler() will cause all button-press events on any
82  CairoWidget to invoke this slot/functor/function/method/callback.
83 
84  We do this because in general, CairoWidgets do not grab
85  keyboard focus, but a button press on them should
86  clear focus from any active text entry.
87 
88  This is global to all CairoWidgets and derived types.
89 
90  However, derived types can override the behaviour by defining their
91  own on_button_press_event() handler which returns true under all
92  conditions (which will block this handler from being called). If
93  they wish to invoke any existing focus handler from their own
94  button press handler, they can just use: focus_handler();
95  */
96  static void set_focus_handler (sigc::slot<void>);
97 
98 protected:
100  virtual bool on_expose_event (GdkEventExpose *);
101  void on_size_allocate (Gtk::Allocation &);
102  void on_state_changed (Gtk::StateType);
103  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
104  bool on_button_press_event (GdkEventButton*);
105  Gdk::Color get_parent_bg ();
106 
107  /* this is an additional virtual "on_..." method. Glibmm does not
108  provide a direct signal for name changes, so this acts as a proxy.
109  */
110 
111  virtual void on_name_changed () {};
112 
113  Gtkmm2ext::ActiveState _active_state;
114  Gtkmm2ext::VisualState _visual_state;
115  bool _need_bg;
116 
117  static bool _flat_buttons;
118  static bool _widget_prelight;
119  bool _grabbed;
120 
121  static sigc::slot<void> focus_handler;
122 
123  private:
124  Cairo::RefPtr<Cairo::Surface> image_surface;
125  Glib::SignalProxyProperty _name_proxy;
126  sigc::connection _parent_style_change;
127  Widget * _current_parent;
128 
129 };
130 
131 #endif
Cairo::RefPtr< Cairo::Surface > image_surface
Definition: cairo_widget.h:124
void unset_visual_state()
Definition: cairo_widget.h:51
Gtkmm2ext::ActiveState active_state() const
Definition: cairo_widget.h:40
LIBGTKMM2EXT_API
sigc::connection _parent_style_change
Definition: cairo_widget.h:126
static bool flat_buttons()
Definition: cairo_widget.h:74
sigc::signal< void > StateChanged
Definition: cairo_widget.h:67
void unset_active_state()
Definition: cairo_widget.h:50
static sigc::slot< void > focus_handler
Definition: cairo_widget.h:121
NoVisualState
Definition: widget_state.h:20
static bool widget_prelight()
Definition: cairo_widget.h:77
Gtkmm2ext::VisualState visual_state() const
Definition: cairo_widget.h:41
static bool _widget_prelight
Definition: cairo_widget.h:118
Gtkmm2ext::VisualState _visual_state
Definition: cairo_widget.h:114
bool get_active()
Definition: cairo_widget.h:57
Glib::SignalProxyProperty _name_proxy
Definition: cairo_widget.h:125
static bool _flat_buttons
Definition: cairo_widget.h:117
Widget * _current_parent
Definition: cairo_widget.h:127
Off
Definition: widget_state.h:13
virtual void on_name_changed()
Definition: cairo_widget.h:111