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