]> git.lyx.org Git - lyx.git/blob - src/mathed/math_scriptinset.h
first shot at preview. It crashes. Don't know why. To see it work a bit, change
[lyx.git] / src / mathed / math_scriptinset.h
1 // -*- C++ -*-
2 #ifndef MATH_SCRIPTINSET_H
3 #define MATH_SCRIPTINSET_H
4
5 #include "math_nestinset.h"
6
7 #ifdef __GNUG__
8 #pragma interface
9 #endif
10
11 /** Inset for super- and subscripts
12     \author André Pönitz
13  */
14
15 class MathScriptInset : public MathNestInset {
16 public:
17         /// create inset without scripts
18         MathScriptInset();
19         /// create inset with single script
20         explicit MathScriptInset(bool up);
21         ///
22         MathInset * clone() const;
23         ///
24         void write(WriteStream & os) const;
25         ///
26         void normalize(NormalStream & os) const;
27         ///
28         void metrics(MathMetricsInfo & st) const;
29         ///
30         void draw(MathPainterInfo &, int x, int y) const;
31         ///
32         void metricsT(TextMetricsInfo const & st) const;
33         ///
34         void drawT(TextPainter &, int x, int y) const;
35
36         ///
37         void metrics(MathInset const * nuc, MathMetricsInfo & st) const;
38         ///
39         void draw(MathInset const * nuc, MathPainterInfo &, int x, int y) const;
40         ///
41         void metricsT(MathInset const * nuc, TextMetricsInfo const & st) const;
42         ///
43         void drawT(MathInset const * nuc, TextPainter &, int x, int y) const;
44         ///
45         int ascent2(MathInset const * nuc) const;
46         ///
47         int descent2(MathInset const * nuc) const;
48         ///
49         int width2(MathInset const * nuc) const;
50
51         ///
52         bool idxLeft(idx_type &, pos_type &) const;
53         ///
54         bool idxRight(idx_type &, pos_type &) const;
55         /// can we enter this cell?
56         bool validCell(idx_type i) const { return script_[i]; }
57
58         /// identifies scriptinsets
59         MathScriptInset const * asScriptInset() const;
60         ///
61         MathScriptInset * asScriptInset();
62
63         /// set limits
64         void limits(int lim) { limits_ = lim; }
65         /// get limits
66         int limits() const { return limits_; }
67         /// true if we have an "inner" position
68         MathXArray const & up() const;
69         /// returns subscript
70         MathXArray const & down() const;
71         /// returns superscript
72         MathXArray & up();
73         /// returns subscript
74         MathXArray & down();
75         /// do we have a superscript?
76         bool hasUp() const;
77         /// do we have a subscript?
78         bool hasDown() const;
79         /// do we have a script?
80         bool has(bool up) const;
81         /// do we have a anything?
82         bool empty() const;
83         /// remove script
84         void removeScript(bool up);
85         /// remove script
86         void removeEmptyScripts();
87         /// make sure a script is accessible
88         void ensure(bool up);
89
90         // call these methods ...2 to make compaq cxx in anal mode happy...
91         /// suppresses empty braces if necessary
92         virtual void write2(MathInset const * nuc, WriteStream & os) const;
93         virtual void normalize2(MathInset const * nuc, NormalStream & os) const;
94         virtual void octavize2(MathInset const * nuc, OctaveStream & os) const;
95         virtual void maplize2(MathInset const * nuc, MapleStream & os) const;
96         virtual void mathmlize2(MathInset const * nuc, MathMLStream & os) const;
97
98 public:
99         /// returns x offset for main part
100         int dxx(MathInset const * nuc) const;
101         /// returns width of nucleus if any
102         int nwid(MathInset const * nuc) const;
103 private:
104         /// returns y offset for superscript
105         int dy0(MathInset const * nuc) const;
106         /// returns y offset for subscript
107         int dy1(MathInset const * nuc) const;
108         /// returns x offset for superscript
109         int dx0(MathInset const * nuc) const;
110         /// returns x offset for subscript
111         int dx1(MathInset const * nuc) const;
112         /// returns ascent of nucleus if any
113         int nasc(MathInset const * nuc) const;
114         /// returns descent of nucleus if any
115         int ndes(MathInset const * nuc) const;
116         /// where do we have to draw the scripts?
117         bool hasLimits(MathInset const * nuc) const;
118
119         /// possible subscript (index 0) and superscript (index 1)
120         bool script_[2];
121         /// 1 - "limits", -1 - "nolimits", 0 - "default"
122         int limits_;
123         /// cached font
124         mutable LyXFont font_;
125 };
126
127 #endif