]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
whichFont down to 5.3%
[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)
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 void MathNestInset::draw(Painter & pain, int x, int y) const
65 {
66         for (idx_type i = 0; i < nargs(); ++i)
67                 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
68 }
69
70
71 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
72 {
73         if (idx + 1 >= nargs())
74                 return false;
75         ++idx;
76         pos = 0;
77         return true;
78 }
79
80
81 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
82 {
83         return idxNext(idx, pos);
84 }
85
86
87 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
88 {
89         if (idx == 0)
90                 return false;
91         --idx;
92         pos = cell(idx).size();
93         return true;
94 }
95
96
97 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
98 {
99         return idxPrev(idx, pos);
100 }
101
102
103 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
104 {
105         if (nargs() == 0)
106                 return false;
107         i = 0;
108         pos = 0;
109         return true;
110 }
111
112
113 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
114 {
115         if (nargs() == 0)
116                 return false;
117         i = nargs() - 1;
118         pos = cell(i).size();
119         return true;
120 }
121
122
123 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
124 {
125         if (pos == 0)
126                 return false;
127         pos = 0;
128         return true;
129 }
130
131
132 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
133 {
134         pos_type n = cell(idx).size();
135         if (pos == n)
136                 return false;
137         pos = n;
138         return true;
139 }
140
141
142 void MathNestInset::dump() const
143 {
144         WriteStream os(lyxerr);
145         os << "---------------------------------------------\n";
146         write(os);
147         os << "\n";
148         for (idx_type i = 0; i < nargs(); ++i)
149                 os << cell(i) << "\n";
150         os << "---------------------------------------------\n";
151 }
152
153
154 void MathNestInset::validate(LaTeXFeatures & features) const
155 {
156         for (idx_type i = 0; i < nargs(); ++i)
157                 cell(i).validate(features);
158 }
159
160
161 bool MathNestInset::match(MathInset * p) const
162 {
163         if (nargs() != p->nargs())
164                 return false;
165         for (idx_type i = 0; i < nargs(); ++i)
166                 if (!cell(i).match(p->cell(i)))
167                         return false;
168         return true;
169 }
170
171
172 void MathNestInset::replace(ReplaceData & rep)
173 {
174         for (idx_type i = 0; i < nargs(); ++i)
175                 cell(i).replace(rep);
176 }
177
178
179 bool MathNestInset::contains(MathArray const & ar)
180 {
181         for (idx_type i = 0; i < nargs(); ++i)
182                 if (cell(i).contains(ar))
183                         return true;
184         return false;
185 }
186
187
188 bool MathNestInset::editing() const
189 {
190         return mathcursor && mathcursor->isInside(this);
191 }
192