]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
use more flexible default for now...
[lyx.git] / src / insets / InsetTabular.cpp
index 81044814c15e38eecdd6bc11e7ca8ab9bb8c1e55..25bd68619633df156639a22486dc36bfe710d641 100644 (file)
@@ -895,16 +895,13 @@ int Tabular::rowHeight(idx_type cell) const
 {
        row_type const span = rowSpan(cell);
        row_type const row = cellRow(cell);
-       int h = rowAscent(row) + rowDescent(row);
-
+       int h = 0;
        for(row_type r = row; r < row + span ; ++r) {
-               if (r > row) {
-                       h += rowAscent(r);
-                       h += interRowSpace(r);
-               }
-               if (r < row + span - 1)
-                       h += rowDescent(r);
+               h += rowAscent(r) + rowDescent(r);
+               if (r != row + span - 1)
+                       h += interRowSpace(r + 1);
        }
+
        return h;
 }
 
@@ -1180,7 +1177,7 @@ LyXAlignment Tabular::getAlignment(idx_type cell, bool onlycolumn) const
 Tabular::VAlignment
 Tabular::getVAlignment(idx_type cell, bool onlycolumn) const
 {
-       if (!onlycolumn && isMultiColumn(cell))
+       if (!onlycolumn && (isMultiColumn(cell) || isMultiRow(cell)))
                return cellInfo(cell).valignment;
        return column_info[cellColumn(cell)].valignment;
 }
@@ -1225,7 +1222,11 @@ int Tabular::textHOffset(idx_type cell) const
 int Tabular::textVOffset(idx_type cell) const
 {
        int h = rowHeight(cell);
-       
+
+       row_type const r = cellRow(cell);
+       if (rowSpan(cell) > 1)
+               h -= rowDescent(r) + rowAscent(r);
+
        int y = 0;
        switch (getVAlignment(cell)) {
           case LYX_VALIGN_TOP:
@@ -1541,15 +1542,7 @@ void Tabular::setMultiRow(idx_type cell, idx_type number)
 
        CellData & cs = cellInfo(cell);
        cs.multirow = CELL_BEGIN_OF_MULTIROW;
-       // reset the vertical alignment to top because multirows cells
-       // cannot be vertically aligned (they can also only have one paragraph)
-       column_info[col].valignment = LYX_VALIGN_TOP;
-
-       // FIXME: the horizontal alignment can only be changed for
-       // the whole table, support for this needs to be implemented
-       // (assigning this to uwestoehr)
-       // until LyX supports this, the alignment is always left
-       column_info[col].alignment = LYX_ALIGN_LEFT;
+       cs.valignment = LYX_VALIGN_MIDDLE;
 
        // set the bottom row of the last selected cell
        setBottomLine(cell, bottomLine(cell + (number - 1)*ncols()));
@@ -1605,6 +1598,7 @@ void Tabular::unsetMultiRow(idx_type cell)
        if (!isMultiRow(cell))
                return;
 
+       cellInfo(cell).valignment = LYX_VALIGN_TOP;
        row_type const row = cellRow(cell);
        col_type const col = cellColumn(cell);
        row_type const span = rowSpan(cell);
@@ -2116,7 +2110,7 @@ int Tabular::TeXCellPreamble(odocstream & os, idx_type cell,
                else
                        // we need to set a default value
                        // needs to be discussed
-                       os << "2.0cm";
+                       os << "*";
                os << "}{";
                } // end if ismultirow
 
@@ -3320,8 +3314,8 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
                }
 
                if (r + 1 < tabular.nrows())
-                       y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
-                            + tabular.interRowSpace(r + 1);
+                       y += tabular.rowDescent(r) + tabular.rowAscent(r + 1) 
+                               + tabular.interRowSpace(r + 1);
        }
 }
 
@@ -3353,7 +3347,6 @@ void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
                tabular.cellRow(cur.idx()), tabular.cellColumn(cur.idx()));
 
        if (cur.selIsMultiCell() || full_cell_selected) {
-               y -= tabular.rowAscent(0);
                for (row_type r = 0; r < tabular.nrows(); ++r) {
                        int xx = x;
                        for (col_type c = 0; c < tabular.ncols(); ++c) {
@@ -3368,8 +3361,9 @@ void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
                                }
                                int const w = tabular.columnWidth(cell);
                                int const h = tabular.rowHeight(cell);
+                               int const yy = y - tabular.rowAscent(r);
                                if (isCellSelected(cur, r, c))
-                                       pi.pain.fillRectangle(xx, y, w, h, Color_selection);
+                                       pi.pain.fillRectangle(xx, yy, w, h, Color_selection);
                                xx += w;
                        }
                        if (r + 1 < tabular.nrows())
@@ -3971,27 +3965,15 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
 {
        switch (cmd.action) {
        case LFUN_INSET_MODIFY: {
-               istringstream is(to_utf8(cmd.argument()));
-               string s;
-               is >> s;
-               if (insetCode(s) != TABULAR_CODE) {
-                       status.clear();
-                       status.setEnabled(false);
+               if (&cur.inset() != this || cmd.getArg(0) != "tabular") 
                        break;
-               }
-               if (&cur.inset() != this) {
-                       // we need the cursor to be _inside_ the table.
-                       status.setEnabled(false);
-                       status.message(from_utf8(N_("Cursor not in table")));
-                       return true;
-               }
-               is >> s;
+
+               string const s = cmd.getArg(1);
                // FIXME: We only check for the very first argument...
                int action = Tabular::LAST_ACTION;
                int i = 0;
                for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
-                       string const tmp = tabularFeature[i].feature;
-                       if (tmp == s.substr(0, tmp.length())) {
+                       if (tabularFeature[i].feature == s) {
                                action = tabularFeature[i].action;
                                break;
                        }
@@ -4002,8 +3984,7 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        return true;
                }
 
-               string const argument
-                       = ltrim(s.substr(tabularFeature[i].feature.length()));
+               string const argument = cmd.getLongArg(2);
 
                row_type sel_row_start = 0;
                row_type sel_row_end = 0;
@@ -4453,14 +4434,10 @@ void InsetTabular::cursorPos(BufferView const & bv,
        int const col = tabular.cellColumn(sl.idx());
 
        // y offset     correction
-       for (int r = 0; r <= row; ++r) {
-               if (r != 0) {
-                       y += tabular.rowAscent(r);
-                       y += tabular.interRowSpace(r);
-               }
-               if (r != row)
-                       y += tabular.rowDescent(r);
-       }
+       for (int r = 0; r < row; ++r)
+               y += tabular.rowDescent(r) + tabular.rowAscent(r + 1) 
+                       + tabular.interRowSpace(r + 1);
+
        y += tabular.textVOffset(sl.idx());
 
        // x offset correction