nick m's fix for markers etc ; several tweaks for mute/solo ; rename run_in_place...
[ardour.git] / libs / gtkmm2ext / gtk_ui.cc
index 55a6bebb02ba1313a48543054f118e9b39bbe730..7b60d6ba52b33d5e111d315514609478d3c157dd 100644 (file)
@@ -37,6 +37,7 @@
 #include <gtkmm2ext/textviewer.h>
 #include <gtkmm2ext/popup.h>
 #include <gtkmm2ext/utils.h>
+#include <gtkmm2ext/window_title.h>
 
 #include "i18n.h"
 
@@ -60,11 +61,13 @@ 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
+UI::UI (string namestr, int *argc, char ***argv) 
        : AbstractUI<UIRequest> (namestr, true)
 {
        theMain = new Main (argc, argv);
+#ifndef GTK_NEW_TOOLTIP_API
        tips = new Tooltips;
+#endif
 
        _active = false;
 
@@ -87,17 +90,19 @@ UI::UI (string namestr, int *argc, char ***argv, string rcfile)
        errors->text().set_editable (false); 
        errors->text().set_name ("ErrorText");
 
-       string title;
-       title = namestr;
-       title += ": Log";
-       errors->set_title (title);
+       Glib::set_application_name(namestr);
+
+       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 (bind (sigc::ptr_fun (just_hide_it), (Window *) errors));
+       errors->set_type_hint (Gdk::WINDOW_TYPE_HINT_UTILITY);
 
        register_thread (pthread_self(), X_("GUI"));
 
-       load_rcfile (rcfile);
+       //load_rcfile (rcfile);
 }
 
 UI::~UI ()
@@ -112,7 +117,7 @@ UI::caller_is_ui_thread ()
 }
 
 int
-UI::load_rcfile (string path)
+UI::load_rcfile (string path, bool themechange)
 {
        if (path.length() == 0) {
                return -1;
@@ -127,6 +132,13 @@ UI::load_rcfile (string path)
        }
        
        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 */
 
@@ -253,7 +265,11 @@ static bool idle_quit ()
 void
 UI::do_quit ()
 {
-       Glib::signal_idle().connect (sigc::ptr_fun (idle_quit));
+       if (getenv ("ARDOUR_RUNNING_UNDER_VALGRIND")) {
+               Main::quit ();
+       } else {
+               Glib::signal_idle().connect (sigc::ptr_fun (idle_quit));
+       }
 }
 
 void
@@ -325,7 +341,7 @@ UI::signal_pipe_callback (void *arg, int fd, GdkInputCondition cond)
        
        /* flush (nonblocking) pipe */
        
-       while (read (fd, buf, 256) > 0);
+       while (read (fd, buf, 256) > 0) {}
        
        ((UI *) arg)->handle_ui_requests ();
 }
@@ -360,7 +376,16 @@ UI::do_request (UIRequest* req)
 
        } else if (req->type == SetTip) {
 
-               /* XXX need to figure out how this works */
+#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
 
        } else {
 
@@ -401,7 +426,7 @@ UI::process_error_message (Transmitter::Channel chn, const char *str)
        RefPtr<Style> style;
        RefPtr<TextBuffer::Tag> ptag;
        RefPtr<TextBuffer::Tag> mtag;
-       char *prefix;
+       const char *prefix;
        size_t prefix_len;
        bool fatal_received = false;
 #ifndef OLD_STYLE_ERRORS
@@ -547,10 +572,31 @@ UI::popup_error (const char *text)
        pup->touch ();
 }
 
+#ifdef GTKOSX
+extern "C" {
+       int gdk_quartz_in_carbon_menu_event_handler ();
+}
+#endif
 
 void
 UI::flush_pending ()
 {
+#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;
@@ -567,7 +613,7 @@ UI::flush_pending ()
 bool
 UI::just_hide_it (GdkEventAny *ev, Window *win)
 {
-       win->hide_all ();
+       win->hide ();
        return true;
 }