]> 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 b28f334fc7a4a1d6be60c669b6e95fc038df848c..39819a3cd211ad52002956027946e2feff89e203 100644 (file)
@@ -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
@@ -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;