From f7b38dbdc55ed671af3a7f78c931a92b4c431f27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Thu, 15 Jan 2004 11:58:35 +0000 Subject: [PATCH] some renaming + safety stuff git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8353 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.C | 5 +++++ src/cursor_slice.C | 23 +++++++------------- src/cursor_slice.h | 16 +++++++------- src/insets/insetbase.h | 11 ++++++++-- src/insets/updatableinset.h | 2 ++ src/mathed/formulabase.C | 42 ++++++++++++++++++------------------- src/mathed/math_cursor.C | 28 ++++++++++++------------- src/mathed/math_cursor.h | 4 ++-- src/mathed/math_inset.C | 4 ++-- src/mathed/math_inset.h | 4 +++- src/mathed/math_nestinset.C | 2 +- src/mathed/math_nestinset.h | 2 +- src/mathed/math_textinset.C | 4 ++-- src/mathed/math_textinset.h | 2 +- 14 files changed, 80 insertions(+), 69 deletions(-) diff --git a/src/BufferView.C b/src/BufferView.C index ca388dc4cf..aca0952c6e 100644 --- a/src/BufferView.C +++ b/src/BufferView.C @@ -614,3 +614,8 @@ void BufferView::putSelectionAt(PosIterator const & cur, update(); } + +CursorSlice & cursorTip(BufferView & bv) +{ + return bv.cursor(); +} diff --git a/src/cursor_slice.C b/src/cursor_slice.C index 4427fc3984..ce9b4605c3 100644 --- a/src/cursor_slice.C +++ b/src/cursor_slice.C @@ -89,41 +89,34 @@ bool CursorSlice::boundary() const MathInset * CursorSlice::asMathInset() const { - return static_cast(const_cast(inset_)); + return inset_ ? inset_->asMathInset() : 0; } UpdatableInset * CursorSlice::asUpdatableInset() const { - return static_cast(const_cast(inset_)); + return inset_ ? inset_->asUpdatableInset() : 0; } -MathArray & CursorSlice::cell(CursorSlice::idx_type idx) const +void CursorSlice::cell(CursorSlice::idx_type idx) const { - BOOST_ASSERT(inset_); BOOST_ASSERT(asMathInset()); - return asMathInset()->cell(idx); + asMathInset()->cell(idx); } MathArray & CursorSlice::cell() const { - BOOST_ASSERT(inset_); + BOOST_ASSERT(asMathInset()); return asMathInset()->cell(idx_); } -void CursorSlice::getPos(int & x, int & y) const +void CursorSlice::getScreenPos(int & x, int & y) const { - BOOST_ASSERT(inset_); - asMathInset()->getPos(idx_, pos_, x, y); -} - - -void CursorSlice::setPos(int pos) -{ - pos_ = pos; + BOOST_ASSERT(asMathInset()); + asMathInset()->getScreenPos(idx_, pos_, x, y); } diff --git a/src/cursor_slice.h b/src/cursor_slice.h index 48a850b98f..0b557bff9d 100644 --- a/src/cursor_slice.h +++ b/src/cursor_slice.h @@ -22,11 +22,12 @@ #include "support/types.h" +class BufferView; class InsetBase; -class UpdatableInset; class MathInset; -class LyXText; class MathArray; +class LyXText; +class UpdatableInset; /// This encapsulates a single slice of a document iterator as used e.g. @@ -80,12 +81,10 @@ public: /// /// returns cell corresponding to this position MathArray & cell() const; - /// returns cell corresponding to this position - MathArray & cell(idx_type idx) const; + /// set cell corresponding to this position + void cell(idx_type idx) const; /// gets screen position of the thing - void getPos(int & x, int & y) const; - /// set position - void setPos(int pos); + void getScreenPos(int & x, int & y) const; /// MathInset * asMathInset() const; @@ -138,6 +137,9 @@ void increment(CursorBase &); CursorBase ibegin(InsetBase * p); /// CursorBase iend(InsetBase * p); +/// +CursorSlice & cursorTip(BufferView &); + #endif diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index be2ed477d8..a7de6df4ed 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -18,12 +18,14 @@ class Buffer; class BufferView; +class DispatchResult; class FuncRequest; +class LaTeXFeatures; +class MathInset; class MetricsInfo; class Dimension; class PainterInfo; -class LaTeXFeatures; -class DispatchResult; +class UpdatableInset; /// Common base class to all insets class InsetBase { @@ -46,6 +48,11 @@ public: /// replicate ourselves virtual std::auto_ptr clone() const = 0; + /// identification as math inset + virtual MathInset * asMathInset() { return 0; } + /// identification as non-math inset + virtual UpdatableInset * asUpdatableInset() { return 0; } + // the real dispatcher DispatchResult dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos); diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index 592028bc44..b549dc212f 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -25,6 +25,8 @@ class UpdatableInset : public InsetOld { public: /// virtual EDITABLE editable() const; + /// identification as math inset + UpdatableInset * asUpdatableInset() { return this; } /// return the cursor pos, relative to the inset pos virtual void getCursorPos(int, int &, int &) const {} diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 3ff6ba7d17..899acf434e 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -166,33 +166,33 @@ void InsetFormulaBase::insetUnlock(BufferView * bv) void InsetFormulaBase::getCursor(BufferView &, int & x, int & y) const { - mathcursor->getPos(x, y); + mathcursor->getScreenPos(x, y); } void InsetFormulaBase::getCursorPos(int, int & x, int & y) const { - if (!mathcursor) { - lyxerr << "getCursorPos - should not happen"; + if (mathcursor) { + mathcursor->getScreenPos(x, y); + x = mathcursor->targetX(); + x -= xo_; + y -= yo_; + lyxerr << "InsetFormulaBase::getCursorPos: " << x << ' ' << y << endl; + } else { x = 0; y = 0; - return; + lyxerr << "getCursorPos - should not happen"; } - mathcursor->getPos(x, y); - x = mathcursor->targetX(); - x -= xo_; - y -= yo_; - lyxerr << "InsetFormulaBase::getCursorPos: " << x << ' ' << y << endl; } void InsetFormulaBase::getCursorDim(int & asc, int & desc) const { - if (!mathcursor) - return; - asc = 10; - desc = 2; - //math_font_max_dim(font_, asc, des); + if (mathcursor) { + asc = 10; + desc = 2; + //math_font_max_dim(font_, asc, des); + } } @@ -226,7 +226,7 @@ DispatchResult InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) MathArray ar; asArray(bv->getClipboard(), ar); mathcursor->selClear(); - mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); + mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); mathcursor->insert(ar); bv->update(); return DispatchResult(true, true); @@ -240,7 +240,7 @@ DispatchResult InsetFormulaBase::lfunMouseRelease(FuncRequest const & cmd) //delete mathcursor; //mathcursor = new MathCursor(this, x == 0); //metrics(bv); - //mathcursor->setPos(x + xo_, y + yo_); + //mathcursor->setScreenPos(x + xo_, y + yo_); return DispatchResult(true, true); } @@ -258,7 +258,7 @@ DispatchResult InsetFormulaBase::lfunMousePress(FuncRequest const & cmd) releaseMathCursor(bv); mathcursor = new MathCursor(this, cmd.x == 0); //metrics(bv); - mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); + mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); } if (cmd.button() == mouse_button::button3) { @@ -270,7 +270,7 @@ DispatchResult InsetFormulaBase::lfunMousePress(FuncRequest const & cmd) first_x = cmd.x; first_y = cmd.y; mathcursor->selClear(); - mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); + mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); mathcursor->dispatch(cmd); return DispatchResult(true, true); } @@ -302,7 +302,7 @@ DispatchResult InsetFormulaBase::lfunMouseMotion(FuncRequest const & cmd) mathcursor->selStart(); BufferView * bv = cmd.view(); - mathcursor->setPos(cmd.x + xo_, cmd.y + yo_); + mathcursor->setScreenPos(cmd.x + xo_, cmd.y + yo_); bv->update(); return DispatchResult(true, true); } @@ -326,7 +326,7 @@ void InsetFormulaBase::edit(BufferView * bv, int x, int y) releaseMathCursor(bv); mathcursor = new MathCursor(this, true); //metrics(bv); - mathcursor->setPos(x + xo_, y + yo_); + mathcursor->setScreenPos(x + xo_, y + yo_); bv->fullCursor().push(this); // if that is removed, we won't get the magenta box when entering an // inset for the first time @@ -506,7 +506,7 @@ InsetFormulaBase::priv_dispatch(FuncRequest const & cmd, int y = 0; istringstream is(cmd.argument.c_str()); is >> x >> y; - mathcursor->setPos(x, y); + mathcursor->setScreenPos(x, y); break; } diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index f652c33f3c..11578c0f99 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -262,19 +262,19 @@ bool positionable } -void MathCursor::setPos(int x, int y) +void MathCursor::setScreenPos(int x, int y) { - dump("setPos 1"); + dump("setScreenPos 1"); bool res = bruteFind(x, y, formula()->xlow(), formula()->xhigh(), formula()->ylow(), formula()->yhigh()); if (!res) { // this can happen on creation of "math-display" - dump("setPos 1.5"); + dump("setScreenPos 1.5"); first(); } targetx_ = -1; // "no target" - dump("setPos 2"); + dump("setScreenPos 2"); } @@ -641,9 +641,9 @@ void MathCursor::handleNest(MathAtom const & a, int c) } -void MathCursor::getPos(int & x, int & y) const +void MathCursor::getScreenPos(int & x, int & y) const { - inset()->getPos(idx(), pos(), x, y); + inset()->getScreenPos(idx(), pos(), x, y); } @@ -652,7 +652,7 @@ int MathCursor::targetX() const if (targetx_ != -1) return targetx_; int x = 0, y = 0; - getPos(x, y); + getScreenPos(x, y); return x; } @@ -944,7 +944,7 @@ bool MathCursor::goUpDown(bool up) // So fiddle around with it only if you know what you are doing! int xo = 0; int yo = 0; - getPos(xo, yo); + getScreenPos(xo, yo); // check if we had something else in mind, if not, this is the future goal if (targetx_ == -1) @@ -1018,7 +1018,7 @@ bool MathCursor::goUpDown(bool up) // any improvement so far? int xnew, ynew; - getPos(xnew, ynew); + getScreenPos(xnew, ynew); if (up ? ynew < yo : ynew > yo) return true; } @@ -1037,7 +1037,7 @@ bool MathCursor::bruteFind // avoid invalid nesting when selecting if (!selection_ || positionable(it, Anchor_)) { int xo, yo; - it.back().getPos(xo, yo); + it.back().getScreenPos(xo, yo); if (xlow <= xo && xo <= xhigh && ylow <= yo && yo <= yhigh) { double d = (x - xo) * (x - xo) + (y - yo) * (y - yo); //lyxerr << "x: " << x << " y: " << y << " d: " << endl; @@ -1066,13 +1066,13 @@ void MathCursor::bruteFind2(int x, int y) double best_dist = 1e10; CursorBase it = Cursor_; - it.back().setPos(0); + it.back().pos(0); CursorBase et = Cursor_; int n = et.back().asMathInset()->cell(et.back().idx_).size(); - et.back().setPos(n); + et.back().pos(n); for (int i = 0; ; ++i) { int xo, yo; - it.back().getPos(xo, yo); + it.back().getScreenPos(xo, yo); 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' @@ -1443,7 +1443,7 @@ DispatchResult MathCursor::dispatch(FuncRequest const & cmd) CursorSlice & pos = Cursor_.back(); int x = 0; int y = 0; - getPos(x, y); + getScreenPos(x, y); if (x < cmd.x && hasPrevAtom()) { DispatchResult const res = prevAtom().nucleus()->dispatch(cmd, pos.idx_, pos.pos_); diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index 55efa1e017..6bf922cbc0 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -98,9 +98,9 @@ public: void niceInsert(std::string const &); /// in pixels from top of screen - void setPos(int x, int y); + void setScreenPos(int x, int y); /// in pixels from top of screen - void getPos(int & x, int & y) const; + void getScreenPos(int & x, int & y) const; /// in pixels from left of screen int targetX() const; /// current inset diff --git a/src/mathed/math_inset.C b/src/mathed/math_inset.C index 9c6299646d..ae0226a884 100644 --- a/src/mathed/math_inset.C +++ b/src/mathed/math_inset.C @@ -116,9 +116,9 @@ bool MathInset::idxEnd(idx_type &, pos_type &) const } -void MathInset::getPos(idx_type, pos_type, int & x, int & y) const +void MathInset::getScreenPos(idx_type, pos_type, int & x, int & y) const { - lyxerr << "MathInset::getPos() called directly!" << endl; + lyxerr << "MathInset::getScreenPos() called directly!" << endl; x = y = 0; } diff --git a/src/mathed/math_inset.h b/src/mathed/math_inset.h index 779e590fa3..f3018235aa 100644 --- a/src/mathed/math_inset.h +++ b/src/mathed/math_inset.h @@ -79,6 +79,8 @@ class MathInset : public InsetBase { public: /// our members behave nicely... MathInset() {} + /// identification as math inset + MathInset * asMathInset() { return this; } /// substitutes macro arguments if necessary virtual void substitute(MathMacro const & macro); @@ -150,7 +152,7 @@ public: /// can we enter this cell? virtual bool validCell(idx_type) const { return true; } /// get coordinates - virtual void getPos(idx_type idx, pos_type pos, int & x, int & y) const; + virtual void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const; /// identifies certain types of insets virtual MathAMSArrayInset * asAMSArrayInset() { return 0; } diff --git a/src/mathed/math_nestinset.C b/src/mathed/math_nestinset.C index 36c9075234..a1a35f9652 100644 --- a/src/mathed/math_nestinset.C +++ b/src/mathed/math_nestinset.C @@ -45,7 +45,7 @@ MathArray const & MathNestInset::cell(idx_type i) const } -void MathNestInset::getPos(idx_type idx, pos_type pos, int & x, int & y) const +void MathNestInset::getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const { MathArray const & ar = cell(idx); x = ar.xo() + ar.pos2x(pos); diff --git a/src/mathed/math_nestinset.h b/src/mathed/math_nestinset.h index 5ec7b9234d..16bf5e7fe3 100644 --- a/src/mathed/math_nestinset.h +++ b/src/mathed/math_nestinset.h @@ -40,7 +40,7 @@ public: /// identifies NestInsets MathNestInset const * asNestInset() const { return this; } /// get cursor position - void getPos(idx_type idx, pos_type pos, int & x, int & y) const; + void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const; /// order of movement through the cells when pressing the left key bool idxLeft(idx_type & idx, pos_type & pos) const; diff --git a/src/mathed/math_textinset.C b/src/mathed/math_textinset.C index 39931d8f42..9000c3cb7d 100644 --- a/src/mathed/math_textinset.C +++ b/src/mathed/math_textinset.C @@ -40,11 +40,11 @@ MathInset::idx_type MathTextInset::pos2row(pos_type pos) const } -void MathTextInset::getPos(idx_type /*idx*/, pos_type pos, int & x, int & y) const +void MathTextInset::getScreenPos(idx_type /*idx*/, pos_type pos, int & x, int & y) const { idx_type const i = pos2row(pos); pos_type const p = pos - cache_.cellinfo_[i].begin_; - cache_.getPos(i, p, x, y); + cache_.getScreenPos(i, p, x, y); y = cache_.cell(i).yo(); } diff --git a/src/mathed/math_textinset.h b/src/mathed/math_textinset.h index cd673f5362..5bc34dc3f5 100644 --- a/src/mathed/math_textinset.h +++ b/src/mathed/math_textinset.h @@ -24,7 +24,7 @@ public: /// virtual std::auto_ptr clone() const; /// get cursor position - void getPos(idx_type idx, pos_type pos, int & x, int & y) const; + void getScreenPos(idx_type idx, pos_type pos, int & x, int & y) const; /// this stores metrics information in cache_ void metrics(MetricsInfo & mi, Dimension & dim) const; /// draw according to cached metrics