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