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