]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
Further cleanup of InsetFlex, InsetCollapsable and InsetLayout:
[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 "ColorCode.h"
17 #include "FontInfo.h"
18
19 #include "support/strfwd.h"
20 #include "support/types.h"
21
22 #include <string>
23
24 class BufferView;
25
26 namespace lyx {
27
28 namespace frontend { class Painter; }
29 class MacroContext;
30
31
32 /// Standard Sizes (mode styles)
33 enum Styles {
34         ///
35         LM_ST_DISPLAY = 0,
36         ///
37         LM_ST_TEXT,
38         ///
39         LM_ST_SCRIPT,
40         ///
41         LM_ST_SCRIPTSCRIPT
42 };
43
44
45 //
46 // This is the part common to MetricsInfo and PainterInfo
47 //
48 class MetricsBase {
49 public:
50         ///
51         MetricsBase();
52         ///
53         MetricsBase(BufferView * bv, FontInfo const & font, int textwidth);
54
55         /// the current view
56         BufferView * bv;
57         /// current font
58         FontInfo font;
59         /// current math style (display/text/script/..)
60         Styles style;
61         /// name of current font - mathed specific
62         std::string fontname;
63         /// This is the width available in pixels
64         int textwidth;
65 };
66
67
68 //
69 // This contains a MetricsBase and information that's only relevant during
70 // the first phase of the two-phase draw
71 //
72 class MetricsInfo {
73 public:
74         ///
75         MetricsInfo();
76         ///
77         MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth, MacroContext const & mc);
78
79         ///
80         MetricsBase base;
81         /// The context to resolve macros
82         MacroContext const & macrocontext;
83 };
84
85
86 //
87 // This contains a MetricsBase and information that's only relevant during
88 // the second phase of the two-phase draw
89 //
90 class PainterInfo {
91 public:
92         ///
93         PainterInfo(BufferView * bv, frontend::Painter & pain);
94         ///
95         void draw(int x, int y, char_type c);
96         ///
97         void draw(int x, int y, docstring const & str);
98
99         ///
100         MetricsBase base;
101         ///
102         frontend::Painter & pain;
103         /// Whether the text at this point is right-to-left (for InsetNewline)
104         bool ltr_pos;
105         /// Whether the parent is deleted (change tracking)
106         bool erased_;
107         ///
108         bool full_repaint;
109         ///
110         ColorCode background_color;
111 };
112
113 class TextMetricsInfo {};
114
115 enum ScreenUpdateStrategy {
116         NoScreenUpdate,
117         SingleParUpdate,
118         FullScreenUpdate,
119         DecorationUpdate
120 };
121
122 class ViewMetricsInfo
123 {
124 public:
125         ViewMetricsInfo()
126                         : p1(0), p2(0), y1(0), y2(0),
127                         update_strategy(FullScreenUpdate), size(0)
128                 {}
129         ViewMetricsInfo(pit_type p1, pit_type p2, int y1, int y2,
130                         ScreenUpdateStrategy updatestrategy, pit_type size)
131                         : p1(p1), p2(p2), y1(y1), y2(y2),
132                         update_strategy(updatestrategy), size(size)
133                 {}
134
135         pit_type p1;
136         pit_type p2;
137         int y1;
138         int y2;
139         ScreenUpdateStrategy update_strategy;
140         pit_type size;
141 };
142
143
144 // Generic base for temporarily changing things.
145 // The original state gets restored when the Changer is destructed.
146
147 template <class Struct, class Temp = Struct>
148 class Changer {
149 public:
150         ///
151         Changer(Struct & orig) : orig_(orig) {}
152 protected:
153         ///
154         Struct & orig_;
155         ///
156         Temp save_;
157 };
158
159
160
161 // temporarily change some aspect of a font
162 class FontChanger : public Changer<FontInfo> {
163 public:
164         ///
165         FontChanger(FontInfo & orig, docstring const & font);
166         FontChanger(MetricsBase & mb, char const * const font);
167         ///
168         ~FontChanger();
169 };
170
171
172 // temporarily change a full font
173 class FontSetChanger : public Changer<MetricsBase> {
174 public:
175         ///
176         FontSetChanger(MetricsBase & mb, docstring const & font);
177         FontSetChanger(MetricsBase & mb, char const * const font);
178         ///
179         ~FontSetChanger();
180 };
181
182
183 // temporarily change the style
184 class StyleChanger : public Changer<MetricsBase> {
185 public:
186         ///
187         StyleChanger(MetricsBase & mb, Styles style);
188         ///
189         ~StyleChanger();
190 };
191
192
193 // temporarily change the style to script style
194 class ScriptChanger : public StyleChanger {
195 public:
196         ///
197         ScriptChanger(MetricsBase & mb);
198 };
199
200
201 // temporarily change the style suitable for use in fractions
202 class FracChanger : public StyleChanger {
203 public:
204         ///
205         FracChanger(MetricsBase & mb);
206 };
207
208
209 // temporarily change the style suitable for use in tabulars and arrays
210 class ArrayChanger : public StyleChanger {
211 public:
212         ///
213         ArrayChanger(MetricsBase & mb);
214 };
215
216
217
218 // temporarily change the shape of a font
219 class ShapeChanger : public Changer<FontInfo, FontShape> {
220 public:
221         ///
222         ShapeChanger(FontInfo & font, FontShape shape);
223         ///
224         ~ShapeChanger();
225 };
226
227
228 // temporarily change the available text width
229 class WidthChanger : public Changer<MetricsBase>
230 {
231 public:
232         ///
233         WidthChanger(MetricsBase & mb, int width);
234         ///
235         ~WidthChanger();
236 };
237
238
239 // temporarily change the used color
240 class ColorChanger : public Changer<FontInfo, std::string> {
241 public:
242         ///
243         ColorChanger(FontInfo & font, std::string const & color);
244         ///
245         ~ColorChanger();
246 };
247
248 } // namespace lyx
249
250 #endif