]> git.lyx.org Git - lyx.git/blob - src/mathed/MathData.h
* dimension.h: new operator!=() and operator=()
[lyx.git] / src / mathed / MathData.h
1 // -*- C++ -*-
2 /**
3  * \file MathData.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author André Pönitz
9  * \author Lars Gullik Bjønnes
10  *
11  * Full author contact details are available in file CREDITS.
12  */
13
14 #ifndef MATH_DATA_H
15 #define MATH_DATA_H
16
17 #include <vector>
18
19 #include "MathAtom.h"
20 #include "dimension.h"
21
22 #include "support/docstream.h"
23
24
25 namespace lyx {
26
27 class BufferView;
28 class LaTeXFeatures;
29 class ReplaceData;
30 class MetricsInfo;
31 class PainterInfo;
32 class TextMetricsInfo;
33 class TextPainter;
34
35
36 class MathArray : private std::vector<MathAtom> {
37 public:
38         /// re-use inhertited stuff
39         typedef std::vector<MathAtom> base_type;
40         using base_type::const_iterator;
41         using base_type::iterator;
42         using base_type::size_type;
43         using base_type::difference_type;
44         using base_type::size;
45         using base_type::empty;
46         using base_type::clear;
47         using base_type::begin;
48         using base_type::end;
49         using base_type::push_back;
50         using base_type::pop_back;
51         using base_type::back;
52         using base_type::front;
53         using base_type::swap;
54         ///
55         typedef size_type idx_type;
56         typedef size_type pos_type;
57
58 public:
59         ///
60         MathArray() {}
61         ///
62         MathArray(const_iterator from, const_iterator to);
63         ///
64         void append(MathArray const & ar);
65
66         /// inserts single atom at position pos
67         void insert(size_type pos, MathAtom const & at);
68         /// inserts multiple atoms at position pos
69         void insert(size_type pos, MathArray const & ar);
70
71         /// erase range from pos1 to pos2
72         void erase(iterator pos1, iterator pos2);
73         /// erase single atom
74         void erase(iterator pos);
75         /// erase range from pos1 to pos2
76         void erase(size_type pos1, size_type pos2);
77         /// erase single atom
78         void erase(size_type pos);
79
80         ///
81         void dump() const;
82         ///
83         void dump2() const;
84         ///
85         void replace(ReplaceData &);
86         ///
87         void substitute(MathArray const & m);
88
89         /// looks for exact match
90         bool match(MathArray const & ar) const;
91         /// looks for inclusion match starting at pos
92         bool matchpart(MathArray const & ar, pos_type pos) const;
93         /// looks for containment, return == size mean not found
94         size_type find(MathArray const & ar) const;
95         /// looks for containment, return == size mean not found
96         size_type find_last(MathArray const & ar) const;
97         ///
98         bool contains(MathArray const & ar) const;
99         ///
100         void validate(LaTeXFeatures &) const;
101
102         /// checked write access
103         MathAtom & operator[](pos_type);
104         /// checked read access
105         MathAtom const & operator[](pos_type) const;
106         /// rebuild cached metrics information
107         void metrics(MetricsInfo & mi) const;
108         /// rebuild cached metrics information
109         bool metrics(MetricsInfo & mi, Dimension & dim) const;
110         /// redraw cell using cache metrics information
111         void draw(PainterInfo & pi, int x, int y) const;
112         /// rebuild cached metrics information
113         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
114         /// redraw cell using cache metrics information
115         void drawT(TextPainter & pi, int x, int y) const;
116         /// mark cell for re-drawing
117         void touch() const;
118
119         /// access to cached x coordinate of last drawing
120         int xo(BufferView const & bv) const;
121         /// access to cached y coordinate of last drawing
122         int yo(BufferView const & bv) const;
123         /// access to cached x coordinate of mid point of last drawing
124         int xm(BufferView const & bv) const { return xo(bv) + dim_.wid / 2; }
125         /// access to cached y coordinate of mid point of last drawing
126         int ym(BufferView const & bv) const { return yo(bv) + (dim_.des - dim_.asc) / 2; }
127         /// write access to coordinate;
128         void setXY(BufferView & bv, int x, int y) const;
129         /// returns x coordinate of given position in the array
130         int pos2x(size_type pos) const;
131         /// returns position of given x coordinate
132         int pos2x(size_type pos, int glue) const;
133         /// returns position of given x coordinate
134         size_type x2pos(int pos) const;
135         /// returns position of given x coordinate fstarting from a certain pos
136         size_type x2pos(int targetx, int glue) const;
137         /// returns distance of this cell to the point given by x and y
138         // assumes valid position and size cache
139         int dist(BufferView const & bv, int x, int y) const;
140
141         /// ascent of this cell above the baseline
142         int ascent() const { return dim_.asc; }
143         /// descent of this cell below the baseline
144         int descent() const { return dim_.des; }
145         /// height of the cell
146         int height() const { return dim_.asc + dim_.des; }
147         /// width of this cell
148         int width() const { return dim_.wid; }
149         /// dimensions of cell
150         Dimension const & dim() const { return dim_; }
151         /// dimensions of cell
152         void setDim(Dimension const & d) const { dim_ = d; }
153
154 protected:
155         /// cached dimensions of cell
156         mutable Dimension dim_;
157
158 private:
159         /// is this an exact match at this position?
160         bool find1(MathArray const & ar, size_type pos) const;
161 };
162
163 ///
164 std::ostream & operator<<(std::ostream & os, MathArray const & ar);
165 ///
166 odocstream & operator<<(odocstream & os, MathArray const & ar);
167
168
169 } // namespace lyx
170
171 #endif