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"
19 #include "Dimension.h"
21 #include "support/docstring.h"
34 * While for editing purpose it is important that macros are counted
35 * as a single element, this is not the case for display. To get the
36 * spacing correct, it is necessary to dissolve all the macros that
37 * can be, along with their arguments. Then one obtains a
38 * representation of the MathData contents as a string of insets and
39 * then spacing can be done properly.
41 * This is the purpose of the MathRow class.
46 // What row elements can be
48 INSET, // this element is a plain inset
50 BEGIN, // an inset and/or a math array begins here
51 END, // an inset and/or a math array ends here
52 DUMMY // a dummy element (used before or after row)
55 // An elements, together with its spacing
59 Element(MetricsInfo const & mi, Type t, MathClass mc = MC_UNKNOWN);
61 /// Classifies the contents of the object
63 /// the class of the element
65 /// the spacing around the element
67 /// count whether the current mathdata is nested in macro(s)
70 InsetMath::marker_type marker;
72 /// When type is INSET
73 /// the math inset (also for BEGIN and END)
74 InsetMath const * inset;
75 // Non empty when there is a completion to draw
77 // the number of characters forming the unique part.
78 size_t compl_unique_to;
90 MathRow(Dimension const & dim) : caret_dim(dim) {}
92 typedef std::vector<Element> Elements;
94 typedef Elements::iterator iterator;
96 typedef Elements::const_iterator const_iterator;
98 iterator begin() { return elements_.begin(); }
100 iterator end() { return elements_.end(); }
102 const_iterator begin() const { return elements_.begin(); }
104 const_iterator end() const { return elements_.end(); }
106 void push_back(Element const & e) { elements_.push_back(e); }
108 Element & back() { return elements_.back(); }
110 // create the math row by unwinding all macros in the MathData and
111 // compute the spacings.
112 MathRow(MetricsInfo & mi, MathData const * ar);
115 void metrics(MetricsInfo & mi, Dimension & dim);
117 void draw(PainterInfo & pi, int const x, int const y) const;
119 /// superscript kerning
120 int kerning(BufferView const *) const;
122 /// useful when the caret visits this cell
127 // Index of the first inset element before position i
128 int before(int i) const;
129 // Index of the first inset element after position i
130 int after(int i) const;
137 std::ostream & operator<<(std::ostream & os, MathRow::Element const & elt);
140 std::ostream & operator<<(std::ostream & os, MathRow const & mrow);