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
|
|
|
|
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);
|
2012-06-01 15:49:40 -04:00
|
|
|
|
2012-06-23 01:06:54 -04:00
|
|
|
std::string splash_file;
|
2008-01-18 22:49:52 -05:00
|
|
|
|
2012-05-18 13:24:06 -04:00
|
|
|
if (!find_file_in_search_path (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
|
|
|
{
|
2013-04-30 13:50:15 -04:00
|
|
|
#ifdef __APPLE__
|
|
|
|
/* 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
|
|
|
|
work across them. The splashscreen is on its own "StatusWindowLevel" so restacking
|
|
|
|
is not going to work.
|
|
|
|
|
|
|
|
So for OS X, we just hide ourselves.
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
|
|
|
#ifdef __APPLE__
|
|
|
|
if (get_window()) {
|
|
|
|
show ();
|
|
|
|
}
|
|
|
|
#else
|
2012-01-10 13:21:39 -05:00
|
|
|
set_keep_above (true);
|
2013-04-30 13:50:15 -04:00
|
|
|
#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();
|
|
|
|
|
|
|
|
if (!window || ev->window != window->gobj()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
/* this must execute AFTER the GDK idle update mechanism
|
|
|
|
*/
|
2012-07-09 21:04:36 -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 ();
|
|
|
|
|
|
|
|
if (!was_mapped) {
|
|
|
|
expose_done = false;
|
2013-03-04 13:19:05 -05:00
|
|
|
expose_is_the_one = false;
|
|
|
|
}
|
2012-07-09 21:04:36 -04:00
|
|
|
|
|
|
|
pop_front ();
|
|
|
|
present ();
|
|
|
|
|
|
|
|
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>");
|
2012-10-23 10:45:09 -04:00
|
|
|
str += Glib::Markup::escape_text (msg);
|
2008-01-19 00:06:33 -05:00
|
|
|
str += "</b>";
|
|
|
|
|
|
|
|
layout->set_markup (str);
|
2008-02-16 17:43:18 -05:00
|
|
|
Glib::RefPtr<Gdk::Window> win = darea.get_window();
|
2012-12-10 20:21:17 -05: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 ();
|
|
|
|
}
|
2012-07-09 21:04:36 -04:00
|
|
|
|
|
|
|
while (!expose_done) {
|
2013-07-04 15:32:41 -04:00
|
|
|
if(gtk_main_iteration ()) return; // quit was called
|
2012-07-09 21:04:36 -04:00
|
|
|
}
|
2013-03-04 13:19:05 -05:00
|
|
|
gdk_display_flush (gdk_display_get_default());
|
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);
|
|
|
|
}
|