X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_atom.h;h=9e02b7a8d30883d17d865cb1a9154433a66681a6;hb=cd03e2b7db8379a91f3d31eac2c5bc25b159c541;hp=a97ad307bb15fbe93d807769424d06ee5d0a50ec;hpb=4253792bd609d0ff130766693e292507dafcf631;p=lyx.git diff --git a/src/mathed/math_atom.h b/src/mathed/math_atom.h index a97ad307bb..9e02b7a8d3 100644 --- a/src/mathed/math_atom.h +++ b/src/mathed/math_atom.h @@ -1,166 +1,72 @@ // -*- C++ -*- +/** + * \file math_atom.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ #ifndef MATH_ATOM_H #define MATH_ATOM_H -#include -#include -#ifdef __GNUG__ -#pragma interface -#endif +/** +Wrapper for MathInset * with copy-semantics -#include "math_defs.h" +-- -/** The 'atom' is the major blob in math typesetting. And 'atom' consists of a nucleus, an optional superscript, and an optional subscript. Exactly where the subscript and superscript are drawn depends on the -size, and type, of the nucleus they are attached to. +size, and type, of the nucleus they are attached to. Jules + +-- + +Ok: Implementing it thusly is not feasible since cursor movement gets +hackish. We use MathAtom only as a wrapper around MathInset * with value +semantics. + +The MathAtom owns the MathInset * and is responsible for proper cloning and +destruction. Every MathInset * should be put into a MathAtom after its +creation as soon as possible. + +Andre' + */ -class LaTeXFeatures; -class MathCharInset; -class MathScriptInset; +class InsetBase; class MathInset; -class MathMacro; -class MathArray; -class Painter; class MathAtom { -public: - /// +public: + /// default constructor, object is useless, but we need it to put it into + // std::containers MathAtom(); - /// + /// the "real constructor" + explicit MathAtom(InsetBase * p); + /// copy constructor, invokes nucleus_->clone() MathAtom(MathAtom const &); - /// - explicit MathAtom(MathInset * p); - /// - MathAtom(MathInset * p, MathScriptInset * up, MathScriptInset * down); - /// - virtual ~MathAtom(); - /// + /// we really need to clean up + ~MathAtom(); + /// assignment invokes nucleus_->clone() void operator=(MathAtom const &); - /// - void swap(MathAtom &); - - /// draw the object, sets xo_ and yo_ cached values - virtual void draw(Painter &, int x, int y) const; - /// reproduce itself - void metrics(MathStyles st) const; - /// - int ascent() const; - /// - int descent() const; - /// - int width() const; - /// - int height() const; - - /// - int xo() const; - /// - int yo() const; - /// - void xo(int tx) const; - /// - void yo(int ty) const; - /// + /// access to the inset (checked with gprof) + MathInset * nucleus() { return nucleus_; } + /// access to the inset + MathInset const * operator->() const { return nucleus_; } - /// - void getXY(int & x, int & y) const; - /// - bool covers(int x, int y) const; + /// width cache. Not nice... + mutable int width_; - /// - void dump() const; - /// - void validate(LaTeXFeatures & features) const; - /// - void handleFont(MathTextCodes) {} - - /// make sure superscript is available - MathScriptInset * ensure(bool up); - /// delete subscript array if empty - void removeEmptyScripts(); - /// delete nucleus - void removeNucleus(); - /// delete superscript - void removeUp(); - /// delete subscript - void removeDown(); - /// can we add a super- or subscript? - virtual bool allows(bool up) const { return script_[up] == 0; } - /// can we add a super- or subscript? - virtual bool allowsLimits() const { return true; } - /// set limits - void limits(int lim) { limits_ = lim; } - /// - int limits() const { return limits_; } - /// - bool hasLimits() const; - /// true if we have an "inner" position - bool hasInner() const; - /// returns superscript - MathScriptInset * up() const; - /// returns subscript - MathScriptInset * down() const; - /// returns superscript - MathScriptInset * & up(); - /// returns subscript - MathScriptInset * & down(); - /// - MathInset * nucleus() const { return nucleus_; } - /// - MathInset * & nucleus() { return nucleus_; } - /// - void substitute(const MathMacro &); - /// - void write(std::ostream &, bool) const; - /// - void writeNormal(std::ostream &) const; - /// returns width of nucleus if any - int nwid() const; - -protected: - /// possible subscript (index 0) and superscript (index 1) - MathScriptInset * script_[2]; +private: /// MathInset * nucleus_; - /// - int limits_; - -private: - /// the following are used for positioning the cursor with the mouse - /// cached cursor start position in pixels from the document left - mutable int xo_; - /// cached cursor start position in pixels from the document top - mutable int yo_; - - /// raw copy - void copy(MathAtom const & p); - /// raw destruction - void done(); - - /// returns y offset for superscript - int dy0() const; - /// returns y offset for subscript - int dy1() const; - /// returns x offset for main part - int dxx() const; - /// returns x offset for superscript - int dx0() const; - /// returns x offset for subscript - int dx1() const; - /// returns ascent of nucleus if any - int nasc() const; - /// returns descent of nucleus if any - int ndes() const; }; -std::ostream & operator<<(std::ostream &, MathAtom const &); - #endif