]> git.lyx.org Git - lyx.git/blob - src/mathed/math_data.h
small up/down tweaking
[lyx.git] / src / mathed / math_data.h
1 // -*- C++ -*-
2 /**
3  *   You are free to use and modify this code under the terms of
4  *   the GNU General Public Licence version 2 or later.
5  */
6
7 /** \class MathArray
8     \brief Low level container for math insets
9  *  \author Alejandro Aguilar Sierra
10  *  \author André Pönitz
11  *  \author Lars Gullik Bjønnes
12  *
13  * Full author contact details are available in file CREDITS
14     \version February 2001
15   */
16
17 #ifndef MATH_DATA_H
18 #define MATH_DATA_H
19
20 #include <iosfwd>
21 #include <vector>
22
23 #include "math_atom.h"
24 #include "dimension.h"
25
26 class MathMacro;
27 class LaTeXFeatures;
28 class ReplaceData;
29 class MathMetricsInfo;
30 class MathPainterInfo;
31 class TextMetricsInfo;
32 class TextPainter;
33
34
35 #ifdef __GNUG__
36 #pragma interface
37 #endif
38
39
40 class MathArray : private std::vector<MathAtom> {
41 public:
42         /// re-use inhertited stuff
43         typedef std::vector<MathAtom> base_type;
44         using base_type::const_iterator;
45         using base_type::iterator;
46         using base_type::size_type;
47         using base_type::difference_type;
48         using base_type::size;
49         using base_type::empty;
50         using base_type::clear;
51         using base_type::begin;
52         using base_type::end;
53         using base_type::push_back;
54         using base_type::pop_back;
55         using base_type::back;
56         using base_type::front;
57         using base_type::swap;
58         ///
59         typedef size_type idx_type;
60         typedef size_type pos_type;
61
62 public:
63         ///
64         MathArray();
65         ///
66         MathArray(const_iterator from, const_iterator to);
67         ///
68         void append(MathArray const & ar);
69
70         /// inserts single atom at position pos
71         void insert(size_type pos, MathAtom const & at);
72         /// inserts multiple atoms at position pos
73         void insert(size_type pos, MathArray const & ar);
74
75         /// erase range from pos1 to pos2
76         void erase(iterator pos1, iterator pos2);
77         /// erase single atom
78         void erase(iterator pos);
79         /// erase range from pos1 to pos2
80         void erase(size_type pos1, size_type pos2);
81         /// erase single atom
82         void erase(size_type pos);
83
84         ///
85         void dump() const;
86         ///
87         void dump2() const;
88         ///
89         void substitute(MathMacro const & macro);
90         ///
91         void replace(ReplaceData &);
92
93         /// looks for exact match
94         bool match(MathArray const & ar) const;
95         /// looks for inclusion match starting at pos
96         bool matchpart(MathArray const & ar, pos_type pos) const;
97         /// looks for containment, return == size mean not found
98         size_type find(MathArray const & ar) const;
99         /// looks for containment, return == size mean not found
100         size_type find_last(MathArray const & ar) const;
101         ///
102         bool contains(MathArray const & ar) const;
103         ///
104         void validate(LaTeXFeatures &) const;
105
106         /// checked write access
107         MathAtom & operator[](pos_type);
108         /// checked read access
109         MathAtom const & operator[](pos_type) const;
110         /// rebuild cached metrics information
111         Dimension const & metrics(MathMetricsInfo & mi) const;
112         /// redraw cell using cache metrics information
113         void draw(MathPainterInfo & pi, int x, int y) const;
114         /// rebuild cached metrics information
115         Dimension const & metricsT(TextMetricsInfo const & mi) const;
116         /// redraw cell using cache metrics information
117         void drawT(TextPainter & pi, int x, int y) const;
118         /// mark cell for re-drawing
119         void touch() const;
120
121         /// access to cached x coordinate of last drawing
122         int xo() const { return xo_; }
123         /// access to cached y coordinate of last drawing
124         int yo() const { return yo_; }
125         /// access to cached x coordinate of mid point of last drawing
126         int xm() const { return xo_ + dim_.w / 2; }
127         /// access to cached y coordinate of mid point of last drawing
128         int ym() const { return yo_ + (dim_.d - dim_.a) / 2; }
129         /// write access to coordinate;
130         void setXY(int x, int y) const;
131         /// returns x coordinate of given position in the array
132         int pos2x(size_type pos) const;
133         /// returns position of given x coordinate
134         int pos2x(size_type pos1, size_type pos2, int glue) const;
135         /// returns position of given x coordinate
136         size_type x2pos(int pos) const;
137         /// returns position of given x coordinate fstarting from a certain pos
138         size_type x2pos(size_type startpos, int targetx, int glue) const;
139         /// returns distance of this cell to the point given by x and y
140         // assumes valid position and size cache
141         int dist(int x, int y) const;
142
143         /// ascent of this cell above the baseline
144         int ascent() const { return dim_.a; }
145         /// descent of this cell below the baseline
146         int descent() const { return dim_.d; }
147         /// height of the cell
148         int height() const { return dim_.a + dim_.d; }
149         /// width of this cell
150         int width() const { return dim_.w; }
151         /// dimensions of cell
152         Dimension const & dim() const   { return dim_; }
153         /// dimensions of cell
154         void setDim(Dimension const & d) const { dim_ = d; }
155         /// bounding box of this cell
156         void boundingBox(int & xlow, int & xhigh, int & ylow, int & yhigh);
157         /// gives center coordinates
158         void center(int & x, int & y) const;
159         /// adjust (x,y) to point on boundary on a straight line from the center
160         void towards(int & x, int & y) const;
161         /// clean up if necessary
162         void notifyCursorLeaves();
163
164 private:
165         /// is this an exact match at this position?
166         bool find1(MathArray const & ar, size_type pos) const;
167
168         /// cached dimensions of cell
169         mutable Dimension dim_;
170         /// cached x coordinate of last drawing
171         mutable int xo_;
172         /// cached y coordinate of last drawing
173         mutable int yo_;
174         /// cached cleaness of cell
175         mutable bool clean_;
176         /// cached draw status of cell
177         mutable bool drawn_;
178 };
179
180 ///
181 std::ostream & operator<<(std::ostream & os, MathArray const & ar);
182
183
184 #endif