]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
- updated BUGS
[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         xo(x);
61         yo(y);
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 }