3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
10 * Splash screen code added by Angus Leeming
16 #include "font_metrics.h"
21 #include "BufferView.h"
23 #include "bufferparams.h"
24 #include "coordcache.h"
33 #include "metricsinfo.h"
34 #include "paragraph.h"
35 #include "rowpainter.h"
38 #include "insets/updatableinset.h"
40 #include "graphics/GraphicsImage.h"
41 #include "graphics/GraphicsLoader.h"
43 #include "support/filetools.h" // LibFileSearch
45 #include <boost/utility.hpp>
46 #include <boost/bind.hpp>
47 #include <boost/signals/trackable.hpp>
49 using lyx::support::LibFileSearch;
59 class SplashScreen : boost::noncopyable, boost::signals::trackable {
61 /// This is a singleton class. Get the instance.
62 static SplashScreen const & get();
64 lyx::graphics::Image const * image() const { return loader_.image(); }
66 string const & text() const { return text_; }
68 LyXFont const & font() const { return font_; }
70 void connect(lyx::graphics::Loader::slot_type const & slot) const {
71 loader_.connect(slot);
74 void startLoading() const {
75 if (loader_.status() == lyx::graphics::WaitingToLoad)
76 loader_.startLoading();
80 /** Make the c-tor private so we can control how many objects
86 lyx::graphics::Loader loader_;
87 /// The text to be written on top of the pixmap
94 SplashScreen const & SplashScreen::get()
96 static SplashScreen singleton;
101 SplashScreen::SplashScreen()
102 : text_(lyx_version ? lyx_version : "unknown")
104 if (!lyxrc.show_banner)
107 string const file = LibFileSearch("images", "banner", "ppm");
111 // The font used to display the version info
112 font_.setFamily(LyXFont::SANS_FAMILY);
113 font_.setSeries(LyXFont::BOLD_SERIES);
114 font_.setSize(LyXFont::SIZE_NORMAL);
115 font_.setColor(LColor::yellow);
117 // Load up the graphics file
124 LyXScreen::LyXScreen()
125 : greyed_out_(true), cursor_visible_(false), sync_allowed_(true)
127 // Start loading the pixmap as soon as possible
128 if (lyxrc.show_banner) {
129 SplashScreen const & splash = SplashScreen::get();
130 splash.connect(boost::bind(&LyXScreen::checkAndGreyOut, this));
131 splash.startLoading();
136 LyXScreen::~LyXScreen()
141 void LyXScreen::checkAndGreyOut()
148 void LyXScreen::showCursor(BufferView & bv)
150 // This code is currently meaningful only for the Qt frontend.
151 // This is the place (like below in hideCursor) where
152 // processEvents is being called, and things like keystrokes and
153 // mouse clicks are being handed to the LyX core, once every
155 // THERE IS NOT SUPPOSED TO BE ANY OTHER CALL TO processEvents
157 // in BufferView::Pimpl::update() and here, the sync_allowed_
158 // guard is set/cleared which is used here to prevent recursive
159 // calls to screen update. startUpdating() and doneUpdating() in
160 // coordcache again contain asserts to detect such recursion.
162 lyx_gui::sync_events();
170 Cursor_Shape shape = BAR_SHAPE;
172 LyXText const & text = *bv.getLyXText();
173 LyXFont const & realfont = text.real_current_font;
174 BufferParams const & bp = bv.buffer()->params();
175 bool const samelang = realfont.language() == bp.language;
176 bool const isrtl = realfont.isVisibleRightToLeft();
178 if (!samelang || isrtl != bp.language->RightToLeft()) {
181 shape = REVERSED_L_SHAPE;
184 // The ERT language hack needs fixing up
185 if (realfont.language() == latex_language)
188 LyXFont const font = bv.cursor().getFont();
189 int const asc = font_metrics::maxAscent(font);
190 int const des = font_metrics::maxDescent(font);
194 bv.cursor().getPos(x, y);
196 //lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl;
198 // if it doesn't touch the screen, don't try to show it
199 if (y + h < 0 || y >= workarea().workHeight())
202 cursor_visible_ = true;
203 showCursor(x, y, h, shape);
207 void LyXScreen::hideCursor()
210 lyx_gui::sync_events();
212 if (!cursor_visible_)
215 cursor_visible_ = false;
220 void LyXScreen::toggleCursor(BufferView & bv)
229 void LyXScreen::redraw(BufferView & bv, ViewMetricsInfo const & vi)
232 workarea().getPainter().start();
234 lyxerr[Debug::DEBUG] << "Redraw screen" << endl;
235 expose(0, 0, workarea().workWidth(), workarea().workHeight());
236 workarea().getPainter().end();
237 theCoords.doneUpdating();
238 sync_allowed_ = true;
242 void LyXScreen::greyOut()
245 workarea().getPainter().start();
247 workarea().getPainter().fillRectangle(0, 0,
248 workarea().workWidth(),
249 workarea().workHeight(),
252 // Add a splash screen to the centre of the work area
253 SplashScreen const & splash = SplashScreen::get();
254 lyx::graphics::Image const * const splash_image = splash.image();
256 int const w = splash_image->getWidth();
257 int const h = splash_image->getHeight();
259 int x = (workarea().workWidth() - w) / 2;
260 int y = (workarea().workHeight() - h) / 2;
262 workarea().getPainter().image(x, y, w, h, *splash_image);
267 workarea().getPainter().text(x, y, splash.text(), splash.font());
269 expose(0, 0, workarea().workWidth(), workarea().workHeight());
270 workarea().getPainter().end();