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