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"
32 #include "metricsinfo.h"
33 #include "paragraph.h"
34 #include "rowpainter.h"
37 #include "insets/updatableinset.h"
39 #include "graphics/GraphicsImage.h"
40 #include "graphics/GraphicsLoader.h"
42 #include "support/filetools.h" // LibFileSearch
44 #include <boost/utility.hpp>
45 #include <boost/bind.hpp>
46 #include <boost/signals/trackable.hpp>
48 using lyx::support::LibFileSearch;
58 class SplashScreen : boost::noncopyable, boost::signals::trackable {
60 /// This is a singleton class. Get the instance.
61 static SplashScreen const & get();
63 lyx::graphics::Image const * image() const { return loader_.image(); }
65 string const & text() const { return text_; }
67 LyXFont const & font() const { return font_; }
69 void connect(lyx::graphics::Loader::slot_type const & slot) const {
70 loader_.connect(slot);
73 void startLoading() const {
74 if (loader_.status() == lyx::graphics::WaitingToLoad)
75 loader_.startLoading();
79 /** Make the c-tor private so we can control how many objects
85 lyx::graphics::Loader loader_;
86 /// The text to be written on top of the pixmap
93 SplashScreen const & SplashScreen::get()
95 static SplashScreen singleton;
100 SplashScreen::SplashScreen()
101 : text_(lyx_version ? lyx_version : "unknown")
103 if (!lyxrc.show_banner)
106 string const file = LibFileSearch("images", "banner", "ppm");
110 // The font used to display the version info
111 font_.setFamily(LyXFont::SANS_FAMILY);
112 font_.setSeries(LyXFont::BOLD_SERIES);
113 font_.setSize(LyXFont::SIZE_NORMAL);
114 font_.setColor(LColor::yellow);
116 // Load up the graphics file
123 LyXScreen::LyXScreen()
124 : cursor_visible_(false), greyed_out_(true)
126 // Start loading the pixmap as soon as possible
127 if (lyxrc.show_banner) {
128 SplashScreen const & splash = SplashScreen::get();
129 splash.connect(boost::bind(&LyXScreen::greyOut, this));
130 splash.startLoading();
135 LyXScreen::~LyXScreen()
140 void LyXScreen::showCursor(BufferView & bv)
142 // this is needed to make sure we copy back the right
143 // pixmap on the hide for the Qt frontend
144 lyx_gui::sync_events();
152 Cursor_Shape shape = BAR_SHAPE;
154 LyXText const & text = *bv.getLyXText();
155 LyXFont const & realfont = text.real_current_font;
156 BufferParams const & bp = bv.buffer()->params();
157 bool const samelang = realfont.language() == bp.language;
158 bool const isrtl = realfont.isVisibleRightToLeft();
160 if (!samelang || isrtl != bp.language->RightToLeft()) {
163 shape = REVERSED_L_SHAPE;
166 // The ERT language hack needs fixing up
167 if (realfont.language() == latex_language)
170 int ascent = font_metrics::maxAscent(realfont);
171 int descent = font_metrics::maxDescent(realfont);
172 int h = ascent + descent;
175 bv.cursor().getPos(x, y);
177 //lyxerr << "LyXScreen::showCursor x: " << x << " y: " << y << endl;
179 // if it doesn't fit entirely on the screen, don't try to show it
180 if (y < 0 || y + h > workarea().workHeight())
183 cursor_visible_ = true;
184 showCursor(x, y, h, shape);
188 void LyXScreen::hideCursor()
190 if (!cursor_visible_)
193 cursor_visible_ = false;
198 void LyXScreen::toggleCursor(BufferView & bv)
207 bool LyXScreen::fitManualCursor(BufferView * bv, LyXText *,
208 int x, int y, int asc, int desc)
210 lyxerr << "LyXScreen::fitManualCursor x: " << x << " y: " << y << std::endl;
211 int const vheight = workarea().workHeight();
212 int const topy = bv->top_y();
215 if (y + desc - topy >= vheight)
216 newtop = y - 3 * vheight / 4; // the scroll region must be so big!!
217 else if (y - asc < topy && topy > 0)
218 newtop = y - vheight / 4;
220 newtop = max(newtop, 0); // can newtop ever be < 0? (Lgb)
230 unsigned int LyXScreen::topCursorVisible(LyXText * text)
232 LyXCursor const & cursor = text->cursor;
233 int top_y = text->bv()->top_y();
235 unsigned int const vheight = workarea().workHeight();
237 Row & row = *text->cursorPar()->getRow(cursor.pos());
239 if (int(cursor.y() - row.baseline() + row.height() - top_y) >= vheight) {
240 if (row.height() < vheight
241 && row.height() > vheight / 4) {
244 - row.baseline() - vheight;
246 // scroll down, the scroll region must be so big!!
247 newtop = cursor.y() - vheight / 2;
250 } else if (int(cursor.y() - row.baseline()) < top_y && top_y > 0) {
251 if (row.height() < vheight && row.height() > vheight / 4) {
252 newtop = cursor.y() - row.baseline();
255 newtop = cursor.y() - vheight / 2;
256 newtop = min(newtop, top_y);
260 return max(newtop, 0);
264 bool LyXScreen::fitCursor(LyXText * text, BufferView * bv)
266 // Is a change necessary?
267 int const newtop = topCursorVisible(text);
268 bool const result = (newtop != bv->top_y());
274 void LyXScreen::redraw(BufferView & bv)
276 greyed_out_ = !bv.text;
283 workarea().getPainter().start();
287 int const y = paintText(bv);
289 // maybe we have to clear the screen at the bottom
290 int const y2 = workarea().workHeight();
291 if (y < y2 && !bv.text->isInInset()) {
292 workarea().getPainter().fillRectangle(0, y,
293 workarea().workWidth(), y2 - y,
297 lyxerr << "Redraw screen" << endl;
299 expose(0, 0, workarea().workWidth(), workarea().workHeight());
301 workarea().getPainter().end();
305 void LyXScreen::greyOut()
310 workarea().getPainter().start();
312 workarea().getPainter().fillRectangle(0, 0,
313 workarea().workWidth(),
314 workarea().workHeight(),
317 // Add a splash screen to the centre of the work area
318 SplashScreen const & splash = SplashScreen::get();
319 lyx::graphics::Image const * const splash_image = splash.image();
321 int const w = splash_image->getWidth();
322 int const h = splash_image->getHeight();
324 int x = (workarea().workWidth() - w) / 2;
325 int y = (workarea().workHeight() - h) / 2;
327 workarea().getPainter().image(x, y, w, h, *splash_image);
332 workarea().getPainter().text(x, y, splash.text(), splash.font());
334 expose(0, 0, workarea().workWidth(), workarea().workHeight());
335 workarea().getPainter().end();