]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_scriptinset.h
Fix to bug 2362: Deleting superscript also deletes subscript.
[lyx.git] / src / mathed / math_scriptinset.h
index 2f9dd58b408cc92fa55e8eb99d893896ad89c625..52beb7073f06b2418328cea41ac31fefcea20519 100644 (file)
 #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
@@ -25,7 +28,7 @@ public:
        /// 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;
        ///
@@ -45,8 +48,6 @@ public:
        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;
@@ -70,13 +71,13 @@ public:
        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;
@@ -88,6 +89,8 @@ public:
        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
@@ -97,9 +100,9 @@ public:
        /// 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
@@ -119,10 +122,10 @@ private:
        /// 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_;
 };