From f76109d8734983e696959df7e7dc62722d621ccf Mon Sep 17 00:00:00 2001 From: Paul Davis Date: Sun, 2 Nov 2014 08:54:51 -0500 Subject: use modal grab and event_is_inside_widget_window() to provide "expected" behaviour when editing in a FloatingTextEntry --- gtk2_ardour/floating_text_entry.cc | 33 +++++++++++++++++++++++++++++++++ gtk2_ardour/floating_text_entry.h | 11 +++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) (limited to 'gtk2_ardour') diff --git a/gtk2_ardour/floating_text_entry.cc b/gtk2_ardour/floating_text_entry.cc index 21be620ddb..0df7221c84 100644 --- a/gtk2_ardour/floating_text_entry.cc +++ b/gtk2_ardour/floating_text_entry.cc @@ -17,30 +17,61 @@ */ +#include "pbd/stacktrace.h" + #include "floating_text_entry.h" #include "gtkmm2ext/doi.h" +#include "gtkmm2ext/utils.h" #include "i18n.h" FloatingTextEntry::FloatingTextEntry () : ArdourWindow ("") + , entry_changed (false) { set_name (X_("FloatingTextEntry")); set_position (Gtk::WIN_POS_MOUSE); set_border_width (0); entry.show (); + entry.signal_changed().connect (sigc::mem_fun (*this, &FloatingTextEntry::changed)); entry.signal_activate().connect (sigc::mem_fun (*this, &FloatingTextEntry::activated)); entry.signal_key_press_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::key_press)); + entry.signal_button_press_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::button_press)); add (entry); } +void +FloatingTextEntry::changed () +{ + entry_changed = true; +} + void FloatingTextEntry::on_realize () { ArdourWindow::on_realize (); get_window()->set_decorations (Gdk::WMDecoration (0)); + entry.add_modal_grab (); +} + +bool +FloatingTextEntry::button_press (GdkEventButton* ev) +{ + if (Gtkmm2ext::event_inside_widget_window (*this, (GdkEvent*) ev)) { + return true; + } + + /* Clicked outside widget window - edit is done */ + + if (entry_changed) { + use_text (entry.get_text ()); + } + + delete_when_idle ( this); + + return false; } void @@ -67,6 +98,8 @@ FloatingTextEntry::key_press (GdkEventKey* ev) void FloatingTextEntry::on_hide () { + entry.remove_modal_grab (); + /* No hide button is shown (no decoration on the window), so being hidden is equivalent to the Escape key or any other method of cancelling the edit. diff --git a/gtk2_ardour/floating_text_entry.h b/gtk2_ardour/floating_text_entry.h index 41ad7f6d35..0471a19596 100644 --- a/gtk2_ardour/floating_text_entry.h +++ b/gtk2_ardour/floating_text_entry.h @@ -33,12 +33,19 @@ class FloatingTextEntry : public ArdourWindow private: Gtk::Entry entry; + bool entry_changed; + + /* handlers for Entry events */ bool key_press (GdkEventKey*); + void activated (); + bool button_press (GdkEventButton*); + void changed (); + + /* handlers for window events */ + void on_realize (); void on_hide (); - void activated (); - }; #endif // __ardour_window_h__ -- cgit v1.2.3