X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetTabular.cpp;h=806d8256f29f7c96a2e7d481f9983ce936e1e514;hb=2203d7aa0a8e9d64666498fb26eb17f699c2f52b;hp=f647c00cb76e00c7283a030f7eb4d206f0e6a561;hpb=fea446303de3693f827b9118b13ea913be269ffb;p=lyx.git diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp index f647c00cb7..806d8256f2 100644 --- a/src/insets/InsetTabular.cpp +++ b/src/insets/InsetTabular.cpp @@ -919,7 +919,7 @@ int Tabular::interColumnSpace(idx_type cell) const } -int Tabular::columnWidth(idx_type cell) const +int Tabular::cellWidth(idx_type cell) const { int w = 0; col_type const span = columnSpan(cell); @@ -961,12 +961,14 @@ bool Tabular::updateColumnWidths() int new_width = 0; for(row_type r = 0; r < nrows(); ++r) { idx_type const i = cellIndex(r, c); - if (columnSpan(i) == 1) - if (getAlignment(i) == LYX_ALIGN_DECIMAL) + if (columnSpan(i) == 1) { + if (getAlignment(i) == LYX_ALIGN_DECIMAL + && cell_info[r][c].decimal_width!=0) new_width = max(new_width, cellInfo(i).width + max_dwidth[c] - cellInfo(i).decimal_width); else new_width = max(new_width, cellInfo(i).width); + } } if (column_info[c].width != new_width) { @@ -1005,13 +1007,6 @@ int Tabular::width() const } -void Tabular::setCellWidth(idx_type cell, int new_width) -{ - cellInfo(cell).width = new_width + 2 * WIDTH_OF_LINE - + interColumnSpace(cell); -} - - void Tabular::setAlignment(idx_type cell, LyXAlignment align, bool onlycolumn) { @@ -1241,36 +1236,32 @@ Length const Tabular::getPWidth(idx_type cell) const } -int Tabular::cellWidth(idx_type cell) const -{ - return cellInfo(cell).width; -} - - int Tabular::textHOffset(idx_type cell) const { // the LaTeX Way :-( int x = WIDTH_OF_LINE; + int const w = cellWidth(cell) - cellInfo(cell).width; + switch (getAlignment(cell)) { case LYX_ALIGN_CENTER: - x += (columnWidth(cell) - cellWidth(cell)) / 2; + x += w / 2; break; case LYX_ALIGN_RIGHT: - x += columnWidth(cell) - cellWidth(cell); - // + interColumnSpace(cell); + x += w; break; case LYX_ALIGN_DECIMAL: { // we center when no decimal point if (cellInfo(cell).decimal_width == 0) { - x += (columnWidth(cell) - cellWidth(cell)) / 2; + x += w / 2; break; } col_type const c = cellColumn(cell); int max_dhoffset = 0; for(row_type r = 0; r < row_info.size() ; ++r) { idx_type const i = cellIndex(r, c); - if (getAlignment(i) == LYX_ALIGN_DECIMAL) + if (getAlignment(i) == LYX_ALIGN_DECIMAL + && cellInfo(i).decimal_width != 0) max_dhoffset = max(max_dhoffset, cellInfo(i).decimal_hoffset); } x += max_dhoffset - cellInfo(cell).decimal_hoffset; @@ -3254,10 +3245,11 @@ void InsetTabular::setBuffer(Buffer & buf) bool InsetTabular::insetAllowed(InsetCode code) const { - switch (code) - { + switch (code) { + case FLOAT_CODE: case MARGIN_CODE: case MATHMACRO_CODE: + case WRAP_CODE: return false; case CAPTION_CODE: @@ -3322,7 +3314,7 @@ int InsetTabular::columnFromX(Cursor & cur, int x) const int w = xo(cur.bv()) + ADD_TO_TABULAR_WIDTH; col_type c = 0; for (; c < tabular.ncols() && x > w; ++c) - w += tabular.columnWidth(c); + w += tabular.cellWidth(c); return c - 1; } @@ -3353,7 +3345,8 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const tabular.cellInset(cell)->metrics(m, dim); if (!p_width.zero()) dim.wid = m.base.textwidth; - tabular.setCellWidth(cell, dim.wid); + tabular.cellInfo(cell).width = dim.wid + 2 * WIDTH_OF_LINE + + tabular.interColumnSpace(cell); // FIXME(?): do we need a second metrics call? TextMetrics const & tm = @@ -3474,7 +3467,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const idx = tabular.cellIndex(r, c); if (tabular.isPartOfMultiRow(r, c)) { - nx += tabular.columnWidth(idx); + nx += tabular.cellWidth(idx); continue; } @@ -3488,7 +3481,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const bv->coordCache().insets().add(cell(idx).get(), cx, cy); cell(idx)->draw(pi, cx, cy); drawCellLines(pi.pain, nx, y, r, idx, pi.change_); - nx += tabular.columnWidth(idx); + nx += tabular.cellWidth(idx); pi.selected = original_selection_state; } @@ -3535,10 +3528,10 @@ void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const idx_type const cell = tabular.cellIndex(r, c); if (tabular.isPartOfMultiRow(r, c)) { - xx += tabular.columnWidth(cell); + xx += tabular.cellWidth(cell); continue; } - int const w = tabular.columnWidth(cell); + int const w = tabular.cellWidth(cell); int const h = tabular.cellHeight(cell); int const yy = y - tabular.rowAscent(r); if (isCellSelected(cur, r, c)) @@ -3562,7 +3555,7 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y, row_type row, idx_type cell, Change const & change) const { y -= tabular.rowAscent(row); - int const w = tabular.columnWidth(cell); + int const w = tabular.cellWidth(cell); int const h = tabular.cellHeight(cell); Color linecolor = change.changed() ? change.color() : Color_tabularline; Color gridcolor = change.changed() ? change.color() : Color_tabularonoffline; @@ -3745,7 +3738,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) // only update if selection changes if (bvcur.idx() == cur.idx() && !(bvcur.realAnchor().idx() == cur.idx() && bvcur.pos() != cur.pos())) - cur.noUpdate(); + cur.noScreenUpdate(); setCursorFromCoordinates(cur, cmd.x(), cmd.y()); bvcur.setCursor(cur); bvcur.setSelection(true); @@ -3939,7 +3932,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) // col_type const col = tabular.cellColumn(cur.idx()); // int const t = cur.bv().top_y() + cur.bv().height(); // if (t < yo() + tabular.getHeightOfTabular()) { -// cur.bv().scrollDocView(t); +// cur.bv().scrollDocView(t, true); // cur.idx() = tabular.cellBelow(first_visible_cell) + col; // } else { // cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + col; @@ -3955,7 +3948,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd) // col_type const col = tabular.cellColumn(cur.idx()); // int const t = cur.bv().top_y() + cur.bv().height(); // if (yo() < 0) { -// cur.bv().scrollDocView(t); +// cur.bv().scrollDocView(t, true); // if (yo() > 0) // cur.idx() = col; // else @@ -4644,7 +4637,7 @@ int InsetTabular::dist(BufferView & bv, idx_type const cell, int x, int y) const Inset const & inset = *tabular.cellInset(cell); Point o = bv.coordCache().getInsets().xy(&inset); int const xbeg = o.x_ - tabular.textHOffset(cell); - int const xend = xbeg + tabular.columnWidth(cell); + int const xend = xbeg + tabular.cellWidth(cell); row_type const row = tabular.cellRow(cell); int const ybeg = o.y_ - tabular.rowAscent(row) - tabular.interRowSpace(row); @@ -4708,7 +4701,7 @@ int InsetTabular::cellXPos(idx_type const cell) const col_type col = tabular.cellColumn(cell); int lx = 0; for (col_type c = 0; c < col; ++c) - lx += tabular.columnWidth(c); + lx += tabular.column_info[c].width; return lx; } @@ -4728,7 +4721,7 @@ void InsetTabular::resetPos(Cursor & cur) const int const X2 = maxwidth; int const offset = ADD_TO_TABULAR_WIDTH + 2; int const x1 = xo(cur.bv()) + cellXPos(cur[i].idx()) + offset; - int const x2 = x1 + tabular.columnWidth(cur[i].idx()); + int const x2 = x1 + tabular.cellWidth(cur[i].idx()); if (x1 < X1) scx_ = X1 + 20 - x1; @@ -4740,7 +4733,7 @@ void InsetTabular::resetPos(Cursor & cur) const // only update if offset changed if (scx_ != scx_old) - cur.updateFlags(Update::Force | Update::FitCursor); + cur.screenUpdateFlags(Update::Force | Update::FitCursor); }