]> git.lyx.org Git - lyx.git/blob - src/mathed/math_scriptinset.h
make cursor less eager to leave the formula when pressing 'up' or 'down'
[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         ///
18         MathScriptInset();
19         ///
20         explicit MathScriptInset(bool up);
21         ///
22         MathInset * clone() const;
23         ///
24         void write(WriteStream & os) const;
25         ///
26         void normalize(NormalStream & os) const;
27         ///
28         void metrics(MathMetricsInfo const & st) const;
29         ///
30         void draw(Painter &, int x, int y) const;
31
32         ///
33         void metrics(MathInset const * nuc, MathMetricsInfo const & st) const;
34         ///
35         void draw(MathInset const * nuc, Painter &, int x, int y) const;
36         ///
37         int ascent(MathInset const * nuc) const;
38         ///
39         int descent(MathInset const * nuc) const;
40         ///
41         int width(MathInset const * nuc) const;
42
43         ///
44         bool idxLeft(idx_type &, pos_type &) const;
45         ///
46         bool idxRight(idx_type &, pos_type &) const;
47         ///
48         bool idxFirstUp(idx_type &, pos_type &) const;
49         ///
50         bool idxFirstDown(idx_type &, pos_type &) const;
51         ///
52         bool idxLastUp(idx_type &, pos_type &) const;
53         ///
54         bool idxLastDown(idx_type &, pos_type &) const;
55
56         ///
57         MathScriptInset const * asScriptInset() const;
58         ///
59         MathScriptInset * asScriptInset();
60
61         /// set limits
62         void limits(int lim) { limits_ = lim; }
63         /// 
64         int limits() const { return limits_; }
65         ///
66         bool hasLimits(MathInset const * nuc) const;
67         /// true if we have an "inner" position
68         MathXArray const & up() const;
69         /// returns subscript
70         MathXArray const & down() const;
71         /// returns superscript
72         MathXArray & up();
73         /// returns subscript
74         MathXArray & down();
75         /// do we have a superscript?
76         bool hasUp() const;
77         /// do we have a subscript?
78         bool hasDown() const;
79         /// do we have a script?
80         bool has(bool up) const;
81         /// remove script
82         void removeScript(bool up);
83         /// remove script
84         void removeEmptyScripts();
85         ///
86         void ensure(bool up);
87
88         /// suppresses empty braces if necessary
89         void write(MathInset const * nuc, WriteStream & os) const;
90         ///
91         void normalize(MathInset const * nuc, NormalStream & os) const;
92         ///
93         void octavize(MathInset const * nuc, OctaveStream & os) const;
94         ///
95         void maplize(MathInset const * nuc, MapleStream & os) const;
96         ///
97         void mathmlize(MathInset const * nuc, MathMLStream & os) const;
98
99 public:
100         /// returns x offset for main part
101         int dxx(MathInset const * nuc) const;
102         /// returns width of nucleus if any
103         int nwid(MathInset const * nuc) const;
104 private:
105         /// returns y offset for superscript
106         int dy0(MathInset const * nuc) const;
107         /// returns y offset for subscript
108         int dy1(MathInset const * nuc) const;
109         /// returns x offset for superscript
110         int dx0(MathInset const * nuc) const;
111         /// returns x offset for subscript
112         int dx1(MathInset const * nuc) const;
113         /// returns ascent of nucleus if any
114         int nasc(MathInset const * nuc) const;
115         /// returns descent of nucleus if any
116         int ndes(MathInset const * nuc) const;
117
118         /// possible subscript (index 0) and superscript (index 1)
119         bool script_[2]; 
120         ///
121         int limits_;
122         ///
123         mutable MathMetricsInfo mi_;
124 };
125
126 #endif
127