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 mode_type currentMode() const { return MATH_MODE; }
33 void metrics(MetricsInfo & mi, Dimension & dim) const;
35 void draw(PainterInfo & pi, int x, int y) const;
37 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
39 void drawT(TextPainter & pi, int x, int y) const;
42 bool idxLeft(LCursor & cur) const;
44 bool idxRight(LCursor & cur) const;
45 /// move cursor up or down
46 bool idxUpDown(LCursor & cur, bool up) const;
47 /// Target pos when we enter the inset from the left by pressing "Right"
48 bool idxFirst(LCursor & cur) const;
49 /// Target pos when we enter the inset from the right by pressing "Left"
50 bool idxLast(LCursor & cur) const;
52 /// write LaTeX and Lyx code
53 void write(WriteStream & os) const;
54 /// write normalized content
55 void normalize(NormalStream &) const;
56 /// write content as something readable by Maple
57 void maple(MapleStream &) const;
58 /// write content as something readable by Mathematica
59 void mathematica(MathematicaStream &) const;
60 /// write content as something resembling MathML
61 void mathmlize(MathMLStream &) const;
62 /// write content as something readable by Octave
63 void octave(OctaveStream &) const;
65 /// identifies scriptinsets
66 MathScriptInset const * asScriptInset() const;
68 MathScriptInset * asScriptInset();
71 void limits(int lim) { limits_ = lim; }
73 int limits() const { return limits_; }
74 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
75 MathArray const & down() const;
76 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
78 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
79 MathArray const & up() const;
80 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
83 MathArray const & nuc() const;
86 /// do we have a superscript?
88 /// do we have a subscript?
90 /// do we have a script?
91 bool has(bool up) const;
92 /// what idx has super/subscript?
93 idx_type idxOfScript(bool up) const;
95 void removeScript(bool up);
96 /// make sure a script is accessible
98 /// say that we have scripts
99 void infoize(std::ostream & os) const;
100 /// say whether we have displayed limits
101 void infoize2(std::ostream & os) const;
103 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
105 virtual std::auto_ptr<InsetBase> doClone() const;
106 /// returns x offset for main part
108 /// returns width of nucleus if any
110 /// returns y offset for superscript
112 /// returns y offset for subscript
114 /// returns x offset for superscript
116 /// returns x offset for subscript
118 /// returns ascent of nucleus if any
120 /// returns descent of nucleus if any
122 /// where do we have to draw the scripts?
123 bool hasLimits() const;
124 /// clean up empty cells and return true if a cell has been deleted.
125 bool notifyCursorLeaves(LCursor & cur);
127 /// possible subscript (index 0) and superscript (index 1)
129 /// 1 - "limits", -1 - "nolimits", 0 - "default"