]> git.lyx.org Git - lyx.git/blob - src/mathed/math_scriptinset.h
the DocIterator stuff
[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         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         /// move cursor left
39         bool idxLeft(LCursor & cur) const;
40         /// move cursor right
41         bool idxRight(LCursor & cur) const;
42         /// move cursor up or down
43         bool idxUpDown(LCursor & cur, bool up) const;
44         /// Target pos when we enter the inset from the left by pressing "Right"
45         bool idxFirst(LCursor & cur) const;
46         /// Target pos when we enter the inset from the right by pressing "Left"
47         bool idxLast(LCursor & cur) const;
48         /// can we enter this cell?
49         bool validCell(idx_type i) const { return i == 2 || script_[i]; }
50
51         /// write LaTeX and Lyx code
52         void write(WriteStream & os) const;
53         /// write normalized content
54         void normalize(NormalStream &) const;
55         /// write content as something readable by Maple
56         void maple(MapleStream &) const;
57         /// write content as something readable by Mathematica
58         void mathematica(MathematicaStream &) const;
59         /// write content as something resembling MathML
60         void mathmlize(MathMLStream &) const;
61         /// write content as something readable by Octave
62         void octave(OctaveStream &) const;
63
64         /// identifies scriptinsets
65         MathScriptInset const * asScriptInset() const;
66         ///
67         MathScriptInset * asScriptInset();
68
69         /// set limits
70         void limits(int lim) { limits_ = lim; }
71         /// get limits
72         int limits() const { return limits_; }
73         /// returns subscript
74         MathArray const & down() const;
75         /// returns subscript
76         MathArray & down();
77         /// returns superscript
78         MathArray const & up() const;
79         /// returns superscript
80         MathArray & up();
81         /// returns nucleus
82         MathArray const & nuc() const;
83         /// returns nucleus
84         MathArray & nuc();
85         /// do we have a superscript?
86         bool hasUp() const;
87         /// do we have a subscript?
88         bool hasDown() const;
89         /// do we have a script?
90         bool has(bool up) const;
91         /// remove script
92         void removeScript(bool up);
93         /// make sure a script is accessible
94         void ensure(bool up);
95         /// say that we have scripts
96         void infoize(std::ostream & os) const;
97         /// say whether we have displayed limits
98         void infoize2(std::ostream & os) const;
99 protected:
100         ///
101         void priv_dispatch(LCursor & cur, FuncRequest const & cmd);
102 private:
103         /// returns x offset for main part
104         int dxx() const;
105         /// returns width of nucleus if any
106         int nwid() const;
107         /// returns y offset for superscript
108         int dy0() const;
109         /// returns y offset for subscript
110         int dy1() const;
111         /// returns x offset for superscript
112         int dx0() const;
113         /// returns x offset for subscript
114         int dx1() const;
115         /// returns ascent of nucleus if any
116         int nasc() const;
117         /// returns descent of nucleus if any
118         int ndes() const;
119         /// where do we have to draw the scripts?
120         bool hasLimits() const;
121         /// clean up empty cells
122         void notifyCursorLeaves(idx_type idx);
123
124         /// possible subscript (index 0) and superscript (index 1)
125         bool script_[2];
126         /// 1 - "limits", -1 - "nolimits", 0 - "default"
127         int limits_;
128 };
129
130 #endif