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 buffer_view_->updateMetrics(false);
193 ViewMetricsInfo const & vi = buffer_view_->viewMetricsInfo();
195 getPainter().start();
196 paintText(*buffer_view_, vi, getPainter());
197 lyxerr[Debug::DEBUG] << "Redraw screen" << endl;
198 int const ymin = std::max(vi.y1, 0);
200 ( vi.p2 < vi.size - 1 ? vi.y2 : height() );
201 expose(0, ymin, width(), ymax - ymin);
205 << " ymin = " << ymin << " width() = " << width()
206 << " ymax-ymin = " << ymax-ymin << std::endl;
210 void WorkArea::processKeySym(LyXKeySymPtr key,
211 key_modifier::state state)
214 buffer_view_->workAreaKeyPress(key, state);
216 /* This is perhaps a bit of a hack. When we move
217 * around, or type, it's nice to be able to see
218 * the cursor immediately after the keypress. So
219 * we reset the toggle timeout and force the visibility
220 * of the cursor. Note we cannot do this inside
221 * dispatch() itself, because that's called recursively.
223 // if (buffer_view_->available())
226 // uneeded "redraw()" call commented out for now.
227 // When/if the call to LyXView::redrawWorkArea() in "lyxfunc.C:1610"
228 // is not needed anymore, this line should be uncommented out
233 void WorkArea::dispatch(FuncRequest const & cmd0)
235 buffer_view_->workAreaDispatch(cmd0);
240 void WorkArea::resizeBufferView()
242 buffer_view_->workAreaResize(width(), height());
247 void WorkArea::greyOut()
250 getPainter().start();
252 getPainter().fillRectangle(0, 0,
257 // Add a splash screen to the centre of the work area
258 SplashScreen const & splash = SplashScreen::get();
259 lyx::graphics::Image const * const splash_image = splash.image();
261 int const w = splash_image->getWidth();
262 int const h = splash_image->getHeight();
264 int x = (width() - w) / 2;
265 int y = (height() - h) / 2;
267 getPainter().image(x, y, w, h, *splash_image);
272 getPainter().text(x, y, splash.text(), splash.font());
274 expose(0, 0, width(), height());
279 void WorkArea::showCursor()
284 if (!buffer_view_->available())
287 CursorShape shape = BAR_SHAPE;
289 LyXText const & text = *buffer_view_->getLyXText();
290 LyXFont const & realfont = text.real_current_font;
291 BufferParams const & bp = buffer_view_->buffer()->params();
292 bool const samelang = realfont.language() == bp.language;
293 bool const isrtl = realfont.isVisibleRightToLeft();
295 if (!samelang || isrtl != bp.language->rightToLeft()) {
298 shape = REVERSED_L_SHAPE;
301 // The ERT language hack needs fixing up
302 if (realfont.language() == latex_language)
305 LyXFont const font = buffer_view_->cursor().getFont();
306 int const asc = font_metrics::maxAscent(font);
307 int const des = font_metrics::maxDescent(font);
311 buffer_view_->cursor().getPos(x, y);
314 // if it doesn't touch the screen, don't try to show it
315 if (y + h < 0 || y >= height())
318 cursor_visible_ = true;
319 showCursor(x, y, h, shape);
323 void WorkArea::hideCursor()
325 if (!cursor_visible_)
328 cursor_visible_ = false;
333 void WorkArea::toggleCursor()
335 if (buffer_view_->buffer()) {
342 // Use this opportunity to deal with any child processes that
343 // have finished but are waiting to communicate this fact
344 // to the rest of LyX.
345 ForkedcallsController & fcc = ForkedcallsController::get();
346 fcc.handleCompletedProcesses();
349 cursor_timeout_.restart();
352 } // namespace frontend