]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
aed935a19fa9d88f99c600eb95d4e661796405c5
[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, string const & name)
10         : MathInset(name), 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         MathNestInset * p = static_cast<MathNestInset *>(clone());
47         for (int i = 0; i < nargs(); ++i)
48                 p->cell(i).substitute(m);
49         array.push_back(p);
50 }
51
52
53 void MathNestInset::metrics(MathStyles st)
54 {
55         size_ = st;
56         for (int i = 0; i < nargs(); ++i)
57                 xcell(i).metrics(st);
58 }
59
60
61 void MathNestInset::draw(Painter & pain, int x, int y)
62 {
63         xo(x);
64         yo(y);
65         for (int i = 0; i < nargs(); ++i)
66                 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
67 }
68
69
70 bool MathNestInset::idxNext(int & idx, int & pos) const
71 {
72         if (idx + 1 >= nargs())
73                 return false;
74         ++idx;
75         pos = 0;
76         return true;
77 }
78
79
80 bool MathNestInset::idxRight(int & idx, int & pos) const
81 {
82         return idxNext(idx, pos);
83 }
84
85
86 bool MathNestInset::idxPrev(int & idx, int & pos) const
87 {
88         if (idx == 0)
89                 return false;
90         --idx;
91         pos = cell(idx).size();
92         return true;
93 }
94
95
96 bool MathNestInset::idxLeft(int & idx, int & pos) const
97 {
98         return idxPrev(idx, pos);
99 }
100
101
102 bool MathNestInset::idxFirst(int & i, int & pos) const
103 {
104         if (nargs() == 0)
105                 return false;
106         i = 0;
107         pos = 0;
108         return true;
109 }
110
111
112 bool MathNestInset::idxLast(int & i, int & pos) const
113 {
114         if (nargs() == 0)
115                 return false;
116         i = nargs() - 1;
117         pos = cell(i).size();
118         return true;
119 }
120
121
122 bool MathNestInset::idxHome(int & /* idx */, int & pos) const
123 {
124         if (pos == 0)
125                 return false;
126         pos = 0;
127         return true;
128 }
129
130
131 bool MathNestInset::idxEnd(int & idx, int & pos) const
132 {
133         if (pos == cell(idx).size())
134                 return false;
135
136         pos = cell(idx).size();
137         return true;
138 }
139
140
141 void MathNestInset::dump() const
142 {
143         lyxerr << "---------------------------------------------\n";
144         write(lyxerr, false);
145         lyxerr << "\n";
146         for (int i = 0; i < nargs(); ++i)
147                 lyxerr << cell(i) << "\n";
148         lyxerr << "---------------------------------------------\n";
149 }
150
151
152 void MathNestInset::push_back(unsigned char ch, MathTextCodes fcode)
153 {
154         if (nargs())
155                 cells_.back().data_.push_back(ch, fcode);
156         else
157                 lyxerr << "can't push without a cell\n";
158 }
159
160
161 void MathNestInset::push_back(MathInset * p)
162 {
163         if (nargs())
164                 cells_.back().data_.push_back(p);
165         else
166                 lyxerr << "can't push without a cell\n";
167 }
168
169
170 void MathNestInset::validate(LaTeXFeatures & features) const
171 {
172         for (int i = 0; i < nargs(); ++i)
173                 cell(i).validate(features);
174 }