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