mainly renaming mathed stuff and a safer way to decide whether a cursor
slice belongs to math or text.
-- 
Those who desire to give up Freedom in order to gain Security, will not have,
nor do they deserve, either one.     (T. Jefferson or B. Franklin or both...)
Index: cursor_slice.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor_slice.C,v
retrieving revision 1.6
diff -u -p -r1.6 cursor_slice.C
--- cursor_slice.C      14 Jan 2004 18:17:01 -0000      1.6
+++ cursor_slice.C      15 Jan 2004 11:16:24 -0000
@@ -89,41 +89,34 @@ bool CursorSlice::boundary() const
 
 MathInset * CursorSlice::asMathInset() const
 {
-       return static_cast<MathInset *>(const_cast<InsetBase *>(inset_));
+       return inset_->asMathInset();
 }
 
 
 UpdatableInset * CursorSlice::asUpdatableInset() const
 {
-       return static_cast<UpdatableInset *>(const_cast<InsetBase *>(inset_));
+       return inset_->asUpdatableInset();
 }
 
 
-MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const
+void CursorSlice::cell(CursorSlice::idx_type idx) const
 {
-       BOOST_ASSERT(inset_);
        BOOST_ASSERT(asMathInset());
-       return asMathInset()->cell(idx);
+       asMathInset()->cell(idx);
 }
 
 
 MathArray & CursorSlice::cell() const
 {
-       BOOST_ASSERT(inset_);
+       BOOST_ASSERT(asMathInset());
        return asMathInset()->cell(idx_);
 }
 
 
-void CursorSlice::getPos(int & x, int & y) const
-{
-       BOOST_ASSERT(inset_);
-       asMathInset()->getPos(idx_, pos_, x, y);
-}
-
-
-void CursorSlice::setPos(int pos)
+void CursorSlice::getScreenPos(int & x, int & y) const
 {
-       pos_ = pos;
+       BOOST_ASSERT(asMathInset());
+       asMathInset()->getScreenPos(idx_, pos_, x, y);
 }
 
 
Index: cursor_slice.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/cursor_slice.h,v
retrieving revision 1.4
diff -u -p -r1.4 cursor_slice.h
--- cursor_slice.h      14 Jan 2004 18:17:01 -0000      1.4
+++ cursor_slice.h      15 Jan 2004 11:16:24 -0000
@@ -80,12 +80,10 @@ public:
        ///
        /// returns cell corresponding to this position
        MathArray & cell() const;
-       /// returns cell corresponding to this position
-       MathArray & cell(idx_type idx) const;
+       /// set cell corresponding to this position
+       void cell(idx_type idx) const;
        /// gets screen position of the thing
-       void getPos(int & x, int & y) const;
-       /// set position
-       void setPos(int pos);
+       void getScreenPos(int & x, int & y) const;
        ///
        MathInset * asMathInset() const;
 
Index: insets/insetbase.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbase.h,v
retrieving revision 1.20
diff -u -p -r1.20 insetbase.h
--- insets/insetbase.h  13 Jan 2004 12:28:35 -0000      1.20
+++ insets/insetbase.h  15 Jan 2004 11:16:25 -0000
@@ -18,12 +18,14 @@
 
 class Buffer;
 class BufferView;
+class DispatchResult;
 class FuncRequest;
+class LaTeXFeatures;
+class MathInset;
 class MetricsInfo;
 class Dimension;
 class PainterInfo;
