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