]> git.lyx.org Git - lyx.git/commitdiff
move things around
authorAndré Pönitz <poenitz@gmx.net>
Fri, 26 Jul 2002 14:11:19 +0000 (14:11 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 26 Jul 2002 14:11:19 +0000 (14:11 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4798 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/formulabase.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_iterator.C
src/mathed/math_iterator.h
src/mathed/math_parboxinset.C

index 03cdf19d6c7931102dcc21a18e80ec2021c4ba4a..dbc150a52fcd4fb0cbcc830dd662b69d9b5317e5 100644 (file)
@@ -882,7 +882,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
        //lyxerr << "searching '" << str << "' in " << this << ar << endl;
 
        for (MathIterator it = current; it != iend(par().nucleus()); ++it) {
-               if (it.cell().matchpart(ar, it.position().pos_)) {
+               if (it.cell().matchpart(ar, it.back().pos_)) {
                        bv->unlockInset(bv->theLockingInset());
                        if (!bv->lockInset(this)) {
                                lyxerr << "Cannot lock inset" << endl;
@@ -891,7 +891,7 @@ bool InsetFormulaBase::searchForward(BufferView * bv, string const & str,
                        delete mathcursor;
                        mathcursor = new MathCursor(this, true);
                        metrics(bv);
-                       mathcursor->setSelection(it.cursor(), ar.size());
+                       mathcursor->setSelection(it, ar.size());
                        current = it;
                        it.jump(ar.size());
                        updateLocal(bv, false);
index 79e454e7e01806a478f228fdac93de4a9ec4b5a8..77b4a35697818f30b349e962ee69bd4581e510c9 100644 (file)
@@ -173,7 +173,7 @@ bool MathCursor::openable(MathAtom const & t, bool sel) const
        if (t->asScriptInset())
                return false;
 
-       if (!sel) {
+       if (sel) {
                // we can't move into anything new during selection
                if (depth() == Anchor_.size())
                        return false;
@@ -258,15 +258,14 @@ void MathCursor::last()
 }
 
 
-bool positionable(MathCursor::cursor_type const & cursor,
-                 MathCursor::cursor_type const & anchor)
+bool positionable(MathIterator const & cursor, MathIterator const & anchor)
 {
        // avoid deeper nested insets when selecting
        if (cursor.size() > anchor.size())
                return false;
 
        // anchor might be deeper, should have same path then
-       for (MathCursor::cursor_type::size_type i = 0; i < cursor.size(); ++i)
+       for (MathIterator::size_type i = 0; i < cursor.size(); ++i)
                if (cursor[i].par_ != anchor[i].par_)
                        return false;
 
@@ -522,7 +521,7 @@ bool MathCursor::up(bool sel)
        dump("up 1");
        macroModeClose();
        selHandle(sel);
-       cursor_type save = Cursor_;
+       MathIterator save = Cursor_;
        if (goUpDown(true))
                return true;
        Cursor_ = save;
@@ -536,7 +535,7 @@ bool MathCursor::down(bool sel)
        dump("down 1");
        macroModeClose();
        selHandle(sel);
-       cursor_type save = Cursor_;
+       MathIterator save = Cursor_;
        if (goUpDown(false))
                return true;
        Cursor_ = save;
@@ -845,8 +844,8 @@ void MathCursor::pullArg()
 
 void MathCursor::touch()
 {
-       cursor_type::const_iterator it = Cursor_.begin();
-       cursor_type::const_iterator et = Cursor_.end();
+       MathIterator::const_iterator it = Cursor_.begin();
+       MathIterator::const_iterator et = Cursor_.end();
        for ( ; it != et; ++it)
                it->xcell().touch();
 }
@@ -1191,23 +1190,23 @@ bool MathCursor::goUpDown(bool up)
 bool MathCursor::bruteFind
        (int x, int y, int xlow, int xhigh, int ylow, int yhigh)
 {
-       cursor_type best_cursor;
+       MathIterator best_cursor;
        double best_dist = 1e10;
 
        MathIterator it = ibegin(formula()->par().nucleus());
        MathIterator et = iend(formula()->par().nucleus());
        while (1) {
                // avoid invalid nesting when selecting
-               if (!selection_ || positionable(it.cursor(), Anchor_)) {
+               if (!selection_ || positionable(it, Anchor_)) {
                        int xo, yo;
-                       it.position().getPos(xo, yo);
+                       it.back().getPos(xo, yo);
                        if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) {
                                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'
                                if (d <= best_dist) {
                                        best_dist   = d;
-                                       best_cursor = it.cursor();
+                                       best_cursor = it;
                                }
                        }
                }
@@ -1516,7 +1515,7 @@ bool MathCursor::interpret(char c)
 }
 
 
-void MathCursor::setSelection(cursor_type const & where, size_type n)
+void MathCursor::setSelection(MathIterator const & where, size_type n)
 {
        selection_ = true;
        Anchor_ = where;
index 161b70e3b1466cf474fcd210872ea41ac1391436..38481da4839a82cb9760d88f6a71f66d2f4da8bf 100644 (file)
@@ -22,7 +22,7 @@
 #endif
 
 #include "math_inset.h"
-#include "math_pos.h"
+#include "math_iterator.h"
 #include "LString.h"
 
 class InsetFormulaBase;
@@ -36,9 +36,9 @@ class Selection;
 [Have a look at math_inset.h first]
 
 The MathCursor is different from the kind of cursor used in the Outer
-World. It contains a stack of MathCursorPositions, each of which is made
+World. It contains a stack of MathCursorPos, each of which is made
 up of a inset pointer, an index and a position offset, marking a path from
-this formula's mathHullInset to the current position.
+this formula's MathHullInset to the current position.
 
 */
 
@@ -55,8 +55,6 @@ public:
        typedef MathInset::row_type        row_type;
        /// type for column numbers
        typedef MathInset::col_type        col_type;
-       /// how to store a cursor
-       typedef std::vector<MathCursorPos> cursor_type;
 
        ///
        explicit MathCursor(InsetFormulaBase *, bool left);
@@ -246,7 +244,7 @@ public:
        /// dump selection information for debugging
        void dump(char const * str) const;
        /// moves on
-       void setSelection(cursor_type const & where, size_type n);
+       void setSelection(MathIterator const & where, size_type n);
        ///
        void insert(char c);
        ///
@@ -303,9 +301,9 @@ private:
        idx_type & idx();
 
        /// path of positions the cursor had to go if it were leaving each inset
-       cursor_type Cursor_;
+       MathIterator Cursor_;
        /// path of positions the anchor had to go if it were leaving each inset
-       mutable cursor_type Anchor_;
+       mutable MathIterator Anchor_;
        /// pointer to enclsing LyX inset
        InsetFormulaBase * formula_;
        // Selection stuff
index 628ead5cab346f3afc8ceaf414ea822801c93676..087c5f27d565db4ee38ef5978b9eaaad4db73580 100644 (file)
@@ -1,12 +1,13 @@
 #include <config.h>
 
 #include "math_iterator.h"
+#include "math_inset.h"
 #include "debug.h"
 #include "support/LAssert.h"
 
 
-//MathIterator::MathIterator()
-//{}
+MathIterator::MathIterator()
+{}
 
 
 MathIterator::MathIterator(MathInset * p)
@@ -15,32 +16,21 @@ MathIterator::MathIterator(MathInset * p)
 }
 
 
-//MathIterator::MathIterator(MathCursor::cursor_type const & c)
-//     : cursor_(c)
-//{}
-
-
-MathCursor::cursor_type const & MathIterator::cursor() const
-{
-       return cursor_;
-}
-
-
 MathInset const * MathIterator::par() const
 {
-       return position().par_;
+       return back().par_;
 }
 
 
 MathInset * MathIterator::par()
 {
-       return position().par_;
+       return back().par_;
 }
 
 
 MathArray const & MathIterator::cell() const
 {
-       MathCursorPos const & top = position();
+       MathCursorPos const & top = back();
        return top.par_->cell(top.idx_);
 }
 
@@ -49,33 +39,33 @@ MathArray const & MathIterator::cell() const
 void MathIterator::push(MathInset * p)
 {
        //lyxerr << "push: " << p << endl;
-       cursor_.push_back(MathCursorPos(p));
+       push_back(MathCursorPos(p));
 }
 
 
 void MathIterator::pop()
 {
        //lyxerr << "pop: " << endl;
-       lyx::Assert(cursor_.size());
-       cursor_.pop_back();
+       lyx::Assert(size());
+       pop_back();
 }
 
 
 MathCursorPos const & MathIterator::operator*() const
 {
-       return position();
+       return back();
 }
 
 
 MathCursorPos const & MathIterator::operator->() const
 {
-       return position();
+       return back();
 }
 
 
 void MathIterator::goEnd()
 {
-       MathCursorPos & top = position();
+       MathCursorPos & top = back();
        top.idx_ = top.par_->nargs() - 1;
        top.pos_ = cell().size();
 }
@@ -83,7 +73,7 @@ void MathIterator::goEnd()
 
 void MathIterator::operator++()
 {
-       MathCursorPos   & top = position();
+       MathCursorPos   & top = back();
        MathArray const & ar  = top.par_->cell(top.idx_);
 
        // move into the current inset if possible
@@ -96,7 +86,7 @@ void MathIterator::operator++()
                return;
        }
 
-       // otherwise move on one cell position if possible
+       // otherwise move on one cell back if possible
        if (top.pos_ < ar.size()) {
                // pos() == size() is valid!
                ++top.pos_;
@@ -113,37 +103,31 @@ void MathIterator::operator++()
                }
        }
 
-       // otherwise leave array, move on one position
+       // otherwise leave array, move on one back
        // this might yield pos() == size(), but that's a ok.
        pop();
        // it certainly invalidates top
-       ++position().pos_;
+       ++back().pos_;
 }
 
 
-void MathIterator::jump(MathInset::difference_type i)
+void MathIterator::jump(difference_type i)
 {
-       position().pos_ += i;
-       //lyx::Assert(position().pos_ >= 0);
-       lyx::Assert(position().pos_ <= cell().size());
+       back().pos_ += i;
+       //lyx::Assert(back().pos_ >= 0);
+       lyx::Assert(back().pos_ <= cell().size());
 }
 
 
 bool operator==(MathIterator const & it, MathIterator const & jt)
 {
-       //lyxerr << "==: " << it.cursor().size() << " " << jt.cursor().size() << endl;
-       if (it.cursor().size() != jt.cursor().size())
-               return false;
-       return it.cursor() == jt.cursor();
+       return MathIterator::base_type(it) == MathIterator::base_type(jt);
 }
 
 
 bool operator!=(MathIterator const & it, MathIterator const & jt)
 {
-       //lyxerr << "!=: " << it.cursor().size() << " " << jt.cursor().size() << endl;
-       if (it.cursor().size() != jt.cursor().size())
-               return true;
-       return it.cursor() != jt.cursor();
+       return MathIterator::base_type(it) != MathIterator::base_type(jt);
 }
 
 
index d30bd4752998ba59c2d499f5935e6c45515d40d5..5d1e972a5eda19f07540ccee4a4f0fcc6d2c7683 100644 (file)
@@ -2,18 +2,33 @@
 #ifndef MATH_ITERATOR_H
 #define MATH_ITERATOR_H
 
-#include "math_cursor.h"
+#include "math_pos.h"
+#include <vector>
 
-// this helper struct is used for traversing math insets
+// this is used for traversing math insets
 
-class MathIterator {
+class MathIterator : private std::vector<MathCursorPos> {
 public:
-       /// default constructor, used for end of range
-       //MathIterator();
+       // re-use inherited stuff
+       typedef std::vector<MathCursorPos> base_type;
+       using base_type::clear;
+       using base_type::size;
+       using base_type::push_back;
+       using base_type::pop_back;
+       using base_type::back;
+       using base_type::begin;
+       using base_type::end;
+       using base_type::operator[];
+       using base_type::size_type;
+       using base_type::difference_type;
+       using base_type::const_iterator;
+       friend bool operator!=(MathIterator const &, MathIterator const &);
+       friend bool operator==(MathIterator const &, MathIterator const &);
+
+       /// default constructor
+       MathIterator();
        /// start with given inset
        explicit MathIterator(MathInset * p);
-       /// start with given position
-       //explicit MathIterator(MathCursor::cursor_type const & cursor);
        ///
        MathCursorPos const & operator*() const;
        ///
@@ -21,13 +36,7 @@ public:
        /// move on one step
        void operator++();
        /// move on several steps
-       void jump(MathInset::difference_type);
-       /// read access to top most item (inline after running gprof!)
-       MathCursorPos const & position() const { return cursor_.back(); }
-       /// write access to top most item
-       MathCursorPos & position() { return cursor_.back(); }
-       /// read access to full path
-       MathCursor::cursor_type const & cursor() const;
+       void jump(difference_type);
        /// read access to top most inset
        MathInset const * par() const;
        /// read access to top most inset
@@ -42,9 +51,6 @@ private:
        void push(MathInset *);
        /// own level up
        void pop();
-
-       /// current position
-       MathCursor::cursor_type cursor_;
 };
 
 ///
index a2ff54baf67d2a0423830c6a5045130d2fc0c103..459949cc5f1883f2fdb0430f816c6a6e98805011 100644 (file)
@@ -189,7 +189,7 @@ void MathParboxInset::metrics(MathMetricsInfo & mi) const
        dim_.w = lyx_width_;
        dim_.a = rows_.front().dim.a;
        dim_.d = rows_.back().dim.d + yo;
-       metricsMarkers();
+       metricsMarkers2();
        xcell(0).setDim(dim_);
 #endif
 }
@@ -203,7 +203,7 @@ void MathParboxInset::draw(MathPainterInfo & pi, int x, int y) const
 #else
        xcell(0).drawExternal(pi, x + 1, y, rows_);
 #endif
-       drawMarkers(pi, x, y);
+       drawMarkers2(pi, x, y);
 }