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
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
2014-11-05 07:08:17 -05:00
|
|
|
FloatingTextEntry::FloatingTextEntry (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)
|
2014-10-31 12:26:57 -04:00
|
|
|
{
|
2014-11-25 05:17:14 -05: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 ();
|
|
|
|
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));
|
|
|
|
PublicEditor::instance ().signal_focus_out_event().connect (sigc::mem_fun (*this, &FloatingTextEntry::entry_focus_out));
|
|
|
|
|
|
|
|
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));
|
|
|
|
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) {
|
|
|
|
use_text (entry.get_text ());
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
delete_when_idle ( this);
|
|
|
|
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) {
|
|
|
|
use_text (entry.get_text ());
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
delete_when_idle ( this);
|
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 ()
|
|
|
|
{
|
2014-11-25 05:17:14 -05:00
|
|
|
use_text (entry.get_text()); // EMIT SIGNAL
|
|
|
|
delete_when_idle (this);
|
2014-10-31 12:26:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
FloatingTextEntry::key_press (GdkEventKey* ev)
|
|
|
|
{
|
2014-11-25 05:17:14 -05:00
|
|
|
switch (ev->keyval) {
|
|
|
|
case GDK_Escape:
|
|
|
|
delete_when_idle (this);
|
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
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
|
|
|
|
2014-11-25 05:17:14 -05:00
|
|
|
delete_when_idle (this);
|
|
|
|
Gtk::Window::on_hide ();
|
2014-10-31 12:26:57 -04:00
|
|
|
}
|