From b3eefc106e14aefca3baa0bb8270fc5d430531eb Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 13 Apr 2004 12:47:48 +0000 Subject: [PATCH] fix the cursor-y problem in math git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8646 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/cursor.C | 8 +++++--- src/insets/insetbase.C | 2 +- src/insets/insetbase.h | 2 +- src/insets/insettabular.C | 2 +- src/insets/insettabular.h | 4 ++-- src/insets/insettext.C | 6 +++--- src/insets/insettext.h | 2 +- src/mathed/math_mboxinset.C | 7 ++++--- src/mathed/math_mboxinset.h | 2 +- src/mathed/math_nestinset.C | 5 ++--- src/mathed/math_nestinset.h | 2 +- src/mathed/math_textinset.C | 6 +++--- src/mathed/math_textinset.h | 4 ++-- 13 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/cursor.C b/src/cursor.C index 41716183f4..9ae8bee4cb 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -270,7 +270,7 @@ void LCursor::getPos(int & x, int & y) const x = 0; y = 0; if (!empty()) - inset().getCursorPos(back(), x, y); + inset().getCursorPos(*this, x, y); } @@ -1085,7 +1085,8 @@ bool LCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh) // avoid invalid nesting when selecting if (!selection() || positionable(it, anchor_)) { int xo = 0, yo = 0; - CursorSlice & cur = it.back(); + LCursor cur = *this; + cur.setCursor(it, false); cur.inset().getCursorPos(cur, xo, yo); if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); @@ -1118,7 +1119,8 @@ void LCursor::bruteFind2(int x, int y) et.back().pos() = et.back().asMathInset()->cell(et.back().idx()).size(); for (int i = 0; ; ++i) { int xo, yo; - CursorSlice & cur = it.back(); + LCursor cur = *this; + cur.setCursor(it, false); cur.inset().getCursorPos(cur, xo, yo); double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); // '<=' in order to take the last possible position diff --git a/src/insets/insetbase.C b/src/insets/insetbase.C index 7bc3fc0b5b..f4f637e0a4 100644 --- a/src/insets/insetbase.C +++ b/src/insets/insetbase.C @@ -227,7 +227,7 @@ void InsetBase::markErased() {} -void InsetBase::getCursorPos(CursorSlice const &, int & x, int & y) const +void InsetBase::getCursorPos(LCursor const &, int & x, int & y) const { lyxerr << "InsetBase::getCursorPos called directly" << std::endl; x = 100; diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index 6c70bceed8..5f9e1c2ac9 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -106,7 +106,7 @@ public: /// do we cover screen position x/y? virtual bool covers(int x, int y) const; /// get the screen positions of the cursor (see note in cursor.C) - virtual void getCursorPos(CursorSlice const & cur, int & x, int & y) const; + virtual void getCursorPos(LCursor const & cur, int & x, int & y) const; /// is this an inset that can be moved into? virtual bool isActive() const { return nargs() > 0; } diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index 983be07164..770d259e7f 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -948,7 +948,7 @@ InsetText & InsetTabular::cell(int idx) } -void InsetTabular::getCursorPos(CursorSlice const & cur, int & x, int & y) const +void InsetTabular::getCursorPos(LCursor const & cur, int & x, int & y) const { cell(cur.idx()).getCursorPos(cur, x, y); } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index 48aaa35cd9..a12205c7d1 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -96,9 +96,9 @@ public: /// void validate(LaTeXFeatures & features) const; /// - InsetOld::Code lyxCode() const { return InsetOld::TABULAR_CODE; } + Code lyxCode() const { return InsetOld::TABULAR_CODE; } /// get the absolute screen x,y of the cursor - void getCursorPos(CursorSlice const & cur, int & x, int & y) const; + void getCursorPos(LCursor const & cur, int & x, int & y) const; /// bool tabularFeatures(LCursor & cur, std::string const & what); /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index 735c96e2fb..131557a2b6 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -388,10 +388,10 @@ void InsetText::validate(LaTeXFeatures & features) const } -void InsetText::getCursorPos(CursorSlice const & cur, int & x, int & y) const +void InsetText::getCursorPos(LCursor const & cur, int & x, int & y) const { - x = text_.cursorX(cur); - y = text_.cursorY(cur); + x = text_.cursorX(cur.top()); + y = text_.cursorY(cur.top()); } diff --git a/src/insets/insettext.h b/src/insets/insettext.h index 87e1153bc3..d89bb3413e 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -90,7 +90,7 @@ public: /// InsetOld::Code lyxCode() const { return InsetOld::TEXT_CODE; } /// FIXME, document - void getCursorPos(CursorSlice const & cur, int & x, int & y) const; + void getCursorPos(LCursor const & cur, int & x, int & y) const; /// void setFont(BufferView *, LyXFont const &, bool toggleall = false, diff --git a/src/mathed/math_mboxinset.C b/src/mathed/math_mboxinset.C index 083860cfa3..c3f090db00 100644 --- a/src/mathed/math_mboxinset.C +++ b/src/mathed/math_mboxinset.C @@ -17,6 +17,7 @@ #include "BufferView.h" #include "buffer.h" #include "bufferparams.h" +#include "cursor.h" #include "debug.h" #include "metricsinfo.h" #include "output_latex.h" @@ -101,8 +102,8 @@ LyXText * MathMBoxInset::getText(int) const } -void MathMBoxInset::getCursorPos(CursorSlice const & cur, int & x, int & y) const +void MathMBoxInset::getCursorPos(LCursor const & cur, int & x, int & y) const { - x = text_.cursorX(cur); - y = text_.cursorY(cur); + x = text_.cursorX(cur.top()); + y = text_.cursorY(cur.top()); } diff --git a/src/mathed/math_mboxinset.h b/src/mathed/math_mboxinset.h index c4cd9a20d5..9a8be27272 100644 --- a/src/mathed/math_mboxinset.h +++ b/src/mathed/math_mboxinset.h @@ -44,7 +44,7 @@ public: /// LyXText * getText(int) const; /// - void getCursorPos(CursorSlice const & cur, int & x, int & y) const; + void getCursorPos(LCursor const & cur, int & x, int & y) const; protected: /// mutable LyXText text_; diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index e4d0cfb34c..e471435cda 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -86,13 +86,12 @@ MathArray const & MathNestInset::cell(idx_type i) const } -void MathNestInset::getCursorPos(CursorSlice const & cur, - int & x, int & y) const +void MathNestInset::getCursorPos(LCursor const & cur, int & x, int & y) const { BOOST_ASSERT(ptr_cmp(&cur.inset(), this)); MathArray const & ar = cur.cell(); x = ar.xo() + ar.pos2x(cur.pos()); - y = ar.yo(); + y = ar.yo() + cur.bv().top_y(); // move cursor visually into empty cells ("blue rectangles"); if (cur.cell().empty()) x += 2; diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index d315ef306a..012f1542ae 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -37,7 +37,7 @@ public: /// identifies NestInsets MathNestInset const * asNestInset() const { return this; } /// get cursor position - void getCursorPos(CursorSlice const & cur, int & x, int & y) const; + void getCursorPos(LCursor const & cur, int & x, int & y) const; /// void edit(LCursor & cur, bool left); /// diff --git a/src/mathed/math_textinset.C b/src/mathed/math_textinset.C index 9219d99523..7f1e870884 100644 --- a/src/mathed/math_textinset.C +++ b/src/mathed/math_textinset.C @@ -13,7 +13,7 @@ #include "math_textinset.h" #include "math_data.h" -#include "cursor_slice.h" +#include "cursor.h" #include "debug.h" #include "metricsinfo.h" @@ -42,9 +42,9 @@ MathInset::idx_type MathTextInset::pos2row(pos_type pos) const } -void MathTextInset::getCursorPos(CursorSlice const & cur, int & x, int & y) const +void MathTextInset::getCursorPos(LCursor const & cur, int & x, int & y) const { - CursorSlice c = cur; + LCursor c = cur; c.idx() = pos2row(cur.pos()); c.pos() -= cache_.cellinfo_[c.idx()].begin_; cache_.getCursorPos(c, x, y); diff --git a/src/mathed/math_textinset.h b/src/mathed/math_textinset.h index 04826766c0..c9a82d13b1 100644 --- a/src/mathed/math_textinset.h +++ b/src/mathed/math_textinset.h @@ -22,9 +22,9 @@ public: /// MathTextInset(); /// - virtual std::auto_ptr clone() const; + std::auto_ptr clone() const; /// get cursor position - void getCursorPos(CursorSlice const & cur, int & x, int & y) const; + void getCursorPos(LCursor const & cur, int & x, int & y) const; /// this stores metrics information in cache_ void metrics(MetricsInfo & mi, Dimension & dim) const; /// draw according to cached metrics -- 2.39.2