]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
ebe624c0447830962a2ce9e4a4532726961ccbb6
[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         array.push_back(clone());
47         for (int i = 0; i < nargs(); ++i)
48                 array.back()->cell(i).substitute(m);
49 }
50
51
52 void MathNestInset::metrics(MathStyles st) const
53 {
54         size_ = st;
55         for (int i = 0; i < nargs(); ++i)
56                 xcell(i).metrics(st);
57 }
58
59
60 void MathNestInset::draw(Painter & pain, int x, int y) const
61 {
62         xo(x);
63         yo(y);
64         for (int i = 0; i < nargs(); ++i)
65                 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
66 }
67
68
69 bool MathNestInset::idxNext(int & idx, int & pos) const
70 {
71         if (idx + 1 >= nargs())
72                 return false;
73         ++idx;
74         pos = 0;
75         return true;
76 }
77
78
79 bool MathNestInset::idxRight(int & idx, int & pos) const
80 {
81         return idxNext(idx, pos);
82 }
83
84
85 bool MathNestInset::idxPrev(int & idx, int & pos) const
86 {
87         if (idx == 0)
88                 return false;
89         --idx;
90         pos = cell(idx).size();
91         return true;
92 }
93
94
95 bool MathNestInset::idxLeft(int & idx, int & pos) const
96 {
97         return idxPrev(idx, pos);
98 }
99
100
101 bool MathNestInset::idxFirst(int & i, int & pos) const
102 {
103         if (nargs() == 0)
104                 return false;
105         i = 0;
106         pos = 0;
107         return true;
108 }
109
110
111 bool MathNestInset::idxLast(int & i, int & pos) const
112 {
113         if (nargs() == 0)
114                 return false;
115         i = nargs() - 1;
116         pos = cell(i).size();
117         return true;
118 }
119
120
121 bool MathNestInset::idxHome(int & /* idx */, int & pos) const
122 {
123         if (pos == 0)
124                 return false;
125         pos = 0;
126         return true;
127 }
128
129
130 bool MathNestInset::idxEnd(int & idx, int & pos) const
131 {
132         if (pos == cell(idx).size())
133                 return false;
134
135         pos = cell(idx).size();
136         return true;
137 }
138
139
140 void MathNestInset::dump() const
141 {
142         lyxerr << "---------------------------------------------\n";
143         write(lyxerr, false);
144         lyxerr << "\n";
145         for (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 (int i = 0; i < nargs(); ++i)
163                 cell(i).validate(features);
164 }