Fix crash when X11 is not available for VST UIs
[ardour.git] / gtk2_ardour / ardour_message.cc
index 48cfa80caffdcdfbf5744a952aae19babebe2dc5..d6302fb2c62d2f6c51203a6d846c523a5e4911c8 100644 (file)
@@ -1,63 +1,98 @@
 /*
-    Copyright (C) 2004 Paul 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
-    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 <gtkmm/stock.h>
+ * Copyright (C) 2019 Robin Gareus <robin@gareus.org>
+ *
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
 #include "ardour_message.h"
-#include "i18n.h"
+#include "splash.h"
 
-using namespace std;
 using namespace Gtk;
 
-ArdourMessage::ArdourMessage (Gtk::Window* parent, 
-                             string name, string msg, 
-                             bool grab_focus, bool auto_run)
-       : ArdourDialog (name)
+ArdourMessageDialog::ArdourMessageDialog (const Glib::ustring& message,
+                                               bool use_markup,
+                                               Gtk::MessageType type,
+                                               Gtk::ButtonsType buttons,
+                                               bool modal)
+       : Gtk::MessageDialog (message, use_markup, type, buttons, modal)
+       , _splash_pushed (false)
 {
-       label.set_text (msg);
-       label.set_alignment (0.5, 0.5);
-       label.set_name (X_("PrompterLabel"));
+       set_position (WIN_POS_MOUSE);
+}
 
-       get_vbox()->pack_start (label);
+ArdourMessageDialog::ArdourMessageDialog (Gtk::Window& parent,
+                                               const Glib::ustring& message,
+                                               bool use_markup,
+                                               Gtk::MessageType type,
+                                               Gtk::ButtonsType buttons,
+                                               bool modal)
+       : Gtk::MessageDialog (parent, message, use_markup, type, buttons, modal)
+       , _splash_pushed (false)
+{
+       set_transient_for (parent);
+       set_position (WIN_POS_MOUSE);
+}
+
+ArdourMessageDialog::~ArdourMessageDialog ()
+{
+       pop_splash ();
+}
 
-       Button* ok_button = add_button (Stock::OK, RESPONSE_ACCEPT);
-       
-       set_name (X_("Prompter"));
-       set_position (Gtk::WIN_POS_MOUSE);
-       set_modal (true);
-       set_type_hint (Gdk::WINDOW_TYPE_HINT_MENU);
+int
+ArdourMessageDialog::run ()
+{
+       push_splash ();
+       int rv = Gtk::MessageDialog::run ();
+       pop_splash ();
+       return rv;
+}
 
-       if (grab_focus) {
-               ok_button->grab_focus ();
-       }
+void
+ArdourMessageDialog::show ()
+{
+       push_splash ();
+       Gtk::MessageDialog::show ();
+}
 
-       if (parent) {
-               set_transient_for (*parent);
-       }
+void
+ArdourMessageDialog::hide ()
+{
+       Gtk::MessageDialog::hide ();
+       pop_splash ();
+}
 
-       if (auto_run) {
-               run ();
+void
+ArdourMessageDialog::pop_splash ()
+{
+       if (_splash_pushed) {
+               Splash* spl = Splash::instance();
+               if (spl) {
+                       spl->pop_front();
+               }
+               _splash_pushed = false;
        }
 }
 
-ArdourMessage::~ArdourMessage()
+void
+ArdourMessageDialog::push_splash ()
 {
+       if (Splash::exists()) {
+               Splash* spl = Splash::instance();
+               if (spl->is_visible()) {
+                       spl->pop_back_for (*this);
+                       _splash_pushed = true;
+               }
+       }
 }