4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Jean-Marc Lasgouttes
9 * Full author contact details are available in file CREDITS.
15 #include "InsetMath.h"
16 #include "MathClass.h"
18 #include "ColorCode.h"
20 #include "support/docstring.h"
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.
43 * This is the purpose of the MathRow class.
48 // What row elements can be
50 INSET, // this element is a plain inset
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)
59 // An elements, together with its spacing
63 Element(MetricsInfo const & mi, Type t, MathClass mc = MC_UNKNOWN);
65 /// Classifies the contents of the object
67 /// the class of the element
69 /// the spacing around the element
71 /// count wether the current mathdata is nested in macro(s)
74 InsetMath::marker_type marker;
76 /// When type is INSET
78 InsetMath const * inset;
79 // Non empty when there is a completion to draw
81 // the number of characters forming the unique part.
82 size_t compl_unique_to;
84 /// When type is BEG_MACRO, END_MACRO, BEG_ARG, END_ARG
86 MathMacro const * macro;
88 // type is BEG_ARG, END_ARG
98 typedef std::vector<Element> Elements;
100 typedef Elements::iterator iterator;
102 typedef Elements::const_iterator const_iterator;
104 iterator begin() { return elements_.begin(); }
106 iterator end() { return elements_.end(); }
108 const_iterator begin() const { return elements_.begin(); }
110 const_iterator end() const { return elements_.end(); }
112 void push_back(Element const & e) { elements_.push_back(e); }
114 Element & back() { return elements_.back(); }
116 // create the math row by unwinding all macros in the MathData and
117 // compute the spacings.
118 MathRow(MetricsInfo & mi, MathData const * ar);
121 void metrics(MetricsInfo & mi, Dimension & dim) const;
123 void draw(PainterInfo & pi, int const x, int const y) const;
125 /// superscript kerning
126 int kerning(BufferView const *) const;
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;
139 std::ostream & operator<<(std::ostream & os, MathRow::Element const & elt);
142 std::ostream & operator<<(std::ostream & os, MathRow const & mrow);