]> git.lyx.org Git - lyx.git/blob - src/mathed/math_atom.h
*** empty log message ***
[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         /// delete nucleus
90         void removeNucleus();
91         /// delete superscript
92         void removeUp();
93         /// delete subscript
94         void removeDown();
95         /// can we add a super- or subscript?
96         virtual bool allows(bool up) const { return script_[up] == 0; }
97         /// can we add a super- or subscript?
98         virtual bool allowsLimits() const { return true; }
99         /// set limits
100         void limits(int lim) { limits_ = lim; }
101         /// 
102         int limits() const { return limits_; }
103         ///
104         bool hasLimits() const;
105         /// true if we have an "inner" position
106         bool hasInner() const;
107         /// returns superscript
108         MathScriptInset * up() const;
109         /// returns subscript
110         MathScriptInset * down() const;
111         /// returns superscript
112         MathScriptInset * & up();
113         /// returns subscript
114         MathScriptInset * & down();
115         ///
116         MathInset * nucleus() const { return nucleus_; }
117         ///
118         MathInset * & nucleus() { return nucleus_; }
119         ///
120         void substitute(const MathMacro &);
121         ///
122         void write(std::ostream &, bool) const;
123         ///
124         void writeNormal(std::ostream &) const;
125         /// returns width of nucleus if any
126         int nwid() const;
127
128 protected:
129         /// possible subscript (index 0) and superscript (index 1)
130         MathScriptInset * script_[2]; 
131         ///
132         MathInset * nucleus_;
133         ///
134         int limits_;
135
136 private:
137         /// the following are used for positioning the cursor with the mouse
138         /// cached cursor start position in pixels from the document left
139         mutable int xo_;
140         /// cached cursor start position in pixels from the document top
141         mutable int yo_;
142
143         /// raw copy
144         void copy(MathAtom const & p);
145         /// raw destruction
146         void done();
147
148         /// returns y offset for superscript
149         int dy0() const;
150         /// returns y offset for subscript
151         int dy1() const;
152         /// returns x offset for main part
153         int dxx() const;
154         /// returns x offset for superscript
155         int dx0() const;
156         /// returns x offset for subscript
157         int dx1() const;
158         /// returns ascent of nucleus if any
159         int nasc() const;
160         /// returns descent of nucleus if any
161         int ndes() const;
162 };
163
164 std::ostream & operator<<(std::ostream &, MathAtom const &);
165
166 #endif