add a focus handling callback so that all button press events on CairoWidgets will cause a focus reset.

Conflicts:
	libs/gtkmm2ext/cairo_widget.cc
	libs/gtkmm2ext/gtkmm2ext/cairo_widget.h
This commit is contained in:
Paul Davis 2014-09-16 12:42:39 -04:00
parent a7aca1a849
commit 59291ede87
2 changed files with 38 additions and 0 deletions

View file

@ -24,6 +24,10 @@
static const char* has_cairo_widget_background_info = "has_cairo_widget_background_info";
static void noop() { }
sigc::slot<void> CairoWidget::focus_handler (sigc::ptr_fun (noop));
CairoWidget::CairoWidget ()
: _active_state (Gtkmm2ext::Off)
, _visual_state (Gtkmm2ext::NoVisualState)
@ -38,6 +42,13 @@ CairoWidget::~CairoWidget ()
{
}
bool
CairoWidget::on_button_press_event (GdkEventButton*)
{
focus_handler();
return false;
}
bool
CairoWidget::on_expose_event (GdkEventExpose *ev)
{
@ -194,3 +205,9 @@ CairoWidget::provide_background_for_cairo_widget (Gtk::Widget& w, const Gdk::Col
g_object_set_data (G_OBJECT(w.gobj()), has_cairo_widget_background_info, (void*) 0xfeedface);
}
void
CairoWidget::set_focus_handler (sigc::slot<void> s)
{
focus_handler = s;
}

View file

@ -69,11 +69,30 @@ public:
virtual void render (cairo_t *, cairo_rectangle_t*) = 0;
/* 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>);
protected:
/** Render the widget to the given Cairo context */
virtual bool on_expose_event (GdkEventExpose *);
void on_size_allocate (Gtk::Allocation &);
void on_state_changed (Gtk::StateType);
bool on_button_press_event (GdkEventButton*);
Gdk::Color get_parent_bg ();
/* this is an additional virtual "on_..." method. Glibmm does not
@ -87,6 +106,8 @@ protected:
bool _need_bg;
GdkEventExpose* _current_event_expose; // Valid only when on_expose_event
static sigc::slot<void> focus_handler;
private:
Glib::SignalProxyProperty _name_proxy;
};