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 "MathClass.h"
17 #include "ColorCode.h"
18 #include "Dimension.h"
20 #include "support/docstring.h"
32 enum class marker_type : int;
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.
42 * This is the purpose of the MathRow class.
47 // What row elements can be
49 INSET, // this element is a plain inset
51 BEGIN, // an inset and/or a math array begins here
52 END, // an inset and/or a math array ends here
53 DUMMY // a dummy element (used before or after row)
56 // An elements, together with its spacing
60 Element(MetricsInfo const & mi, Type t, MathClass mc = MC_UNKNOWN);
62 /// Classifies the contents of the object
64 /// the class of the element
66 /// the spacing around the element
68 /// count whether the current mathdata is nested in macro(s)
73 /// When type is INSET
74 /// the math inset (also for BEGIN and END)
75 InsetMath const * inset;
76 // Non empty when there is a completion to draw
78 // the number of characters forming the unique part.
79 size_t compl_unique_to;
91 MathRow(Dimension const & dim) : caret_dim(dim) {}
93 typedef std::vector<Element> Elements;
95 typedef Elements::iterator iterator;
97 typedef Elements::const_iterator const_iterator;
99 iterator begin() { return elements_.begin(); }
101 iterator end() { return elements_.end(); }
103 const_iterator begin() const { return elements_.begin(); }
105 const_iterator end() const { return elements_.end(); }
107 void push_back(Element const & e) { elements_.push_back(e); }
109 Element & back() { return elements_.back(); }
111 // create the math row by unwinding all macros in the MathData and
112 // compute the spacings.
113 MathRow(MetricsInfo & mi, MathData const * ar);
116 void metrics(MetricsInfo & mi, Dimension & dim);
118 void draw(PainterInfo & pi, int const x, int const y) const;
120 /// superscript kerning
121 int kerning(BufferView const *) const;
123 /// useful when the caret visits this cell
128 // Index of the first inset element before position i
129 int before(int i) const;
130 // Index of the first inset element after position i
131 int after(int i) const;
138 std::ostream & operator<<(std::ostream & os, MathRow::Element const & elt);
141 std::ostream & operator<<(std::ostream & os, MathRow const & mrow);