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.
21 #pragma implementation
24 #include "math_inset.h"
25 #include "mathed/support.h"
30 int MathInset::workwidth;
33 MathInset::MathInset(int nargs, string const & name, MathInsetTypes ot)
34 : name_(name), objtype(ot), width_(0), ascent_(0), descent_(0),
35 size_(LM_ST_DISPLAY), cells_(nargs), xo_(0), yo_(0)
39 int MathInset::ascent() const
45 int MathInset::descent() const
51 int MathInset::width() const
57 int MathInset::height() const
59 return ascent_ + descent_;
63 int MathInset::limits() const
69 void MathInset::limits(int)
73 string const & MathInset::name() const
79 MathInsetTypes MathInset::GetType() const
85 void MathInset::SetType(MathInsetTypes t)
91 void MathInset::SetName(string const & n)
97 MathStyles MathInset::size() const
103 void MathInset::size(MathStyles s)
108 std::ostream & operator<<(std::ostream & os, MathInset const & inset)
110 inset.Write(os, false);
115 int MathInset::xo() const
121 int MathInset::yo() const
127 void MathInset::xo(int x)
133 void MathInset::yo(int y)
139 int MathInset::nargs() const
141 return cells_.size();
146 MathXArray & MathInset::xcell(int i)
151 MathXArray const & MathInset::xcell(int i) const
158 MathArray & MathInset::cell(int i)
160 return cells_[i].data_;
163 MathArray const & MathInset::cell(int i) const
165 return cells_[i].data_;
169 void MathInset::substitute(MathArray & array, MathMacro const & m) const
171 MathInset * p = clone();
172 for (int i = 0; i < nargs(); ++i)
173 p->cell(i).substitute(m);
177 void MathInset::Metrics(MathStyles st, int, int)
180 for (int i = 0; i < nargs(); ++i)
181 xcell(i).Metrics(st);
184 void MathInset::draw(Painter & pain, int x, int y)
188 for (int i = 0; i < nargs(); ++i)
189 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
193 bool MathInset::idxNext(int & idx, int & pos) const
195 if (idx + 1 >= nargs())
203 bool MathInset::idxRight(int & idx, int & pos) const
205 return idxNext(idx, pos);
209 bool MathInset::idxPrev(int & idx, int & pos) const
214 pos = cell(idx).size();
219 bool MathInset::idxLeft(int & idx, int & pos) const
221 return idxPrev(idx, pos);
224 bool MathInset::idxUp(int &, int &) const
230 bool MathInset::idxDown(int &, int &) const
236 bool MathInset::idxFirst(int & i, int & pos) const
245 bool MathInset::idxLast(int & i, int & pos) const
250 pos = cell(i).size();
255 bool MathInset::idxHome(int & /* idx */, int & pos) const
264 bool MathInset::idxEnd(int & idx, int & pos) const
266 if (pos == cell(idx).size())
269 pos = cell(idx).size();
274 bool MathInset::idxFirstUp(int &, int &) const
280 bool MathInset::idxFirstDown(int &, int &) const
285 void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
292 bool MathInset::idxLastUp(int &, int &) const
298 bool MathInset::idxLastDown(int &, int &) const
304 void MathInset::GetXY(int & x, int & y) const
312 void MathInset::UserSetSize(MathStyles sz)
316 flag = flag & ~LMPF_FIXED_SIZE;
321 void MathInset::WriteNormal(std::ostream & os) const
323 os << "[" << name_ << "] ";
327 void MathInset::dump() const
329 lyxerr << "---------------------------------------------\n";
330 Write(lyxerr, false);
332 for (int i = 0; i < nargs(); ++i)
333 lyxerr << cell(i) << "\n";
334 lyxerr << "---------------------------------------------\n";
338 void MathInset::push_back(byte ch, MathTextCodes fcode)
341 cells_.back().data_.push_back(ch, fcode);
343 lyxerr << "can't push without a cell\n";
347 void MathInset::push_back(MathInset * p)
350 cells_.back().data_.push_back(p);
352 lyxerr << "can't push without a cell\n";
356 bool MathInset::covers(int x, int y) const
361 y >= yo_ - ascent_ &&