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
This commit is contained in:
André Pönitz 2001-08-08 09:31:36 +00:00
parent b1fb4b15f2
commit 08c784de22
6 changed files with 77 additions and 37 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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