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), code_(LM_TC_MIN), 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 string const & MathInset::name() const
65 void MathInset::setName(string const & n)
71 MathStyles MathInset::size() const
77 void MathInset::size(MathStyles s)
83 std::ostream & operator<<(std::ostream & os, MathInset const & inset)
85 inset.write(os, false);
90 int MathInset::xo() const
96 int MathInset::yo() const
102 void MathInset::xo(int x)
108 void MathInset::yo(int y)
114 int MathInset::nargs() const
116 return cells_.size();
120 MathXArray & MathInset::xcell(int i)
126 MathXArray const & MathInset::xcell(int i) const
132 MathArray & MathInset::cell(int i)
134 return cells_[i].data_;
138 MathArray const & MathInset::cell(int i) const
140 return cells_[i].data_;
144 void MathInset::substitute(MathArray & array, MathMacro const & m) const
146 MathInset * p = clone();
147 for (int i = 0; i < nargs(); ++i)
148 p->cell(i).substitute(m);
153 void MathInset::metrics(MathStyles st)
156 for (int i = 0; i < nargs(); ++i)
157 xcell(i).metrics(st);
161 void MathInset::draw(Painter & pain, int x, int y)
165 for (int i = 0; i < nargs(); ++i)
166 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
170 bool MathInset::idxNext(int & idx, int & pos) const
172 if (idx + 1 >= nargs())
180 bool MathInset::idxRight(int & idx, int & pos) const
182 return idxNext(idx, pos);
186 bool MathInset::idxPrev(int & idx, int & pos) const
191 pos = cell(idx).size();
196 bool MathInset::idxLeft(int & idx, int & pos) const
198 return idxPrev(idx, pos);
202 bool MathInset::idxUp(int &, int &) const
208 bool MathInset::idxDown(int &, int &) const
214 bool MathInset::idxFirst(int & i, int & pos) const
224 bool MathInset::idxLast(int & i, int & pos) const
229 pos = cell(i).size();
234 bool MathInset::idxHome(int & /* idx */, int & pos) const
243 bool MathInset::idxEnd(int & idx, int & pos) const
245 if (pos == cell(idx).size())
248 pos = cell(idx).size();
253 bool MathInset::idxFirstUp(int &, int &) const
259 bool MathInset::idxFirstDown(int &, int &) const
265 void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
272 void MathInset::idxDeleteRange(int, int)
276 bool MathInset::idxLastUp(int &, int &) const
282 bool MathInset::idxLastDown(int &, int &) const
288 void MathInset::getXY(int & x, int & y) const
296 void MathInset::userSetSize(MathStyles sz)
300 flag = flag & ~LMPF_FIXED_SIZE;
305 void MathInset::writeNormal(std::ostream & os) const
307 os << "[" << name_ << "] ";
311 void MathInset::dump() const
313 lyxerr << "---------------------------------------------\n";
314 write(lyxerr, false);
316 for (int i = 0; i < nargs(); ++i)
317 lyxerr << cell(i) << "\n";
318 lyxerr << "---------------------------------------------\n";
322 void MathInset::push_back(unsigned char ch, MathTextCodes fcode)
325 cells_.back().data_.push_back(ch, fcode);
327 lyxerr << "can't push without a cell\n";
331 void MathInset::push_back(MathInset * p)
334 cells_.back().data_.push_back(p);
336 lyxerr << "can't push without a cell\n";
340 bool MathInset::covers(int x, int y) const
345 y >= yo_ - ascent_ &&
350 void MathInset::validate(LaTeXFeatures & features) const
352 for (int i = 0; i < nargs(); ++i)
353 cell(i).validate(features);
357 std::vector<int> MathInset::idxBetween(int from, int to) const
359 std::vector<int> res;
360 for (int i = from; i <= to; ++i)
366 MathTextCodes MathInset::code() const
372 void MathInset::code(MathTextCodes t)