]> git.lyx.org Git - lyx.git/blob - src/mathed/MathData.h
make it compile again (hopefully)
[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 class BufferView;
25 class LaTeXFeatures;
26 class ReplaceData;
27 class MetricsInfo;
28 class PainterInfo;
29 class TextMetricsInfo;
30 class TextPainter;
31
32
33 class MathArray : private std::vector<MathAtom> {
34 public:
35         /// re-use inhertited stuff
36         typedef std::vector<MathAtom> base_type;
37         using base_type::const_iterator;
38         using base_type::iterator;
39         using base_type::size_type;
40         using base_type::difference_type;
41         using base_type::size;
42         using base_type::empty;
43         using base_type::clear;
44         using base_type::begin;
45         using base_type::end;
46         using base_type::push_back;
47         using base_type::pop_back;
48         using base_type::back;
49         using base_type::front;
50         using base_type::swap;
51         ///
52         typedef size_type idx_type;
53         typedef size_type pos_type;
54
55 public:
56         ///
57         MathArray();
58         ///
59         MathArray(const_iterator from, const_iterator to);
60         ///
61         void append(MathArray const & ar);
62
63         /// inserts single atom at position pos
64         void insert(size_type pos, MathAtom const & at);
65         /// inserts multiple atoms at position pos
66         void insert(size_type pos, MathArray const & ar);
67
68         /// erase range from pos1 to pos2
69         void erase(iterator pos1, iterator pos2);
70         /// erase single atom
71         void erase(iterator pos);
72         /// erase range from pos1 to pos2
73         void erase(size_type pos1, size_type pos2);
74         /// erase single atom
75         void erase(size_type pos);
76
77         ///
78         void dump() const;
79         ///
80         void dump2() const;
81         ///
82         void replace(ReplaceData &);
83         ///
84         void substitute(MathArray const & m);
85
86         /// looks for exact match
87         bool match(MathArray const & ar) const;
88         /// looks for inclusion match starting at pos
89         bool matchpart(MathArray const & ar, pos_type pos) const;
90         /// looks for containment, return == size mean not found
91         size_type find(MathArray const & ar) const;
92         /// looks for containment, return == size mean not found
93         size_type find_last(MathArray const & ar) const;
94         ///
95         bool contains(MathArray const & ar) const;
96         ///
97         void validate(LaTeXFeatures &) const;
98
99         /// checked write access
100         MathAtom & operator[](pos_type);
101         /// checked read access
102         MathAtom const & operator[](pos_type) const;
103         /// rebuild cached metrics information
104         void metrics(MetricsInfo & mi) const;
105         /// rebuild cached metrics information
106         void metrics(MetricsInfo & mi, Dimension & dim) const;
107         /// redraw cell using cache metrics information
108         void draw(PainterInfo & pi, int x, int y) const;
109         /// rebuild cached metrics information
110         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
111         /// redraw cell using cache metrics information
112         void drawT(TextPainter & pi, int x, int y) const;
113         /// mark cell for re-drawing
114         void touch() const;
115
116         /// access to cached x coordinate of last drawing
117         int xo(BufferView & bv) const;
118         /// access to cached y coordinate of last drawing
119         int yo(BufferView & bv) const;
120         /// access to cached x coordinate of mid point of last drawing
121         int xm(BufferView & bv) const { return xo(bv) + dim_.wid / 2; }
122         /// access to cached y coordinate of mid point of last drawing
123         int ym(BufferView & bv) const { return yo(bv) + (dim_.des - dim_.asc) / 2; }
124         /// write access to coordinate;
125         void setXY(BufferView & bv, int x, int y) const;
126         /// returns x coordinate of given position in the array
127         int pos2x(size_type pos) const;
128         /// returns position of given x coordinate
129         int pos2x(size_type pos, int glue) const;
130         /// returns position of given x coordinate
131         size_type x2pos(int pos) const;
132         /// returns position of given x coordinate fstarting from a certain pos
133         size_type x2pos(int targetx, int glue) const;
134         /// returns distance of this cell to the point given by x and y
135         // assumes valid position and size cache
136         int dist(BufferView & bv, int x, int y) const;
137
138         /// ascent of this cell above the baseline
139         int ascent() const { return dim_.asc; }
140         /// descent of this cell below the baseline
141         int descent() const { return dim_.des; }
142         /// height of the cell
143         int height() const { return dim_.asc + dim_.des; }
144         /// width of this cell
145         int width() const { return dim_.wid; }
146         /// dimensions of cell
147         Dimension const & dim() const { return dim_; }
148         /// dimensions of cell
149         void setDim(Dimension const & d) const { dim_ = d; }
150
151 private:
152         /// is this an exact match at this position?
153         bool find1(MathArray const & ar, size_type pos) const;
154
155         /// cached dimensions of cell
156         mutable Dimension dim_;
157 };
158
159 ///
160 std::ostream & operator<<(std::ostream & os, MathArray const & ar);
161 ///
162 lyx::odocstream & operator<<(lyx::odocstream & os, MathArray const & ar);
163
164
165 #endif