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, short 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 bool MathInset::GetLimits() const
69 void MathInset::SetLimits(bool) {}
72 string const & MathInset::name() const
78 short MathInset::GetType() const
84 void MathInset::SetType(short t)
90 void MathInset::SetName(string const & n)
96 MathStyles MathInset::size() const
102 void MathInset::size(MathStyles s)
107 std::ostream & operator<<(std::ostream & os, MathInset const & inset)
109 inset.Write(os, false);
114 int MathInset::xo() const
120 int MathInset::yo() const
126 void MathInset::xo(int x)
132 void MathInset::yo(int y)
138 int MathInset::nargs() const
140 return cells_.size();
145 MathXArray & MathInset::xcell(int i)
150 MathXArray const & MathInset::xcell(int i) const
157 MathArray & MathInset::cell(int i)
159 return cells_[i].data_;
162 MathArray const & MathInset::cell(int i) const
164 return cells_[i].data_;
168 void MathInset::setData(MathArray const & a, int idx)
170 cells_[idx].data_ = a;
174 void MathInset::substitute(MathArray & array, MathMacro const & m) const
176 MathInset * p = Clone();
177 for (int i = 0; i < nargs(); ++i)
178 p->cell(i).substitute(m);
182 void MathInset::Metrics(MathStyles st)
185 for (int i = 0; i < nargs(); ++i)
186 xcell(i).Metrics(st);
189 void MathInset::draw(Painter & pain, int x, int y)
193 for (int i = 0; i < nargs(); ++i)
194 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
198 bool MathInset::idxRight(int & idx, int & pos) const
200 if (idx + 1 >= nargs())
208 bool MathInset::idxLeft(int & idx, int & pos) const
213 pos = cell(idx).size();
218 bool MathInset::idxUp(int &, int &) const
224 bool MathInset::idxDown(int &, int &) const
230 bool MathInset::idxFirst(int & i, int & pos) const
239 bool MathInset::idxLast(int & i, int & pos) const
244 pos = cell(i).size();
249 bool MathInset::idxHome(int & i, int & pos) const
258 bool MathInset::idxEnd(int & idx, int & pos) const
260 if (pos == cell(idx).size())
263 pos = cell(idx).size();
268 void MathInset::GetXY(int & x, int & y) const
276 void MathInset::UserSetSize(MathStyles sz)
280 flag = flag & ~LMPF_FIXED_SIZE;
285 void MathInset::WriteNormal(std::ostream & os) const
287 os << "[" << name_ << "] ";
291 void MathInset::dump() const
293 lyxerr << "---------------------------------------------\n";
294 Write(lyxerr, false);
296 for (int i = 0; i < nargs(); ++i)
297 lyxerr << cell(i) << "\n";
298 lyxerr << "---------------------------------------------\n";
302 void MathInset::push_back(byte ch, MathTextCodes fcode)
305 cells_.back().data_.push_back(ch, fcode);
307 lyxerr << "can't push without a cell\n";
311 void MathInset::push_back(MathInset * p)
314 cells_.back().data_.push_back(p);
316 lyxerr << "can't push without a cell\n";
320 bool MathInset::covers(int x, int y) const
325 y >= yo_ - ascent_ &&