#include "math_nestinset.h"
-/// An inset for super- and subscripts.
+// An inset for super- and subscripts or both. The 'nucleus' is always
+// cell 0. If there is just one script, it's cell 1 and cell_1_is_up_
+// is set accordingly. If both are used, cell 1 is up and cell 2 is down.
+
class MathScriptInset : public MathNestInset {
public:
/// create inset without scripts
/// create inset with single script and given nucleus
MathScriptInset(MathAtom const & at, bool up);
///
- std::auto_ptr<InsetBase> clone() const;
+ mode_type currentMode() const { return MATH_MODE; }
///
void metrics(MetricsInfo & mi, Dimension & dim) const;
///
bool idxFirst(LCursor & cur) const;
/// Target pos when we enter the inset from the right by pressing "Left"
bool idxLast(LCursor & cur) const;
- /// can we enter this cell?
- bool validCell(idx_type i) const { return i == 2 || script_[i]; }
/// write LaTeX and Lyx code
void write(WriteStream & os) const;
void limits(int lim) { limits_ = lim; }
/// get limits
int limits() const { return limits_; }
- /// returns subscript
+ /// returns subscript. Always run 'hasDown' or 'has(false)' before!
MathArray const & down() const;
- /// returns subscript
+ /// returns subscript. Always run 'hasDown' or 'has(false)' before!
MathArray & down();
- /// returns superscript
+ /// returns superscript. Always run 'hasUp' or 'has(true)' before!
MathArray const & up() const;
- /// returns superscript
+ /// returns superscript. Always run 'hasUp' or 'has(true)' before!
MathArray & up();
/// returns nucleus
MathArray const & nuc() const;
bool hasDown() const;
/// do we have a script?
bool has(bool up) const;
+ /// what idx has super/subscript?
+ idx_type idxOfScript(bool up) const;
/// remove script
void removeScript(bool up);
/// make sure a script is accessible
/// say whether we have displayed limits
void infoize2(std::ostream & os) const;
protected:
- ///
- DispatchResult priv_dispatch(LCursor & cur, FuncRequest const & cmd);
+ virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
private:
+ virtual std::auto_ptr<InsetBase> doClone() const;
/// returns x offset for main part
int dxx() const;
/// returns width of nucleus if any
/// where do we have to draw the scripts?
bool hasLimits() const;
/// clean up empty cells
- void notifyCursorLeaves(idx_type idx);
+ void notifyCursorLeaves(LCursor & cur);
/// possible subscript (index 0) and superscript (index 1)
- bool script_[2];
+ bool cell_1_is_up_;
/// 1 - "limits", -1 - "nolimits", 0 - "default"
int limits_;
};