3 * \file math_scriptinset.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 "math_nestinset.h"
18 // An inset for super- and subscripts or both. The 'nucleus' is always
19 // cell 0. If there is just one script, it's cell 1 and cell_1_is_up_
20 // is set accordingly. If both are used, cell 1 is up and cell 2 is down.
22 class MathScriptInset : public MathNestInset {
24 /// create inset without scripts
26 /// create inset with single script
27 explicit MathScriptInset(bool up);
28 /// create inset with single script and given nucleus
29 MathScriptInset(MathAtom const & at, bool up);
31 void metrics(MetricsInfo & mi, Dimension & dim) const;
33 void draw(PainterInfo & pi, int x, int y) const;
35 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
37 void drawT(TextPainter & pi, int x, int y) const;
40 bool idxLeft(LCursor & cur) const;
42 bool idxRight(LCursor & cur) const;
43 /// move cursor up or down
44 bool idxUpDown(LCursor & cur, bool up) const;
45 /// Target pos when we enter the inset from the left by pressing "Right"
46 bool idxFirst(LCursor & cur) const;
47 /// Target pos when we enter the inset from the right by pressing "Left"
48 bool idxLast(LCursor & cur) const;
50 /// write LaTeX and Lyx code
51 void write(WriteStream & os) const;
52 /// write normalized content
53 void normalize(NormalStream &) const;
54 /// write content as something readable by Maple
55 void maple(MapleStream &) const;
56 /// write content as something readable by Mathematica
57 void mathematica(MathematicaStream &) const;
58 /// write content as something resembling MathML
59 void mathmlize(MathMLStream &) const;
60 /// write content as something readable by Octave
61 void octave(OctaveStream &) const;
63 /// identifies scriptinsets
64 MathScriptInset const * asScriptInset() const;
66 MathScriptInset * asScriptInset();
69 void limits(int lim) { limits_ = lim; }
71 int limits() const { return limits_; }
72 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
73 MathArray const & down() const;
74 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
76 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
77 MathArray const & up() const;
78 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
81 MathArray const & nuc() const;
84 /// do we have a superscript?
86 /// do we have a subscript?
88 /// do we have a script?
89 bool has(bool up) const;
90 /// what idx has super/subscript?
91 idx_type idxOfScript(bool up) const;
93 void removeScript(bool up);
94 /// make sure a script is accessible
96 /// say that we have scripts
97 void infoize(std::ostream & os) const;
98 /// say whether we have displayed limits
99 void infoize2(std::ostream & os) const;
101 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
103 virtual std::auto_ptr<InsetBase> doClone() const;
104 /// returns x offset for main part
106 /// returns width of nucleus if any
108 /// returns y offset for superscript
110 /// returns y offset for subscript
112 /// returns x offset for superscript
114 /// returns x offset for subscript
116 /// returns ascent of nucleus if any
118 /// returns descent of nucleus if any
120 /// where do we have to draw the scripts?
121 bool hasLimits() const;
122 /// clean up empty cells
123 void notifyCursorLeaves(LCursor & cur);
125 /// possible subscript (index 0) and superscript (index 1)
127 /// 1 - "limits", -1 - "nolimits", 0 - "default"