-class LaTeXFeatures;
-class DispatchResult;
+class UpdatableInset;
 
 /// Common base class to all insets
 class InsetBase {
@@ -45,6 +47,11 @@ public:
        virtual ~InsetBase() {}
        /// replicate ourselves
        virtual std::auto_ptr<InsetBase> clone() const = 0;
+
+       /// identification as math inset
+       virtual MathInset * asMathInset() { return 0; }
+       /// identification as non-math inset
+       virtual UpdatableInset * asUpdatableInset() { return 0; }
 
        // the real dispatcher
        DispatchResult
Index: insets/updatableinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/updatableinset.h,v
retrieving revision 1.29
diff -u -p -r1.29 updatableinset.h
--- insets/updatableinset.h     8 Jan 2004 18:30:13 -0000       1.29
+++ insets/updatableinset.h     15 Jan 2004 11:16:25 -0000
@@ -25,6 +25,8 @@ class UpdatableInset : public InsetOld {
 public:
        ///
        virtual EDITABLE editable() const;
+       /// identification as math inset
+       UpdatableInset * asUpdatableInset() { return this; }
 
        /// return the cursor pos, relative to the inset pos
        virtual void getCursorPos(int, int &, int &) const {}
Index: mathed/formulabase.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/formulabase.C,v
retrieving revision 1.321
diff -u -p -r1.321 formulabase.C
--- mathed/formulabase.C        14 Jan 2004 18:17:01 -0000      1.321
+++ mathed/formulabase.C        15 Jan 2004 11:16:25 -0000
@@ -166,33 +166,33 @@ void InsetFormulaBase::insetUnlock(Buffe
 
 void InsetFormulaBase::getCursor(BufferView &, int & x, int & y) const
 {
-       mathcursor->getPos(x, y);
+       mathcursor->getScreenPos(x, y);
 }
 
 
 void InsetFormulaBase::getCursorPos(int, int & x, int & y) const
 {
-       if (!mathcursor) {
-               lyxerr << "getCursorPos - should not happen";
+       if (mathcursor) {
+               mathcursor->getScreenPos(x, y);
+               x = mathcursor->targetX();
+               x -= xo_;
+               y -= yo_;
+               lyxerr << "InsetFormulaBase::getCursorPos: " << x << ' ' << y << endl;
+       } else {
                x = 0;
                y = 0;
-               return;
+               lyxerr << "getCursorPos - should not happen";
        }
-       mathcursor->getPos(x, y);
-       x = mathcursor->targetX();
-       x -= xo_;
-       y -= yo_;
-       lyxerr << "InsetFormulaBase::getCursorPos: " << x << ' ' << y << endl;
 }
 
 
 void InsetFormulaBase::getCursorDim(int & asc, int & desc) const
 {
-       if (!mathcursor)
-               return;
-       asc = 10;
-       desc = 2;
-       //math_font_max_dim(font_, asc, des);
+       if (mathcursor) {
+               asc = 10;
+               desc = 2;
+               //math_font_max_dim(font_, asc, des);
+       }
 }
 
 
@@ -226,7 +226,7 @@ DispatchResult InsetFormulaBase::lfunMou
                MathArray ar;
                asArray(bv->getClipboard(), ar);
                mathcursor->selClear();
-               mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
+               mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_);
                mathcursor->insert(ar);
                bv->update();
                return DispatchResult(true, true);
@@ -240,7 +240,7 @@ DispatchResult InsetFormulaBase::lfunMou
                //delete mathcursor;
                //mathcursor = new MathCursor(this, x == 0);
                //metrics(bv);
-               //mathcursor->setPos(x + xo_, y + yo_);
+               //mathcursor->setScreenPos(x + xo_, y + yo_);
                return DispatchResult(true, true);
        }
 
@@ -258,7 +258,7 @@ DispatchResult InsetFormulaBase::lfunMou
                releaseMathCursor(bv);
                mathcursor = new MathCursor(this, cmd.x == 0);
                //metrics(bv);
-               mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
+               mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_);
        }
 
        if (cmd.button() == mouse_button::button3) {
@@ -270,7 +270,7 @@ DispatchResult InsetFormulaBase::lfunMou
                first_x = cmd.x;
                first_y = cmd.y;
                mathcursor->selClear();
-               mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
+               mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_);
                mathcursor->dispatch(cmd);
                return DispatchResult(true, true);
        }
@@ -302,7 +302,7 @@ DispatchResult InsetFormulaBase::lfunMou
                mathcursor->selStart();
 
        BufferView * bv = cmd.view();
-       mathcursor->setPos(cmd.x + xo_, cmd.y + yo_);
+       mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_);
        bv->update();
        return DispatchResult(true, true);
 }
@@ -326,7 +326,7 @@ void InsetFormulaBase::edit(BufferView *
        releaseMathCursor(bv);
        mathcursor = new MathCursor(this, true);
        //metrics(bv);
-       mathcursor->setPos(x + xo_, y + yo_);
+       mathcursor->setScreenPos(x + xo_, y + yo_);
        bv->fullCursor().push(this);
        // if that is removed, we won't get the magenta box when entering an
        // inset for the first time
@@ -506,7 +506,7 @@ InsetFormulaBase::priv_dispatch(FuncRequ
                int y = 0;
                istringstream is(cmd.argument.c_str());
                is >> x >> y;
-               mathcursor->setPos(x, y);
+               mathcursor->setScreenPos(x, y);
                break;
        }
 
Index: mathed/math_cursor.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.C,v
retrieving revision 1.376
diff -u -p -r1.376 math_cursor.C
--- mathed/math_cursor.C        14 Jan 2004 18:17:01 -0000      1.376
+++ mathed/math_cursor.C        15 Jan 2004 11:16:25 -0000
@@ -262,19 +262,19 @@ bool positionable
 }
 
 
