/* * Copyright (C) 1999-2019 Paul Davis * Copyright (C) 2005 Taybin Rutkin * Copyright (C) 2006-2007 Tim Mayberry * Copyright (C) 2007-2011 David Robillard * Copyright (C) 2007-2011 Doug McLain * Copyright (C) 2009-2012 Carl Hetherington * Copyright (C) 2013 John Emmas * Copyright (C) 2014-2019 Robin Gareus * * 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. */ #include #include #include #include #include #include #include #include #include "pbd/error.h" #include "pbd/touchable.h" #include "pbd/failed_constructor.h" #include "pbd/localtime_r.h" #include "pbd/pthread_utils.h" #include "pbd/replace_all.h" #include "gtkmm2ext/application.h" #include "gtkmm2ext/bindings.h" #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" #include "gtkmm2ext/gui_thread.h" #include "pbd/i18n.h" using namespace Gtkmm2ext; using namespace Gtk; using namespace Glib; using namespace PBD; using std::map; UI* UI::theGtkUI = 0; BaseUI::RequestType Gtkmm2ext::NullMessage = BaseUI::new_request_type(); 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(); #include "pbd/abstract_ui.cc" /* instantiate the template */ template class AbstractUI; UI::UI (string application_name, string thread_name, int *argc, char ***argv) : AbstractUI (thread_name) , _receiver (*this) , global_bindings (0) , errors (0) { theMain = new Main (argc, argv); char buf[18]; /* pthread public name has a 16 char limit */ snprintf (buf, sizeof (buf), "%.11sGUI", PROGRAM_NAME); pthread_set_name (buf); _active = false; if (!theGtkUI) { theGtkUI = this; } else { fatal << "duplicate UI requested" << endmsg; abort(); /* NOTREACHED */ } /* the GUI event loop runs in the main thread of the app, which is assumed to have called this. */ run_loop_thread = Threads::Thread::self(); /* store "this" as the UI-for-thread of this thread, same argument as for previous line. */ set_event_loop_for_thread (this); /* we will be receiving requests */ EventLoop::register_request_buffer_factory ("gui", request_buffer_factory); /* attach our request source to the default main context */ attach_request_source (); errors = new TextViewer (800,600); errors->text().set_editable (false); errors->text().set_name ("ErrorText"); errors->signal_unmap().connect (sigc::bind (sigc::ptr_fun (&ActionManager::uncheck_toggleaction), X_("Editor/toggle-log-window"))); Glib::set_application_name (application_name); WindowTitle title(Glib::get_application_name()); title += _("Log"); errors->set_title (title.get_string()); errors->dismiss_button().set_name ("ErrorLogCloseButton"); errors->signal_delete_event().connect (sigc::bind (sigc::ptr_fun (just_hide_it), (Window *) errors)); errors->set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY); //load_rcfile (rcfile); /* instantiate the Application singleton */ Application::instance(); } UI::~UI () { _receiver.hangup (); delete (errors); } bool UI::caller_is_ui_thread () { return Threads::Thread::self() == run_loop_thread; } int UI::load_rcfile (string path, bool themechange) { /* 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, * except that doesn't actually work... */ static Glib::RefPtr