]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
Revert "Fix display of a math hull inset in a tight inset"
[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         /// font of the containing inset
51         FontInfo outer_font;
52         /// name of current font - mathed specific
53         std::string fontname;
54         /// This is the width available in pixels
55         int textwidth;
56         /// count wether the current mathdata is nested in macro(s)
57         int macro_nesting;
58
59         /// Temporarily change a full font.
60         Changer changeFontSet(std::string const & name);
61         /// Temporarily change font size in text mode, only record it in math mode.
62         Changer changeFontSize(std::string const & fontsize, bool mathmode);
63         /// Temporarily change the font to math if needed.
64         Changer changeEnsureMath(Inset::mode_type mode = Inset::MATH_MODE);
65         // Temporarily change to the style suitable for use in fractions
66         Changer changeFrac();
67         // Temporarily change to the style suitable for use in arrays
68         // or to style suitable for smallmatrix when \c small is true.
69         Changer changeArray(bool small = false);
70         // Temporarily change the style to (script)script style
71         Changer changeScript();
72         ///
73         int solidLineThickness() const { return solid_line_thickness_; }
74         ///
75         int solidLineOffset() const { return solid_line_offset_; }
76         ///
77         int dottedLineThickness() const { return dotted_line_thickness_; }
78         /** return the on-screen size of this length
79          *
80          *  This version of the function uses the current inset width as
81          *  width and the EM value of the current font.
82          */
83         int inPixels(Length const & len) const;
84
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, bool vm, bool tight_insets);
103
104         ///
105         MetricsBase base;
106         /// The context to resolve macros
107         MacroContext const & macrocontext;
108         /// Are we at the start of a paragraph (vertical mode)?
109         bool vmode;
110         /// if true, do not expand insets to max width artificially
111         bool tight_insets;
112 };
113
114
115 //
116 // This contains a MetricsBase and information that's only relevant during
117 // the second phase of the two-phase draw
118 //
119 class PainterInfo {
120 public:
121         ///
122         PainterInfo(BufferView * bv, frontend::Painter & pain);
123         ///
124         void draw(int x, int y, char_type c);
125         ///
126         void draw(int x, int y, docstring const & str);
127         /// Determines the background color based on the
128         /// selection state, the background color inherited from the parent inset
129         /// and the inset's own background color (if one is specified).
130         /// \param sel whether to take the selection state into account
131         ColorCode backgroundColor(Inset const * inset = nullptr, bool sel = true) const;
132
133         /// Determines the text color based on the intended color, the
134         /// change tracking state and the selection state.
135         /// \param color what the color should be by default
136         Color textColor(Color const & color) const;
137
138         ///
139         MetricsBase base;
140         ///
141         frontend::Painter & pain;
142         /// Whether the text at this point is right-to-left (for insets)
143         bool ltr_pos;
144         /// The change the parent is part of (change tracking)
145         Change change;
146         /// Whether the parent is selected as a whole
147         bool selected;
148         /// Whether the left/right margins are selected
149         bool selected_left, selected_right;
150         /// Whether the spell checker is enabled for the parent
151         bool do_spellcheck;
152         /// True when it can be assumed that the screen has been cleared
153         bool full_repaint;
154         /// Current background color
155         ColorCode background_color;
156         /// The left and right position of current line (inside margins).
157         /// Useful for drawing display math numbering
158         int leftx, rightx;
159 };
160
161 class TextMetricsInfo {};
162
163 } // namespace lyx
164
165 #endif