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