]> git.lyx.org Git - lyx.git/blobdiff - src/tabular.C
Forgot to add this files.
[lyx.git] / src / tabular.C
index 7acb56729297ec60fcbbea8fc060c57536f2756f..9d75e17045bc5dc7a0d35207460f5fcc24a2e110 100644 (file)
@@ -53,7 +53,7 @@ LyXTabular::cellstruct::cellstruct()
     top_line = true;
     bottom_line = false;
     rotate = false;
-    linebreaks = false;
+    usebox = false;
 }
 
 
@@ -249,7 +249,7 @@ void LyXTabular::AppendColumn(int cell)
                                                          cellstruct()));
     int column = column_of_cell(cell);
     int i, j;
-    column_vector::iterator cit = column_info.begin() + column;
+    column_vector::iterator cit = column_info.begin() + column + 1;
     column_info.insert(cit, columnstruct());
 
     for (i = 0; i < rows_; ++i) {
@@ -544,11 +544,13 @@ bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
     }
     // set the width to MAX_WIDTH until width > 0
     int width = (new_width + 2 * WIDTH_OF_LINE);
-    for (i = column1; (i < column2) && (width > 0); ++i) {
+    for (i = column1; (i < column2) && (width>column_info[i].width_of_column);
+        ++i)
+    {
         cell_info[row][i].width_of_cell = column_info[i].width_of_column;
         width -= column_info[i].width_of_column;
     }
-    if (i == column2) {
+    if (width > 0) {
         cell_info[row][i].width_of_cell = width;
     }
     return true;
@@ -578,10 +580,12 @@ bool LyXTabular::SetWidthOfCell(int cell, int new_width)
 {
     int row = row_of_cell(cell);
     int column1 = column_of_cell(cell);
-    int tmp = 0;
+    bool tmp = false;
     int width = 0;
 
-    if (IsMultiColumn(cell)) {
+    if (GetWidthOfCell(cell) == (new_width+2*WIDTH_OF_LINE))
+       return false;
+    if (IsMultiColumn(cell, true)) {
         tmp = SetWidthOfMulticolCell(cell, new_width);
     } else {
        width = (new_width + 2*WIDTH_OF_LINE);
@@ -779,9 +783,6 @@ int LyXTabular::GetWidthOfCell(int cell) const
     for (; i <= column2; ++i) {
        result += cell_info[row][i].width_of_cell;
     }
-    
-//    result += GetAdditionalWidth(cell);
-    
     return result;
 }
 
@@ -847,12 +848,16 @@ bool LyXTabular::calculate_width_of_column(int column)
 }
 
 
+///
+/// calculate the with of the column without regarding REAL MultiColumn
+/// cells. This means MultiColumn-cells spanning more than 1 column.
+///
 bool LyXTabular::calculate_width_of_column_NMC(int column)
 {
     int old_column_width = column_info[column].width_of_column;
     int max = 0;
     for (int i = 0; i < rows_; ++i) {
-        if (!IsMultiColumn(GetCellNumber(i, column)) &&
+        if (!IsMultiColumn(GetCellNumber(i, column), true) &&
             (cell_info[i][column].width_of_cell > max)) {
             max = cell_info[i][column].width_of_cell;
         }
@@ -940,7 +945,7 @@ void LyXTabular::Write(Buffer const * buf, ostream & os) const
                " leftline=" << cell_info[i][j].left_line <<
                " rightline=" << cell_info[i][j].right_line <<
                " rotate=" << cell_info[i][j].rotate <<
-               " linebreaks=" << cell_info[i][j].linebreaks <<
+               " usebox=" << cell_info[i][j].usebox <<
                " width=\"" << cell_info[i][j].p_width <<
                "\" special=\"" << cell_info[i][j].align_special <<
                "\">" << endl;
@@ -1110,7 +1115,7 @@ void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
            (void)getTokenValue(line, "leftline", cell_info[i][j].left_line);
            (void)getTokenValue(line, "rightline", cell_info[i][j].right_line);
            (void)getTokenValue(line, "rotate", cell_info[i][j].rotate);
-           (void)getTokenValue(line, "linebreaks", cell_info[i][j].linebreaks);
+           (void)getTokenValue(line, "usebox", cell_info[i][j].usebox);
            (void)getTokenValue(line, "width", cell_info[i][j].p_width);
            (void)getTokenValue(line, "special", cell_info[i][j].align_special);
            l_getline(is, line);
@@ -1248,7 +1253,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
                cell_info[i][j].top_line = static_cast<char>(c);
                cell_info[i][j].bottom_line = static_cast<char>(d);
                cell_info[i][j].rotate = static_cast<bool>(f);
-               cell_info[i][j].linebreaks = static_cast<bool>(g);
+               cell_info[i][j].usebox = static_cast<bool>(g);
                cell_info[i][j].align_special = s1;
                cell_info[i][j].p_width = s2;
            }
@@ -1326,7 +1331,7 @@ void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
            }
            inset = GetCellInset(cell);
            row = row_of_cell(cell);
-           if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].linebreaks)
+           if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox)
            {
                // insert a space instead
                par->Erase(i);
@@ -1509,9 +1514,10 @@ int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
 }
 
 
-bool LyXTabular::IsMultiColumn(int cell) const
+bool LyXTabular::IsMultiColumn(int cell, bool real) const
 {
-    return (cellinfo_of_cell(cell)->multicolumn != LyXTabular::CELL_NORMAL);
+    return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&
+       (cellinfo_of_cell(cell)->multicolumn !=LyXTabular::CELL_NORMAL));
 }
 
 
