]> git.lyx.org Git - lyx.git/blob - src/frontends/WorkArea.C
Extraced from r14281 from the younes branch.
[lyx.git] / src / frontends / WorkArea.C
1 /**
2  * \file WorkArea.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Levon
7  * \author Abdelrazak Younes
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * Splash screen code added by Angus Leeming
12  */
13
14 #include <config.h>
15
16 #include "WorkArea.h"
17
18 #include "font_metrics.h"
19 #include "lyx_gui.h"
20 #include "Painter.h"
21
22 #include "BufferView.h"
23 #include "buffer.h"
24 #include "bufferparams.h"
25 #include "coordcache.h"
26 #include "cursor.h"
27 #include "debug.h"
28 #include "language.h"
29 #include "LColor.h"
30 #include "lyxfont.h"
31 #include "lyxrc.h"
32 #include "lyxrow.h"
33 #include "lyxtext.h"
34 #include "metricsinfo.h"
35 #include "paragraph.h"
36 #include "rowpainter.h"
37 #include "version.h"
38
39 #include "graphics/GraphicsImage.h"
40 #include "graphics/GraphicsLoader.h"
41
42 #include "support/filetools.h" // LibFileSearch
43
44 #include <boost/utility.hpp>
45 #include <boost/bind.hpp>
46 #include <boost/signals/trackable.hpp>
47
48 using lyx::support::libFileSearch;
49
50 using std::endl;
51 using std::min;
52 using std::max;
53 using std::string;
54
55
56 namespace lyx {
57 namespace frontend {
58
59 class SplashScreen : boost::noncopyable, boost::signals::trackable {
60 public:
61         /// This is a singleton class. Get the instance.
62         static SplashScreen const & get();
63         ///
64         lyx::graphics::Image const * image() const { return loader_.image(); }
65         ///
66         string const & text() const { return text_; }
67         ///
68         LyXFont const & font() const { return font_; }
69         ///
70         void connect(lyx::graphics::Loader::slot_type const & slot) const {
71                 loader_.connect(slot);
72         }
73         ///
74         void startLoading() const {
75                 if (loader_.status() == lyx::graphics::WaitingToLoad)
76                         loader_.startLoading();
77         }
78
79 private:
80         /** Make the c-tor private so we can control how many objects
81          *  are instantiated.
82          */
83         SplashScreen();
84
85         ///
86         lyx::graphics::Loader loader_;
87         /// The text to be written on top of the pixmap
88         string const text_;
89         /// in this font...
90         LyXFont font_;
91 };
92
93
94 SplashScreen const & SplashScreen::get()
95 {
96         static SplashScreen singleton;
97         return singleton;
98 }
99
100
101 SplashScreen::SplashScreen()
102         : text_(lyx_version ? lyx_version : "unknown")
103 {
104         if (!lyxrc.show_banner)
105                 return;
106
107         string const file = libFileSearch("images", "banner", "ppm");
108         if (file.empty())
109                 return;
110
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);
116
117         // Load up the graphics file
118         loader_.reset(file);
119 }
120
121 WorkArea::WorkArea(BufferView * buffer_view)
122         :  buffer_view_(buffer_view), greyed_out_(true)
123 {
124         // Start loading the pixmap as soon as possible
125         if (lyxrc.show_banner) {
126                 SplashScreen const & splash = SplashScreen::get();
127                 splash.connect(boost::bind(&WorkArea::checkAndGreyOut, this));
128                 splash.startLoading();
129         }
130 }
131
132
133 void WorkArea::setBufferView(BufferView * buffer_view)
134 {
135         buffer_view_ = buffer_view;
136 }
137
138
139 BufferView & WorkArea::bufferView()
140 {
141         return *buffer_view_;
142 }
143
144
145 BufferView const & WorkArea::bufferView() const
146 {
147         return *buffer_view_;
148 }
149
150
151 void WorkArea::checkAndGreyOut()
152 {
153         if (greyed_out_)
154                 greyOut();
155 }
156
157
158 void WorkArea::redraw(BufferView & bv)
159 {
160         greyed_out_ = false;
161         ViewMetricsInfo const & vi = bv.viewMetricsInfo();
162         getPainter().start();
163         paintText(*buffer_view_, vi);
164         lyxerr[Debug::DEBUG] << "Redraw screen" << endl;
165         int const ymin = std::max(vi.y1, 0);
166         int const ymax =
167                 ( vi.p2 < vi.size - 1 ?  vi.y2 : height() );
168         expose(0, ymin, width(), ymax - ymin);
169         getPainter().end();
170         theCoords.doneUpdating();
171 }
172
173
174 void WorkArea::greyOut()
175 {
176         greyed_out_ = true;
177         getPainter().start();
178
179         getPainter().fillRectangle(0, 0,
180                 width(),
181                 height(),
182                 LColor::bottomarea);
183
184         // Add a splash screen to the centre of the work area
185         SplashScreen const & splash = SplashScreen::get();
186         lyx::graphics::Image const * const splash_image = splash.image();
187         if (splash_image) {
188                 int const w = splash_image->getWidth();
189                 int const h = splash_image->getHeight();
190
191                 int x = (width() - w) / 2;
192                 int y = (height() - h) / 2;
193
194                 getPainter().image(x, y, w, h, *splash_image);
195
196                 x += 260;
197                 y += 265;
198
199                 getPainter().text(x, y, splash.text(), splash.font());
200         }
201         expose(0, 0, width(), height());
202         getPainter().end();
203 }
204
205 } // namespace frontend
206 } // namespace lyx