]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
Fix text direction issue for InsetInfo in RTL context
[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 #include "insets/Inset.h"
24
25
26 #include <string>
27
28
29 namespace lyx {
30
31 namespace frontend { class Painter; }
32 class BufferView;
33 class Length;
34 class MacroContext;
35
36
37 //
38 // This is the part common to MetricsInfo and PainterInfo
39 //
40 class MetricsBase {
41 public:
42         ///
43         MetricsBase(BufferView * bv = 0, FontInfo font = FontInfo(),
44                     int textwidth = 0);
45
46         /// the current view
47         BufferView * bv;
48         /// current font
49         FontInfo font;
50         /// name of current font - mathed specific
51         std::string fontname;
52         /// This is the width available in pixels
53         int textwidth;
54         /// count wether the current mathdata is nested in macro(s)
55         int macro_nesting;
56
57         /// Temporarily change a full font.
58         Changer changeFontSet(std::string const & font);
59         /// Temporarily change the font to math if needed.
60         Changer changeEnsureMath(Inset::mode_type mode = Inset::MATH_MODE);
61         // Temporarily change to the style suitable for use in fractions
62         Changer changeFrac();
63         // Temporarily change to the style suitable for use in arrays
64         Changer changeArray();
65         // Temporarily change the style to (script)script style
66         Changer changeScript();
67         ///
68         int solidLineThickness() const { return solid_line_thickness_; }
69         ///
70         int solidLineOffset() const { return solid_line_offset_; }
71         ///
72         int dottedLineThickness() const { return dotted_line_thickness_; }
73         /** return the on-screen size of this length
74          *
75          *  This version of the function uses the current inset width as
76          *  width and the EM value of the current font.
77          */
78         int inPixels(Length const & len) const;
79
80 private:
81         int solid_line_thickness_;
82         int solid_line_offset_;
83         int dotted_line_thickness_;
84 };
85
86
87 //
88 // This contains a MetricsBase and information that's only relevant during
89 // the first phase of the two-phase draw
90 //
91 class MetricsInfo {
92 public:
93         ///
94         MetricsInfo();
95         ///
96         MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
97                     MacroContext const & mc);
98
99         ///
100         MetricsBase base;
101         /// The context to resolve macros
102         MacroContext const & macrocontext;
103 };
104
105
106 //
107 // This contains a MetricsBase and information that's only relevant during
108 // the second phase of the two-phase draw
109 //
110 class PainterInfo {
111 public:
112         ///
113         PainterInfo(BufferView * bv, frontend::Painter & pain);
114         ///
115         void draw(int x, int y, char_type c);
116         ///
117         void draw(int x, int y, docstring const & str);
118         /// Determines the background color for the specified inset based on the
119         /// selection state, the background color inherited from the parent inset
120         /// and the inset's own background color.
121         /// \param sel whether to take the selection state into account
122         ColorCode backgroundColor(Inset const * inset, bool sel = true) const;
123
124         /// Determines the text color based on the intended color, the
125         /// change tracking state and the selection state.
126         /// \param color what the color should be by default
127         Color textColor(Color const & color) const;
128
129         ///
130         MetricsBase base;
131         ///
132         frontend::Painter & pain;
133         /// Whether the text at this point is right-to-left (for insets)
134         bool ltr_pos;
135         /// The change the parent is part of (change tracking)
136         Change change_;
137         /// Whether the parent is selected as a whole
138         bool selected;
139         /// Whether the spell checker is enabled for the parent
140         bool do_spellcheck;
141         /// True when it can be assumed that the screen has been cleared
142         bool full_repaint;
143         /// Current background color
144         ColorCode background_color;
145 };
146
147 class TextMetricsInfo {};
148
149 } // namespace lyx
150
151 #endif