]> git.lyx.org Git - lyx.git/blob - src/mathed/math_scriptinset.h
fad32bf22e243e971873a71665e3e28dd4bed5f2
[lyx.git] / src / mathed / math_scriptinset.h
1 // -*- C++ -*-
2 #ifndef MATH_SCRIPTINSET_H
3 #define MATH_SCRIPTINSET_H
4
5 #include "math_nestinset.h"
6
7
8 /** Inset for super- and subscripts
9  *  \author André Pönitz
10  *
11  * Full author contact details are available in file CREDITS
12  */
13
14 class MathScriptInset : public MathNestInset {
15 public:
16         /// create inset without scripts
17         MathScriptInset();
18         /// create inset with single script
19         explicit MathScriptInset(bool up);
20         /// create inset with single script and given nucleus
21         MathScriptInset(MathAtom const & at, bool up);
22         ///
23         MathInset * clone() const;
24         ///
25         void metrics(MathMetricsInfo & mi) const;
26         ///
27         void draw(MathPainterInfo & pi, int x, int y) const;
28         ///
29         void metricsT(TextMetricsInfo const & mi) const;
30         ///
31         void drawT(TextPainter & pi, int x, int y) const;
32
33         /// write LaTeX and Lyx code
34         void write(WriteStream & os) const;
35         /// write normalized content
36         void normalize(NormalStream &) const;
37         /// write content as something readable by Maple
38         void maplize(MapleStream &) const;
39         /// write content as something readable by Mathematica
40         void mathematicize(MathematicaStream &) const;
41         /// write content as something resembling MathML
42         void mathmlize(MathMLStream &) const;
43         /// write content as something readable by Octave
44         void octavize(OctaveStream &) const;
45         /// move cursor left
46         bool idxLeft(idx_type &, pos_type &) const;
47         /// move cursor right
48         bool idxRight(idx_type &, pos_type &) const;
49         /// move cursor up or down
50         bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
51         /// Target pos when we enter the inset from the left by pressing "Right"
52         bool idxFirst(idx_type & idx, pos_type & pos) const;
53         /// Target pos when we enter the inset from the right by pressing "Left"
54         bool idxLast(idx_type & idx, pos_type & pos) const;
55         /// can we enter this cell?
56         bool validCell(idx_type i) const { return i == 2 || script_[i]; }
57
58         /// identifies scriptinsets
59         MathScriptInset const * asScriptInset() const;
60         ///
61         MathScriptInset * asScriptInset();
62
63         /// set limits
64         void limits(int lim) { limits_ = lim; }
65         /// get limits
66         int limits() const { return limits_; }
67         /// returns subscript
68         MathArray const & down() const;
69         /// returns subscript
70         MathArray & down();
71         /// returns superscript
72         MathArray const & up() const;
73         /// returns superscript
74         MathArray & up();
75         /// returns nucleus
76         MathArray const & nuc() const;
77         /// returns nucleus
78         MathArray & nuc();
79         /// do we have a superscript?
80         bool hasUp() const;
81         /// do we have a subscript?
82         bool hasDown() const;
83         /// do we have a script?
84         bool has(bool up) const;
85         /// remove script
86         void removeScript(bool up);
87         /// make sure a script is accessible
88         void ensure(bool up);
89         /// say that we have scripts
90         void infoize(std::ostream & os) const;
91         /// say whether we have displayed limits
92         void infoize2(std::ostream & os) const;
93         /// local dispatcher
94         result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
95
96 private:
97         /// returns x offset for main part
98         int dxx() const;
99         /// returns width of nucleus if any
100         int nwid() const;
101         /// returns y offset for superscript
102         int dy0() const;
103         /// returns y offset for subscript
104         int dy1() const;
105         /// returns x offset for superscript
106         int dx0() const;
107         /// returns x offset for subscript
108         int dx1() const;
109         /// returns ascent of nucleus if any
110         int nasc() const;
111         /// returns descent of nucleus if any
112         int ndes() const;
113         /// where do we have to draw the scripts?
114         bool hasLimits() const;
115         /// clean up empty cells
116         void notifyCursorLeaves(idx_type idx);
117
118         /// possible subscript (index 0) and superscript (index 1)
119         bool script_[2];
120         /// 1 - "limits", -1 - "nolimits", 0 - "default"
121         int limits_;
122 };
123
124 #endif