2005-05-13 16:47:18 -04:00
|
|
|
/*
|
2005-10-10 16:38:53 -04:00
|
|
|
Copyright (C) 1999-2005 Paul Barton-Davis
|
2005-05-13 16:47:18 -04: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.
|
|
|
|
|
|
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
$Id$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <cerrno>
|
|
|
|
#include <climits>
|
|
|
|
#include <cctype>
|
|
|
|
|
|
|
|
#include <gtkmm.h>
|
|
|
|
#include <pbd/error.h>
|
|
|
|
#include <pbd/touchable.h>
|
|
|
|
#include <pbd/failed_constructor.h>
|
|
|
|
#include <pbd/pthread_utils.h>
|
2006-02-15 10:55:48 -05:00
|
|
|
#include <pbd/stacktrace.h>
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
#include <gtkmm2ext/gtk_ui.h>
|
|
|
|
#include <gtkmm2ext/textviewer.h>
|
|
|
|
#include <gtkmm2ext/popup.h>
|
|
|
|
#include <gtkmm2ext/utils.h>
|
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace Gtkmm2ext;
|
2005-11-30 14:34:09 -05:00
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Glib;
|
2006-06-21 19:01:03 -04:00
|
|
|
using namespace PBD;
|
2005-05-13 16:47:18 -04:00
|
|
|
using std::map;
|
|
|
|
|
|
|
|
pthread_t UI::gui_thread;
|
|
|
|
UI *UI::theGtkUI = 0;
|
|
|
|
|
2006-04-24 18:45:19 -04:00
|
|
|
BaseUI::RequestType Gtkmm2ext::ErrorMessage = BaseUI::new_request_type();
|
|
|
|
BaseUI::RequestType Gtkmm2ext::Quit = 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 */
|
|
|
|
|
|
|
|
|
|
|
|
UI::UI (string namestr, int *argc, char ***argv, string rcfile)
|
|
|
|
: AbstractUI<UIRequest> (namestr, true)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2005-11-30 14:34:09 -05:00
|
|
|
theMain = new Main (argc, argv);
|
|
|
|
tips = new Tooltips;
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
_active = false;
|
|
|
|
|
|
|
|
if (!theGtkUI) {
|
|
|
|
theGtkUI = this;
|
|
|
|
gui_thread = pthread_self ();
|
|
|
|
} else {
|
|
|
|
fatal << "duplicate UI requested" << endmsg;
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2006-04-24 18:45:19 -04:00
|
|
|
/* 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);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
errors = new TextViewer (850,100);
|
|
|
|
errors->text().set_editable (false);
|
|
|
|
errors->text().set_name ("ErrorText");
|
|
|
|
|
|
|
|
string title;
|
2006-04-24 18:45:19 -04:00
|
|
|
title = namestr;
|
2005-05-13 16:47:18 -04:00
|
|
|
title += ": Log";
|
|
|
|
errors->set_title (title);
|
|
|
|
|
|
|
|
errors->dismiss_button().set_name ("ErrorLogCloseButton");
|
2006-04-24 18:45:19 -04:00
|
|
|
errors->signal_delete_event().connect (bind (sigc::ptr_fun (just_hide_it), (Window *) errors));
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
register_thread (pthread_self(), X_("GUI"));
|
|
|
|
|
2005-11-30 14:34:09 -05:00
|
|
|
load_rcfile (rcfile);
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
UI::~UI ()
|
|
|
|
{
|
2006-04-24 18:45:19 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
UI::caller_is_ui_thread ()
|
|
|
|
{
|
|
|
|
return pthread_equal (gui_thread, pthread_self());
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
UI::load_rcfile (string path)
|
|
|
|
{
|
|
|
|
if (path.length() == 0) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (access (path.c_str(), R_OK)) {
|
|
|
|
error << "UI: couldn't find rc file \""
|
|
|
|
<< path
|
|
|
|
<< '"'
|
|
|
|
<< endmsg;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2005-11-30 14:34:09 -05:00
|
|
|
RC rc (path.c_str());
|
|
|
|
|
|
|
|
/* have to pack widgets into a toplevel window so that styles will stick */
|
|
|
|
|
|
|
|
Window temp_window (WINDOW_TOPLEVEL);
|
|
|
|
HBox box;
|
|
|
|
Label a_widget1;
|
|
|
|
Label a_widget2;
|
|
|
|
Label a_widget3;
|
|
|
|
Label a_widget4;
|
|
|
|
RefPtr<Gtk::Style> style;
|
|
|
|
RefPtr<TextBuffer> buffer (errors->text().get_buffer());
|
|
|
|
|
|
|
|
box.pack_start (a_widget1);
|
|
|
|
box.pack_start (a_widget2);
|
|
|
|
box.pack_start (a_widget3);
|
|
|
|
box.pack_start (a_widget4);
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
a_widget1.set_name ("FatalMessage");
|
|
|
|
a_widget1.ensure_style ();
|
|
|
|
style = a_widget1.get_style();
|
|
|
|
|
|
|
|
fatal_ptag->property_font_desc().set_value(style->get_font());
|
|
|
|
fatal_ptag->property_foreground_gdk().set_value(style->get_fg(STATE_ACTIVE));
|
|
|
|
fatal_ptag->property_background_gdk().set_value(style->get_bg(STATE_ACTIVE));
|
|
|
|
fatal_mtag->property_font_desc().set_value(style->get_font());
|
|
|
|
fatal_mtag->property_foreground_gdk().set_value(style->get_fg(STATE_NORMAL));
|
|
|
|
fatal_mtag->property_background_gdk().set_value(style->get_bg(STATE_NORMAL));
|
|
|
|
|
|
|
|
a_widget2.set_name ("ErrorMessage");
|
|
|
|
a_widget2.ensure_style ();
|
|
|
|
style = a_widget2.get_style();
|
|
|
|
|
|
|
|
error_ptag->property_font_desc().set_value(style->get_font());
|
|
|
|
error_ptag->property_foreground_gdk().set_value(style->get_fg(STATE_ACTIVE));
|
|
|
|
error_ptag->property_background_gdk().set_value(style->get_bg(STATE_ACTIVE));
|
|
|
|
error_mtag->property_font_desc().set_value(style->get_font());
|
|
|
|
error_mtag->property_foreground_gdk().set_value(style->get_fg(STATE_NORMAL));
|
|
|
|
error_mtag->property_background_gdk().set_value(style->get_bg(STATE_NORMAL));
|
|
|
|
|
|
|
|
a_widget3.set_name ("WarningMessage");
|
|
|
|
a_widget3.ensure_style ();
|
|
|
|
style = a_widget3.get_style();
|
|
|
|
|
|
|
|
warning_ptag->property_font_desc().set_value(style->get_font());
|
|
|
|
warning_ptag->property_foreground_gdk().set_value(style->get_fg(STATE_ACTIVE));
|
|
|
|
warning_ptag->property_background_gdk().set_value(style->get_bg(STATE_ACTIVE));
|
|
|
|
warning_mtag->property_font_desc().set_value(style->get_font());
|
|
|
|
warning_mtag->property_foreground_gdk().set_value(style->get_fg(STATE_NORMAL));
|
|
|
|
warning_mtag->property_background_gdk().set_value(style->get_bg(STATE_NORMAL));
|
|
|
|
|
|
|
|
a_widget4.set_name ("InfoMessage");
|
|
|
|
a_widget4.ensure_style ();
|
|
|
|
style = a_widget4.get_style();
|
|
|
|
|
|
|
|
info_ptag->property_font_desc().set_value(style->get_font());
|
|
|
|
info_ptag->property_foreground_gdk().set_value(style->get_fg(STATE_ACTIVE));
|
|
|
|
info_ptag->property_background_gdk().set_value(style->get_bg(STATE_ACTIVE));
|
|
|
|
info_mtag->property_font_desc().set_value(style->get_font());
|
|
|
|
info_mtag->property_foreground_gdk().set_value(style->get_fg(STATE_NORMAL));
|
|
|
|
info_mtag->property_background_gdk().set_value(style->get_bg(STATE_NORMAL));
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::run (Receiver &old_receiver)
|
|
|
|
{
|
|
|
|
listen_to (error);
|
|
|
|
listen_to (info);
|
|
|
|
listen_to (warning);
|
|
|
|
listen_to (fatal);
|
|
|
|
|
|
|
|
old_receiver.hangup ();
|
|
|
|
starting ();
|
|
|
|
_active = true;
|
|
|
|
theMain->run ();
|
|
|
|
_active = false;
|
|
|
|
stopping ();
|
|
|
|
hangup ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UI::running ()
|
|
|
|
{
|
|
|
|
return _active;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::kill ()
|
|
|
|
{
|
|
|
|
if (_active) {
|
|
|
|
pthread_kill (gui_thread, SIGKILL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::quit ()
|
|
|
|
{
|
2006-04-24 18:45:19 -04:00
|
|
|
UIRequest *req = get_request (Quit);
|
|
|
|
|
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_request (req);
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
2005-12-04 23:11:08 -05:00
|
|
|
static bool idle_quit ()
|
|
|
|
{
|
|
|
|
Main::quit ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
void
|
|
|
|
UI::do_quit ()
|
|
|
|
{
|
2005-12-04 23:11:08 -05:00
|
|
|
Glib::signal_idle().connect (sigc::ptr_fun (idle_quit));
|
2005-12-02 14:18:26 -05:00
|
|
|
}
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
void
|
|
|
|
UI::touch_display (Touchable *display)
|
|
|
|
{
|
2006-04-24 18:45:19 -04:00
|
|
|
UIRequest *req = get_request (TouchDisplay);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->display = display;
|
|
|
|
|
|
|
|
send_request (req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-11-30 14:34:09 -05:00
|
|
|
UI::set_tip (Widget *w, const gchar *tip, const gchar *hlp)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-04-24 18:45:19 -04:00
|
|
|
UIRequest *req = get_request (SetTip);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->widget = w;
|
|
|
|
req->msg = tip;
|
|
|
|
req->msg2 = hlp;
|
|
|
|
|
|
|
|
send_request (req);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-11-30 14:34:09 -05:00
|
|
|
UI::set_state (Widget *w, StateType state)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-04-24 18:45:19 -04:00
|
|
|
UIRequest *req = get_request (StateChange);
|
2005-05-13 16:47:18 -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)
|
|
|
|
{
|
2006-04-24 18:45:19 -04:00
|
|
|
UIRequest *req = get_request (AddIdle);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->function = func;
|
|
|
|
req->arg = arg;
|
|
|
|
|
|
|
|
send_request (req);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* END abstract_ui interfaces */
|
|
|
|
|
|
|
|
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 ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-04-24 18:45:19 -04:00
|
|
|
UI::do_request (UIRequest* req)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2006-04-24 18:45:19 -04:00
|
|
|
if (req->type == ErrorMessage) {
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
process_error_message (req->chn, req->msg);
|
|
|
|
free (const_cast<char*>(req->msg)); /* it was strdup'ed */
|
2006-01-28 11:54:25 -05:00
|
|
|
req->msg = 0; /* don't free it again in the destructor */
|
2006-04-24 18:45:19 -04:00
|
|
|
|
|
|
|
} else if (req->type == Quit) {
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
do_quit ();
|
|
|
|
|
2006-04-24 18:45:19 -04:00
|
|
|
} else if (req->type == CallSlot) {
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
req->slot ();
|
2006-04-24 18:45:19 -04:00
|
|
|
|
|
|
|
} else if (req->type == TouchDisplay) {
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
req->display->touch ();
|
|
|
|
if (req->display->delete_after_touch()) {
|
|
|
|
delete req->display;
|
|
|
|
}
|
2006-04-24 18:45:19 -04:00
|
|
|
|
|
|
|
} else if (req->type == StateChange) {
|
|
|
|
|
2005-05-13 16:47:18 -04:00
|
|
|
req->widget->set_state (req->new_state);
|
|
|
|
|
2006-04-24 18:45:19 -04:00
|
|
|
} else if (req->type == SetTip) {
|
2005-05-13 16:47:18 -04:00
|
|
|
|
2006-04-24 18:45:19 -04:00
|
|
|
/* XXX need to figure out how this works */
|
2005-05-13 16:47:18 -04:00
|
|
|
|
2006-04-24 18:45:19 -04:00
|
|
|
} else {
|
2005-05-13 16:47:18 -04:00
|
|
|
|
2006-04-24 18:45:19 -04:00
|
|
|
error << "GtkUI: unknown request type "
|
|
|
|
<< (int) req->type
|
|
|
|
<< endmsg;
|
|
|
|
}
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*======================================================================
|
|
|
|
Error Display
|
|
|
|
======================================================================*/
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::receive (Transmitter::Channel chn, const char *str)
|
|
|
|
{
|
2006-04-24 18:45:19 -04:00
|
|
|
if (caller_is_ui_thread()) {
|
2005-05-13 16:47:18 -04:00
|
|
|
process_error_message (chn, str);
|
|
|
|
} else {
|
2006-04-24 18:45:19 -04:00
|
|
|
UIRequest* req = get_request (ErrorMessage);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
if (req == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
req->chn = chn;
|
|
|
|
req->msg = strdup (str);
|
|
|
|
|
|
|
|
send_request (req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OLD_STYLE_ERRORS 1
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::process_error_message (Transmitter::Channel chn, const char *str)
|
|
|
|
{
|
2005-11-30 14:34:09 -05:00
|
|
|
RefPtr<Style> style;
|
|
|
|
RefPtr<TextBuffer::Tag> ptag;
|
|
|
|
RefPtr<TextBuffer::Tag> mtag;
|
2005-05-13 16:47:18 -04:00
|
|
|
char *prefix;
|
|
|
|
size_t prefix_len;
|
|
|
|
bool fatal_received = false;
|
|
|
|
#ifndef OLD_STYLE_ERRORS
|
2005-11-30 14:34:09 -05:00
|
|
|
PopUp* popup = new PopUp (WIN_POS_CENTER, 0, true);
|
2005-05-13 16:47:18 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (chn) {
|
|
|
|
case Transmitter::Fatal:
|
|
|
|
prefix = "[FATAL]: ";
|
2005-11-30 14:34:09 -05:00
|
|
|
ptag = fatal_ptag;
|
|
|
|
mtag = fatal_mtag;
|
2005-05-13 16:47:18 -04:00
|
|
|
prefix_len = 9;
|
|
|
|
fatal_received = true;
|
|
|
|
break;
|
|
|
|
case Transmitter::Error:
|
|
|
|
#if OLD_STYLE_ERRORS
|
|
|
|
prefix = "[ERROR]: ";
|
2005-11-30 14:34:09 -05:00
|
|
|
ptag = error_ptag;
|
|
|
|
mtag = error_mtag;
|
2005-05-13 16:47:18 -04:00
|
|
|
prefix_len = 9;
|
|
|
|
#else
|
|
|
|
popup->set_name ("ErrorMessage");
|
|
|
|
popup->set_text (str);
|
|
|
|
popup->touch ();
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
case Transmitter::Info:
|
|
|
|
#if OLD_STYLE_ERRORS
|
|
|
|
prefix = "[INFO]: ";
|
2005-11-30 14:34:09 -05:00
|
|
|
ptag = info_ptag;
|
|
|
|
mtag = info_mtag;
|
2005-05-13 16:47:18 -04:00
|
|
|
prefix_len = 8;
|
|
|
|
#else
|
|
|
|
popup->set_name ("InfoMessage");
|
|
|
|
popup->set_text (str);
|
|
|
|
popup->touch ();
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
break;
|
|
|
|
case Transmitter::Warning:
|
|
|
|
#if OLD_STYLE_ERRORS
|
|
|
|
prefix = "[WARNING]: ";
|
2005-11-30 14:34:09 -05:00
|
|
|
ptag = warning_ptag;
|
|
|
|
mtag = warning_mtag;
|
2005-05-13 16:47:18 -04:00
|
|
|
prefix_len = 11;
|
|
|
|
#else
|
|
|
|
popup->set_name ("WarningMessage");
|
|
|
|
popup->set_text (str);
|
|
|
|
popup->touch ();
|
|
|
|
return;
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* no choice but to use text/console output here */
|
|
|
|
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 {
|
|
|
|
|
2005-11-30 14:34:09 -05:00
|
|
|
display_message (prefix, prefix_len, ptag, mtag, str);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
if (!errors->is_visible()) {
|
|
|
|
toggle_errors();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
errors->text().get_buffer()->end_user_action();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::toggle_errors ()
|
|
|
|
{
|
|
|
|
if (!errors->is_visible()) {
|
2005-11-30 14:34:09 -05:00
|
|
|
errors->set_position (WIN_POS_MOUSE);
|
2005-05-13 16:47:18 -04:00
|
|
|
errors->show ();
|
|
|
|
} else {
|
|
|
|
errors->hide ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-11-30 14:34:09 -05:00
|
|
|
UI::display_message (const char *prefix, gint prefix_len, RefPtr<TextBuffer::Tag> ptag, RefPtr<TextBuffer::Tag> mtag, const char *msg)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
2005-11-30 14:34:09 -05:00
|
|
|
RefPtr<TextBuffer> buffer (errors->text().get_buffer());
|
2005-05-13 16:47:18 -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 ();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::handle_fatal (const char *message)
|
|
|
|
{
|
2005-11-30 14:34:09 -05:00
|
|
|
Window win (WINDOW_POPUP);
|
|
|
|
VBox packer;
|
|
|
|
Label label (message);
|
|
|
|
Button quit (_("Press To Exit"));
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
win.set_default_size (400, 100);
|
|
|
|
|
|
|
|
string title;
|
2006-04-24 18:45:19 -04:00
|
|
|
title = name();
|
2005-05-13 16:47:18 -04:00
|
|
|
title += ": Fatal Error";
|
|
|
|
win.set_title (title);
|
|
|
|
|
2005-11-30 14:34:09 -05:00
|
|
|
win.set_position (WIN_POS_MOUSE);
|
2005-05-13 16:47:18 -04:00
|
|
|
win.add (packer);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::popup_error (const char *text)
|
|
|
|
{
|
|
|
|
PopUp *pup;
|
|
|
|
|
2006-04-24 18:45:19 -04:00
|
|
|
if (!caller_is_ui_thread()) {
|
2005-05-13 16:47:18 -04:00
|
|
|
error << "non-UI threads can't use UI::popup_error"
|
|
|
|
<< endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-11-30 14:34:09 -05:00
|
|
|
pup = new PopUp (WIN_POS_MOUSE, 0, true);
|
2005-05-13 16:47:18 -04:00
|
|
|
pup->set_text (text);
|
|
|
|
pup->touch ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::flush_pending ()
|
|
|
|
{
|
2006-04-24 18:45:19 -04:00
|
|
|
if (!caller_is_ui_thread()) {
|
2005-05-13 16:47:18 -04:00
|
|
|
error << "non-UI threads cannot call UI::flush_pending()"
|
|
|
|
<< endmsg;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gtk_main_iteration();
|
|
|
|
|
|
|
|
while (gtk_events_pending()) {
|
|
|
|
gtk_main_iteration();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2005-11-30 14:34:09 -05:00
|
|
|
UI::just_hide_it (GdkEventAny *ev, Window *win)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
|
|
|
win->hide_all ();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
Gdk::Color
|
2005-12-18 07:02:42 -05:00
|
|
|
UI::get_color (const string& prompt, bool& picked, const Gdk::Color* initial)
|
2005-05-13 16:47:18 -04:00
|
|
|
{
|
|
|
|
Gdk::Color color;
|
|
|
|
|
2005-11-30 14:34:09 -05:00
|
|
|
ColorSelectionDialog color_dialog (prompt);
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
color_dialog.set_modal (true);
|
|
|
|
color_dialog.get_cancel_button()->signal_clicked().connect (bind (mem_fun (*this, &UI::color_selection_done), false));
|
|
|
|
color_dialog.get_ok_button()->signal_clicked().connect (bind (mem_fun (*this, &UI::color_selection_done), true));
|
|
|
|
color_dialog.signal_delete_event().connect (mem_fun (*this, &UI::color_selection_deleted));
|
|
|
|
|
|
|
|
if (initial) {
|
|
|
|
color_dialog.get_colorsel()->set_current_color (*initial);
|
|
|
|
}
|
|
|
|
|
|
|
|
color_dialog.show_all ();
|
|
|
|
color_picked = false;
|
|
|
|
picked = false;
|
|
|
|
|
2005-11-30 14:34:09 -05:00
|
|
|
Main::run();
|
2005-05-13 16:47:18 -04:00
|
|
|
|
|
|
|
color_dialog.hide_all ();
|
|
|
|
|
|
|
|
if (color_picked) {
|
|
|
|
Gdk::Color f_rgba = color_dialog.get_colorsel()->get_current_color ();
|
|
|
|
color.set_red(f_rgba.get_red());
|
|
|
|
color.set_green(f_rgba.get_green());
|
|
|
|
color.set_blue(f_rgba.get_blue());
|
|
|
|
|
|
|
|
picked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
UI::color_selection_done (bool status)
|
|
|
|
{
|
|
|
|
color_picked = status;
|
2005-11-30 14:34:09 -05:00
|
|
|
Main::quit ();
|
2005-05-13 16:47:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
UI::color_selection_deleted (GdkEventAny *ev)
|
|
|
|
{
|
2005-11-30 14:34:09 -05:00
|
|
|
Main::quit ();
|
2005-05-13 16:47:18 -04:00
|
|
|
return true;
|
|
|
|
}
|