]> git.lyx.org Git - lyx.git/blob - src/mathed/math_nestinset.C
make \newcommand{\bb}[1]{\mathbf{#1}} work for read/write/display.
[lyx.git] / src / mathed / math_nestinset.C
1 #ifdef __GNUG__
2 #pragma implementation
3 #endif
4
5 #include "math_nestinset.h"
6 #include "math_mathmlstream.h"
7 #include "debug.h"
8
9
10 MathNestInset::MathNestInset(idx_type nargs)
11         : MathDimInset(), cells_(nargs)
12 {}
13
14
15 MathInset::idx_type MathNestInset::nargs() const
16 {
17         return cells_.size();
18 }
19
20
21 MathXArray & MathNestInset::xcell(idx_type i)
22 {
23         return cells_[i];
24 }
25
26
27 MathXArray const & MathNestInset::xcell(idx_type i) const
28 {
29         return cells_[i];
30 }
31
32
33 MathArray & MathNestInset::cell(idx_type i)
34 {
35         return cells_[i].data_;
36 }
37
38
39 MathArray const & MathNestInset::cell(idx_type i) const
40 {
41         return cells_[i].data_;
42 }
43
44
45 void MathNestInset::substitute(MathMacro const & m)
46 {
47         for (idx_type i = 0; i < nargs(); ++i)
48                 cell(i).substitute(m);
49 }
50
51
52 void MathNestInset::metrics(MathMetricsInfo const & mi) const
53 {
54         for (idx_type i = 0; i < nargs(); ++i)
55                 xcell(i).metrics(mi);
56 }
57
58
59 void MathNestInset::draw(Painter & pain, int x, int y) const
60 {
61         for (idx_type i = 0; i < nargs(); ++i)
62                 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
63 }
64
65
66 bool MathNestInset::idxNext(idx_type & idx, pos_type & pos) const
67 {
68         if (idx + 1 >= nargs())
69                 return false;
70         ++idx;
71         pos = 0;
72         return true;
73 }
74
75
76 bool MathNestInset::idxRight(idx_type & idx, pos_type & pos) const
77 {
78         return idxNext(idx, pos);
79 }
80
81
82 bool MathNestInset::idxPrev(idx_type & idx, pos_type & pos) const
83 {
84         if (idx == 0)
85                 return false;
86         --idx;
87         pos = cell(idx).size();
88         return true;
89 }
90
91
92 bool MathNestInset::idxLeft(idx_type & idx, pos_type & pos) const
93 {
94         return idxPrev(idx, pos);
95 }
96
97
98 bool MathNestInset::idxFirst(idx_type & i, pos_type & pos) const
99 {
100         if (nargs() == 0)
101                 return false;
102         i = 0;
103         pos = 0;
104         return true;
105 }
106
107
108 bool MathNestInset::idxLast(idx_type & i, pos_type & pos) const
109 {
110         if (nargs() == 0)
111                 return false;
112         i = nargs() - 1;
113         pos = cell(i).size();
114         return true;
115 }
116
117
118 bool MathNestInset::idxHome(idx_type & /* idx */, pos_type & pos) const
119 {
120         if (pos == 0)
121                 return false;
122         pos = 0;
123         return true;
124 }
125
126
127 bool MathNestInset::idxEnd(idx_type & idx, pos_type & pos) const
128 {
129         pos_type n = cell(idx).size();
130         if (pos == n)
131                 return false;
132         pos = n;
133         return true;
134 }
135
136
137 void MathNestInset::dump() const
138 {
139         WriteStream os(lyxerr);
140         os << "---------------------------------------------\n";
141         write(os);
142         os << "\n";
143         for (idx_type i = 0; i < nargs(); ++i)
144                 os << cell(i) << "\n";
145         os << "---------------------------------------------\n";
146 }
147
148
149 void MathNestInset::validate(LaTeXFeatures & features) const
150 {
151         for (idx_type i = 0; i < nargs(); ++i)
152                 cell(i).validate(features);
153 }
154
155
156 bool MathNestInset::match(MathInset * p) const
157 {
158         if (nargs() != p->nargs())
159                 return false;
160         for (idx_type i = 0; i < nargs(); ++i)
161                 if (!cell(i).match(p->cell(i)))
162                         return false;
163         return true;
164 }
165
166
167 void MathNestInset::replace(ReplaceData & rep)
168 {
169         for (idx_type i = 0; i < nargs(); ++i)
170                 cell(i).replace(rep);
171 }