]> git.lyx.org Git - lyx.git/blob - src/metricsinfo.h
Add In nsetOld * argument to updateInset to rebreak the correct par.
[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 "LString.h"
17
18 class Painter;
19 class BufferView;
20
21
22 /// Standard Sizes (mode styles)
23 enum Styles {
24         ///
25         LM_ST_DISPLAY = 0,
26         ///
27         LM_ST_TEXT,
28         ///
29         LM_ST_SCRIPT,
30         ///
31         LM_ST_SCRIPTSCRIPT
32 };
33
34
35 // 
36 // This is the part common to MetricsInfo and PainterInfo
37 //
38 struct MetricsBase {
39         ///
40         MetricsBase();
41         ///
42         MetricsBase(BufferView * bv, LyXFont const & font, int textwidth);
43
44         /// the current view
45         BufferView * bv;
46         /// current font
47         LyXFont font;
48         /// current math style (display/text/script/..)
49         Styles style;
50         /// name of current font - mathed specific
51         string fontname;
52         /// This is the width available in pixels
53         int textwidth;
54 };
55
56
57 //
58 // This contains a Metricsbase and Information that's only relevant during
59 // the first phase of the two-phase draw
60 //
61 struct MetricsInfo {
62         ///
63         MetricsInfo();
64         ///
65         MetricsInfo(BufferView * bv, LyXFont const & font, int textwidth);
66
67         ///
68         MetricsBase base;
69 };
70
71
72 //
73 // This contains a Metricsbase and Information that's only relevant during
74 // the second phase of the two-phase draw
75 //
76 struct PainterInfo {
77         ///
78         explicit PainterInfo(BufferView * bv);
79         ///
80         void draw(int x, int y, char c);
81
82         ///
83         MetricsBase base;
84         ///
85         Painter & pain;
86         /// width of current item
87         int width;
88 };
89
90
91 struct TextMetricsInfo {};
92
93
94 // Generic base for temporarily changing things.
95 // The original state gets restored when the Changer is destructed.
96
97 template <class Struct, class Temp = Struct>
98 struct Changer {
99         ///
100         Changer(Struct & orig) : orig_(orig) {}
101 protected:
102         ///
103         Struct & orig_;
104         ///
105         Temp save_;
106 };
107
108
109
110 // temporarily change some aspect of a font
111 struct FontChanger : public Changer<LyXFont> {
112         ///
113         FontChanger(LyXFont & orig, char const * font);
114         ///
115         ~FontChanger();
116 };
117
118
119 // temporarily change a full font
120 struct FontSetChanger : public Changer<MetricsBase> {
121         ///
122         FontSetChanger(MetricsBase & mb, char const * font);
123         ///
124         ~FontSetChanger();
125 };
126
127
128 // temporarily change the style
129 struct StyleChanger : public Changer<MetricsBase> {
130         ///
131         StyleChanger(MetricsBase & mb, Styles style);
132         ///
133         ~StyleChanger();
134 };
135
136
137 // temporarily change the style to script style
138 struct ScriptChanger : public StyleChanger {
139         ///
140         ScriptChanger(MetricsBase & mb);
141 };
142
143
144 // temporarily change the style suitable for use in fractions
145 struct FracChanger : public StyleChanger {
146         ///
147         FracChanger(MetricsBase & mb);
148 };
149
150
151 // temporarily change the style suitable for use in tabulars and arrays
152 struct ArrayChanger : public StyleChanger {
153         ///
154         ArrayChanger(MetricsBase & mb);
155 };
156
157
158
159 // temporarily change the shape of a font
160 struct ShapeChanger : public Changer<LyXFont, LyXFont::FONT_SHAPE> {
161         ///
162         ShapeChanger(LyXFont & font, LyXFont::FONT_SHAPE shape);
163         ///
164         ~ShapeChanger();
165 };
166
167
168 // temporarily change the available text width
169 struct WidthChanger : public Changer<MetricsBase>
170 {
171         ///
172         WidthChanger(MetricsBase & mb, int width);
173         ///
174         ~WidthChanger();
175 };
176
177
178 #endif