Merge branch 'nsm' of https://github.com/royvegard/ardour
[ardour.git] / libs / gtkmm2ext / gtkmm2ext / gtk_ui.h
index 5446374d7bad729214202883ee6108984e4895be..64176232f05f4a2f36d2cba695fb64217a9e202d 100644 (file)
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id$
 */
 
 #ifndef __pbd_gtk_ui_h__
 #define __pbd_gtk_ui_h__
 
 #include <string>
-#include <queue>
 #include <map>
 
 #include <stdint.h>
 #include <setjmp.h>
 #include <pthread.h>
+
+#include <glibmm/thread.h>
+
 #include <gtkmm/widget.h>
 #include <gtkmm/style.h>
+#ifndef GTK_NEW_TOOLTIP_API
+#include <gtkmm/tooltips.h>
+#endif
 #include <gtkmm/textbuffer.h>
 #include <gtkmm/main.h>
-#include <gtkmm/tooltips.h>
 #include <gdkmm/color.h>
 #include <pbd/abstract_ui.h>
 #include <pbd/ringbufferNPT.h>
-#include <pbd/atomic.h>
 #include <pbd/pool.h>
 #include <pbd/error.h>
 #include <pbd/receiver.h>
-#include <pbd/lockmonitor.h>
-
-using std::string;
-using std::queue;
 
 class Touchable;
 
@@ -51,8 +50,8 @@ namespace Gtkmm2ext {
 
 class TextViewer;
 
+extern BaseUI::RequestType NullMessage;
 extern BaseUI::RequestType ErrorMessage;
-extern BaseUI::RequestType Quit;
 extern BaseUI::RequestType CallSlot;
 extern BaseUI::RequestType TouchDisplay;
 extern BaseUI::RequestType StateChange;
@@ -76,20 +75,36 @@ struct UIRequest : public BaseUI::BaseRequestObject {
     Transmitter::Channel chn;
     void *arg;
     const char *msg2;
-    sigc::slot<void> slot;
+
+    UIRequest () {
+            type = NullMessage;
+    }
     
     ~UIRequest () { 
            if (type == ErrorMessage && msg) {
                    /* msg was strdup()'ed */
-                   free ((char *)msg);
+                   free (const_cast<char *>(msg));
            }
     }
- };
+};
 
-class UI : public Receiver, public AbstractUI<UIRequest>
+class UI : public AbstractUI<UIRequest>
 {
+  private:
+       class MyReceiver : public Receiver {
+         public:
+               MyReceiver (UI& ui) : _ui (ui) {}
+               void receive (Transmitter::Channel chn, const char *msg) {
+                       _ui.receive (chn, msg);
+               }
+         private:
+               UI& _ui;
+       };
+
+       MyReceiver _receiver;
+
   public:
-       UI (string name, int *argc, char **argv[], string rcfile);
+       UI (std::string name, int *argc, char **argv[]);
        virtual ~UI ();
 
        static UI *instance() { return theGtkUI; }
@@ -106,24 +121,32 @@ class UI : public Receiver, public AbstractUI<UIRequest>
 
        bool running ();
        void quit    ();
-       void kill    ();
-       int  load_rcfile (string);
+       int  load_rcfile (std::string, bool themechange = false);
        void run (Receiver &old_receiver);
 
        void set_state (Gtk::Widget *w, Gtk::StateType state);
-       void popup_error (const char *text);
+       void popup_error (const std::string& text);
        void flush_pending ();
        void toggle_errors ();
+       void show_errors ();
        void touch_display (Touchable *);
-       void set_tip (Gtk::Widget *w, const gchar *tip, const gchar *hlp);
+       void set_tip (Gtk::Widget &w, const gchar *tip);
+       void set_tip (Gtk::Widget &w, const std::string &tip);
+       void set_tip (Gtk::Widget *w, const gchar *tip, const gchar *hlp="");
        void idle_add (int (*func)(void *), void *arg);
 
+       Gtk::Main& main() const { return *theMain; }
+
        template<class T> static bool idle_delete (T *obj) { delete obj; return false; }
        template<class T> static void delete_when_idle (T *obj) {
                Glib::signal_idle().connect (bind (slot (&UI::idle_delete<T>), obj));
        }
 
-       Gdk::Color get_color (const string& prompt, bool& picked, const Gdk::Color *initial = 0);
+       template<class T> void delete_in_self (T *obj) {
+               call_slot (boost::bind (&UI::delete_in_self, this, obj));
+       }
+
+       Gdk::Color get_color (const std::string& prompt, bool& picked, const Gdk::Color *initial = 0);
 
        /* starting is sent just before we enter the main loop,
           stopping just after we return from it (at the top level)
@@ -132,23 +155,24 @@ class UI : public Receiver, public AbstractUI<UIRequest>
        sigc::signal<void> starting;
        sigc::signal<void> stopping;
 
-       static bool just_hide_it (GdkEventAny *, Gtk::Window *);
+       sigc::signal<void> theme_changed;
 
-       static pthread_t the_gui_thread() { return gui_thread; }
+       static bool just_hide_it (GdkEventAny *, Gtk::Window *);
 
   protected:
        virtual void handle_fatal (const char *);
-       virtual void display_message (const char *prefix, gint prefix_len, 
-                                     Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, 
-                                     Glib::RefPtr<Gtk::TextBuffer::Tag> mtag, 
-                                     const char *msg);
+       virtual void display_message (const char *prefix, gint prefix_len,
+                       Glib::RefPtr<Gtk::TextBuffer::Tag> ptag, Glib::RefPtr<Gtk::TextBuffer::Tag> mtag,
+                       const char *msg);
 
   private:
        static UI *theGtkUI;
-       static pthread_t gui_thread;
+
        bool _active;
        Gtk::Main *theMain;
+#ifndef GTK_NEW_TOOLTIP_API
        Gtk::Tooltips *tips;
+#endif
        TextViewer *errors;
        Glib::RefPtr<Gtk::TextBuffer::Tag> error_ptag;
        Glib::RefPtr<Gtk::TextBuffer::Tag> error_mtag;
@@ -168,6 +192,7 @@ class UI : public Receiver, public AbstractUI<UIRequest>
        bool color_picked;
 
        void do_request (UIRequest*);
+
 };
 
 } /* namespace */