-void MathCursor::setPos(int x, int y)
+void MathCursor::setScreenPos(int x, int y)
 {
-       dump("setPos 1");
+       dump("setScreenPos 1");
        bool res = bruteFind(x, y,
                formula()->xlow(), formula()->xhigh(),
                formula()->ylow(), formula()->yhigh());
        if (!res) {
                // this can happen on creation of "math-display"
-               dump("setPos 1.5");
+               dump("setScreenPos 1.5");
                first();
        }
        targetx_ = -1; // "no target"
-       dump("setPos 2");
+       dump("setScreenPos 2");
 }
 
 
@@ -641,9 +641,9 @@ void MathCursor::handleNest(MathAtom con
 }
 
 
-void MathCursor::getPos(int & x, int & y) const
+void MathCursor::getScreenPos(int & x, int & y) const
 {
-       inset()->getPos(idx(), pos(), x, y);
+       inset()->getScreenPos(idx(), pos(), x, y);
 }
 
 
@@ -652,7 +652,7 @@ int MathCursor::targetX() const
        if (targetx_ != -1)
                return targetx_;
        int x = 0, y = 0;
-       getPos(x, y);
+       getScreenPos(x, y);
        return x;
 }
 
@@ -944,7 +944,7 @@ bool MathCursor::goUpDown(bool up)
        // So fiddle around with it only if you know what you are doing!
   int xo = 0;
        int yo = 0;
-       getPos(xo, yo);
+       getScreenPos(xo, yo);
 
        // check if we had something else in mind, if not, this is the future goal
        if (targetx_ == -1)
@@ -1018,7 +1018,7 @@ bool MathCursor::goUpDown(bool up)
 
                // any improvement so far?
                int xnew, ynew;
-               getPos(xnew, ynew);
+               getScreenPos(xnew, ynew);
                if (up ? ynew < yo : ynew > yo)
                        return true;
        }
