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