]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
Fix fuer #209
[lyx.git] / src / tabular.C
index d8623ee958b40acb5018c68e64e2df6cd81d88d2..97b1a00ad92576017d52ff6138bc6fbfd303cf8c 100644 (file)
@@ -552,7 +552,7 @@ int LyXTabular::GetAdditionalHeight(int row) const
        bool top = true;
        bool bottom = true;
 
-       for (int column = 0; column < columns_ - 1 && bottom; ++column) {
+       for (int column = 0; column < columns_ && bottom; ++column) {
                switch (cell_info[row - 1][column].multicolumn) {
                case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
                        bottom = cell_info[row - 1][column].bottom_line;
@@ -561,7 +561,7 @@ int LyXTabular::GetAdditionalHeight(int row) const
                        bottom = row_info[row - 1].bottom_line;
                }
        }
-       for (int column = 0; column < columns_ - 1 && top; ++column) {
+       for (int column = 0; column < columns_ && top; ++column) {
                switch (cell_info[row][column].multicolumn){
                case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
                        top = cell_info[row][column].top_line;
@@ -2647,13 +2647,53 @@ InsetText * LyXTabular::GetCellInset(int row, int column) const
 }
 
 
+int LyXTabular::GetCellFromInset(Inset const * inset, int maybe_cell) const
+{
+       // is this inset part of the tabular?
+       if (!inset || inset->owner() != owner_) {
+               lyxerr[Debug::INSETTEXT]
+                       << "this is not a cell of the tabular!" << endl;
+               return -1;
+       }
+       
+       const int save_cur_cell = cur_cell;
+       int cell = cur_cell;
+       if (GetCellInset(cell) != inset) {
+               cell = maybe_cell;
+               if (cell == -1 || GetCellInset(cell) != inset) {
+                       cell = -1;
+               }
+       }
+       
+       if (cell == -1) {
+               for (cell = GetNumberOfCells(); cell >= 0; --cell) {
+                       if (GetCellInset(cell) == inset)
+                               break;
+               }
+               lyxerr[Debug::INSETTEXT]
+                        << "LyXTabular::GetCellFromInset: "
+                                   << "cell=" << cell
+                                   << ", cur_cell=" << save_cur_cell 
+                                   << ", maybe_cell=" << maybe_cell
+                                   << endl;
+               // We should have found a cell at this point
+               if (cell == -1) {
+                       lyxerr << "LyXTabular::GetCellFromInset: "
+                              << "Cell not found!" << endl;
+               }
+       }
+       
+       return cell;
+}
+
+
 void LyXTabular::Validate(LaTeXFeatures & features) const
 {
        if (IsLongTabular())
                features.require("longtable");
        if (NeedRotating())
                features.require("rotating");
-       for (int cell = 0; !features.isRequired("array") && (cell < numberofcells); ++cell) {
+       for (int cell = 0; cell < numberofcells; ++cell) {
                if (GetVAlignment(cell) != LYX_VALIGN_TOP)
                        features.require("array");
                GetCellInset(cell)->validate(features);