@@ -1037,7 +1037,7 @@ bool MathCursor::bruteFind
                // avoid invalid nesting when selecting
                if (!selection_ || positionable(it, Anchor_)) {
                        int xo, yo;
-                       it.back().getPos(xo, yo);
+                       it.back().getScreenPos(xo, yo);
                        if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
                                double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
                                //lyxerr << "x: " << x << " y: " << y << " d: " << 
endl;
@@ -1066,13 +1066,13 @@ void MathCursor::bruteFind2(int x, int y
        double best_dist = 1e10;
 
        CursorBase it = Cursor_;
-       it.back().setPos(0);
+       it.back().pos(0);
        CursorBase et = Cursor_;
        int n = et.back().asMathInset()->cell(et.back().idx_).size();
-       et.back().setPos(n);
+       et.back().pos(n);
        for (int i = 0; ; ++i) {
                int xo, yo;
-               it.back().getPos(xo, yo);
+               it.back().getScreenPos(xo, yo);
                double d = (x - xo) * (x - xo) + (y - yo) * (y - yo);
                // '<=' in order to take the last possible position
                // this is important for clicking behind \sum in e.g. '\sum_i a'
@@ -1443,7 +1443,7 @@ DispatchResult MathCursor::dispatch(Func
                        CursorSlice & pos = Cursor_.back();
                        int x = 0;
                        int y = 0;
-                       getPos(x, y);
+                       getScreenPos(x, y);
                        if (x < cmd.x && hasPrevAtom()) {
                                DispatchResult const res =
                                        prevAtom().nucleus()->dispatch(cmd, pos.idx_, 
pos.pos_);
Index: mathed/math_cursor.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_cursor.h,v
retrieving revision 1.156
diff -u -p -r1.156 math_cursor.h
--- mathed/math_cursor.h        14 Jan 2004 18:17:02 -0000      1.156
+++ mathed/math_cursor.h        15 Jan 2004 11:16:25 -0000
@@ -98,9 +98,9 @@ public:
        void niceInsert(std::string const &);
 
        /// in pixels from top of screen
-       void setPos(int x, int y);
+       void setScreenPos(int x, int y);
        /// in pixels from top of screen
-       void getPos(int & x, int & y) const;
+       void getScreenPos(int & x, int & y) const;
        /// in pixels from left of screen
        int targetX() const;
        /// current inset
Index: mathed/math_inset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.C,v
retrieving revision 1.125
diff -u -p -r1.125 math_inset.C
--- mathed/math_inset.C 5 Nov 2003 12:06:20 -0000       1.125
+++ mathed/math_inset.C 15 Jan 2004 11:16:25 -0000
@@ -116,9 +116,9 @@ bool MathInset::idxEnd(idx_type &, pos_t
 }
 
 
-void MathInset::getPos(idx_type, pos_type, int & x, int & y) const
+void MathInset::getScreenPos(idx_type, pos_type, int & x, int & y) const
 {
-       lyxerr << "MathInset::getPos() called directly!" << endl;
+       lyxerr << "MathInset::getScreenPos() called directly!" << endl;
        x = y = 0;
 }
 
Index: mathed/math_inset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_inset.h,v
retrieving revision 1.173
diff -u -p -r1.173 math_inset.h
--- mathed/math_inset.h 7 Jan 2004 18:28:50 -0000       1.173
+++ mathed/math_inset.h 15 Jan 2004 11:16:25 -0000
@@ -79,6 +79,8 @@ class MathInset : public InsetBase {
 public:
        /// our members behave nicely...
        MathInset() {}
+       /// identification as math inset
+       MathInset * asMathInset() { return this; }
 
        /// substitutes macro arguments if necessary
        virtual void substitute(MathMacro const & macro);
@@ -150,7 +152,7 @@ public:
        /// can we enter this cell?
        virtual bool validCell(idx_type) const { return true; }
        /// get coordinates
-       virtual void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
+       virtual void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const;
 
        /// identifies certain types of insets
        virtual MathAMSArrayInset       * asAMSArrayInset()       { return 0; }
Index: mathed/math_nestinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_nestinset.C,v
retrieving revision 1.78
diff -u -p -r1.78 math_nestinset.C
--- mathed/math_nestinset.C     7 Jan 2004 18:28:50 -0000       1.78
+++ mathed/math_nestinset.C     15 Jan 2004 11:16:25 -0000
@@ -45,7 +45,7 @@ MathArray const & MathNestInset::cell(id
 }
 
 
-void MathNestInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const
+void MathNestInset::getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const
 {
        MathArray const & ar = cell(idx);
        x = ar.xo() + ar.pos2x(pos);
Index: mathed/math_nestinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_nestinset.h,v
retrieving revision 1.46
diff -u -p -r1.46 math_nestinset.h
--- mathed/math_nestinset.h     7 Jan 2004 18:28:50 -0000       1.46
+++ mathed/math_nestinset.h     15 Jan 2004 11:16:25 -0000
@@ -40,7 +40,7 @@ public:
        /// identifies NestInsets
        MathNestInset const * asNestInset() const { return this; }
        /// get cursor position
-       void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
+       void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const;
 
        /// order of movement through the cells when pressing the left key
        bool idxLeft(idx_type & idx, pos_type & pos) const;
Index: mathed/math_textinset.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_textinset.C,v
retrieving revision 1.16
diff -u -p -r1.16 math_textinset.C
--- mathed/math_textinset.C     7 Sep 2003 21:25:37 -0000       1.16
+++ mathed/math_textinset.C     15 Jan 2004 11:16:25 -0000
@@ -40,11 +40,11 @@ MathInset::idx_type MathTextInset::pos2r
 }
 
 
-void MathTextInset::getPos(idx_type /*idx*/, pos_type pos, int & x, int & y) const
+void MathTextInset::getScreenPos(idx_type /*idx*/, pos_type pos, int & x, int & y) 
const
 {
        idx_type const i = pos2row(pos);
        pos_type const p = pos - cache_.cellinfo_[i].begin_;
-       cache_.getPos(i, p, x, y);
+       cache_.getScreenPos(i, p, x, y);
        y = cache_.cell(i).yo();
 }
 
Index: mathed/math_textinset.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_textinset.h,v
retrieving revision 1.11
diff -u -p -r1.11 math_textinset.h
--- mathed/math_textinset.h     19 Aug 2003 13:00:56 -0000      1.11
+++ mathed/math_textinset.h     15 Jan 2004 11:16:25 -0000
@@ -24,7 +24,7 @@ public:
        ///
        virtual std::auto_ptr<InsetBase> clone() const;
        /// get cursor position
-       void getPos(idx_type idx, pos_type pos, int & x, int & y) const;
+       void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const;
        /// this stores metrics information in cache_
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        /// draw according to cached metrics

Reply via email to