From 08c784de22815ba5f640eee1e6be311e805863b8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Wed, 8 Aug 2001 09:31:36 +0000 Subject: [PATCH] proper cursor up/down for centered and right aligned grid columns git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2450 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/formula.C | 3 -- src/mathed/math_cursor.C | 55 +++++++++++++++++++++++++------------ src/mathed/math_cursor.h | 15 ++++++---- src/mathed/math_gridinset.C | 33 ++++++++++++++-------- src/mathed/math_gridinset.h | 4 +++ src/mathed/math_inset.h | 4 +++ 6 files changed, 77 insertions(+), 37 deletions(-) diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 88dacdbed8..3dba3bc584 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -172,9 +172,6 @@ InsetFormula::localDispatch(BufferView * bv, kb_action action, case LFUN_BREAKLINE: bv->lockedInsetStoreUndo(Undo::INSERT); - int x; - int y; - mathcursor->getPos(x, y); mathcursor->breakLine(); mathcursor->normalize(); updateLocal(bv, true); diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index b78c6a7405..6efdbdf294 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -906,6 +906,9 @@ void MathCursor::handleNest(MathInset * p) void MathCursor::getPos(int & x, int & y) { +#ifdef WITH_WARNINGS +#warning This should probably take cellXOffset and cellYOffset into account +#endif x = xarray().xo() + xarray().pos2x(pos()); y = xarray().yo(); } @@ -1142,19 +1145,6 @@ MathXArray & MathCursor::xarray() const } -int MathCursor::xpos() const -{ - normalize(); - return xarray().pos2x(pos()); -} - - -void MathCursor::gotoX(int x) -{ - pos() = xarray().x2pos(x); -} - - void MathCursor::idxNext() { par()->idxNext(idx(), pos()); @@ -1305,22 +1295,53 @@ MathCursorPos MathCursor::normalAnchor() const } +int MathCursor::cellXOffset() const +{ + return par()->cellXOffset(idx()); +} + + +int MathCursor::cellYOffset() const +{ + return par()->cellYOffset(idx()); +} + + +int MathCursor::xpos() const +{ + return cellXOffset() + xarray().pos2x(pos()); +} + + +int MathCursor::ypos() const +{ + return cellYOffset(); +} + + + +void MathCursor::gotoX(int x) +{ + pos() = xarray().x2pos(x - cellXOffset()); +} + + bool MathCursor::idxUp() { - int x = xarray().pos2x(pos()); + int x = xpos(); if (!par()->idxUp(idx(), pos())) return false; - pos() = xarray().x2pos(x); + gotoX(x); return true; } bool MathCursor::idxDown() { - int x = xarray().pos2x(pos()); + int x = xpos(); if (!par()->idxDown(idx(), pos())) return false; - pos() = xarray().x2pos(x); + gotoX(x); return true; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 6404f49427..8e700b943a 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -245,11 +245,6 @@ public: /// void dump(char const * str) const; - /// - int xpos() const; - /// - void gotoX(int x); - /// void merge(MathArray const & arr); /// @@ -265,6 +260,16 @@ private: int & pos(); /// int & idx(); + /// x-offset of current cell relative to par xo + int cellXOffset() const; + /// y-offset of current cell relative to par yo + int cellYOffset() const; + /// current x position relative to par xo + int xpos() const; + /// current y position relative to par yo + int ypos() const; + /// adjust position in current cell according to x. idx is not changed. + void gotoX(int x); /// InsetFormulaBase * const formula_; diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 2648283d11..5cb230c18c 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -193,22 +193,13 @@ void MathGridInset::metrics(MathStyles st) const */ } + void MathGridInset::draw(Painter & pain, int x, int y) const { xo(x); yo(y); - for (int row = 0; row < nrows(); ++row) { - int yy = y + rowinfo_[row].offset_; - for (int col = 0; col < ncols(); ++col) { - int xx = x + colinfo_[col].offset_; - char align = colinfo_[col].h_align_; - if (align == 'r' || align == 'R') - xx += colinfo_[col].width_ - xcell(index(row, col)).width(); - if (align == 'c' || align == 'C') - xx += (colinfo_[col].width_ - xcell(index(row, col)).width()) / 2; - xcell(index(row, col)).draw(pain, xx, yy); - } - } + for (int idx = 0; idx < nargs(); ++idx) + xcell(idx).draw(pain, x + cellXOffset(idx), y + cellYOffset(idx)); } @@ -283,6 +274,24 @@ void MathGridInset::delCol(int col) } +int MathGridInset::cellXOffset(int idx) const +{ + int c = col(idx); + int x = colinfo_[c].offset_; + char align = colinfo_[c].h_align_; + if (align == 'r' || align == 'R') + x += colinfo_[c].width_ - xcell(idx).width(); + if (align == 'c' || align == 'C') + x += (colinfo_[c].width_ - xcell(idx).width()) / 2; + return x; +} + + +int MathGridInset::cellYOffset(int idx) const +{ + return rowinfo_[row(idx)].offset_; +} + bool MathGridInset::idxUp(int & idx, int & pos) const { if (idx < ncols()) diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index b3a7e9c522..1b4e4ca269 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -86,6 +86,10 @@ public: int col(int idx) const { return idx % ncols(); } /// int row(int idx) const { return idx / ncols(); } + /// + int cellXOffset(int idx) const; + /// + int cellYOffset(int idx) const; /// bool idxUp(int &, int &) const; diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index c2475b1d14..6ff7f6c338 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -150,6 +150,10 @@ public: /// virtual int row(int) const { return 0; } /// + virtual int cellXOffset(int) const { return 0; } + /// + virtual int cellYOffset(int) const { return 0; } + /// virtual void addRow(int) {} /// virtual void delRow(int) {} -- 2.39.2