]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
a48b45c563bf2f8af93ab258f4f6ac40b2edb111
[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(BufferView * bv = 0, FontInfo font = FontInfo(),
56                     int textwidth = 0);
57
58         /// the current view
59         BufferView * bv;
60         /// current font
61         FontInfo font;
62         /// current math style (display/text/script/..)
63         Styles style;
64         /// name of current font - mathed specific
65         std::string fontname;
66         /// This is the width available in pixels
67         int textwidth;
68         /// count wether the current mathdata is nested in macro(s)
69         int macro_nesting;
70
71         /// Temporarily change a full font.
72         Changer changeFontSet(std::string 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         int solidLineThickness() const { return solid_line_thickness_; }
81         ///
82         int solidLineOffset() const { return solid_line_offset_; }
83         ///
84         int dottedLineThickness() const { return dotted_line_thickness_; }
85 private:
86         int solid_line_thickness_;
87         int solid_line_offset_;
88         int dotted_line_thickness_;
89 };
90
91
92 //
93 // This contains a MetricsBase and information that's only relevant during
94 // the first phase of the two-phase draw
95 //
96 class MetricsInfo {
97 public:
98         ///
99         MetricsInfo();
100         ///
101         MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
102                     MacroContext const & mc);
103
104         ///
105         MetricsBase base;
106         /// The context to resolve macros
107         MacroContext const & macrocontext;
108 };
109
110
111 //
112 // This contains a MetricsBase and information that's only relevant during
113 // the second phase of the two-phase draw
114 //
115 class PainterInfo {
116 public:
117         ///
118         PainterInfo(BufferView * bv, frontend::Painter & pain);
119         ///
120         void draw(int x, int y, char_type c);
121         ///
122         void draw(int x, int y, docstring const & str);
123         /// Determines the background color for the specified inset based on the
124         /// selection state, the background color inherited from the parent inset 
125         /// and the inset's own background color.
126         /// \param sel whether to take the selection state into account
127         ColorCode backgroundColor(Inset const * inset, bool sel = true) const;
128
129         /// Determines the text color based on the intended color, the
130         /// change tracking state and the selection state. 
131         /// \param color what the color should be by default
132         Color textColor(Color const & color) const;
133
134         ///
135         MetricsBase base;
136         ///
137         frontend::Painter & pain;
138         /// Whether the text at this point is right-to-left (for InsetNewline)
139         bool ltr_pos;
140         /// The change the parent is part of (change tracking)
141         Change change_;
142         /// Whether the parent is selected as a whole
143         bool selected;
144         /// Whether the spell checker is enabled for the parent
145         bool do_spellcheck;
146         ///
147         bool full_repaint;
148         /// Current background color
149         ColorCode background_color;
150 };
151
152 class TextMetricsInfo {};
153
154 } // namespace lyx
155
156 #endif