]> git.lyx.org Git - lyx.git/blob - src/mathed/MathRow.h
95786b23b4e398768fae2800797fac8d54e48169
[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
19 #include "support/docstring.h"
20
21 #include <vector>
22
23 namespace lyx {
24
25 class BufferView;
26 class Dimension;
27 class MetricsInfo;
28 class PainterInfo;
29
30 class InsetMath;
31 class MathData;
32 class MathMacro;
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                 BEG_MACRO, // a macro begins here
51                 END_MACRO, // a macro ends here
52                 BEG_ARG, // a macro argument begins here
53                 END_ARG, // a macro argument ends here
54                 BEGIN, // dummy element before row
55                 END, // dummy element after row
56                 BOX // an empty box
57         };
58
59         // An elements, together with its spacing
60         struct Element
61         {
62                 ///
63                 Element(Type t);
64
65                 /// Classifies the contents of the object
66                 Type type;
67
68                 /// When type is INSET
69                 /// the math inset
70                 InsetMath const * inset;
71                 /// the class of the inset
72                 MathClass mclass;
73                 /// the spacing around the inset
74                 int before, after;
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                 /// When type is BEG_MACRO, END_MACRO, BEG_ARG, END_ARG
81                 /// the math macro
82                 MathMacro const * macro;
83
84                 // type is BEG_ARG, END_ARG
85                 MathData const * ar;
86
87                 // type is BOX
88                 ColorCode color;
89         };
90
91         ///
92         MathRow() {};
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) const;
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 private:
125         // Index of the first inset element before position i
126         int before(int i) const;
127         // Index of the first inset element after position i
128         int after(int i) const;
129
130         ///
131         Elements elements_;
132 };
133
134 ///
135 std::ostream & operator<<(std::ostream & os, MathRow::Element const & elt);
136
137 ///
138 std::ostream & operator<<(std::ostream & os, MathRow const & mrow);
139
140
141 } // namespace lyx
142
143 #endif