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