3 * \file InsetMathScript.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef MATH_SCRIPTINSET_H
13 #define MATH_SCRIPTINSET_H
15 #include "InsetMathNest.h"
21 // An inset for super- and subscripts or both. The 'nucleus' is always
22 // cell 0. If there is just one script, it's cell 1 and cell_1_is_up_
23 // is set accordingly. If both are used, cell 1 is up and cell 2 is down.
25 class InsetMathScript : public InsetMathNest {
27 /// create inset without scripts
28 InsetMathScript(Buffer * buf);
29 /// create inset with single script
30 explicit InsetMathScript(Buffer * buf, bool up);
31 /// create inset with single script and given nucleus
32 InsetMathScript(Buffer * buf, MathAtom const & at, bool up);
34 mode_type currentMode() const { return MATH_MODE; }
36 void metrics(MetricsInfo & mi, Dimension & dim) const;
38 void draw(PainterInfo & pi, int x, int y) const;
40 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
42 void drawT(TextPainter & pi, int x, int y) const;
44 /// move cursor backwards
45 bool idxBackward(Cursor & cur) const;
46 /// move cursor forward
47 bool idxForward(Cursor & cur) const;
48 /// move cursor up or down
49 bool idxUpDown(Cursor & cur, bool up) const;
50 /// Target pos when we enter the inset while moving forward
51 bool idxFirst(Cursor & cur) const;
52 /// Target pos when we enter the inset while moving backwards
53 bool idxLast(Cursor & cur) const;
55 /// write LaTeX and Lyx code
56 void write(WriteStream & os) const;
57 /// write normalized content
58 void normalize(NormalStream &) const;
59 /// write content as something readable by Maple
60 void maple(MapleStream &) const;
61 /// write content as something readable by Mathematica
62 void mathematica(MathematicaStream &) const;
63 /// write content as MathML
64 void mathmlize(MathStream &) const;
65 /// write content as HTML
66 void htmlize(HtmlStream &) const;
67 /// write content as something readable by Octave
68 void octave(OctaveStream &) const;
70 /// identifies scriptinsets
71 InsetMathScript const * asScriptInset() const;
73 InsetMathScript * asScriptInset();
76 void limits(int lim) { limits_ = lim; }
78 int limits() const { return limits_; }
79 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
80 MathData const & down() const;
81 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
83 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
84 MathData const & up() const;
85 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
88 MathData const & nuc() const;
91 /// do we have a superscript?
93 /// do we have a subscript?
95 /// do we have a script?
96 bool has(bool up) const;
97 /// what idx has super/subscript?
98 idx_type idxOfScript(bool up) const;
100 void removeScript(bool up);
101 /// make sure a script is accessible
102 void ensure(bool up);
103 /// say that we have scripts
104 void infoize(odocstream & os) const;
105 /// say whether we have displayed limits
106 void infoize2(odocstream & os) const;
108 InsetCode lyxCode() const { return MATH_SCRIPT_CODE; }
110 void validate(LaTeXFeatures &features) const;
112 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
113 /// do we want to handle this event?
114 bool getStatus(Cursor & cur, FuncRequest const & cmd,
115 FuncStatus & status) const;
117 virtual Inset * clone() const;
118 /// returns x offset for main part
119 int dxx(BufferView const & bv) const;
120 /// returns width of nucleus if any
121 int nwid(BufferView const &) const;
122 /// returns y offset for either superscript or subscript
123 int dy01(BufferView const &, int asc, int des, int what) const;
124 /// returns y offset for superscript
125 int dy0(BufferView const &) const;
126 /// returns y offset for subscript
127 int dy1(BufferView const &) const;
128 /// returns x offset for superscript
129 int dx0(BufferView const & bv) const;
130 /// returns x offset for subscript
131 int dx1(BufferView const & bv) const;
132 /// returns ascent of nucleus if any
133 int nasc(BufferView const &) const;
134 /// returns descent of nucleus if any
135 int ndes(BufferView const &) const;
136 /// returns superscript kerning of nucleus if any
137 int nker(BufferView const * bv) const;
138 /// where do we have to draw the scripts?
139 bool hasLimits() const;
140 /// clean up empty cells and return true if a cell has been deleted.
141 bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
143 /// possible subscript (index 0) and superscript (index 1)
145 /// 1 - "limits", -1 - "nolimits", 0 - "default"