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