]> git.lyx.org Git - lyx.git/blob - src/mathed/MathRow.h
Amend 6c3447c8: FindAdv: sometimes a space is added on some math symbols
[lyx.git] / src / mathed / MathRow.h
1 // -*- C++ -*-
2 /**
3  * \file MathRow.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jean-Marc Lasgouttes
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef MATH_ROW_H
13 #define MATH_ROW_H
14
15 #include "MathClass.h"
16
17 #include "ColorCode.h"
18 #include "Dimension.h"
19
20 #include "support/docstring.h"
21
22 #include <vector>
23
24 namespace lyx {
25
26 class BufferView;
27 class InsetMath;
28 class MathData;
29 class MetricsInfo;
30 class PainterInfo;
31
32 enum class marker_type : int;
33
34 /*
35  * While for editing purpose it is important that macros are counted
36  * as a single element, this is not the case for display. To get the
37  * spacing correct, it is necessary to dissolve all the macros that
38  * can be, along with their arguments. Then one obtains a
39  * representation of the MathData contents as a string of insets and
40  * then spacing can be done properly.
41  *
42  * This is the purpose of the MathRow class.
43  */
44 class MathRow
45 {
46 public:
47         // What row elements can be
48         enum Type {
49                 INSET, // this element is a plain inset
50                 BOX, // an empty box
51                 BEGIN, // an inset and/or a math array begins here
52                 END, // an inset and/or a math array ends here
53                 BEGIN_SEL, // the selection begins here
54                 END_SEL, // the selection ends here
55                 DUMMY // a dummy element (used before or after row)
56         };
57
58         // An elements, together with its spacing
59         struct Element
60         {
61                 ///
62                 Element(MetricsInfo const & mi, Type t, MathClass mc = MC_UNKNOWN);
63
64                 /// Classifies the contents of the object
65                 Type type;
66                 /// the class of the element
67                 MathClass mclass;
68                 /// the spacing around the element
69                 int before, after;
70                 /// count whether the current mathdata is nested in macro(s)
71                 int macro_nesting;
72                 /// Marker type
73                 marker_type marker;
74
75                 /// When type is INSET
76                 /// the math inset (also for BEGIN and END)
77                 InsetMath const * inset;
78                 // Non empty when there is a completion to draw
79                 docstring compl_text;
80                 // the number of characters forming the unique part.
81                 size_t compl_unique_to;
82
83                 // type is BEGIN, END
84                 MathData const * ar;
85
86                 // type is BOX
87                 ColorCode color;
88         };
89
90         ///
91         MathRow() {}
92         ///
93         MathRow(Dimension const & dim) : caret_dim(dim) {}
94         ///
95         typedef std::vector<Element> Elements;
96         ///
97         typedef Elements::iterator iterator;
98         ///
99         typedef Elements::const_iterator const_iterator;
100         ///
101         iterator begin() { return elements_.begin(); }
102         ///
103         iterator end() { return elements_.end(); }
104         ///
105         const_iterator begin() const { return elements_.begin(); }
106         ///
107         const_iterator end() const { return elements_.end(); }
108         //
109         void push_back(Element const & e) { elements_.push_back(e); }
110         //
111         Element & back() { return elements_.back(); }
112
113         // create the math row by unwinding all macros in the MathData and
114         // compute the spacings.
115         MathRow(MetricsInfo & mi, MathData const * ar);
116
117         //
118         void metrics(MetricsInfo & mi, Dimension & dim);
119         //
120         void draw(PainterInfo & pi, int const x, int const y) const;
121
122         /// superscript kerning
123         int kerning(BufferView const *) const;
124
125         /// useful when the caret visits this cell
126         Dimension caret_dim;
127
128
129 private:
130         // Index of the first inset element before position i
131         int before(int i) const;
132         // Index of the first inset element after position i
133         int after(int i) const;
134
135         ///
136         Elements elements_;
137 };
138
139 ///
140 std::ostream & operator<<(std::ostream & os, MathRow::Element const & elt);
141
142 ///
143 std::ostream & operator<<(std::ostream & os, MathRow const & mrow);
144
145
146 } // namespace lyx
147
148 #endif