2 Copyright (C) 2008 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include "pbd/failed_constructor.h"
23 #include "pbd/file_utils.h"
25 #include "ardour/ardour.h"
26 #include "ardour/filesystem_paths.h"
32 #include "gui_thread.h"
41 using namespace ARDOUR;
43 Splash* Splash::the_splash = 0;
47 assert (the_splash == 0);
49 std::string splash_file;
51 if (!find_file (ardour_data_search_path(), "splash.png", splash_file)) {
52 cerr << "Cannot find splash screen image file\n";
53 throw failed_constructor();
57 pixbuf = Gdk::Pixbuf::create_from_file (splash_file);
61 cerr << "Cannot construct splash screen image\n";
62 throw failed_constructor();
65 darea.set_size_request (pixbuf->get_width(), pixbuf->get_height());
67 set_position (WIN_POS_CENTER);
68 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
69 darea.set_double_buffered (false);
71 layout = create_pango_layout ("");
73 string i18n = string_compose (_("%1 loading ..."), PROGRAM_NAME);
77 layout->set_markup (str);
80 darea.signal_expose_event().connect (sigc::mem_fun (*this, &Splash::expose));
84 set_default_size (pixbuf->get_width(), pixbuf->get_height());
85 set_resizable (false);
86 set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);
90 expose_is_the_one = false;
92 ARDOUR::BootMessage.connect (msg_connection, invalidator (*this), boost::bind (&Splash::boot_message, this, _1), gui_context());
101 Splash::pop_back_for (Gtk::Window& win)
103 #if defined __APPLE__ || defined PLATFORM_WINDOWS
104 /* April 2013: window layering on OS X is a bit different to X Window. at present,
105 the "restack()" functionality in GDK will only operate on windows in the same
106 "level" (e.g. two normal top level windows, or two utility windows) and will not
107 work across them. The splashscreen is on its own "StatusWindowLevel" so restacking
108 is not going to work.
110 So for OS X, we just hide ourselves.
112 Oct 2014: The Windows situation is similar, although it should be possible
113 to play tricks with gdk's set_type_hint() or directly hack things using
114 SetWindowLong() and UpdateLayeredWindow()
119 set_keep_above (false);
120 get_window()->restack (win.get_window(), false);
128 #if defined __APPLE__ || defined PLATFORM_WINDOWS
136 Splash::on_realize ()
138 Window::on_realize ();
139 get_window()->set_decorations (Gdk::WMDecoration(0));
140 layout->set_font_description (get_style()->get_font());
144 Splash::on_button_release_event (GdkEventButton* ev)
146 RefPtr<Gdk::Window> window = get_window();
148 if (!window || ev->window != window->gobj()) {
157 Splash::expose (GdkEventExpose* ev)
159 RefPtr<Gdk::Window> window = darea.get_window();
161 /* note: height & width need to be constrained to the pixbuf size
162 in case a WM provides us with a screwy allocation
165 window->draw_pixbuf (get_style()->get_bg_gc (STATE_NORMAL), pixbuf,
166 ev->area.x, ev->area.y,
167 ev->area.x, ev->area.y,
168 min ((pixbuf->get_width() - ev->area.x), ev->area.width),
169 min ((pixbuf->get_height() - ev->area.y), ev->area.height),
170 Gdk::RGB_DITHER_NONE, 0, 0);
172 Glib::RefPtr<Gtk::Style> style = darea.get_style();
173 Glib::RefPtr<Gdk::GC> white = style->get_white_gc();
175 window->draw_layout (white, 10, pixbuf->get_height() - 30, layout);
177 /* this must execute AFTER the GDK idle update mechanism
180 if (expose_is_the_one) {
181 Glib::signal_idle().connect (sigc::mem_fun (this, &Splash::idle_after_expose),
182 GDK_PRIORITY_REDRAW+2);
189 Splash::boot_message (std::string msg)
195 Splash::idle_after_expose ()
204 bool was_mapped = is_mapped ();
208 expose_is_the_one = false;
215 while (!expose_done) {
216 gtk_main_iteration ();
218 gdk_display_flush (gdk_display_get_default());
223 Splash::message (const string& msg)
226 str += Glib::Markup::escape_text (msg);
231 layout->set_markup (str);
232 Glib::RefPtr<Gdk::Window> win = darea.get_window();
237 if (win->is_visible ()) {
238 win->invalidate_rect (Gdk::Rectangle (0, darea.get_height() - 30, darea.get_width(), 30), true);
246 Splash::on_map_event (GdkEventAny* ev)
248 expose_is_the_one = true;
249 return Window::on_map_event (ev);