]> git.lyx.org Git - lyx.git/blob - src/mathed/MathRow.h
Fix font of macro template name
[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
20 #include "support/docstring.h"
21
22 #include <vector>
23
24 namespace lyx {
25
26 class BufferView;
27 class Dimension;
28 class MetricsInfo;
29 class PainterInfo;
30
31 class InsetMath;
32 class MathData;
33 class MathMacro;
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                 BEG_MACRO, // a macro begins here
53                 END_MACRO, // a macro ends here
54                 BEG_ARG, // a macro argument begins here
55                 END_ARG, // a macro argument ends here
56                 DUMMY // a dummy element (used before or after row)
57         };
58
59         // An elements, together with its spacing
60         struct Element
61         {
62                 ///
63                 Element(MetricsInfo const & mi, Type t, MathClass mc = MC_UNKNOWN);
64
65                 /// Classifies the contents of the object
66                 Type type;
67                 /// the class of the element
68                 MathClass mclass;
69                 /// the spacing around the element
70                 int before, after;
71                 /// count wether the current mathdata is nested in macro(s)
72                 int macro_nesting;
73                 /// Marker type
74                 InsetMath::marker_type marker;
75
76                 /// When type is INSET
77                 /// the math inset
78                 InsetMath const * inset;
79                 // Non empty when there is a completion to draw
80                 docstring compl_text;
81                 // the number of characters forming the unique part.
82                 size_t compl_unique_to;
83
84                 /// When type is BEG_MACRO, END_MACRO, BEG_ARG, END_ARG
85                 /// the math macro
86                 MathMacro const * macro;
87
88                 // type is BEG_ARG, END_ARG
89                 MathData const * ar;
90
91                 // type is BOX
92                 ColorCode color;
93         };
94
95         ///
96         MathRow() {};
97         ///
98         typedef std::vector<Element> Elements;
99         ///
100         typedef Elements::iterator iterator;
101         ///
102         typedef Elements::const_iterator const_iterator;
103         ///
104         iterator begin() { return elements_.begin(); }
105         ///
106         iterator end() { return elements_.end(); }
107         ///
108         const_iterator begin() const { return elements_.begin(); }
109         ///
110         const_iterator end() const { return elements_.end(); }
111         //
112         void push_back(Element const & e) { elements_.push_back(e); }
113         //
114         Element & back() { return elements_.back(); }
115
116         // create the math row by unwinding all macros in the MathData and
117         // compute the spacings.
118         MathRow(MetricsInfo & mi, MathData const * ar);
119
120         //
121         void metrics(MetricsInfo & mi, Dimension & dim) const;
122         //
123         void draw(PainterInfo & pi, int const x, int const y) const;
124
125         /// superscript kerning
126         int kerning(BufferView const *) const;
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