update();
}
+
+CursorSlice & cursorTip(BufferView & bv)
+{
+ return bv.cursor();
+}
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);
}
#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.
///
/// 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;
CursorBase ibegin(InsetBase * p);
///
CursorBase iend(InsetBase * p);
+///
+CursorSlice & cursorTip(BufferView &);
+
#endif
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 {
/// 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);
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 {}
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);
+ }
}
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);
//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);
}
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) {
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);
}
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);
}
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
int y = 0;
istringstream is(cmd.argument.c_str());
is >> x >> y;
- mathcursor->setPos(x, y);
+ mathcursor->setScreenPos(x, y);
break;
}
}
-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");
}
}
-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);
}
if (targetx_ != -1)
return targetx_;
int x = 0, y = 0;
- getPos(x, y);
+ getScreenPos(x, y);
return x;
}
// 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)
// any improvement so far?
int xnew, ynew;
- getPos(xnew, ynew);
+ getScreenPos(xnew, ynew);
if (up ? ynew < yo : ynew > yo)
return true;
}
// 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;
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'
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_);
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
}
-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;
}
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);
/// 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; }
}
-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);
/// 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;
}
-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();
}
///
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