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