]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
Fix working of the spellchecker dialog with ispell when there are no
[lyx.git] / src / tabular.C
index 99e7816168bc011a4d64bf3c845fd3b14a4161a6..6c5d2f388c3055079546c7f0efe12d579168b851 100644 (file)
@@ -16,6 +16,9 @@
 #pragma implementation
 #endif
 
+// temporary until verified (08/08/2001 Jug)
+#define SPECIAL_COLUM_HANDLING 1
+
 #include <algorithm>
 #include <cstdlib>
 
@@ -30,6 +33,7 @@
 #include "LaTeXFeatures.h"
 #include "support/lstrings.h"
 #include "support/lyxmanip.h"
+#include "support/LAssert.h"
 #include "insets/insettabular.h"
 #include "insets/insettext.h"
 #include "gettext.h"
@@ -434,17 +438,43 @@ bool LyXTabular::BottomLine(int cell, bool onlycolumn) const
 
 bool LyXTabular::LeftLine(int cell, bool onlycolumn) const
 {
-       if (!onlycolumn && IsMultiColumn(cell))
+       if (!onlycolumn && IsMultiColumn(cell)) {
+#ifdef SPECIAL_COLUM_HANDLING
+               if (cellinfo_of_cell(cell)->align_special.empty())
+                       return cellinfo_of_cell(cell)->left_line;
+               return prefixIs(frontStrip(cellinfo_of_cell(cell)->align_special), "|");
+#else
                return cellinfo_of_cell(cell)->left_line;
+#endif
+       }
+#ifdef SPECIAL_COLUM_HANDLING
+       if (column_info[column_of_cell(cell)].align_special.empty())
+               return column_info[column_of_cell(cell)].left_line;
+       return prefixIs(frontStrip(column_info[column_of_cell(cell)].align_special), "|");
+#else
        return column_info[column_of_cell(cell)].left_line;
+#endif
 }
 
 
 bool LyXTabular::RightLine(int cell, bool onlycolumn) const
 {
-       if (!onlycolumn && IsMultiColumn(cell))
+       if (!onlycolumn && IsMultiColumn(cell)) {
+#ifdef SPECIAL_COLUM_HANDLING
+               if (cellinfo_of_cell(cell)->align_special.empty())
+                       return cellinfo_of_cell(cell)->right_line;
+               return suffixIs(strip(cellinfo_of_cell(cell)->align_special), "|");
+#else
                return cellinfo_of_cell(cell)->right_line;
+#endif
+       }
+#ifdef SPECIAL_COLUM_HANDLING
+       if (column_info[column_of_cell(cell)].align_special.empty())
+               return column_info[right_column_of_cell(cell)].right_line;
+       return suffixIs(strip(column_info[column_of_cell(cell)].align_special), "|");
+#else
        return column_info[right_column_of_cell(cell)].right_line;
+#endif
 }
 
 
@@ -477,7 +507,11 @@ bool LyXTabular::LeftAlreadyDrawed(int cell) const
                                LyXTabular::CELL_PART_OF_MULTICOLUMN));
                if (GetAdditionalWidth(cell_info[row][column].cellno))
                        return false;
+#ifdef SPECIAL_COLUM_HANDLING
                return column_info[column].right_line;
+#else
+               return RightLine(cell_info[row][column].cellno, true);
+#endif
        }
        return false;
 }
@@ -526,11 +560,14 @@ int LyXTabular::GetAdditionalWidth(int cell) const
        // internally already set in SetWidthOfCell
        // used to get it back in text.C
        int const col = right_column_of_cell(cell);
-       if (col < columns_ - 1 && column_info[col].right_line &&
-               column_info[col+1].left_line)
+       int const row = row_of_cell(cell);
+       if (col < columns_ - 1 && RightLine(cell, true) &&
+               LeftLine(cell_info[row][col+1].cellno, true)) // column_info[col+1].left_line)
+       {
                return WIDTH_OF_LINE;
-       else
+       } else {
                return 0;
+       }
 }
 
 
