]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
Reduce Michael's buglist.
[lyx.git] / src / mathed / math_nestinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_nestinset.h"
6 #include "math_mathmlstream.h"
7 #include "debug.h"
8
9
10 MathNestInset::MathNestInset(idx_type nargs)
11         : MathDimInset(), cells_(nargs)
12 {}
13
14
15 MathInset::idx_type MathNestInset::nargs() const
16 {
17         return cells_.size();
18 }
19
20
21 MathXArray & MathNestInset::xcell(idx_type i)
22 {
23         return cells_[i];
24 }
25
26
27 MathXArray const & MathNestInset::xcell(idx_type i) const
28 {
29         return cells_[i];
30 }
31
32
33 MathArray & MathNestInset::cell(idx_type i)
34 {
35         return cells_[i].data_;
36 }
37
38
39 MathArray const & MathNestInset::cell(idx_type i) const
40 {
41         return cells_[i].data_;
42 }
43
44
45 void MathNestInset::substitute(MathMacro const & m)
46 {
47         for (idx_type i = 0; i < nargs(); ++i)
48                 cell(i).substitute(m);
49 }
50
51
52 void MathNestInset::metrics(MathMetricsInfo const & mi) const
53 {
54         for (idx_type i = 0; i < nargs(); ++i)
55                 xcell(i).metrics(mi);
56 }
57
58
59 void MathNestInset::draw(Painter & pain, int x, int y) const
60 {
61         for (idx_type i = 0; i < nargs(); ++i)
62                 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
63 }
64
65
66 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
67 {
68         if (idx + 1 >= nargs())
69                 return false;
70         ++idx;
71         pos = 0;
72         return true;
73 }
74
75
76 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
77 {
78         return idxNext(idx, pos);
79 }
80
81
82 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
83 {
84         if (idx == 0)
85                 return false;
86         --idx;
87         pos = cell(idx).size();
88         return true;
89 }
90
91
92 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
93 {
94         return idxPrev(idx, pos);
95 }
96
97
98 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
99 {
100         if (nargs() == 0)
101                 return false;
102         i = 0;
103         pos = 0;
104         return true;
105 }
106
107
108 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
109 {
110         if (nargs() == 0)
111                 return false;
112         i = nargs() - 1;
113         pos = cell(i).size();
114         return true;
115 }
116
117
118 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
119 {
120         if (pos == 0)
121                 return false;
122         pos = 0;
123         return true;
124 }
125
126
127 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
128 {
129         pos_type n = cell(idx).size();
130         if (pos == n)
131                 return false;
132         pos = n;
133         return true;
134 }
135
136
137 void MathNestInset::dump() const
138 {
139         WriteStream os(lyxerr);
140         os << "---------------------------------------------\n";
141         write(os);
142         os << "\n";
143         for (idx_type i = 0; i < nargs(); ++i)
144                 os << cell(i) << "\n";
145         os << "---------------------------------------------\n";
146 }
147
148
149 void MathNestInset::validate(LaTeXFeatures & features) const
150 {
151         for (idx_type i = 0; i < nargs(); ++i)
152                 cell(i).validate(features);
153 }
154
155
156 bool MathNestInset::covers(int x, int y) const
157 {
158         if (!nargs())
159                 return false;
160         int x0 = xcell(0).xo();
161         int y0 = xcell(0).yo() - xcell(0).ascent();
162         int x1 = xcell(0).xo() + xcell(0).width();
163         int y1 = xcell(0).yo() + xcell(0).descent();
164         for (idx_type i = 1; i < nargs(); ++i) {
165                 x0 = std::min(x0, xcell(i).xo());
166                 y0 = std::min(y0, xcell(i).yo() - xcell(i).ascent());
167                 x1 = std::max(x1, xcell(i).xo() + xcell(i).width());
168                 y1 = std::max(y1, xcell(i).yo() + xcell(i).descent());
169         }
170         //lyxerr << "xO: " << x0 << " x1: " << x1 << " "
171         //       << "yO: " << y0 << " y1: " << y1 <<  "         "
172         //       << "x: " << x << " y: " << y << '\n';
173         return x >= x0 && x <= x1 && y >= y0 && y <= y1;
174 }
175
176
177 bool MathNestInset::match(MathInset * p) const
178 {
179         if (nargs() != p->nargs())
180                 return false;
181         for (idx_type i = 0; i < nargs(); ++i)
182                 if (!cell(i).match(p->cell(i)))
183                         return false;
184         return true;
185 }
186
187
188 void MathNestInset::replace(ReplaceData & rep)
189 {
190         for (idx_type i = 0; i < nargs(); ++i)
191                 cell(i).replace(rep);
192 }