]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
Small update to README
[lyx.git] / src / MetricsInfo.h
1 // -*- C++ -*-
2 /**
3  * \file MetricsInfo.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  * \author Stefan Schimanski
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef METRICSINFO_H
14 #define METRICSINFO_H
15
16 #include "Changes.h"
17 #include "ColorCode.h"
18 #include "FontInfo.h"
19
20 #include "support/strfwd.h"
21
22 #include <string>
23
24
25 namespace lyx {
26
27 namespace frontend { class Painter; }
28 class BufferView;
29 class Inset;
30 class MacroContext;
31
32
33 /// Standard Sizes (mode styles)
34 enum Styles {
35         ///
36         LM_ST_DISPLAY = 0,
37         ///
38         LM_ST_TEXT,
39         ///
40         LM_ST_SCRIPT,
41         ///
42         LM_ST_SCRIPTSCRIPT
43 };
44
45
46 //
47 // This is the part common to MetricsInfo and PainterInfo
48 //
49 class MetricsBase {
50 public:
51         ///
52         MetricsBase();
53         ///
54         MetricsBase(BufferView * bv, FontInfo const & font, int textwidth);
55
56         /// the current view
57         BufferView * bv;
58         /// current font
59         FontInfo font;
60         /// current math style (display/text/script/..)
61         Styles style;
62         /// name of current font - mathed specific
63         std::string fontname;
64         /// This is the width available in pixels
65         int textwidth;
66 };
67
68
69 //
70 // This contains a MetricsBase and information that's only relevant during
71 // the first phase of the two-phase draw
72 //
73 class MetricsInfo {
74 public:
75         ///
76         MetricsInfo();
77         ///
78         MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth, MacroContext const & mc);
79
80         ///
81         MetricsBase base;
82         /// The context to resolve macros
83         MacroContext const & macrocontext;
84 };
85
86
87 //
88 // This contains a MetricsBase and information that's only relevant during
89 // the second phase of the two-phase draw
90 //
91 class PainterInfo {
92 public:
93         ///
94         PainterInfo(BufferView * bv, frontend::Painter & pain);
95         ///
96         void draw(int x, int y, char_type c);
97         ///
98         void draw(int x, int y, docstring const & str);
99         /// Determines the background color for the specified inset based on the
100         /// selection state, the background color inherited from the parent inset 
101         /// and the inset's own background color.
102         /// \param sel whether to take the selection state into account
103         ColorCode backgroundColor(Inset const * inset, bool sel = true) const;
104
105         /// Determines the text color based on the intended color, the
106         /// change tracking state and the selection state. 
107         /// \param color what the color should be by default
108         Color textColor(Color const & color) const;
109
110         ///
111         MetricsBase base;
112         ///
113         frontend::Painter & pain;
114         /// Whether the text at this point is right-to-left (for InsetNewline)
115         bool ltr_pos;
116         /// The change the parent is part of (change tracking)
117         Change change_;
118         /// Whether the parent is selected as a whole
119         bool selected;
120         /// Whether the spell checker is enabled for the parent
121         bool do_spellcheck;
122         ///
123         bool full_repaint;
124         /// Current background color
125         ColorCode background_color;
126 };
127
128 class TextMetricsInfo {};
129
130
131 /// Generic base for temporarily changing things. The derived class is
132 /// responsible for restoring the original state when the Changer is
133 /// destructed.
134 template <class Struct, class Temp = Struct>
135 class Changer {
136 protected:
137         ///
138         Changer(Struct & orig, Temp const & save) : orig_(orig), save_(save) {}
139         ///
140         Changer(Struct & orig) : orig_(orig), save_(orig) {}
141         ///
142         Struct & orig_;
143         ///
144         Temp save_;
145 };
146
147
148
149 // temporarily change some aspect of a font
150 class FontChanger : public Changer<FontInfo> {
151 public:
152         ///
153         FontChanger(FontInfo & orig, docstring const & font);
154         FontChanger(MetricsBase & mb, char const * const font);
155         ///
156         ~FontChanger();
157 };
158
159
160 // temporarily change a full font
161 class FontSetChanger : public Changer<MetricsBase> {
162 public:
163         ///
164         FontSetChanger(MetricsBase & mb, docstring const & font,
165                         bool really_change_font = true);
166         FontSetChanger(MetricsBase & mb, char const * const font,
167                         bool really_change_font = true);
168         ///
169         ~FontSetChanger();
170 private:
171         ///
172         bool change_;
173 };
174
175
176 // temporarily change the style
177 class StyleChanger : public Changer<MetricsBase> {
178 public:
179         ///
180         StyleChanger(MetricsBase & mb, Styles style);
181         ///
182         ~StyleChanger();
183 };
184
185
186 // temporarily change the style to script style
187 class ScriptChanger : public StyleChanger {
188 public:
189         ///
190         ScriptChanger(MetricsBase & mb);
191 };
192
193
194 // temporarily change the style suitable for use in fractions
195 class FracChanger : public StyleChanger {
196 public:
197         ///
198         FracChanger(MetricsBase & mb);
199 };
200
201
202 // temporarily change the style suitable for use in tabulars and arrays
203 class ArrayChanger : public StyleChanger {
204 public:
205         ///
206         ArrayChanger(MetricsBase & mb);
207 };
208
209
210
211 // temporarily change the shape of a font
212 class ShapeChanger : public Changer<FontInfo, FontShape> {
213 public:
214         ///
215         ShapeChanger(FontInfo & font, FontShape shape);
216         ///
217         ~ShapeChanger();
218 };
219
220
221 // temporarily change the available text width
222 class WidthChanger : public Changer<MetricsBase>
223 {
224 public:
225         ///
226         WidthChanger(MetricsBase & mb, int width);
227         ///
228         ~WidthChanger();
229 };
230
231
232 // temporarily change the used color
233 class ColorChanger : public Changer<FontInfo, ColorCode> {
234 public:
235         ///
236         ColorChanger(FontInfo & font, ColorCode color,
237                      bool really_change_color = true);
238         ///
239         ~ColorChanger();
240 private:
241         ///
242         bool change_;
243 };
244
245 } // namespace lyx
246
247 #endif