X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Ftable.C;h=2b585c939523ee08e7f20ddca1a2ff90040bed63;hb=a040c0bc6f017d0591bbc7ad1aa590589dbc40ff;hp=11531464456f375c0b1e95da64cec45bc4e5270d;hpb=2f3e0b32e674f2932c123b87df954a34c4518594;p=lyx.git diff --git a/src/table.C b/src/table.C index 1153146445..2b585c9395 100644 --- a/src/table.C +++ b/src/table.C @@ -1,12 +1,12 @@ /* This file is part of - * ====================================================== + * ====================================================== * * LyX, The Document Processor * * Copyright (C) 1995 Matthias Ettrich * Copyright (C) 1995-1998 The LyX Team. * - *====================================================== + * ====================================================== */ #include @@ -45,7 +45,7 @@ LyXTable::~LyXTable() { delete[] columnofcell; delete[] column_info; delete[] row_info; - for (i=0; icell_info[row][column] = cell_info[row][column]; } } - for (row=0; rowrow_info[row] = row_info[row]; } - for (column=0; columncolumn_info[column].left_line = column_info[column].left_line; result->column_info[column].right_line = column_info[column].right_line; result->column_info[column].alignment = column_info[column].alignment; @@ -76,7 +76,7 @@ LyXTable* LyXTable::Clone() } result->SetLongTable(is_long_table); - result->rotate=rotate; + result->rotate = rotate; result->Reinit(); return result; } @@ -85,7 +85,7 @@ LyXTable* LyXTable::Clone() /* activates all lines and sets all widths to 0 */ void LyXTable::Init(int rows_arg, int columns_arg) { - int i,j,cellno; + int i, j, cellno; rows = rows_arg; columns = columns_arg; column_info = new columnstruct[columns]; @@ -93,13 +93,13 @@ void LyXTable::Init(int rows_arg, int columns_arg) cell_info = new cellstruct*[rows]; cellno = 0; - for (i=0; i= row; i--) { + for (i = rows-1; i >= row; i--) { cell_info2[i+1] = cell_info[i]; row_info2[i+1] = row_info[i]; } - for (i=row;row_info[i].is_cont_row;i--); - if (((row+1)>=rows) || !row_info[row+1].is_cont_row) + for (i = row;row_info[i].is_cont_row;i--); + if (((row+1)>= rows) || !row_info[row+1].is_cont_row) row_info2[row+1].is_cont_row = false; row_info2[row+1].top_line = row_info[i].top_line; cell_info2[row+1] = new cellstruct[columns]; - for (i=0; i=column; i--){ + for (i = columns-1; i>= column; i--){ column_info2[i+1] = column_info[i]; } delete[] column_info; column_info = column_info2; - for (i=0; i= numberofcells) return false; - int row=row_of_cell(cell); + int row = row_of_cell(cell); if (RowHasContRow(cell)) return BottomLine(cell_info[row+1][column_of_cell(cell)].cellno); @@ -445,7 +445,7 @@ int LyXTable::AdditionalHeight(int cell) int bottom = 1; int column; if (row){ - for (column=0;column < columns-1 && bottom;column++){ + for (column = 0;column < columns-1 && bottom;column++){ switch (cell_info[row-1][column].multicolumn){ case LyXTable::CELL_BEGIN_OF_MULTICOLUMN: bottom = cell_info[row-1][column].bottom_line; @@ -454,7 +454,7 @@ int LyXTable::AdditionalHeight(int cell) bottom = row_info[row-1].bottom_line; } } - for (column=0;column < columns-1 && top;column++){ + for (column = 0;column < columns-1 && top;column++){ switch (cell_info[row][column].multicolumn){ case LyXTable::CELL_BEGIN_OF_MULTICOLUMN: top = cell_info[row][column].top_line; @@ -489,8 +489,8 @@ int LyXTable::WidthOfColumn(int cell) int column1 = column_of_cell(cell); int column2 = right_column_of_cell(cell); int i; - int result=0; - for (i=column1; i<=column2;i++){ + int result = 0; + for (i = column1; i<= column2;i++){ result += column_info[i].width_of_column; } return result; @@ -512,19 +512,19 @@ bool LyXTable::SetWidthOfMulticolCell(int cell, int new_width) int column1 = column_of_cell(cell); int column2 = right_column_of_cell(cell); int i; - int width=0; + int width = 0; // first set columns to 0 so we can calculate the right width - for (i=column1; i<=column2;i++) { + for (i = column1; i<= column2;i++) { cell_info[row][i].width_of_cell = 0; } // set the width to MAX_WIDTH until width > 0 width = (new_width + 2*WIDTH_OF_LINE); - for (i=column1; (i 0);i++){ + for (i = column1; (i 0);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 (i == column2) { cell_info[row][i].width_of_cell = width; } return true; @@ -539,13 +539,13 @@ void LyXTable::recalculateMulticolCells(int cell, int new_width) i; // first set columns to 0 so we can calculate the right width - for (i=column1; i<=column2;++i) + for (i = column1; i<= column2;++i) cell_info[row][i].width_of_cell = 0; - for(i=cell+1;(ip_width = width; } else { column_info[column_of_cell(fvcell)].p_width = width; - SetAlignment(cell,LYX_ALIGN_LEFT); + if (!width.empty()) // do this only if there is a width + SetAlignment(cell, LYX_ALIGN_LEFT); } return true; } @@ -617,10 +618,10 @@ bool LyXTable::SetAlignSpecial(int cell, string special, int what) bool LyXTable::SetAllLines(int cell, bool line) { - SetTopLine(cell,line); - SetBottomLine(cell,line); - SetRightLine(cell,line); - SetLeftLine(cell,line); + SetTopLine(cell, line); + SetBottomLine(cell, line); + SetRightLine(cell, line); + SetLeftLine(cell, line); return true; } @@ -629,7 +630,7 @@ bool LyXTable::SetTopLine(int cell, bool line) int row = row_of_cell(cell); if (IsContRow(cell)) - SetTopLine(cell_info[row-1][column_of_cell(cell)].cellno,line); + SetTopLine(cell_info[row-1][column_of_cell(cell)].cellno, line); else if (!IsMultiColumn(cell)) row_info[row].top_line = line; else @@ -643,7 +644,7 @@ bool LyXTable::SetBottomLine(int cell, bool line) int row = row_of_cell(cell); if (RowHasContRow(cell)) - SetBottomLine(cell_info[row+1][column_of_cell(cell)].cellno,line); + SetBottomLine(cell_info[row+1][column_of_cell(cell)].cellno, line); else if (!IsMultiColumn(cell)) row_info[row_of_cell(cell)].bottom_line = line; else @@ -696,8 +697,8 @@ int LyXTable::GetWidthOfCell(int cell) int column1 = column_of_cell(cell); int column2 = right_column_of_cell(cell); int i; - int result=0; - for (i=column1; i<=column2;i++){ + int result = 0; + for (i = column1; i<= column2;i++){ result += cell_info[row][i].width_of_cell; } @@ -744,7 +745,7 @@ bool LyXTable::calculate_width_of_column(int column) int i, max; int old_column_width = column_info[column].width_of_column; max = 0; - for (i=0; i max) { max = cell_info[i][column].width_of_cell; } @@ -758,8 +759,8 @@ bool LyXTable::calculate_width_of_column_NMC(int column) int i, max; int old_column_width = column_info[column].width_of_column; max = 0; - for (i=0; i max)) { max = cell_info[i][column].width_of_cell; } @@ -770,9 +771,8 @@ bool LyXTable::calculate_width_of_column_NMC(int column) void LyXTable::calculate_width_of_table() { - int i; width_of_table = 0; - for (i=0; i 2) { - fgets(vtmp,sizeof(vtmp),file); - sscanf(vtmp, "%d %d %d %d %d %d %d %d\n", &rows_arg, &columns_arg, - &is_long_table_arg, &rotate_arg, &a, &b, &c, &d); - } else - fscanf(file, "%d %d\n", - &rows_arg, &columns_arg); +#ifdef WITH_WARNINGS +#warning Insert a error message window here that this format is not supported anymore +#endif + if (version < 5) { + fprintf(stderr, "Tabular format < 5 is not supported anymore\n" + "Get an older version of LyX (< 1.1.x) for conversion!\n"); + return; + } + a = b = c = d = -1; + fgets(vtmp, sizeof(vtmp), file); + sscanf(vtmp, "%d %d %d %d %d %d %d %d\n", &rows_arg, &columns_arg, + &is_long_table_arg, &rotate_arg, &a, &b, &c, &d); Init(rows_arg, columns_arg); SetLongTable(is_long_table_arg); SetRotateTable(rotate_arg); @@ -887,9 +888,9 @@ void LyXTable::Read(FILE* file) endfirsthead = b; endfoot = c; endlastfoot = d; - for (i=0; i= 0) { - fprintf(file,"\nT}"); + fprintf(file, "\nT}"); ret++; } fprintf(file, "\n"); @@ -1343,14 +1317,14 @@ int LyXTable::RoffEndOfCell(FILE* file, int cell) fprintf(file, ".TE\n.pl 1c"); } else { if (cell < 0){ - int fcell=0; + int fcell = 0; // preamble fprintf(file, "\n.pl 500c\n.TS\n"); - for (j=0; j= 0) { - fprintf(file,"T{\n"); + fprintf(file, "T{\n"); ret++; } } else { // usual cells if (CellHasContRow(cell) >= 0) { - fprintf(file,"\nT}"); + fprintf(file, "\nT}"); ret++; } if (right_column_of_cell(cell) == columns -1){ @@ -1407,7 +1381,7 @@ int LyXTable::RoffEndOfCell(FILE* file, int cell) fprintf(file, "\t"); if ((cell < GetNumberOfCells() - 1) && (CellHasContRow(cell+1) >= 0)) { - fprintf(file,"T{\n"); + fprintf(file, "T{\n"); ret++; } } @@ -1415,7 +1389,7 @@ int LyXTable::RoffEndOfCell(FILE* file, int cell) return ret; } -const char *LyXTable::getDocBookAlign(int cell, bool isColumn) +char const *LyXTable::getDocBookAlign(int cell, bool isColumn) { int i; if (isColumn) @@ -1461,53 +1435,13 @@ const char *LyXTable::getDocBookAlign(int cell, bool isColumn) // cell <0 will tex the preamble // returns the number of printed newlines -int LyXTable::DocBookEndOfCell(string& file, int cell, int &depth) +int LyXTable::DocBookEndOfCell(string & file, int cell, int &depth) { int i; int ret = 0; //int tmp; // tmp2; // unused int nvcell; // fcell; // unused if (ShouldBeVeryLastCell(cell)) { -#if 0 - // the very end at the very beginning - if (Linebreaks(cell)) - file += "\\smallskip{}}"; - if (IsMultiColumn(cell)) - file += '}'; - if (RotateCell(cell)) { - file += "\n\\end{sideways}"; - ret++; - } - file += "\\\\\n"; - ret++; - - tmp = 0; - fcell = cell; - while (!IsFirstCell(fcell))fcell--; - for (i=0; i < NumberOfCellsInRow(fcell); i++){ - if (BottomLine(fcell+i)) - tmp++; - } - if (tmp == NumberOfCellsInRow(fcell)){ - file += "\\hline "; - } else { - tmp = 0; - for (i=0; i < NumberOfCellsInRow(fcell); i++){ - if (BottomLine(fcell+i)){ - file += "\\cline{"; - file += column_of_cell(fcell+i)+1; - file += '-'; - file += right_column_of_cell(fcell+i)+1; - file += "} "; - tmp = 1; - } - } - } - if (tmp){ - file += '\n'; - ret++; - } -#endif addNewlineAndDepth(file,--depth); file += ""; addNewlineAndDepth(file,--depth); @@ -1520,12 +1454,6 @@ int LyXTable::DocBookEndOfCell(string& file, int cell, int &depth) else file += ""; addNewlineAndDepth(file,--depth); -#if 0 - if (rotate) { - file += "\n\\end{sideways}"; - ret++; - } -#endif ret += 4; } else { nvcell = NextVirtualCell(cell+1); @@ -1540,14 +1468,14 @@ int LyXTable::DocBookEndOfCell(string& file, int cell, int &depth) file += "' COLSEP='1' ROWSEP='1'>"; addNewlineAndDepth(file,++depth); ret++; - for (i=0; i= 0) && -// (sflag2 || (row == endhead) || (row == endfirsthead)); - row += 2; - bool sflag1 = IsLongTable() && (row != endhead) && - (row != endfirsthead) && - ((row == endfoot) || (row == endlastfoot)); - row--; - if (IsLongTable() && (row == endhead)) { - file += "\\endhead\n"; - ret++; - } - if (IsLongTable() && (row == endfirsthead)) { - file += "\\endfirsthead\n"; - ret++; - } - if (sflag1) { // add the \hline for next foot row - if (!hline1.empty()) { - file += hline1 + '\n'; - ret++; - } - } - // add the \hline for the first row - if (pr_top_hline && sflag2) { - if (!hline2.empty()) { - file += hline2 + '\n'; - ret++; - } - } - if (nvcell < numberofcells && RotateCell(nvcell)) { - file += "\\begin{sideways}\n"; - ret++; - } -#endif } else { addNewlineAndDepth(file,--depth); file += ""; - addNewlineAndDepth(file,depth); - file += "align_special.empty()) { - file += cellinfo_of_cell(cell+1)->align_special; - file += "}{"; - } else { - if (LeftLine(nvcell)) - file += '|'; - if (!GetPWidth(nvcell).empty()) { - file += "p{"; - file += GetPWidth(nvcell); - file += '}'; - } else { - switch (GetAlignment(nvcell)) { - case LYX_ALIGN_LEFT: file += 'l'; break; - case LYX_ALIGN_RIGHT: file += 'r'; break; - default: file += 'c'; break; - } - } - if (RightLine(nvcell)) - file += '|'; - //if (column_of_cell(cell+2)!=0 && LeftLine(cell+2)) - if (((nvcell+1) < numberofcells) && - (NextVirtualCell(nvcell+1) < numberofcells) && - (column_of_cell(NextVirtualCell(nvcell+1))!=0) && - LeftLine(NextVirtualCell(nvcell+1))) - file += '|'; - file += "}{"; - } - } - if (nvcell < numberofcells && Linebreaks(nvcell)) { -// !column_info[column_of_cell(nvcell)].p_width.empty()) { - file += "\\parbox{"; - file += GetPWidth(nvcell); - file += "}{\\smallskip{}"; - } -#endif } return ret; } @@ -1896,12 +1582,12 @@ void LyXTable::SetMultiColumn(int cell, int number) cellinfo_of_cell(fvcell)->top_line = row_info[row_of_cell(fvcell)].top_line; cellinfo_of_cell(fvcell)->bottom_line = row_info[row_of_cell(fvcell)].bottom_line; for (number--;number>0;number--){ - cellinfo_of_cell(fvcell+number)->multicolumn = + cellinfo_of_cell(fvcell+number)->multicolumn = LyXTable::CELL_PART_OF_MULTICOLUMN; new_width += cellinfo_of_cell(fvcell+number)->width_of_cell; } set_row_column_number_info(); - SetWidthOfCell(fvcell,new_width); + SetWidthOfCell(fvcell, new_width); } @@ -1935,7 +1621,7 @@ int LyXTable::UnsetMultiColumn(int cell) while (column < columns && cell_info[row][column].multicolumn == LyXTable::CELL_PART_OF_MULTICOLUMN){ - cell_info[row][column].multicolumn = + cell_info[row][column].multicolumn = LyXTable::CELL_NORMAL; column++; result++; @@ -1948,27 +1634,27 @@ int LyXTable::UnsetMultiColumn(int cell) void LyXTable::delete_column(int column) { - int i,j; + int i, j; columnstruct *column_info2 = new columnstruct[columns-1]; - for (i=0; i=0)) + if (!RowHasContRow(cell) || (CellHasContRow(cell)>= 0)) AppendRow(cell); row_info[row].is_cont_row = true; row_info[row].top_line = false; @@ -2100,7 +1786,7 @@ bool LyXTable::ShouldBeVeryLastCell(int cell) bool LyXTable::ShouldBeVeryLastRow(int cell) { - if (CellHasContRow(cell)>=0) + if (CellHasContRow(cell)>= 0) return false; int row = row_of_cell(cell)+1; int column = column_of_cell(cell);