X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2FInsetMathGrid.cpp;h=0a637ec715c26ae8f32d5bf4ab5f718de9d02385;hb=21c92c8a129b5f3ff56de33bf2941a25967cffbb;hp=496ba36bb57dab70090113e072d80e6bfada6c98;hpb=ed856c9f4d8bf83963a6d8e21cf454b355881d48;p=lyx.git diff --git a/src/mathed/InsetMathGrid.cpp b/src/mathed/InsetMathGrid.cpp index 496ba36bb5..0a637ec715 100644 --- a/src/mathed/InsetMathGrid.cpp +++ b/src/mathed/InsetMathGrid.cpp @@ -92,7 +92,7 @@ InsetMathGrid::CellInfo::CellInfo() InsetMathGrid::RowInfo::RowInfo() - : descent(0), ascent(0), offset(0), lines(0), skip(0), + : descent(0), ascent(0), lines(0), skip(0), allow_newpage(true) {} @@ -424,10 +424,10 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const rowinfo_[nrows()].descent = 0; // compute vertical offsets - rowinfo_[0].offset = 0; + rowinfo_[0].offset[&bv] = 0; for (row_type row = 1; row <= nrows(); ++row) { - rowinfo_[row].offset = - rowinfo_[row - 1].offset + + rowinfo_[row].offset[&bv] = + rowinfo_[row - 1].offset[&bv] + rowinfo_[row - 1].descent + rowinfo_[row - 1].skipPixels(mi) + rowsep() + @@ -442,13 +442,13 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const h = 0; break; case 'b': - h = rowinfo_[nrows() - 1].offset; + h = rowinfo_[nrows() - 1].offset[&bv]; break; default: - h = rowinfo_[nrows() - 1].offset / 2; + h = rowinfo_[nrows() - 1].offset[&bv] / 2; } for (row_type row = 0; row <= nrows(); ++row) - rowinfo_[row].offset -= h; + rowinfo_[row].offset[&bv] -= h; // multicolumn cell widths, as a map from first column to width in a @@ -528,12 +528,12 @@ void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const + vlinesep() * colinfo_[ncols()].lines + border(); - dim.asc = - rowinfo_[0].offset + dim.asc = - rowinfo_[0].offset[&bv] + rowinfo_[0].ascent + hlinesep() * rowinfo_[0].lines + border(); - dim.des = rowinfo_[nrows() - 1].offset + dim.des = rowinfo_[nrows() - 1].offset[&bv] + rowinfo_[nrows() - 1].descent + hlinesep() * rowinfo_[nrows()].lines + border() + 1; @@ -608,9 +608,10 @@ int InsetMathGrid::vLineHOffset(col_type col, unsigned int line) const } -int InsetMathGrid::hLineVOffset(row_type row, unsigned int line) const +int InsetMathGrid::hLineVOffset(BufferView const & bv, row_type row, + unsigned int line) const { - return rowinfo_[row].offset + return rowinfo_[row].offset[&bv] - rowinfo_[row].ascent - line * hlinesep() - hlinesep()/2 - rowsep()/2; @@ -625,11 +626,11 @@ void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const if (cellinfo_[idx].multi != CELL_PART_OF_MULTICOLUMN) { cell(idx).draw(pi, x + leftMargin() + cellXOffset(bv, idx), - y + cellYOffset(idx)); + y + cellYOffset(bv, idx)); row_type r = row(idx); - int const yy1 = y + hLineVOffset(r, 0); - int const yy2 = y + hLineVOffset(r + 1, rowinfo_[r + 1].lines - 1); + int const yy1 = y + hLineVOffset(bv, r, 0); + int const yy2 = y + hLineVOffset(bv, r + 1, rowinfo_[r + 1].lines - 1); auto draw_left_borders = [&](col_type c) { for (unsigned int i = 0; i < colinfo_[c].lines; ++i) { int const xx = x + vLineHOffset(c, i); @@ -650,15 +651,18 @@ void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const int const xx1 = x + vLineHOffset(0, 0); int const xx2 = x + vLineHOffset(ncols(), colinfo_[ncols()].lines - 1); for (unsigned int i = 0; i < rowinfo_[r].lines; ++i) { - int const yy = y + hLineVOffset(r, i); + int const yy = y + hLineVOffset(bv, r, i); pi.pain.line(xx1, yy, xx2, yy, Color_foreground); } } } -void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const +void InsetMathGrid::metricsT(TextMetricsInfo const & /*mi*/, Dimension & /*dim*/) const { +// FIXME: this does not compile anymore with offset being a map +// It is not worth fixing it at this point since the code is basically dead. +#if 0 // let the cells adjust themselves for (idx_type i = 0; i < nargs(); ++i) if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) @@ -685,9 +689,9 @@ void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const rowinfo_[nrows()].descent = 0; // compute vertical offsets - rowinfo_[0].offset = 0; + rowinfo_[0].offset[&bv] = 0; for (row_type row = 1; row <= nrows(); ++row) { - rowinfo_[row].offset = + rowinfo_[row].offset[&bv] = rowinfo_[row - 1].offset + rowinfo_[row - 1].descent + //rowinfo_[row - 1].skipPixels(mi) + @@ -751,6 +755,7 @@ void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const + rowinfo_[nrows() - 1].descent //+ hlinesep() * rowinfo_[nrows()].lines + 1; +#endif } @@ -762,12 +767,12 @@ void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const } -void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype) +void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted) { // pass down for (idx_type idx = 0; idx < nargs(); ++idx) if (cellinfo_[idx].multi != CELL_PART_OF_MULTICOLUMN) - cell(idx).updateBuffer(it, utype); + cell(idx).updateBuffer(it, utype, deleted); } @@ -891,6 +896,8 @@ void InsetMathGrid::delCol(col_type col) tmpcellinfo.push_back(cellinfo_[i]); } swap(cells_, tmpcells); + // copying cells loses the buffer reference + setBuffer(*buffer_); swap(cellinfo_, tmpcellinfo); colinfo_.erase(colinfo_.begin() + col); @@ -935,9 +942,9 @@ int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const } -int InsetMathGrid::cellYOffset(idx_type idx) const +int InsetMathGrid::cellYOffset(BufferView const & bv, idx_type idx) const { - return rowinfo_[row(idx)].offset; + return rowinfo_[row(idx)].offset[&bv]; } @@ -1177,15 +1184,15 @@ void InsetMathGrid::normalize(NormalStream & os) const } -void InsetMathGrid::mathmlize(MathStream & os) const +void InsetMathGrid::mathmlize(MathStream & ms) const { bool const havetable = nrows() > 1 || ncols() > 1; if (havetable) - os << MTag("mtable"); + ms << MTag("mtable"); char const * const celltag = havetable ? "mtd" : "mrow"; for (row_type row = 0; row < nrows(); ++row) { if (havetable) - os << MTag("mtr"); + ms << MTag("mtr"); for (col_type col = 0; col < ncols(); ++col) { idx_type const i = index(row, col); if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) { @@ -1193,16 +1200,16 @@ void InsetMathGrid::mathmlize(MathStream & os) const ostringstream attr; if (havetable && cellcols > 1) attr << "colspan='" << cellcols << '\''; - os << MTag(celltag, attr.str()); - os << cell(index(row, col)); - os << ETag(celltag); + ms << MTag(celltag, attr.str()); + ms << cell(index(row, col)); + ms << ETag(celltag); } } if (havetable) - os << ETag("mtr"); + ms << ETag("mtr"); } if (havetable) - os << ETag("mtable"); + ms << ETag("mtable"); } @@ -1617,36 +1624,47 @@ void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd) } else { // multiple cells cur.recordUndoInset(); - col_type const numcols = - min(grid.ncols(), ncols() - col(cur.idx())); + col_type startcol = col(cur.idx()); + row_type startrow = cur.row(); + col_type oldncols = ncols(); + col_type numcols = + min(grid.ncols(), ncols() - startcol); row_type const numrows = min(grid.nrows(), nrows() - cur.row()); for (row_type r = 0; r < numrows; ++r) { for (col_type c = 0; c < numcols; ++c) { - idx_type i = index(r + cur.row(), c + col(cur.idx())); - cell(i).insert(0, grid.cell(grid.index(r, c))); + idx_type i = index(r + startrow, c + startcol); + cell(i).insert(c == 0 ? cur.pos() : 0, + grid.cell(grid.index(r, c))); } if (hline_enabled) rowinfo_[r].lines += grid.rowinfo_[r].lines; else { for (unsigned int l = 0; l < grid.rowinfo_[r].lines; ++l) { - idx_type i = index(r + cur.row(), 0); + idx_type i = index(r + startrow, 0); cell(i).insert(0, MathAtom(new InsetMathUnknown(from_ascii("\\hline")))); } } - // append the left over horizontal cells to the last column - idx_type i = index(r + cur.row(), ncols() - 1); - for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c) + // append columns for the left over horizontal cells + for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c) { + addCol(c + startcol); + idx_type i = index(r + startrow, min(c + startcol, ncols() - 1)); cell(i).append(grid.cell(grid.index(r, c))); + ++numcols; + } } - // append the left over vertical cells to the last _cell_ + // amend cursor position if cols have been appended + cur.idx() += startrow * (ncols() - oldncols); + // append rows for the left over vertical cells idx_type i = nargs() - 1; for (row_type r = numrows; r < grid.nrows(); ++r) { + row_type crow = startrow + r; + addRow(crow - 1); for (col_type c = 0; c < grid.ncols(); ++c) - cell(i).append(grid.cell(grid.index(r, c))); + cell(index(min(crow, nrows() - 1), min(c + startcol, ncols() - 1))).append(grid.cell(grid.index(r, c))); if (hline_enabled) - rowinfo_[r].lines += grid.rowinfo_[r].lines; + rowinfo_[crow].lines += grid.rowinfo_[r].lines; else { for (unsigned int l = 0; l < grid.rowinfo_[r].lines; ++l) { cell(i).insert(0, @@ -1785,25 +1803,6 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd, from_utf8(s))); } -#if 0 - // FIXME: What did this code do? - // Please check whether it is still needed! - // should be more precise - if (v_align_ == '\0') { - status.enable(true); - break; - } - if (cmd.argument().empty()) { - status.enable(false); - break; - } - if (!contains("tcb", cmd.argument()[0])) { - status.enable(false); - break; - } - status.setOnOff(cmd.argument()[0] == v_align_); - status.setEnabled(true); -#endif return true; } @@ -1823,8 +1822,7 @@ bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd, } -// static -char InsetMathGrid::colAlign(HullType type, col_type col, BufferParams const & bp) +char InsetMathGrid::colAlign(HullType type, col_type col) const { switch (type) { case hullEqnArray: @@ -1833,10 +1831,13 @@ char InsetMathGrid::colAlign(HullType type, col_type col, BufferParams const & b case hullMultline: return 'c'; case hullGather: - if (!bp.is_math_indent) - return 'c'; - else + LASSERT(isBufferValid(), + LYXERR0("Buffer not set correctly. Please report!"); + return 'c';); + if (buffer().params().is_math_indent) return 'l'; + else + return 'c'; case hullAlign: case hullAlignAt: