]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
Fix wrongly copy-pasted entries in SpellcheckerUi.ui
[lyx.git] / src / insets / InsetTabular.cpp
index 4b2463ded229774b895a34e59d83b8310d3f372e..5eb59e54d2513c8100e86b0ba3de223c4ec22f7d 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";
 
@@ -2874,9 +2887,9 @@ docstring Tabular::xhtmlRow(XHTMLStream & xs, row_type row,
                if (isMultiColumn(cell))
                        attr << " colspan='" << columnSpan(cell) << "'";
 
-               xs << html::StartTag(celltag, attr.str());
+               xs << html::StartTag(celltag, attr.str()) << html::CR();
                ret += cellInset(cell)->xhtml(xs, runparams);
-               xs << html::EndTag(celltag);
+               xs << html::EndTag(celltag) << html::CR();
                ++cell;
        }
        xs << html::EndTag("tr");
@@ -2902,17 +2915,19 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
                        align = "right";
                        break;
                }
-               xs << html::StartTag("div", "class='longtable' style='text-align: " + align + ";'");
+               xs << html::StartTag("div", "class='longtable' style='text-align: " + align + ";'")
+                  << html::CR();
                if (haveLTCaption()) {
-                       xs << html::StartTag("div", "class='longtable-caption' style='text-align: " + align + ";'");
+                       xs << html::StartTag("div", "class='longtable-caption' style='text-align: " + align + ";'")
+                          << html::CR();
                        for (row_type r = 0; r < nrows(); ++r)
                                if (row_info[r].caption)
                                        ret += xhtmlRow(xs, r, runparams);
-                       xs << html::EndTag("div");
+                       xs << html::EndTag("div") << html::CR();
                }
        }
 
-       xs << html::StartTag("table");
+       xs << html::StartTag("table") << html::CR();
 
        // output header info
        bool const havefirsthead = haveLTFirstHead();
@@ -2921,40 +2936,42 @@ docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
        // in XHTML. this test accomplishes that.
        bool const havehead = !havefirsthead && haveLTHead();
        if (havehead || havefirsthead) {
-               xs << html::StartTag("thead");
+               xs << html::StartTag("thead") << html::CR();
                for (row_type r = 0; r < nrows(); ++r) {
                        if ((havefirsthead && row_info[r].endfirsthead)
                            || (havehead && row_info[r].endhead)) {
                                ret += xhtmlRow(xs, r, runparams, true);
                        }
                }
-               xs << html::EndTag("thead");
+               xs << html::EndTag("thead") << html::CR();
        }
        // output footer info
        bool const havelastfoot = haveLTLastFoot();
        // as before.
        bool const havefoot = !havelastfoot && haveLTFoot();
        if (havefoot || havelastfoot) {
-               xs << html::StartTag("tfoot");
+               xs << html::StartTag("tfoot") << html::CR();
                for (row_type r = 0; r < nrows(); ++r) {
                        if ((havelastfoot && row_info[r].endlastfoot)
                            || (havefoot && row_info[r].endfoot)) {
                                ret += xhtmlRow(xs, r, runparams);
                        }
                }
-               xs << html::EndTag("tfoot");
+               xs << html::EndTag("tfoot") << html::CR();
        }
 
-       xs << html::StartTag("tbody");
+       xs << html::StartTag("tbody") << html::CR();
        for (row_type r = 0; r < nrows(); ++r) {
                if (isValidRow(r)) {
                        ret += xhtmlRow(xs, r, runparams);
                }
        }
        xs << html::EndTag("tbody")
-          << html::EndTag("table");
+          << html::CR()
+          << html::EndTag("table")
+          << html::CR();
        if (is_long_tabular)
-               xs << html::EndTag("div");
+               xs << html::EndTag("div") << html::CR();
        return ret;
 }
 
@@ -3992,6 +4009,8 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cmd = FuncRequest(finish_lfun);
                else
                        cur.dispatched();
+
+               cur.screenUpdateFlags(Update::Force | Update::FitCursor);
                break;
 
        }
@@ -4028,6 +4047,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cur.setCurrentFont();
                        return;
                }
+               cur.screenUpdateFlags(Update::FitCursor);
                break;
 
        case LFUN_UP_SELECT:
@@ -4061,6 +4081,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                        cur.setCurrentFont();
                        return;
                }
+               cur.screenUpdateFlags(Update::FitCursor);
                break;
 
 //     case LFUN_SCREEN_DOWN: {
@@ -4272,8 +4293,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 +4652,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 +5196,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: