]> git.lyx.org Git - lyx.git/blob - src/mathed/math_atom.h
try to do with super- and subscripts what TeX does
[lyx.git] / src / mathed / math_atom.h
1 // -*- C++ -*-
2
3 #ifndef MATH_ATOM_H
4 #define MATH_ATOM_H
5
6 #include <config.h>
7 #include <iosfwd>
8
9 #ifdef __GNUG__
10 #pragma interface
11 #endif
12
13 #include "math_defs.h"
14
15 /** 
16 The 'atom' is the major blob in math typesetting.  And 'atom' consists
17 of a nucleus, an optional superscript, and an optional subscript.
18
19 Exactly where the subscript and superscript are drawn depends on the
20 size, and type, of the nucleus they are attached to.  
21
22 Jules
23 */
24
25 class LaTeXFeatures;
26 class MathCharInset;
27 class MathScriptInset;
28 class MathInset;
29 class MathMacro;
30 class MathArray;
31 class Painter;
32
33 class MathAtom {
34 public: 
35         ///
36         MathAtom();
37         ///
38         MathAtom(MathAtom const &);
39         ///
40         explicit MathAtom(MathInset * p);
41         /// 
42         virtual ~MathAtom(); 
43         ///
44         void operator=(MathAtom const &);
45         ///
46         void swap(MathAtom &);
47
48         /// draw the object, sets xo_ and yo_ cached values 
49         virtual void draw(Painter &, int x, int y) const;
50         /// reproduce itself
51         void metrics(MathStyles st) const;
52         /// 
53         int ascent() const;
54         ///
55         int descent() const;
56         ///
57         int width() const;
58         ///
59         int height() const;
60
61         ///
62         int xo() const;
63         ///
64         int yo() const;
65         ///
66         void xo(int tx) const;
67         ///
68         void yo(int ty) const;
69         ///
70
71         ///
72         void getXY(int & x, int & y) const;
73         ///
74         bool covers(int x, int y) const;
75
76         ///
77         void dump() const;
78         ///
79         void validate(LaTeXFeatures & features) const;
80         ///
81         void handleFont(MathTextCodes) {}
82
83         /// make sure superscript is available
84         MathScriptInset * ensure(bool up);
85         /// delete subscript array if empty
86         void removeEmptyScripts();
87         /// can we add a super- or subscript?
88         virtual bool allows(bool up) const { return script_[up] == 0; }
89         /// can we add a super- or subscript?
90         virtual bool allowsLimits() const { return true; }
91         /// set limits
92         void limits(int lim) { limits_ = lim; }
93         /// 
94         int limits() const { return limits_; }
95         ///
96         bool hasLimits() const;
97         /// returns superscript
98         MathScriptInset * up() const;
99         /// returns subscript
100         MathScriptInset * down() const;
101         ///
102         MathInset * nucleus() const { return nucleus_; }
103         ///
104         void substitute(MathArray &, const MathMacro &) const;
105         ///
106         void write(std::ostream &, bool) const;
107         ///
108         void writeNormal(std::ostream &) const;
109
110 protected:
111         /// possible subscript (index 0) and superscript (index 1)
112         MathScriptInset * script_[2]; 
113         ///
114         MathInset * nucleus_;
115         ///
116         int limits_;
117
118 private:
119         /// the following are used for positioning the cursor with the mouse
120         /// cached cursor start position in pixels from the document left
121         mutable int xo_;
122         /// cached cursor start position in pixels from the document top
123         mutable int yo_;
124
125         /// raw copy
126         void copy(MathAtom const & p);
127         /// raw destruction
128         void done();
129
130         /// returns y offset for superscript
131         int dy0() const;
132         /// returns y offset for subscript
133         int dy1() const;
134         /// returns x offset for superscript
135         int dx0() const;
136         /// returns x offset for subscript
137         int dx1() const;
138         /// returns x offset for main part
139         int dxx() const;
140         /// returns width of nucleus if any
141         int nwid() const;
142         /// returns ascent of nucleus if any
143         int nasc() const;
144         /// returns descent of nucleus if any
145         int ndes() const;
146 };
147
148 std::ostream & operator<<(std::ostream &, MathAtom const &);
149
150 #endif