From a415942e0172aa7d820049d2043d45d778624cb5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 20 Nov 2001 09:06:12 +0000 Subject: [PATCH] small mouse click stuff. still not ok... git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3046 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formulabase.C | 82 +++++++++++++++++++----------------- src/mathed/math_arrayinset.C | 2 + src/mathed/math_cursor.C | 13 +++++- src/mathed/math_cursor.h | 4 +- 4 files changed, 61 insertions(+), 40 deletions(-) diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index a2cb097665..4ad563632d 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -56,7 +56,8 @@ namespace { // local global int sel_x; int sel_y; -bool sel_flag; +int last_x; +int last_y; void handleFont(BufferView * bv, MathTextCodes t) @@ -134,9 +135,6 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int /*y*/, unsigned int) // if that is removed, we won't get the magenta box when entering an // inset for the first time bv->updateInset(this, false); - sel_x = 0; - sel_y = 0; - sel_flag = false; } @@ -198,21 +196,21 @@ void InsetFormulaBase::toggleInsetCursor(BufferView * bv) void InsetFormulaBase::showInsetCursor(BufferView * bv, bool) { - if (!isCursorVisible()) { - if (mathcursor) { - int x; - int y; - mathcursor->getPos(x, y); - int asc = 0; - int des = 0; - MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT); - math_font_max_dim(LM_TC_TEXTRM, mi, asc, des); - //bv->fitLockedInsetCursor(x, y, asc, des); - //metrics(bv); - //lyxerr << "showInsetCursor: " << x << " " << y << "\n"; - } - toggleInsetCursor(bv); + if (isCursorVisible()) + return; + if (mathcursor) { + int x; + int y; + mathcursor->getPos(x, y); + int asc = 0; + int des = 0; + MathMetricsInfo mi(bv, font_, display() ? LM_ST_DISPLAY : LM_ST_TEXT); + math_font_max_dim(LM_TC_TEXTRM, mi, asc, des); + //bv->fitLockedInsetCursor(x, y, asc, des); + //metrics(bv); + //lyxerr << "showInsetCursor: " << x << " " << y << "\n"; } + toggleInsetCursor(bv); } @@ -244,46 +242,54 @@ void InsetFormulaBase::updateLocal(BufferView * bv, bool dirty) void InsetFormulaBase::insetButtonRelease(BufferView * bv, - int x, int y, int /*button*/) + int /*x*/, int /*y*/, int /*button*/) { - if (mathcursor) { - hideInsetCursor(bv); - mathcursor->setPos(x + xo_, y + yo_); - //lyxerr << "insetButtonRelease: " << x + xo_ << " " << y + yo_ << "\n"; - showInsetCursor(bv); - sel_flag = false; - bv->updateInset(this, false); - } + if (!mathcursor) + return; + hideInsetCursor(bv); + showInsetCursor(bv); + bv->updateInset(this, false); } void InsetFormulaBase::insetButtonPress(BufferView * bv, int x, int y, int /*button*/) { + if (!mathcursor) + return; //lyxerr << "insetButtonPress: " << x + xo_ << " " << y + yo_ << "\n"; - sel_flag = false; sel_x = x + xo_; sel_y = y + yo_; - if (mathcursor) - mathcursor->selStart(); + last_x = x; + last_y = y; + mathcursor->setPos(x + xo_, y + yo_); + mathcursor->selStart(); bv->updateInset(this, false); } void InsetFormulaBase::insetMotionNotify(BufferView * bv, - int x, int y, int /*button*/) + int x, int y, int button) { - //lyxerr << "insetMotionNotify: " << x + xo_ << " " << y + yo_ << "\n"; - if (abs(x - sel_x) > 4 && !sel_flag) - sel_flag = true; + if (!mathcursor) + return; - if (sel_flag) { + if (abs(x - last_x) < 2 && abs(y - last_y) < 2) { + //lyxerr << "insetMotionNotify: ignored\n"; + return; + } + last_x = x; + last_y = y; + + //lyxerr << "insetMotionNotify: " << x + xo_ << " " << y + yo_ + // << ' ' << button << "\n"; + if (button == 256) { hideInsetCursor(bv); mathcursor->setPos(x + xo_, y + xo_); showInsetCursor(bv); - mathcursor->getPos(x, y); - if (sel_x != x || sel_y != y) - bv->updateInset(this, false); + bv->updateInset(this, false); + } else { + insetButtonPress(bv, x, y, button); } } diff --git a/src/mathed/math_arrayinset.C b/src/mathed/math_arrayinset.C index 97240cb67c..862e3b4173 100644 --- a/src/mathed/math_arrayinset.C +++ b/src/mathed/math_arrayinset.C @@ -2,6 +2,8 @@ #pragma implementation #endif +#include + #include "math_arrayinset.h" #include "math_parser.h" #include "math_mathmlstream.h" diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index b7cde31ef2..274b8bf522 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -369,7 +369,7 @@ void MathCursor::last() } -void MathCursor::setPos(int x, int y) +void MathCursor::setPos(int x, int y, bool respect_anchor) { //dump("setPos 1"); //lyxerr << "MathCursor::setPos x: " << x << " y: " << y << "\n"; @@ -408,6 +408,17 @@ void MathCursor::setPos(int x, int y) pushRight(prevAtom()); else break; + + if (respect_anchor) { + if (Cursor_.size() > Anchor_.size()) { + popLeft(); + break; + } + if (Anchor_[Cursor_.size() - 1].par_ != Cursor_.back().par_) { + popLeft(); + break; + } + } } //dump("setPos 2"); } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 0bb6d0063d..3aa02de956 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -110,7 +110,9 @@ public: /// void delLine(); /// This is in pixels from (maybe?) the top of inset - void setPos(int, int); + // don't move further in than the Anchor's inset if respect_anchor == true + void setPos(int x, int y, bool respect_anchor = false); + /// This is in pixels from (maybe?) the top of inset, don't move further /// void getPos(int & x, int & y); /// -- 2.39.2