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