Merge branch 'master' into windows
[ardour.git] / libs / gtkmm2ext / popup.cc
index a29be1932fcaeff7157faefd787e9c00add96c9d..6f4a8a5427d3372d6787098a08b92aac7103bc80 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <gtkmm2ext/popup.h>
 #include <gtkmm2ext/utils.h>
+#include <gtkmm2ext/gtk_ui.h>
 
 using namespace std;
 using namespace Gtk;
@@ -30,10 +31,6 @@ using namespace Gtkmm2ext;
 PopUp::PopUp (Gtk::WindowPosition pos, unsigned int showfor_msecs, bool doh)
        : Window (WINDOW_POPUP)
 {
-
-       realize ();
-       Glib::RefPtr<Gdk::Window> win (get_window());
-       win->set_decorations (Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH));
        add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
        signal_button_press_event().connect(mem_fun(*this,&PopUp::button_click));
        set_border_width (12);
@@ -50,6 +47,13 @@ PopUp::~PopUp ()
 {
 }
 
+void
+PopUp::on_realize ()
+{
+       Gtk::Window::on_realize();
+       get_window()->set_decorations (Gdk::WMDecoration (Gdk::DECOR_BORDER|Gdk::DECOR_RESIZEH));
+}
+
 gint
 PopUp::remove_prompt_timeout (void *arg)
 {
@@ -70,18 +74,27 @@ PopUp::remove ()
 {
        hide ();
 
+       if (popdown_time != 0 && timeout != -1) {
+               g_source_remove (timeout);
+       }
+
        if (delete_on_hide) {
                std::cerr << "deleting prompter\n";
-               if (popdown_time != 0 && timeout != -1) {
-                       gtk_timeout_remove (timeout);
-               }
-               gtk_idle_add (idle_delete, this);
+               g_idle_add (idle_delete, this);
        }
 }
+#define ENSURE_GUI_THREAD(slot) \
+     if (!Gtkmm2ext::UI::instance()->caller_is_ui_thread()) {\
+             Gtkmm2ext::UI::instance()->call_slot (MISSING_INVALIDATOR, (slot)); \
+        return;\
+     }
+
 
 void
 PopUp::touch ()
 {
+       ENSURE_GUI_THREAD (mem_fun (*this, &PopUp::touch));
+
        if (is_visible ()) {
                remove ();
        } else {
@@ -90,7 +103,7 @@ PopUp::touch ()
                show_all ();
                
                if (popdown_time != 0) {
-                       timeout = gtk_timeout_add (popdown_time, 
+                       timeout = g_timeout_add (popdown_time, 
                                                   remove_prompt_timeout, 
                                                   this);
                }
@@ -98,7 +111,7 @@ PopUp::touch ()
 }
 
 gint
-PopUp::button_click (GdkEventButton *ev)
+PopUp::button_click (GdkEventButton */*ev*/)
 {
        remove ();
        return TRUE;
@@ -118,16 +131,17 @@ PopUp::set_name (string name)
 }
 
 bool
-PopUp::on_delete_event (GdkEventAny* ev)
+PopUp::on_delete_event (GdkEventAny* /*ev*/)
 {
        hide();
 
+       if (popdown_time != 0 && timeout != -1) {
+               g_source_remove (timeout);
+       }       
+
        if (delete_on_hide) {
                std::cerr << "deleting prompter\n" << endl;
-               if (popdown_time != 0 && timeout != -1) {
-                       gtk_timeout_remove (timeout);
-               }
-               gtk_idle_add (idle_delete, this);
+               g_idle_add (idle_delete, this);
        }
 
        return true;