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