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 *======================================================
20 #pragma implementation
23 extern void addNewlineAndDepth(string &file, int const depth); // Jug 990923
25 #define WIDTH_OF_LINE 5
28 LyXTable::LyXTable(int rows_arg, int columns_arg)
30 Init(rows_arg, columns_arg);
34 LyXTable::LyXTable(LyXLex &lex)
36 FILE *file = lex.getFile();
41 LyXTable::~LyXTable() {
44 delete[] columnofcell;
47 for (i=0; i<rows; i++) {
48 delete[] cell_info[i]; // verify that this shoudn't be freed with delete
54 LyXTable* LyXTable::Clone()
56 LyXTable *result = new LyXTable(rows, columns);
59 for (row=0; row<rows; row++){
60 for (column=0; column<columns;column++){
61 result->cell_info[row][column] = cell_info[row][column];
65 for (row=0; row<rows; row++){
66 result->row_info[row] = row_info[row];
69 for (column=0; column<columns; column++){
70 result->column_info[column].left_line = column_info[column].left_line;
71 result->column_info[column].right_line = column_info[column].right_line;
72 result->column_info[column].alignment = column_info[column].alignment;
73 result->column_info[column].p_width = column_info[column].p_width;
74 result->column_info[column].align_special = column_info[column].align_special;
77 result->SetLongTable(is_long_table);
78 result->rotate=rotate;
84 /* activates all lines and sets all widths to 0 */
85 void LyXTable::Init(int rows_arg, int columns_arg)
89 columns = columns_arg;
90 column_info = new columnstruct[columns];
91 row_info = new rowstruct[rows];
92 cell_info = new cellstruct*[rows];
95 for (i=0; i<rows;i++) {
96 cell_info[i] = new cellstruct[columns];
97 row_info[i].top_line = true;
98 row_info[i].bottom_line = false;
99 row_info[i].is_cont_row = false;
100 row_info[i].newpage = false;
101 for (j=0; j<columns; j++) {
102 cell_info[i][j].cellno = cellno++;
103 cell_info[i][j].width_of_cell = 0;
104 cell_info[i][j].multicolumn = LyXTable::CELL_NORMAL;
105 cell_info[i][j].alignment = LYX_ALIGN_CENTER;
106 cell_info[i][j].top_line = row_info[i].top_line;
107 cell_info[i][j].bottom_line = row_info[i].bottom_line;
108 cell_info[i][j].has_cont_row = false;
109 cell_info[i][j].rotate = false;
110 cell_info[i][j].linebreaks = false;
113 row_info[i-1].bottom_line = true;
114 row_info[0].bottom_line = true;
116 for (i=0; i<columns;i++) {
117 column_info[i].left_line = true;
118 column_info[i].right_line = false;
119 column_info[i].alignment = LYX_ALIGN_CENTER;
120 // set width_of_column to zero before it is used in
121 // calculate_width_of_column() (thornley)
122 column_info[i].width_of_column = 0;
123 calculate_width_of_column(i);
125 column_info[i-1].right_line = true;
127 calculate_width_of_table();
131 set_row_column_number_info();
132 is_long_table = false;
141 void LyXTable::AppendRow(int cell)
143 int row = row_of_cell(cell);
144 rowstruct *row_info2 = new rowstruct[rows+1];
145 cellstruct** cell_info2 = new cellstruct*[rows+1];
148 for (i=0; i <= row; i++) {
149 cell_info2[i] = cell_info[i];
150 row_info2[i] = row_info[i];
152 for (i=rows-1; i >= row; i--) {
153 cell_info2[i+1] = cell_info[i];
154 row_info2[i+1] = row_info[i];
156 for (i=row;row_info[i].is_cont_row;i--);
157 if (((row+1)>=rows) || !row_info[row+1].is_cont_row)
158 row_info2[row+1].is_cont_row = false;
159 row_info2[row+1].top_line = row_info[i].top_line;
160 cell_info2[row+1] = new cellstruct[columns];
161 for (i=0; i<columns; i++) {
162 cell_info2[row+1][i].width_of_cell = 0;
163 cell_info2[row+1][i] = cell_info2[row][i];
167 cell_info = cell_info2;
169 row_info = row_info2;
177 void LyXTable::DeleteRow(int cell)
179 int row = row_of_cell(cell);
180 while(!row_info[row].is_cont_row && RowHasContRow(cell))
181 DeleteRow(cell_info[row+1][0].cellno);
182 rowstruct *row_info2 = new rowstruct[rows-1];
183 cellstruct** cell_info2 = new cellstruct*[rows-1];
186 delete[] cell_info[row];
187 for (i=0; i < row; i++) {
188 cell_info2[i] = cell_info[i];
189 row_info2[i] = row_info[i];
191 if (row_info[i].is_cont_row)
192 row_info2[i-1].bottom_line = row_info[i].bottom_line;
193 for (i=row; i < rows - 1; i++) {
194 cell_info2[i] = cell_info[i+1];
195 row_info2[i] = row_info[i+1];
200 cell_info = cell_info2;
202 row_info = row_info2;
210 void LyXTable::AppendColumn(int cell)
213 columnstruct *column_info2 = new columnstruct[columns+1];
214 int column = right_column_of_cell(cell);
216 for (i=0; i<=column; i++){
217 column_info2[i] = column_info[i];
219 for (i=columns-1; i>=column; i--){
220 column_info2[i+1] = column_info[i];
223 delete[] column_info;
224 column_info = column_info2;
226 for (i=0; i<rows;i++){
227 cellstruct* tmp = cell_info[i];
228 cell_info[i] = new cellstruct[columns+1];
229 for (j=0; j<=column; j++){
230 cell_info[i][j]=tmp[j];
232 for (j=column; j<columns; j++){
233 cell_info[i][j+1]=tmp[j];
235 // care about multicolumns
236 if (cell_info[i][column+1].multicolumn
237 ==LyXTable::CELL_BEGIN_OF_MULTICOLUMN){
238 cell_info[i][column+1].multicolumn =
239 LyXTable::CELL_PART_OF_MULTICOLUMN;
241 if (column + 1 == columns
242 || cell_info[i][column+2].multicolumn
243 !=LyXTable::CELL_PART_OF_MULTICOLUMN){
244 cell_info[i][column+1].multicolumn =
245 LyXTable::CELL_NORMAL;
256 void LyXTable::Reinit()
260 for (i=0; i<rows;i++) {
261 for (j=0; j<columns; j++) {
262 cell_info[i][j].width_of_cell = 0;
263 if ((i+1 < rows) && !row_info[i+1].is_cont_row)
264 cell_info[i][j].has_cont_row = false;
268 for (i=0; i<columns;i++) {
269 calculate_width_of_column(i);
271 calculate_width_of_table();
273 set_row_column_number_info();
277 void LyXTable::set_row_column_number_info()
283 for (row=0; row<rows; ++row) {
284 for (column=0; column<columns; ++column) {
285 if (cell_info[row][column].multicolumn
286 != LyXTable::CELL_PART_OF_MULTICOLUMN)
288 cell_info[row][column].cellno = numberofcells;
291 ++numberofcells; // because this is one more than as we start from 0
297 rowofcell = new int[numberofcells];
299 delete [] columnofcell;
300 columnofcell = new int[numberofcells];
302 while (c < numberofcells && row < rows && column < columns) {
304 columnofcell[c]=column;
308 } while (column < columns &&
309 cell_info[row][column].multicolumn
310 == LyXTable::CELL_PART_OF_MULTICOLUMN);
311 if (column == columns){
319 void LyXTable::DeleteColumn(int cell)
321 int column1 = column_of_cell(cell);
322 int column2 = right_column_of_cell(cell);
325 if (column1 == 0 && column2 == columns - 1)
328 for (column = column1; column <= column2;column++){
329 delete_column(column1);
335 int LyXTable::GetNumberOfCells()
337 return numberofcells;
341 int LyXTable::NumberOfCellsInRow(int cell)
343 int row = row_of_cell(cell);
346 for (i=0; i<columns; i++){
347 if (cell_info[row][i].multicolumn != LyXTable::CELL_PART_OF_MULTICOLUMN)
354 int LyXTable::AppendCellAfterCell(int append_cell, int question_cell)
356 return (right_column_of_cell(append_cell) ==
357 right_column_of_cell(question_cell));
361 int LyXTable::DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell)
363 if (column_of_cell(delete_column_cell) == 0 &&
364 right_column_of_cell(delete_column_cell) == columns - 1)
368 (column_of_cell(cell) >= column_of_cell(delete_column_cell) &&
369 column_of_cell(cell) <= right_column_of_cell(delete_column_cell));
373 /* returns 1 if there is a topline, returns 0 if not */
374 bool LyXTable::TopLine(int cell)
376 int row=row_of_cell(cell);
379 return TopLine(cell_info[row-1][column_of_cell(cell)].cellno);
380 if (IsMultiColumn(cell))
381 return cellinfo_of_cell(cell)->top_line;
382 return row_info[row].top_line;
386 bool LyXTable::BottomLine(int cell)
388 //no bottom line underneath non-existent cells if you please
389 if(cell >= numberofcells)
392 int row=row_of_cell(cell);
394 if (RowHasContRow(cell))
395 return BottomLine(cell_info[row+1][column_of_cell(cell)].cellno);
396 if (IsMultiColumn(cell))
397 return cellinfo_of_cell(cell)->bottom_line;
398 return row_info[row_of_cell(cell)].bottom_line;
402 bool LyXTable::LeftLine(int cell)
404 return column_info[column_of_cell(cell)].left_line;
407 bool LyXTable::RightLine(int cell)
409 return column_info[right_column_of_cell(cell)].right_line;
413 bool LyXTable::TopAlreadyDrawed(int cell)
415 if (AdditionalHeight(cell))
417 int row = row_of_cell(cell);
419 int column = column_of_cell(cell);
421 && cell_info[row-1][column].multicolumn
422 == LyXTable::CELL_PART_OF_MULTICOLUMN)
424 if (cell_info[row-1][column].multicolumn
425 == LyXTable::CELL_NORMAL)
426 return row_info[row-1].bottom_line;
428 return cell_info[row-1][column].bottom_line;
434 bool LyXTable::VeryLastRow(int cell)
436 return (row_of_cell(cell) == rows-1);
440 int LyXTable::AdditionalHeight(int cell)
442 int row = row_of_cell(cell);
447 for (column=0;column < columns-1 && bottom;column++){
448 switch (cell_info[row-1][column].multicolumn){
449 case LyXTable::CELL_BEGIN_OF_MULTICOLUMN:
450 bottom = cell_info[row-1][column].bottom_line;
452 case LyXTable::CELL_NORMAL:
453 bottom = row_info[row-1].bottom_line;
456 for (column=0;column < columns-1 && top;column++){
457 switch (cell_info[row][column].multicolumn){
458 case LyXTable::CELL_BEGIN_OF_MULTICOLUMN:
459 top = cell_info[row][column].top_line;
461 case LyXTable::CELL_NORMAL:
462 top = row_info[row].top_line;
466 return WIDTH_OF_LINE;
472 int LyXTable::AdditionalWidth(int cell)
474 // internally already set in SetWidthOfCell
475 // used to get it back in text.C
476 int col = right_column_of_cell(cell);
477 if (col < columns - 1 && column_info[col].right_line &&
478 column_info[col+1].left_line)
479 return WIDTH_OF_LINE;
485 // returns the maximum over all rows
486 int LyXTable::WidthOfColumn(int cell)
488 int column1 = column_of_cell(cell);
489 int column2 = right_column_of_cell(cell);
492 for (i=column1; i<=column2;i++){
493 result += column_info[i].width_of_column;
499 int LyXTable::WidthOfTable()
501 return width_of_table;
504 /* returns 1 if a complete update is necessary, otherwise 0 */
505 bool LyXTable::SetWidthOfMulticolCell(int cell, int new_width)
507 if (!IsMultiColumn(cell))
510 int row = row_of_cell(cell);
511 int column1 = column_of_cell(cell);
512 int column2 = right_column_of_cell(cell);
516 // first set columns to 0 so we can calculate the right width
517 for (i=column1; i<=column2;i++) {
518 cell_info[row][i].width_of_cell = 0;
520 // set the width to MAX_WIDTH until width > 0
521 width = (new_width + 2*WIDTH_OF_LINE);
522 for (i=column1; (i<column2) && (width > 0);i++){
523 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
524 width -= column_info[i].width_of_column;
527 cell_info[row][i].width_of_cell = width;
532 void LyXTable::recalculateMulticolCells(int cell, int new_width)
535 row = row_of_cell(cell),
536 column1 = column_of_cell(cell),
537 column2 = right_column_of_cell(cell),
540 // first set columns to 0 so we can calculate the right width
541 for (i=column1; i<=column2;++i)
542 cell_info[row][i].width_of_cell = 0;
543 for(i=cell+1;(i<numberofcells) && (!IsMultiColumn(i));++i)
545 if (i < numberofcells)
546 recalculateMulticolCells(i,GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
547 SetWidthOfMulticolCell(cell,new_width);
550 /* returns 1 if a complete update is necessary, otherwise 0 */
551 bool LyXTable::SetWidthOfCell(int cell, int new_width)
553 int row = row_of_cell(cell);
554 int column1 = column_of_cell(cell);
558 if (IsMultiColumn(cell)) {
559 tmp = SetWidthOfMulticolCell(cell, new_width);
561 width = (new_width + 2*WIDTH_OF_LINE);
562 cell_info[row][column1].width_of_cell = width;
563 if (column_info[column1].right_line && (column1 < columns-1) &&
564 column_info[column1+1].left_line) // additional width
565 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
566 tmp = calculate_width_of_column_NMC(column1);
570 for(i=0; i<columns;++i)
571 calculate_width_of_column_NMC(i);
572 for(i=0; (i<numberofcells) && !IsMultiColumn(i); ++i)
575 recalculateMulticolCells(i,GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
576 for(i=0; i<columns;++i)
577 calculate_width_of_column(i);
578 calculate_width_of_table();
585 bool LyXTable::SetAlignment(int cell, char align)
587 if (!IsMultiColumn(cell))
588 column_info[column_of_cell(cell)].alignment = align;
589 cellinfo_of_cell(cell)->alignment = align;
593 bool LyXTable::SetPWidth(int cell, string width)
595 int fvcell = FirstVirtualCell(cell);
597 if (IsMultiColumn(fvcell)) {
598 // if (column_info[column_of_cell(cell)].p_width.empty())
599 // column_info[column_of_cell(cell)].p_width = width;
600 cellinfo_of_cell(fvcell)->p_width = width;
602 column_info[column_of_cell(fvcell)].p_width = width;
603 SetAlignment(cell,LYX_ALIGN_LEFT);
608 bool LyXTable::SetAlignSpecial(int cell, string special, int what)
610 if (what == SET_SPECIAL_MULTI)
611 cellinfo_of_cell(cell)->align_special = special;
613 column_info[column_of_cell(cell)].align_special = special;
617 bool LyXTable::SetAllLines(int cell, bool line)
619 SetTopLine(cell,line);
620 SetBottomLine(cell,line);
621 SetRightLine(cell,line);
622 SetLeftLine(cell,line);
626 bool LyXTable::SetTopLine(int cell, bool line)
628 int row = row_of_cell(cell);
631 SetTopLine(cell_info[row-1][column_of_cell(cell)].cellno,line);
632 else if (!IsMultiColumn(cell))
633 row_info[row].top_line = line;
635 cellinfo_of_cell(cell)->top_line = line;
640 bool LyXTable::SetBottomLine(int cell, bool line)
642 int row = row_of_cell(cell);
644 if (RowHasContRow(cell))
645 SetBottomLine(cell_info[row+1][column_of_cell(cell)].cellno,line);
646 else if (!IsMultiColumn(cell))
647 row_info[row_of_cell(cell)].bottom_line = line;
649 cellinfo_of_cell(cell)->bottom_line = line;
654 bool LyXTable::SetLeftLine(int cell, bool line)
656 column_info[column_of_cell(cell)].left_line = line;
661 bool LyXTable::SetRightLine(int cell, bool line)
663 column_info[right_column_of_cell(cell)].right_line = line;
668 char LyXTable::GetAlignment(int cell)
670 if (IsMultiColumn(cell))
671 return cellinfo_of_cell(cell)->alignment;
673 return column_info[column_of_cell(cell)].alignment;
676 string LyXTable::GetPWidth(int cell)
678 int fvcell = FirstVirtualCell(cell);
680 if (IsMultiColumn(fvcell)) // && !cellinfo_of_cell(cell)->p_width.empty())
681 return cellinfo_of_cell(fvcell)->p_width;
682 return column_info[column_of_cell(fvcell)].p_width;
685 string LyXTable::GetAlignSpecial(int cell, int what)
687 if (what == SET_SPECIAL_MULTI)
688 return cellinfo_of_cell(cell)->align_special;
689 return column_info[column_of_cell(cell)].align_special;
692 int LyXTable::GetWidthOfCell(int cell)
694 int row = row_of_cell(cell);
695 int column1 = column_of_cell(cell);
696 int column2 = right_column_of_cell(cell);
699 for (i=column1; i<=column2;i++){
700 result += cell_info[row][i].width_of_cell;
703 result += AdditionalWidth(cell);
709 int LyXTable::GetBeginningOfTextInCell(int cell)
713 switch (GetAlignment(cell)){
714 case LYX_ALIGN_CENTER:
715 x += (WidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
717 case LYX_ALIGN_RIGHT:
718 x += WidthOfColumn(cell) - GetWidthOfCell(cell) + AdditionalWidth(cell);
720 default: /* LYX_ALIGN_LEFT: nothing :-) */
730 bool LyXTable::IsFirstCell(int cell)
732 return (column_of_cell(cell) == 0);
735 bool LyXTable::IsLastCell(int cell)
737 return (right_column_of_cell(cell) == (columns-1));
741 bool LyXTable::calculate_width_of_column(int column)
744 int old_column_width = column_info[column].width_of_column;
746 for (i=0; i<rows; i++) {
747 if (cell_info[i][column].width_of_cell > max) {
748 max = cell_info[i][column].width_of_cell;
751 column_info[column].width_of_column = max;
752 return (column_info[column].width_of_column != old_column_width);
755 bool LyXTable::calculate_width_of_column_NMC(int column)
758 int old_column_width = column_info[column].width_of_column;
760 for (i=0; i<rows; ++i) {
761 if (!IsMultiColumn(GetCellNumber(column,i)) &&
762 (cell_info[i][column].width_of_cell > max)) {
763 max = cell_info[i][column].width_of_cell;
766 column_info[column].width_of_column = max;
767 return (column_info[column].width_of_column != old_column_width);
770 void LyXTable::calculate_width_of_table()
774 for (i=0; i<columns;i++) {
775 width_of_table += column_info[i].width_of_column;
780 int LyXTable::row_of_cell(int cell)
782 if (cell >= numberofcells)
786 return rowofcell[cell];
790 int LyXTable::column_of_cell(int cell)
792 if (cell >= numberofcells)
796 return columnofcell[cell];
800 int LyXTable::right_column_of_cell(int cell)
802 int row = row_of_cell(cell);
803 int column = column_of_cell(cell);
804 while (column < columns - 1 &&
805 cell_info[row][column+1].multicolumn == LyXTable::CELL_PART_OF_MULTICOLUMN)
811 void LyXTable::Write(FILE* file)
814 fprintf(file, "multicol5\n");
815 fprintf(file, "%d %d %d %d %d %d %d %d\n", rows, columns, is_long_table,
816 rotate, endhead, endfirsthead, endfoot, endlastfoot);
817 for (i=0; i<rows; i++){
818 fprintf(file, "%d %d %d %d\n", row_info[i].top_line,
819 row_info[i].bottom_line, row_info[i].is_cont_row,
820 row_info[i].newpage);
822 for (i=0; i<columns; i++){
823 fprintf(file, "%d %d %d \"%s\" \"%s\"\n",
824 column_info[i].alignment, column_info[i].left_line,
825 column_info[i].right_line,
826 VSpace(column_info[i].p_width).asLyXCommand().c_str(),
827 column_info[i].align_special.c_str());
830 for (i=0; i<rows;i++){
831 for (j=0;j<columns;j++){
832 fprintf(file, "%d %d %d %d %d %d %d \"%s\" \"%s\"\n",
833 cell_info[i][j].multicolumn,
834 cell_info[i][j].alignment,
835 cell_info[i][j].top_line,
836 cell_info[i][j].bottom_line,
837 cell_info[i][j].has_cont_row,
838 cell_info[i][j].rotate,
839 cell_info[i][j].linebreaks,
840 cell_info[i][j].align_special.c_str(),
841 cell_info[i][j].p_width.c_str());
847 #warning Clean up this code in 0.13 (Jug)
849 void LyXTable::Read(FILE* file)
855 int is_long_table_arg = false;
856 int rotate_arg = false;
866 char vtmp[100], stmp[100], atmp[100];
868 fscanf(file, "%s\n", vtmp);
871 version = atoi(s.c_str()+8);
876 fgets(vtmp,sizeof(vtmp),file);
877 sscanf(vtmp, "%d %d %d %d %d %d %d %d\n", &rows_arg, &columns_arg,
878 &is_long_table_arg, &rotate_arg, &a, &b, &c, &d);
880 fscanf(file, "%d %d\n",
881 &rows_arg, &columns_arg);
882 Init(rows_arg, columns_arg);
883 SetLongTable(is_long_table_arg);
884 SetRotateTable(rotate_arg);
889 for (i=0; i<rows; i++){
891 fgets(vtmp,sizeof(vtmp),file);
892 sscanf(vtmp, "%d %d %d %d\n",
894 row_info[i].top_line = a;
895 row_info[i].bottom_line = b;
896 row_info[i].is_cont_row = c;
897 row_info[i].newpage = d;
899 for (i=0; i<columns; i++){
902 fgets(vtmp,sizeof(vtmp),file);
903 sscanf(vtmp, "%d %d %d %s %s", &a, &b, &c, stmp, atmp);
904 column_info[i].alignment = (char) a;
905 column_info[i].left_line = b;
906 column_info[i].right_line = c;
907 if (*stmp == '"') { /* strip quotes if they exists */
910 // there are quotes so I have to reread the string correctly
911 // this is only because the old format did not have "
912 // this means also that atmp is ONLY set here!!!
914 sscanf(vtmp, "%*d %*d %*d %*s \"%[^\"]\"", atmp);
915 else // otherwise after the first empty "" read is aborded
916 sscanf(vtmp, "%*d %*d %*d \"%[^\"]\" \"%[^\"]\"", stmp, atmp);
917 column_info[i].p_width = stmp;
918 column_info[i].align_special = atmp;
920 column_info[i].p_width = stmp;
923 for (i=0; i<rows;i++){
924 for (j=0;j<columns;j++){
925 fscanf(file, "%d %d\n", &a, &b);
926 cell_info[i][j].multicolumn = (char) a;
927 cell_info[i][j].alignment = (char) b;
930 } else if (version < 4) {
931 for (i=0; i<rows;i++){
932 for (j=0;j<columns;j++){
933 fscanf(file, "%d %d %d %d\n", &a, &b, &c, &d);
934 cell_info[i][j].multicolumn = (char) a;
935 cell_info[i][j].alignment = (char) b;
936 cell_info[i][j].top_line = (char) c;
937 cell_info[i][j].bottom_line = (char) d;
941 for (i=0; i<rows;i++){
942 for (j=0;j<columns;j++){
946 fgets(vtmp,sizeof(vtmp),file);
947 sscanf(vtmp, "%d %d %d %d %d %d %d %s %s\n",
948 &a, &b, &c, &d, &e, &f, &g, stmp, atmp);
949 cell_info[i][j].multicolumn = (char) a;
950 cell_info[i][j].alignment = (char) b;
951 cell_info[i][j].top_line = (char) c;
952 cell_info[i][j].bottom_line = (char) d;
953 cell_info[i][j].has_cont_row = (bool) e;
954 cell_info[i][j].rotate = (bool) f;
955 cell_info[i][j].linebreaks = (bool) g;
956 // this is only to see if I have an empty string first
957 // this clause should be always TRUE!!!
962 sscanf(vtmp,"%*d %*d %*d %*d %*d %*d %*d %*s \"%[^\"]\"",
964 else // otherwise after the first empty "" read is aborded
965 sscanf(vtmp,"%*d %*d %*d %*d %*d %*d %*d \"%[^\"]\" \"%[^\"]\"",
967 cell_info[i][j].align_special = stmp;
968 cell_info[i][j].p_width = atmp;
970 cell_info[i][j].align_special = stmp;
974 set_row_column_number_info();
978 // cell <0 will tex the preamble
979 // returns the number of printed newlines
980 int LyXTable::TexEndOfCell(string& file, int cell)
986 if (ShouldBeVeryLastCell(cell)) {
987 // the very end at the very beginning
988 if (Linebreaks(cell))
989 file += "\\smallskip{}}";
990 if (IsMultiColumn(cell))
992 if (RotateCell(cell)) {
993 file += "\n\\end{sideways}";
1001 while (!IsFirstCell(fcell))fcell--;
1002 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1003 if (BottomLine(fcell+i))
1006 if (tmp == NumberOfCellsInRow(fcell)){
1010 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1011 if (BottomLine(fcell+i)){
1013 file += column_of_cell(fcell+i)+1;
1015 file += right_column_of_cell(fcell+i)+1;
1026 file += "\\end{longtable}";
1028 file += "\\end{tabular}";
1030 file += "\n\\end{sideways}";
1034 nvcell = NextVirtualCell(cell+1);
1038 file += "\\begin{sideways}\n";
1042 file += "\\begin{longtable}{";
1044 file += "\\begin{tabular}{";
1045 for (i=0; i<columns;i++){
1046 if (column_info[i].left_line)
1048 if (!column_info[i].align_special.empty()) {
1049 file += column_info[i].align_special.c_str();
1050 } else if (!column_info[i].p_width.empty()) {
1052 file += column_info[i].p_width;
1055 switch (column_info[i].alignment) {
1056 case LYX_ALIGN_LEFT:
1059 case LYX_ALIGN_RIGHT:
1067 if (column_info[i].right_line)
1073 if (GetNumberOfCells()){
1075 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1076 if (TopLine(fcell+i))
1079 if (tmp == NumberOfCellsInRow(fcell)){
1083 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1084 if (TopLine(fcell+i)){
1086 file += column_of_cell(fcell+i)+1;
1088 file += right_column_of_cell(fcell+i)+1;
1099 if (RotateCell(0)) {
1100 file += "\\begin{sideways}\n";
1105 if (Linebreaks(cell))
1106 file += "\\smallskip{}}";
1107 if (IsMultiColumn(cell)){
1110 if (RotateCell(cell)) {
1111 file += "\n\\end{sideways}";
1114 if (IsLastCell(cell)) {
1115 int row = row_of_cell(cell);
1116 string hline1,hline2;
1117 bool print_hline = true;
1118 bool pr_top_hline,flag1,flag2;
1119 flag1 = IsLongTable() &&
1120 ((row == endhead) || (row == endfirsthead) ||
1121 (row == endfoot) || (row == endlastfoot));
1123 flag2 = IsLongTable() &&
1124 ((row <= endhead) || (row <= endfirsthead) ||
1125 (row <= endfoot) || (row <= endlastfoot));
1127 // print the bottom hline only if (otherwise it is doubled):
1128 // - is no LongTable
1129 // - there IS a first-header
1130 // - the next row is no special header/footer
1131 // & this row is no special header/footer
1132 // - the next row is a special header/footer
1133 // & this row is a special header/footer
1134 pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1135 (endfirsthead == endhead);
1140 while (!IsFirstCell(fcell))
1142 for (i=0; i < NumberOfCellsInRow(cell); i++){
1143 if (BottomLine(fcell+i))
1146 if (tmp == NumberOfCellsInRow(cell)){
1148 hline1 = "\\hline ";
1151 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1152 if (BottomLine(fcell+i)){
1154 file += column_of_cell(fcell+i)+1;
1156 file += right_column_of_cell(fcell+i)+1;
1158 hline1 += "\\cline{";
1159 hline1 += column_of_cell(fcell+i)+1;
1161 hline1 += right_column_of_cell(fcell+i)+1;
1171 if (IsLongTable() && (row == endfoot)) {
1172 file += "\\endfoot\n";
1174 print_hline = false; // no double line below footer
1176 if (IsLongTable() && (row == endlastfoot)) {
1177 file += "\\endlastfoot\n";
1179 print_hline = false; // no double line below footer
1181 if (IsLongTable() && row_info[row].newpage) {
1182 file += "\\newpage\n";
1184 print_hline = false; // no line below a \\newpage-command
1187 if (nvcell < numberofcells && (cell < GetNumberOfCells()-1) &&
1188 !ShouldBeVeryLastCell(cell)) {
1191 // Now jump all ContRows
1192 while (IsContRow(fcell))
1194 while (!IsFirstCell(fcell))
1197 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1198 if (TopLine(fcell+i))
1201 if (tmp == NumberOfCellsInRow(fcell)){
1204 hline2 = "\\hline ";
1208 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1209 if (TopLine(fcell+i)){
1212 file += column_of_cell(fcell+i)+1;
1214 file += right_column_of_cell(fcell+i)+1;
1217 hline2 += "\\cline{";
1218 hline2 += column_of_cell(fcell+i)+1;
1220 hline2 += right_column_of_cell(fcell+i)+1;
1226 if (tmp && print_hline){
1231 // the order here is important as if one defines two
1232 // or more things in one line only the first entry is
1233 // displayed the other are set to an empty-row. This
1234 // is important if I have a footer and want that the
1235 // lastfooter is NOT displayed!!!
1236 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1237 (row == endfoot) || (row == endlastfoot);
1239 // sflag2 = IsLongTable() && (row >= 0) &&
1240 // (sflag2 || (row == endhead) || (row == endfirsthead));
1242 bool sflag1 = IsLongTable() && (row != endhead) &&
1243 (row != endfirsthead) &&
1244 ((row == endfoot) || (row == endlastfoot));
1246 if (IsLongTable() && (row == endhead)) {
1247 file += "\\endhead\n";
1250 if (IsLongTable() && (row == endfirsthead)) {
1251 file += "\\endfirsthead\n";
1254 if (sflag1) { // add the \hline for next foot row
1255 if (!hline1.empty()) {
1256 file += hline1 + '\n';
1260 // add the \hline for the first row
1261 if (pr_top_hline && sflag2) {
1262 if (!hline2.empty()) {
1263 file += hline2 + '\n';
1267 if (nvcell < numberofcells && RotateCell(nvcell)) {
1268 file += "\\begin{sideways}\n";
1274 if (nvcell < numberofcells && RotateCell(nvcell)) {
1275 file += "\\begin{sideways}\n";
1280 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1281 file += "\\multicolumn{";
1282 file += cells_in_multicolumn(nvcell);
1284 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1285 file += cellinfo_of_cell(cell+1)->align_special;
1288 if (LeftLine(nvcell))
1290 if (!GetPWidth(nvcell).empty()) {
1292 file += GetPWidth(nvcell);
1295 switch (GetAlignment(nvcell)) {
1296 case LYX_ALIGN_LEFT: file += 'l'; break;
1297 case LYX_ALIGN_RIGHT: file += 'r'; break;
1298 default: file += 'c'; break;
1301 if (RightLine(nvcell))
1303 //if (column_of_cell(cell+2)!=0 && LeftLine(cell+2))
1304 if (((nvcell+1) < numberofcells) &&
1305 (NextVirtualCell(nvcell+1) < numberofcells) &&
1306 (column_of_cell(NextVirtualCell(nvcell+1))!=0) &&
1307 LeftLine(NextVirtualCell(nvcell+1)))
1312 if (nvcell < numberofcells && Linebreaks(nvcell)) {
1313 // !column_info[column_of_cell(nvcell)].p_width.empty()) {
1314 file += "\\parbox{";
1315 file += GetPWidth(nvcell);
1316 file += "}{\\smallskip{}";
1323 // cell <0 will tex the preamble
1324 // returns the number of printed newlines
1325 int LyXTable::RoffEndOfCell(FILE* file, int cell)
1330 if (cell == GetNumberOfCells() - 1){
1331 // the very end at the very beginning
1332 if (CellHasContRow(cell) >= 0) {
1333 fprintf(file,"\nT}");
1336 fprintf(file, "\n");
1338 if (row_info[row_of_cell(cell)].bottom_line) {
1339 fprintf(file, "_\n");
1342 fprintf(file, ".TE\n.pl 1c");
1347 fprintf(file, "\n.pl 500c\n.TS\n");
1348 for (j=0; j<rows; j++) {
1349 for (i=0; i<columns;i++,fcell++) {
1350 if (column_info[i].left_line)
1351 fprintf(file, " | ");
1352 if (cell_info[j][i].multicolumn==CELL_PART_OF_MULTICOLUMN)
1355 switch (column_info[i].alignment) {
1356 case LYX_ALIGN_LEFT:
1359 case LYX_ALIGN_RIGHT:
1367 if (!column_info[i].p_width.empty())
1368 fprintf(file, "w(%s)", column_info[i].p_width.c_str());
1369 if (column_info[i].right_line)
1370 fprintf(file, " | ");
1373 fprintf(file, "\n");
1377 fprintf(file, ".\n");
1379 if (row_info[0].top_line) {
1380 fprintf(file,"_\n");
1383 if (CellHasContRow(0) >= 0) {
1384 fprintf(file,"T{\n");
1389 if (CellHasContRow(cell) >= 0) {
1390 fprintf(file,"\nT}");
1393 if (right_column_of_cell(cell) == columns -1){
1394 fprintf(file, "\n");
1396 int row = row_of_cell(cell);
1397 if (row_info[row++].bottom_line) {
1398 fprintf(file, "_\n");
1401 if ((row < rows) && row_info[row].top_line) {
1402 fprintf(file, "_\n");
1406 fprintf(file, "\t");
1407 if ((cell < GetNumberOfCells() - 1) &&
1408 (CellHasContRow(cell+1) >= 0)) {
1409 fprintf(file,"T{\n");
1417 const char *LyXTable::getDocBookAlign(int cell, bool isColumn)
1423 i = column_of_cell(cell);
1424 if (!isColumn && IsMultiColumn(cell)) {
1425 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1426 return cellinfo_of_cell(cell)->align_special.c_str();
1428 switch (GetAlignment(cell)) {
1429 case LYX_ALIGN_LEFT:
1431 case LYX_ALIGN_RIGHT:
1438 if (!column_info[i].align_special.empty()) {
1439 return column_info[i].align_special.c_str();
1441 #ifdef IGNORE_THIS_FOR_NOW
1442 else if (!column_info[i].p_width.empty()) {
1444 file += column_info[i].p_width;
1449 switch (column_info[i].alignment) {
1450 case LYX_ALIGN_LEFT:
1452 case LYX_ALIGN_RIGHT:
1461 // cell <0 will tex the preamble
1462 // returns the number of printed newlines
1463 int LyXTable::DocBookEndOfCell(string& file, int cell, int &depth)
1467 //int tmp; // tmp2; //Â unused
1468 int nvcell; // fcell; //Â unused
1469 if (ShouldBeVeryLastCell(cell)) {
1471 // the very end at the very beginning
1472 if (Linebreaks(cell))
1473 file += "\\smallskip{}}";
1474 if (IsMultiColumn(cell))
1476 if (RotateCell(cell)) {
1477 file += "\n\\end{sideways}";
1485 while (!IsFirstCell(fcell))fcell--;
1486 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1487 if (BottomLine(fcell+i))
1490 if (tmp == NumberOfCellsInRow(fcell)){
1494 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1495 if (BottomLine(fcell+i)){
1497 file += column_of_cell(fcell+i)+1;
1499 file += right_column_of_cell(fcell+i)+1;
1510 addNewlineAndDepth(file,--depth);
1512 addNewlineAndDepth(file,--depth);
1514 addNewlineAndDepth(file,--depth);
1516 addNewlineAndDepth(file,--depth);
1518 file += "</TGROUP>";
1520 file += "</TGROUP>";
1521 addNewlineAndDepth(file,--depth);
1524 file += "\n\\end{sideways}";
1530 nvcell = NextVirtualCell(cell+1);
1539 file += "' COLSEP='1' ROWSEP='1'>";
1540 addNewlineAndDepth(file,++depth);
1542 for (i=0; i<columns;i++) {
1543 file += "<COLSPEC ALIGN='";
1544 file += getDocBookAlign(i, true);
1545 file += "' COLNAME='col";
1547 file += "' COLNUM='";
1549 file += "' COLSEP='";
1550 if (i == (columns-1)) {
1553 if (column_info[i].right_line ||
1554 column_info[i+1].left_line)
1560 addNewlineAndDepth(file,depth);
1562 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1563 if (column_info[i].left_line)
1569 if (GetNumberOfCells()) {
1571 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1572 if (TopLine(fcell+i))
1575 if (tmp == NumberOfCellsInRow(fcell)){
1579 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1580 if (TopLine(fcell+i)){
1582 file += column_of_cell(fcell+i)+1;
1584 file += right_column_of_cell(fcell+i)+1;
1595 if (RotateCell(0)) {
1596 file += "\\begin{sideways}\n";
1601 addNewlineAndDepth(file,++depth);
1603 addNewlineAndDepth(file,++depth);
1604 file += "<ENTRY ALIGN='";
1605 file += getDocBookAlign(0);
1607 if (IsMultiColumn(0)) {
1608 file += " NAMEST='col1' NAMEEND='col";
1609 file += cells_in_multicolumn(0);
1613 addNewlineAndDepth(file,++depth);
1618 if (Linebreaks(cell))
1619 file += "\\smallskip{}}";
1620 if (IsMultiColumn(cell)){
1623 if (RotateCell(cell)) {
1624 file += "\n\\end{sideways}";
1628 if (IsLastCell(cell)) {
1629 addNewlineAndDepth(file,--depth);
1631 addNewlineAndDepth(file,--depth);
1633 addNewlineAndDepth(file,depth);
1635 addNewlineAndDepth(file,++depth);
1636 file += "<ENTRY ALIGN='";
1637 file += getDocBookAlign(cell+1);
1638 file += "' VALIGN='middle'";
1639 if (IsMultiColumn(cell+1)) {
1640 file += " NAMEST='col";
1641 file += column_of_cell(cell+1) + 1;
1642 file += "' NAMEEND='col";
1643 file += column_of_cell(cell+1) +
1644 cells_in_multicolumn(cell+1);
1648 addNewlineAndDepth(file,++depth);
1651 int row = row_of_cell(cell);
1652 string hline1,hline2;
1653 bool print_hline = true;
1654 bool pr_top_hline,flag1,flag2;
1655 flag1 = IsLongTable() &&
1656 ((row == endhead) || (row == endfirsthead) ||
1657 (row == endfoot) || (row == endlastfoot));
1659 flag2 = IsLongTable() &&
1660 ((row <= endhead) || (row <= endfirsthead) ||
1661 (row <= endfoot) || (row <= endlastfoot));
1663 // print the bottom hline only if (otherwise it is doubled):
1664 // - is no LongTable
1665 // - there IS a first-header
1666 // - the next row is no special header/footer
1667 // & this row is no special header/footer
1668 // - the next row is a special header/footer
1669 // & this row is a special header/footer
1670 pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1671 (endfirsthead == endhead);
1676 while (!IsFirstCell(fcell))
1678 for (i=0; i < NumberOfCellsInRow(cell); i++){
1679 if (BottomLine(fcell+i))
1682 if (tmp == NumberOfCellsInRow(cell)){
1684 hline1 = "\\hline ";
1687 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1688 if (BottomLine(fcell+i)){
1690 file += column_of_cell(fcell+i)+1;
1692 file += right_column_of_cell(fcell+i)+1;
1694 hline1 += "\\cline{";
1695 hline1 += column_of_cell(fcell+i)+1;
1697 hline1 += right_column_of_cell(fcell+i)+1;
1707 if (IsLongTable() && (row == endfoot)) {
1708 file += "\\endfoot\n";
1710 print_hline = false; // no double line below footer
1712 if (IsLongTable() && (row == endlastfoot)) {
1713 file += "\\endlastfoot\n";
1715 print_hline = false; // no double line below footer
1717 if (IsLongTable() && row_info[row].newpage) {
1718 file += "\\newpage\n";
1720 print_hline = false; // no line below a \\newpage-command
1723 if (nvcell < numberofcells && (cell < GetNumberOfCells()-1) &&
1724 !ShouldBeVeryLastCell(cell)) {
1726 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1727 if (TopLine(fcell+i))
1730 if (tmp == NumberOfCellsInRow(fcell)){
1733 hline2 = "\\hline ";
1737 for (i=0; i < NumberOfCellsInRow(fcell); i++){
1738 if (TopLine(fcell+i)){
1741 file += column_of_cell(fcell+i)+1;
1743 file += right_column_of_cell(fcell+i)+1;
1746 hline2 += "\\cline{";
1747 hline2 += column_of_cell(fcell+i)+1;
1749 hline2 += right_column_of_cell(fcell+i)+1;
1755 if (tmp && print_hline){
1760 // the order here is important as if one defines two
1761 // or more things in one line only the first entry is
1762 // displayed the other are set to an empty-row. This
1763 // is important if I have a footer and want that the
1764 // lastfooter is NOT displayed!!!
1765 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1766 (row == endfoot) || (row == endlastfoot);
1768 // sflag2 = IsLongTable() && (row >= 0) &&
1769 // (sflag2 || (row == endhead) || (row == endfirsthead));
1771 bool sflag1 = IsLongTable() && (row != endhead) &&
1772 (row != endfirsthead) &&
1773 ((row == endfoot) || (row == endlastfoot));
1775 if (IsLongTable() && (row == endhead)) {
1776 file += "\\endhead\n";
1779 if (IsLongTable() && (row == endfirsthead)) {
1780 file += "\\endfirsthead\n";
1783 if (sflag1) { // add the \hline for next foot row
1784 if (!hline1.empty()) {
1785 file += hline1 + '\n';
1789 // add the \hline for the first row
1790 if (pr_top_hline && sflag2) {
1791 if (!hline2.empty()) {
1792 file += hline2 + '\n';
1796 if (nvcell < numberofcells && RotateCell(nvcell)) {
1797 file += "\\begin{sideways}\n";
1802 addNewlineAndDepth(file,--depth);
1804 addNewlineAndDepth(file,depth);
1805 file += "<ENTRY ALIGN='";
1806 file += getDocBookAlign(cell+1);
1807 file += "' VALIGN='middle'";
1808 if (IsMultiColumn(cell+1)) {
1809 file += " NAMEST='col";
1810 file += column_of_cell(cell+1) + 1;
1811 file += "' NAMEEND='col";
1812 file += column_of_cell(cell+1) +
1813 cells_in_multicolumn(cell+1);
1817 addNewlineAndDepth(file,++depth);
1820 if (nvcell < numberofcells && RotateCell(nvcell)) {
1821 file += "\\begin{sideways}\n";
1828 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1829 file += "\\multicolumn{";
1830 file += cells_in_multicolumn(nvcell);
1832 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1833 file += cellinfo_of_cell(cell+1)->align_special;
1836 if (LeftLine(nvcell))
1838 if (!GetPWidth(nvcell).empty()) {
1840 file += GetPWidth(nvcell);
1843 switch (GetAlignment(nvcell)) {
1844 case LYX_ALIGN_LEFT: file += 'l'; break;
1845 case LYX_ALIGN_RIGHT: file += 'r'; break;
1846 default: file += 'c'; break;
1849 if (RightLine(nvcell))
1851 //if (column_of_cell(cell+2)!=0 && LeftLine(cell+2))
1852 if (((nvcell+1) < numberofcells) &&
1853 (NextVirtualCell(nvcell+1) < numberofcells) &&
1854 (column_of_cell(NextVirtualCell(nvcell+1))!=0) &&
1855 LeftLine(NextVirtualCell(nvcell+1)))
1860 if (nvcell < numberofcells && Linebreaks(nvcell)) {
1861 // !column_info[column_of_cell(nvcell)].p_width.empty()) {
1862 file += "\\parbox{";
1863 file += GetPWidth(nvcell);
1864 file += "}{\\smallskip{}";
1872 bool LyXTable::IsMultiColumn(int cell)
1874 int fvcell = FirstVirtualCell(cell);
1876 return (cellinfo_of_cell(fvcell)->multicolumn != LyXTable::CELL_NORMAL);
1880 LyXTable::cellstruct* LyXTable::cellinfo_of_cell(int cell)
1882 int row = row_of_cell(cell);
1883 int column = column_of_cell(cell);
1884 return &cell_info[row][column];
1888 void LyXTable::SetMultiColumn(int cell, int number)
1890 int fvcell = FirstVirtualCell(cell);
1891 int new_width = cellinfo_of_cell(fvcell)->width_of_cell;
1893 cellinfo_of_cell(fvcell)->multicolumn = LyXTable::CELL_BEGIN_OF_MULTICOLUMN;
1894 cellinfo_of_cell(fvcell)->alignment = column_info[column_of_cell(fvcell)].alignment;
1895 cellinfo_of_cell(fvcell)->top_line = row_info[row_of_cell(fvcell)].top_line;
1896 cellinfo_of_cell(fvcell)->bottom_line = row_info[row_of_cell(fvcell)].bottom_line;
1897 for (number--;number>0;number--){
1898 cellinfo_of_cell(fvcell+number)->multicolumn =
1899 LyXTable::CELL_PART_OF_MULTICOLUMN;
1900 new_width += cellinfo_of_cell(fvcell+number)->width_of_cell;
1902 set_row_column_number_info();
1903 SetWidthOfCell(fvcell,new_width);
1907 int LyXTable::cells_in_multicolumn(int cell)
1909 int row = row_of_cell(cell);
1910 int column = column_of_cell(cell);
1913 while (column < columns && cell_info[row][column].multicolumn
1914 == LyXTable::CELL_PART_OF_MULTICOLUMN){
1922 int LyXTable::UnsetMultiColumn(int cell)
1924 int fvcell = FirstVirtualCell(cell);
1925 int row = row_of_cell(fvcell);
1926 int column = column_of_cell(fvcell);
1930 if (cell_info[row][column].multicolumn
1931 == LyXTable::CELL_BEGIN_OF_MULTICOLUMN){
1932 cell_info[row][column].multicolumn = LyXTable::CELL_NORMAL;
1934 while (column < columns &&
1935 cell_info[row][column].multicolumn
1936 == LyXTable::CELL_PART_OF_MULTICOLUMN){
1937 cell_info[row][column].multicolumn =
1938 LyXTable::CELL_NORMAL;
1943 set_row_column_number_info();
1948 void LyXTable::delete_column(int column)
1951 columnstruct *column_info2 = new columnstruct[columns-1];
1953 for (i=0; i<column; i++){
1954 column_info2[i] = column_info[i];
1956 for (i=column; i<columns-1; i++){
1957 column_info2[i] = column_info[i+1];
1960 delete[] column_info;
1961 column_info = column_info2;
1963 for (i=0; i<rows;i++){
1964 cellstruct* tmp = cell_info[i];
1965 cell_info[i] = new cellstruct[columns-1];
1966 for (j=0; j<column; j++){
1967 cell_info[i][j]=tmp[j];
1969 for (j=column; j<columns-1; j++){
1970 cell_info[i][j]=tmp[j+1];
1979 void LyXTable::SetLongTable(int what)
1981 is_long_table = what;
1984 bool LyXTable::IsLongTable()
1986 return is_long_table;
1989 void LyXTable::SetRotateTable(int what)
1994 bool LyXTable::RotateTable()
1999 void LyXTable::SetRotateCell(int cell, int what)
2001 cellinfo_of_cell(cell)->rotate = what;
2004 bool LyXTable::RotateCell(int cell)
2006 return cellinfo_of_cell(cell)->rotate;
2009 bool LyXTable::NeedRotating()
2013 for (int i=0; i<rows;i++){
2014 for (int j=0;j<columns;j++){
2015 if (cell_info[i][j].rotate)
2022 void LyXTable::AppendContRow(int cell)
2024 int row = row_of_cell(cell)+1;
2026 if (!RowHasContRow(cell) || (CellHasContRow(cell)>=0))
2028 row_info[row].is_cont_row = true;
2029 row_info[row].top_line = false;
2030 cell_info[row-1][column_of_cell(cell)].has_cont_row = true;
2034 bool LyXTable::IsContRow(int cell)
2036 return row_info[row_of_cell(cell)].is_cont_row;
2039 int LyXTable::CellHasContRow(int cell)
2041 int row = row_of_cell(cell);
2043 if (VeryLastRow(cell))
2045 if (cell_info[row][column_of_cell(cell)].has_cont_row)
2046 return cell_info[row+1][column_of_cell(cell)].cellno;
2050 bool LyXTable::RowHasContRow(int cell)
2052 int row = row_of_cell(cell) + 1;
2055 return row_info[row].is_cont_row;
2059 int LyXTable::FirstVirtualCell(int cell)
2061 if (!IsContRow(cell))
2063 int row = row_of_cell(cell);
2064 int column = column_of_cell(cell);
2065 for(;(row>0) && IsContRow(cell_info[row][column].cellno); row--)
2067 return cell_info[row][column].cellno;
2071 int LyXTable::NextVirtualCell(int cell)
2073 if (!IsContRow(cell))
2075 int row = row_of_cell(cell);
2076 for(;(row < rows - 1) && IsContRow(cell_info[row][0].cellno); ++row)
2078 // what if(row >= rows) ?
2079 return cell_info[row][0].cellno;
2083 bool LyXTable::ShouldBeVeryLastCell(int cell)
2084 // "very last cell" ..of what? the row? the table?
2085 // "Cell" in this context appears to not count `virtual' cells
2087 int fcell = cell + 1;
2089 if (cell == GetNumberOfCells() - 1)
2090 return true; // not really sure if I should return false here
2091 if (!IsContRow(fcell))
2093 while((fcell < GetNumberOfCells() - 1) && IsContRow(fcell))
2095 if (fcell < GetNumberOfCells() - 1)
2100 bool LyXTable::ShouldBeVeryLastRow(int cell)
2102 if (CellHasContRow(cell)>=0)
2104 int row = row_of_cell(cell)+1;
2105 int column = column_of_cell(cell);
2106 while((row < rows) && IsContRow(cell_info[row][column].cellno))
2109 return false; // found another valid row
2110 // I do not have any valid row after the actual
2114 int LyXTable::GetCellAbove(int cell)
2116 int row = row_of_cell(cell);
2119 return cell_info[row-1][column_of_cell(cell)].cellno;
2123 int LyXTable::GetCellNumber(int column, int row)
2125 if (column >= columns)
2126 column = columns - 1;
2127 else if (column < 0)
2134 return cell_info[row][column].cellno;
2137 void LyXTable::SetLinebreaks(int cell, bool what)
2139 cellinfo_of_cell(FirstVirtualCell(cell))->linebreaks = what;
2142 bool LyXTable::Linebreaks(int cell)
2144 int fvcell = FirstVirtualCell(cell);
2146 if (column_info[column_of_cell(fvcell)].p_width.empty() &&
2147 !(IsMultiColumn(fvcell) && !cellinfo_of_cell(fvcell)->p_width.empty()))
2149 return cellinfo_of_cell(fvcell)->linebreaks;
2152 void LyXTable::SetLTHead(int cell, bool first)
2154 int row = row_of_cell(cell);
2157 if (row == endfirsthead)
2169 bool LyXTable::RowOfLTHead(int cell)
2171 if ((endhead+1) > rows)
2173 return (row_of_cell(cell) == endhead);
2176 bool LyXTable::RowOfLTFirstHead(int cell)
2178 if ((endfirsthead+1) > rows)
2180 return (row_of_cell(cell) == endfirsthead);
2183 void LyXTable::SetLTFoot(int cell, bool last)
2185 int row = row_of_cell(cell);
2188 if (row == endlastfoot)
2200 bool LyXTable::RowOfLTFoot(int cell)
2202 if ((endfoot+1) > rows) {
2206 return (row_of_cell(cell) == endfoot);
2209 bool LyXTable::RowOfLTLastFoot(int cell)
2211 if ((endlastfoot+1) > rows)
2213 return (row_of_cell(cell) == endlastfoot);
2216 void LyXTable::SetLTNewPage(int cell, bool what)
2218 row_info[row_of_cell(cell)].newpage = what;
2221 bool LyXTable::LTNewPage(int cell)
2223 return row_info[row_of_cell(cell)].newpage;