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, MathInsetTypes ot)
30 : name_(name), objtype(ot), 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 MathInsetTypes MathInset::GetType() const
81 void MathInset::SetType(MathInsetTypes t)
87 void MathInset::SetName(string const & n)
93 MathStyles MathInset::size() const
99 void MathInset::size(MathStyles s)
104 std::ostream & operator<<(std::ostream & os, MathInset const & inset)
106 inset.Write(os, false);
111 int MathInset::xo() const
117 int MathInset::yo() const
123 void MathInset::xo(int x)
129 void MathInset::yo(int y)
135 int MathInset::nargs() const
137 return cells_.size();
142 MathXArray & MathInset::xcell(int i)
147 MathXArray const & MathInset::xcell(int i) const
154 MathArray & MathInset::cell(int i)
156 return cells_[i].data_;
159 MathArray const & MathInset::cell(int i) const
161 return cells_[i].data_;
165 void MathInset::substitute(MathArray & array, MathMacro const & m) const
167 MathInset * p = clone();
168 for (int i = 0; i < nargs(); ++i)
169 p->cell(i).substitute(m);
173 void MathInset::Metrics(MathStyles st)
176 for (int i = 0; i < nargs(); ++i)
177 xcell(i).Metrics(st);
180 void MathInset::draw(Painter & pain, int x, int y)
184 for (int i = 0; i < nargs(); ++i)
185 xcell(i).draw(pain, x + xcell(i).xo(), y + xcell(i).yo());
189 bool MathInset::idxNext(int & idx, int & pos) const
191 if (idx + 1 >= nargs())
199 bool MathInset::idxRight(int & idx, int & pos) const
201 return idxNext(idx, pos);
205 bool MathInset::idxPrev(int & idx, int & pos) const
210 pos = cell(idx).size();
215 bool MathInset::idxLeft(int & idx, int & pos) const
217 return idxPrev(idx, pos);
220 bool MathInset::idxUp(int &, int &) const
226 bool MathInset::idxDown(int &, int &) const
232 bool MathInset::idxFirst(int & i, int & pos) const
241 bool MathInset::idxLast(int & i, int & pos) const
246 pos = cell(i).size();
251 bool MathInset::idxHome(int & /* idx */, int & pos) const
260 bool MathInset::idxEnd(int & idx, int & pos) const
262 if (pos == cell(idx).size())
265 pos = cell(idx).size();
270 bool MathInset::idxFirstUp(int &, int &) const
276 bool MathInset::idxFirstDown(int &, int &) const
281 void MathInset::idxDelete(int &, bool & popit, bool & deleteit)
287 void MathInset::idxDeleteRange(int, int)
291 bool MathInset::idxLastUp(int &, int &) const
297 bool MathInset::idxLastDown(int &, int &) const
303 void MathInset::GetXY(int & x, int & y) const
311 void MathInset::UserSetSize(MathStyles sz)
315 flag = flag & ~LMPF_FIXED_SIZE;
320 void MathInset::WriteNormal(std::ostream & os) const
322 os << "[" << name_ << "] ";
326 void MathInset::dump() const
328 lyxerr << "---------------------------------------------\n";
329 Write(lyxerr, false);
331 for (int i = 0; i < nargs(); ++i)
332 lyxerr << cell(i) << "\n";
333 lyxerr << "---------------------------------------------\n";
337 void MathInset::push_back(unsigned char ch, MathTextCodes fcode)
340 cells_.back().data_.push_back(ch, fcode);
342 lyxerr << "can't push without a cell\n";
346 void MathInset::push_back(MathInset * p)
349 cells_.back().data_.push_back(p);
351 lyxerr << "can't push without a cell\n";
355 bool MathInset::covers(int x, int y) const
360 y >= yo_ - ascent_ &&
364 void MathInset::Validate(LaTeXFeatures & features) const
366 for (int i = 0; i < nargs(); ++i)
367 cell(i).Validate(features);
370 std::vector<int> MathInset::idxBetween(int from, int to) const
372 std::vector<int> res;
373 for (int i = from; i <= to; ++i)