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