2008-06-02 17:41:35 -04:00
|
|
|
/*
|
2019-08-02 22:40:09 -04:00
|
|
|
* Copyright (C) 1999-2019 Paul Davis <paul@linuxaudiosystems.com>
|
|
|
|
* Copyright (C) 2005 Taybin Rutkin <taybin@taybin.com>
|
|
|
|
* Copyright (C) 2006-2007 Tim Mayberry <mojofunk@gmail.com>
|
|
|
|
* Copyright (C) 2007-2011 David Robillard <d@drobilla.net>
|
|
|
|
* Copyright (C) 2007-2011 Doug McLain <doug@nostar.net>
|
|
|
|
* Copyright (C) 2009-2012 Carl Hetherington <carl@carlh.net>
|
|
|
|
* Copyright (C) 2013 John Emmas <john@creativepost.co.uk>
|
|
|
|
* Copyright (C) 2014-2019 Robin Gareus <robin@gareus.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <climits>
|
|
|
|
#include <cctype>
|
|
|
|
|
|
|
|
#include <gtkmm.h>
|
2012-12-07 08:43:45 -05:00
|
|
|
|
|
|
|
#include "pbd/error.h"
|
|
|
|
#include "pbd/touchable.h"
|
|
|
|
#include "pbd/failed_constructor.h"
|
2020-01-18 12:17:44 -05:00
|
|
|
#include "pbd/localtime_r.h"
|
2012-12-07 08:43:45 -05:00
|
|
|
#include "pbd/pthread_utils.h"
|
|
|
|
#include "pbd/replace_all.h"
|
|
|
|
|
|
|
|
#include "gtkmm2ext/application.h"
|
2015-08-10 14:31:59 -04:00
|
|
|
#include "gtkmm2ext/bindings.h"
|
2012-12-07 08:43:45 -05:00
|
|
|
#include "gtkmm2ext/gtk_ui.h"
|
|
|
|
#include "gtkmm2ext/textviewer.h"
|
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
#include "gtkmm2ext/window_title.h"
|
|
|
|
#include "gtkmm2ext/actions.h"
|
|
|
|
#include "gtkmm2ext/activatable.h"
|
|
|
|
#include "gtkmm2ext/actions.h"
|
2013-10-17 14:36:41 -04:00
|
|
|
#include "gtkmm2ext/gui_thread.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2016-07-14 14:44:52 -04:00
|
|
|
#include "pbd/i18n.h"
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
using namespace Gtkmm2ext;
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Glib;
|
|
|
|
using namespace PBD;
|
|
|
|
using std::map;
|
|
|
|
|
2015-07-23 08:59:32 -04:00
|
|
|
UI* UI::theGtkUI = 0;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2011-02-07 13:21:50 -05:00
|
|
|
BaseUI::RequestType Gtkmm2ext::NullMessage = BaseUI::new_request_type();
|
2008-06-02 17:41:35 -04:00
|
|
|
BaseUI::RequestType Gtkmm2ext::ErrorMessage = BaseUI::new_request_type();
|
|
|
|
BaseUI::RequestType Gtkmm2ext::TouchDisplay = BaseUI::new_request_type();
|
|
|
|
BaseUI::RequestType Gtkmm2ext::StateChange = BaseUI::new_request_type();
|
|
|
|
BaseUI::RequestType Gtkmm2ext::SetTip = BaseUI::new_request_type();
|
|
|
|
BaseUI::RequestType Gtkmm2ext::AddIdle = BaseUI::new_request_type();
|
|
|
|
BaseUI::RequestType Gtkmm2ext::AddTimeout = BaseUI::new_request_type();
|
|
|
|
|
2024-10-19 18:16:01 -04:00
|
|
|
#include "pbd/abstract_ui.inc.cc" /* instantiate the template */
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2014-05-23 14:48:56 -04:00
|
|
|
template class AbstractUI<Gtkmm2ext::UIRequest>;
|
|
|
|
|
2015-12-29 05:03:09 -05:00
|
|
|
UI::UI (string application_name, string thread_name, int *argc, char ***argv)
|
|
|
|
: AbstractUI<UIRequest> (thread_name)
|
2012-05-14 13:07:53 -04:00
|
|
|
, _receiver (*this)
|
2015-08-10 14:31:59 -04:00
|
|
|
, global_bindings (0)
|
2014-06-15 07:04:47 -04:00
|
|
|
, errors (0)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
theMain = new Main (argc, argv);
|
|
|
|
|
2020-04-30 13:03:49 -04:00
|
|
|
char buf[18];
|
|
|
|
/* pthread public name has a 16 char limit */
|
|
|
|
snprintf (buf, sizeof (buf), "%.11sGUI", PROGRAM_NAME);
|
|
|
|
pthread_set_name (buf);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
_active = false;
|
|
|
|
|
|
|
|
if (!theGtkUI) {
|
|
|
|
theGtkUI = this;
|
|
|
|
} else {
|
|
|
|
fatal << "duplicate UI requested" << endmsg;
|
2014-11-14 04:47:43 -05:00
|
|
|
abort(); /* NOTREACHED */
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
2009-12-08 22:05:14 -05:00
|
|
|
/* the GUI event loop runs in the main thread of the app,
|
2022-02-28 16:34:02 -05:00
|
|
|
* which is assumed to have called this.
|
|
|
|
*/
|
|
|
|
_run_loop_thread = PBD::Thread::self ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-12-10 12:45:18 -05:00
|
|
|
/* store "this" as the UI-for-thread of this thread, same argument
|
|
|
|
as for previous line.
|
|
|
|
*/
|
|
|
|
|
2009-12-21 13:23:07 -05:00
|
|
|
set_event_loop_for_thread (this);
|
2009-12-08 22:05:14 -05:00
|
|
|
|
|
|
|
/* attach our request source to the default main context */
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2013-07-11 12:56:35 -04:00
|
|
|
attach_request_source ();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-10-22 16:05:15 -04:00
|
|
|
errors = new TextViewer (800,600);
|
2009-10-22 15:00:40 -04:00
|
|
|
errors->text().set_editable (false);
|
2008-06-02 17:41:35 -04:00
|
|
|
errors->text().set_name ("ErrorText");
|
2019-03-20 14:15:22 -04:00
|
|
|
errors->signal_unmap().connect (sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), X_("Editor/toggle-log-window")));
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2015-12-29 05:03:09 -05:00
|
|
|
Glib::set_application_name (application_name);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
WindowTitle title(Glib::get_application_name());
|
|
|
|
title += _("Log");
|
|
|
|
errors->set_title (title.get_string());
|
|
|
|
|
|
|
|
errors->dismiss_button().set_name ("ErrorLogCloseButton");
|
2012-04-15 15:28:44 -04:00
|
|
|
errors->signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), (Window *) errors));
|
2008-12-12 09:43:24 -05:00
|
|
|
errors->set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
//load_rcfile (rcfile);
|
2010-08-16 22:48:24 -04:00
|
|
|
|
|
|
|
/* instantiate the Application singleton */
|
|
|
|
|
|
|
|
Application::instance();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
UI::~UI ()
|
|
|
|
{
|
2013-10-07 20:27:04 -04:00
|
|
|
_receiver.hangup ();
|
2014-06-15 07:04:47 -04:00
|
|
|
delete (errors);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2022-02-28 16:34:02 -05:00
|
|
|
UI::caller_is_ui_thread () const
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
2022-02-28 16:34:02 -05:00
|
|
|
return caller_is_self ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
UI::load_rcfile (string path, bool themechange)
|
|
|
|
{
|
2009-10-22 15:53:22 -04:00
|
|
|
/* Yes, pointers to Glib::RefPtr. If these are not kept around,
|
|
|
|
* a segfault somewhere deep in the wonderfully robust glib will result.
|
|
|
|
* This does not occur if wiget.get_style is used instead of rc.get_style below,
|
2015-10-04 14:51:05 -04:00
|
|
|
* except that doesn't actually work...
|
2009-12-08 22:05:14 -05:00
|
|
|
*/
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2009-10-22 15:53:22 -04:00
|
|
|
static Glib::RefPtr<Style>* fatal_style = 0;
|
|
|
|
static Glib::RefPtr<Style>* error_style = 0;
|
|
|
|
static Glib::RefPtr<Style>* warning_style = 0;
|
|
|
|
static Glib::RefPtr<Style>* info_style = 0;
|
2020-10-13 15:46:52 -04:00
|
|
|
static Glib::RefPtr<Style>* debug_style = 0;
|
2009-10-22 15:53:22 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (path.length() == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-02-14 16:49:43 -05:00
|
|
|
if (!Glib::file_test (path, Glib::FILE_TEST_EXISTS|Glib::FILE_TEST_IS_REGULAR)) {
|
2009-10-22 15:00:40 -04:00
|
|
|
error << "UI: couldn't find rc file \""
|
2008-06-02 17:41:35 -04:00
|
|
|
<< path
|
|
|
|
<< '"'
|
|
|
|
<< endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
2009-10-22 15:00:40 -04:00
|
|
|
|
2011-02-15 13:02:50 -05:00
|
|
|
RC rc (path.c_str());
|
|
|
|
//this is buggy in gtkmm for some reason, so use C
|
|
|
|
//RC::reset_styles (Gtk::Settings::get_default());
|
|
|
|
gtk_rc_reset_styles (gtk_settings_get_default());
|
2011-02-14 16:49:43 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
theme_changed.emit();
|
|
|
|
|
|
|
|
if (themechange) {
|
|
|
|
return 0; //Don't continue on every time there is a theme change
|
|
|
|
}
|
|
|
|
|
|
|
|
/* have to pack widgets into a toplevel window so that styles will stick */
|
|
|
|
|
|
|
|
Window temp_window (WINDOW_TOPLEVEL);
|
2009-10-22 15:53:22 -04:00
|
|
|
temp_window.ensure_style ();
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
HBox box;
|
2009-10-22 15:53:22 -04:00
|
|
|
Label fatal_widget;
|
|
|
|
Label error_widget;
|
|
|
|
Label warning_widget;
|
|
|
|
Label info_widget;
|
2020-10-13 15:46:52 -04:00
|
|
|
Label debug_widget;
|
2008-06-02 17:41:35 -04:00
|
|
|
RefPtr<Gtk::Style> style;
|
|
|
|
RefPtr<TextBuffer> buffer (errors->text().get_buffer());
|
|
|
|
|
2009-10-22 15:53:22 -04:00
|
|
|
box.pack_start (fatal_widget);
|
|
|
|
box.pack_start (error_widget);
|
|
|
|
box.pack_start (warning_widget);
|
|
|
|
box.pack_start (info_widget);
|
2020-10-13 15:46:52 -04:00
|
|
|
box.pack_start (debug_widget);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
fatal_ptag = buffer->create_tag();
|
|
|
|
fatal_mtag = buffer->create_tag();
|
2020-10-13 15:46:52 -04:00
|
|
|
error_ptag = buffer->create_tag();
|
|
|
|
error_mtag = buffer->create_tag();
|
2008-06-02 17:41:35 -04:00
|
|
|
warning_ptag = buffer->create_tag();
|
|
|
|
warning_mtag = buffer->create_tag();
|
|
|
|
info_ptag = buffer->create_tag();
|
|
|
|
info_mtag = buffer->create_tag();
|
2020-10-13 15:46:52 -04:00
|
|
|
debug_ptag = buffer->create_tag();
|
|
|
|
debug_mtag = buffer->create_tag();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-10-22 15:53:22 -04:00
|
|
|
fatal_widget.set_name ("FatalMessage");
|
|
|
|
delete fatal_style;
|
2010-07-08 22:45:15 -04:00
|
|
|
|
|
|
|
/* This next line and the similar ones below are sketchily
|
|
|
|
* guessed to fix #2885. I think maybe that problems occur
|
|
|
|
* because with gtk_rc_get_style (to quote its docs) "no
|
|
|
|
* refcount is added to the returned style". So I've switched
|
|
|
|
* this to use Glib::wrap with take_copy == true, which requires
|
|
|
|
* all the nasty casts and calls to plain-old-C GTK.
|
|
|
|
*
|
|
|
|
* At worst I think this causes a memory leak; at least it appears
|
|
|
|
* to fix the bug.
|
|
|
|
*
|
|
|
|
* I could be wrong about any or all of the above.
|
|
|
|
*/
|
|
|
|
fatal_style = new Glib::RefPtr<Style> (Glib::wrap (gtk_rc_get_style (reinterpret_cast<GtkWidget*> (fatal_widget.gobj())), true));
|
2009-10-22 15:53:22 -04:00
|
|
|
|
|
|
|
fatal_ptag->property_font_desc().set_value((*fatal_style)->get_font());
|
|
|
|
fatal_ptag->property_foreground_gdk().set_value((*fatal_style)->get_fg(STATE_ACTIVE));
|
|
|
|
fatal_ptag->property_background_gdk().set_value((*fatal_style)->get_bg(STATE_ACTIVE));
|
|
|
|
fatal_mtag->property_font_desc().set_value((*fatal_style)->get_font());
|
|
|
|
fatal_mtag->property_foreground_gdk().set_value((*fatal_style)->get_fg(STATE_NORMAL));
|
|
|
|
fatal_mtag->property_background_gdk().set_value((*fatal_style)->get_bg(STATE_NORMAL));
|
|
|
|
|
|
|
|
error_widget.set_name ("ErrorMessage");
|
|
|
|
delete error_style;
|
2010-07-08 22:45:15 -04:00
|
|
|
error_style = new Glib::RefPtr<Style> (Glib::wrap (gtk_rc_get_style (reinterpret_cast<GtkWidget*> (error_widget.gobj())), true));
|
2009-10-22 15:53:22 -04:00
|
|
|
|
|
|
|
error_ptag->property_font_desc().set_value((*error_style)->get_font());
|
|
|
|
error_ptag->property_foreground_gdk().set_value((*error_style)->get_fg(STATE_ACTIVE));
|
|
|
|
error_ptag->property_background_gdk().set_value((*error_style)->get_bg(STATE_ACTIVE));
|
|
|
|
error_mtag->property_font_desc().set_value((*error_style)->get_font());
|
|
|
|
error_mtag->property_foreground_gdk().set_value((*error_style)->get_fg(STATE_NORMAL));
|
|
|
|
error_mtag->property_background_gdk().set_value((*error_style)->get_bg(STATE_NORMAL));
|
|
|
|
|
|
|
|
warning_widget.set_name ("WarningMessage");
|
|
|
|
delete warning_style;
|
2010-07-08 22:45:15 -04:00
|
|
|
warning_style = new Glib::RefPtr<Style> (Glib::wrap (gtk_rc_get_style (reinterpret_cast<GtkWidget*> (warning_widget.gobj())), true));
|
2009-10-22 15:53:22 -04:00
|
|
|
|
|
|
|
warning_ptag->property_font_desc().set_value((*warning_style)->get_font());
|
|
|
|
warning_ptag->property_foreground_gdk().set_value((*warning_style)->get_fg(STATE_ACTIVE));
|
|
|
|
warning_ptag->property_background_gdk().set_value((*warning_style)->get_bg(STATE_ACTIVE));
|
|
|
|
warning_mtag->property_font_desc().set_value((*warning_style)->get_font());
|
|
|
|
warning_mtag->property_foreground_gdk().set_value((*warning_style)->get_fg(STATE_NORMAL));
|
|
|
|
warning_mtag->property_background_gdk().set_value((*warning_style)->get_bg(STATE_NORMAL));
|
|
|
|
|
|
|
|
info_widget.set_name ("InfoMessage");
|
|
|
|
delete info_style;
|
2010-07-08 22:45:15 -04:00
|
|
|
info_style = new Glib::RefPtr<Style> (Glib::wrap (gtk_rc_get_style (reinterpret_cast<GtkWidget*> (info_widget.gobj())), true));
|
2009-10-22 15:53:22 -04:00
|
|
|
|
|
|
|
info_ptag->property_font_desc().set_value((*info_style)->get_font());
|
|
|
|
info_ptag->property_foreground_gdk().set_value((*info_style)->get_fg(STATE_ACTIVE));
|
|
|
|
info_ptag->property_background_gdk().set_value((*info_style)->get_bg(STATE_ACTIVE));
|
|
|
|
info_mtag->property_font_desc().set_value((*info_style)->get_font());
|
|
|
|
info_mtag->property_foreground_gdk().set_value((*info_style)->get_fg(STATE_NORMAL));
|
|
|
|
info_mtag->property_background_gdk().set_value((*info_style)->get_bg(STATE_NORMAL));
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2020-10-13 15:46:52 -04:00
|
|
|
debug_widget.set_name ("DebugMessage");
|
|
|
|
delete debug_style;
|
|
|
|
debug_style = new Glib::RefPtr<Style> (Glib::wrap (gtk_rc_get_style (reinterpret_cast<GtkWidget*> (debug_widget.gobj())), true));
|
|
|
|
|
|
|
|
debug_ptag->property_font_desc().set_value((*debug_style)->get_font());
|
|
|
|
debug_ptag->property_foreground_gdk().set_value((*debug_style)->get_fg(STATE_ACTIVE));
|
|
|
|
debug_ptag->property_background_gdk().set_value((*debug_style)->get_bg(STATE_ACTIVE));
|
|
|
|
debug_mtag->property_font_desc().set_value((*debug_style)->get_font());
|
|
|
|
debug_mtag->property_foreground_gdk().set_value((*debug_style)->get_fg(STATE_NORMAL));
|
|
|
|
debug_mtag->property_background_gdk().set_value((*debug_style)->get_bg(STATE_NORMAL));
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::run (Receiver &old_receiver)
|
|
|
|
{
|
2020-10-13 15:46:52 -04:00
|
|
|
_receiver.listen_to (debug);
|
2012-05-14 13:07:53 -04:00
|
|
|
_receiver.listen_to (info);
|
|
|
|
_receiver.listen_to (warning);
|
2020-10-13 15:46:52 -04:00
|
|
|
_receiver.listen_to (error);
|
2012-05-14 13:07:53 -04:00
|
|
|
_receiver.listen_to (fatal);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2009-07-17 18:12:21 -04:00
|
|
|
/* stop the old receiver (text/console) once we hit the first idle */
|
|
|
|
|
|
|
|
Glib::signal_idle().connect (bind_return (mem_fun (old_receiver, &Receiver::hangup), false));
|
|
|
|
|
2013-10-07 20:27:04 -04:00
|
|
|
if (starting ()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-22 15:00:40 -04:00
|
|
|
_active = true;
|
2008-06-02 17:41:35 -04:00
|
|
|
theMain->run ();
|
|
|
|
_active = false;
|
2013-10-07 20:27:04 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UI::running ()
|
|
|
|
{
|
|
|
|
return _active;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::quit ()
|
|
|
|
{
|
|
|
|
UIRequest *req = get_request (Quit);
|
|
|
|
|
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_request (req);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool idle_quit ()
|
|
|
|
{
|
|
|
|
Main::quit ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::do_quit ()
|
|
|
|
{
|
|
|
|
if (getenv ("ARDOUR_RUNNING_UNDER_VALGRIND")) {
|
|
|
|
Main::quit ();
|
|
|
|
} else {
|
|
|
|
Glib::signal_idle().connect (sigc::ptr_fun (idle_quit));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::touch_display (Touchable *display)
|
|
|
|
{
|
|
|
|
UIRequest *req = get_request (TouchDisplay);
|
|
|
|
|
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->display = display;
|
|
|
|
|
|
|
|
send_request (req);
|
2009-10-22 15:00:40 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2010-02-08 19:50:24 -05:00
|
|
|
void
|
|
|
|
UI::set_tip (Widget &w, const gchar *tip)
|
|
|
|
{
|
|
|
|
set_tip(&w, tip, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::set_tip (Widget &w, const std::string& tip)
|
|
|
|
{
|
|
|
|
set_tip(&w, tip.c_str(), "");
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
|
|
|
UI::set_tip (Widget *w, const gchar *tip, const gchar *hlp)
|
|
|
|
{
|
|
|
|
UIRequest *req = get_request (SetTip);
|
|
|
|
|
2010-02-08 19:50:24 -05:00
|
|
|
std::string msg(tip);
|
|
|
|
|
|
|
|
Glib::RefPtr<Gtk::Action> action = w->get_action();
|
2011-11-24 00:36:31 -05:00
|
|
|
|
|
|
|
if (!action) {
|
|
|
|
Gtkmm2ext::Activatable* activatable;
|
|
|
|
if ((activatable = dynamic_cast<Gtkmm2ext::Activatable*>(w))) {
|
|
|
|
action = activatable->get_related_action();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-08 19:50:24 -05:00
|
|
|
if (action) {
|
2022-04-08 14:09:37 -04:00
|
|
|
/* get_bindings_from_widget_hierarchy */
|
2021-09-19 12:46:06 -04:00
|
|
|
Widget* ww = w;
|
|
|
|
Bindings* bindings = NULL;
|
|
|
|
do {
|
|
|
|
bindings = (Bindings*) ww->get_data ("ardour-bindings");
|
|
|
|
if (bindings) {
|
|
|
|
break;
|
2015-08-10 14:31:59 -04:00
|
|
|
}
|
2021-09-19 12:46:06 -04:00
|
|
|
ww = ww->get_parent ();
|
|
|
|
} while (ww);
|
2015-08-10 14:31:59 -04:00
|
|
|
|
|
|
|
if (!bindings) {
|
|
|
|
bindings = global_bindings;
|
|
|
|
}
|
2015-10-26 14:35:06 -04:00
|
|
|
|
2015-08-10 14:31:59 -04:00
|
|
|
if (bindings) {
|
|
|
|
Bindings::Operation op;
|
|
|
|
KeyboardKey kb = bindings->get_binding_for_action (action, op);
|
|
|
|
string shortcut = kb.display_label ();
|
2012-12-07 08:43:45 -05:00
|
|
|
if (!shortcut.empty()) {
|
|
|
|
replace_all (shortcut, "<", "");
|
|
|
|
replace_all (shortcut, ">", "-");
|
|
|
|
msg.append(_("\n\nShortcut: ")).append (shortcut);
|
2011-11-24 00:36:31 -05:00
|
|
|
}
|
|
|
|
}
|
2010-02-08 19:50:24 -05:00
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-01 20:58:32 -05:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
req->widget = w;
|
2010-02-08 19:50:24 -05:00
|
|
|
req->msg = msg.c_str();
|
2008-06-02 17:41:35 -04:00
|
|
|
req->msg2 = hlp;
|
|
|
|
|
|
|
|
send_request (req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::set_state (Widget *w, StateType state)
|
|
|
|
{
|
|
|
|
UIRequest *req = get_request (StateChange);
|
2009-10-22 15:00:40 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->new_state = state;
|
|
|
|
req->widget = w;
|
|
|
|
|
|
|
|
send_request (req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::idle_add (int (*func)(void *), void *arg)
|
|
|
|
{
|
|
|
|
UIRequest *req = get_request (AddIdle);
|
|
|
|
|
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->function = func;
|
|
|
|
req->arg = arg;
|
|
|
|
|
|
|
|
send_request (req);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* END abstract_ui interfaces */
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::do_request (UIRequest* req)
|
|
|
|
{
|
|
|
|
if (req->type == ErrorMessage) {
|
|
|
|
|
|
|
|
process_error_message (req->chn, req->msg);
|
|
|
|
free (const_cast<char*>(req->msg)); /* it was strdup'ed */
|
|
|
|
req->msg = 0; /* don't free it again in the destructor */
|
|
|
|
|
|
|
|
} else if (req->type == Quit) {
|
|
|
|
|
|
|
|
do_quit ();
|
|
|
|
|
|
|
|
} else if (req->type == CallSlot) {
|
2009-12-22 15:21:43 -05:00
|
|
|
#ifndef NDEBUG
|
|
|
|
if (getenv ("DEBUG_THREADED_SIGNALS")) {
|
2015-12-12 11:01:49 -05:00
|
|
|
cerr << "call slot for " << event_loop_name() << endl;
|
2009-12-22 15:21:43 -05:00
|
|
|
}
|
|
|
|
#endif
|
2009-12-08 22:05:14 -05:00
|
|
|
req->the_slot ();
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
} else if (req->type == TouchDisplay) {
|
|
|
|
|
|
|
|
req->display->touch ();
|
|
|
|
if (req->display->delete_after_touch()) {
|
|
|
|
delete req->display;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (req->type == StateChange) {
|
|
|
|
|
|
|
|
req->widget->set_state (req->new_state);
|
|
|
|
|
|
|
|
} else if (req->type == SetTip) {
|
|
|
|
|
2018-04-11 20:34:19 -04:00
|
|
|
gchar* old = gtk_widget_get_tooltip_markup (req->widget->gobj());
|
|
|
|
if (
|
|
|
|
(old && req->msg && strcmp (old, req->msg))
|
|
|
|
||
|
|
|
|
((old == NULL) != (req->msg == NULL || req->msg[0] == '\0'))
|
|
|
|
) {
|
|
|
|
gtk_widget_set_tooltip_markup (req->widget->gobj(), req->msg);
|
|
|
|
}
|
2021-05-22 16:11:42 -04:00
|
|
|
g_free (old);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
error << "GtkUI: unknown request type "
|
|
|
|
<< (int) req->type
|
|
|
|
<< endmsg;
|
2009-10-22 15:00:40 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*======================================================================
|
|
|
|
Error Display
|
|
|
|
======================================================================*/
|
|
|
|
|
2015-06-29 16:27:03 -04:00
|
|
|
void
|
2020-02-28 01:26:13 -05:00
|
|
|
UI::dump_errors (std::ostream& ostr, size_t limit)
|
2015-06-29 16:27:03 -04:00
|
|
|
{
|
|
|
|
Glib::Threads::Mutex::Lock lm (error_lock);
|
2020-03-31 12:26:54 -04:00
|
|
|
bool first = true;
|
|
|
|
|
|
|
|
if (limit > 0) {
|
|
|
|
/* reverse listing, Errors only */
|
2020-04-01 21:43:29 -04:00
|
|
|
for (list<string>::reverse_iterator i = error_stack.rbegin(); i != error_stack.rend(); ++i) {
|
2020-03-31 12:26:54 -04:00
|
|
|
if ((*i).substr (0, 9) == X_("WARNING: ") || (*i).substr (0, 6) == X_("INFO: ")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
ostr << *i << endl;
|
2020-02-28 01:26:13 -05:00
|
|
|
if (--limit == 0) {
|
|
|
|
ostr << "..." << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 16:27:03 -04:00
|
|
|
}
|
2020-03-31 12:26:54 -04:00
|
|
|
|
|
|
|
if (first) {
|
|
|
|
for (list<string>::const_iterator i = error_stack.begin(); i != error_stack.end(); ++i) {
|
|
|
|
if (first) {
|
|
|
|
ostr << endl << X_("Log Messages:") << endl;
|
|
|
|
first = false;
|
|
|
|
}
|
|
|
|
ostr << *i << endl;
|
|
|
|
if (limit > 0) {
|
|
|
|
if (--limit == 0) {
|
|
|
|
ostr << "..." << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-06-29 16:27:03 -04:00
|
|
|
ostr << endl;
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
|
|
|
UI::receive (Transmitter::Channel chn, const char *str)
|
|
|
|
{
|
2015-06-29 16:27:03 -04:00
|
|
|
{
|
|
|
|
Glib::Threads::Mutex::Lock lm (error_lock);
|
|
|
|
switch (chn) {
|
|
|
|
case Transmitter::Fatal:
|
|
|
|
error_stack.push_back (string (X_("FATAL: ")) + str);
|
|
|
|
break;
|
|
|
|
case Transmitter::Error:
|
|
|
|
error_stack.push_back (string (X_("ERROR: ")) + str);
|
|
|
|
break;
|
|
|
|
case Transmitter::Warning:
|
|
|
|
error_stack.push_back (string (X_("WARNING: ")) + str);
|
|
|
|
break;
|
|
|
|
case Transmitter::Info:
|
|
|
|
error_stack.push_back (string (X_("INFO: ")) + str);
|
|
|
|
break;
|
2020-10-13 15:46:52 -04:00
|
|
|
case Transmitter::Debug:
|
|
|
|
error_stack.push_back (string (X_("Debug: ")) + str);
|
|
|
|
break;
|
2015-06-29 16:27:03 -04:00
|
|
|
case Transmitter::Throw:
|
|
|
|
error_stack.push_back (string (X_("THROW: ")) + str);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
if (caller_is_ui_thread()) {
|
|
|
|
process_error_message (chn, str);
|
|
|
|
} else {
|
|
|
|
UIRequest* req = get_request (ErrorMessage);
|
|
|
|
|
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->chn = chn;
|
|
|
|
req->msg = strdup (str);
|
|
|
|
|
|
|
|
send_request (req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::process_error_message (Transmitter::Channel chn, const char *str)
|
|
|
|
{
|
|
|
|
RefPtr<Style> style;
|
|
|
|
RefPtr<TextBuffer::Tag> ptag;
|
|
|
|
RefPtr<TextBuffer::Tag> mtag;
|
|
|
|
const char *prefix;
|
|
|
|
size_t prefix_len;
|
|
|
|
bool fatal_received = false;
|
|
|
|
|
|
|
|
switch (chn) {
|
|
|
|
case Transmitter::Fatal:
|
|
|
|
prefix = "[FATAL]: ";
|
|
|
|
ptag = fatal_ptag;
|
|
|
|
mtag = fatal_mtag;
|
|
|
|
prefix_len = 9;
|
|
|
|
fatal_received = true;
|
|
|
|
break;
|
|
|
|
case Transmitter::Error:
|
|
|
|
prefix = "[ERROR]: ";
|
|
|
|
ptag = error_ptag;
|
|
|
|
mtag = error_mtag;
|
|
|
|
prefix_len = 9;
|
|
|
|
break;
|
2020-10-13 15:46:52 -04:00
|
|
|
case Transmitter::Warning:
|
|
|
|
prefix = "[WARNING]: ";
|
|
|
|
ptag = warning_ptag;
|
|
|
|
mtag = warning_mtag;
|
|
|
|
prefix_len = 11;
|
|
|
|
break;
|
2008-06-02 17:41:35 -04:00
|
|
|
case Transmitter::Info:
|
|
|
|
prefix = "[INFO]: ";
|
|
|
|
ptag = info_ptag;
|
|
|
|
mtag = info_mtag;
|
|
|
|
prefix_len = 8;
|
|
|
|
break;
|
2020-10-13 15:46:52 -04:00
|
|
|
case Transmitter::Debug:
|
|
|
|
prefix = "[DEBUG]: ";
|
|
|
|
ptag = debug_ptag;
|
|
|
|
mtag = debug_mtag;
|
|
|
|
prefix_len = 9;
|
2008-06-02 17:41:35 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* no choice but to use text/console output here */
|
|
|
|
cerr << "programmer error in UI::check_error_messages (channel = " << chn << ")\n";
|
2019-07-04 16:21:35 -04:00
|
|
|
::exit (EXIT_FAILURE);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
2009-10-22 14:11:22 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
errors->text().get_buffer()->begin_user_action();
|
|
|
|
|
|
|
|
if (fatal_received) {
|
|
|
|
handle_fatal (str);
|
|
|
|
} else {
|
2009-10-22 14:11:22 -04:00
|
|
|
|
2012-05-10 18:45:56 -04:00
|
|
|
if (!ptag || !mtag) {
|
|
|
|
/* oops, message sent before we set up tags - don't crash */
|
|
|
|
cerr << prefix << str << endl;
|
|
|
|
} else {
|
|
|
|
display_message (prefix, prefix_len, ptag, mtag, str);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
errors->text().get_buffer()->end_user_action();
|
|
|
|
}
|
|
|
|
|
2011-04-04 10:22:27 -04:00
|
|
|
void
|
|
|
|
UI::show_errors ()
|
|
|
|
{
|
2018-12-12 08:41:57 -05:00
|
|
|
Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-log-window"));
|
|
|
|
tact->set_active ();
|
2011-04-04 10:22:27 -04:00
|
|
|
}
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
void
|
|
|
|
UI::toggle_errors ()
|
|
|
|
{
|
2018-12-12 08:41:57 -05:00
|
|
|
Glib::RefPtr<ToggleAction> tact = ActionManager::get_toggle_action (X_("Editor"), X_("toggle-log-window"));
|
2010-09-21 20:41:25 -04:00
|
|
|
if (tact->get_active()) {
|
2008-06-02 17:41:35 -04:00
|
|
|
errors->set_position (WIN_POS_MOUSE);
|
|
|
|
errors->show ();
|
|
|
|
} else {
|
|
|
|
errors->hide ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-07-21 11:55:17 -04:00
|
|
|
UI::display_message (const char *prefix, gint /*prefix_len*/, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
RefPtr<TextBuffer> buffer (errors->text().get_buffer());
|
2020-03-08 18:31:51 -04:00
|
|
|
Glib::DateTime tm (g_date_time_new_now_local ());
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2020-03-08 18:31:51 -04:00
|
|
|
buffer->insert_with_tag(buffer->end(), tm.format ("%FT%H:%M:%S "), ptag);
|
2008-06-02 17:41:35 -04:00
|
|
|
buffer->insert_with_tag(buffer->end(), prefix, ptag);
|
|
|
|
buffer->insert_with_tag(buffer->end(), msg, mtag);
|
|
|
|
buffer->insert_with_tag(buffer->end(), "\n", mtag);
|
|
|
|
|
|
|
|
errors->scroll_to_bottom ();
|
2009-10-22 14:11:22 -04:00
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
void
|
|
|
|
UI::handle_fatal (const char *message)
|
|
|
|
{
|
2009-07-17 18:12:21 -04:00
|
|
|
Dialog win;
|
2008-06-02 17:41:35 -04:00
|
|
|
Label label (message);
|
|
|
|
Button quit (_("Press To Exit"));
|
2009-07-17 18:12:21 -04:00
|
|
|
HBox hpacker;
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
win.set_default_size (400, 100);
|
2009-10-22 14:11:22 -04:00
|
|
|
|
2009-12-08 22:05:14 -05:00
|
|
|
WindowTitle title(Glib::get_application_name());
|
2008-06-02 17:41:35 -04:00
|
|
|
title += ": Fatal Error";
|
2009-12-08 22:05:14 -05:00
|
|
|
win.set_title (title.get_string());
|
2008-06-02 17:41:35 -04:00
|
|
|
|
|
|
|
win.set_position (WIN_POS_MOUSE);
|
2009-07-17 18:12:21 -04:00
|
|
|
win.set_border_width (12);
|
|
|
|
|
|
|
|
win.get_vbox()->pack_start (label, true, true);
|
|
|
|
hpacker.pack_start (quit, true, false);
|
|
|
|
win.get_vbox()->pack_start (hpacker, false, false);
|
2008-06-02 17:41:35 -04:00
|
|
|
|
2023-08-24 13:59:51 -04:00
|
|
|
quit.signal_clicked().connect ([&win] { win.response (-4); });
|
|
|
|
win.signal_response().connect([this] (int) { UI::quit (); });
|
2009-10-22 14:11:22 -04:00
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
win.show_all ();
|
|
|
|
win.set_modal (true);
|
|
|
|
|
|
|
|
theMain->run ();
|
2009-10-22 14:11:22 -04:00
|
|
|
|
2009-07-17 18:12:21 -04:00
|
|
|
_exit (1);
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-04-20 22:24:38 -04:00
|
|
|
UI::popup_error (const string& text)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
if (!caller_is_ui_thread()) {
|
2009-10-22 15:00:40 -04:00
|
|
|
error << "non-UI threads can't use UI::popup_error"
|
2008-06-02 17:41:35 -04:00
|
|
|
<< endmsg;
|
|
|
|
return;
|
|
|
|
}
|
2009-10-22 15:00:40 -04:00
|
|
|
|
2011-06-22 10:38:32 -04:00
|
|
|
MessageDialog msg (text);
|
|
|
|
msg.set_title (string_compose (_("I'm sorry %1, I can't do that"), g_get_user_name()));
|
2015-12-12 11:01:56 -05:00
|
|
|
msg.set_wmclass (X_("error"), Glib::get_application_name());
|
2011-06-22 10:38:32 -04:00
|
|
|
msg.set_position (WIN_POS_MOUSE);
|
|
|
|
msg.run ();
|
2008-06-02 17:41:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2016-07-25 08:13:52 -04:00
|
|
|
UI::flush_pending (float timeout)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
if (!caller_is_ui_thread()) {
|
|
|
|
error << "non-UI threads cannot call UI::flush_pending()"
|
|
|
|
<< endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-25 08:13:52 -04:00
|
|
|
int64_t end = g_get_monotonic_time () + timeout * 1e6;
|
|
|
|
|
2008-06-02 17:41:35 -04:00
|
|
|
gtk_main_iteration();
|
|
|
|
|
|
|
|
while (gtk_events_pending()) {
|
2016-07-25 08:13:52 -04:00
|
|
|
if (timeout > 0 && end < g_get_monotonic_time ()) {
|
|
|
|
cerr << "UI::flush_pending timed out after " << timeout << "s.\n";
|
|
|
|
break;
|
|
|
|
}
|
2008-06-02 17:41:35 -04:00
|
|
|
gtk_main_iteration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-08-26 12:45:18 -04:00
|
|
|
UI::just_hide_it (GdkEventAny* /*ev*/, Window *win)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
win->hide ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::color_selection_done (bool status)
|
|
|
|
{
|
|
|
|
color_picked = status;
|
|
|
|
Main::quit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2013-08-26 12:45:18 -04:00
|
|
|
UI::color_selection_deleted (GdkEventAny* /*ev*/)
|
2008-06-02 17:41:35 -04:00
|
|
|
{
|
|
|
|
Main::quit ();
|
|
|
|
return true;
|
|
|
|
}
|