]> git.lyx.org Git - lyx.git/commitdiff
fix cursor positioning using the mouse
authorAndré Pönitz <poenitz@gmx.net>
Tue, 11 Sep 2001 12:46:58 +0000 (12:46 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 11 Sep 2001 12:46:58 +0000 (12:46 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2724 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/array.C
src/mathed/math_atom.C
src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_inset.C
src/mathed/math_scriptinset.C

index 5b9b7cbbdad6d87718b1052996ed3505f12fb8b0..9460af42045c24f4498ed9f01e38ac84abe109b1 100644 (file)
@@ -52,7 +52,7 @@ MathAtom const * MathArray::at(int pos) const
 void MathArray::insert(int pos, MathInset * p)
 {
        //cerr << "\n  1: "; p->write(cerr, true); cerr << p << "\n";
-       // inserting th
+       // inserting here invalidates the pointer!
        bf_.insert(begin() + pos, MathAtom(p));
        //cerr << "\n  2: "; p->write(cerr, true); cerr << p << "\n";
 }
index 33ae8e4bf782f3163dbeb8b51ecba27ae8d8c187..217f10906956974a9413f6a8c17fafe5fe9d322e 100644 (file)
@@ -315,9 +315,9 @@ void MathAtom::draw(Painter & pain, int x, int y) const
        if (nucleus())
                nucleus()->draw(pain, x + dxx(), y);
        if (up())
-               up()->xcell(0).draw(pain, x + dx1(), y - dy1());
+               up()->draw(pain, x + dx1(), y - dy1());
        if (down())
-               down()->xcell(0).draw(pain, x + dx0(), y + dy0());
+               down()->draw(pain, x + dx0(), y + dy0());
 }
 
 
index f9a8524493372a0936a0917c43fda1d17fcc6b22..e334f75eba2dd20a74891dc8a966868b16c4faf2 100644 (file)
@@ -232,22 +232,34 @@ bool MathCursor::openable(MathInset * p, bool sel) const
 }
 
 
