2 Copyright (C) 2014 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "pbd/stacktrace.h"
21 #include "public_editor.h"
24 #include "floating_text_entry.h"
25 #include "gtkmm2ext/doi.h"
26 #include "gtkmm2ext/utils.h"
30 FloatingTextEntry::FloatingTextEntry (Gtk::Window* parent, const std::string& initial_contents)
31 : Gtk::Window (Gtk::WINDOW_POPUP)
32 , entry_changed (false)
33 , by_popup_menu (false)
35 set_name (X_("FloatingTextEntry"));
36 set_position (Gtk::WIN_POS_MOUSE);
39 if (!initial_contents.empty()) {
40 entry.set_text (initial_contents);
44 entry.signal_changed().connect (sigc::mem_fun (*this, &FloatingTextEntry::changed));
45 entry.signal_activate().connect (sigc::mem_fun (*this, &FloatingTextEntry::activated));
46 entry.signal_key_press_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::key_press), false);
47 entry.signal_key_release_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::key_release), false);
48 entry.signal_button_press_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::button_press));
49 entry.signal_populate_popup().connect (sigc::mem_fun (*this, &FloatingTextEntry::populate_popup));
51 entry.select_region (0, -1);
52 // entry.set_state (Gtk::STATE_SELECTED);
55 parent->signal_focus_out_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::entry_focus_out));
62 FloatingTextEntry::populate_popup (Gtk::Menu *)
68 FloatingTextEntry::changed ()
74 FloatingTextEntry::on_realize ()
76 Gtk::Window::on_realize ();
77 get_window()->set_decorations (Gdk::WMDecoration (0));
78 entry.add_modal_grab ();
82 FloatingTextEntry::entry_focus_out (GdkEventFocus* ev)
85 by_popup_menu = false;
89 entry.remove_modal_grab ();
91 use_text (entry.get_text (), 0);
94 delete_when_idle ( this);
99 FloatingTextEntry::button_press (GdkEventButton* ev)
101 if (Gtkmm2ext::event_inside_widget_window (*this, (GdkEvent*) ev)) {
105 /* Clicked outside widget window - edit is done */
106 entry.remove_modal_grab ();
108 /* arrange re-propagation of the event once we go idle */
109 Glib::signal_idle().connect (sigc::bind_return (sigc::bind (sigc::ptr_fun (gtk_main_do_event), gdk_event_copy ((GdkEvent*) ev)), false));
112 use_text (entry.get_text (), 0);
115 delete_when_idle ( this);
121 FloatingTextEntry::activated ()
123 use_text (entry.get_text(), 0); // EMIT SIGNAL
124 delete_when_idle (this);
128 FloatingTextEntry::key_press (GdkEventKey* ev)
130 /* steal escape, tabs from GTK */
132 switch (ev->keyval) {
134 case GDK_ISO_Left_Tab:
142 FloatingTextEntry::key_release (GdkEventKey* ev)
144 switch (ev->keyval) {
147 delete_when_idle (this);
150 case GDK_ISO_Left_Tab:
151 /* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
152 * generates a different ev->keyval, rather than setting
155 use_text (entry.get_text(), -1); // EMIT SIGNAL, move to prev
156 delete_when_idle (this);
160 use_text (entry.get_text(), 1); // EMIT SIGNAL, move to next
161 delete_when_idle (this);
172 FloatingTextEntry::on_hide ()
174 entry.remove_modal_grab ();
176 /* No hide button is shown (no decoration on the window),
177 so being hidden is equivalent to the Escape key or any other
178 method of cancelling the edit.
181 delete_when_idle (this);
182 Gtk::Window::on_hide ();