]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
try to fix rounding errors
[lyx.git] / src / mathed / math_nestinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_nestinset.h"
6 #include "math_cursor.h"
7 #include "math_mathmlstream.h"
8 #include "debug.h"
9
10
11 MathNestInset::MathNestInset(idx_type nargs)
12         : MathDimInset(), cells_(nargs), lock_(false)
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         MathMetricsInfo m = mi;
56         m.inset = this;
57         for (idx_type i = 0; i < nargs(); ++i) {
58                 m.idx = i;
59                 xcell(i).metrics(m);
60         }
61 }
62
63
64 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
65 {
66         if (idx + 1 >= nargs())
67                 return false;
68         ++idx;
69         pos = 0;
70         return true;
71 }
72
73
74 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
75 {
76         return idxNext(idx, pos);
77 }
78
79
80 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
81 {
82         if (idx == 0)
83                 return false;
84         --idx;
85         pos = cell(idx).size();
86         return true;
87 }
88
89
90 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
91 {
92         return idxPrev(idx, pos);
93 }
94
95
96 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
97 {
98         if (nargs() == 0)
99                 return false;
100         i = 0;
101         pos = 0;
102         return true;
103 }
104
105
106 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
107 {
108         if (nargs() == 0)
109                 return false;
110         i = nargs() - 1;
111         pos = cell(i).size();
112         return true;
113 }
114
115
116 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
117 {
118         if (pos == 0)
119                 return false;
120         pos = 0;
121         return true;
122 }
123
124
125 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
126 {
127         pos_type n = cell(idx).size();
128         if (pos == n)
129                 return false;
130         pos = n;
131         return true;
132 }
133
134
135 void MathNestInset::dump() const
136 {
137         WriteStream os(lyxerr);
138         os << "---------------------------------------------\n";
139         write(os);
140         os << "\n";
141         for (idx_type i = 0; i < nargs(); ++i)
142                 os << cell(i) << "\n";
143         os << "---------------------------------------------\n";
144 }
145
146
147 void MathNestInset::validate(LaTeXFeatures & features) const
148 {
149         for (idx_type i = 0; i < nargs(); ++i)
150                 cell(i).validate(features);
151 }
152
153
154 bool MathNestInset::match(MathInset * p) const
155 {
156         if (nargs() != p->nargs())
157                 return false;
158         for (idx_type i = 0; i < nargs(); ++i)
159                 if (!cell(i).match(p->cell(i)))
160                         return false;
161         return true;
162 }
163
164
165 void MathNestInset::replace(ReplaceData & rep)
166 {
167         for (idx_type i = 0; i < nargs(); ++i)
168                 cell(i).replace(rep);
169 }
170
171
172 bool MathNestInset::contains(MathArray const & ar)
173 {
174         for (idx_type i = 0; i < nargs(); ++i)
175                 if (cell(i).contains(ar))
176                         return true;
177         return false;
178 }
179
180
181 bool MathNestInset::editing() const
182 {
183         return mathcursor && mathcursor->isInside(this);
184 }
185
186
187 bool MathNestInset::lock() const
188 {
189         return lock_;
190 }
191
192
193 void MathNestInset::lock(bool l)
194 {
195         lock_ = l;
196 }
197
198
199 bool MathNestInset::isActive() const
200 {
201         return !lock_ && nargs() > 0;
202 }