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