-bool MathCursor::positionable(MathInset * p, bool sel) const
+MathInset * MathCursor::positionable(MathAtom * t, int x, int y) const
 {
-       if (!p)
-               return false;
-
-       if (!p->nargs())
-               return false;
+       if (!t)
+               return 0;
 
-       if (sel) {
+       if (selection_) {
                // we can't move into anything new during selection
                if (Cursor_.size() == Anchor_.size())
-                       return false;
-               if (p != Anchor_[Cursor_.size()].par_)
-                       return false;
+                       return 0;
+               //if (t != Anchor_[Cursor_.size()].par_)
+               //      return 0;
        }
-       return true;
+
+       MathInset * p;
+
+       p = t->nucleus();
+       if (p && p->nargs() && p->covers(x, y))
+               return p;
+
+       p = t->up();
+       if (p && p->nargs() && p->covers(x, y))
+               return p;
+
+       p = t->down();
+       if (p && p->nargs() && p->covers(x, y))
+               return p;
+
+       return 0;
 }
 
 
@@ -327,7 +339,7 @@ void MathCursor::last()
 
 void MathCursor::setPos(int x, int y)
 {
-       dump("setPos 1");
+       //dump("setPos 1");
        //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n";
 
        macroModeClose();
@@ -339,7 +351,7 @@ void MathCursor::setPos(int x, int y)
        while (1) {
                idx() = -1;
                cursor().pos_ = -1;
-               //lyxerr << "found idx: " << idx_ << " cursor: " << pos()  << "\n";
+               //lyxerr << "found idx: " << idx() << " cursor: " << pos()  << "\n";
                int distmin = 1 << 30; // large enough
                for (int i = 0; i < par()->nargs(); ++i) {
                        MathXArray const & ar = par()->xcell(i);
@@ -351,23 +363,21 @@ void MathCursor::setPos(int x, int y)
                        //lyxerr << "idx: " << i << " xx: " << xx << " yy: " << yy
                        //      << " c: " << c  << " xo: " << ar.xo() << "\n";
                        if (yy + xx <= distmin) {
-                               distmin        = yy + xx;
-                               idx()  = i;
-                               pos()  = c;
+                               distmin = yy + xx;
+                               idx()   = i;
+                               pos()   = c;
                        }
                }
                //lyxerr << "found idx: " << idx() << " cursor: "
                //      << pos()  << "\n";
-               MathInset * n = nextInset();
-               MathInset * p = prevInset();
-               if (positionable(n, selection_) && n->covers(x, y))
-                       pushLeft(n);
-               else if (positionable(p, selection_) && p->covers(x, y))
+               if (MathInset * p = positionable(nextAtom(), x, y))
+                       pushLeft(p);
+               else if (MathInset * p = positionable(prevAtom(), x, y))
                        pushRight(p);
                else 
                        break;
        }
-       dump("setPos 2");
+       //dump("setPos 2");
 }
 
 
index 3b9d2eb4912a4da8d447605558b14b516033b9e9..34f93337891f9851ef2ed385b9fc0977e621b927 100644 (file)
@@ -259,7 +259,7 @@ private:
        /// can we enter the inset? 
        bool openable(MathInset *, bool selection) const;
        /// can the setPos routine enter that inset?
-       bool positionable(MathInset *, bool selection) const;
+       MathInset * positionable(MathAtom *, int x, int y) const;
        /// write access to cursor cell position
        int & pos();
        /// write access to cursor cell index
index e9e4bb654bc82dbd2cb9acde22b38094b1d93809..e132d5ce50bd39317aef40817b5b397005b7dad3 100644 (file)
@@ -267,6 +267,8 @@ void MathInset::push_back(MathInset *)
 
 bool MathInset::covers(int x, int y) const
 {
+       //lyxerr << "cover? p: " << this << " x: " << x << " y: " <<  y
+       //      << " xo_: " << xo_ << " yo_: " << yo_  << endl;
        return
                x >= xo_ &&
                x <= xo_ + width() &&
index a8bf9d6b7b64d1c0489437d7c13406c3bc6ba661..019c045e37ed8a7129bf452deedce02c237961f8 100644 (file)
@@ -1,6 +1,5 @@
 #include <config.h>
 #include "debug.h"
-#include "support.h"
 #include "support/LOstream.h"
 
 #ifdef __GNUG__
@@ -20,92 +19,6 @@ MathInset * MathScriptInset::clone() const
        return new MathScriptInset(*this);
 }
 
-#if 0
-
-bool MathScriptInset::idxUp(int & idx, int & pos) const
-{
-       if (idx == 0 || !up()) 
-               return false;
-       idx = 0;
-       pos = 0;
-       return true;
-}
-
-bool MathScriptInset::idxDown(int & idx, int & pos) const
-{
-       if (idx == 1 || !down()) 
-               return false;
-       idx = 1;
-       pos = 0;
-       return true;
-}
-
-bool MathScriptInset::idxFirst(int & idx, int & pos) const
-{
-       idx = up() ? 0 : 1;
-       pos = 0;
-       return true;
-}
-
-bool MathScriptInset::idxLast(int & idx, int & pos) const
-{
-       idx = down() ? 1 : 0;
-       pos = cell(idx).size();
-       return true;
-}
-
-
-bool MathScriptInset::idxFirstUp(int & idx, int & pos) const
-{
-       if (!up()) 
-               return false;
-       idx = 0;
-       pos = 0;
-       return true;
-}
-
-
-bool MathScriptInset::idxFirstDown(int & idx, int & pos) const
-{
-       if (!down()) 
-               return false;
-       idx = 1;
-       pos = 0;
-       return true;
-}
-
-
-bool MathScriptInset::idxLastUp(int & idx, int & pos) const
-{
-       if (!up()) 
-               return false;
-       idx = 0;
-       pos = cell(idx).size();
-       return true;
-}
-
-
-bool MathScriptInset::idxLastDown(int & idx, int & pos) const
-{
-       if (!down()) 
-               return false;
-       idx = 1;
-       pos = cell(idx).size();
-       return true;
-}
-
-void MathScriptInset::idxDelete(int & idx, bool & popit, bool & deleteit)
-{
-       if (idx == 0) 
-               up(false);
-       else
-               down(false);
-       popit = true;
-       deleteit = !(up() || down());
-}
-
-#endif
-
 
 void MathScriptInset::write(std::ostream & os, bool fragile) const
 {