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