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