Ardour  9.0-pre0-582-g084a23a80d
cairo_widget.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
3  * Copyright (C) 2014-2018 Robin Gareus <robin@gareus.org>
4  * Copyright (C) 2014 Ben Loftis <ben@harrisonconsoles.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  */
20 
21 #ifndef __gtk2_ardour_cairo_widget_h__
22 #define __gtk2_ardour_cairo_widget_h__
23 
24 #include <cairomm/context.h>
25 #include <cairomm/surface.h>
26 #include <gtkmm/eventbox.h>
27 
28 #include "gtkmm2ext/visibility.h"
29 #include "gtkmm2ext/cairo_canvas.h"
30 #include "gtkmm2ext/cairo_theme.h"
31 #include "gtkmm2ext/colors.h"
32 #include "gtkmm2ext/widget_state.h"
33 
38 {
39 public:
41  virtual ~CairoWidget ();
42 
44  void use_nsglview (bool retina = true);
45  void use_image_surface (bool yn = true);
46 
47  /* swizzle Gtk::Widget methods for Canvas::Widget */
48  void queue_draw ();
49  void queue_resize ();
50  int get_width () const;
51  int get_height () const;
53 
54  void set_dirty (cairo_rectangle_t *area = 0);
55 
56  Gtkmm2ext::ActiveState active_state() const { return _active_state; }
57  Gtkmm2ext::VisualState visual_state() const { return _visual_state; }
58 
59  /* derived widgets can override these two to catch
60  changes in active & visual state
61  */
62 
65 
66  void unset_active_state () { set_active_state (Gtkmm2ext::Off); }
67  void unset_visual_state () { set_visual_state (Gtkmm2ext::NoVisualState); }
68 
69  /* this is an API simplification for widgets
70  that only use the Active and Normal active states.
71  */
72  void set_active (bool);
73  bool get_active () const { return active_state() != Gtkmm2ext::Off; }
74 
75  /* widgets can be told to only draw their "foreground, and thus leave
76  in place whatever background is drawn by their parent. the default
77  is that the widget will fill its event window with the background
78  color of the parent container.
79  */
80 
81  void set_draw_background (bool yn);
82 
83  sigc::signal<void> StateChanged;
84  sigc::signal<bool> QueueDraw;
85  sigc::signal<bool> QueueResize;
86 
88 
89  uint32_t background_color ();
90 
91 
92  static void set_source_rgb_a( cairo_t* cr, Gdk::Color, float a=1.0 );
93  static void set_source_rgb_a( cairo_t* cr, Gtkmm2ext::Color, float a=1.0 );
94 
95  /* set_focus_handler() will cause all button-press events on any
96  CairoWidget to invoke this slot/functor/function/method/callback.
97 
98  We do this because in general, CairoWidgets do not grab
99  keyboard focus, but a button press on them should
100  clear focus from any active text entry.
101 
102  This is global to all CairoWidgets and derived types.
103 
104  However, derived types can override the behaviour by defining their
105  own on_button_press_event() handler which returns true under all
106  conditions (which will block this handler from being called). If
107  they wish to invoke any existing focus handler from their own
108  button press handler, they can just use: focus_handler();
109  */
110  static void set_focus_handler (sigc::slot<void,Gtk::Widget*>);
111 
112 protected:
114  virtual bool on_expose_event (GdkEventExpose *);
117  void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
118  void on_realize ();
121  void on_map();
122  void on_unmap();
123 
124  /* this is an additional virtual "on_..." method. Glibmm does not
125  provide a direct signal for name changes, so this acts as a proxy.
126  */
127 
128  virtual void on_name_changed () {};
129 
132  bool _need_bg;
133  bool _grabbed;
134 
135  static sigc::slot<void,Gtk::Widget*> focus_handler;
136 
137 private:
139 
140  Cairo::RefPtr<Cairo::Surface> image_surface;
141  Glib::SignalProxyProperty _name_proxy;
142  sigc::connection _parent_style_change;
143  Widget * _current_parent;
145  void* _nsglview;
148  Glib::ustring _widget_name;
149 
150 };
151 
152 #endif
virtual void set_visual_state(Gtkmm2ext::VisualState)
Gtkmm2ext::VisualState _visual_state
Definition: cairo_widget.h:131
Gtkmm2ext::ActiveState _active_state
Definition: cairo_widget.h:128
void * _nsglview
Definition: cairo_widget.h:145
virtual bool on_expose_event(GdkEventExpose *)
sigc::connection _parent_style_change
Definition: cairo_widget.h:142
static void provide_background_for_cairo_widget(Gtk::Widget &w, const Gdk::Color &bg)
static void set_source_rgb_a(cairo_t *cr, Gdk::Color, float a=1.0)
static void set_source_rgb_a(cairo_t *cr, Gtkmm2ext::Color, float a=1.0)
virtual ~CairoWidget()
bool _canvas_widget
Definition: cairo_widget.h:144
virtual void on_name_changed()
Definition: cairo_widget.h:128
sigc::signal< bool > QueueDraw
Definition: cairo_widget.h:84
void set_active(bool)
sigc::signal< bool > QueueResize
Definition: cairo_widget.h:85
void on_realize()
This is a default handler for the signal signal_realize().
void use_nsglview(bool retina=true)
void on_style_changed(const Glib::RefPtr< Gtk::Style > &)
bool on_button_press_event(GdkEventButton *)
This is a default handler for the signal signal_button_press_event().
void queue_draw()
uint32_t background_color()
Widget * _current_parent
Definition: cairo_widget.h:143
sigc::signal< void > StateChanged
Definition: cairo_widget.h:83
bool _use_image_surface
Definition: cairo_widget.h:146
void on_unmap()
This is a default handler for the signal signal_unmap().
void on_state_changed(Gtk::StateType)
This is a default handler for the signal signal_state_changed().
Cairo::RefPtr< Cairo::Surface > image_surface
Definition: cairo_widget.h:140
void set_canvas_widget()
static sigc::slot< void, Gtk::Widget * > focus_handler
Definition: cairo_widget.h:135
void set_draw_background(bool yn)
Gdk::Color get_parent_bg()
Glib::ustring _widget_name
Definition: cairo_widget.h:148
void use_image_surface(bool yn=true)
Gtkmm2ext::ActiveState active_state() const
Definition: cairo_widget.h:56
void size_allocate(Gtk::Allocation &)
void unset_active_state()
Definition: cairo_widget.h:66
bool get_active() const
Definition: cairo_widget.h:73
Gtkmm2ext::VisualState visual_state() const
Definition: cairo_widget.h:57
Glib::SignalProxyProperty _name_proxy
Definition: cairo_widget.h:141
int get_height() const
static void set_focus_handler(sigc::slot< void, Gtk::Widget * >)
void unset_visual_state()
Definition: cairo_widget.h:67
int get_width() const
void on_size_allocate(Gtk::Allocation &)
This is a default handler for the signal signal_size_allocate().
void queue_resize()
void on_map()
This is a default handler for the signal signal_map().
virtual void set_active_state(Gtkmm2ext::ActiveState)
Gdk::Rectangle _allocation
Definition: cairo_widget.h:147
void on_widget_name_changed()
void set_dirty(cairo_rectangle_t *area=0)
#define LIBGTKMM2EXT_API
uint32_t Color
Definition: colors.h:33