]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathScript.h
Introduce hooks to encapsulate macro code of MathRow
[lyx.git] / src / mathed / InsetMathScript.h
1 // -*- C++ -*-
2 /**
3  * \file InsetMathScript.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 "InsetMathNest.h"
16
17
18 namespace lyx {
19
20
21 // An inset for super- and subscripts or both.  The 'nucleus' is always
22 // cell 0.  If there is just one script, it's cell 1 and cell_1_is_up_
23 // is set accordingly.  If both are used, cell 1 is up and cell 2 is down.
24
25 class InsetMathScript : public InsetMathNest {
26 public:
27         /// create inset without scripts
28         InsetMathScript(Buffer * buf);
29         /// create inset with single script
30         explicit InsetMathScript(Buffer * buf, bool up);
31         /// create inset with single script and given nucleus
32         InsetMathScript(Buffer * buf, MathAtom const & at, bool up);
33         ///
34         mode_type currentMode() const { return MATH_MODE; }
35         ///
36         MathClass mathClass() const;
37         ///
38         void metrics(MetricsInfo & mi, Dimension & dim) const;
39         ///
40         void draw(PainterInfo & pi, int x, int y) const;
41         ///
42         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
43         ///
44         void drawT(TextPainter & pi, int x, int y) const;
45
46         /// move cursor backwards
47         bool idxBackward(Cursor & cur) const;
48         /// move cursor forward
49         bool idxForward(Cursor & cur) const;
50         /// move cursor up or down
51         bool idxUpDown(Cursor & cur, bool up) const;
52         /// Target pos when we enter the inset while moving forward
53         bool idxFirst(Cursor & cur) const;
54         /// Target pos when we enter the inset while moving backwards
55         bool idxLast(Cursor & cur) const;
56
57         /// write LaTeX and Lyx code
58         void write(WriteStream & os) const;
59         /// write normalized content
60         void normalize(NormalStream &) const;
61         /// write content as something readable by Maple
62         void maple(MapleStream &) const;
63         /// write content as something readable by Mathematica
64         void mathematica(MathematicaStream &) const;
65         /// write content as MathML
66         void mathmlize(MathStream &) const;
67         /// write content as HTML
68         void htmlize(HtmlStream &) const;
69         /// write content as something readable by Octave
70         void octave(OctaveStream &) const;
71
72         /// identifies scriptinsets
73         InsetMathScript const * asScriptInset() const;
74         ///
75         InsetMathScript * asScriptInset();
76
77         /// set limits
78         void limits(int lim) { limits_ = lim; }
79         /// get limits
80         int limits() const { return limits_; }
81         /// returns subscript. Always run 'hasDown' or 'has(false)' before!
82         MathData const & down() const;
83         /// returns subscript. Always run 'hasDown' or 'has(false)' before!
84         MathData & down();
85         /// returns superscript. Always run 'hasUp' or 'has(true)' before!
86         MathData const & up() const;
87         /// returns superscript. Always run 'hasUp' or 'has(true)' before!
88         MathData & up();
89         /// returns nucleus
90         MathData const & nuc() const;
91         /// returns nucleus
92         MathData & nuc();
93         /// do we have a superscript?
94         bool hasUp() const;
95         /// do we have a subscript?
96         bool hasDown() const;
97         /// do we have a script?
98         bool has(bool up) const;
99         /// what idx has super/subscript?
100         idx_type idxOfScript(bool up) const;
101         /// remove script
102         void removeScript(bool up);
103         /// make sure a script is accessible
104         void ensure(bool up);
105         /// say that we have scripts
106         void infoize(odocstream & os) const;
107         /// say whether we have displayed limits
108         void infoize2(odocstream & os) const;
109         ///
110         InsetCode lyxCode() const { return MATH_SCRIPT_CODE; }
111         ///
112         void validate(LaTeXFeatures &features) const;
113 protected:
114         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
115         /// do we want to handle this event?
116         bool getStatus(Cursor & cur, FuncRequest const & cmd,
117                 FuncStatus & status) const;
118 private:
119         virtual Inset * clone() const;
120         /// returns x offset for main part
121         int dxx(BufferView const & bv) const;
122         /// returns width of nucleus if any
123         int nwid(BufferView const &) const;
124         /// returns y offset for either superscript or subscript
125         int dy01(BufferView const &, int asc, int des, int what) const;
126         /// returns y offset for superscript
127         int dy0(BufferView const &) const;
128         /// returns y offset for subscript
129         int dy1(BufferView const &) const;
130         /// returns x offset for superscript
131         int dx0(BufferView const & bv) const;
132         /// returns x offset for subscript
133         int dx1(BufferView const & bv) const;
134         /// returns ascent of nucleus if any
135         int nasc(BufferView const &) const;
136         /// returns descent of nucleus if any
137         int ndes(BufferView const &) const;
138         /// Italic correction: amount of displacement between subscript and
139         /// superscript in math mode as per Appendix G, rule 18f.  A positive value
140         /// shifts the superscript to the right, and a negative value shifts the
141         /// subscript to the left.
142         int nker(BufferView const * bv) const;
143         /// where do we have to draw the scripts?
144         bool hasLimits() const;
145         /// clean up empty cells and return true if a cell has been deleted.
146         bool notifyCursorLeaves(Cursor const & old, Cursor & cur);
147
148         /// possible subscript (index 0) and superscript (index 1)
149         bool cell_1_is_up_;
150         /// 1 - "limits", -1 - "nolimits", 0 - "default"
151         int limits_;
152 };
153
154
155 } // namespace lyx
156
157 #endif