2009-06-20 13:47:10 +00:00
|
|
|
/*
|
2019-08-03 04:40:09 +02:00
|
|
|
* Copyright (C) 2011-2016 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
|
* Copyright (C) 2014-2018 Robin Gareus <robin@gareus.org>
|
|
|
|
|
* Copyright (C) 2014 Ben Loftis <ben@harrisonconsoles.com>
|
|
|
|
|
*
|
|
|
|
|
* 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.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*/
|
2009-06-20 13:47:10 +00:00
|
|
|
|
2009-06-20 13:44:47 +00:00
|
|
|
#ifndef __gtk2_ardour_cairo_widget_h__
|
|
|
|
|
#define __gtk2_ardour_cairo_widget_h__
|
|
|
|
|
|
2017-03-20 17:11:56 +01:00
|
|
|
#include <cairomm/context.h>
|
2014-10-28 02:15:10 +01:00
|
|
|
#include <cairomm/surface.h>
|
2009-06-20 13:44:47 +00:00
|
|
|
#include <gtkmm/eventbox.h>
|
2013-10-17 11:26:01 -04:00
|
|
|
|
|
|
|
|
#include "gtkmm2ext/visibility.h"
|
2017-03-20 05:19:38 +01:00
|
|
|
#include "gtkmm2ext/cairo_canvas.h"
|
2011-11-01 01:22:08 +00:00
|
|
|
#include "gtkmm2ext/widget_state.h"
|
2009-06-20 13:44:47 +00:00
|
|
|
|
2011-10-27 20:24:29 +00:00
|
|
|
/** A parent class for widgets that are rendered using Cairo.
|
2009-06-21 15:56:16 +00:00
|
|
|
*/
|
|
|
|
|
|
2017-03-20 05:19:38 +01:00
|
|
|
class LIBGTKMM2EXT_API CairoWidget : public Gtk::EventBox, public Gtkmm2ext::CairoCanvas
|
2009-06-20 13:44:47 +00:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CairoWidget ();
|
|
|
|
|
virtual ~CairoWidget ();
|
|
|
|
|
|
2016-12-19 13:36:42 +01:00
|
|
|
void set_canvas_widget ();
|
2017-03-20 05:19:38 +01:00
|
|
|
void use_nsglview ();
|
2016-12-19 13:36:42 +01:00
|
|
|
|
|
|
|
|
/* swizzle Gtk::Widget methods for Canvas::Widget */
|
|
|
|
|
void queue_draw ();
|
|
|
|
|
void queue_resize ();
|
|
|
|
|
int get_width () const;
|
|
|
|
|
int get_height () const;
|
|
|
|
|
void size_allocate (Gtk::Allocation&);
|
|
|
|
|
|
2016-02-12 22:57:46 +01:00
|
|
|
void set_dirty (cairo_rectangle_t *area = 0);
|
2009-06-20 13:44:47 +00:00
|
|
|
|
2011-11-01 01:22:08 +00:00
|
|
|
Gtkmm2ext::ActiveState active_state() const { return _active_state; }
|
|
|
|
|
Gtkmm2ext::VisualState visual_state() const { return _visual_state; }
|
2015-10-05 16:17:49 +02:00
|
|
|
|
2014-08-30 01:42:37 +02:00
|
|
|
/* derived widgets can override these two to catch
|
2011-11-17 22:49:13 +00:00
|
|
|
changes in active & visual state
|
|
|
|
|
*/
|
2015-10-05 16:17:49 +02:00
|
|
|
|
2011-11-01 01:22:08 +00:00
|
|
|
virtual void set_active_state (Gtkmm2ext::ActiveState);
|
|
|
|
|
virtual void set_visual_state (Gtkmm2ext::VisualState);
|
2011-11-17 22:49:13 +00:00
|
|
|
|
2012-02-07 17:43:55 +00:00
|
|
|
void unset_active_state () { set_active_state (Gtkmm2ext::Off); }
|
|
|
|
|
void unset_visual_state () { set_visual_state (Gtkmm2ext::NoVisualState); }
|
2011-11-17 22:49:13 +00:00
|
|
|
|
|
|
|
|
/* this is an API simplification for widgets
|
|
|
|
|
that only use the Active and Normal active states.
|
|
|
|
|
*/
|
|
|
|
|
void set_active (bool);
|
2016-02-05 23:10:49 +10:00
|
|
|
bool get_active () const { return active_state() != Gtkmm2ext::Off; }
|
2011-10-26 21:01:14 +00:00
|
|
|
|
2011-11-18 15:35:58 +00: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 21:01:14 +00:00
|
|
|
sigc::signal<void> StateChanged;
|
2016-12-19 13:36:42 +01:00
|
|
|
sigc::signal<bool> QueueDraw;
|
|
|
|
|
sigc::signal<bool> QueueResize;
|
2011-10-26 21:01:14 +00:00
|
|
|
|
2011-11-18 15:35:58 +00:00
|
|
|
static void provide_background_for_cairo_widget (Gtk::Widget& w, const Gdk::Color& bg);
|
|
|
|
|
|
2017-03-20 05:19:38 +01:00
|
|
|
uint32_t background_color ();
|
|
|
|
|
|
2014-08-27 10:55:01 -05:00
|
|
|
static void set_flat_buttons (bool yn);
|
2018-10-02 21:27:55 +02:00
|
|
|
static void set_boxy_buttons (bool yn);
|
2014-08-27 10:55:01 -05:00
|
|
|
static bool flat_buttons() { return _flat_buttons; }
|
2018-10-02 21:27:55 +02:00
|
|
|
static bool boxy_buttons() { return _boxy_buttons; }
|
2014-08-27 10:55:01 -05:00
|
|
|
|
2015-01-28 02:22:52 +01:00
|
|
|
static void set_widget_prelight (bool yn);
|
|
|
|
|
static bool widget_prelight() { return _widget_prelight; }
|
|
|
|
|
|
2014-08-27 10:55:01 -05:00
|
|
|
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.
|
2015-10-05 16:17:49 +02:00
|
|
|
|
2014-09-16 12:42:39 -04:00
|
|
|
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
|
2015-10-04 14:51:05 -04:00
|
|
|
conditions (which will block this handler from being called). If
|
2014-09-16 12:42:39 -04:00
|
|
|
they wish to invoke any existing focus handler from their own
|
|
|
|
|
button press handler, they can just use: focus_handler();
|
|
|
|
|
*/
|
2016-03-15 12:34:26 -04:00
|
|
|
static void set_focus_handler (sigc::slot<void,Gtk::Widget*>);
|
2014-09-16 12:42:39 -04:00
|
|
|
|
2009-06-20 13:44:47 +00:00
|
|
|
protected:
|
2009-06-21 15:56:16 +00:00
|
|
|
/** Render the widget to the given Cairo context */
|
2009-06-20 13:44:47 +00:00
|
|
|
virtual bool on_expose_event (GdkEventExpose *);
|
|
|
|
|
void on_size_allocate (Gtk::Allocation &);
|
2011-11-03 14:50:42 +00:00
|
|
|
void on_state_changed (Gtk::StateType);
|
2014-08-30 01:42:37 +02:00
|
|
|
void on_style_changed (const Glib::RefPtr<Gtk::Style>&);
|
2017-03-20 05:19:38 +01:00
|
|
|
void on_realize ();
|
2014-09-16 12:42:39 -04:00
|
|
|
bool on_button_press_event (GdkEventButton*);
|
2011-10-26 21:01:14 +00:00
|
|
|
Gdk::Color get_parent_bg ();
|
2017-03-20 16:31:42 +01:00
|
|
|
void on_map();
|
|
|
|
|
void on_unmap();
|
2015-10-05 16:17:49 +02:00
|
|
|
|
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 13:44:47 +00:00
|
|
|
|
2011-11-01 01:22:08 +00:00
|
|
|
Gtkmm2ext::ActiveState _active_state;
|
|
|
|
|
Gtkmm2ext::VisualState _visual_state;
|
2011-11-18 15:35:58 +00:00
|
|
|
bool _need_bg;
|
2014-08-27 10:55:01 -05:00
|
|
|
|
|
|
|
|
static bool _flat_buttons;
|
2018-10-02 21:27:55 +02:00
|
|
|
static bool _boxy_buttons;
|
2015-01-28 02:22:52 +01:00
|
|
|
static bool _widget_prelight;
|
2014-08-21 11:13:23 -05:00
|
|
|
bool _grabbed;
|
2014-03-06 09:44:33 -05:00
|
|
|
|
2016-03-15 12:34:26 -04:00
|
|
|
static sigc::slot<void,Gtk::Widget*> focus_handler;
|
2014-09-16 12:42:39 -04:00
|
|
|
|
2014-03-06 09:44:33 -05:00
|
|
|
private:
|
2014-10-28 02:15:10 +01:00
|
|
|
Cairo::RefPtr<Cairo::Surface> image_surface;
|
2014-03-06 09:44:33 -05:00
|
|
|
Glib::SignalProxyProperty _name_proxy;
|
2014-08-30 01:42:37 +02:00
|
|
|
sigc::connection _parent_style_change;
|
|
|
|
|
Widget * _current_parent;
|
2016-12-19 13:36:42 +01:00
|
|
|
bool _canvas_widget;
|
2017-03-20 05:19:38 +01:00
|
|
|
void* _nsglview;
|
2016-12-19 13:36:42 +01:00
|
|
|
Gdk::Rectangle _allocation;
|
2015-10-05 16:17:49 +02:00
|
|
|
|
2009-06-20 13:44:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|