@@ -1684,18 +1690,20 @@ int LyXTabular::GetCellNumber(int row, int column) const
 }
 
 
-void LyXTabular::SetLinebreaks(int cell, bool what)
+void LyXTabular::SetUsebox(int cell, int what)
 {
-    cellinfo_of_cell(cell)->linebreaks = what;
+    cellinfo_of_cell(cell)->usebox = what;
 }
 
 
-bool LyXTabular::GetLinebreaks(int cell) const
+int LyXTabular::GetUsebox(int cell) const
 {
     if (column_info[column_of_cell(cell)].p_width.empty() &&
         !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
-        return false;
-    return cellinfo_of_cell(cell)->linebreaks;
+        return 0;
+    if (cellinfo_of_cell(cell)->usebox > 1)
+       return cellinfo_of_cell(cell)->usebox;
+    return UseParbox(cell);
 }
 
 
@@ -1950,7 +1958,7 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
            os << "}{";
        }
     }
-    if (GetLinebreaks(cell)) {
+    if (GetUsebox(cell) == 1) {
        os << "\\parbox[";
        switch(GetVAlignment(cell)) {
        case LYX_VALIGN_TOP:
@@ -1963,7 +1971,22 @@ int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
            os << "b";
            break;
        }
-       os << "]{" << GetPWidth(cell) << "}{\\smallskip{}";
+       os << "]{" << GetPWidth(cell) << "}{";
+    } else if (GetUsebox(cell) == 2) {
+       os << "\\begin{minipage}[";
+       switch(GetVAlignment(cell)) {
+       case LYX_VALIGN_TOP:
+           os << "t";
+           break;
+       case LYX_VALIGN_CENTER:
+           os << "m";
+           break;
+       case LYX_VALIGN_BOTTOM:
+           os << "b";
+           break;
+       }
+       os << "]{" << GetPWidth(cell) << "}\n";
+       ++ret;
     }
     return ret;
 }
@@ -1974,13 +1997,17 @@ int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
     int ret = 0;
 
     // usual cells
-    if (GetLinebreaks(cell))
-       os << "\\smallskip{}}";
+    if (GetUsebox(cell) == 1)
+       os << "}";
+    else if (GetUsebox(cell) == 2) {
+       os << "%\n\\end{minipage}";
+       ret += 2;
+    }
     if (IsMultiColumn(cell)){
        os << '}';
     }
     if (GetRotateCell(cell)) {
-       os << endl << "\\end{sideways}";
+       os << "%\n\\end{sideways}";
        ++ret;
     }
     return ret;
@@ -2150,3 +2177,17 @@ void LyXTabular::Validate(LaTeXFeatures & features) const
        GetCellInset(cell)->Validate(features);
     }
 }
+
+
+bool LyXTabular::UseParbox(int cell) const
+{
+    LyXParagraph *par = GetCellInset(cell)->par;
+
+    for(;par; par = par->next) {
+       for(int i = 0; i < par->Last(); ++i) {
+           if (par->GetChar(i) == LyXParagraph::META_NEWLINE)
+               return true;
+       }
+    }
+    return false;
+}