fix the cursor-y problem in math

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8646 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2004-04-13 12:47:48 +00:00
parent da61af2b8e
commit b3eefc106e
13 changed files with 27 additions and 25 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,9 +22,9 @@ public:
///
MathTextInset();
///
virtual std::auto_ptr<InsetBase> clone() const;
std::auto_ptr<InsetBase> 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