3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Abdelrazak Younes
9 * Full author contact details are available in file CREDITS.
11 * Splash screen code added by Angus Leeming
18 #include "font_metrics.h"
22 #include "BufferView.h"
24 #include "bufferparams.h"
25 #include "coordcache.h"
34 #include "metricsinfo.h"
35 #include "paragraph.h"
36 #include "rowpainter.h"
39 #include "graphics/GraphicsImage.h"
40 #include "graphics/GraphicsLoader.h"
42 #include "support/filetools.h" // LibFileSearch
43 #include "support/forkedcontr.h"
45 #include <boost/utility.hpp>
46 #include <boost/bind.hpp>
47 #include <boost/current_function.hpp>
48 #include <boost/signals/trackable.hpp>
50 using lyx::support::libFileSearch;
51 using lyx::support::ForkedcallsController;
62 // FIXME: The SplashScreen should be transfered to the
63 // LyXView and create a WorkArea only when a new buffer exists. This
64 // will allow to call WorkArea::redraw() in the constructor.
65 class SplashScreen : boost::noncopyable, boost::signals::trackable {
67 /// This is a singleton class. Get the instance.
68 static SplashScreen const & get();
70 lyx::graphics::Image const * image() const { return loader_.image(); }
72 string const & text() const { return text_; }
74 LyXFont const & font() const { return font_; }
76 void connect(lyx::graphics::Loader::slot_type const & slot) const {
77 loader_.connect(slot);
80 void startLoading() const {
81 if (loader_.status() == lyx::graphics::WaitingToLoad)
82 loader_.startLoading();
86 /** Make the c-tor private so we can control how many objects
92 lyx::graphics::Loader loader_;
93 /// The text to be written on top of the pixmap
100 SplashScreen const & SplashScreen::get()
102 static SplashScreen singleton;
107 SplashScreen::SplashScreen()
108 : text_(lyx_version ? lyx_version : "unknown")
110 if (!lyxrc.show_banner)
113 string const file = libFileSearch("images", "banner", "ppm");
117 // The font used to display the version info
118 font_.setFamily(LyXFont::SANS_FAMILY);
119 font_.setSeries(LyXFont::BOLD_SERIES);
120 font_.setSize(LyXFont::SIZE_NORMAL);
121 font_.setColor(LColor::yellow);
123 // Load up the graphics file
129 // All the below connection objects are needed because of a bug in some
130 // versions of GCC (<=2.96 are on the suspects list.) By having and assigning
131 // to these connections we avoid a segfault upon startup, and also at exit.
134 boost::signals::connection timecon;
138 WorkArea::WorkArea(BufferView * buffer_view)
139 : buffer_view_(buffer_view), greyed_out_(true),
140 cursor_visible_(false), cursor_timeout_(400)
142 // Start loading the pixmap as soon as possible
143 if (lyxrc.show_banner) {
144 SplashScreen const & splash = SplashScreen::get();
145 splash.connect(boost::bind(&WorkArea::checkAndGreyOut, this));
146 splash.startLoading();
150 timecon = cursor_timeout_.timeout
151 .connect(boost::bind(&WorkArea::toggleCursor, this));
153 cursor_timeout_.start();
157 void WorkArea::setBufferView(BufferView * buffer_view)
159 buffer_view_ = buffer_view;
163 BufferView & WorkArea::bufferView()
165 return *buffer_view_;
169 BufferView const & WorkArea::bufferView() const
171 return *buffer_view_;
175 void WorkArea::checkAndGreyOut()
182 void WorkArea::redraw()
187 if (!buffer_view_->buffer()) {
192 if (!buffer_view_->needsRedraw())
195 ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
197 getPainter().start();
198 paintText(*buffer_view_, vi, getPainter());
199 lyxerr[Debug::DEBUG] << "Redraw screen" << endl;
200 int const ymin = std::max(vi.y1, 0);
202 ( vi.p2 < vi.size - 1 ? vi.y2 : height() );
203 expose(0, ymin, width(), ymax - ymin);
205 buffer_view_->needsRedraw(false);
208 << " ymin = " << ymin << " width() = " << width()
209 << " ymax-ymin = " << ymax-ymin << std::endl;
213 void WorkArea::processKeySym(LyXKeySymPtr key,
214 key_modifier::state state)
217 buffer_view_->workAreaKeyPress(key, state);
219 /* This is perhaps a bit of a hack. When we move
220 * around, or type, it's nice to be able to see
221 * the cursor immediately after the keypress. So
222 * we reset the toggle timeout and force the visibility
223 * of the cursor. Note we cannot do this inside
224 * dispatch() itself, because that's called recursively.
226 // if (buffer_view_->available())
232 void WorkArea::dispatch(FuncRequest const & cmd0)
234 buffer_view_->workAreaDispatch(cmd0);
239 void WorkArea::resizeBufferView()
241 buffer_view_->workAreaResize(width(), height());
246 void WorkArea::greyOut()
249 getPainter().start();
251 getPainter().fillRectangle(0, 0,
256 // Add a splash screen to the centre of the work area
257 SplashScreen const & splash = SplashScreen::get();
258 lyx::graphics::Image const * const splash_image = splash.image();
260 int const w = splash_image->getWidth();
261 int const h = splash_image->getHeight();
263 int x = (width() - w) / 2;
264 int y = (height() - h) / 2;
266 getPainter().image(x, y, w, h, *splash_image);
271 getPainter().text(x, y, splash.text(), splash.font());
273 expose(0, 0, width(), height());
278 void WorkArea::showCursor()
283 if (!buffer_view_->available())
286 CursorShape shape = BAR_SHAPE;
288 LyXText const & text = *buffer_view_->getLyXText();
289 LyXFont const & realfont = text.real_current_font;
290 BufferParams const & bp = buffer_view_->buffer()->params();
291 bool const samelang = realfont.language() == bp.language;
292 bool const isrtl = realfont.isVisibleRightToLeft();
294 if (!samelang || isrtl != bp.language->rightToLeft()) {
297 shape = REVERSED_L_SHAPE;
300 // The ERT language hack needs fixing up
301 if (realfont.language() == latex_language)
304 LyXFont const font = buffer_view_->cursor().getFont();
305 int const asc = font_metrics::maxAscent(font);
306 int const des = font_metrics::maxDescent(font);
310 buffer_view_->cursor().getPos(x, y);
313 // if it doesn't touch the screen, don't try to show it
314 if (y + h < 0 || y >= height())
317 cursor_visible_ = true;
318 showCursor(x, y, h, shape);
322 void WorkArea::hideCursor()
324 if (!cursor_visible_)
327 cursor_visible_ = false;
332 void WorkArea::toggleCursor()
334 if (buffer_view_->buffer()) {
341 // Use this opportunity to deal with any child processes that
342 // have finished but are waiting to communicate this fact
343 // to the rest of LyX.
344 ForkedcallsController & fcc = ForkedcallsController::get();
345 fcc.handleCompletedProcesses();
348 cursor_timeout_.restart();
351 } // namespace frontend