some renaming + safety stuff

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8353 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-01-15 11:58:35 +00:00
parent 6102cddc08
commit f7b38dbdc5
14 changed files with 80 additions and 69 deletions

View File

@ -614,3 +614,8 @@ void BufferView::putSelectionAt(PosIterator const & cur,
update();
}
CursorSlice & cursorTip(BufferView & bv)
{
return bv.cursor();
}

View File

@ -89,41 +89,34 @@ bool CursorSlice::boundary() const
MathInset * CursorSlice::asMathInset() const
{
return static_cast<MathInset *>(const_cast<InsetBase *>(inset_));
return inset_ ? inset_->asMathInset() : 0;
}
UpdatableInset * CursorSlice::asUpdatableInset() const
{
return static_cast<UpdatableInset *>(const_cast<InsetBase *>(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);
}

View File

@ -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

View File

@ -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<InsetBase> 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);

View File

@ -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 {}

View File

@ -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;
}

View File

@ -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_);

View File

@ -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

View File

@ -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;
}

View File

@ -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; }

View File

@ -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);

View File

@ -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;

View File

@ -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();
}

View File

@ -24,7 +24,7 @@ public:
///
virtual std::auto_ptr<InsetBase> 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