]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
3f18724cb72313e23df648116519c42f1317f69d
[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/Changer.h"
22
23
24 #include <string>
25
26
27 namespace lyx {
28
29 namespace frontend { class Painter; }
30 class BufferView;
31 class Inset;
32 class MacroContext;
33
34
35 /// Standard Sizes (mode styles)
36 /// note: These values are hard-coded in changeStyle
37 enum Styles {
38         ///
39         LM_ST_DISPLAY = 0,
40         ///
41         LM_ST_TEXT,
42         ///
43         LM_ST_SCRIPT,
44         ///
45         LM_ST_SCRIPTSCRIPT
46 };
47
48
49 //
50 // This is the part common to MetricsInfo and PainterInfo
51 //
52 class MetricsBase {
53 public:
54         ///
55         MetricsBase();
56         ///
57         MetricsBase(BufferView * bv, FontInfo const & font, int textwidth);
58
59         /// the current view
60         BufferView * bv;
61         /// current font
62         FontInfo font;
63         /// current math style (display/text/script/..)
64         Styles style;
65         /// name of current font - mathed specific
66         std::string fontname;
67         /// This is the width available in pixels
68         int textwidth;
69
70         /// Temporarily change a full font.
71         Changer changeFontSet(docstring const & font, bool cond = true);
72         Changer changeFontSet(char const * font, bool cond = true);
73         /// Temporarily change the font size and the math style.
74         Changer changeStyle(Styles style, bool cond = true);
75         // Temporarily change to the style suitable for use in fractions
76         Changer changeFrac(bool cond = true);
77         // Temporarily change the style to (script)script style
78         Changer changeScript(bool cond = true);
79 };
80
81
82 //
83 // This contains a MetricsBase and information that's only relevant during
84 // the first phase of the two-phase draw
85 //
86 class MetricsInfo {
87 public:
88         ///
89         MetricsInfo();
90         ///
91         MetricsInfo(BufferView * bv, FontInfo const & font, int textwidth, MacroContext const & mc);
92
93         ///
94         MetricsBase base;
95         /// The context to resolve macros
96         MacroContext const & macrocontext;
97 };
98
99
100 //
101 // This contains a MetricsBase and information that's only relevant during
102 // the second phase of the two-phase draw
103 //
104 class PainterInfo {
105 public:
106         ///
107         PainterInfo(BufferView * bv, frontend::Painter & pain);
108         ///
109         void draw(int x, int y, char_type c);
110         ///
111         void draw(int x, int y, docstring const & str);
112         /// Determines the background color for the specified inset based on the
113         /// selection state, the background color inherited from the parent inset 
114         /// and the inset's own background color.
115         /// \param sel whether to take the selection state into account
116         ColorCode backgroundColor(Inset const * inset, bool sel = true) const;
117
118         /// Determines the text color based on the intended color, the
119         /// change tracking state and the selection state. 
120         /// \param color what the color should be by default
121         Color textColor(Color const & color) const;
122
123         ///
124         MetricsBase base;
125         ///
126         frontend::Painter & pain;
127         /// Whether the text at this point is right-to-left (for InsetNewline)
128         bool ltr_pos;
129         /// The change the parent is part of (change tracking)
130         Change change_;
131         /// Whether the parent is selected as a whole
132         bool selected;
133         /// Whether the spell checker is enabled for the parent
134         bool do_spellcheck;
135         ///
136         bool full_repaint;
137         /// Current background color
138         ColorCode background_color;
139 };
140
141 class TextMetricsInfo {};
142
143 } // namespace lyx
144
145 #endif