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