]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
Pure HTML output for math macros.
[lyx.git] / src / insets / InsetTabular.cpp
index a46c0a2c0c9b78d616ed8916436321aa710c4384..d398c87f4c40bffe1d332f733c0bf493e1fb4aa5 100644 (file)
@@ -538,6 +538,7 @@ Tabular::CellData::CellData(CellData const & cs)
          multirow(cs.multirow),
          alignment(cs.alignment),
          valignment(cs.valignment),
+         voffset(cs.voffset),
          top_line(cs.top_line),
          bottom_line(cs.bottom_line),
          left_line(cs.left_line),
@@ -564,6 +565,7 @@ void Tabular::CellData::swap(CellData & rhs)
        std::swap(multirow, rhs.multirow);
        std::swap(alignment, rhs.alignment);
        std::swap(valignment, rhs.valignment);
+       std::swap(voffset, rhs.voffset);
        std::swap(top_line, rhs.top_line);
        std::swap(bottom_line, rhs.bottom_line);
        std::swap(left_line, rhs.left_line);
@@ -3201,8 +3203,8 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
        }
 
        for (row_type r = 0; r < tabular.nrows(); ++r) {
-               int maxAsc = 0;
-               int maxDesc = 0;
+               int maxasc = 0;
+               int maxdes = 0;
                for (col_type c = 0; c < tabular.ncols(); ++c) {
                        if (tabular.isPartOfMultiColumn(r, c)
                                || tabular.isPartOfMultiRow(r, c))
@@ -3211,12 +3213,7 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
                        idx_type const cell = tabular.cellIndex(r, c);
                        Dimension dim;
                        MetricsInfo m = mi;
-                       Length p_width;
-                       if (tabular.cell_info[r][c].multicolumn ==
-                               Tabular::CELL_BEGIN_OF_MULTICOLUMN)
-                               p_width = tabular.cellInfo(cell).p_width;
-                       else
-                               p_width = tabular.column_info[c].p_width;
+                       Length const p_width = tabular.getPWidth(cell);
                        if (!p_width.zero())
                                m.base.textwidth = p_width.inPixels(mi.base.textwidth);
                        tabular.cellInset(cell)->metrics(m, dim);
@@ -3224,34 +3221,36 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
                                dim.wid = m.base.textwidth;
                        tabular.setCellWidth(cell, dim.wid);
 
-                       // FIXME?: do we need a second metrics call
-                       // to get the descent of the text in last par?
+                       // FIXME(?): do we need a second metrics call?
                        TextMetrics const & tm = 
                                mi.base.bv->textMetrics(tabular.cellInset(cell)->getText(0));
-                       int const backdes = tm.last().second->descent();
-
+                       // with LYX_VALIGN_BOTTOM the descent is relative to the last par
+                       // = descent of text in last par + TEXT_TO_INSET_OFFSET:
+                       int const lastpardes = tm.last().second->descent()
+                               + TEXT_TO_INSET_OFFSET;
+                       int offset = 0;
                        switch (tabular.getVAlignment(cell)) { 
                                case Tabular::LYX_VALIGN_TOP:
-                                       tabular.cell_info[r][c].voffset = 0; 
                                        break; 
                                case Tabular::LYX_VALIGN_MIDDLE:
-                                       tabular.cell_info[r][c].voffset = -(dim.des - backdes - TEXT_TO_INSET_OFFSET)/2; 
+                                       offset = -(dim.des - lastpardes)/2; 
                                        break; 
                                case Tabular::LYX_VALIGN_BOTTOM:
-                                       tabular.cell_info[r][c].voffset = -(dim.des - backdes - TEXT_TO_INSET_OFFSET);
+                                       offset = -(dim.des - lastpardes); 
                                        break;
                        }
-                       maxAsc  = max(maxAsc, dim.asc - tabular.cell_info[r][c].voffset);
-                       maxDesc = max(maxDesc, dim.des + tabular.cell_info[r][c].voffset);
+                       tabular.cell_info[r][c].voffset = offset;
+                       maxasc = max(maxasc, dim.asc - offset);
+                       maxdes = max(maxdes, dim.des + offset);
                }
                int const top_space = tabular.row_info[r].top_space_default ?
                        default_line_space :
                        tabular.row_info[r].top_space.inPixels(mi.base.textwidth);
-               tabular.setRowAscent(r, maxAsc + ADD_TO_HEIGHT + top_space);
+               tabular.setRowAscent(r, maxasc + ADD_TO_HEIGHT + top_space);
                int const bottom_space = tabular.row_info[r].bottom_space_default ?
                        default_line_space :
                        tabular.row_info[r].bottom_space.inPixels(mi.base.textwidth);
-               tabular.setRowDescent(r, maxDesc + ADD_TO_HEIGHT + bottom_space);
+               tabular.setRowDescent(r, maxdes + ADD_TO_HEIGHT + bottom_space);
        }
        tabular.updateColumnWidths();
        dim.asc = tabular.rowAscent(0);
@@ -3259,6 +3258,7 @@ void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
        dim.wid = tabular.width() + 2 * ADD_TO_TABULAR_WIDTH;
 }
 
+
 bool InsetTabular::isCellSelected(Cursor & cur, row_type row, col_type col) 
        const
 {
@@ -4288,6 +4288,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
        case LFUN_BRANCH_INSERT:
        case LFUN_PHANTOM_INSERT:
        case LFUN_WRAP_INSERT:
+       case LFUN_PREVIEW_INSERT:
        case LFUN_ERT_INSERT: {
                if (cur.selIsMultiCell()) {
                        status.setEnabled(false);
@@ -4847,7 +4848,7 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                break;
 
        case Tabular::SET_SPECIAL_MULTIROW:
-               //FIXME: noting to do here?
+               // nothing to do
                break;
 
        case Tabular::APPEND_ROW: