]> git.lyx.org Git - lyx.git/blob - src/mathed/math_scriptinset.h
Andreas' patch to prevent crash on click on previewd inset
[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 or both.  The 'nucleus' is always
19 // cell 0.  If there is just one script, it's cell 1 and cell_1_is_up_
20 // is set accordingly.  If both are used, cell 1 is up and cell 2 is down.
21
22 class MathScriptInset : public MathNestInset {
23 public:
24         /// create inset without scripts
25         MathScriptInset();
26         /// create inset with single script
27         explicit MathScriptInset(bool up);
28         /// create inset with single script and given nucleus
29         MathScriptInset(MathAtom const & at, bool up);
30         ///
31         void metrics(MetricsInfo & mi, Dimension & dim) const;
32         ///
33         void draw(PainterInfo & pi, int x, int y) const;
34         ///
35         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
36         ///
37         void drawT(TextPainter & pi, int x, int y) const;
38
39         /// move cursor left
40         bool idxLeft(LCursor & cur) const;
41         /// move cursor right
42         bool idxRight(LCursor & cur) const;
43         /// move cursor up or down
44         bool idxUpDown(LCursor & cur, bool up) const;
45         /// Target pos when we enter the inset from the left by pressing "Right"
46         bool idxFirst(LCursor & cur) const;
47         /// Target pos when we enter the inset from the right by pressing "Left"
48         bool idxLast(LCursor & cur) const;
49
50         /// write LaTeX and Lyx code
51         void write(WriteStream & os) const;
52         /// write normalized content
53         void normalize(NormalStream &) const;
54         /// write content as something readable by Maple
55         void maple(MapleStream &) const;
56         /// write content as something readable by Mathematica
57         void mathematica(MathematicaStream &) const;
58         /// write content as something resembling MathML
59         void mathmlize(MathMLStream &) const;
60         /// write content as something readable by Octave
61         void octave(OctaveStream &) const;
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. Always run 'hasDown' or 'has(false)' before!
73         MathArray const & down() const;
74         /// returns subscript. Always run 'hasDown' or 'has(false)' before!
75         MathArray & down();
76         /// returns superscript. Always run 'hasUp' or 'has(true)' before!
77         MathArray const & up() const;
78         /// returns superscript. Always run 'hasUp' or 'has(true)' before!
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         /// what idx has super/subscript?
91         idx_type idxOfScript(bool up) const;
92         /// remove script
93         void removeScript(bool up);
94         /// make sure a script is accessible
95         void ensure(bool up);
96         /// say that we have scripts
97         void infoize(std::ostream & os) const;
98         /// say whether we have displayed limits
99         void infoize2(std::ostream & os) const;
100 protected:
101         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
102 private:
103         virtual std::auto_ptr<InsetBase> doClone() const;
104         /// returns x offset for main part
105         int dxx() const;
106         /// returns width of nucleus if any
107         int nwid() const;
108         /// returns y offset for superscript
109         int dy0() const;
110         /// returns y offset for subscript
111         int dy1() const;
112         /// returns x offset for superscript
113         int dx0() const;
114         /// returns x offset for subscript
115         int dx1() const;
116         /// returns ascent of nucleus if any
117         int nasc() const;
118         /// returns descent of nucleus if any
119         int ndes() const;
120         /// where do we have to draw the scripts?
121         bool hasLimits() const;
122         /// clean up empty cells
123         void notifyCursorLeaves(LCursor & cur);
124
125         /// possible subscript (index 0) and superscript (index 1)
126         bool cell_1_is_up_;
127         /// 1 - "limits", -1 - "nolimits", 0 - "default"
128         int limits_;
129 };
130
131 #endif