]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
3d1de5e64eda6427c324cef853ba2af916ae013e
[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(MathMacro const & m)
45 {
46         for (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 (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 (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(int & idx, 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(int & idx, int & pos) const
79 {
80         return idxNext(idx, pos);
81 }
82
83
84 bool MathNestInset::idxPrev(int & idx, 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(int & idx, int & pos) const
95 {
96         return idxPrev(idx, pos);
97 }
98
99
100 bool MathNestInset::idxFirst(int & i, 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(int & i, 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(int & /* idx */, int & pos) const
121 {
122         if (pos == 0)
123                 return false;
124         pos = 0;
125         return true;
126 }
127
128
129 bool MathNestInset::idxEnd(int & idx, int & pos) const
130 {
131         if (pos == cell(idx).size())
132                 return false;
133
134         pos = cell(idx).size();
135         return true;
136 }
137
138
139 void MathNestInset::dump() const
140 {
141         lyxerr << "---------------------------------------------\n";
142         write(lyxerr, false);
143         lyxerr << "\n";
144         for (int i = 0; i < nargs(); ++i)
145                 lyxerr << cell(i) << "\n";
146         lyxerr << "---------------------------------------------\n";
147 }
148
149
150 void MathNestInset::push_back(MathInset * p)
151 {
152         if (nargs())
153                 cells_.back().data_.push_back(p);
154         else
155                 lyxerr << "can't push without a cell\n";
156 }
157
158
159 void MathNestInset::validate(LaTeXFeatures & features) const
160 {
161         for (int i = 0; i < nargs(); ++i)
162                 cell(i).validate(features);
163 }