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"
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 BEGIN, // an inset and/or a math array begins here
53 END, // an inset and/or a math array ends here
54 DUMMY // a dummy element (used before or after row)
57 // An elements, together with its spacing
61 Element(MetricsInfo const & mi, Type t, MathClass mc = MC_UNKNOWN);
63 /// Classifies the contents of the object
65 /// the class of the element
67 /// the spacing around the element
69 /// count whether the current mathdata is nested in macro(s)
72 InsetMath::marker_type marker;
74 /// When type is INSET
75 /// the math inset (also for BEGIN and END)
76 InsetMath const * inset;
77 // Non empty when there is a completion to draw
79 // the number of characters forming the unique part.
80 size_t compl_unique_to;
92 MathRow(Dimension const & dim) : caret_dim(dim) {}
94 typedef std::vector<Element> Elements;
96 typedef Elements::iterator iterator;
98 typedef Elements::const_iterator const_iterator;
100 iterator begin() { return elements_.begin(); }
102 iterator end() { return elements_.end(); }
104 const_iterator begin() const { return elements_.begin(); }
106 const_iterator end() const { return elements_.end(); }
108 void push_back(Element const & e) { elements_.push_back(e); }
110 Element & back() { return elements_.back(); }
112 // create the math row by unwinding all macros in the MathData and
113 // compute the spacings.
114 MathRow(MetricsInfo & mi, MathData const * ar);
117 void metrics(MetricsInfo & mi, Dimension & dim);
119 void draw(PainterInfo & pi, int const x, int const y) const;
121 /// superscript kerning
122 int kerning(BufferView const *) const;
124 /// useful when the caret visits this cell
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);