]> git.lyx.org Git - lyx.git/blob - src/frontends/WorkArea.C
This is the merging of the GUI API cleanup branch that was developed in svn+ssh:...
[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(LyXView & owner, int w, int h)
122         : 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::checkAndGreyOut()
134 {
135         if (greyed_out_)
136                 greyOut();
137 }
138
139
140 void WorkArea::redraw(BufferView & bv, ViewMetricsInfo const & vi)
141 {
142         greyed_out_ = false;
143         getPainter().start();
144         paintText(bv, vi);
145         lyxerr[Debug::DEBUG] << "Redraw screen" << endl;
146         int const ymin = std::max(vi.y1, 0);
147         int const ymax =
148                 ( vi.p2 < vi.size - 1 ?  vi.y2 : height() );
149         expose(0, ymin, width(), ymax - ymin);
150         getPainter().end();
151         theCoords.doneUpdating();
152 }
153
154
155 void WorkArea::greyOut()
156 {
157         greyed_out_ = true;
158         getPainter().start();
159
160         getPainter().fillRectangle(0, 0,
161                 width(),
162                 height(),
163                 LColor::bottomarea);
164
165         // Add a splash screen to the centre of the work area
166         SplashScreen const & splash = SplashScreen::get();
167         lyx::graphics::Image const * const splash_image = splash.image();
168         if (splash_image) {
169                 int const w = splash_image->getWidth();
170                 int const h = splash_image->getHeight();
171
172                 int x = (width() - w) / 2;
173                 int y = (height() - h) / 2;
174
175                 getPainter().image(x, y, w, h, *splash_image);
176
177                 x += 260;
178                 y += 265;
179
180                 getPainter().text(x, y, splash.text(), splash.font());
181         }
182         expose(0, 0, width(), height());
183         getPainter().end();
184 }
185
186 } // namespace frontend
187 } // namespace lyx