]> git.lyx.org Git - features.git/commitdiff
some renaming + safety stuff
authorAndré Pönitz <poenitz@gmx.net>
Thu, 15 Jan 2004 11:58:35 +0000 (11:58 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 15 Jan 2004 11:58:35 +0000 (11:58 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8353 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/BufferView.C
src/cursor_slice.C
src/cursor_slice.h
src/insets/insetbase.h
src/insets/updatableinset.h
src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_inset.C
src/mathed/math_inset.h
src/mathed/math_nestinset.C
src/mathed/math_nestinset.h
src/mathed/math_textinset.C
src/mathed/math_textinset.h

index ca388dc4cf0a0078c8a1ede2ff2baab59507901b..aca0952c6ee8d450ddd6ffa8a4e56b69314fd842 100644 (file)
@@ -614,3 +614,8 @@ void BufferView::putSelectionAt(PosIterator const & cur,
        update();
 }
 
+
+CursorSlice & cursorTip(BufferView & bv)
+{
+       return bv.cursor();
+}
index 4427fc3984f0647fe7b2644f306e475d1b8996e3..ce9b4605c392a04c5f669785ee775dfaa67b286c 100644 (file)
@@ -89,41 +89,34 @@ bool CursorSlice::boundary() const
 
 MathInset * CursorSlice::asMathInset() const
 {
-       return static_cast<MathInset *>(const_cast<InsetBase *>(inset_));
+       return inset_ ? inset_->asMathInset() : 0;
 }
 
 
 UpdatableInset * CursorSlice::asUpdatableInset() const
 {
-       return static_cast<UpdatableInset *>(const_cast<InsetBase *>(inset_));
+       return inset_ ? inset_->asUpdatableInset() : 0;
 }
 
 
-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
+void CursorSlice::getScreenPos(int & x, int & y) const
 {
-       BOOST_ASSERT(inset_);
-       asMathInset()->getPos(idx_, pos_, x, y);
-}
-
-
-void CursorSlice::setPos(int pos)
-{
-       pos_ = pos;
+       BOOST_ASSERT(asMathInset());
+       asMathInset()->getScreenPos(idx_, pos_, x, y);
 }
 
 
index 48a850b98f48345763d5ec001e866fc74540f27f..0b557bff9d277ad9b7a25c2cedadc4a5c88155ca 100644 (file)
 
 #include "support/types.h"
 
+class BufferView;
 class InsetBase;
-class UpdatableInset;
 class MathInset;
-class LyXText;
 class MathArray;
+class LyXText;
+class UpdatableInset;
 
 
 /// This encapsulates a single slice of a document iterator as used e.g.
@@ -80,12 +81,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;
 
@@ -138,6 +137,9 @@ void increment(CursorBase &);
 CursorBase ibegin(InsetBase * p);
 ///
 CursorBase iend(InsetBase * p);
+///
+CursorSlice & cursorTip(BufferView &);
+
 
 
 #endif
index be2ed477d8eec58627c3d2a8383e0f2c4b52a6e0..a7de6df4ed622041bbe979f32df81eadcd7b7945 100644 (file)
 
 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 {
@@ -46,6 +48,11 @@ public:
        /// 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
        dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
index 592028bc44c91e09f9aa44548d53302138270ab6..b549dc212fd328c4e3e77da8808f2e8cc41d7b44 100644 (file)
@@ -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 3ff6ba7d170f9a37c827a6342223ded13313fdfd..899acf434e283a87d37cee2ec8440a6b1491ed5a 100644 (file)
@@ -166,33 +166,33 @@ void InsetFormulaBase::insetUnlock(BufferView * bv)
 
 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::lfunMouseRelease(FuncRequest const & cmd)
                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::lfunMouseRelease(FuncRequest const & cmd)
                //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::lfunMousePress(FuncRequest const & cmd)
                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::lfunMousePress(FuncRequest const & cmd)
                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::lfunMouseMotion(FuncRequest const & cmd)
                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 * bv, int x, int y)
        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(FuncRequest const & cmd,
                int y = 0;
                istringstream is(cmd.argument.c_str());
                is >> x >> y;
-               mathcursor->setPos(x, y);
+               mathcursor->setScreenPos(x, y);
                break;
        }
 
index f652c33f3c7c529dfcacf3614a5a968efd51ad70..11578c0f9973aaa221f4cbd46d1b094eed1ecae3 100644 (file)
@@ -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 const & a, int c)
 }
 
 
-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(FuncRequest const & cmd)
                        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 55efa1e017fb4adf7f02062d2b72516b4bc7e4f8..6bf922cbc0ea903dcd93f098b1a99297d90e2aea 100644 (file)
@@ -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 9c6299646d46591fbb3ae9df6eecf3efaa27b5dd..ae0226a884c600cf4f69d6dccb59fca0c22b97cd 100644 (file)
@@ -116,9 +116,9 @@ bool MathInset::idxEnd(idx_type &, pos_type &) const
 }
 
 
-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 779e590fa38925b9bf8b6341770de4b4abbac321..f3018235aaa2382e2de2d0df84de7d163a8f5eea 100644 (file)
@@ -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 36c90752345b9f5985e801c132b0b36cdbcdd3d5..a1a35f9652dee6bad5be6814940979871c646154 100644 (file)
@@ -45,7 +45,7 @@ MathArray const & MathNestInset::cell(idx_type i) const
 }
 
 
-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 5ec7b9234d546864bfe70b8fcf1f84a532448a1b..16bf5e7fe3cc5172896eec34c1c54837d6cce166 100644 (file)
@@ -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 39931d8f42bb6492f9b7c98511d1edd97a130008..9000c3cb7d854ddb0228b8f5eca1b7e4e0b547e6 100644 (file)
@@ -40,11 +40,11 @@ MathInset::idx_type MathTextInset::pos2row(pos_type pos) const
 }
 
 
-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 cd673f5362cdb58b4950c057971ba1aa5a747442..5bc34dc3f56522d4a0ec9ca7cfe453b42ede3c88 100644 (file)
@@ -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