]> git.lyx.org Git - lyx.git/blob - src/mathed/math_atom.h
changed cursor movement/deletion behaviour in super/subscripts
[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         MathAtom(MathInset * p, MathScriptInset * up, MathScriptInset * down);
43         /// 
44         virtual ~MathAtom(); 
45         ///
46         void operator=(MathAtom const &);
47         ///
48         void swap(MathAtom &);
49
50         /// draw the object, sets xo_ and yo_ cached values 
51         virtual void draw(Painter &, int x, int y) const;
52         /// reproduce itself
53         void metrics(MathStyles st) const;
54         /// 
55         int ascent() const;
56         ///
57         int descent() const;
58         ///
59         int width() const;
60         ///
61         int height() const;
62
63         ///
64         int xo() const;
65         ///
66         int yo() const;
67         ///
68         void xo(int tx) const;
69         ///
70         void yo(int ty) const;
71         ///
72
73         ///
74         void getXY(int & x, int & y) const;
75         ///
76         bool covers(int x, int y) const;
77
78         ///
79         void dump() const;
80         ///
81         void validate(LaTeXFeatures & features) const;
82         ///
83         void handleFont(MathTextCodes) {}
84
85         /// make sure superscript is available
86         MathScriptInset * ensure(bool up);
87         /// delete subscript array if empty
88         void removeEmptyScripts();
89         /// can we add a super- or subscript?
90         virtual bool allows(bool up) const { return script_[up] == 0; }
91         /// can we add a super- or subscript?
92         virtual bool allowsLimits() const { return true; }
93         /// set limits
94         void limits(int lim) { limits_ = lim; }
95         /// 
96         int limits() const { return limits_; }
97         ///
98         bool hasLimits() const;
99         /// returns superscript
100         MathScriptInset * up() const;
101         /// returns subscript
102         MathScriptInset * down() const;
103         /// returns superscript
104         MathScriptInset * & up();
105         /// returns subscript
106         MathScriptInset * & down();
107         ///
108         MathInset * nucleus() const { return nucleus_; }
109         ///
110         void substitute(const MathMacro &);
111         ///
112         void write(std::ostream &, bool) const;
113         ///
114         void writeNormal(std::ostream &) const;
115
116 protected:
117         /// possible subscript (index 0) and superscript (index 1)
118         MathScriptInset * script_[2]; 
119         ///
120         MathInset * nucleus_;
121         ///
122         int limits_;
123
124 private:
125         /// the following are used for positioning the cursor with the mouse
126         /// cached cursor start position in pixels from the document left
127         mutable int xo_;
128         /// cached cursor start position in pixels from the document top
129         mutable int yo_;
130
131         /// raw copy
132         void copy(MathAtom const & p);
133         /// raw destruction
134         void done();
135
136         /// returns y offset for superscript
137         int dy0() const;
138         /// returns y offset for subscript
139         int dy1() const;
140         /// returns x offset for superscript
141         int dx0() const;
142         /// returns x offset for subscript
143         int dx1() const;
144         /// returns x offset for main part
145         int dxx() const;
146         /// returns width of nucleus if any
147         int nwid() const;
148         /// returns ascent of nucleus if any
149         int nasc() const;
150         /// returns descent of nucleus if any
151         int ndes() const;
152 };
153
154 std::ostream & operator<<(std::ostream &, MathAtom const &);
155
156 #endif