]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetTabular.cpp
InsetTabular.cpp: fix #6585 also for wrapped floats - thanks Vincent
[lyx.git] / src / insets / InsetTabular.cpp
index 806d8256f29f7c96a2e7d481f9983ce936e1e514..39819a3cd211ad52002956027946e2feff89e203 100644 (file)
@@ -523,11 +523,11 @@ InsetTableCell splitCell(InsetTableCell & head, docstring const align_d, bool &
 
        pit_type const psize = head.paragraphs().front().size();
        hassep = dit;
-       if (hassep)
+       if (hassep) {
                head.paragraphs().front().eraseChars(dit.pos(), psize, false);
-
-       tail.paragraphs().front().eraseChars(0, 
-               dit.pos() < psize ? dit.pos() + 1 : psize, false);
+               tail.paragraphs().front().eraseChars(0, 
+                       dit.pos() < psize ? dit.pos() + 1 : psize, false);
+       }
 
        return tail;
 }
@@ -580,7 +580,7 @@ Tabular::CellData::CellData(CellData const & cs)
          rotate(cs.rotate),
          align_special(cs.align_special),
          p_width(cs.p_width),
-         inset(dynamic_cast<InsetTableCell *>(cs.inset->clone()))
+         inset(static_cast<InsetTableCell *>(cs.inset->clone()))
 {
 }
 
@@ -1995,29 +1995,29 @@ int Tabular::TeXTopHLine(odocstream & os, row_type row, string const lang) const
                }
        } else if (row == 0) {
                for (col_type c = 0; c < ncols(); ++c) {
-                       for ( ; c < ncols() && !topline[c]; ++c) {}
-
-                       col_type offset = 0;
-                       for (col_type j = 0 ; j < c; ++j)
-                               if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
-                                       ++offset;
-
-                       //babel makes the "-" character an active one, so we have to suppress this here
-                       //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
-                       if (lang == "slovak" || lang == "czech")
-                               os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline") 
-                                  << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
-                       else
-                               os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
-
-                       col_type cstart = c;
-                       for ( ; c < ncols() && topline[c]; ++c) {}
-
-                       for (col_type j = cstart ; j < c ; ++j)
-                               if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
-                                       ++offset;
-
-                       os << c + offset << "} ";
+                       if (topline[c]) {
+                               col_type offset = 0;
+                               for (col_type j = 0 ; j < c; ++j)
+                                       if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
+                                               ++offset;
+                               
+                               //babel makes the "-" character an active one, so we have to suppress this here
+                               //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
+                               if (lang == "slovak" || lang == "czech")
+                                       os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline") 
+                                       << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
+                               else
+                                       os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
+                               
+                               col_type cstart = c;
+                               for ( ; c < ncols() && topline[c]; ++c) {}
+                               
+                               for (col_type j = cstart ; j < c ; ++j)
+                                       if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
+                                               ++offset;
+                               
+                               os << c + offset << "} ";
+                       }
                }
        }
        os << "\n";
@@ -2068,29 +2068,29 @@ int Tabular::TeXBottomHLine(odocstream & os, row_type row, string const lang) co
                        os << "\\hline ";
        } else {
                for (col_type c = 0; c < ncols(); ++c) {
-                       for ( ; c < ncols() && !bottomline[c]; ++c) {}
-
-                       col_type offset = 0;
-                       for (col_type j = 0 ; j < c; ++j)
-                               if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
-                                       ++offset;
-
-                       //babel makes the "-" character an active one, so we have to suppress this here
-                       //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
-                       if (lang == "slovak" || lang == "czech")
-                               os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline") 
-                                  << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
-                       else
-                               os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
-
-                       col_type cstart = c;
-                       for ( ; c < ncols() && bottomline[c]; ++c) {}
-
-                       for (col_type j = cstart ; j < c ; ++j)
-                               if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
-                                       ++offset;
-
-                       os << c + offset << "} ";
+                       if (bottomline[c]) {
+                               col_type offset = 0;
+                               for (col_type j = 0 ; j < c; ++j)
+                                       if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
+                                               ++offset;
+                               
+                               //babel makes the "-" character an active one, so we have to suppress this here
+                               //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
+                               if (lang == "slovak" || lang == "czech")
+                                       os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline")
+                                       << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
+                               else
+                                       os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
+                               
+                               col_type cstart = c;
+                               for ( ; c < ncols() && bottomline[c]; ++c) {}
+                               
+                               for (col_type j = cstart ; j < c ; ++j)
+                                       if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
+                                               ++offset;
+                               
+                               os << c + offset << "} ";
+                       }
                }
        }
        os << "\n";
@@ -2201,7 +2201,6 @@ int Tabular::TeXCellPreamble(odocstream & os, idx_type cell,
                        os << from_ascii(getPWidth(cell).asLatexString());
                else
                        // we need to set a default value
-                       // needs to be discussed
                        os << "*";
                os << "}{";
        } // end if ismultirow
@@ -3480,7 +3479,7 @@ void InsetTabular::draw(PainterInfo & pi, int x, int y) const
                        // Cache the Inset position.
                        bv->coordCache().insets().add(cell(idx).get(), cx, cy);
                        cell(idx)->draw(pi, cx, cy);
-                       drawCellLines(pi.pain, nx, y, r, idx, pi.change_);
+                       drawCellLines(pi, nx, y, r, idx);
                        nx += tabular.cellWidth(idx);
                        pi.selected = original_selection_state;
                }
@@ -3551,25 +3550,25 @@ void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
 }
 
 
