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)
|
2017-07-28 20:05:28 -04:00
|
|
|
: Gtk::Window ()
|
|
|
|
, entry_changed (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);
|
2017-07-28 20:05:28 -04:00
|
|
|
set_type_hint(Gdk::WINDOW_TYPE_HINT_POPUP_MENU);
|
|
|
|
set_resizable (false);
|
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)));
|
2016-05-21 19:17:11 -04:00
|
|
|
|
|
|
|
entry.select_region (0, -1);
|
2015-07-07 22:12:21 -04:00
|
|
|
|
|
|
|
if (parent) {
|
2017-07-28 20:05:28 -04:00
|
|
|
set_transient_for (*parent);
|
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
|
|
|
}
|
|
|
|
|
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));
|
2017-07-28 20:05:28 -04:00
|
|
|
set_keep_above (true);
|
2014-11-25 05:17:14 -05:00
|
|
|
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
|
|
|
{
|
2014-11-25 05:17:14 -05:00
|
|
|
entry.remove_modal_grab ();
|
|
|
|
if (entry_changed) {
|
2017-07-20 17:41:18 -04:00
|
|
|
disconect_signals ();
|
|
|
|
use_text (entry.get_text (), 0); /* EMIT SIGNAL */
|
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) {
|
2017-07-20 17:41:18 -04:00
|
|
|
disconect_signals ();
|
|
|
|
use_text (entry.get_text (), 0); /* EMIT SIGNAL */
|
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 ()
|
|
|
|
{
|
2017-07-20 17:41:18 -04:00
|
|
|
disconect_signals ();
|
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.
|
|
|
|
*/
|
2017-07-20 17:41:18 -04:00
|
|
|
disconect_signals ();
|
2016-05-21 19:17:11 -04:00
|
|
|
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:
|
2017-07-20 17:41:18 -04:00
|
|
|
disconect_signals ();
|
2016-05-21 19:17:11 -04:00
|
|
|
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),
|
2017-07-20 17:41:18 -04:00
|
|
|
* so being hidden is equivalent to the Escape key or any other
|
|
|
|
* method of cancelling the edit.
|
|
|
|
*
|
|
|
|
* This is also used during disconect_signals() before calling
|
|
|
|
* use_text (). see note below.
|
|
|
|
*
|
|
|
|
* If signals are already disconnected, idle-delete must be
|
|
|
|
* in progress already.
|
|
|
|
*/
|
|
|
|
if (!_connections.empty ()) {
|
|
|
|
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
|
2017-07-20 17:41:18 -04:00
|
|
|
FloatingTextEntry::disconect_signals ()
|
2017-03-05 10:42:40 -05:00
|
|
|
{
|
|
|
|
for (std::list<sigc::connection>::iterator i = _connections.begin(); i != _connections.end(); ++i) {
|
|
|
|
i->disconnect ();
|
|
|
|
}
|
2017-07-21 12:58:51 -04:00
|
|
|
_connections.clear ();
|
2017-07-20 17:41:18 -04:00
|
|
|
/* the entry is floating on-top, emitting use_text()
|
|
|
|
* may result in another dialog being shown (cannot rename track)
|
|
|
|
* which would
|
|
|
|
* - be stacked below the floating text entry
|
|
|
|
* - return focus to the entry when closedA
|
|
|
|
* so we hide the entry here.
|
|
|
|
*/
|
|
|
|
hide ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
FloatingTextEntry::idle_delete_self ()
|
|
|
|
{
|
|
|
|
disconect_signals ();
|
2017-03-05 10:42:40 -05:00
|
|
|
delete_when_idle (this);
|
|
|
|
}
|