2009-06-20 09:47:10 -04:00
|
|
|
/*
|
2009-10-14 12:10:01 -04:00
|
|
|
Copyright (C) 2009 Paul Davis
|
2009-06-20 09:47:10 -04:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2009-06-20 09:44:47 -04:00
|
|
|
#ifndef __gtk2_ardour_cairo_widget_h__
|
|
|
|
#define __gtk2_ardour_cairo_widget_h__
|
|
|
|
|
2014-10-27 21:15:10 -04:00
|
|
|
#include <cairomm/surface.h>
|
2009-06-20 09:44:47 -04:00
|
|
|
#include <gtkmm/eventbox.h>
|
2013-10-17 11:26:01 -04:00
|
|
|
|
|
|
|
#include "gtkmm2ext/visibility.h"
|
2011-10-31 21:22:08 -04:00
|
|
|
#include "gtkmm2ext/widget_state.h"
|
2009-06-20 09:44:47 -04:00
|
|
|
|
2011-10-27 16:24:29 -04:00
|
|
|
/** A parent class for widgets that are rendered using Cairo.
|
2009-06-21 11:56:16 -04:00
|
|
|
*/
|
|
|
|
|
2013-10-17 11:26:01 -04:00
|
|
|
class LIBGTKMM2EXT_API CairoWidget : public Gtk::EventBox
|
2009-06-20 09:44:47 -04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CairoWidget ();
|
|
|
|
virtual ~CairoWidget ();
|
|
|
|
|
|
|
|
void set_dirty ();
|
|
|
|
|
2011-10-31 21:22:08 -04:00
|
|
|
Gtkmm2ext::ActiveState active_state() const { return _active_state; }
|
|
|
|
Gtkmm2ext::VisualState visual_state() const { return _visual_state; }
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2014-08-29 19:42:37 -04:00
|
|
|
/* derived widgets can override these two to catch
|
2011-11-17 17:49:13 -05:00
|
|
|
changes in active & visual state
|
|
|
|
*/
|
|
|
|
|
2011-10-31 21:22:08 -04:00
|
|
|
virtual void set_active_state (Gtkmm2ext::ActiveState);
|
|
|
|
virtual void set_visual_state (Gtkmm2ext::VisualState);
|
2011-11-17 17:49:13 -05:00
|
|
|
|
2012-02-07 12:43:55 -05:00
|
|
|
void unset_active_state () { set_active_state (Gtkmm2ext::Off); }
|
|
|
|
void unset_visual_state () { set_visual_state (Gtkmm2ext::NoVisualState); }
|
2011-11-17 17:49:13 -05:00
|
|
|
|
|
|
|
/* this is an API simplification for widgets
|
|
|
|
that only use the Active and Normal active states.
|
|
|
|
*/
|
|
|
|
void set_active (bool);
|
2012-02-07 12:43:55 -05:00
|
|
|
bool get_active () { return active_state() != Gtkmm2ext::Off; }
|
2011-10-26 17:01:14 -04:00
|
|
|
|
2011-11-18 10:35:58 -05:00
|
|
|
/* widgets can be told to only draw their "foreground, and thus leave
|
|
|
|
in place whatever background is drawn by their parent. the default
|
|
|
|
is that the widget will fill its event window with the background
|
|
|
|
color of the parent container.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void set_draw_background (bool yn);
|
|
|
|
|
2011-10-26 17:01:14 -04:00
|
|
|
sigc::signal<void> StateChanged;
|
|
|
|
|
2011-11-18 10:35:58 -05:00
|
|
|
static void provide_background_for_cairo_widget (Gtk::Widget& w, const Gdk::Color& bg);
|
|
|
|
|
2014-06-03 23:56:08 -04:00
|
|
|
virtual void render (cairo_t *, cairo_rectangle_t*) = 0;
|
|
|
|
|
2014-08-27 11:55:01 -04:00
|
|
|
static void set_flat_buttons (bool yn);
|
|
|
|
static bool flat_buttons() { return _flat_buttons; }
|
|
|
|
|
|
|
|
static void set_source_rgb_a( cairo_t* cr, Gdk::Color, float a=1.0 );
|
|
|
|
|
2014-09-16 12:42:39 -04:00
|
|
|
/* set_focus_handler() will cause all button-press events on any
|
|
|
|
CairoWidget to invoke this slot/functor/function/method/callback.
|
|
|
|
|
|
|
|
We do this because in general, CairoWidgets do not grab
|
|
|
|
keyboard focus, but a button press on them should
|
|
|
|
clear focus from any active text entry.
|
|
|
|
|
|
|
|
This is global to all CairoWidgets and derived types.
|
|
|
|
|
|
|
|
However, derived types can override the behaviour by defining their
|
|
|
|
own on_button_press_event() handler which returns true under all
|
|
|
|
conditions (which will block this handler from being called). If
|
|
|
|
they wish to invoke any existing focus handler from their own
|
|
|
|
button press handler, they can just use: focus_handler();
|
|
|
|
*/
|
|
|
|
static void set_focus_handler (sigc::slot<void>);
|
|
|
|
|
2009-06-20 09:44:47 -04:00
|
|
|
protected:
|
2009-06-21 11:56:16 -04:00
|
|
|
/** Render the widget to the given Cairo context */
|
2009-06-20 09:44:47 -04:00
|
|
|
virtual bool on_expose_event (GdkEventExpose *);
|
|
|
|
void on_size_allocate (Gtk::Allocation &);
|
2011-11-03 10:50:42 -04:00
|
|
|
void on_state_changed (Gtk::StateType);
|
2014-08-29 19:42:37 -04:00
|
|
|
void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
|
2014-09-16 12:42:39 -04:00
|
|
|
bool on_button_press_event (GdkEventButton*);
|
2011-10-26 17:01:14 -04:00
|
|
|
Gdk::Color get_parent_bg ();
|
2014-03-06 09:44:33 -05:00
|
|
|
|
|
|
|
/* this is an additional virtual "on_..." method. Glibmm does not
|
|
|
|
provide a direct signal for name changes, so this acts as a proxy.
|
|
|
|
*/
|
|
|
|
|
|
|
|
virtual void on_name_changed () {};
|
2009-06-20 09:44:47 -04:00
|
|
|
|
2011-10-31 21:22:08 -04:00
|
|
|
Gtkmm2ext::ActiveState _active_state;
|
|
|
|
Gtkmm2ext::VisualState _visual_state;
|
2011-11-18 10:35:58 -05:00
|
|
|
bool _need_bg;
|
2014-08-27 11:55:01 -04:00
|
|
|
|
|
|
|
static bool _flat_buttons;
|
2014-08-21 12:13:23 -04:00
|
|
|
bool _grabbed;
|
2014-03-06 09:44:33 -05:00
|
|
|
|
2014-09-16 12:42:39 -04:00
|
|
|
static sigc::slot<void> focus_handler;
|
|
|
|
|
2014-03-06 09:44:33 -05:00
|
|
|
private:
|
2014-10-27 21:15:10 -04:00
|
|
|
Cairo::RefPtr<Cairo::Surface> image_surface;
|
2014-03-06 09:44:33 -05:00
|
|
|
Glib::SignalProxyProperty _name_proxy;
|
2014-08-29 19:42:37 -04:00
|
|
|
sigc::connection _parent_style_change;
|
|
|
|
Widget * _current_parent;
|
2014-09-16 12:42:39 -04:00
|
|
|
|
2009-06-20 09:44:47 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|