/*
- Copyright (C) 1999-2005 Paul Barton-Davis
+ Copyright (C) 1999-2005 Paul Barton-Davis
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
#include <pbd/touchable.h>
#include <pbd/failed_constructor.h>
#include <pbd/pthread_utils.h>
+#include <pbd/stacktrace.h>
#include <gtkmm2ext/gtk_ui.h>
#include <gtkmm2ext/textviewer.h>
#include <gtkmm2ext/popup.h>
#include <gtkmm2ext/utils.h>
+#include <gtkmm2ext/window_title.h>
+#include <gtkmm2ext/actions.h>
#include "i18n.h"
using namespace Gtkmm2ext;
+using namespace Gtk;
+using namespace Glib;
+using namespace PBD;
using std::map;
-pthread_t UI::gui_thread;
UI *UI::theGtkUI = 0;
-UI::UI (string name, int *argc, char ***argv, string rcfile)
- : _ui_name (name)
-{
- theMain = new Gtk::Main (argc, argv);
- tips = new Gtk::Tooltips;
+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();
- if (pthread_key_create (&thread_request_buffer_key, 0)) {
- cerr << _("cannot create thread request buffer key") << endl;
- throw failed_constructor();
- }
+#include "pbd/abstract_ui.cc" /* instantiate the template */
- PBD::ThreadCreated.connect (mem_fun (*this, &UI::register_thread));
+UI::UI (string namestr, int *argc, char ***argv)
+ : AbstractUI<UIRequest> (namestr)
+{
+ theMain = new Main (argc, argv);
+#ifndef GTK_NEW_TOOLTIP_API
+ tips = new Tooltips;
+#endif
- _ok = false;
_active = false;
if (!theGtkUI) {
theGtkUI = this;
- gui_thread = pthread_self ();
} else {
fatal << "duplicate UI requested" << endmsg;
/* NOTREACHED */
}
- if (setup_signal_pipe ()) {
- return;
- }
+ /* the GUI event loop runs in the main thread of the app,
+ which is assumed to have called this.
+ */
- load_rcfile (rcfile);
+ run_loop_thread = Thread::self();
+
+ /* store "this" as the UI-for-thread of this thread, same argument
+ as for previous line.
+ */
- errors = new TextViewer (850,100);
- errors->text().set_editable (false);
- errors->text().set_name ("ErrorText");
+ set_event_loop_for_thread (this);
- string title;
- title = _ui_name;
- title += ": Log";
- errors->set_title (title);
+ /* attach our request source to the default main context */
- errors->dismiss_button().set_name ("ErrorLogCloseButton");
-// errors->realize();
+ request_channel.ios()->attach (MainContext::get_default());
- Glib::RefPtr<Gdk::Window> win(errors->get_window());
- win->set_decorations (Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH));
+ errors = new TextViewer (800,600);
+ errors->text().set_editable (false);
+ errors->text().set_name ("ErrorText");
- errors->signal_delete_event().connect (bind (ptr_fun (just_hide_it), (Gtk::Window *) errors));
+ Glib::set_application_name(namestr);
- register_thread (pthread_self(), X_("GUI"));
+ WindowTitle title(Glib::get_application_name());
+ title += _("Log");
+ errors->set_title (title.get_string());
- _ok = true;
+ errors->dismiss_button().set_name ("ErrorLogCloseButton");
+ errors->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), (Window *) errors));
+ errors->set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
+
+ //load_rcfile (rcfile);
}
UI::~UI ()
{
- close (signal_pipe[0]);
- close (signal_pipe[1]);
+}
+
+
+bool
+UI::caller_is_ui_thread ()
+{
+ return Thread::self() == run_loop_thread;
}
int
-UI::load_rcfile (string path)
+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<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;
+
if (path.length() == 0) {
return -1;
}
if (access (path.c_str(), R_OK)) {
- error << "UI: couldn't find rc file \""
+ error << "UI: couldn't find rc file \""
<< path
<< '"'
<< endmsg;
return -1;
}
-
- gtk_rc_parse (path.c_str());
-
- Gtk::Label *a_widget1;
- Gtk::Label *a_widget2;
- Gtk::Label *a_widget3;
- Gtk::Label *a_widget4;
-
- a_widget1 = new Gtk::Label;
- a_widget2 = new Gtk::Label;
- a_widget3 = new Gtk::Label;
- a_widget4 = new Gtk::Label;
-
- a_widget1->set_name ("FatalMessage");
- a_widget1->ensure_style ();
- fatal_message_style = a_widget1->get_style();
- a_widget2->set_name ("ErrorMessage");
- a_widget2->ensure_style ();
- error_message_style = a_widget2->get_style();
-
- a_widget3->set_name ("WarningMessage");
- a_widget3->ensure_style ();
- warning_message_style = a_widget3->get_style();
-
- a_widget4->set_name ("InfoMessage");
- a_widget4->ensure_style ();
- info_message_style = a_widget4->get_style();
-
- delete a_widget1;
- delete a_widget2;
- delete a_widget3;
- delete a_widget4;
+ RC rc (path.c_str());
+ //RC::reset_styles (Gtk::Settings::get_default());
+ gtk_rc_reset_styles (gtk_settings_get_default());
+ 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);
+ temp_window.ensure_style ();
+
+ HBox box;
+ Label fatal_widget;
+ Label error_widget;
+ Label warning_widget;
+ Label info_widget;
+ RefPtr<Gtk::Style> style;
+ RefPtr<TextBuffer> buffer (errors->text().get_buffer());
+
+ box.pack_start (fatal_widget);
+ box.pack_start (error_widget);
+ box.pack_start (warning_widget);
+ box.pack_start (info_widget);
+
+ error_ptag = buffer->create_tag();
+ error_mtag = buffer->create_tag();
+ fatal_ptag = buffer->create_tag();
+ fatal_mtag = buffer->create_tag();
+ warning_ptag = buffer->create_tag();
+ warning_mtag = buffer->create_tag();
+ info_ptag = buffer->create_tag();
+ info_mtag = buffer->create_tag();
+
+ fatal_widget.set_name ("FatalMessage");
+ delete fatal_style;
+ fatal_style = new Glib::RefPtr<Style>(rc.get_style(fatal_widget));
+
+ 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;
+ error_style = new Glib::RefPtr<Style>(rc.get_style(error_widget));
+
+ 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;
+ warning_style = new Glib::RefPtr<Style>(rc.get_style(warning_widget));
+
+ 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;
+ info_style = new Glib::RefPtr<Style>(rc.get_style(info_widget));
+
+ 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));
return 0;
}
listen_to (warning);
listen_to (fatal);
- old_receiver.hangup ();
+ /* 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));
+
starting ();
- _active = true;
+ _active = true;
theMain->run ();
_active = false;
stopping ();
}
void
-UI::kill ()
+UI::quit ()
{
- if (_active) {
- pthread_kill (gui_thread, SIGKILL);
- }
+ UIRequest *req = get_request (Quit);
+
+ if (req == 0) {
+ return;
+ }
+
+ send_request (req);
}
-void
-UI::quit ()
+static bool idle_quit ()
{
- request (Quit);
+ Main::quit ();
+ return true;
}
void
UI::do_quit ()
{
- Gtk::Main::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)
{
- Request *req = get_request (TouchDisplay);
+ UIRequest *req = get_request (TouchDisplay);
if (req == 0) {
return;
req->display = display;
send_request (req);
-}
+}
void
-UI::call_slot (sigc::slot<void> slot)
+UI::set_tip (Widget &w, const gchar *tip)
{
- Request *req = get_request (CallSlot);
-
- if (req == 0) {
- return;
- }
-
- req->slot = slot;
+ set_tip(&w, tip, "");
+}
- send_request (req);
-}
+void
+UI::set_tip (Widget &w, const std::string& tip)
+{
+ set_tip(&w, tip.c_str(), "");
+}
void
-UI::call_slot_locked (sigc::slot<void> slot)
+UI::set_tip (Widget *w, const gchar *tip, const gchar *hlp)
{
- if (caller_is_gui_thread()) {
- call_slot (slot);
- return;
- }
+ UIRequest *req = get_request (SetTip);
- Request *req = get_request (CallSlotLocked);
+ std::string msg(tip);
- if (req == 0) {
- return;
+ Glib::RefPtr<Gtk::Action> action = w->get_action();
+ if (action) {
+ Gtk::AccelKey key;
+ bool has_key = ActionManager::lookup_entry(action->get_accel_path(), key);
+ if (has_key && key.get_abbrev() != "") {
+ msg.append("\n\n Key: ").append(key.get_abbrev());
+ }
}
- req->slot = slot;
-
- pthread_mutex_init (&req->slot_lock, NULL);
- pthread_cond_init (&req->slot_cond, NULL);
- pthread_mutex_lock (&req->slot_lock);
-
- send_request (req);
-
- pthread_cond_wait (&req->slot_cond, &req->slot_lock);
- pthread_mutex_unlock (&req->slot_lock);
-
- delete req;
-}
-
-void
-UI::set_tip (Gtk::Widget *w, const gchar *tip, const gchar *hlp)
-{
- Request *req = get_request (SetTip);
-
if (req == 0) {
return;
}
req->widget = w;
- req->msg = tip;
+ req->msg = msg.c_str();
req->msg2 = hlp;
send_request (req);
}
void
-UI::set_state (Gtk::Widget *w, Gtk::StateType state)
+UI::set_state (Widget *w, StateType state)
{
- Request *req = get_request (StateChange);
-
+ UIRequest *req = get_request (StateChange);
+
if (req == 0) {
return;
}
void
UI::idle_add (int (*func)(void *), void *arg)
{
- Request *req = get_request (AddIdle);
+ UIRequest *req = get_request (AddIdle);
if (req == 0) {
return;
send_request (req);
}
-void
-UI::timeout_add (unsigned int timeout, int (*func)(void *), void *arg)
-{
- Request *req = get_request (AddTimeout);
-
- if (req == 0) {
- return;
- }
-
- req->function = func;
- req->arg = arg;
- req->timeout = timeout;
-
- send_request (req);
-}
-
/* END abstract_ui interfaces */
-/* Handling requests */
-
-void
-UI::register_thread (pthread_t thread_id, string name)
+/** Create a PBD::EventLoop::InvalidationRecord and attach a callback
+ * to a given sigc::trackable so that PBD::EventLoop::invalidate_request
+ * is called when that trackable is destroyed.
+ */
+PBD::EventLoop::InvalidationRecord*
+__invalidator (sigc::trackable& trackable, const char* file, int line)
{
- RingBufferNPT<Request>* b = new RingBufferNPT<Request> (128);
-
- {
- PBD::LockMonitor lm (request_buffer_map_lock, __LINE__, __FILE__);
- request_buffers[thread_id] = b;
- }
+ PBD::EventLoop::InvalidationRecord* ir = new PBD::EventLoop::InvalidationRecord;
- pthread_setspecific (thread_request_buffer_key, b);
-}
-
-UI::Request::Request()
-{
+ ir->file = file;
+ ir->line = line;
-}
+ trackable.add_destroy_notify_callback (ir, PBD::EventLoop::invalidate_request);
-UI::Request*
-UI::get_request (RequestType rt)
-{
- RingBufferNPT<Request>* rbuf = static_cast<RingBufferNPT<Request>* >(pthread_getspecific (thread_request_buffer_key));
-
- if (rbuf == 0) {
- /* Cannot happen, but if it does we can't use the error reporting mechanism */
- cerr << _("programming error: ")
- << string_compose (X_("no GUI request buffer found for thread %1"), pthread_self())
- << endl;
- abort ();
- }
-
- RingBufferNPT<Request>::rw_vector vec;
-
- rbuf->get_write_vector (&vec);
-
- if (vec.len[0] == 0) {
- if (vec.len[1] == 0) {
- cerr << string_compose (X_("no space in GUI request buffer for thread %1"), pthread_self())
- << endl;
- return 0;
- } else {
- vec.buf[1]->type = rt;
- return vec.buf[1];
- }
- } else {
- vec.buf[0]->type = rt;
- return vec.buf[0];
- }
+ return ir;
}
-int
-UI::setup_signal_pipe ()
+void
+UI::do_request (UIRequest* req)
{
- /* setup the pipe that other threads send us notifications/requests
- through.
- */
-
- if (pipe (signal_pipe)) {
- error << "UI: cannot create error signal pipe ("
- << strerror (errno) << ")"
- << endmsg;
-
- return -1;
- }
+ if (req->type == ErrorMessage) {
- if (fcntl (signal_pipe[0], F_SETFL, O_NONBLOCK)) {
- error << "UI: cannot set O_NONBLOCK on "
- "signal read pipe ("
- << strerror (errno) << ")"
- << endmsg;
- return -1;
- }
-
- if (fcntl (signal_pipe[1], F_SETFL, O_NONBLOCK)) {
- error << "UI: cannot set O_NONBLOCK on "
- "signal write pipe ("
- << strerror (errno)
- << ")"
- << endmsg;
- return -1;
- }
-
- /* add the pipe to the select/poll loop that GDK does */
-
- gdk_input_add (signal_pipe[0],
- GDK_INPUT_READ,
- UI::signal_pipe_callback,
- this);
+ 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 */
- return 0;
-}
+ } else if (req->type == Quit) {
-void
-UI::signal_pipe_callback (void *arg, int fd, GdkInputCondition cond)
-{
- char buf[256];
-
- /* flush (nonblocking) pipe */
-
- while (read (fd, buf, 256) > 0);
-
- ((UI *) arg)->handle_ui_requests ();
-}
+ do_quit ();
-void
-UI::handle_ui_requests ()
-{
- RequestBufferMap::iterator i;
-
- request_buffer_map_lock.lock ();
-
- for (i = request_buffers.begin(); i != request_buffers.end(); ++i) {
-
- RingBufferNPT<Request>::rw_vector vec;
-
- while (true) {
-
- /* we must process requests 1 by 1 because
- the request may run a recursive main
- event loop that will itself call
- handle_ui_requests. when we return
- from the request handler, we cannot
- expect that the state of queued requests
- is even remotely consistent with
- the condition before we called it.
- */
-
- i->second->get_read_vector (&vec);
-
- if (vec.len[0] == 0) {
- break;
- } else {
- /* copy constructor does a deep
- copy of the Request object,
- unlike Ringbuffer::read()
- */
- Request req (*vec.buf[0]);
- i->second->increment_read_ptr (1);
- request_buffer_map_lock.unlock ();
- do_request (&req);
- request_buffer_map_lock.lock ();
- }
+ } else if (req->type == CallSlot) {
+#ifndef NDEBUG
+ if (getenv ("DEBUG_THREADED_SIGNALS")) {
+ cerr << "call slot for " << name() << endl;
}
- }
-
- request_buffer_map_lock.unlock ();
-}
+#endif
+ req->the_slot ();
-void
-UI::do_request (Request* req)
-{
- switch (req->type) {
- case ErrorMessage:
- process_error_message (req->chn, req->msg);
- free (const_cast<char*>(req->msg)); /* it was strdup'ed */
- break;
-
- case Quit:
- do_quit ();
- break;
-
- case CallSlot:
- req->slot ();
- break;
+ } else if (req->type == TouchDisplay) {
- case CallSlotLocked:
- pthread_mutex_lock (&req->slot_lock);
- req->slot ();
- pthread_cond_signal (&req->slot_cond);
- pthread_mutex_unlock (&req->slot_lock);
- break;
-
- case TouchDisplay:
req->display->touch ();
if (req->display->delete_after_touch()) {
delete req->display;
}
- break;
-
- case StateChange:
+
+ } else if (req->type == StateChange) {
+
req->widget->set_state (req->new_state);
- break;
-
- case SetTip:
- /* XXX need to figure out how this works */
- break;
-
- case AddIdle:
- gtk_idle_add (req->function, req->arg);
- break;
-
- case AddTimeout:
- gtk_timeout_add (req->timeout, req->function, req->arg);
- break;
-
- default:
- error << "UI: unknown request type "
- << (int) req->type
- << endmsg;
- }
-}
-void
-UI::send_request (Request *req)
-{
- if (instance() == 0) {
- return; /* XXX is this the right thing to do ? */
- }
-
- if (caller_is_gui_thread()) {
- // cerr << "GUI thread sent request " << req << " type = " << req->type << endl;
- do_request (req);
- } else {
- const char c = 0;
- RingBufferNPT<Request*>* rbuf = static_cast<RingBufferNPT<Request*> *> (pthread_getspecific (thread_request_buffer_key));
-
- if (rbuf == 0) {
- /* can't use the error system to report this, because this
- thread isn't registered!
- */
- cerr << _("programming error: ")
- << string_compose (X_("UI::send_request() called from %1, but no request buffer exists for that thread"),
- pthread_self())
- << endl;
- abort ();
- }
-
- // cerr << "thread " << pthread_self() << " sent request " << req << " type = " << req->type << endl;
- rbuf->increment_write_ptr (1);
- write (signal_pipe[1], &c, 1);
- }
-}
+ } else if (req->type == SetTip) {
-void
-UI::request (RequestType rt)
-{
- Request *req = get_request (rt);
+#ifdef GTK_NEW_TOOLTIP_API
+ /* even if the installed GTK is up to date,
+ at present (November 2008) our included
+ version of gtkmm is not. so use the GTK
+ API that we've verified has the right function.
+ */
+ gtk_widget_set_tooltip_text (req->widget->gobj(), req->msg);
+#else
+ tips->set_tip (*req->widget, req->msg, "");
+#endif
- if (req == 0) {
- return;
- }
+ } else {
- send_request (req);
+ error << "GtkUI: unknown request type "
+ << (int) req->type
+ << endmsg;
+ }
}
/*======================================================================
void
UI::receive (Transmitter::Channel chn, const char *str)
{
- if (caller_is_gui_thread()) {
+ if (caller_is_ui_thread()) {
process_error_message (chn, str);
} else {
- Request* req = get_request (ErrorMessage);
+ UIRequest* req = get_request (ErrorMessage);
if (req == 0) {
return;
void
UI::process_error_message (Transmitter::Channel chn, const char *str)
{
- Glib::RefPtr<Gtk::Style> style;
- char *prefix;
+ RefPtr<Style> style;
+ RefPtr<TextBuffer::Tag> ptag;
+ RefPtr<TextBuffer::Tag> mtag;
+ const char *prefix;
size_t prefix_len;
bool fatal_received = false;
#ifndef OLD_STYLE_ERRORS
- PopUp* popup = new PopUp (Gtk::WIN_POS_CENTER, 0, true);
+ PopUp* popup = new PopUp (WIN_POS_CENTER, 0, true);
#endif
switch (chn) {
case Transmitter::Fatal:
prefix = "[FATAL]: ";
- style = fatal_message_style;
+ ptag = fatal_ptag;
+ mtag = fatal_mtag;
prefix_len = 9;
fatal_received = true;
break;
case Transmitter::Error:
#if OLD_STYLE_ERRORS
prefix = "[ERROR]: ";
- style = error_message_style;
+ ptag = error_ptag;
+ mtag = error_mtag;
prefix_len = 9;
#else
popup->set_name ("ErrorMessage");
#endif
break;
case Transmitter::Info:
-#if OLD_STYLE_ERRORS
+#if OLD_STYLE_ERRORS
prefix = "[INFO]: ";
- style = info_message_style;
+ ptag = info_ptag;
+ mtag = info_mtag;
prefix_len = 8;
#else
popup->set_name ("InfoMessage");
case Transmitter::Warning:
#if OLD_STYLE_ERRORS
prefix = "[WARNING]: ";
- style = warning_message_style;
+ ptag = warning_ptag;
+ mtag = warning_mtag;
prefix_len = 11;
#else
popup->set_name ("WarningMessage");
cerr << "programmer error in UI::check_error_messages (channel = " << chn << ")\n";
::exit (1);
}
-
+
errors->text().get_buffer()->begin_user_action();
if (fatal_received) {
handle_fatal (str);
} else {
-
- display_message (prefix, prefix_len, style, str);
-
- if (!errors->is_visible()) {
+
+ display_message (prefix, prefix_len, ptag, mtag, str);
+
+ if (!errors->is_visible() && chn != Transmitter::Info) {
toggle_errors();
}
}
UI::toggle_errors ()
{
if (!errors->is_visible()) {
- errors->set_position (Gtk::WIN_POS_MOUSE);
+ errors->set_position (WIN_POS_MOUSE);
errors->show ();
} else {
errors->hide ();
}
void
-UI::display_message (const char *prefix, gint prefix_len, Glib::RefPtr<Gtk::Style> style, const char *msg)
+UI::display_message (const char *prefix, gint /*prefix_len*/, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
{
- Glib::RefPtr<Gtk::TextBuffer::Tag> ptag = Gtk::TextBuffer::Tag::create();
- Glib::RefPtr<Gtk::TextBuffer::Tag> mtag = Gtk::TextBuffer::Tag::create();
-
- Pango::FontDescription pfont(style->get_font());
- ptag->property_font_desc().set_value(pfont);
- ptag->property_foreground_gdk().set_value(style->get_fg(Gtk::STATE_ACTIVE));
- ptag->property_background_gdk().set_value(style->get_bg(Gtk::STATE_ACTIVE));
-
- Pango::FontDescription mfont (style->get_font());
- mtag->property_font_desc().set_value(mfont);
- mtag->property_foreground_gdk().set_value(style->get_fg(Gtk::STATE_NORMAL));
- mtag->property_background_gdk().set_value(style->get_bg(Gtk::STATE_NORMAL));
+ RefPtr<TextBuffer> buffer (errors->text().get_buffer());
- Glib::RefPtr<Gtk::TextBuffer> buffer (errors->text().get_buffer());
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 ();
-}
+}
void
UI::handle_fatal (const char *message)
{
- Gtk::Window win (Gtk::WINDOW_POPUP);
- Gtk::VBox packer;
- Gtk::Label label (message);
- Gtk::Button quit (_("Press To Exit"));
+ Dialog win;
+ Label label (message);
+ Button quit (_("Press To Exit"));
+ HBox hpacker;
win.set_default_size (400, 100);
-
- string title;
- title = _ui_name;
+
+ WindowTitle title(Glib::get_application_name());
title += ": Fatal Error";
- win.set_title (title);
+ win.set_title (title.get_string());
- win.set_position (Gtk::WIN_POS_MOUSE);
- win.add (packer);
+ win.set_position (WIN_POS_MOUSE);
+ 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);
- packer.pack_start (label, true, true);
- packer.pack_start (quit, false, false);
quit.signal_clicked().connect(mem_fun(*this,&UI::quit));
-
+
win.show_all ();
win.set_modal (true);
theMain->run ();
-
- exit (1);
+
+ _exit (1);
}
void
-UI::popup_error (const char *text)
+UI::popup_error (const string& text)
{
PopUp *pup;
- if (!caller_is_gui_thread()) {
- error << "non-UI threads can't use UI::popup_error"
+ if (!caller_is_ui_thread()) {
+ error << "non-UI threads can't use UI::popup_error"
<< endmsg;
return;
}
-
- pup = new PopUp (Gtk::WIN_POS_MOUSE, 0, true);
+
+ pup = new PopUp (WIN_POS_MOUSE, 0, true);
pup->set_text (text);
pup->touch ();
}
+#ifdef GTKOSX
+extern "C" {
+ int gdk_quartz_in_carbon_menu_event_handler ();
+}
+#endif
void
UI::flush_pending ()
{
- if (!caller_is_gui_thread()) {
+#ifdef GTKOSX
+ /* as of february 11th 2008, gtk/osx has a problem in that mac menu events
+ are handled using Carbon with an "internal" event handling system that
+ doesn't pass things back to the glib/gtk main loop. this makes
+ gtk_main_iteration() block if we call it while in a menu event handler
+ because glib gets confused and thinks there are two threads running
+ g_main_poll_func().
+
+ this hack (relies on code in gtk2_ardour/sync-menu.c) works
+ around that.
+ */
+
+ if (gdk_quartz_in_carbon_menu_event_handler()) {
+ return;
+ }
+#endif
+ if (!caller_is_ui_thread()) {
error << "non-UI threads cannot call UI::flush_pending()"
<< endmsg;
return;
}
bool
-UI::just_hide_it (GdkEventAny *ev, Gtk::Window *win)
+UI::just_hide_it (GdkEventAny */*ev*/, Window *win)
{
- win->hide_all ();
+ win->hide ();
return true;
}
Gdk::Color
-UI::get_color (const string& prompt, bool& picked, Gdk::Color* initial)
+UI::get_color (const string& prompt, bool& picked, const Gdk::Color* initial)
{
Gdk::Color color;
- Gtk::ColorSelectionDialog color_dialog (prompt);
+ ColorSelectionDialog color_dialog (prompt);
color_dialog.set_modal (true);
color_dialog.get_cancel_button()->signal_clicked().connect (bind (mem_fun (*this, &UI::color_selection_done), false));
color_picked = false;
picked = false;
- Gtk::Main::run();
+ Main::run();
color_dialog.hide_all ();
UI::color_selection_done (bool status)
{
color_picked = status;
- Gtk::Main::quit ();
+ Main::quit ();
}
bool
-UI::color_selection_deleted (GdkEventAny *ev)
+UI::color_selection_deleted (GdkEventAny */*ev*/)
{
- Gtk::Main::quit ();
+ Main::quit ();
return true;
}