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 *======================================================
17 // $Id: table.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $
19 #if !defined(lint) && !defined(WITH_WARNINGS)
20 static char vcid[] = "$Id: table.C,v 1.1 1999/09/27 18:44:38 larsbj Exp $";
24 #pragma implementation
27 extern void addNewlineAndDepth(LString &file, int const depth); // Jug 990923
29 #define WIDTH_OF_LINE 5
32 LyXTable::LyXTable(int rows_arg, int columns_arg)
34 Init(rows_arg, columns_arg);
38 LyXTable::LyXTable(LyXLex &lex)
40 FILE *file = lex.getFile();
45 LyXTable::~LyXTable() {
48 delete[] columnofcell;
51 for (i=0; i<rows; i++) {
52 delete[] cell_info[i]; // verify that this shoudn't be freed with delete
58 LyXTable* LyXTable::Clone()
60 LyXTable *result = new LyXTable(rows, columns);
63 for (row=0; row<rows; row++){
64 for (column=0; column<columns;column++){
65 result->cell_info[row][column] = cell_info[row][column];
69 for (row=0; row<rows; row++){
70 result->row_info[row] = row_info[row];
73 for (column=0; column<columns; column++){
74 result->column_info[column].left_line = column_info[column].left_line;
75 result->column_info[column].right_line = column_info[column].right_line;
76 result->column_info[column].alignment = column_info[column].alignment;
77 result->column_info[column].p_width = column_info[column].p_width;
78 result->column_info[column].align_special = column_info[column].align_special;
81 result->SetLongTable(is_long_table);
82 result->rotate=rotate;
88 /* activates all lines and sets all widths to 0 */
89 void LyXTable::Init(int rows_arg, int columns_arg)
93 columns = columns_arg;
94 column_info = new columnstruct[columns];
95 row_info = new rowstruct[rows];
96 cell_info = new cellstruct*[rows];
99 for (i=0; i<rows;i++) {
100 cell_info[i] = new cellstruct[columns];
101 row_info[i].top_line = true;
102 row_info[i].bottom_line = false;
103 row_info[i].is_cont_row = false;
104 row_info[i].newpage = false;
105 for (j=0; j<columns; j++) {
106 cell_info[i][j].cellno = cellno++;
107 cell_info[i][j].width_of_cell = 0;
108 cell_info[i][j].multicolumn = LyXTable::CELL_NORMAL;
109 cell_info[i][j].alignment = LYX_ALIGN_CENTER;
110 cell_info[i][j].top_line = row_info[i].top_line;
111 cell_info[i][j].bottom_line = row_info[i].bottom_line;
112 cell_info[i][j].has_cont_row = false;
113 cell_info[i][j].rotate = false;
114 cell_info[i][j].linebreaks = false;
117 row_info[i-1].bottom_line = true;
118 row_info[0].bottom_line = true;
120 for (i=0; i<columns;i++) {
121 column_info[i].left_line = true;
122 column_info[i].right_line = false;
123 column_info[i].alignment = LYX_ALIGN_CENTER;
124 // set width_of_column to zero before it is used in
125 // calculate_width_of_column() (thornley)
126 column_info[i].width_of_column = 0;
127 calculate_width_of_column(i);
129 column_info[i-1].right_line = true;
131 calculate_width_of_table();
135 set_row_column_number_info();
136 is_long_table = false;
145 void LyXTable::AppendRow(int cell)
147 int row = row_of_cell(cell);
148 rowstruct *row_info2 = new rowstruct[rows+1];
149 cellstruct** cell_info2 = new cellstruct*[rows+1];
152 for (i=0; i <= row; i++) {
153 cell_info2[i] = cell_info[i];
154 row_info2[i] = row_info[i];
156 for (i=rows-1; i >= row; i--) {
157 cell_info2[i+1] = cell_info[i];
158 row_info2[i+1] = row_info[i];
160 for (i=row;row_info[i].is_cont_row;i--);
161 if (((row+1)>=rows) || !row_info[row+1].is_cont_row)
162 row_info2[row+1].is_cont_row = false;
163 row_info2[row+1].top_line = row_info[i].top_line;
164 cell_info2[row+1] = new cellstruct[columns];
165 for (i=0; i<columns; i++) {
166 cell_info2[row+1][i].width_of_cell = 0;
167 cell_info2[row+1][i] = cell_info2[row][i];
171 cell_info = cell_info2;
173 row_info = row_info2;
181 void LyXTable::DeleteRow(int cell)
183 int row = row_of_cell(cell);
184 while(!row_info[row].is_cont_row && RowHasContRow(cell))
185 DeleteRow(cell_info[row+1][0].cellno);
186 rowstruct *row_info2 = new rowstruct[rows-1];
187 cellstruct** cell_info2 = new cellstruct*[rows-1];
190 delete[] cell_info[row];
191 for (i=0; i < row; i++) {
192 cell_info2[i] = cell_info[i];
193 row_info2[i] = row_info[i];
195 if (row_info[i].is_cont_row)
196 row_info2[i-1].bottom_line = row_info[i].bottom_line;
197 for (i=row; i < rows - 1; i++) {
198 cell_info2[i] = cell_info[i+1];
199 row_info2[i] = row_info[i+1];
204 cell_info = cell_info2;
206 row_info = row_info2;
214 void LyXTable::AppendColumn(int cell)
217 columnstruct *column_info2 = new columnstruct[columns+1];
218 int column = right_column_of_cell(cell);
220 for (i=0; i<=column; i++){
221 column_info2[i] = column_info[i];
223 for (i=columns-1; i>=column; i--){
224 column_info2[i+1] = column_info[i];
227 delete[] column_info;
228 column_info = column_info2;
230 for (i=0; i<rows;i++){
231 cellstruct* tmp = cell_info[i];
232 cell_info[i] = new cellstruct[columns+1];
233 for (j=0; j<=column; j++){
234 cell_info[i][j]=tmp[j];
236 for (j=column; j<columns; j++){
237 cell_info[i][j+1]=tmp[j];
239 // care about multicolumns
240 if (cell_info[i][column+1].multicolumn
241 ==LyXTable::CELL_BEGIN_OF_MULTICOLUMN){
242 cell_info[i][column+1].multicolumn =
243 LyXTable::CELL_PART_OF_MULTICOLUMN;
245 if (column + 1 == columns
246 || cell_info[i][column+2].multicolumn
247 !=LyXTable::CELL_PART_OF_MULTICOLUMN){
248 cell_info[i][column+1].multicolumn =
249 LyXTable::CELL_NORMAL;
260 void LyXTable::Reinit()
264 for (i=0; i<rows;i++) {
265 for (j=0; j<columns; j++) {
266 cell_info[i][j].width_of_cell = 0;
267 if ((i+1 < rows) && !row_info[i+1].is_cont_row)
268 cell_info[i][j].has_cont_row = false;
272 for (i=0; i<columns;i++) {
273 calculate_width_of_column(i);
275 calculate_width_of_table();
277 set_row_column_number_info();
281 void LyXTable::set_row_column_number_info()
287 for (row=0; row<rows; ++row) {
288 for (column=0; column<columns; ++column) {
289 if (cell_info[row][column].multicolumn
290 != LyXTable::CELL_PART_OF_MULTICOLUMN)
292 cell_info[row][column].cellno = numberofcells;
295 ++numberofcells; // because this is one more than as we start from 0
301 rowofcell = new int[numberofcells];
303 delete [] columnofcell;
304 columnofcell = new int[numberofcells];
306 while (c < numberofcells && row < rows && column < columns) {
308 columnofcell[c]=column;
312 } while (column < columns &&
313 cell_info[row][column].multicolumn
314 == LyXTable::CELL_PART_OF_MULTICOLUMN);
315 if (column == columns){
323 void LyXTable::DeleteColumn(int cell)
325 int column1 = column_of_cell(cell);
326 int column2 = right_column_of_cell(cell);
329 if (column1 == 0 && column2 == columns - 1)
332 for (column = column1; column <= column2;column++){
333 delete_column(column1);
339 int LyXTable::GetNumberOfCells()
341 return numberofcells;
345 int LyXTable::NumberOfCellsInRow(int cell)
347 int row = row_of_cell(cell);
350 for (i=0; i<columns; i++){
351 if (cell_info[row][i].multicolumn != LyXTable::CELL_PART_OF_MULTICOLUMN)
358 int LyXTable::AppendCellAfterCell(int append_cell, int question_cell)
360 return (right_column_of_cell(append_cell) ==
361 right_column_of_cell(question_cell));
365 int LyXTable::DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell)
367 if (column_of_cell(delete_column_cell) == 0 &&
368 right_column_of_cell(delete_column_cell) == columns - 1)
372 (column_of_cell(cell) >= column_of_cell(delete_column_cell) &&
373 column_of_cell(cell) <= right_column_of_cell(delete_column_cell));
377 /* returns 1 if there is a topline, returns 0 if not */
378 bool LyXTable::TopLine(int cell)
380 int row=row_of_cell(cell);
383 return TopLine(cell_info[row-1][column_of_cell(cell)].cellno);
384 if (IsMultiColumn(cell))
385 return cellinfo_of_cell(cell)->top_line;
386 return row_info[row].top_line;
390 bool LyXTable::BottomLine(int cell)
392 //no bottom line underneath non-existent cells if you please
393 if(cell >= numberofcells)
396 int row=row_of_cell(cell);
398 if (RowHasContRow(cell))
399 return BottomLine(cell_info[row+1][column_of_cell(cell)].cellno);
400 if (IsMultiColumn(cell))
401 return cellinfo_of_cell(cell)->bottom_line;
402 return row_info[row_of_cell(cell)].bottom_line;
406 bool LyXTable::LeftLine(int cell)
408 return column_info[column_of_cell(cell)].left_line;
411 bool LyXTable::RightLine(int cell)
413 return column_info[right_column_of_cell(cell)].right_line;
417 bool LyXTable::TopAlreadyDrawed(int cell)
419 if (AdditionalHeight(cell))
421 int row = row_of_cell(cell);
423 int column = column_of_cell(cell);
425 && cell_info[row-1][column].multicolumn
426 == LyXTable::CELL_PART_OF_MULTICOLUMN)
428 if (cell_info[row-1][column].multicolumn
429 == LyXTable::CELL_NORMAL)
430 return row_info[row-1].bottom_line;
432 return cell_info[row-1][column].bottom_line;
438 bool LyXTable::VeryLastRow(int cell)
440 return (row_of_cell(cell) == rows-1);
444 int LyXTable::AdditionalHeight(int cell)
446 int row = row_of_cell(cell);
451 for (column=0;column < columns-1 && bottom;column++){
452 switch (cell_info[row-1][column].multicolumn){
453 case LyXTable::CELL_BEGIN_OF_MULTICOLUMN:
454 bottom = cell_info[row-1][column].bottom_line;
456 case LyXTable::CELL_NORMAL:
457 bottom = row_info[row-1].bottom_line;
460 for (column=0;column < columns-1 && top;column++){
461 switch (cell_info[row][column].multicolumn){
462 case LyXTable::CELL_BEGIN_OF_MULTICOLUMN:
463 top = cell_info[row][column].top_line;
465 case LyXTable::CELL_NORMAL:
466 top = row_info[row].top_line;
470 return WIDTH_OF_LINE;
476 int LyXTable::AdditionalWidth(int cell)
478 // internally already set in SetWidthOfCell
479 // used to get it back in text.C
480 int col = right_column_of_cell(cell);
481 if (col < columns - 1 && column_info[col].right_line &&
482 column_info[col+1].left_line)
483 return WIDTH_OF_LINE;
489 // returns the maximum over all rows
490 int LyXTable::WidthOfColumn(int cell)
492 int column1 = column_of_cell(cell);
493 int column2 = right_column_of_cell(cell);
496 for (i=column1; i<=column2;i++){
497 result += column_info[i].width_of_column;
503 int LyXTable::WidthOfTable()
505 return width_of_table;
508 /* returns 1 if a complete update is necessary, otherwise 0 */
509 bool LyXTable::SetWidthOfMulticolCell(int cell, int new_width)
511 if (!IsMultiColumn(cell))
514 int row = row_of_cell(cell);
515 int column1 = column_of_cell(cell);
516 int column2 = right_column_of_cell(cell);
520 // first set columns to 0 so we can calculate the right width
521 for (i=column1; i<=column2;i++) {
522 cell_info[row][i].width_of_cell = 0;
524 // set the width to MAX_WIDTH until width > 0
525 width = (new_width + 2*WIDTH_OF_LINE);
526 for (i=column1; (i<column2) && (width > 0);i++){
527 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
528 width -= column_info[i].width_of_column;
531 cell_info[row][i].width_of_cell = width;
536 void LyXTable::recalculateMulticolCells(int cell, int new_width)
539 row = row_of_cell(cell),
540 column1 = column_of_cell(cell),
541 column2 = right_column_of_cell(cell),
544 // first set columns to 0 so we can calculate the right width
545 for (i=column1; i<=column2;++i)
546 cell_info[row][i].width_of_cell = 0;
547 for(i=cell+1;(i<numberofcells) && (!IsMultiColumn(i));++i)
549 if (i < numberofcells)
550 recalculateMulticolCells(i,GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
551 SetWidthOfMulticolCell(cell,new_width);
554 /* returns 1 if a complete update is necessary, otherwise 0 */
555 bool LyXTable::SetWidthOfCell(int cell, int new_width)
557 int row = row_of_cell(cell);
558 int column1 = column_of_cell(cell);
562 if (IsMultiColumn(cell)) {
563 tmp = SetWidthOfMulticolCell(cell, new_width);
565 width = (new_width + 2*WIDTH_OF_LINE);
566 cell_info[row][column1].width_of_cell = width;
567 if (column_info[column1].right_line && (column1 < columns-1) &&
568 column_info[column1+1].left_line) // additional width
569 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
570 tmp = calculate_width_of_column_NMC(column1);
574 for(i=0; i<columns;++i)
575 calculate_width_of_column_NMC(i);
576 for(i=0; (i<numberofcells) && !IsMultiColumn(i); ++i)
579 recalculateMulticolCells(i,GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
580 for(i=0; i<columns;++i)
581 calculate_width_of_column(i);
582 calculate_width_of_table();
589 bool LyXTable::SetAlignment(int cell, char align)
591 if (!IsMultiColumn(cell))
592 column_info[column_of_cell(cell)].alignment = align;
593 cellinfo_of_cell(cell)->alignment = align;
597 bool LyXTable::SetPWidth(int cell, LString width)
599 int fvcell = FirstVirtualCell(cell);
601 if (IsMultiColumn(fvcell)) {
602 // if (column_info[column_of_cell(cell)].p_width.empty())
603 // column_info[column_of_cell(cell)].p_width = width;
604 cellinfo_of_cell(fvcell)->p_width = width;
606 column_info[column_of_cell(fvcell)].p_width = width;
607 SetAlignment(cell,LYX_ALIGN_LEFT);
612 bool LyXTable::SetAlignSpecial(int cell, LString special, int what)
614 if (what == SET_SPECIAL_MULTI)
615 cellinfo_of_cell(cell)->align_special = special;
617 column_info[column_of_cell(cell)].align_special = special;
621 bool LyXTable::SetAllLines(int cell, bool line)
623 SetTopLine(cell,line);
624 SetBottomLine(cell,line);
625 SetRightLine(cell,line);
626 SetLeftLine(cell,line);
630 bool LyXTable::SetTopLine(int cell, bool line)
632 int row = row_of_cell(cell);
635 SetTopLine(cell_info[row-1][column_of_cell(cell)].cellno,line);
636 else if (!IsMultiColumn(cell))
637 row_info[row].top_line = line;
639 cellinfo_of_cell(cell)->top_line = line;
644 bool LyXTable::SetBottomLine(int cell, bool line)
646 int row = row_of_cell(cell);
648 if (RowHasContRow(cell))
649 SetBottomLine(cell_info[row+1][column_of_cell(cell)].cellno,line);
650 else if (!IsMultiColumn(cell))
651 row_info[row_of_cell(cell)].bottom_line = line;
653 cellinfo_of_cell(cell)->bottom_line = line;
658 bool LyXTable::SetLeftLine(int cell, bool line)
660 column_info[column_of_cell(cell)].left_line = line;
665 bool LyXTable::SetRightLine(int cell, bool line)
667 column_info[right_column_of_cell(cell)].right_line = line;
672 char LyXTable::GetAlignment(int cell)
674 if (IsMultiColumn(cell))
675 return cellinfo_of_cell(cell)->alignment;
677 return column_info[column_of_cell(cell)].alignment;
680 LString LyXTable::GetPWidth(int cell)
682 int fvcell = FirstVirtualCell(cell);
684 if (IsMultiColumn(fvcell)) // && !cellinfo_of_cell(cell)->p_width.empty())
685 return cellinfo_of_cell(fvcell)->p_width;
686 return column_info[column_of_cell(fvcell)].p_width;
689 LString LyXTable::GetAlignSpecial(int cell, int what)
691 if (what == SET_SPECIAL_MULTI)
692 return cellinfo_of_cell(cell)->align_special;
693 return column_info[column_of_cell(cell)].align_special;
696 int LyXTable::GetWidthOfCell(int cell)
698 int row = row_of_cell(cell);
699 int column1 = column_of_cell(cell);
700 int column2 = right_column_of_cell(cell);
703 for (i=column1; i<=column2;i++){
704 result += cell_info[row][i].width_of_cell;
707 result += AdditionalWidth(cell);
713 int LyXTable::GetBeginningOfTextInCell(int cell)
717 switch (GetAlignment(cell)){
718 case LYX_ALIGN_CENTER:
719 x += (WidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
721 case LYX_ALIGN_RIGHT:
722 x += WidthOfColumn(cell) - GetWidthOfCell(cell) + AdditionalWidth(cell);
724 default: /* LYX_ALIGN_LEFT: nothing :-) */
734 bool LyXTable::IsFirstCell(int cell)
736 return (column_of_cell(cell) == 0);
739 bool LyXTable::IsLastCell(int cell)
741 return (right_column_of_cell(cell) == (columns-1));
745 bool LyXTable::calculate_width_of_column(int column)
748 int old_column_width = column_info[column].width_of_column;
750 for (i=0; i<rows; i++) {
751 if (cell_info[i][column].width_of_cell > max) {
752 max = cell_info[i][column].width_of_cell;
755 column_info[column].width_of_column = max;
756 return (column_info[column].width_of_column != old_column_width);
759 bool LyXTable::calculate_width_of_column_NMC(int column)
762 int old_column_width = column_info[column].width_of_column;
764 for (i=0; i<rows; ++i) {
765 if (!IsMultiColumn(GetCellNumber(column,i)) &&
766 (cell_info[i][column].width_of_cell > max)) {
767 max = cell_info[i][column].width_of_cell;
770 column_info[column].width_of_column = max;
771 return (column_info[column].width_of_column != old_column_width);
774 void LyXTable::calculate_width_of_table()
778 for (i=0; i<columns;i++) {
779 width_of_table += column_info[i].width_of_column;
784 int LyXTable::row_of_cell(int cell)
786 if (cell >= numberofcells)
790 return rowofcell[cell];
794 int LyXTable::column_of_cell(int cell)
796 if (cell >= numberofcells)
800 return columnofcell[cell];
804 int LyXTable::right_column_of_cell(int cell)
806 int row = row_of_cell(cell);
807 int column = column_of_cell(cell);
808 while (column < columns - 1 &&
809 cell_info[row][column+1].multicolumn == LyXTable::CELL_PART_OF_MULTICOLUMN)
815 void LyXTable::Write(FILE* file)
818 fprintf(file, "multicol5\n");
819 fprintf(file, "%d %d %d %d %d %d %d %d\n", rows, columns, is_long_table,
820 rotate, endhead, endfirsthead, endfoot, endlastfoot);
821 for (i=0; i<rows; i++){
822 fprintf(file, "%d %d %d %d\n", row_info[i].top_line,
823 row_info[i].bottom_line, row_info[i].is_cont_row,
824 row_info[i].newpage);
826 for (i=0; i<columns; i++){
827 fprintf(file, "%d %d %d \"%s\" \"%s\"\n",
828 column_info[i].alignment, column_info[i].left_line,
829 column_info[i].right_line,
830 VSpace(column_info[i].p_width).asLyXCommand().c_str(),
831 column_info[i].align_special.c_str());
834 for (i=0; i<rows;i++){
835 for (j=0;j<columns;j++){
836 fprintf(file, "%d %d %d %d %d %d %d \"%s\" \"%s\"\n",
837 cell_info[i][j].multicolumn,
838 cell_info[i][j].alignment,
839 cell_info[i][j].top_line,
840 cell_info[i][j].bottom_line,
841 cell_info[i][j].has_cont_row,
842 cell_info[i][j].rotate,
843 cell_info[i][j].linebreaks,
844 cell_info[i][j].align_special.c_str(),
845 cell_info[i][j].p_width.c_str());
851 #warning Clean up this code in 0.13 (Jug)
853 void LyXTable::Read(FILE* file)
859 int is_long_table_arg = false;
860 int rotate_arg = false;
870 char vtmp[100], stmp[100], atmp[100];
872 fscanf(file, "%s\n", vtmp);
875 version = atoi(s.c_str()+8);
880 fgets(vtmp,sizeof(vtmp),file);
881 sscanf(vtmp, "%d %d %d %d %d %d %d %d\n", &rows_arg, &columns_arg,
882 &is_long_table_arg, &rotate_arg, &a, &b, &c, &d);
884 fscanf(file, "%d %d\n",
885 &rows_arg, &columns_arg);
886 Init(rows_arg, columns_arg);
887 SetLongTable(is_long_table_arg);
888 SetRotateTable(rotate_arg);
893 for (i=0; i<rows; i++){
895 fgets(vtmp,sizeof(vtmp),file);
896 sscanf(vtmp, "%d %d %d %d\n",
898 row_info[i].top_line = a;
899 row_info[i].bottom_line = b;
900 row_info[i].is_cont_row = c;
901 row_info[i].newpage = d;
903 for (i=0; i<columns; i++){
906 fgets(vtmp,sizeof(vtmp),file);
907 sscanf(vtmp, "%d %d %d %s %s", &a, &b, &c, stmp, atmp);
908 column_info[i].alignment = (char) a;
909 column_info[i].left_line = b;
910 column_info[i].right_line = c;
911 if (*stmp == '"') { /* strip quotes if they exists */
914 // there are quotes so I have to reread the string correctly
915 // this is only because the old format did not have "
916 // this means also that atmp is ONLY set here!!!
918 sscanf(vtmp, "%*d %*d %*d %*s \"%[^\"]\"", atmp);
919 else // otherwise after the first empty "" read is aborded
920 sscanf(vtmp, "%*d %*d %*d \"%[^\"]\" \"%[^\"]\"", stmp, atmp);
921 column_info[i].p_width = stmp;
922 column_info[i].align_special = atmp;
924 column_info[i].p_width = stmp;
927 for (i=0; i<rows;i++){
928 for (j=0;j<columns;j++){
929 fscanf(file, "%d %d\n", &a, &b);
930 cell_info[i][j].multicolumn = (char) a;
931 cell_info[i][j].alignment = (char) b;
934 } else if (version < 4) {
935 for (i=0; i<rows;i++){
936 for (j=0;j<columns;j++){
937 fscanf(file, "%d %d %d %d\n", &a, &b, &c, &d);
938 cell_info[i][j].multicolumn = (char) a;
939 cell_info[i][j].alignment = (char) b;
940 cell_info[i][j].top_line = (char) c;
941 cell_info[i][j].bottom_line = (char) d;
945 for (i=0; i<rows;i++){
946 for (j=0;j<columns;j++){
950 fgets(vtmp,sizeof(vtmp),file);
951 sscanf(vtmp, "%d %d %d %d %d %d %d %s %s\n",
952 &a, &b, &c, &d, &e, &f, &g, stmp, atmp);
953 cell_info[i][j].multicolumn = (char) a;
954 cell_info[i][j].alignment = (char) b;
955 cell_info[i][j].top_line = (char) c;
956 cell_info[i][j].bottom_line = (char) d;
957 cell_info[i][j].has_cont_row = (bool) e;
958 cell_info[i][j].rotate = (bool) f;
959 cell_info[i][j].linebreaks = (bool) g;
960 // this is only to see if I have an empty string first
961 // this clause should be always TRUE!!!
966 sscanf(vtmp,"%*d %*d %*d %*d %*d %*d %*d %*s \"%[^\"]\"",
968 else // otherwise after the first empty "" read is aborded
969 sscanf(vtmp,"%*d %*d %*d %*d %*d %*d %*d \"%[^\"]\" \"%[^\"]\"",
971 cell_info[i][j].align_special = stmp;
972 cell_info[i][j].p_width = atmp;
974 cell_info[i][j].align_special = stmp;
978 set_row_column_number_info();
982 // cell <0 will tex the preamble
983 // returns the number of printed newlines
984 int LyXTable::TexEndOfCell(LString& file, int cell)
990 if (ShouldBeVeryLastCell(cell)) {
991 // the very end at the very beginning
992 if (Linebreaks(cell))
993 file += "\\smallskip{}}";
994 if (IsMultiColumn(cell))
996 if (RotateCell(cell)) {
997 file += "\n\\end{sideways}";
1005 while (!IsFirstCell(fcell))fcell--;
1006 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1007 if (BottomLine(fcell+i))
1010 if (tmp == NumberOfCellsInRow(fcell)){
1014 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1015 if (BottomLine(fcell+i)){
1017 file += column_of_cell(fcell+i)+1;
1019 file += right_column_of_cell(fcell+i)+1;
1030 file += "\\end{longtable}";
1032 file += "\\end{tabular}";
1034 file += "\n\\end{sideways}";
1038 nvcell = NextVirtualCell(cell+1);
1042 file += "\\begin{sideways}\n";
1046 file += "\\begin{longtable}{";
1048 file += "\\begin{tabular}{";
1049 for (i=0; i<columns;i++){
1050 if (column_info[i].left_line)
1052 if (!column_info[i].align_special.empty()) {
1053 file += column_info[i].align_special.c_str();
1054 } else if (!column_info[i].p_width.empty()) {
1056 file += column_info[i].p_width;
1059 switch (column_info[i].alignment) {
1060 case LYX_ALIGN_LEFT:
1063 case LYX_ALIGN_RIGHT:
1071 if (column_info[i].right_line)
1077 if (GetNumberOfCells()){
1079 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1080 if (TopLine(fcell+i))
1083 if (tmp == NumberOfCellsInRow(fcell)){
1087 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1088 if (TopLine(fcell+i)){
1090 file += column_of_cell(fcell+i)+1;
1092 file += right_column_of_cell(fcell+i)+1;
1103 if (RotateCell(0)) {
1104 file += "\\begin{sideways}\n";
1109 if (Linebreaks(cell))
1110 file += "\\smallskip{}}";
1111 if (IsMultiColumn(cell)){
1114 if (RotateCell(cell)) {
1115 file += "\n\\end{sideways}";
1118 if (IsLastCell(cell)) {
1119 int row = row_of_cell(cell);
1120 LString hline1,hline2;
1121 bool print_hline = true;
1122 bool pr_top_hline,flag1,flag2;
1123 flag1 = IsLongTable() &&
1124 ((row == endhead) || (row == endfirsthead) ||
1125 (row == endfoot) || (row == endlastfoot));
1127 flag2 = IsLongTable() &&
1128 ((row <= endhead) || (row <= endfirsthead) ||
1129 (row <= endfoot) || (row <= endlastfoot));
1131 // print the bottom hline only if (otherwise it is doubled):
1132 // - is no LongTable
1133 // - there IS a first-header
1134 // - the next row is no special header/footer
1135 // & this row is no special header/footer
1136 // - the next row is a special header/footer
1137 // & this row is a special header/footer
1138 pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1139 (endfirsthead == endhead);
1144 while (!IsFirstCell(fcell))
1146 for (i=0; i < NumberOfCellsInRow(cell); i++){
1147 if (BottomLine(fcell+i))
1150 if (tmp == NumberOfCellsInRow(cell)){
1152 hline1 = "\\hline ";
1155 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1156 if (BottomLine(fcell+i)){
1158 file += column_of_cell(fcell+i)+1;
1160 file += right_column_of_cell(fcell+i)+1;
1162 hline1 += "\\cline{";
1163 hline1 += column_of_cell(fcell+i)+1;
1165 hline1 += right_column_of_cell(fcell+i)+1;
1175 if (IsLongTable() && (row == endfoot)) {
1176 file += "\\endfoot\n";
1178 print_hline = false; // no double line below footer
1180 if (IsLongTable() && (row == endlastfoot)) {
1181 file += "\\endlastfoot\n";
1183 print_hline = false; // no double line below footer
1185 if (IsLongTable() && row_info[row].newpage) {
1186 file += "\\newpage\n";
1188 print_hline = false; // no line below a \\newpage-command
1191 if (nvcell < numberofcells && (cell < GetNumberOfCells()-1) &&
1192 !ShouldBeVeryLastCell(cell)) {
1195 // Now jump all ContRows
1196 while (IsContRow(fcell))
1198 while (!IsFirstCell(fcell))
1201 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1202 if (TopLine(fcell+i))
1205 if (tmp == NumberOfCellsInRow(fcell)){
1208 hline2 = "\\hline ";
1212 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1213 if (TopLine(fcell+i)){
1216 file += column_of_cell(fcell+i)+1;
1218 file += right_column_of_cell(fcell+i)+1;
1221 hline2 += "\\cline{";
1222 hline2 += column_of_cell(fcell+i)+1;
1224 hline2 += right_column_of_cell(fcell+i)+1;
1230 if (tmp && print_hline){
1235 // the order here is important as if one defines two
1236 // or more things in one line only the first entry is
1237 // displayed the other are set to an empty-row. This
1238 // is important if I have a footer and want that the
1239 // lastfooter is NOT displayed!!!
1240 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1241 (row == endfoot) || (row == endlastfoot);
1243 // sflag2 = IsLongTable() && (row >= 0) &&
1244 // (sflag2 || (row == endhead) || (row == endfirsthead));
1246 bool sflag1 = IsLongTable() && (row != endhead) &&
1247 (row != endfirsthead) &&
1248 ((row == endfoot) || (row == endlastfoot));
1250 if (IsLongTable() && (row == endhead)) {
1251 file += "\\endhead\n";
1254 if (IsLongTable() && (row == endfirsthead)) {
1255 file += "\\endfirsthead\n";
1258 if (sflag1) { // add the \hline for next foot row
1259 if (!hline1.empty()) {
1260 file += hline1 + '\n';
1264 // add the \hline for the first row
1265 if (pr_top_hline && sflag2) {
1266 if (!hline2.empty()) {
1267 file += hline2 + '\n';
1271 if (nvcell < numberofcells && RotateCell(nvcell)) {
1272 file += "\\begin{sideways}\n";
1278 if (nvcell < numberofcells && RotateCell(nvcell)) {
1279 file += "\\begin{sideways}\n";
1284 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1285 file += "\\multicolumn{";
1286 file += cells_in_multicolumn(nvcell);
1288 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1289 file += cellinfo_of_cell(cell+1)->align_special;
1292 if (LeftLine(nvcell))
1294 if (!GetPWidth(nvcell).empty()) {
1296 file += GetPWidth(nvcell);
1299 switch (GetAlignment(nvcell)) {
1300 case LYX_ALIGN_LEFT: file += 'l'; break;
1301 case LYX_ALIGN_RIGHT: file += 'r'; break;
1302 default: file += 'c'; break;
1305 if (RightLine(nvcell))
1307 //if (column_of_cell(cell+2)!=0 && LeftLine(cell+2))
1308 if (((nvcell+1) < numberofcells) &&
1309 (NextVirtualCell(nvcell+1) < numberofcells) &&
1310 (column_of_cell(NextVirtualCell(nvcell+1))!=0) &&
1311 LeftLine(NextVirtualCell(nvcell+1)))
1316 if (nvcell < numberofcells && Linebreaks(nvcell)) {
1317 // !column_info[column_of_cell(nvcell)].p_width.empty()) {
1318 file += "\\parbox{";
1319 file += GetPWidth(nvcell);
1320 file += "}{\\smallskip{}";
1327 // cell <0 will tex the preamble
1328 // returns the number of printed newlines
1329 int LyXTable::RoffEndOfCell(FILE* file, int cell)
1334 if (cell == GetNumberOfCells() - 1){
1335 // the very end at the very beginning
1336 if (CellHasContRow(cell) >= 0) {
1337 fprintf(file,"\nT}");
1340 fprintf(file, "\n");
1342 if (row_info[row_of_cell(cell)].bottom_line) {
1343 fprintf(file, "_\n");
1346 fprintf(file, ".TE\n.pl 1c");
1351 fprintf(file, "\n.pl 500c\n.TS\n");
1352 for (j=0; j<rows; j++) {
1353 for (i=0; i<columns;i++,fcell++) {
1354 if (column_info[i].left_line)
1355 fprintf(file, " | ");
1356 if (cell_info[j][i].multicolumn==CELL_PART_OF_MULTICOLUMN)
1359 switch (column_info[i].alignment) {
1360 case LYX_ALIGN_LEFT:
1363 case LYX_ALIGN_RIGHT:
1371 if (!column_info[i].p_width.empty())
1372 fprintf(file, "w(%s)", column_info[i].p_width.c_str());
1373 if (column_info[i].right_line)
1374 fprintf(file, " | ");
1377 fprintf(file, "\n");
1381 fprintf(file, ".\n");
1383 if (row_info[0].top_line) {
1384 fprintf(file,"_\n");
1387 if (CellHasContRow(0) >= 0) {
1388 fprintf(file,"T{\n");
1393 if (CellHasContRow(cell) >= 0) {
1394 fprintf(file,"\nT}");
1397 if (right_column_of_cell(cell) == columns -1){
1398 fprintf(file, "\n");
1400 int row = row_of_cell(cell);
1401 if (row_info[row++].bottom_line) {
1402 fprintf(file, "_\n");
1405 if ((row < rows) && row_info[row].top_line) {
1406 fprintf(file, "_\n");
1410 fprintf(file, "\t");
1411 if ((cell < GetNumberOfCells() - 1) &&
1412 (CellHasContRow(cell+1) >= 0)) {
1413 fprintf(file,"T{\n");
1421 const char *LyXTable::getDocBookAlign(int cell, bool isColumn=false)
1427 i = column_of_cell(cell);
1428 if (!isColumn && IsMultiColumn(cell)) {
1429 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1430 return cellinfo_of_cell(cell)->align_special.c_str();
1432 switch (GetAlignment(cell)) {
1433 case LYX_ALIGN_LEFT:
1435 case LYX_ALIGN_RIGHT:
1442 if (!column_info[i].align_special.empty()) {
1443 return column_info[i].align_special.c_str();
1445 #ifdef IGNORE_THIS_FOR_NOW
1446 else if (!column_info[i].p_width.empty()) {
1448 file += column_info[i].p_width;
1453 switch (column_info[i].alignment) {
1454 case LYX_ALIGN_LEFT:
1456 case LYX_ALIGN_RIGHT:
1465 // cell <0 will tex the preamble
1466 // returns the number of printed newlines
1467 int LyXTable::DocBookEndOfCell(LString& file, int cell, int &depth)
1473 if (ShouldBeVeryLastCell(cell)) {
1475 // the very end at the very beginning
1476 if (Linebreaks(cell))
1477 file += "\\smallskip{}}";
1478 if (IsMultiColumn(cell))
1480 if (RotateCell(cell)) {
1481 file += "\n\\end{sideways}";
1489 while (!IsFirstCell(fcell))fcell--;
1490 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1491 if (BottomLine(fcell+i))
1494 if (tmp == NumberOfCellsInRow(fcell)){
1498 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1499 if (BottomLine(fcell+i)){
1501 file += column_of_cell(fcell+i)+1;
1503 file += right_column_of_cell(fcell+i)+1;
1514 addNewlineAndDepth(file,--depth);
1516 addNewlineAndDepth(file,--depth);
1518 addNewlineAndDepth(file,--depth);
1520 addNewlineAndDepth(file,--depth);
1522 file += "</TGROUP>";
1524 file += "</TGROUP>";
1525 addNewlineAndDepth(file,--depth);
1528 file += "\n\\end{sideways}";
1534 nvcell = NextVirtualCell(cell+1);
1543 file += "' COLSEP='1' ROWSEP='1'>";
1544 addNewlineAndDepth(file,++depth);
1546 for (i=0; i<columns;i++) {
1547 file += "<COLSPEC ALIGN='";
1548 file += getDocBookAlign(i, true);
1549 file += "' COLNAME='col";
1551 file += "' COLNUM='";
1553 file += "' COLSEP='";
1554 if (i == (columns-1)) {
1557 if (column_info[i].right_line ||
1558 column_info[i+1].left_line)
1564 addNewlineAndDepth(file,depth);
1566 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1567 if (column_info[i].left_line)
1573 if (GetNumberOfCells()) {
1575 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1576 if (TopLine(fcell+i))
1579 if (tmp == NumberOfCellsInRow(fcell)){
1583 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1584 if (TopLine(fcell+i)){
1586 file += column_of_cell(fcell+i)+1;
1588 file += right_column_of_cell(fcell+i)+1;
1599 if (RotateCell(0)) {
1600 file += "\\begin{sideways}\n";
1605 addNewlineAndDepth(file,++depth);
1607 addNewlineAndDepth(file,++depth);
1608 file += "<ENTRY ALIGN='";
1609 file += getDocBookAlign(0);
1611 if (IsMultiColumn(0)) {
1612 file += " NAMEST='col1' NAMEEND='col";
1613 file += cells_in_multicolumn(0);
1617 addNewlineAndDepth(file,++depth);
1622 if (Linebreaks(cell))
1623 file += "\\smallskip{}}";
1624 if (IsMultiColumn(cell)){
1627 if (RotateCell(cell)) {
1628 file += "\n\\end{sideways}";
1632 if (IsLastCell(cell)) {
1633 addNewlineAndDepth(file,--depth);
1635 addNewlineAndDepth(file,--depth);
1637 addNewlineAndDepth(file,depth);
1639 addNewlineAndDepth(file,++depth);
1640 file += "<ENTRY ALIGN='";
1641 file += getDocBookAlign(cell+1);
1642 file += "' VALIGN='middle'";
1643 if (IsMultiColumn(cell+1)) {
1644 file += " NAMEST='col";
1645 file += column_of_cell(cell+1) + 1;
1646 file += "' NAMEEND='col";
1647 file += column_of_cell(cell+1) +
1648 cells_in_multicolumn(cell+1);
1652 addNewlineAndDepth(file,++depth);
1655 int row = row_of_cell(cell);
1656 LString hline1,hline2;
1657 bool print_hline = true;
1658 bool pr_top_hline,flag1,flag2;
1659 flag1 = IsLongTable() &&
1660 ((row == endhead) || (row == endfirsthead) ||
1661 (row == endfoot) || (row == endlastfoot));
1663 flag2 = IsLongTable() &&
1664 ((row <= endhead) || (row <= endfirsthead) ||
1665 (row <= endfoot) || (row <= endlastfoot));
1667 // print the bottom hline only if (otherwise it is doubled):
1668 // - is no LongTable
1669 // - there IS a first-header
1670 // - the next row is no special header/footer
1671 // & this row is no special header/footer
1672 // - the next row is a special header/footer
1673 // & this row is a special header/footer
1674 pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1675 (endfirsthead == endhead);
1680 while (!IsFirstCell(fcell))
1682 for (i=0; i < NumberOfCellsInRow(cell); i++){
1683 if (BottomLine(fcell+i))
1686 if (tmp == NumberOfCellsInRow(cell)){
1688 hline1 = "\\hline ";
1691 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1692 if (BottomLine(fcell+i)){
1694 file += column_of_cell(fcell+i)+1;
1696 file += right_column_of_cell(fcell+i)+1;
1698 hline1 += "\\cline{";
1699 hline1 += column_of_cell(fcell+i)+1;
1701 hline1 += right_column_of_cell(fcell+i)+1;
1711 if (IsLongTable() && (row == endfoot)) {
1712 file += "\\endfoot\n";
1714 print_hline = false; // no double line below footer
1716 if (IsLongTable() && (row == endlastfoot)) {
1717 file += "\\endlastfoot\n";
1719 print_hline = false; // no double line below footer
1721 if (IsLongTable() && row_info[row].newpage) {
1722 file += "\\newpage\n";
1724 print_hline = false; // no line below a \\newpage-command
1727 if (nvcell < numberofcells && (cell < GetNumberOfCells()-1) &&
1728 !ShouldBeVeryLastCell(cell)) {
1730 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1731 if (TopLine(fcell+i))
1734 if (tmp == NumberOfCellsInRow(fcell)){
1737 hline2 = "\\hline ";
1741 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1742 if (TopLine(fcell+i)){
1745 file += column_of_cell(fcell+i)+1;
1747 file += right_column_of_cell(fcell+i)+1;
1750 hline2 += "\\cline{";
1751 hline2 += column_of_cell(fcell+i)+1;
1753 hline2 += right_column_of_cell(fcell+i)+1;
1759 if (tmp && print_hline){
1764 // the order here is important as if one defines two
1765 // or more things in one line only the first entry is
1766 // displayed the other are set to an empty-row. This
1767 // is important if I have a footer and want that the
1768 // lastfooter is NOT displayed!!!
1769 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1770 (row == endfoot) || (row == endlastfoot);
1772 // sflag2 = IsLongTable() && (row >= 0) &&
1773 // (sflag2 || (row == endhead) || (row == endfirsthead));
1775 bool sflag1 = IsLongTable() && (row != endhead) &&
1776 (row != endfirsthead) &&
1777 ((row == endfoot) || (row == endlastfoot));
1779 if (IsLongTable() && (row == endhead)) {
1780 file += "\\endhead\n";
1783 if (IsLongTable() && (row == endfirsthead)) {
1784 file += "\\endfirsthead\n";
1787 if (sflag1) { // add the \hline for next foot row
1788 if (!hline1.empty()) {
1789 file += hline1 + '\n';
1793 // add the \hline for the first row
1794 if (pr_top_hline && sflag2) {
1795 if (!hline2.empty()) {
1796 file += hline2 + '\n';
1800 if (nvcell < numberofcells && RotateCell(nvcell)) {
1801 file += "\\begin{sideways}\n";
1806 addNewlineAndDepth(file,--depth);
1808 addNewlineAndDepth(file,depth);
1809 file += "<ENTRY ALIGN='";
1810 file += getDocBookAlign(cell+1);
1811 file += "' VALIGN='middle'";
1812 if (IsMultiColumn(cell+1)) {
1813 file += " NAMEST='col";
1814 file += column_of_cell(cell+1) + 1;
1815 file += "' NAMEEND='col";
1816 file += column_of_cell(cell+1) +
1817 cells_in_multicolumn(cell+1);
1821 addNewlineAndDepth(file,++depth);
1824 if (nvcell < numberofcells && RotateCell(nvcell)) {
1825 file += "\\begin{sideways}\n";
1832 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1833 file += "\\multicolumn{";
1834 file += cells_in_multicolumn(nvcell);
1836 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1837 file += cellinfo_of_cell(cell+1)->align_special;
1840 if (LeftLine(nvcell))
1842 if (!GetPWidth(nvcell).empty()) {
1844 file += GetPWidth(nvcell);
1847 switch (GetAlignment(nvcell)) {
1848 case LYX_ALIGN_LEFT: file += 'l'; break;
1849 case LYX_ALIGN_RIGHT: file += 'r'; break;
1850 default: file += 'c'; break;
1853 if (RightLine(nvcell))
1855 //if (column_of_cell(cell+2)!=0 && LeftLine(cell+2))
1856 if (((nvcell+1) < numberofcells) &&
1857 (NextVirtualCell(nvcell+1) < numberofcells) &&
1858 (column_of_cell(NextVirtualCell(nvcell+1))!=0) &&
1859 LeftLine(NextVirtualCell(nvcell+1)))
1864 if (nvcell < numberofcells && Linebreaks(nvcell)) {
1865 // !column_info[column_of_cell(nvcell)].p_width.empty()) {
1866 file += "\\parbox{";
1867 file += GetPWidth(nvcell);
1868 file += "}{\\smallskip{}";
1876 bool LyXTable::IsMultiColumn(int cell)
1878 int fvcell = FirstVirtualCell(cell);
1880 return (cellinfo_of_cell(fvcell)->multicolumn != LyXTable::CELL_NORMAL);
1884 LyXTable::cellstruct* LyXTable::cellinfo_of_cell(int cell)
1886 int row = row_of_cell(cell);
1887 int column = column_of_cell(cell);
1888 return &cell_info[row][column];
1892 void LyXTable::SetMultiColumn(int cell, int number)
1894 int fvcell = FirstVirtualCell(cell);
1895 int new_width = cellinfo_of_cell(fvcell)->width_of_cell;
1897 cellinfo_of_cell(fvcell)->multicolumn = LyXTable::CELL_BEGIN_OF_MULTICOLUMN;
1898 cellinfo_of_cell(fvcell)->alignment = column_info[column_of_cell(fvcell)].alignment;
1899 cellinfo_of_cell(fvcell)->top_line = row_info[row_of_cell(fvcell)].top_line;
1900 cellinfo_of_cell(fvcell)->bottom_line = row_info[row_of_cell(fvcell)].bottom_line;
1901 for (number--;number>0;number--){
1902 cellinfo_of_cell(fvcell+number)->multicolumn =
1903 LyXTable::CELL_PART_OF_MULTICOLUMN;
1904 new_width += cellinfo_of_cell(fvcell+number)->width_of_cell;
1906 set_row_column_number_info();
1907 SetWidthOfCell(fvcell,new_width);
1911 int LyXTable::cells_in_multicolumn(int cell)
1913 int row = row_of_cell(cell);
1914 int column = column_of_cell(cell);
1917 while (column < columns && cell_info[row][column].multicolumn
1918 == LyXTable::CELL_PART_OF_MULTICOLUMN){
1926 int LyXTable::UnsetMultiColumn(int cell)
1928 int fvcell = FirstVirtualCell(cell);
1929 int row = row_of_cell(fvcell);
1930 int column = column_of_cell(fvcell);
1934 if (cell_info[row][column].multicolumn
1935 == LyXTable::CELL_BEGIN_OF_MULTICOLUMN){
1936 cell_info[row][column].multicolumn = LyXTable::CELL_NORMAL;
1938 while (column < columns &&
1939 cell_info[row][column].multicolumn
1940 == LyXTable::CELL_PART_OF_MULTICOLUMN){
1941 cell_info[row][column].multicolumn =
1942 LyXTable::CELL_NORMAL;
1947 set_row_column_number_info();
1952 void LyXTable::delete_column(int column)
1955 columnstruct *column_info2 = new columnstruct[columns-1];
1957 for (i=0; i<column; i++){
1958 column_info2[i] = column_info[i];
1960 for (i=column; i<columns-1; i++){
1961 column_info2[i] = column_info[i+1];
1964 delete[] column_info;
1965 column_info = column_info2;
1967 for (i=0; i<rows;i++){
1968 cellstruct* tmp = cell_info[i];
1969 cell_info[i] = new cellstruct[columns-1];
1970 for (j=0; j<column; j++){
1971 cell_info[i][j]=tmp[j];
1973 for (j=column; j<columns-1; j++){
1974 cell_info[i][j]=tmp[j+1];
1983 void LyXTable::SetLongTable(int what)
1985 is_long_table = what;
1988 bool LyXTable::IsLongTable()
1990 return is_long_table;
1993 void LyXTable::SetRotateTable(int what)
1998 bool LyXTable::RotateTable()
2003 void LyXTable::SetRotateCell(int cell, int what)
2005 cellinfo_of_cell(cell)->rotate = what;
2008 bool LyXTable::RotateCell(int cell)
2010 return cellinfo_of_cell(cell)->rotate;
2013 bool LyXTable::NeedRotating()
2017 for (int i=0; i<rows;i++){
2018 for (int j=0;j<columns;j++){
2019 if (cell_info[i][j].rotate)
2026 void LyXTable::AppendContRow(int cell)
2028 int row = row_of_cell(cell)+1;
2030 if (!RowHasContRow(cell) || (CellHasContRow(cell)>=0))
2032 row_info[row].is_cont_row = true;
2033 row_info[row].top_line = false;
2034 cell_info[row-1][column_of_cell(cell)].has_cont_row = true;
2038 bool LyXTable::IsContRow(int cell)
2040 return row_info[row_of_cell(cell)].is_cont_row;
2043 int LyXTable::CellHasContRow(int cell)
2045 int row = row_of_cell(cell);
2047 if (VeryLastRow(cell))
2049 if (cell_info[row][column_of_cell(cell)].has_cont_row)
2050 return cell_info[row+1][column_of_cell(cell)].cellno;
2054 bool LyXTable::RowHasContRow(int cell)
2056 int row = row_of_cell(cell) + 1;
2059 return row_info[row].is_cont_row;
2063 int LyXTable::FirstVirtualCell(int cell)
2065 if (!IsContRow(cell))
2067 int row = row_of_cell(cell);
2068 int column = column_of_cell(cell);
2069 for(;(row>0) && IsContRow(cell_info[row][column].cellno); row--)
2071 return cell_info[row][column].cellno;
2075 int LyXTable::NextVirtualCell(int cell)
2077 if (!IsContRow(cell))
2079 int row = row_of_cell(cell);
2080 for(;(row < rows - 1) && IsContRow(cell_info[row][0].cellno); ++row)
2082 // what if(row >= rows) ?
2083 return cell_info[row][0].cellno;
2087 bool LyXTable::ShouldBeVeryLastCell(int cell)
2088 // "very last cell" ..of what? the row? the table?
2089 // "Cell" in this context appears to not count `virtual' cells
2091 int fcell = cell + 1;
2093 if (cell == GetNumberOfCells() - 1)
2094 return true; // not really sure if I should return false here
2095 if (!IsContRow(fcell))
2097 while((fcell < GetNumberOfCells() - 1) && IsContRow(fcell))
2099 if (fcell < GetNumberOfCells() - 1)
2104 bool LyXTable::ShouldBeVeryLastRow(int cell)
2106 if (CellHasContRow(cell)>=0)
2108 int row = row_of_cell(cell)+1;
2109 int column = column_of_cell(cell);
2110 while((row < rows) && IsContRow(cell_info[row][column].cellno))
2113 return false; // found another valid row
2114 // I do not have any valid row after the actual
2118 int LyXTable::GetCellAbove(int cell)
2120 int row = row_of_cell(cell);
2123 return cell_info[row-1][column_of_cell(cell)].cellno;
2127 int LyXTable::GetCellNumber(int column, int row)
2129 if (column >= columns)
2130 column = columns - 1;
2131 else if (column < 0)
2138 return cell_info[row][column].cellno;
2141 void LyXTable::SetLinebreaks(int cell, bool what)
2143 cellinfo_of_cell(FirstVirtualCell(cell))->linebreaks = what;
2146 bool LyXTable::Linebreaks(int cell)
2148 int fvcell = FirstVirtualCell(cell);
2150 if (column_info[column_of_cell(fvcell)].p_width.empty() &&
2151 !(IsMultiColumn(fvcell) && !cellinfo_of_cell(fvcell)->p_width.empty()))
2153 return cellinfo_of_cell(fvcell)->linebreaks;
2156 void LyXTable::SetLTHead(int cell, bool first)
2158 int row = row_of_cell(cell);
2161 if (row == endfirsthead)
2173 bool LyXTable::RowOfLTHead(int cell)
2175 if ((endhead+1) > rows)
2177 return (row_of_cell(cell) == endhead);
2180 bool LyXTable::RowOfLTFirstHead(int cell)
2182 if ((endfirsthead+1) > rows)
2184 return (row_of_cell(cell) == endfirsthead);
2187 void LyXTable::SetLTFoot(int cell, bool last)
2189 int row = row_of_cell(cell);
2192 if (row == endlastfoot)
2204 bool LyXTable::RowOfLTFoot(int cell)
2206 if ((endfoot+1) > rows) {
2210 return (row_of_cell(cell) == endfoot);
2213 bool LyXTable::RowOfLTLastFoot(int cell)
2215 if ((endlastfoot+1) > rows)
2217 return (row_of_cell(cell) == endlastfoot);
2220 void LyXTable::SetLTNewPage(int cell, bool what)
2222 row_info[row_of_cell(cell)].newpage = what;
2225 bool LyXTable::LTNewPage(int cell)
2227 return row_info[row_of_cell(cell)].newpage;