]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathScript.h
Move several common types to support/types.h
[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         explicit 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 override { return MATH_MODE; }
35         ///
36         MathClass mathClass() const override;
37         ///
38         void metrics(MetricsInfo & mi, Dimension & dim) const override;
39         ///
40         void draw(PainterInfo & pi, int x, int y) const override;
41         ///
42         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const override;
43         ///
44         void drawT(TextPainter & pi, int x, int y) const override;
45
46         /// move cursor backwards
47         bool idxBackward(Cursor & cur) const override;
48         /// move cursor forward
49         bool idxForward(Cursor & cur) const override;
50         /// move cursor up or down
51         bool idxUpDown(Cursor & cur, bool up) const override;
52         /// The index of the cell entered while moving backward
53         size_type lastIdx() const override { return 0; }
54
55         /// write LaTeX and Lyx code
56         void write(WriteStream & os) const override;
57         /// write normalized content
58         void normalize(NormalStream &) const override;
59         /// write content as something readable by Maple
60         void maple(MapleStream &) const override;
61         /// write content as something readable by Mathematica
62         void mathematica(MathematicaStream &) const override;
63         /// write content as MathML
64         void mathmlize(MathStream &) const override;
65         /// write content as HTML
66         void htmlize(HtmlStream &) const override;
67         /// write content as something readable by Octave
68         void octave(OctaveStream &) const override;
69
70         /// identifies scriptinsets
71         InsetMathScript const * asScriptInset() const override;
72         ///
73         InsetMathScript * asScriptInset() override;
74
75         /// returns subscript. Always run 'hasDown' or 'has(false)' before!
76         MathData const & down() const;
77         /// returns subscript. Always run 'hasDown' or 'has(false)' before!
78         MathData & down();
79         /// returns superscript. Always run 'hasUp' or 'has(true)' before!
80         MathData const & up() const;
81         /// returns superscript. Always run 'hasUp' or 'has(true)' before!
82         MathData & up();
83         /// returns nucleus
84         MathData const & nuc() const;
85         /// returns nucleus
86         MathData & nuc();
87         /// do we have a superscript?
88         bool hasUp() const;
89         /// do we have a subscript?
90         bool hasDown() const;
91         /// do we have a script?
92         bool has(bool up) const;
93         /// what idx has super/subscript?
94         idx_type idxOfScript(bool up) const;
95         /// remove script
96         void removeScript(bool up);
97         /// make sure a script is accessible
98         void ensure(bool up);
99         /// say that we have scripts
100         void infoize(odocstream & os) const override;
101         /// say whether we have displayed limits
102         void infoize2(odocstream & os) const override;
103         ///
104         InsetCode lyxCode() const override { return MATH_SCRIPT_CODE; }
105         ///
106         void validate(LaTeXFeatures &features) const override;
107 private:
108         Inset * clone() const override;
109         /// returns x offset for main part
110         int dxx(BufferView const & bv) const;
111         /// returns width of nucleus if any
112         int nwid(BufferView const &) const;
113         /// returns y offset for either superscript or subscript
114         int dy01(BufferView const &, int asc, int des, int what) const;
115         /// returns y offset for superscript
116         int dy0(BufferView const &) const;
117         /// returns y offset for subscript
118         int dy1(BufferView const &) const;
119         /// returns x offset for superscript
120         int dx0(BufferView const & bv) const;
121         /// returns x offset for subscript
122         int dx1(BufferView const & bv) const;
123         /// returns ascent of nucleus if any
124         int nasc(BufferView const &) const;
125         /// returns descent of nucleus if any
126         int ndes(BufferView const &) const;
127         /// Italic correction: amount of displacement between subscript and
128         /// superscript in math mode as per Appendix G, rule 18f.  A positive value
129         /// shifts the superscript to the right, and a negative value shifts the
130         /// subscript to the left.
131         int nker(BufferView const * bv) const;
132         /// do we we have to draw the scripts above/below nucleus?
133         bool hasLimits(FontInfo const &) const;
134         /// clean up empty cells and return true if a cell has been deleted.
135         bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
136
137         /// possible subscript (index 0) and superscript (index 1)
138         bool cell_1_is_up_;
139         /// remember whether we are in display mode (used by mathml output)
140         mutable bool has_limits_ = false;
141 };
142
143
144 } // namespace lyx
145
146 #endif