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_atom.h"
23 #include "math_scriptinset.h"
26 #include "support/LAssert.h"
30 : nucleus_(0), limits_(0), xo_(0), yo_(0)
37 MathAtom::MathAtom(MathInset * p)
38 : nucleus_(p), limits_(0), xo_(0), yo_(0)
45 MathAtom::MathAtom(MathInset * p, MathScriptInset * up, MathScriptInset * down)
46 : nucleus_(p), limits_(0), xo_(0), yo_(0)
53 MathAtom::MathAtom(MathAtom const & p)
59 void MathAtom::operator=(MathAtom const & p)
82 void MathAtom::copy(MathAtom const & p)
84 //cerr << "calling MathAtom::copy\n";
88 nucleus_ = p.nucleus_;
89 script_[0] = p.script_[0];
90 script_[1] = p.script_[1];
92 nucleus_ = nucleus_->clone();
94 script_[0] = new MathScriptInset(*script_[0]);
96 script_[1] = new MathScriptInset(*script_[1]);
100 int MathAtom::height() const
102 return ascent() + descent();
106 std::ostream & operator<<(std::ostream & os, MathAtom const & atom)
108 atom.write(os, false);
113 int MathAtom::xo() const
119 int MathAtom::yo() const
125 void MathAtom::xo(int x) const
131 void MathAtom::yo(int y) const
137 void MathAtom::getXY(int & x, int & y) const
145 void MathAtom::userSetSize(MathStyles sz)
149 flag = flag & ~LMPF_FIXED_SIZE;
154 void MathAtom::writeNormal(std::ostream & os) const
160 void MathAtom::dump() const
162 lyxerr << "---------------------------------------------\n";
163 write(lyxerr, false);
164 lyxerr << "\n---------------------------------------------\n";
168 bool MathAtom::covers(int x, int y) const
172 x <= xo_ + width() &&
173 y >= yo_ - ascent() &&
174 y <= yo_ + descent();
178 MathScriptInset * MathAtom::ensure(bool up)
181 script_[up] = new MathScriptInset(up);
186 void MathAtom::validate(LaTeXFeatures &) const
190 void MathAtom::metrics(MathStyles st) const
192 MathStyles tt = smallerStyleScript(st);
194 nucleus()->metrics(st);
202 MathScriptInset * MathAtom::up() const
208 MathScriptInset * MathAtom::down() const
214 MathScriptInset * & MathAtom::up()
220 MathScriptInset * & MathAtom::down()
226 int MathAtom::dy0() const
230 int des = down()->ascent();
234 des = std::max(des, ndes());
239 int MathAtom::dy1() const
243 int asc = up()->descent();
247 asc = std::max(asc, nasc());
248 asc = std::max(asc, mathed_char_ascent(LM_TC_VAR, LM_ST_TEXT, 'I'));
253 int MathAtom::dx0() const
256 return hasLimits() ? (width() - down()->width()) / 2 : nwid();
260 int MathAtom::dx1() const
263 return hasLimits() ? (width() - up()->width()) / 2 : nwid();
267 int MathAtom::dxx() const
269 lyx::Assert(nucleus());
270 return hasLimits() ? (width() - nwid()) / 2 : 0;
274 int MathAtom::ascent() const
276 return dy1() + (up() ? up()->ascent() : 0);
280 int MathAtom::descent() const
282 return dy0() + (down() ? down()->descent() : 0);
286 int MathAtom::width() const
292 wid = std::max(wid, up()->width());
294 wid = std::max(wid, down()->width());
297 wid = std::max(wid, up()->width());
299 wid = std::max(wid, down()->width());
306 int MathAtom::nwid() const
308 return nucleus() ? nucleus()->width() : 0;
312 int MathAtom::nasc() const
314 return nucleus() ? nucleus()->ascent()
315 : mathed_char_ascent(LM_TC_VAR, LM_ST_TEXT, 'I');
319 int MathAtom::ndes() const
321 return nucleus() ? nucleus()->descent()
322 : mathed_char_descent(LM_TC_VAR, LM_ST_TEXT, 'I');
326 void MathAtom::draw(Painter & pain, int x, int y) const
331 nucleus()->draw(pain, x + dxx(), y);
333 up()->draw(pain, x + dx1(), y - dy1());
335 down()->draw(pain, x + dx0(), y + dy0());
339 void MathAtom::write(std::ostream & os, bool fragile) const
342 nucleus()->write(os, fragile);
343 if (nucleus()->takesLimits()) {
354 up()->write(os, fragile);
360 down()->write(os, fragile);
366 bool MathAtom::hasLimits() const
369 limits_ == 1 || (limits_ == 0 && nucleus() && nucleus()->isScriptable());
373 void MathAtom::substitute(MathMacro const & m)
376 nucleus()->substitute(m);
380 down()->substitute(m);
384 void MathAtom::removeEmptyScripts()
386 for (int i = 0; i <= 1; ++i)
387 if (script_[i] && !script_[i]->cell(0).size()) {