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