1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright (C) 1995 Matthias Ettrich
7 * Copyright (C) 1995-1998 The LyX Team.
9 *======================================================
18 #include "support/lstrings.h"
21 #pragma implementation
24 extern void addNewlineAndDepth(string &file, int const depth); // Jug 990923
26 #define WIDTH_OF_LINE 5
29 LyXTable::LyXTable(int rows_arg, int columns_arg)
31 Init(rows_arg, columns_arg);
35 LyXTable::LyXTable(LyXLex &lex)
37 FILE *file = lex.getFile();
42 LyXTable::~LyXTable() {
45 delete[] columnofcell;
48 for (i=0; i<rows; i++) {
49 delete[] cell_info[i]; // verify that this shoudn't be freed with delete
55 LyXTable* LyXTable::Clone()
57 LyXTable *result = new LyXTable(rows, columns);
60 for (row=0; row<rows; row++){
61 for (column=0; column<columns;column++){
62 result->cell_info[row][column] = cell_info[row][column];
66 for (row=0; row<rows; row++){
67 result->row_info[row] = row_info[row];
70 for (column=0; column<columns; column++){
71 result->column_info[column].left_line = column_info[column].left_line;
72 result->column_info[column].right_line = column_info[column].right_line;
73 result->column_info[column].alignment = column_info[column].alignment;
74 result->column_info[column].p_width = column_info[column].p_width;
75 result->column_info[column].align_special = column_info[column].align_special;
78 result->SetLongTable(is_long_table);
79 result->rotate=rotate;
85 /* activates all lines and sets all widths to 0 */
86 void LyXTable::Init(int rows_arg, int columns_arg)
90 columns = columns_arg;
91 column_info = new columnstruct[columns];
92 row_info = new rowstruct[rows];
93 cell_info = new cellstruct*[rows];
96 for (i=0; i<rows;i++) {
97 cell_info[i] = new cellstruct[columns];
98 row_info[i].top_line = true;
99 row_info[i].bottom_line = false;
100 row_info[i].is_cont_row = false;
101 row_info[i].newpage = false;
102 for (j=0; j<columns; j++) {
103 cell_info[i][j].cellno = cellno++;
104 cell_info[i][j].width_of_cell = 0;
105 cell_info[i][j].multicolumn = LyXTable::CELL_NORMAL;
106 cell_info[i][j].alignment = LYX_ALIGN_CENTER;
107 cell_info[i][j].top_line = row_info[i].top_line;
108 cell_info[i][j].bottom_line = row_info[i].bottom_line;
109 cell_info[i][j].has_cont_row = false;
110 cell_info[i][j].rotate = false;
111 cell_info[i][j].linebreaks = false;
114 row_info[i-1].bottom_line = true;
115 row_info[0].bottom_line = true;
117 for (i=0; i<columns;i++) {
118 column_info[i].left_line = true;
119 column_info[i].right_line = false;
120 column_info[i].alignment = LYX_ALIGN_CENTER;
121 // set width_of_column to zero before it is used in
122 // calculate_width_of_column() (thornley)
123 column_info[i].width_of_column = 0;
124 calculate_width_of_column(i);
126 column_info[i-1].right_line = true;
128 calculate_width_of_table();
132 set_row_column_number_info();
133 is_long_table = false;
142 void LyXTable::AppendRow(int cell)
144 int row = row_of_cell(cell);
145 rowstruct *row_info2 = new rowstruct[rows+1];
146 cellstruct** cell_info2 = new cellstruct*[rows+1];
149 for (i=0; i <= row; i++) {
150 cell_info2[i] = cell_info[i];
151 row_info2[i] = row_info[i];
153 for (i=rows-1; i >= row; i--) {
154 cell_info2[i+1] = cell_info[i];
155 row_info2[i+1] = row_info[i];
157 for (i=row;row_info[i].is_cont_row;i--);
158 if (((row+1)>=rows) || !row_info[row+1].is_cont_row)
159 row_info2[row+1].is_cont_row = false;
160 row_info2[row+1].top_line = row_info[i].top_line;
161 cell_info2[row+1] = new cellstruct[columns];
162 for (i=0; i<columns; i++) {
163 cell_info2[row+1][i].width_of_cell = 0;
164 cell_info2[row+1][i] = cell_info2[row][i];
168 cell_info = cell_info2;
170 row_info = row_info2;
178 void LyXTable::DeleteRow(int cell)
180 int row = row_of_cell(cell);
181 while(!row_info[row].is_cont_row && RowHasContRow(cell))
182 DeleteRow(cell_info[row+1][0].cellno);
183 rowstruct *row_info2 = new rowstruct[rows-1];
184 cellstruct** cell_info2 = new cellstruct*[rows-1];
187 delete[] cell_info[row];
188 for (i=0; i < row; i++) {
189 cell_info2[i] = cell_info[i];
190 row_info2[i] = row_info[i];
192 if (row_info[i].is_cont_row)
193 row_info2[i-1].bottom_line = row_info[i].bottom_line;
194 for (i=row; i < rows - 1; i++) {
195 cell_info2[i] = cell_info[i+1];
196 row_info2[i] = row_info[i+1];
201 cell_info = cell_info2;
203 row_info = row_info2;
211 void LyXTable::AppendColumn(int cell)
214 columnstruct *column_info2 = new columnstruct[columns+1];
215 int column = right_column_of_cell(cell);
217 for (i=0; i<=column; i++){
218 column_info2[i] = column_info[i];
220 for (i=columns-1; i>=column; i--){
221 column_info2[i+1] = column_info[i];
224 delete[] column_info;
225 column_info = column_info2;
227 for (i=0; i<rows;i++){
228 cellstruct* tmp = cell_info[i];
229 cell_info[i] = new cellstruct[columns+1];
230 for (j=0; j<=column; j++){
231 cell_info[i][j]=tmp[j];
233 for (j=column; j<columns; j++){
234 cell_info[i][j+1]=tmp[j];
236 // care about multicolumns
237 if (cell_info[i][column+1].multicolumn
238 ==LyXTable::CELL_BEGIN_OF_MULTICOLUMN){
239 cell_info[i][column+1].multicolumn =
240 LyXTable::CELL_PART_OF_MULTICOLUMN;
242 if (column + 1 == columns
243 || cell_info[i][column+2].multicolumn
244 !=LyXTable::CELL_PART_OF_MULTICOLUMN){
245 cell_info[i][column+1].multicolumn =
246 LyXTable::CELL_NORMAL;
257 void LyXTable::Reinit()
261 for (i=0; i<rows;i++) {
262 for (j=0; j<columns; j++) {
263 cell_info[i][j].width_of_cell = 0;
264 if ((i+1 < rows) && !row_info[i+1].is_cont_row)
265 cell_info[i][j].has_cont_row = false;
269 for (i=0; i<columns;i++) {
270 calculate_width_of_column(i);
272 calculate_width_of_table();
274 set_row_column_number_info();
278 void LyXTable::set_row_column_number_info()
284 for (row=0; row<rows; ++row) {
285 for (column=0; column<columns; ++column) {
286 if (cell_info[row][column].multicolumn
287 != LyXTable::CELL_PART_OF_MULTICOLUMN)
289 cell_info[row][column].cellno = numberofcells;
292 ++numberofcells; // because this is one more than as we start from 0
298 rowofcell = new int[numberofcells];
300 delete [] columnofcell;
301 columnofcell = new int[numberofcells];
303 while (c < numberofcells && row < rows && column < columns) {
305 columnofcell[c]=column;
309 } while (column < columns &&
310 cell_info[row][column].multicolumn
311 == LyXTable::CELL_PART_OF_MULTICOLUMN);
312 if (column == columns){
320 void LyXTable::DeleteColumn(int cell)
322 int column1 = column_of_cell(cell);
323 int column2 = right_column_of_cell(cell);
326 if (column1 == 0 && column2 == columns - 1)
329 for (column = column1; column <= column2;column++){
330 delete_column(column1);
336 int LyXTable::GetNumberOfCells()
338 return numberofcells;
342 int LyXTable::NumberOfCellsInRow(int cell)
344 int row = row_of_cell(cell);
347 for (i=0; i<columns; i++){
348 if (cell_info[row][i].multicolumn != LyXTable::CELL_PART_OF_MULTICOLUMN)
355 int LyXTable::AppendCellAfterCell(int append_cell, int question_cell)
357 return (right_column_of_cell(append_cell) ==
358 right_column_of_cell(question_cell));
362 int LyXTable::DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell)
364 if (column_of_cell(delete_column_cell) == 0 &&
365 right_column_of_cell(delete_column_cell) == columns - 1)
369 (column_of_cell(cell) >= column_of_cell(delete_column_cell) &&
370 column_of_cell(cell) <= right_column_of_cell(delete_column_cell));
374 /* returns 1 if there is a topline, returns 0 if not */
375 bool LyXTable::TopLine(int cell)
377 int row=row_of_cell(cell);
380 return TopLine(cell_info[row-1][column_of_cell(cell)].cellno);
381 if (IsMultiColumn(cell))
382 return cellinfo_of_cell(cell)->top_line;
383 return row_info[row].top_line;
387 bool LyXTable::BottomLine(int cell)
389 //no bottom line underneath non-existent cells if you please
390 if(cell >= numberofcells)
393 int row=row_of_cell(cell);
395 if (RowHasContRow(cell))
396 return BottomLine(cell_info[row+1][column_of_cell(cell)].cellno);
397 if (IsMultiColumn(cell))
398 return cellinfo_of_cell(cell)->bottom_line;
399 return row_info[row_of_cell(cell)].bottom_line;
403 bool LyXTable::LeftLine(int cell)
405 return column_info[column_of_cell(cell)].left_line;
408 bool LyXTable::RightLine(int cell)
410 return column_info[right_column_of_cell(cell)].right_line;
414 bool LyXTable::TopAlreadyDrawed(int cell)
416 if (AdditionalHeight(cell))
418 int row = row_of_cell(cell);
420 int column = column_of_cell(cell);
422 && cell_info[row-1][column].multicolumn
423 == LyXTable::CELL_PART_OF_MULTICOLUMN)
425 if (cell_info[row-1][column].multicolumn
426 == LyXTable::CELL_NORMAL)
427 return row_info[row-1].bottom_line;
429 return cell_info[row-1][column].bottom_line;
435 bool LyXTable::VeryLastRow(int cell)
437 return (row_of_cell(cell) == rows-1);
441 int LyXTable::AdditionalHeight(int cell)
443 int row = row_of_cell(cell);
448 for (column=0;column < columns-1 && bottom;column++){
449 switch (cell_info[row-1][column].multicolumn){
450 case LyXTable::CELL_BEGIN_OF_MULTICOLUMN:
451 bottom = cell_info[row-1][column].bottom_line;
453 case LyXTable::CELL_NORMAL:
454 bottom = row_info[row-1].bottom_line;
457 for (column=0;column < columns-1 && top;column++){
458 switch (cell_info[row][column].multicolumn){
459 case LyXTable::CELL_BEGIN_OF_MULTICOLUMN:
460 top = cell_info[row][column].top_line;
462 case LyXTable::CELL_NORMAL:
463 top = row_info[row].top_line;
467 return WIDTH_OF_LINE;
473 int LyXTable::AdditionalWidth(int cell)
475 // internally already set in SetWidthOfCell
476 // used to get it back in text.C
477 int col = right_column_of_cell(cell);
478 if (col < columns - 1 && column_info[col].right_line &&
479 column_info[col+1].left_line)
480 return WIDTH_OF_LINE;
486 // returns the maximum over all rows
487 int LyXTable::WidthOfColumn(int cell)
489 int column1 = column_of_cell(cell);
490 int column2 = right_column_of_cell(cell);
493 for (i=column1; i<=column2;i++){
494 result += column_info[i].width_of_column;
500 int LyXTable::WidthOfTable()
502 return width_of_table;
505 /* returns 1 if a complete update is necessary, otherwise 0 */
506 bool LyXTable::SetWidthOfMulticolCell(int cell, int new_width)
508 if (!IsMultiColumn(cell))
511 int row = row_of_cell(cell);
512 int column1 = column_of_cell(cell);
513 int column2 = right_column_of_cell(cell);
517 // first set columns to 0 so we can calculate the right width
518 for (i=column1; i<=column2;i++) {
519 cell_info[row][i].width_of_cell = 0;
521 // set the width to MAX_WIDTH until width > 0
522 width = (new_width + 2*WIDTH_OF_LINE);
523 for (i=column1; (i<column2) && (width > 0);i++){
524 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
525 width -= column_info[i].width_of_column;
528 cell_info[row][i].width_of_cell = width;
533 void LyXTable::recalculateMulticolCells(int cell, int new_width)
536 row = row_of_cell(cell),
537 column1 = column_of_cell(cell),
538 column2 = right_column_of_cell(cell),
541 // first set columns to 0 so we can calculate the right width
542 for (i=column1; i<=column2;++i)
543 cell_info[row][i].width_of_cell = 0;
544 for(i=cell+1;(i<numberofcells) && (!IsMultiColumn(i));++i)
546 if (i < numberofcells)
547 recalculateMulticolCells(i,GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
548 SetWidthOfMulticolCell(cell,new_width);
551 /* returns 1 if a complete update is necessary, otherwise 0 */
552 bool LyXTable::SetWidthOfCell(int cell, int new_width)
554 int row = row_of_cell(cell);
555 int column1 = column_of_cell(cell);
559 if (IsMultiColumn(cell)) {
560 tmp = SetWidthOfMulticolCell(cell, new_width);
562 width = (new_width + 2*WIDTH_OF_LINE);
563 cell_info[row][column1].width_of_cell = width;
564 if (column_info[column1].right_line && (column1 < columns-1) &&
565 column_info[column1+1].left_line) // additional width
566 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
567 tmp = calculate_width_of_column_NMC(column1);
571 for(i=0; i<columns;++i)
572 calculate_width_of_column_NMC(i);
573 for(i=0; (i<numberofcells) && !IsMultiColumn(i); ++i)
576 recalculateMulticolCells(i,GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
577 for(i=0; i<columns;++i)
578 calculate_width_of_column(i);
579 calculate_width_of_table();
586 bool LyXTable::SetAlignment(int cell, char align)
588 if (!IsMultiColumn(cell))
589 column_info[column_of_cell(cell)].alignment = align;
590 cellinfo_of_cell(cell)->alignment = align;
594 bool LyXTable::SetPWidth(int cell, string width)
596 int fvcell = FirstVirtualCell(cell);
598 if (IsMultiColumn(fvcell)) {
599 // if (column_info[column_of_cell(cell)].p_width.empty())
600 // column_info[column_of_cell(cell)].p_width = width;
601 cellinfo_of_cell(fvcell)->p_width = width;
603 column_info[column_of_cell(fvcell)].p_width = width;
604 if (!width.empty()) // do this only if there is a width
605 SetAlignment(cell,LYX_ALIGN_LEFT);
610 bool LyXTable::SetAlignSpecial(int cell, string special, int what)
612 if (what == SET_SPECIAL_MULTI)
613 cellinfo_of_cell(cell)->align_special = special;
615 column_info[column_of_cell(cell)].align_special = special;
619 bool LyXTable::SetAllLines(int cell, bool line)
621 SetTopLine(cell,line);
622 SetBottomLine(cell,line);
623 SetRightLine(cell,line);
624 SetLeftLine(cell,line);
628 bool LyXTable::SetTopLine(int cell, bool line)
630 int row = row_of_cell(cell);
633 SetTopLine(cell_info[row-1][column_of_cell(cell)].cellno,line);
634 else if (!IsMultiColumn(cell))
635 row_info[row].top_line = line;
637 cellinfo_of_cell(cell)->top_line = line;
642 bool LyXTable::SetBottomLine(int cell, bool line)
644 int row = row_of_cell(cell);
646 if (RowHasContRow(cell))
647 SetBottomLine(cell_info[row+1][column_of_cell(cell)].cellno,line);
648 else if (!IsMultiColumn(cell))
649 row_info[row_of_cell(cell)].bottom_line = line;
651 cellinfo_of_cell(cell)->bottom_line = line;
656 bool LyXTable::SetLeftLine(int cell, bool line)
658 column_info[column_of_cell(cell)].left_line = line;
663 bool LyXTable::SetRightLine(int cell, bool line)
665 column_info[right_column_of_cell(cell)].right_line = line;
670 char LyXTable::GetAlignment(int cell)
672 if (IsMultiColumn(cell))
673 return cellinfo_of_cell(cell)->alignment;
675 return column_info[column_of_cell(cell)].alignment;
678 string LyXTable::GetPWidth(int cell)
680 int fvcell = FirstVirtualCell(cell);
682 if (IsMultiColumn(fvcell)) // && !cellinfo_of_cell(cell)->p_width.empty())
683 return cellinfo_of_cell(fvcell)->p_width;
684 return column_info[column_of_cell(fvcell)].p_width;
687 string LyXTable::GetAlignSpecial(int cell, int what)
689 if (what == SET_SPECIAL_MULTI)
690 return cellinfo_of_cell(cell)->align_special;
691 return column_info[column_of_cell(cell)].align_special;
694 int LyXTable::GetWidthOfCell(int cell)
696 int row = row_of_cell(cell);
697 int column1 = column_of_cell(cell);
698 int column2 = right_column_of_cell(cell);
701 for (i=column1; i<=column2;i++){
702 result += cell_info[row][i].width_of_cell;
705 result += AdditionalWidth(cell);
711 int LyXTable::GetBeginningOfTextInCell(int cell)
715 switch (GetAlignment(cell)){
716 case LYX_ALIGN_CENTER:
717 x += (WidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
719 case LYX_ALIGN_RIGHT:
720 x += WidthOfColumn(cell) - GetWidthOfCell(cell) + AdditionalWidth(cell);
722 default: /* LYX_ALIGN_LEFT: nothing :-) */
732 bool LyXTable::IsFirstCell(int cell)
734 return (column_of_cell(cell) == 0);
737 bool LyXTable::IsLastCell(int cell)
739 return (right_column_of_cell(cell) == (columns-1));
743 bool LyXTable::calculate_width_of_column(int column)
746 int old_column_width = column_info[column].width_of_column;
748 for (i=0; i<rows; i++) {
749 if (cell_info[i][column].width_of_cell > max) {
750 max = cell_info[i][column].width_of_cell;
753 column_info[column].width_of_column = max;
754 return (column_info[column].width_of_column != old_column_width);
757 bool LyXTable::calculate_width_of_column_NMC(int column)
760 int old_column_width = column_info[column].width_of_column;
762 for (i=0; i<rows; ++i) {
763 if (!IsMultiColumn(GetCellNumber(column,i)) &&
764 (cell_info[i][column].width_of_cell > max)) {
765 max = cell_info[i][column].width_of_cell;
768 column_info[column].width_of_column = max;
769 return (column_info[column].width_of_column != old_column_width);
772 void LyXTable::calculate_width_of_table()
776 for (i=0; i<columns;i++) {
777 width_of_table += column_info[i].width_of_column;
782 int LyXTable::row_of_cell(int cell)
784 if (cell >= numberofcells)
788 return rowofcell[cell];
792 int LyXTable::column_of_cell(int cell)
794 if (cell >= numberofcells)
798 return columnofcell[cell];
802 int LyXTable::right_column_of_cell(int cell)
804 int row = row_of_cell(cell);
805 int column = column_of_cell(cell);
806 while (column < columns - 1 &&
807 cell_info[row][column+1].multicolumn == LyXTable::CELL_PART_OF_MULTICOLUMN)
813 void LyXTable::Write(FILE* file)
816 fprintf(file, "multicol5\n");
817 fprintf(file, "%d %d %d %d %d %d %d %d\n", rows, columns, is_long_table,
818 rotate, endhead, endfirsthead, endfoot, endlastfoot);
819 for (i=0; i<rows; i++){
820 fprintf(file, "%d %d %d %d\n", row_info[i].top_line,
821 row_info[i].bottom_line, row_info[i].is_cont_row,
822 row_info[i].newpage);
824 for (i=0; i<columns; i++){
825 fprintf(file, "%d %d %d \"%s\" \"%s\"\n",
826 column_info[i].alignment, column_info[i].left_line,
827 column_info[i].right_line,
828 VSpace(column_info[i].p_width).asLyXCommand().c_str(),
829 column_info[i].align_special.c_str());
832 for (i=0; i<rows;i++){
833 for (j=0;j<columns;j++){
834 fprintf(file, "%d %d %d %d %d %d %d \"%s\" \"%s\"\n",
835 cell_info[i][j].multicolumn,
836 cell_info[i][j].alignment,
837 cell_info[i][j].top_line,
838 cell_info[i][j].bottom_line,
839 cell_info[i][j].has_cont_row,
840 cell_info[i][j].rotate,
841 cell_info[i][j].linebreaks,
842 cell_info[i][j].align_special.c_str(),
843 cell_info[i][j].p_width.c_str());
849 #warning Clean up this code in 0.13 (Jug)
851 void LyXTable::Read(FILE* file)
857 int is_long_table_arg = false;
858 int rotate_arg = false;
868 char vtmp[100], stmp[100], atmp[100];
870 fscanf(file, "%s\n", vtmp);
873 version = atoi(s.c_str()+8);
878 fgets(vtmp,sizeof(vtmp),file);
879 sscanf(vtmp, "%d %d %d %d %d %d %d %d\n", &rows_arg, &columns_arg,
880 &is_long_table_arg, &rotate_arg, &a, &b, &c, &d);
882 fscanf(file, "%d %d\n",
883 &rows_arg, &columns_arg);
884 Init(rows_arg, columns_arg);
885 SetLongTable(is_long_table_arg);
886 SetRotateTable(rotate_arg);
891 for (i=0; i<rows; i++){
893 fgets(vtmp,sizeof(vtmp),file);
894 sscanf(vtmp, "%d %d %d %d\n",
896 row_info[i].top_line = a;
897 row_info[i].bottom_line = b;
898 row_info[i].is_cont_row = c;
899 row_info[i].newpage = d;
901 for (i=0; i<columns; i++){
904 fgets(vtmp,sizeof(vtmp),file);
905 sscanf(vtmp, "%d %d %d %s %s", &a, &b, &c, stmp, atmp);
906 column_info[i].alignment = (char) a;
907 column_info[i].left_line = b;
908 column_info[i].right_line = c;
909 if (*stmp == '"') { /* strip quotes if they exists */
912 // there are quotes so I have to reread the string correctly
913 // this is only because the old format did not have "
914 // this means also that atmp is ONLY set here!!!
916 sscanf(vtmp, "%*d %*d %*d %*s \"%[^\"]\"", atmp);
917 else // otherwise after the first empty "" read is aborded
918 sscanf(vtmp, "%*d %*d %*d \"%[^\"]\" \"%[^\"]\"", stmp, atmp);
919 column_info[i].p_width = stmp;
920 column_info[i].align_special = atmp;
922 column_info[i].p_width = stmp;
925 for (i=0; i<rows;i++){
926 for (j=0;j<columns;j++){
927 fscanf(file, "%d %d\n", &a, &b);
928 cell_info[i][j].multicolumn = (char) a;
929 cell_info[i][j].alignment = (char) b;
932 } else if (version < 4) {
933 for (i=0; i<rows;i++){
934 for (j=0;j<columns;j++){
935 fscanf(file, "%d %d %d %d\n", &a, &b, &c, &d);
936 cell_info[i][j].multicolumn = (char) a;
937 cell_info[i][j].alignment = (char) b;
938 cell_info[i][j].top_line = (char) c;
939 cell_info[i][j].bottom_line = (char) d;
943 for (i=0; i<rows;i++){
944 for (j=0;j<columns;j++){
948 fgets(vtmp,sizeof(vtmp),file);
949 sscanf(vtmp, "%d %d %d %d %d %d %d %s %s\n",
950 &a, &b, &c, &d, &e, &f, &g, stmp, atmp);
951 cell_info[i][j].multicolumn = (char) a;
952 cell_info[i][j].alignment = (char) b;
953 cell_info[i][j].top_line = (char) c;
954 cell_info[i][j].bottom_line = (char) d;
955 cell_info[i][j].has_cont_row = (bool) e;
956 cell_info[i][j].rotate = (bool) f;
957 cell_info[i][j].linebreaks = (bool) g;
958 // this is only to see if I have an empty string first
959 // this clause should be always TRUE!!!
964 sscanf(vtmp,"%*d %*d %*d %*d %*d %*d %*d %*s \"%[^\"]\"",
966 else // otherwise after the first empty "" read is aborded
967 sscanf(vtmp,"%*d %*d %*d %*d %*d %*d %*d \"%[^\"]\" \"%[^\"]\"",
969 cell_info[i][j].align_special = stmp;
970 cell_info[i][j].p_width = atmp;
972 cell_info[i][j].align_special = stmp;
976 set_row_column_number_info();
980 // cell <0 will tex the preamble
981 // returns the number of printed newlines
982 int LyXTable::TexEndOfCell(string& file, int cell)
988 if (ShouldBeVeryLastCell(cell)) {
989 // the very end at the very beginning
990 if (Linebreaks(cell))
991 file += "\\smallskip{}}";
992 if (IsMultiColumn(cell))
994 if (RotateCell(cell)) {
995 file += "\n\\end{sideways}";
1003 while (!IsFirstCell(fcell))fcell--;
1004 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1005 if (BottomLine(fcell+i))
1008 if (tmp == NumberOfCellsInRow(fcell)){
1012 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1013 if (BottomLine(fcell+i)){
1015 file += tostr(column_of_cell(fcell+i)+1);
1017 file += tostr(right_column_of_cell(fcell+i)+1);
1028 file += "\\end{longtable}";
1030 file += "\\end{tabular}";
1032 file += "\n\\end{sideways}";
1036 nvcell = NextVirtualCell(cell+1);
1040 file += "\\begin{sideways}\n";
1044 file += "\\begin{longtable}{";
1046 file += "\\begin{tabular}{";
1047 for (i=0; i<columns;i++){
1048 if (column_info[i].left_line)
1050 if (!column_info[i].align_special.empty()) {
1051 file += column_info[i].align_special.c_str();
1052 } else if (!column_info[i].p_width.empty()) {
1054 file += column_info[i].p_width;
1057 switch (column_info[i].alignment) {
1058 case LYX_ALIGN_LEFT:
1061 case LYX_ALIGN_RIGHT:
1069 if (column_info[i].right_line)
1075 if (GetNumberOfCells()){
1077 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1078 if (TopLine(fcell+i))
1081 if (tmp == NumberOfCellsInRow(fcell)){
1085 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1086 if (TopLine(fcell+i)){
1088 file += tostr(column_of_cell(fcell+i)+1);
1090 file += tostr(right_column_of_cell(fcell+i)+1);
1101 if (RotateCell(0)) {
1102 file += "\\begin{sideways}\n";
1107 if (Linebreaks(cell))
1108 file += "\\smallskip{}}";
1109 if (IsMultiColumn(cell)){
1112 if (RotateCell(cell)) {
1113 file += "\n\\end{sideways}";
1116 if (IsLastCell(cell)) {
1117 int row = row_of_cell(cell);
1118 string hline1,hline2;
1119 bool print_hline = true;
1120 bool pr_top_hline,flag1,flag2;
1121 flag1 = IsLongTable() &&
1122 ((row == endhead) || (row == endfirsthead) ||
1123 (row == endfoot) || (row == endlastfoot));
1125 flag2 = IsLongTable() &&
1126 ((row <= endhead) || (row <= endfirsthead) ||
1127 (row <= endfoot) || (row <= endlastfoot));
1129 // print the bottom hline only if (otherwise it is doubled):
1130 // - is no LongTable
1131 // - there IS a first-header
1132 // - the next row is no special header/footer
1133 // & this row is no special header/footer
1134 // - the next row is a special header/footer
1135 // & this row is a special header/footer
1136 pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1137 (endfirsthead == endhead);
1142 while (!IsFirstCell(fcell))
1144 for (i=0; i < NumberOfCellsInRow(cell); i++){
1145 if (BottomLine(fcell+i))
1148 if (tmp == NumberOfCellsInRow(cell)){
1150 hline1 = "\\hline ";
1153 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1154 if (BottomLine(fcell+i)){
1156 file += tostr(column_of_cell(fcell+i)+1);
1158 file += tostr(right_column_of_cell(fcell+i)+1);
1160 hline1 += "\\cline{";
1161 hline1 += tostr(column_of_cell(fcell+i)+1);
1163 hline1 += tostr(right_column_of_cell(fcell+i)+1);
1173 if (IsLongTable() && (row == endfoot)) {
1174 file += "\\endfoot\n";
1176 print_hline = false; // no double line below footer
1178 if (IsLongTable() && (row == endlastfoot)) {
1179 file += "\\endlastfoot\n";
1181 print_hline = false; // no double line below footer
1183 if (IsLongTable() && row_info[row].newpage) {
1184 file += "\\newpage\n";
1186 print_hline = false; // no line below a \\newpage-command
1189 if (nvcell < numberofcells && (cell < GetNumberOfCells()-1) &&
1190 !ShouldBeVeryLastCell(cell)) {
1193 // Now jump all ContRows
1194 while (IsContRow(fcell))
1196 while (!IsFirstCell(fcell))
1199 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1200 if (TopLine(fcell+i))
1203 if (tmp == NumberOfCellsInRow(fcell)){
1206 hline2 = "\\hline ";
1210 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1211 if (TopLine(fcell+i)){
1214 file += tostr(column_of_cell(fcell+i)+1);
1216 file += tostr(right_column_of_cell(fcell+i)+1);
1219 hline2 += "\\cline{";
1220 hline2 += tostr(column_of_cell(fcell+i)+1);
1222 hline2 += tostr(right_column_of_cell(fcell+i)+1);
1228 if (tmp && print_hline){
1233 // the order here is important as if one defines two
1234 // or more things in one line only the first entry is
1235 // displayed the other are set to an empty-row. This
1236 // is important if I have a footer and want that the
1237 // lastfooter is NOT displayed!!!
1238 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1239 (row == endfoot) || (row == endlastfoot);
1241 // sflag2 = IsLongTable() && (row >= 0) &&
1242 // (sflag2 || (row == endhead) || (row == endfirsthead));
1244 bool sflag1 = IsLongTable() && (row != endhead) &&
1245 (row != endfirsthead) &&
1246 ((row == endfoot) || (row == endlastfoot));
1248 if (IsLongTable() && (row == endhead)) {
1249 file += "\\endhead\n";
1252 if (IsLongTable() && (row == endfirsthead)) {
1253 file += "\\endfirsthead\n";
1256 if (sflag1) { // add the \hline for next foot row
1257 if (!hline1.empty()) {
1258 file += hline1 + '\n';
1262 // add the \hline for the first row
1263 if (pr_top_hline && sflag2) {
1264 if (!hline2.empty()) {
1265 file += hline2 + '\n';
1269 if (nvcell < numberofcells && RotateCell(nvcell)) {
1270 file += "\\begin{sideways}\n";
1276 if (nvcell < numberofcells && RotateCell(nvcell)) {
1277 file += "\\begin{sideways}\n";
1282 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1283 file += "\\multicolumn{";
1284 file += tostr(cells_in_multicolumn(nvcell));
1286 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1287 file += cellinfo_of_cell(cell+1)->align_special;
1290 if (LeftLine(nvcell))
1292 if (!GetPWidth(nvcell).empty()) {
1294 file += GetPWidth(nvcell);
1297 switch (GetAlignment(nvcell)) {
1298 case LYX_ALIGN_LEFT: file += 'l'; break;
1299 case LYX_ALIGN_RIGHT: file += 'r'; break;
1300 default: file += 'c'; break;
1303 if (RightLine(nvcell))
1305 //if (column_of_cell(cell+2)!=0 && LeftLine(cell+2))
1306 if (((nvcell+1) < numberofcells) &&
1307 (NextVirtualCell(nvcell+1) < numberofcells) &&
1308 (column_of_cell(NextVirtualCell(nvcell+1))!=0) &&
1309 LeftLine(NextVirtualCell(nvcell+1)))
1314 if (nvcell < numberofcells && Linebreaks(nvcell)) {
1315 // !column_info[column_of_cell(nvcell)].p_width.empty()) {
1316 file += "\\parbox{";
1317 file += GetPWidth(nvcell);
1318 file += "}{\\smallskip{}";
1325 // cell <0 will tex the preamble
1326 // returns the number of printed newlines
1327 int LyXTable::RoffEndOfCell(FILE* file, int cell)
1332 if (cell == GetNumberOfCells() - 1){
1333 // the very end at the very beginning
1334 if (CellHasContRow(cell) >= 0) {
1335 fprintf(file,"\nT}");
1338 fprintf(file, "\n");
1340 if (row_info[row_of_cell(cell)].bottom_line) {
1341 fprintf(file, "_\n");
1344 fprintf(file, ".TE\n.pl 1c");
1349 fprintf(file, "\n.pl 500c\n.TS\n");
1350 for (j=0; j<rows; j++) {
1351 for (i=0; i<columns;i++,fcell++) {
1352 if (column_info[i].left_line)
1353 fprintf(file, " | ");
1354 if (cell_info[j][i].multicolumn==CELL_PART_OF_MULTICOLUMN)
1357 switch (column_info[i].alignment) {
1358 case LYX_ALIGN_LEFT:
1361 case LYX_ALIGN_RIGHT:
1369 if (!column_info[i].p_width.empty())
1370 fprintf(file, "w(%s)", column_info[i].p_width.c_str());
1371 if (column_info[i].right_line)
1372 fprintf(file, " | ");
1375 fprintf(file, "\n");
1379 fprintf(file, ".\n");
1381 if (row_info[0].top_line) {
1382 fprintf(file,"_\n");
1385 if (CellHasContRow(0) >= 0) {
1386 fprintf(file,"T{\n");
1391 if (CellHasContRow(cell) >= 0) {
1392 fprintf(file,"\nT}");
1395 if (right_column_of_cell(cell) == columns -1){
1396 fprintf(file, "\n");
1398 int row = row_of_cell(cell);
1399 if (row_info[row++].bottom_line) {
1400 fprintf(file, "_\n");
1403 if ((row < rows) && row_info[row].top_line) {
1404 fprintf(file, "_\n");
1408 fprintf(file, "\t");
1409 if ((cell < GetNumberOfCells() - 1) &&
1410 (CellHasContRow(cell+1) >= 0)) {
1411 fprintf(file,"T{\n");
1419 const char *LyXTable::getDocBookAlign(int cell, bool isColumn)
1425 i = column_of_cell(cell);
1426 if (!isColumn && IsMultiColumn(cell)) {
1427 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1428 return cellinfo_of_cell(cell)->align_special.c_str();
1430 switch (GetAlignment(cell)) {
1431 case LYX_ALIGN_LEFT:
1433 case LYX_ALIGN_RIGHT:
1440 if (!column_info[i].align_special.empty()) {
1441 return column_info[i].align_special.c_str();
1443 #ifdef IGNORE_THIS_FOR_NOW
1444 else if (!column_info[i].p_width.empty()) {
1446 file += column_info[i].p_width;
1451 switch (column_info[i].alignment) {
1452 case LYX_ALIGN_LEFT:
1454 case LYX_ALIGN_RIGHT:
1463 // cell <0 will tex the preamble
1464 // returns the number of printed newlines
1465 int LyXTable::DocBookEndOfCell(string& file, int cell, int &depth)
1469 //int tmp; // tmp2; //Â unused
1470 int nvcell; // fcell; //Â unused
1471 if (ShouldBeVeryLastCell(cell)) {
1473 // the very end at the very beginning
1474 if (Linebreaks(cell))
1475 file += "\\smallskip{}}";
1476 if (IsMultiColumn(cell))
1478 if (RotateCell(cell)) {
1479 file += "\n\\end{sideways}";
1487 while (!IsFirstCell(fcell))fcell--;
1488 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1489 if (BottomLine(fcell+i))
1492 if (tmp == NumberOfCellsInRow(fcell)){
1496 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1497 if (BottomLine(fcell+i)){
1499 file += column_of_cell(fcell+i)+1;
1501 file += right_column_of_cell(fcell+i)+1;
1512 addNewlineAndDepth(file,--depth);
1514 addNewlineAndDepth(file,--depth);
1516 addNewlineAndDepth(file,--depth);
1518 addNewlineAndDepth(file,--depth);
1520 file += "</TGROUP>";
1522 file += "</TGROUP>";
1523 addNewlineAndDepth(file,--depth);
1526 file += "\n\\end{sideways}";
1532 nvcell = NextVirtualCell(cell+1);
1540 file += tostr(columns);
1541 file += "' COLSEP='1' ROWSEP='1'>";
1542 addNewlineAndDepth(file,++depth);
1544 for (i=0; i<columns;i++) {
1545 file += "<COLSPEC ALIGN='";
1546 file += getDocBookAlign(i, true);
1547 file += "' COLNAME='col";
1549 file += "' COLNUM='";
1551 file += "' COLSEP='";
1552 if (i == (columns-1)) {
1555 if (column_info[i].right_line ||
1556 column_info[i+1].left_line)
1562 addNewlineAndDepth(file,depth);
1564 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1565 if (column_info[i].left_line)
1571 if (GetNumberOfCells()) {
1573 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1574 if (TopLine(fcell+i))
1577 if (tmp == NumberOfCellsInRow(fcell)){
1581 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1582 if (TopLine(fcell+i)){
1584 file += column_of_cell(fcell+i)+1;
1586 file += right_column_of_cell(fcell+i)+1;
1597 if (RotateCell(0)) {
1598 file += "\\begin{sideways}\n";
1603 addNewlineAndDepth(file,++depth);
1605 addNewlineAndDepth(file,++depth);
1606 file += "<ENTRY ALIGN='";
1607 file += getDocBookAlign(0);
1609 if (IsMultiColumn(0)) {
1610 file += " NAMEST='col1' NAMEEND='col";
1611 file += tostr(cells_in_multicolumn(0));
1615 addNewlineAndDepth(file,++depth);
1620 if (Linebreaks(cell))
1621 file += "\\smallskip{}}";
1622 if (IsMultiColumn(cell)){
1625 if (RotateCell(cell)) {
1626 file += "\n\\end{sideways}";
1630 if (IsLastCell(cell)) {
1631 addNewlineAndDepth(file,--depth);
1633 addNewlineAndDepth(file,--depth);
1635 addNewlineAndDepth(file,depth);
1637 addNewlineAndDepth(file,++depth);
1638 file += "<ENTRY ALIGN='";
1639 file += getDocBookAlign(cell+1);
1640 file += "' VALIGN='middle'";
1641 if (IsMultiColumn(cell+1)) {
1642 file += " NAMEST='col";
1643 file += tostr(column_of_cell(cell+1) + 1);
1644 file += "' NAMEEND='col";
1645 file += tostr(column_of_cell(cell+1) +
1646 cells_in_multicolumn(cell+1));
1650 addNewlineAndDepth(file,++depth);
1653 int row = row_of_cell(cell);
1654 string hline1,hline2;
1655 bool print_hline = true;
1656 bool pr_top_hline,flag1,flag2;
1657 flag1 = IsLongTable() &&
1658 ((row == endhead) || (row == endfirsthead) ||
1659 (row == endfoot) || (row == endlastfoot));
1661 flag2 = IsLongTable() &&
1662 ((row <= endhead) || (row <= endfirsthead) ||
1663 (row <= endfoot) || (row <= endlastfoot));
1665 // print the bottom hline only if (otherwise it is doubled):
1666 // - is no LongTable
1667 // - there IS a first-header
1668 // - the next row is no special header/footer
1669 // & this row is no special header/footer
1670 // - the next row is a special header/footer
1671 // & this row is a special header/footer
1672 pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1673 (endfirsthead == endhead);
1678 while (!IsFirstCell(fcell))
1680 for (i=0; i < NumberOfCellsInRow(cell); i++){
1681 if (BottomLine(fcell+i))
1684 if (tmp == NumberOfCellsInRow(cell)){
1686 hline1 = "\\hline ";
1689 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1690 if (BottomLine(fcell+i)){
1692 file += column_of_cell(fcell+i)+1;
1694 file += right_column_of_cell(fcell+i)+1;
1696 hline1 += "\\cline{";
1697 hline1 += column_of_cell(fcell+i)+1;
1699 hline1 += right_column_of_cell(fcell+i)+1;
1709 if (IsLongTable() && (row == endfoot)) {
1710 file += "\\endfoot\n";
1712 print_hline = false; // no double line below footer
1714 if (IsLongTable() && (row == endlastfoot)) {
1715 file += "\\endlastfoot\n";
1717 print_hline = false; // no double line below footer
1719 if (IsLongTable() && row_info[row].newpage) {
1720 file += "\\newpage\n";
1722 print_hline = false; // no line below a \\newpage-command
1725 if (nvcell < numberofcells && (cell < GetNumberOfCells()-1) &&
1726 !ShouldBeVeryLastCell(cell)) {
1728 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1729 if (TopLine(fcell+i))
1732 if (tmp == NumberOfCellsInRow(fcell)){
1735 hline2 = "\\hline ";
1739 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1740 if (TopLine(fcell+i)){
1743 file += column_of_cell(fcell+i)+1;
1745 file += right_column_of_cell(fcell+i)+1;
1748 hline2 += "\\cline{";
1749 hline2 += column_of_cell(fcell+i)+1;
1751 hline2 += right_column_of_cell(fcell+i)+1;
1757 if (tmp && print_hline){
1762 // the order here is important as if one defines two
1763 // or more things in one line only the first entry is
1764 // displayed the other are set to an empty-row. This
1765 // is important if I have a footer and want that the
1766 // lastfooter is NOT displayed!!!
1767 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1768 (row == endfoot) || (row == endlastfoot);
1770 // sflag2 = IsLongTable() && (row >= 0) &&
1771 // (sflag2 || (row == endhead) || (row == endfirsthead));
1773 bool sflag1 = IsLongTable() && (row != endhead) &&
1774 (row != endfirsthead) &&
1775 ((row == endfoot) || (row == endlastfoot));
1777 if (IsLongTable() && (row == endhead)) {
1778 file += "\\endhead\n";
1781 if (IsLongTable() && (row == endfirsthead)) {
1782 file += "\\endfirsthead\n";
1785 if (sflag1) { // add the \hline for next foot row
1786 if (!hline1.empty()) {
1787 file += hline1 + '\n';
1791 // add the \hline for the first row
1792 if (pr_top_hline && sflag2) {
1793 if (!hline2.empty()) {
1794 file += hline2 + '\n';
1798 if (nvcell < numberofcells && RotateCell(nvcell)) {
1799 file += "\\begin{sideways}\n";
1804 addNewlineAndDepth(file,--depth);
1806 addNewlineAndDepth(file,depth);
1807 file += "<ENTRY ALIGN='";
1808 file += getDocBookAlign(cell+1);
1809 file += "' VALIGN='middle'";
1810 if (IsMultiColumn(cell+1)) {
1811 file += " NAMEST='col";
1812 file += tostr(column_of_cell(cell+1) + 1);
1813 file += "' NAMEEND='col";
1814 file += tostr(column_of_cell(cell+1) +
1815 cells_in_multicolumn(cell+1));
1819 addNewlineAndDepth(file,++depth);
1822 if (nvcell < numberofcells && RotateCell(nvcell)) {
1823 file += "\\begin{sideways}\n";
1830 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1831 file += "\\multicolumn{";
1832 file += cells_in_multicolumn(nvcell);
1834 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1835 file += cellinfo_of_cell(cell+1)->align_special;
1838 if (LeftLine(nvcell))
1840 if (!GetPWidth(nvcell).empty()) {
1842 file += GetPWidth(nvcell);
1845 switch (GetAlignment(nvcell)) {
1846 case LYX_ALIGN_LEFT: file += 'l'; break;
1847 case LYX_ALIGN_RIGHT: file += 'r'; break;
1848 default: file += 'c'; break;
1851 if (RightLine(nvcell))
1853 //if (column_of_cell(cell+2)!=0 && LeftLine(cell+2))
1854 if (((nvcell+1) < numberofcells) &&
1855 (NextVirtualCell(nvcell+1) < numberofcells) &&
1856 (column_of_cell(NextVirtualCell(nvcell+1))!=0) &&
1857 LeftLine(NextVirtualCell(nvcell+1)))
1862 if (nvcell < numberofcells && Linebreaks(nvcell)) {
1863 // !column_info[column_of_cell(nvcell)].p_width.empty()) {
1864 file += "\\parbox{";
1865 file += GetPWidth(nvcell);
1866 file += "}{\\smallskip{}";
1874 bool LyXTable::IsMultiColumn(int cell)
1876 int fvcell = FirstVirtualCell(cell);
1878 return (cellinfo_of_cell(fvcell)->multicolumn != LyXTable::CELL_NORMAL);
1882 LyXTable::cellstruct* LyXTable::cellinfo_of_cell(int cell)
1884 int row = row_of_cell(cell);
1885 int column = column_of_cell(cell);
1886 return &cell_info[row][column];
1890 void LyXTable::SetMultiColumn(int cell, int number)
1892 int fvcell = FirstVirtualCell(cell);
1893 int new_width = cellinfo_of_cell(fvcell)->width_of_cell;
1895 cellinfo_of_cell(fvcell)->multicolumn = LyXTable::CELL_BEGIN_OF_MULTICOLUMN;
1896 cellinfo_of_cell(fvcell)->alignment = column_info[column_of_cell(fvcell)].alignment;
1897 cellinfo_of_cell(fvcell)->top_line = row_info[row_of_cell(fvcell)].top_line;
1898 cellinfo_of_cell(fvcell)->bottom_line = row_info[row_of_cell(fvcell)].bottom_line;
1899 for (number--;number>0;number--){
1900 cellinfo_of_cell(fvcell+number)->multicolumn =
1901 LyXTable::CELL_PART_OF_MULTICOLUMN;
1902 new_width += cellinfo_of_cell(fvcell+number)->width_of_cell;
1904 set_row_column_number_info();
1905 SetWidthOfCell(fvcell,new_width);
1909 int LyXTable::cells_in_multicolumn(int cell)
1911 int row = row_of_cell(cell);
1912 int column = column_of_cell(cell);
1915 while (column < columns && cell_info[row][column].multicolumn
1916 == LyXTable::CELL_PART_OF_MULTICOLUMN){
1924 int LyXTable::UnsetMultiColumn(int cell)
1926 int fvcell = FirstVirtualCell(cell);
1927 int row = row_of_cell(fvcell);
1928 int column = column_of_cell(fvcell);
1932 if (cell_info[row][column].multicolumn
1933 == LyXTable::CELL_BEGIN_OF_MULTICOLUMN){
1934 cell_info[row][column].multicolumn = LyXTable::CELL_NORMAL;
1936 while (column < columns &&
1937 cell_info[row][column].multicolumn
1938 == LyXTable::CELL_PART_OF_MULTICOLUMN){
1939 cell_info[row][column].multicolumn =
1940 LyXTable::CELL_NORMAL;
1945 set_row_column_number_info();
1950 void LyXTable::delete_column(int column)
1953 columnstruct *column_info2 = new columnstruct[columns-1];
1955 for (i=0; i<column; i++){
1956 column_info2[i] = column_info[i];
1958 for (i=column; i<columns-1; i++){
1959 column_info2[i] = column_info[i+1];
1962 delete[] column_info;
1963 column_info = column_info2;
1965 for (i=0; i<rows;i++){
1966 cellstruct* tmp = cell_info[i];
1967 cell_info[i] = new cellstruct[columns-1];
1968 for (j=0; j<column; j++){
1969 cell_info[i][j]=tmp[j];
1971 for (j=column; j<columns-1; j++){
1972 cell_info[i][j]=tmp[j+1];
1981 void LyXTable::SetLongTable(int what)
1983 is_long_table = what;
1986 bool LyXTable::IsLongTable()
1988 return is_long_table;
1991 void LyXTable::SetRotateTable(int what)
1996 bool LyXTable::RotateTable()
2001 void LyXTable::SetRotateCell(int cell, int what)
2003 cellinfo_of_cell(cell)->rotate = what;
2006 bool LyXTable::RotateCell(int cell)
2008 return cellinfo_of_cell(cell)->rotate;
2011 bool LyXTable::NeedRotating()
2015 for (int i=0; i<rows;i++){
2016 for (int j=0;j<columns;j++){
2017 if (cell_info[i][j].rotate)
2024 void LyXTable::AppendContRow(int cell)
2026 int row = row_of_cell(cell)+1;
2028 if (!RowHasContRow(cell) || (CellHasContRow(cell)>=0))
2030 row_info[row].is_cont_row = true;
2031 row_info[row].top_line = false;
2032 cell_info[row-1][column_of_cell(cell)].has_cont_row = true;
2036 bool LyXTable::IsContRow(int cell)
2038 return row_info[row_of_cell(cell)].is_cont_row;
2041 int LyXTable::CellHasContRow(int cell)
2043 int row = row_of_cell(cell);
2045 if (VeryLastRow(cell))
2047 if (cell_info[row][column_of_cell(cell)].has_cont_row)
2048 return cell_info[row+1][column_of_cell(cell)].cellno;
2052 bool LyXTable::RowHasContRow(int cell)
2054 int row = row_of_cell(cell) + 1;
2057 return row_info[row].is_cont_row;
2061 int LyXTable::FirstVirtualCell(int cell)
2063 if (!IsContRow(cell))
2065 int row = row_of_cell(cell);
2066 int column = column_of_cell(cell);
2067 for(;(row>0) && IsContRow(cell_info[row][column].cellno); row--)
2069 return cell_info[row][column].cellno;
2073 int LyXTable::NextVirtualCell(int cell)
2075 if (!IsContRow(cell))
2077 int row = row_of_cell(cell);
2078 for(;(row < rows - 1) && IsContRow(cell_info[row][0].cellno); ++row)
2080 // what if(row >= rows) ?
2081 return cell_info[row][0].cellno;
2085 bool LyXTable::ShouldBeVeryLastCell(int cell)
2086 // "very last cell" ..of what? the row? the table?
2087 // "Cell" in this context appears to not count `virtual' cells
2089 int fcell = cell + 1;
2091 if (cell == GetNumberOfCells() - 1)
2092 return true; // not really sure if I should return false here
2093 if (!IsContRow(fcell))
2095 while((fcell < GetNumberOfCells() - 1) && IsContRow(fcell))
2097 if (fcell < GetNumberOfCells() - 1)
2102 bool LyXTable::ShouldBeVeryLastRow(int cell)
2104 if (CellHasContRow(cell)>=0)
2106 int row = row_of_cell(cell)+1;
2107 int column = column_of_cell(cell);
2108 while((row < rows) && IsContRow(cell_info[row][column].cellno))
2111 return false; // found another valid row
2112 // I do not have any valid row after the actual
2116 int LyXTable::GetCellAbove(int cell)
2118 int row = row_of_cell(cell);
2121 return cell_info[row-1][column_of_cell(cell)].cellno;
2125 int LyXTable::GetCellNumber(int column, int row)
2127 if (column >= columns)
2128 column = columns - 1;
2129 else if (column < 0)
2136 return cell_info[row][column].cellno;
2139 void LyXTable::SetLinebreaks(int cell, bool what)
2141 cellinfo_of_cell(FirstVirtualCell(cell))->linebreaks = what;
2144 bool LyXTable::Linebreaks(int cell)
2146 int fvcell = FirstVirtualCell(cell);
2148 if (column_info[column_of_cell(fvcell)].p_width.empty() &&
2149 !(IsMultiColumn(fvcell) && !cellinfo_of_cell(fvcell)->p_width.empty()))
2151 return cellinfo_of_cell(fvcell)->linebreaks;
2154 void LyXTable::SetLTHead(int cell, bool first)
2156 int row = row_of_cell(cell);
2159 if (row == endfirsthead)
2171 bool LyXTable::RowOfLTHead(int cell)
2173 if ((endhead+1) > rows)
2175 return (row_of_cell(cell) == endhead);
2178 bool LyXTable::RowOfLTFirstHead(int cell)
2180 if ((endfirsthead+1) > rows)
2182 return (row_of_cell(cell) == endfirsthead);
2185 void LyXTable::SetLTFoot(int cell, bool last)
2187 int row = row_of_cell(cell);
2190 if (row == endlastfoot)
2202 bool LyXTable::RowOfLTFoot(int cell)
2204 if ((endfoot+1) > rows) {
2208 return (row_of_cell(cell) == endfoot);
2211 bool LyXTable::RowOfLTLastFoot(int cell)
2213 if ((endlastfoot+1) > rows)
2215 return (row_of_cell(cell) == endlastfoot);
2218 void LyXTable::SetLTNewPage(int cell, bool what)
2220 row_info[row_of_cell(cell)].newpage = what;
2223 bool LyXTable::LTNewPage(int cell)
2225 return row_info[row_of_cell(cell)].newpage;