fix keyboard event handling for host-provided plugin GUIs
[ardour2.git] / gtk2_ardour / splash.cc
blobaecc4319305313fd69f9b6dc0055a4f480147d4b
1 #include <string>
3 #include <pbd/failed_constructor.h>
4 #include <ardour/ardour.h>
6 #include "gui_thread.h"
7 #include "splash.h"
9 #include "i18n.h"
11 using namespace Gtk;
12 using namespace Glib;
13 using namespace std;
14 using namespace ARDOUR;
16 Splash* Splash::the_splash = 0;
18 Splash::Splash ()
20 string path = find_data_file ("splash.png");
22 if (path.empty()) {
23 throw failed_constructor();
26 try {
27 pixbuf = Gdk::Pixbuf::create_from_file (path);
30 catch (...) {
31 throw failed_constructor();
34 darea.set_size_request (pixbuf->get_width(), pixbuf->get_height());
35 set_keep_above (true);
36 set_position (WIN_POS_CENTER);
37 darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
38 darea.set_double_buffered (false);
40 layout = create_pango_layout ("");
41 string str = "<b>";
42 string i18n = string_compose (_("%1 loading ..."), PROGRAM_NAME);
43 str += i18n;
44 str += "</b>";
46 layout->set_markup (str);
48 darea.show ();
49 darea.signal_expose_event().connect (mem_fun (*this, &Splash::expose));
51 add (darea);
53 set_default_size (pixbuf->get_width(), pixbuf->get_height());
54 the_splash = this;
56 ARDOUR::BootMessage.connect (mem_fun (*this, &Splash::boot_message));
59 void
60 Splash::pop_back ()
62 set_keep_above (false);
65 void
66 Splash::on_realize ()
68 Window::on_realize ();
70 // Without override redirect, splash screen has redraw problems with ion3.
71 // With override redirect, it is not properly on top with some other
72 // popular (metacity for example) window managers.
73 // Maybe setting override redirect and something else (like the splash wm hint)
74 // will make the splash to work for everybody
75 // Override redirect only does not work on OS X too.
76 // Until we find solution that works for everybody this env var kludge is used
77 if (getenv ("ARDOUR_USE_OVERRIDE_REDIRECT_SPLASH") != 0) {
78 get_window()->set_override_redirect (true);
79 } else {
80 get_window()->set_decorations (Gdk::WMDecoration (0));
83 layout->set_font_description (get_style()->get_font());
87 bool
88 Splash::on_button_release_event (GdkEventButton* ev)
90 hide ();
91 return true;
94 bool
95 Splash::expose (GdkEventExpose* ev)
97 RefPtr<Gdk::Window> window = darea.get_window();
99 /* note: height & width need to be constrained to the pixbuf size
100 in case a WM provides us with a screwy allocation
103 window->draw_pixbuf (get_style()->get_bg_gc (STATE_NORMAL), pixbuf,
104 ev->area.x, ev->area.y,
105 ev->area.x, ev->area.y,
106 min ((pixbuf->get_width() - ev->area.x), ev->area.width),
107 min ((pixbuf->get_height() - ev->area.y), ev->area.height),
108 Gdk::RGB_DITHER_NONE, 0, 0);
110 Glib::RefPtr<Gtk::Style> style = darea.get_style();
111 Glib::RefPtr<Gdk::GC> white = style->get_white_gc();
113 window->draw_layout (white, 10, pixbuf->get_height() - 30, layout);
115 return true;
118 void
119 Splash::boot_message (std::string msg)
121 message (msg);
124 void
125 Splash::message (const string& msg)
127 string str ("<b>");
128 str += msg;
129 str += "</b>";
131 layout->set_markup (str);
132 Glib::RefPtr<Gdk::Window> win = darea.get_window();
134 if (win) {
135 win->invalidate_rect (Gdk::Rectangle (0, darea.get_height() - 30,
136 darea.get_width(), 30), true);
137 win->process_updates (true);
138 gdk_flush ();