@@ -607,17 +644,28 @@ bool LyXTabular::SetWidthOfCell(int cell, int new_width)
        int const column1 = column_of_cell(cell);
        bool tmp = false;
        int width = 0;
+       int add_width = 0;
 
-       if (GetWidthOfCell(cell) == (new_width+2*WIDTH_OF_LINE))
+#ifdef SPECIAL_COLUM_HANDLING
+       if (RightLine(cell_info[row][column1].cellno, true) &&
+               (column1 < columns_-1) &&
+               LeftLine(cell_info[row][column1+1].cellno, true))
+#else
+       if (column_info[column1].right_line && (column1 < columns_-1) &&
+               column_info[column1+1].left_line) // additional width
+#endif
+       {
+               // additional width
+               add_width = WIDTH_OF_LINE;
+       }
+       if (GetWidthOfCell(cell) == (new_width+2*WIDTH_OF_LINE+add_width)) {
                return false;
+       }
        if (IsMultiColumn(cell, true)) {
                tmp = SetWidthOfMulticolCell(cell, new_width);
        } else {
-               width = (new_width + 2*WIDTH_OF_LINE);
+               width = (new_width + 2*WIDTH_OF_LINE + add_width);
                cell_info[row][column1].width_of_cell = width;
-               if (column_info[column1].right_line && (column1 < columns_-1) &&
-                       column_info[column1+1].left_line) // additional width
-                       cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
                tmp = calculate_width_of_column_NMC(column1);
        }
        if (tmp) {
@@ -934,6 +982,7 @@ int LyXTabular::right_column_of_cell(int cell) const
 
 
 // Perfect case for a template... (Lgb)
+// or perhaps not...
 #if 1
 template<class T>
 string const write_attribute(string const & name, T const & t)
@@ -1495,15 +1544,20 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
        LyXFont font(LyXFont::ALL_INHERIT);
        font.setLanguage(owner_->bufferOwner()->getLanguage());
 
-       while (lex.IsOK()) {
+       while (lex.isOK()) {
                lex.nextToken();
-               string const token = lex.GetString();
+               string const token = lex.getString();
                if (token.empty())
                        continue;
                if (token == "\\layout"
                        || token == "\\end_float"
                        || token == "\\end_deeper") {
                        lex.pushToken(token);
+#ifndef NO_COMPABILITY
+                       // Here we need to insert the inset_ert_contents into the last
+                       // cell of the tabular.
+                       owner_->bufferOwner()->insertErtContents(par, pos, font);
+#endif
                        break;
                }
                if (owner_->bufferOwner()->parseSingleLyXformat2Token(lex, par,
@@ -1530,7 +1584,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
        for (int i = 0; i < par->size(); ++i) {
                if (par->isNewline(i)) {
                        ++cell;
-                       if (cell > GetNumberOfCells()) {
+                       if (cell > numberofcells) {
                                lyxerr << "Some error in reading old table format occured!" <<
                                        endl << "Terminating when reading cell[" << cell << "]!" <<
                                        endl;
@@ -1556,7 +1610,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
                        }
                }
                par->copyIntoMinibuffer(*owner_->bufferOwner(), i);
-               inset->par->insertFromMinibuffer(inset->par->size());
+               inset->paragraph()->insertFromMinibuffer(inset->paragraph()->size());
        }
        delete par;
        Reinit();
@@ -1682,7 +1736,7 @@ bool LyXTabular::NeedRotating() const
 
 bool LyXTabular::IsLastCell(int cell) const
 {
-       if ((cell + 1) < GetNumberOfCells())
+       if ((cell + 1) < numberofcells)
                return false;
        return true;
 }
@@ -1726,6 +1780,7 @@ int LyXTabular::GetLastCellBelow(int cell) const
 
 int LyXTabular::GetCellNumber(int row, int column) const
 {
+#if 0
        if (column >= columns_)
                column = columns_ - 1;
        else if (column < 0)
@@ -1734,7 +1789,9 @@ int LyXTabular::GetCellNumber(int row, int column) const
                row = rows_ - 1;
        else if (row < 0)
                row = 0;
-       
+#else
+       lyx::Assert(column >= 0 || column < columns_ || row >= 0 || row < rows_);
+#endif
        return cell_info[row][column].cellno;
 }
 
@@ -2090,40 +2147,42 @@ int LyXTabular::Latex(Buffer const * buf,
        else
                os << "\\begin{tabular}{";
        for (int i = 0; i < columns_; ++i) {
-               if (column_info[i].left_line)
-                       os << '|';
                if (!column_info[i].align_special.empty()) {
                        os << column_info[i].align_special;
-               } else if (!column_info[i].p_width.empty()) {
-                       switch (column_info[i].valignment) {
-                       case LYX_VALIGN_TOP:
-                               os << "p";
-                               break;
-                       case LYX_VALIGN_CENTER:
-                               os << "m";
-                               break;
-                       case LYX_VALIGN_BOTTOM:
-                               os << "b";
-                               break;
+               } else { 
+                       if (column_info[i].left_line)
+                               os << '|';
+                       if (!column_info[i].p_width.empty()) {
+                               switch (column_info[i].valignment) {
+                               case LYX_VALIGN_TOP:
+                                       os << "p";
+                                       break;
+                               case LYX_VALIGN_CENTER:
+                                       os << "m";
+                                       break;
+                               case LYX_VALIGN_BOTTOM:
+                                       os << "b";
+                                       break;
                        }
-                       os << "{"
-                          << column_info[i].p_width
-                          << '}';
-               } else {
-                       switch (column_info[i].alignment) {
-                       case LYX_ALIGN_LEFT:
-                               os << 'l';
-                               break;
-                       case LYX_ALIGN_RIGHT:
+                               os << "{"
+                                  << column_info[i].p_width
+                                  << '}';
+                       } else {
+                               switch (column_info[i].alignment) {
+                               case LYX_ALIGN_LEFT:
+                                       os << 'l';
+                                       break;
+                               case LYX_ALIGN_RIGHT:
                                os << 'r';
                                break;
-                       default:
-                               os << 'c';
-                               break;
+                               default:
+                                       os << 'c';
+                                       break;
+                               }
                        }
+                       if (column_info[i].right_line)
+                               os << '|';
                }
-               if (column_info[i].right_line)
-                       os << '|';
        }
        os << "}\n";
        ++ret;
@@ -2163,8 +2222,8 @@ int LyXTabular::Latex(Buffer const * buf,
                        ret += TeXCellPreamble(os, cell);
                        InsetText * inset = GetCellInset(cell);
 
-                       bool rtl = inset->par->isRightToLeftPar(buf->params) &&
-                                       inset->par->size() > 0 && GetPWidth(cell).empty();
+                       bool rtl = inset->paragraph()->isRightToLeftPar(buf->params) &&
+                                       inset->paragraph()->size() > 0 && GetPWidth(cell).empty();
 
                        if (rtl)
                                os << "\\R{";
@@ -2297,7 +2356,7 @@ int LyXTabular::DocBook(Buffer const * buf, ostream & os) const
                        }
                
                        os << ">";
-                       ret += GetCellInset(cell)->docBook(buf, os);
+                       ret += GetCellInset(cell)->docbook(buf, os);
                        os << "</entry>";
                        ++cell;
                }
@@ -2530,11 +2589,6 @@ InsetText * LyXTabular::GetCellInset(int cell) const
 
 InsetText * LyXTabular::GetCellInset(int row, int column) const
 {
-#ifdef WITH_WARNINGS
-#warning Juergen, should we check whether the row/column values are correct?
-// If we do not need to do that, the tests in GetCellNumber should be
-// changed to asserts.
-#endif
        cur_cell = GetCellNumber(row, column);
        return & cell_info[row][column].inset;
 }
@@ -2570,7 +2624,7 @@ std::vector<string> const LyXTabular::getLabelList() const
                        
 LyXTabular::BoxType LyXTabular::UseParbox(int cell) const
 {
-       Paragraph * par = GetCellInset(cell)->par;
+       Paragraph * par = GetCellInset(cell)->paragraph();
 
        for (; par; par = par->next()) {
                for (int i = 0; i < par->size(); ++i) {