]> git.lyx.org Git - lyx.git/blob - src/MetricsInfo.h
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         /// 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 & name);
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         // or to style suitable for smallmatrix when \c small is true.
65         Changer changeArray(bool small = false);
66         // Temporarily change the style to (script)script style
67         Changer changeScript();
68         ///
69         int solidLineThickness() const { return solid_line_thickness_; }
70         ///
71         int solidLineOffset() const { return solid_line_offset_; }
72         ///
73         int dottedLineThickness() const { return dotted_line_thickness_; }
74         /** return the on-screen size of this length
75          *
76          *  This version of the function uses the current inset width as
77          *  width and the EM value of the current font.
78          */
79         int inPixels(Length const & len) const;
80
81 private:
82         int solid_line_thickness_;
83         int solid_line_offset_;
84         int dotted_line_thickness_;
85 };
86
87
88 //
89 // This contains a MetricsBase and information that's only relevant during
90 // the first phase of the two-phase draw
91 //
92 class MetricsInfo {
93 public:
94         ///
95         MetricsInfo();
96         ///
97         MetricsInfo(BufferView * bv, FontInfo font, int textwidth,
98                     MacroContext const & mc, bool vm, bool tight_insets);
99
100         ///
101         MetricsBase base;
102         /// The context to resolve macros
103         MacroContext const & macrocontext;
104         /// Are we at the start of a paragraph (vertical mode)?
105         bool vmode;
106         /// if true, do not expand insets to max width artificially
107         bool tight_insets;
108         /// Extra width required by an inset, in addition to its dimension
109         int extrawidth;
110 };
111
112
113 //
114 // This contains a MetricsBase and information that's only relevant during
115 // the second phase of the two-phase draw
116 //
117 class PainterInfo {
118 public:
119         ///
120         PainterInfo(BufferView * bv, frontend::Painter & pain);
121         ///
122         void draw(int x, int y, char_type c);
123         ///
124         void draw(int x, int y, docstring const & str);
125         /// Determines the background color based on the
126         /// selection state, the background color inherited from the parent inset
127         /// and the inset's own background color (if one is specified).
128         /// \param sel whether to take the selection state into account
129         ColorCode backgroundColor(Inset const * inset = nullptr, bool sel = true) const;
130
131         /// Determines the text color based on the intended color, the
132         /// change tracking state and the selection state.
133         /// \param color what the color should be by default
134         Color textColor(Color const & color) const;
135
136         ///
137         MetricsBase base;
138         ///
139         frontend::Painter & pain;
140         /// Whether the text at this point is right-to-left (for insets)
141         bool ltr_pos;
142         /// The change the parent is part of (change tracking)
143         Change change;
144         /// Whether the parent is selected as a whole
145         bool selected;
146         /// Whether the left/right margins are selected
147         bool selected_left, selected_right;
148         /// Whether the spell checker is enabled for the parent
149         bool do_spellcheck;
150         /// True when it can be assumed that the screen has been cleared
151         bool full_repaint;
152         /// Current background color
153         ColorCode background_color;
154         /// The left and right position of current line (inside margins).
155         /// Useful for drawing display math numbering
156         int leftx, rightx;
157 };
158
159 class TextMetricsInfo {};
160
161 } // namespace lyx
162
163 #endif