3 * Purpose: Implementation of insets for mathed
4 * Author: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
5 * Created: January 1996
8 * Dependencies: Xlib, XForms
10 * Copyright: 1996, 1997 Alejandro Aguilar Sierra
14 * You are free to use and modify this code under the terms of
15 * the GNU General Public Licence version 2 or later.
19 #pragma implementation
22 #include "math_inset.h"
26 int MathInset::workwidth;
29 MathInset::MathInset(int nargs, string const & name)
30 : name_(name), width_(0), ascent_(0), descent_(0),
31 size_(LM_ST_DISPLAY), cells_(nargs), xo_(0), yo_(0)
35 int MathInset::ascent() const
41 int MathInset::descent() const
47 int MathInset::width() const
53 int MathInset::height() const
55 return ascent_ + descent_;
59 int MathInset::limits() const
65 void MathInset::limits(int)
69 string const & MathInset::name() const
75 void MathInset::setName(string const & n)
81 MathStyles MathInset::size() const
87 void MathInset::size(MathStyles s)
92 std::ostream & operator<<(std::ostream & os, MathInset const & inset)
94 inset.write(os, false);
99 int MathInset::xo() const
105 int MathInset::yo() const
111 void MathInset::xo(int x)
117 void MathInset::yo(int y)
123 int MathInset::nargs() const
125 return cells_.size();
130 MathXArray & MathInset::xcell(int i)
135 MathXArray const & MathInset::xcell(int i) const
142 MathArray & MathInset::cell(int i)
144 return cells_[i].data_;
147 MathArray const & MathInset::cell(int i) const
149 return cells_[i].data_;
153 void MathInset::substitute(MathArray & array, MathMacro const & m) const
155 MathInset * p = clone();
156 for (int i = 0; i < nargs(); ++i)
157 p->cell(i).substitute(m);
161 void MathInset::metrics(MathStyles st)
164 for (int i = 0; i < nargs(); ++i)
165 xcell(i).metrics(st);
168 void MathInset::draw(Painter & pain, int x, int y)
172 for (int i = 0; i < nargs(); ++i)
173 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
177 bool MathInset::idxNext(int & idx, int & pos) const
179 if (idx + 1 >= nargs())
187 bool MathInset::idxRight(int & idx, int & pos) const
189 return idxNext(idx, pos);
193 bool MathInset::idxPrev(int & idx, int & pos) const
198 pos = cell(idx).size();
203 bool MathInset::idxLeft(int & idx, int & pos) const
205 return idxPrev(idx, pos);
208 bool MathInset::idxUp(int &, int &) const
214 bool MathInset::idxDown(int &, int &) const
220 bool MathInset::idxFirst(int & i, int & pos) const
229 bool MathInset::idxLast(int & i, int & pos) const
234 pos = cell(i).size();
239 bool MathInset::idxHome(int & /* idx */, int & pos) const
248 bool MathInset::idxEnd(int & idx, int & pos) const
250 if (pos == cell(idx).size())
253 pos = cell(idx).size();
258 bool MathInset::idxFirstUp(int &, int &) const
264 bool MathInset::idxFirstDown(int &, int &) const
269 void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
275 void MathInset::idxDeleteRange(int, int)
279 bool MathInset::idxLastUp(int &, int &) const
285 bool MathInset::idxLastDown(int &, int &) const
291 void MathInset::getXY(int & x, int & y) const
299 void MathInset::userSetSize(MathStyles sz)
303 flag = flag & ~LMPF_FIXED_SIZE;
308 void MathInset::writeNormal(std::ostream & os) const
310 os << "[" << name_ << "] ";
314 void MathInset::dump() const
316 lyxerr << "---------------------------------------------\n";
317 write(lyxerr, false);
319 for (int i = 0; i < nargs(); ++i)
320 lyxerr << cell(i) << "\n";
321 lyxerr << "---------------------------------------------\n";
325 void MathInset::push_back(unsigned char ch, MathTextCodes fcode)
328 cells_.back().data_.push_back(ch, fcode);
330 lyxerr << "can't push without a cell\n";
334 void MathInset::push_back(MathInset * p)
337 cells_.back().data_.push_back(p);
339 lyxerr << "can't push without a cell\n";
343 bool MathInset::covers(int x, int y) const
348 y >= yo_ - ascent_ &&
352 void MathInset::validate(LaTeXFeatures & features) const
354 for (int i = 0; i < nargs(); ++i)
355 cell(i).validate(features);
358 std::vector<int> MathInset::idxBetween(int from, int to) const
360 std::vector<int> res;
361 for (int i = from; i <= to; ++i)