diff options
author | Paul Davis <paul@linuxaudiosystems.com> | 2014-09-16 12:42:39 -0400 |
---|---|---|
committer | Paul Davis <paul@linuxaudiosystems.com> | 2014-09-16 12:42:39 -0400 |
commit | 9be64f2648ab7568ead1452da01fa25242549184 (patch) | |
tree | 1c3e96c4cb1f1d163aebff08471957510e0a2979 /libs/gtkmm2ext | |
parent | 261aa3258fb9d740b3fde897cd39575e453f6f41 (diff) |
add a focus handling callback so that all button press events on CairoWidgets will cause a focus reset.
Diffstat (limited to 'libs/gtkmm2ext')
-rw-r--r-- | libs/gtkmm2ext/cairo_widget.cc | 16 | ||||
-rw-r--r-- | libs/gtkmm2ext/gtkmm2ext/cairo_widget.h | 21 |
2 files changed, 37 insertions, 0 deletions
diff --git a/libs/gtkmm2ext/cairo_widget.cc b/libs/gtkmm2ext/cairo_widget.cc index 16e7f29b5f..03c23000a2 100644 --- a/libs/gtkmm2ext/cairo_widget.cc +++ b/libs/gtkmm2ext/cairo_widget.cc @@ -26,6 +26,9 @@ static const char* has_cairo_widget_background_info = "has_cairo_widget_backgrou bool CairoWidget::_flat_buttons = false; +static void noop() { } +sigc::slot<void> CairoWidget::focus_handler (sigc::ptr_fun (noop)); + void CairoWidget::set_source_rgb_a( cairo_t* cr, Gdk::Color col, float a) //ToDo: this one and the Canvas version should be in a shared file (?) { float r = col.get_red_p (); @@ -52,6 +55,13 @@ CairoWidget::~CairoWidget () } bool +CairoWidget::on_button_press_event (GdkEventButton*) +{ + focus_handler(); + return false; +} + +bool CairoWidget::on_expose_event (GdkEventExpose *ev) { cairo_t* cr = gdk_cairo_create (get_window ()->gobj()); @@ -220,3 +230,9 @@ CairoWidget::set_flat_buttons (bool yn) { _flat_buttons = yn; } + +void +CairoWidget::set_focus_handler (sigc::slot<void> s) +{ + focus_handler = s; +} diff --git a/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h b/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h index 2e845b94eb..87002101bd 100644 --- a/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h +++ b/libs/gtkmm2ext/gtkmm2ext/cairo_widget.h @@ -74,12 +74,30 @@ public: static void set_source_rgb_a( cairo_t* cr, Gdk::Color, float a=1.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); void on_style_changed (const Glib::RefPtr<Gtk::Style>&); + bool on_button_press_event (GdkEventButton*); Gdk::Color get_parent_bg (); /* this is an additional virtual "on_..." method. Glibmm does not @@ -95,10 +113,13 @@ protected: static bool _flat_buttons; bool _grabbed; + static sigc::slot<void> focus_handler; + private: Glib::SignalProxyProperty _name_proxy; sigc::connection _parent_style_change; Widget * _current_parent; + }; #endif |