case LFUN_BREAKLINE:
bv->lockedInsetStoreUndo(Undo::INSERT);
- int x;
- int y;
- mathcursor->getPos(x, y);
mathcursor->breakLine();
mathcursor->normalize();
updateLocal(bv, true);
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();
}
}
-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());
}
+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;
}
///
void dump(char const * str) const;
- ///
- int xpos() const;
- ///
- void gotoX(int x);
-
///
void merge(MathArray const & arr);
///
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_;
*/
}
+
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));
}
}
+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())
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;
///
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) {}