2012-06-01 15:49:40 -04:00
|
|
|
/*
|
|
|
|
Copyright (C) 2008 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.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2008-01-18 22:49:52 -05:00
|
|
|
#include <string>
|
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "pbd/failed_constructor.h"
|
|
|
|
#include "pbd/file_utils.h"
|
2012-07-09 21:04:36 -04:00
|
|
|
|
2009-02-25 13:26:51 -05:00
|
|
|
#include "ardour/ardour.h"
|
|
|
|
#include "ardour/filesystem_paths.h"
|
2008-01-18 22:49:52 -05:00
|
|
|
|
2015-10-15 05:24:15 -04:00
|
|
|
#include "gtkmm2ext/utils.h"
|
|
|
|
|
2013-04-30 13:50:15 -04:00
|
|
|
#ifdef check
|
|
|
|
#undef check
|
|
|
|
#endif
|
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
#include "gui_thread.h"
|
2008-01-18 22:49:52 -05:00
|
|
|
#include "splash.h"
|
|
|
|
|
|
|
|
#include "i18n.h"
|
|
|
|
|
|
|
|
using namespace Gtk;
|
|
|
|
using namespace Glib;
|
2009-05-12 13:03:42 -04:00
|
|
|
using namespace PBD;
|
2008-01-18 22:49:52 -05:00
|
|
|
using namespace std;
|
|
|
|
using namespace ARDOUR;
|
|
|
|
|
2008-02-02 12:22:04 -05:00
|
|
|
Splash* Splash::the_splash = 0;
|
|
|
|
|
2008-01-18 22:49:52 -05:00
|
|
|
Splash::Splash ()
|
|
|
|
{
|
2012-06-01 16:01:37 -04:00
|
|
|
assert (the_splash == 0);
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-06-23 01:06:54 -04:00
|
|
|
std::string splash_file;
|
2008-01-18 22:49:52 -05:00
|
|
|
|
2014-06-19 07:23:12 -04:00
|
|
|
if (!find_file (ardour_data_search_path(), "splash.png", splash_file)) {
|
2012-07-09 21:04:36 -04:00
|
|
|
cerr << "Cannot find splash screen image file\n";
|
2008-01-18 22:49:52 -05:00
|
|
|
throw failed_constructor();
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2012-06-23 01:06:54 -04:00
|
|
|
pixbuf = Gdk::Pixbuf::create_from_file (splash_file);
|
2008-01-18 22:49:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
catch (...) {
|
2012-07-09 21:04:36 -04:00
|
|
|
cerr << "Cannot construct splash screen image\n";
|
2008-01-18 22:49:52 -05:00
|
|
|
throw failed_constructor();
|
|
|
|
}
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-01-19 00:06:33 -05:00
|
|
|
darea.set_size_request (pixbuf->get_width(), pixbuf->get_height());
|
2012-01-10 13:21:39 -05:00
|
|
|
pop_front ();
|
2008-01-18 22:49:52 -05:00
|
|
|
set_position (WIN_POS_CENTER);
|
2008-01-19 00:06:33 -05:00
|
|
|
darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
|
2008-02-16 17:43:18 -05:00
|
|
|
darea.set_double_buffered (false);
|
2008-01-19 00:06:33 -05:00
|
|
|
|
|
|
|
layout = create_pango_layout ("");
|
2008-02-01 22:57:35 -05:00
|
|
|
string str = "<b>";
|
2010-03-14 22:31:27 -04:00
|
|
|
string i18n = string_compose (_("%1 loading ..."), PROGRAM_NAME);
|
2008-02-01 22:57:35 -05:00
|
|
|
str += i18n;
|
|
|
|
str += "</b>";
|
|
|
|
|
|
|
|
layout->set_markup (str);
|
2008-01-19 00:06:33 -05:00
|
|
|
|
|
|
|
darea.show ();
|
2009-12-11 18:29:48 -05:00
|
|
|
darea.signal_expose_event().connect (sigc::mem_fun (*this, &Splash::expose));
|
2008-01-19 00:06:33 -05:00
|
|
|
|
|
|
|
add (darea);
|
2008-02-02 12:22:04 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
set_default_size (pixbuf->get_width(), pixbuf->get_height());
|
2012-08-07 19:56:17 -04:00
|
|
|
set_resizable (false);
|
2012-11-13 22:35:25 -05:00
|
|
|
set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);
|
2008-02-02 12:22:04 -05:00
|
|
|
the_splash = this;
|
2008-02-16 17:43:18 -05:00
|
|
|
|
2012-07-09 21:04:36 -04:00
|
|
|
expose_done = false;
|
2013-03-04 13:19:05 -05:00
|
|
|
expose_is_the_one = false;
|
2012-07-09 21:04:36 -04:00
|
|
|
|
2012-04-25 08:58:19 -04:00
|
|
|
ARDOUR::BootMessage.connect (msg_connection, invalidator (*this), boost::bind (&Splash::boot_message, this, _1), gui_context());
|
2008-02-02 12:22:04 -05:00
|
|
|
}
|
|
|
|
|
2012-06-01 15:49:40 -04:00
|
|
|
Splash::~Splash ()
|
|
|
|
{
|
|
|
|
the_splash = 0;
|
|
|
|
}
|
|
|
|
|
2008-02-02 12:22:04 -05:00
|
|
|
void
|
2012-01-10 13:21:39 -05:00
|
|
|
Splash::pop_back_for (Gtk::Window& win)
|
2008-02-02 12:22:04 -05:00
|
|
|
{
|
2014-10-22 08:29:33 -04:00
|
|
|
#if defined __APPLE__ || defined PLATFORM_WINDOWS
|
2013-04-30 13:50:15 -04:00
|
|
|
/* April 2013: window layering on OS X is a bit different to X Window. at present,
|
|
|
|
the "restack()" functionality in GDK will only operate on windows in the same
|
|
|
|
"level" (e.g. two normal top level windows, or two utility windows) and will not
|
2015-10-04 14:51:05 -04:00
|
|
|
work across them. The splashscreen is on its own "StatusWindowLevel" so restacking
|
2013-04-30 13:50:15 -04:00
|
|
|
is not going to work.
|
|
|
|
|
|
|
|
So for OS X, we just hide ourselves.
|
2014-10-22 08:29:33 -04:00
|
|
|
|
|
|
|
Oct 2014: The Windows situation is similar, although it should be possible
|
|
|
|
to play tricks with gdk's set_type_hint() or directly hack things using
|
|
|
|
SetWindowLong() and UpdateLayeredWindow()
|
2013-04-30 13:50:15 -04:00
|
|
|
*/
|
2014-01-11 15:01:29 -05:00
|
|
|
(void) win;
|
2013-04-30 13:50:15 -04:00
|
|
|
hide();
|
|
|
|
#else
|
2008-02-02 12:22:04 -05:00
|
|
|
set_keep_above (false);
|
2012-01-10 13:21:39 -05:00
|
|
|
get_window()->restack (win.get_window(), false);
|
2013-04-30 13:50:15 -04:00
|
|
|
#endif
|
2012-01-10 13:21:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Splash::pop_front ()
|
|
|
|
{
|
2013-04-30 13:50:15 -04:00
|
|
|
|
2014-10-22 08:29:33 -04:00
|
|
|
#if defined __APPLE__ || defined PLATFORM_WINDOWS
|
2013-04-30 13:50:15 -04:00
|
|
|
if (get_window()) {
|
|
|
|
show ();
|
|
|
|
}
|
|
|
|
#endif
|
2008-01-19 00:06:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Splash::on_realize ()
|
|
|
|
{
|
|
|
|
Window::on_realize ();
|
2008-02-01 22:57:35 -05:00
|
|
|
get_window()->set_decorations (Gdk::WMDecoration(0));
|
2008-01-19 00:06:33 -05:00
|
|
|
layout->set_font_description (get_style()->get_font());
|
2008-01-18 22:49:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2012-07-09 21:04:36 -04:00
|
|
|
Splash::on_button_release_event (GdkEventButton* ev)
|
2008-01-18 22:49:52 -05:00
|
|
|
{
|
2012-07-09 21:04:36 -04:00
|
|
|
RefPtr<Gdk::Window> window = get_window();
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2012-07-09 21:04:36 -04:00
|
|
|
if (!window || ev->window != window->gobj()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2008-01-18 22:49:52 -05:00
|
|
|
hide ();
|
2008-01-19 00:06:33 -05:00
|
|
|
return true;
|
2008-01-18 22:49:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2008-01-19 00:06:33 -05:00
|
|
|
Splash::expose (GdkEventExpose* ev)
|
2008-01-18 22:49:52 -05:00
|
|
|
{
|
2008-01-19 00:06:33 -05:00
|
|
|
RefPtr<Gdk::Window> window = darea.get_window();
|
2008-01-18 22:49:52 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
/* note: height & width need to be constrained to the pixbuf size
|
|
|
|
in case a WM provides us with a screwy allocation
|
|
|
|
*/
|
|
|
|
|
2008-02-01 22:57:35 -05:00
|
|
|
window->draw_pixbuf (get_style()->get_bg_gc (STATE_NORMAL), pixbuf,
|
2008-01-18 22:49:52 -05:00
|
|
|
ev->area.x, ev->area.y,
|
|
|
|
ev->area.x, ev->area.y,
|
2009-10-14 12:10:01 -04:00
|
|
|
min ((pixbuf->get_width() - ev->area.x), ev->area.width),
|
2008-02-16 17:43:18 -05:00
|
|
|
min ((pixbuf->get_height() - ev->area.y), ev->area.height),
|
2008-01-18 22:49:52 -05:00
|
|
|
Gdk::RGB_DITHER_NONE, 0, 0);
|
2009-10-14 12:10:01 -04:00
|
|
|
|
2008-02-01 22:57:35 -05:00
|
|
|
Glib::RefPtr<Gtk::Style> style = darea.get_style();
|
2008-01-19 00:06:33 -05:00
|
|
|
Glib::RefPtr<Gdk::GC> white = style->get_white_gc();
|
|
|
|
|
|
|
|
window->draw_layout (white, 10, pixbuf->get_height() - 30, layout);
|
2012-12-05 18:58:27 -05:00
|
|
|
|
2015-10-04 14:51:05 -04:00
|
|
|
/* this must execute AFTER the GDK idle update mechanism
|
2012-12-05 18:58:27 -05:00
|
|
|
*/
|
2015-10-04 14:51:05 -04:00
|
|
|
|
2013-03-04 13:19:05 -05:00
|
|
|
if (expose_is_the_one) {
|
|
|
|
Glib::signal_idle().connect (sigc::mem_fun (this, &Splash::idle_after_expose),
|
|
|
|
GDK_PRIORITY_REDRAW+2);
|
|
|
|
}
|
2008-02-01 22:57:35 -05:00
|
|
|
|
2008-01-18 22:49:52 -05:00
|
|
|
return true;
|
|
|
|
}
|
2008-01-19 00:06:33 -05:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
void
|
|
|
|
Splash::boot_message (std::string msg)
|
|
|
|
{
|
|
|
|
message (msg);
|
|
|
|
}
|
|
|
|
|
2012-07-09 21:04:36 -04:00
|
|
|
bool
|
|
|
|
Splash::idle_after_expose ()
|
|
|
|
{
|
|
|
|
expose_done = true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Splash::display ()
|
|
|
|
{
|
|
|
|
bool was_mapped = is_mapped ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-09 21:04:36 -04:00
|
|
|
if (!was_mapped) {
|
|
|
|
expose_done = false;
|
2013-03-04 13:19:05 -05:00
|
|
|
expose_is_the_one = false;
|
2015-10-04 14:51:05 -04:00
|
|
|
}
|
2012-07-09 21:04:36 -04:00
|
|
|
|
|
|
|
pop_front ();
|
|
|
|
present ();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2012-07-09 21:04:36 -04:00
|
|
|
if (!was_mapped) {
|
|
|
|
while (!expose_done) {
|
|
|
|
gtk_main_iteration ();
|
|
|
|
}
|
2013-03-04 13:19:05 -05:00
|
|
|
gdk_display_flush (gdk_display_get_default());
|
2012-07-09 21:04:36 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-19 00:06:33 -05:00
|
|
|
void
|
|
|
|
Splash::message (const string& msg)
|
|
|
|
{
|
|
|
|
string str ("<b>");
|
2015-10-15 05:24:15 -04:00
|
|
|
str += Gtkmm2ext::markup_escape_text (msg);
|
2008-01-19 00:06:33 -05:00
|
|
|
str += "</b>";
|
|
|
|
|
2014-02-28 16:40:01 -05:00
|
|
|
show ();
|
|
|
|
|
2008-01-19 00:06:33 -05:00
|
|
|
layout->set_markup (str);
|
2008-02-16 17:43:18 -05:00
|
|
|
Glib::RefPtr<Gdk::Window> win = darea.get_window();
|
2015-10-05 10:17:49 -04:00
|
|
|
|
2008-02-16 17:43:18 -05:00
|
|
|
if (win) {
|
2012-07-09 21:04:36 -04:00
|
|
|
expose_done = false;
|
2012-12-05 18:58:27 -05:00
|
|
|
|
2012-12-10 20:21:17 -05:00
|
|
|
if (win->is_visible ()) {
|
|
|
|
win->invalidate_rect (Gdk::Rectangle (0, darea.get_height() - 30, darea.get_width(), 30), true);
|
|
|
|
} else {
|
|
|
|
darea.queue_draw ();
|
|
|
|
}
|
2008-02-16 17:43:18 -05:00
|
|
|
}
|
2008-01-19 00:06:33 -05:00
|
|
|
}
|
2013-03-04 13:19:05 -05:00
|
|
|
|
|
|
|
bool
|
|
|
|
Splash::on_map_event (GdkEventAny* ev)
|
|
|
|
{
|
|
|
|
expose_is_the_one = true;
|
|
|
|
return Window::on_map_event (ev);
|
|
|
|
}
|