-void InsetTabular::drawCellLines(Painter & pain, int x, int y,
-                                                                row_type row, idx_type cell, Change const & change) const
+void InsetTabular::drawCellLines(PainterInfo & pi, int x, int y,
+                                row_type row, idx_type cell) const
 {
        y -= tabular.rowAscent(row);
        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;
+       Color const linecolor = pi.textColor(Color_tabularline);
+       Color const gridcolor = pi.textColor(Color_tabularonoffline);
 
        // Top
        bool drawline = tabular.topLine(cell)
                || (row > 0 && tabular.bottomLine(tabular.cellAbove(cell)));
-       pain.line(x, y, x + w, y,
+       pi.pain.line(x, y, x + w, y,
                drawline ? linecolor : gridcolor,
                drawline ? Painter::line_solid : Painter::line_onoffdash);
 
        // Bottom
        drawline = tabular.bottomLine(cell);
-       pain.line(x, y + h, x + w, y + h,
+       pi.pain.line(x, y + h, x + w, y + h,
                drawline ? linecolor : gridcolor,
                drawline ? Painter::line_solid : Painter::line_onoffdash);
 
@@ -3577,7 +3576,7 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y,
        col_type const col = tabular.cellColumn(cell);
        drawline = tabular.leftLine(cell)
                || (col > 0 && tabular.rightLine(tabular.cellIndex(row, col - 1)));
-       pain.line(x, y, x, y + h,
+       pi.pain.line(x, y, x, y + h,
                drawline ? linecolor : gridcolor,
                drawline ? Painter::line_solid : Painter::line_onoffdash);
 
@@ -3586,7 +3585,7 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int y,
        drawline = tabular.rightLine(cell)
                   || (col + 1 < tabular.ncols()
                       && tabular.leftLine(tabular.cellIndex(row, col + 1)));
-       pain.line(x + w, y, x + w, y + h,
+       pi.pain.line(x + w, y, x + w, y + h,
                drawline ? linecolor : gridcolor,
                drawline ? Painter::line_solid : Painter::line_onoffdash);
 }
@@ -3773,7 +3772,15 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_CHAR_RIGHT_SELECT:
        case LFUN_CHAR_RIGHT:
        case LFUN_CHAR_LEFT_SELECT:
-       case LFUN_CHAR_LEFT: {
+       case LFUN_CHAR_LEFT: 
+       case LFUN_WORD_FORWARD:
+       case LFUN_WORD_FORWARD_SELECT:
+       case LFUN_WORD_BACKWARD:
+       case LFUN_WORD_BACKWARD_SELECT:
+       case LFUN_WORD_RIGHT:
+       case LFUN_WORD_RIGHT_SELECT:
+       case LFUN_WORD_LEFT:
+       case LFUN_WORD_LEFT_SELECT: {
                // determine whether we move to next or previous cell, where to enter 
                // the new cell from, and which command to "finish" (i.e., exit the
                // inset) with:
@@ -3782,12 +3789,16 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                FuncCode finish_lfun;
 
                if (act == LFUN_CHAR_FORWARD 
-                               || act == LFUN_CHAR_FORWARD_SELECT) {
+                               || act == LFUN_CHAR_FORWARD_SELECT
+                               || act == LFUN_WORD_FORWARD
+                               || act == LFUN_WORD_FORWARD_SELECT) {
                        next_cell = true;
                        finish_lfun = LFUN_FINISHED_FORWARD;
                }
                else if (act == LFUN_CHAR_BACKWARD
-                               || act == LFUN_CHAR_BACKWARD_SELECT) {
+                               || act == LFUN_CHAR_BACKWARD_SELECT
+                               || act == LFUN_WORD_BACKWARD
+                               || act == LFUN_WORD_BACKWARD_SELECT) {
                        next_cell = false;
                        finish_lfun = LFUN_FINISHED_BACKWARD;
                }
@@ -3795,7 +3806,9 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                // table's direction.
                else {
                        bool const right = act == LFUN_CHAR_RIGHT
-                               || act == LFUN_CHAR_RIGHT_SELECT;
+                               || act == LFUN_CHAR_RIGHT_SELECT
+                               || act == LFUN_WORD_RIGHT
+                               || act == LFUN_WORD_RIGHT_SELECT;
                        next_cell = isRightToLeft(cur) != right;
                        
                        if (lyxrc.visual_cursor)
@@ -3804,10 +3817,14 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
                        finish_lfun = right ? LFUN_FINISHED_RIGHT : LFUN_FINISHED_LEFT;
                }
 
-               bool const select = act == LFUN_CHAR_FORWARD_SELECT ||
-                   act == LFUN_CHAR_BACKWARD_SELECT ||
-                   act == LFUN_CHAR_RIGHT_SELECT ||
-                   act == LFUN_CHAR_LEFT_SELECT;
+               bool const select =     act == LFUN_CHAR_FORWARD_SELECT 
+                   || act == LFUN_CHAR_BACKWARD_SELECT
+                   || act == LFUN_CHAR_RIGHT_SELECT
+                   || act == LFUN_CHAR_LEFT_SELECT
+                       || act == LFUN_WORD_FORWARD_SELECT
+                       || act == LFUN_WORD_RIGHT_SELECT
+                       || act == LFUN_WORD_BACKWARD_SELECT
+                       || act == LFUN_WORD_LEFT_SELECT;
 
                // If we have a multicell selection or we're 
                // not doing some LFUN_*_SELECT thing anyway...
@@ -4296,6 +4313,10 @@ bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
                        break;
 
                case Tabular::SET_LONGTABULAR:
+                       // setting as longtable is not allowed when table is inside a float
+                       if (cur.innerInsetOfType(FLOAT_CODE) != 0
+                               || cur.innerInsetOfType(WRAP_CODE) != 0)
+                               status.setEnabled(false);
                        status.setOnOff(tabular.is_long_tabular);
                        break;