]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
tex2lyx: support for multiple indices and subindices
[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         /// Determines the text color based on the intended color, the
107         /// change tracking state and the selection state. 
108         /// \param color what the color should be by default
109         Color textColor(Color const & color) const;
110
111         ///
112         MetricsBase base;
113         ///
114         frontend::Painter & pain;
115         /// Whether the text at this point is right-to-left (for InsetNewline)
116         bool ltr_pos;
117         /// The change the parent is part of (change tracking)
118         Change change_;
119         /// Whether the parent is selected as a whole
120         bool selected;
121         ///
122         bool full_repaint;
123         /// Current background color
124         ColorCode background_color;
125 };
126
127 class TextMetricsInfo {};
128
129
130 /// Generic base for temporarily changing things.
131 /// The original state gets restored when the Changer is destructed.
132 template <class Struct, class Temp = Struct>
133 class Changer {
134 public:
135         ///
136         Changer(Struct & orig) : orig_(orig) {}
137 protected:
138         ///
139         Struct & orig_;
140         ///
141         Temp save_;
142 };
143
144
145
146 // temporarily change some aspect of a font
147 class FontChanger : public Changer<FontInfo> {
148 public:
149         ///
150         FontChanger(FontInfo & orig, docstring const & font);
151         FontChanger(MetricsBase & mb, char const * const font);
152         ///
153         ~FontChanger();
154 };
155
156
157 // temporarily change a full font
158 class FontSetChanger : public Changer<MetricsBase> {
159 public:
160         ///
161         FontSetChanger(MetricsBase & mb, docstring const & font,
162                         bool really_change_font = true);
163         FontSetChanger(MetricsBase & mb, char const * const font,
164                         bool really_change_font = true);
165         ///
166         ~FontSetChanger();
167 private:
168         ///
169         bool change_;
170 };
171
172
173 // temporarily change the style
174 class StyleChanger : public Changer<MetricsBase> {
175 public:
176         ///
177         StyleChanger(MetricsBase & mb, Styles style);
178         ///
179         ~StyleChanger();
180 };
181
182
183 // temporarily change the style to script style
184 class ScriptChanger : public StyleChanger {
185 public:
186         ///
187         ScriptChanger(MetricsBase & mb);
188 };
189
190
191 // temporarily change the style suitable for use in fractions
192 class FracChanger : public StyleChanger {
193 public:
194         ///
195         FracChanger(MetricsBase & mb);
196 };
197
198
199 // temporarily change the style suitable for use in tabulars and arrays
200 class ArrayChanger : public StyleChanger {
201 public:
202         ///
203         ArrayChanger(MetricsBase & mb);
204 };
205
206
207
208 // temporarily change the shape of a font
209 class ShapeChanger : public Changer<FontInfo, FontShape> {
210 public:
211         ///
212         ShapeChanger(FontInfo & font, FontShape shape);
213         ///
214         ~ShapeChanger();
215 };
216
217
218 // temporarily change the available text width
219 class WidthChanger : public Changer<MetricsBase>
220 {
221 public:
222         ///
223         WidthChanger(MetricsBase & mb, int width);
224         ///
225         ~WidthChanger();
226 };
227
228
229 // temporarily change the used color
230 class ColorChanger : public Changer<FontInfo, ColorCode> {
231 public:
232         ///
233         ColorChanger(FontInfo & font, ColorCode color,
234                      bool really_change_color = true);
235         ///
236         ~ColorChanger();
237 private:
238         ///
239         bool change_;
240 };
241
242 } // namespace lyx
243
244 #endif