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 "support/docstring.h"
33 * While for editing purpose it is important that macros are counted
34 * as a single element, this is not the case for display. To get the
35 * spacing correct, it is necessary to dissolve all the macros that
36 * can be, along with their arguments. Then one obtains a
37 * representation of the MathData contents as a string of insets and
38 * then spacing can be done properly.
40 * This is the purpose of the MathRow class.
45 // What row elements can be
47 INSET, // this element is a plain inset
48 BEG_MACRO, // a macro begins here
49 END_MACRO, // a macro ends here
50 BEG_ARG, // a macro argument begins here
51 END_ARG, // a macro argument ends here
52 BEGIN, // dummy element before row
53 END, // dummy element after row
56 // An elements, together with its spacing
60 Element(Type t = INSET, MathClass const mc = MC_ORD);
62 /// Classifies the contents of the object
65 /// When type is INSET
67 InsetMath const * inset;
68 /// the class of the inset
70 /// the spacing around the inset
72 // Non empty when there is a completion to draw
74 // the number of characters forming the unique part.
75 size_t compl_unique_to;
77 /// When type is BEG_MACRO, END_MACRO, BEG_ARG, END_ARG
79 MathMacro const * macro;
81 // type is BEG_ARG, END_ARG
88 typedef std::vector<Element> Elements;
90 typedef Elements::iterator iterator;
92 typedef Elements::const_iterator const_iterator;
94 iterator begin() { return elements_.begin(); }
96 iterator end() { return elements_.end(); }
98 const_iterator begin() const { return elements_.begin(); }
100 const_iterator end() const { return elements_.end(); }
102 void push_back(Element const & e) { elements_.push_back(e); }
104 Element & back() { return elements_.back(); }
106 // create the math row by unwinding all macros in the MathData and
107 // compute the spacings.
108 MathRow(MetricsInfo const & mi, MathData const * ar);
111 void metrics(MetricsInfo & mi, Dimension & dim) const;
113 void draw(PainterInfo & pi, int const x, int const y) const;
115 /// superscript kerning
116 int kerning(BufferView const *) const;
119 // Index of the first inset element before position i
120 int before(int i) const;
121 // Index of the first inset element after position i
122 int after(int i) const;
129 std::ostream & operator<<(std::ostream & os, MathRow::Element const & elt);
132 std::ostream & operator<<(std::ostream & os, MathRow const & mrow);