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