]> git.lyx.org Git - lyx.git/blob - src/mathed/MathRow.h
Fix wrong mode on output for macros that shadow global macros
[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                 BOX, // an empty box
51                 BEG_MACRO, // a macro begins here
52                 END_MACRO, // a macro ends here
53                 BEG_ARG, // a macro argument begins here
54                 END_ARG, // a macro argument 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(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
71                 /// When type is INSET
72                 /// the math inset
73                 InsetMath const * inset;
74                 // Non empty when there is a completion to draw
75                 docstring compl_text;
76                 // the number of characters forming the unique part.
77                 size_t compl_unique_to;
78
79                 /// When type is BEG_MACRO, END_MACRO, BEG_ARG, END_ARG
80                 /// the math macro
81                 MathMacro const * macro;
82
83                 // type is BEG_ARG, END_ARG
84                 MathData const * ar;
85
86                 // type is BOX
87                 ColorCode color;
88         };
89
90         ///
91         MathRow() {};
92         ///
93         typedef std::vector<Element> Elements;
94         ///
95         typedef Elements::iterator iterator;
96         ///
97         typedef Elements::const_iterator const_iterator;
98         ///
99         iterator begin() { return elements_.begin(); }
100         ///
101         iterator end() { return elements_.end(); }
102         ///
103         const_iterator begin() const { return elements_.begin(); }
104         ///
105         const_iterator end() const { return elements_.end(); }
106         //
107         void push_back(Element const & e) { elements_.push_back(e); }
108         //
109         Element & back() { return elements_.back(); }
110
111         // create the math row by unwinding all macros in the MathData and
112         // compute the spacings.
113         MathRow(MetricsInfo & mi, MathData const * ar);
114
115         //
116         void metrics(MetricsInfo & mi, Dimension & dim) const;
117         //
118         void draw(PainterInfo & pi, int const x, int const y) const;
119
120         /// superscript kerning
121         int kerning(BufferView const *) const;
122
123 private:
124         // Index of the first inset element before position i
125         int before(int i) const;
126         // Index of the first inset element after position i
127         int after(int i) const;
128
129         ///
130         Elements elements_;
131 };
132
133 ///
134 std::ostream & operator<<(std::ostream & os, MathRow::Element const & elt);
135
136 ///
137 std::ostream & operator<<(std::ostream & os, MathRow const & mrow);
138
139
140 } // namespace lyx
141
142 #endif