2014-10-31 12:26:57 -04:00
|
|
|
/*
|
2014-11-25 05:17:14 -05:00
|
|
|
Copyright (C) 2014 Paul Davis
|
2014-10-31 12:26:57 -04:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
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.
|
2014-10-31 12:26:57 -04:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
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.
|
2014-10-31 12:26:57 -04:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2014-10-31 12:26:57 -04:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-11-02 08:54:51 -05:00
|
|
|
#include "pbd/stacktrace.h"
|
2014-11-24 17:28:33 -05:00
|
|
|
#include "public_editor.h"
|
|
|
|
|
2014-11-02 08:54:51 -05:00
|
|
|
|
2014-10-31 12:26:57 -04:00
|
|
|
#include "floating_text_entry.h"
|
|
|
|
#include "gtkmm2ext/doi.h"
|
2014-11-02 08:54:51 -05:00
|
|
|
#include "gtkmm2ext/utils.h"
|
2014-10-31 12:26:57 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2014-10-31 12:26:57 -04:00
|
|
|
|
2015-07-07 22:12:21 -04:00
|
|
|
FloatingTextEntry::FloatingTextEntry (Gtk::Window* parent, const std::string& initial_contents)
|
2014-11-24 17:28:33 -05:00
|
|
|
: Gtk::Window (Gtk::WINDOW_POPUP)
|
2014-11-02 08:54:51 -05:00
|
|
|
, entry_changed (false)
|
2016-05-21 19:17:11 -04:00
|
|
|
, by_popup_menu (false)
|
2014-10-31 12:26:57 -04:00
|
|
|
{
|
2016-07-02 13:53:30 -04:00
|
|
|
//set_name (X_("FloatingTextEntry"));
|
2014-10-31 12:26:57 -04:00
|
|
|
set_position (Gtk::WIN_POS_MOUSE);
|
2014-11-25 05:17:14 -05:00
|
|
|
set_border_width (0);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
if (!initial_contents.empty()) {
|
|
|
|
entry.set_text (initial_contents);
|
|
|
|
}
|
|
|
|
|
|
|
|
entry.show ();
|
2017-03-05 10:42:40 -05:00
|
|
|
_connections.push_back (entry.signal_changed().connect (sigc::mem_fun (*this, &FloatingTextEntry::changed)));
|
|
|
|
_connections.push_back (entry.signal_activate().connect (sigc::mem_fun (*this, &FloatingTextEntry::activated)));
|
|
|
|
_connections.push_back (entry.signal_key_press_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::key_press), false));
|
|
|
|
_connections.push_back (entry.signal_key_release_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::key_release), false));
|
|
|
|
_connections.push_back (entry.signal_button_press_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::button_press)));
|
|
|
|
_connections.push_back (entry.signal_populate_popup().connect (sigc::mem_fun (*this, &FloatingTextEntry::populate_popup)));
|
2016-05-21 19:17:11 -04:00
|
|
|
|
|
|
|
entry.select_region (0, -1);
|
2015-07-07 22:12:21 -04:00
|
|
|
|
|
|
|
if (parent) {
|
2017-03-05 10:42:40 -05:00
|
|
|
_connections.push_back (parent->signal_focus_out_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::entry_focus_out)));
|
2015-07-07 22:12:21 -04:00
|
|
|
}
|
2014-11-25 05:17:14 -05:00
|
|
|
|
|
|
|
add (entry);
|
2014-10-31 12:26:57 -04:00
|
|
|
}
|
|
|
|
|
2016-05-21 19:17:11 -04:00
|
|
|
void
|
|
|
|
FloatingTextEntry::populate_popup (Gtk::Menu *)
|
|
|
|
{
|
|
|
|
by_popup_menu = true;
|
|
|
|
}
|
|
|
|
|
2014-11-02 08:54:51 -05:00
|
|
|
void
|
|
|
|
FloatingTextEntry::changed ()
|
|
|
|
{
|
2014-11-25 05:17:14 -05:00
|
|
|
entry_changed = true;
|
2014-11-02 08:54:51 -05:00
|
|
|
}
|
|
|
|
|
2014-10-31 12:26:57 -04:00
|
|
|
void
|
|
|
|
FloatingTextEntry::on_realize ()
|
|
|
|
{
|
2014-11-25 05:17:14 -05:00
|
|
|
Gtk::Window::on_realize ();
|
|
|
|
get_window()->set_decorations (Gdk::WMDecoration (0));
|
|
|
|
entry.add_modal_grab ();
|
2014-11-02 08:54:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-11-24 17:28:33 -05:00
|
|
|
FloatingTextEntry::entry_focus_out (GdkEventFocus* ev)
|
2014-11-02 08:54:51 -05:00
|
|
|
{
|
2016-05-21 19:17:11 -04:00
|
|
|
if (by_popup_menu) {
|
|
|
|
by_popup_menu = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
entry.remove_modal_grab ();
|
|
|
|
if (entry_changed) {
|
2016-05-21 19:17:11 -04:00
|
|
|
use_text (entry.get_text (), 0);
|
2014-11-25 05:17:14 -05:00
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2017-03-05 10:42:40 -05:00
|
|
|
idle_delete_self ();
|
2014-11-25 05:17:14 -05:00
|
|
|
return false;
|
2014-11-24 17:28:33 -05:00
|
|
|
}
|
2014-11-02 08:54:51 -05:00
|
|
|
|
2014-11-24 17:28:33 -05:00
|
|
|
bool
|
|
|
|
FloatingTextEntry::button_press (GdkEventButton* ev)
|
|
|
|
{
|
2014-11-25 05:17:14 -05:00
|
|
|
if (Gtkmm2ext::event_inside_widget_window (*this, (GdkEvent*) ev)) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-11-02 11:25:31 -05:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
/* Clicked outside widget window - edit is done */
|
|
|
|
entry.remove_modal_grab ();
|
2014-11-02 11:25:31 -05:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
/* arrange re-propagation of the event once we go idle */
|
|
|
|
Glib::signal_idle().connect (sigc::bind_return (sigc::bind (sigc::ptr_fun (gtk_main_do_event), gdk_event_copy ((GdkEvent*) ev)), false));
|
2014-11-02 11:25:31 -05:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
if (entry_changed) {
|
2016-05-21 19:17:11 -04:00
|
|
|
use_text (entry.get_text (), 0);
|
2014-11-25 05:17:14 -05:00
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2017-03-05 10:42:40 -05:00
|
|
|
idle_delete_self ();
|
2014-11-02 11:25:31 -05:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
return false;
|
2014-10-31 12:26:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FloatingTextEntry::activated ()
|
|
|
|
{
|
2016-05-21 19:17:11 -04:00
|
|
|
use_text (entry.get_text(), 0); // EMIT SIGNAL
|
2017-03-05 10:42:40 -05:00
|
|
|
idle_delete_self ();
|
2014-10-31 12:26:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FloatingTextEntry::key_press (GdkEventKey* ev)
|
2016-05-21 19:17:11 -04:00
|
|
|
{
|
|
|
|
/* steal escape, tabs from GTK */
|
|
|
|
|
|
|
|
switch (ev->keyval) {
|
|
|
|
case GDK_Escape:
|
|
|
|
case GDK_ISO_Left_Tab:
|
|
|
|
case GDK_Tab:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FloatingTextEntry::key_release (GdkEventKey* ev)
|
2014-10-31 12:26:57 -04:00
|
|
|
{
|
2014-11-25 05:17:14 -05:00
|
|
|
switch (ev->keyval) {
|
|
|
|
case GDK_Escape:
|
2016-05-21 19:17:11 -04:00
|
|
|
/* cancel edit */
|
2017-03-05 10:42:40 -05:00
|
|
|
idle_delete_self ();
|
2016-05-21 19:17:11 -04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case GDK_ISO_Left_Tab:
|
|
|
|
/* Shift+Tab Keys Pressed. Note that for Shift+Tab, GDK actually
|
|
|
|
* generates a different ev->keyval, rather than setting
|
|
|
|
* ev->state.
|
|
|
|
*/
|
|
|
|
use_text (entry.get_text(), -1); // EMIT SIGNAL, move to prev
|
2017-03-05 10:42:40 -05:00
|
|
|
idle_delete_self ();
|
2016-05-21 19:17:11 -04:00
|
|
|
return true;
|
|
|
|
|
|
|
|
case GDK_Tab:
|
|
|
|
use_text (entry.get_text(), 1); // EMIT SIGNAL, move to next
|
2017-03-05 10:42:40 -05:00
|
|
|
idle_delete_self ();
|
2014-11-25 05:17:14 -05:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-05-21 19:17:11 -04:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
return false;
|
2014-10-31 12:26:57 -04:00
|
|
|
}
|
|
|
|
|
2016-05-21 19:17:11 -04:00
|
|
|
|
2014-10-31 12:26:57 -04:00
|
|
|
void
|
|
|
|
FloatingTextEntry::on_hide ()
|
|
|
|
{
|
2014-11-25 05:17:14 -05:00
|
|
|
entry.remove_modal_grab ();
|
2014-11-02 08:54:51 -05:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* No hide button is shown (no decoration on the window),
|
|
|
|
so being hidden is equivalent to the Escape key or any other
|
2014-11-25 05:17:14 -05:00
|
|
|
method of cancelling the edit.
|
|
|
|
*/
|
2014-10-31 12:26:57 -04:00
|
|
|
|
2017-03-05 10:42:40 -05:00
|
|
|
idle_delete_self ();
|
2014-11-25 05:17:14 -05:00
|
|
|
Gtk::Window::on_hide ();
|
2014-10-31 12:26:57 -04:00
|
|
|
}
|
2017-03-05 10:42:40 -05:00
|
|
|
|
|
|
|
void
|
|
|
|
FloatingTextEntry::idle_delete_self ()
|
|
|
|
{
|
|
|
|
for (std::list<sigc::connection>::iterator i = _connections.begin(); i != _connections.end(); ++i) {
|
|
|
|
i->disconnect ();
|
|
|
|
}
|
|
|
|
delete_when_idle (this);
|
|
|
|
}
|