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