]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
#7379 avoid the wrap spell check question when buffer is empty
[lyx.git] / src / insets / InsetTabular.cpp
index 4b2463ded229774b895a34e59d83b8310d3f372e..c5cc505004cd2723a9d856d6af45baeac221d488 100644 (file)
@@ -1342,8 +1342,9 @@ Tabular::idx_type Tabular::getFirstCellInRow(row_type row) const
 Tabular::idx_type Tabular::getLastCellInRow(row_type row) const
 {
        col_type c = ncols() - 1;
-       while (cell_info[row][c].multirow == CELL_PART_OF_MULTIROW
-               || cell_info[row][c].multicolumn == CELL_PART_OF_MULTICOLUMN)
+       while (c > 0
+              && (cell_info[row][c].multirow == CELL_PART_OF_MULTIROW
+                  || cell_info[row][c].multicolumn == CELL_PART_OF_MULTICOLUMN))
                --c;
        return cell_info[row][c].cellno;
 }
@@ -2441,14 +2442,16 @@ void Tabular::TeXRow(otexstream & os, row_type row,
        for (col_type c = 0; c < ncols(); ++c) {
                if (isPartOfMultiColumn(row, c))
                        continue;
-                       
-               if (isPartOfMultiRow(row, c) && 
-                       column_info[c].alignment != LYX_ALIGN_DECIMAL) {
-                       os << " & "; 
+
+               cell = cellIndex(row, c);
+
+               if (isPartOfMultiRow(row, c)
+                   && column_info[c].alignment != LYX_ALIGN_DECIMAL) {
+                       if (cell != getLastCellInRow(row))
+                               os << " & "; 
                        continue;
                }
 
-               cell = cellIndex(row, c);
                TeXCellPreamble(os, cell, ismulticol, ismultirow);
                shared_ptr<InsetTableCell> inset = cellInset(cell);
 
@@ -2492,8 +2495,11 @@ void Tabular::TeXRow(otexstream & os, row_type row,
                        head.latex(os, newrp);
                        os << '&';
                        tail.latex(os, newrp);
-               } else if (!isPartOfMultiRow(row, c))
+               } else if (!isPartOfMultiRow(row, c)) {
+                       if (!runparams.nice)
+                               os.texrow().start(par.id(), 0);
                        inset->latex(os, newrp);
+               }
 
                runparams.encoding = newrp.encoding;
                if (rtl)
@@ -2501,7 +2507,10 @@ void Tabular::TeXRow(otexstream & os, row_type row,
 
                TeXCellPostamble(os, cell, ismulticol, ismultirow);
                if (cell != getLastCellInRow(row)) { // not last cell in row
-                       os << " & ";
+                       if (runparams.nice)
+                               os << " & ";
+                       else
+                               os << " &\n";
                }
        }
        if (row_info[row].caption && !endfirsthead.empty && !haveLTFirstHead())
@@ -2554,6 +2563,10 @@ void Tabular::latex(otexstream & os, OutputParams const & runparams) const
        //+                      first the opening preamble                    +
        //+---------------------------------------------------------------------
 
+       os << safebreakln;
+       if (runparams.lastid != -1)
+               os.texrow().start(runparams.lastid, runparams.lastpos);
+
        if (rotate)
                os << "\\begin{sideways}\n";
 
@@ -3992,6 +4005,8 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cmd = FuncRequest(finish_lfun);
                else
                        cur.dispatched();
+
+               cur.screenUpdateFlags(Update::Force | Update::FitCursor);
                break;
 
        }
@@ -4028,6 +4043,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cur.setCurrentFont();
                        return;
                }
+               cur.screenUpdateFlags(Update::FitCursor);
                break;
 
        case LFUN_UP_SELECT:
@@ -4061,6 +4077,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cur.setCurrentFont();
                        return;
                }
+               cur.screenUpdateFlags(Update::FitCursor);
                break;
 
 //     case LFUN_SCREEN_DOWN: {
@@ -4272,8 +4289,16 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                if (&cur.inset() != this || cmd.getArg(0) != "tabular") 
                        break;
 
-               string const s = cmd.getArg(1);
                // FIXME: We only check for the very first argument...
+               string const s = cmd.getArg(1);
+               // We always enable the lfun if it is coming from the dialog
+               // because the dialog makes sure all the settings are valid,
+               // even though the first argument might not be valid now.
+               if (s == "from-dialog") {
+                       status.setEnabled(true);
+                       return true;
+               }
+
                int action = Tabular::LAST_ACTION;
                int i = 0;
                for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
@@ -4623,8 +4648,13 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
        }
 
        // disable in non-fixed-width cells
-       case LFUN_NEWLINE_INSERT:
-       case LFUN_BREAK_PARAGRAPH: {
+       case LFUN_BREAK_PARAGRAPH:
+               // multirow does not allow paragraph breaks
+               if (tabular.isMultiRow(cur.idx())) {
+                       status.setEnabled(false);
+                       return true;
+               }
+       case LFUN_NEWLINE_INSERT: {
                if (tabular.getPWidth(cur.idx()).zero()) {
                        status.setEnabled(false);
                        return true;
@@ -5162,28 +5192,11 @@ void InsetTabular::tabularFeatures(Cursor & cur,
                if (len.zero()
                    && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
                        tabularFeatures(cur, Tabular::ALIGN_CENTER, string());
-               // check if there is a 1-column multicolumn cell
-               // if so it must get the same width
-               for (row_type r = 0; r < tabular.nrows(); ++r) {
-                       if (tabular.isMultiColumn(tabular.cellIndex(r, column))
-                               && tabular.columnSpan(tabular.cellIndex(r, column)) == 1)
-                               tabular.setMColumnPWidth(cur, tabular.cellIndex(r, column), len);
-               }
                break;
        }
 
        case Tabular::SET_MPWIDTH:
                tabular.setMColumnPWidth(cur, cur.idx(), Length(value));
-               // if the multicolumn only spans 1 column, the width of the whole column
-               // must have the same width, see bug #7055
-               if (tabular.columnSpan(cur.idx()) == 1)
-                       for (row_type r = 0; r < tabular.nrows(); ++r) {
-                               if (!tabular.isMultiColumn(tabular.cellIndex(r, column)))
-                                       tabular.setColumnPWidth(cur, tabular.cellIndex(r, column), Length(value));
-                               else if (tabular.isMultiColumn(tabular.cellIndex(r, column))
-                                       && tabular.columnSpan(tabular.cellIndex(r, column)) == 1)
-                                       tabular.setMColumnPWidth(cur, tabular.cellIndex(r, column), Length(value));
-                       }
                break;
 
        case Tabular::SET_MROFFSET: