packaging tweaks for OS X
[ardour.git] / gtk2_ardour / splash.cc
1 #include <string>
2
3 #include "pbd/failed_constructor.h"
4 #include "pbd/file_utils.h"
5 #include "ardour/ardour.h"
6 #include "ardour/filesystem_paths.h"
7
8 #include "gui_thread.h"
9 #include "splash.h"
10
11 #include "i18n.h"
12
13 using namespace Gtk;
14 using namespace Glib;
15 using namespace PBD;
16 using namespace std;
17 using namespace ARDOUR;
18
19 Splash* Splash::the_splash = 0;
20
21 Splash::Splash ()
22 {
23         sys::path splash_file;
24
25         if (!find_file_in_search_path (ardour_data_search_path(), "splash.png", splash_file)) {
26                 throw failed_constructor();
27         }
28
29         try {
30                 pixbuf = Gdk::Pixbuf::create_from_file (splash_file.to_string());
31         }
32
33         catch (...) {
34                 throw failed_constructor();
35         }
36
37         darea.set_size_request (pixbuf->get_width(), pixbuf->get_height());
38         pop_front ();
39         set_position (WIN_POS_CENTER);
40         darea.add_events (Gdk::BUTTON_PRESS_MASK|Gdk::BUTTON_RELEASE_MASK);
41         darea.set_double_buffered (false);
42
43         layout = create_pango_layout ("");
44         string str = "<b>";
45         string i18n = string_compose (_("%1 loading ..."), PROGRAM_NAME);
46         str += i18n;
47         str += "</b>";
48
49         layout->set_markup (str);
50
51         darea.show ();
52         darea.signal_expose_event().connect (sigc::mem_fun (*this, &Splash::expose));
53
54         add (darea);
55
56         set_default_size (pixbuf->get_width(), pixbuf->get_height());
57         the_splash = this;
58
59         ARDOUR::BootMessage.connect (msg_connection, invalidator (*this), boost::bind (&Splash::boot_message, this, _1), gui_context());
60 }
61
62 void
63 Splash::pop_back_for (Gtk::Window& win)
64 {
65         set_keep_above (false);
66         get_window()->restack (win.get_window(), false);
67         win.signal_hide().connect (sigc::mem_fun (*this, &Splash::pop_front));
68 }
69
70 void
71 Splash::pop_front ()
72 {
73         set_keep_above (true);
74 }
75
76 void
77 Splash::on_realize ()
78 {
79         Window::on_realize ();
80         get_window()->set_decorations (Gdk::WMDecoration(0));
81         layout->set_font_description (get_style()->get_font());
82 }
83
84
85 bool
86 Splash::on_button_release_event (GdkEventButton*)
87 {
88         hide ();
89         return true;
90 }
91
92 bool
93 Splash::expose (GdkEventExpose* ev)
94 {
95         RefPtr<Gdk::Window> window = darea.get_window();
96
97         /* note: height & width need to be constrained to the pixbuf size
98            in case a WM provides us with a screwy allocation
99         */
100
101         window->draw_pixbuf (get_style()->get_bg_gc (STATE_NORMAL), pixbuf,
102                              ev->area.x, ev->area.y,
103                              ev->area.x, ev->area.y,
104                              min ((pixbuf->get_width() - ev->area.x), ev->area.width),
105                              min ((pixbuf->get_height() - ev->area.y), ev->area.height),
106                              Gdk::RGB_DITHER_NONE, 0, 0);
107
108         Glib::RefPtr<Gtk::Style> style = darea.get_style();
109         Glib::RefPtr<Gdk::GC> white = style->get_white_gc();
110
111         window->draw_layout (white, 10, pixbuf->get_height() - 30, layout);
112
113         return true;
114 }
115
116 void
117 Splash::boot_message (std::string msg)
118 {
119         message (msg);
120 }
121
122 void
123 Splash::message (const string& msg)
124 {
125         string str ("<b>");
126         str += msg;
127         str += "</b>";
128
129         layout->set_markup (str);
130         Glib::RefPtr<Gdk::Window> win = darea.get_window();
131
132         if (win) {
133                 win->invalidate_rect (Gdk::Rectangle (0, darea.get_height() - 30,
134                                                       darea.get_width(), 30), true);
135                 win->process_updates (true);
136                 gdk_flush ();
137         }
138 }