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(string const & name, MathInsetTypes ot, int nargs)
34 : name_(name), objtype(ot), width_(0), ascent_(0), descent_(0),
35 size_(LM_ST_TEXT), 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 bool MathInset::hasLimits() const
79 string const & MathInset::name() const
85 MathInsetTypes MathInset::GetType() const
91 void MathInset::SetType(MathInsetTypes t)
97 void MathInset::SetName(string const & n)
103 MathStyles MathInset::size() const
109 void MathInset::size(MathStyles s)
114 std::ostream & operator<<(std::ostream & os, MathInset const & inset)
116 inset.Write(os, false);
121 int MathInset::xo() const
127 int MathInset::yo() const
133 void MathInset::xo(int x)
139 void MathInset::yo(int y)
145 int MathInset::nargs() const
147 return cells_.size();
152 MathXArray & MathInset::xcell(int i)
157 MathXArray const & MathInset::xcell(int i) const
164 MathArray & MathInset::cell(int i)
166 return cells_[i].data_;
169 MathArray const & MathInset::cell(int i) const
171 return cells_[i].data_;
175 void MathInset::setData(MathArray const & a, int idx)
177 cells_[idx].data_ = a;
181 void MathInset::substitute(MathArray & array, MathMacro const & m) const
183 MathInset * p = clone();
184 for (int i = 0; i < nargs(); ++i)
185 p->cell(i).substitute(m);
189 void MathInset::Metrics(MathStyles st)
192 for (int i = 0; i < nargs(); ++i)
193 xcell(i).Metrics(st);
196 void MathInset::draw(Painter & pain, int x, int y)
200 for (int i = 0; i < nargs(); ++i)
201 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
205 bool MathInset::idxRight(int & idx, int & pos) const
207 if (idx + 1 >= nargs())
215 bool MathInset::idxLeft(int & idx, int & pos) const
220 pos = cell(idx).size();
225 bool MathInset::idxUp(int &, int &) const
231 bool MathInset::idxDown(int &, int &) const
237 bool MathInset::idxFirst(int & i, int & pos) const
246 bool MathInset::idxLast(int & i, int & pos) const
251 pos = cell(i).size();
256 bool MathInset::idxHome(int & /* idx */, int & pos) const
265 bool MathInset::idxEnd(int & idx, int & pos) const
267 if (pos == cell(idx).size())
270 pos = cell(idx).size();
275 bool MathInset::idxFirstUp(int &, int &) const
281 bool MathInset::idxFirstDown(int &, int &) const
286 bool MathInset::idxDelete(int)
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_ &&