1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1995 Matthias Ettrich
7 * Copyright 1995-2000 The LyX Team.
9 * ======================================================
18 #include "support/lstrings.h"
23 #pragma implementation
26 #ifdef USE_OSTREAM_ONLY
27 #include "support/lyxmanip.h"
29 extern void addNewlineAndDepth(string & file, int depth); // Jug 990923
32 static int const WIDTH_OF_LINE = 5;
35 LyXTable::LyXTable(int rows_arg, int columns_arg)
37 Init(rows_arg, columns_arg);
41 LyXTable::LyXTable(LyXLex & lex)
43 istream & is = lex.getStream();
48 LyXTable::~LyXTable() {
50 delete[] columnofcell;
53 for (int i = 0; i < rows; ++i) {
54 delete[] cell_info[i]; // verify that this shoudn't be freed with delete
60 LyXTable * LyXTable::Clone()
62 LyXTable * result = new LyXTable(rows, columns);
65 for (row = 0; row < rows; ++row) {
66 for (column = 0; column < columns; ++column) {
67 result->cell_info[row][column] = cell_info[row][column];
71 for (row = 0; row < rows; ++row) {
72 result->row_info[row] = row_info[row];
75 for (column = 0; column < columns; ++column) {
76 result->column_info[column].left_line = column_info[column].left_line;
77 result->column_info[column].right_line = column_info[column].right_line;
78 result->column_info[column].alignment = column_info[column].alignment;
79 result->column_info[column].p_width = column_info[column].p_width;
80 result->column_info[column].align_special = column_info[column].align_special;
83 result->SetLongTable(is_long_table);
84 result->rotate = rotate;
90 /* activates all lines and sets all widths to 0 */
91 void LyXTable::Init(int rows_arg, int columns_arg)
95 columns = columns_arg;
96 column_info = new columnstruct[columns];
97 row_info = new rowstruct[rows];
98 cell_info = new cellstruct*[rows];
101 for (i = 0; i < rows; ++i) {
102 cell_info[i] = new cellstruct[columns];
103 row_info[i].top_line = true;
104 row_info[i].bottom_line = false;
105 row_info[i].is_cont_row = false;
106 row_info[i].newpage = false;
107 for (j = 0; j < columns; ++j) {
108 cell_info[i][j].cellno = cellno++;
109 cell_info[i][j].width_of_cell = 0;
110 cell_info[i][j].multicolumn = LyXTable::CELL_NORMAL;
111 cell_info[i][j].alignment = LYX_ALIGN_CENTER;
112 cell_info[i][j].top_line = row_info[i].top_line;
113 cell_info[i][j].bottom_line = row_info[i].bottom_line;
114 cell_info[i][j].has_cont_row = false;
115 cell_info[i][j].rotate = false;
116 cell_info[i][j].linebreaks = false;
119 row_info[i-1].bottom_line = true;
120 row_info[0].bottom_line = true;
122 for (i = 0; i < columns; ++i) {
123 column_info[i].left_line = true;
124 column_info[i].right_line = false;
125 column_info[i].alignment = LYX_ALIGN_CENTER;
126 // set width_of_column to zero before it is used in
127 // calculate_width_of_column() (thornley)
128 column_info[i].width_of_column = 0;
129 calculate_width_of_column(i);
131 column_info[i-1].right_line = true;
133 calculate_width_of_table();
137 set_row_column_number_info();
138 is_long_table = false;
147 void LyXTable::AppendRow(int cell)
149 int row = row_of_cell(cell);
150 rowstruct * row_info2 = new rowstruct[rows + 1];
151 cellstruct ** cell_info2 = new cellstruct * [rows + 1];
154 for (i = 0; i <= row; ++i) {
155 cell_info2[i] = cell_info[i];
156 row_info2[i] = row_info[i];
158 for (i = rows - 1; i >= row; --i) {
159 cell_info2[i + 1] = cell_info[i];
160 row_info2[i + 1] = row_info[i];
162 for (i = row; row_info[i].is_cont_row; --i);
163 if (((row + 1) >= rows) || !row_info[row + 1].is_cont_row)
164 row_info2[row + 1].is_cont_row = false;
165 row_info2[row + 1].top_line = row_info[i].top_line;
166 cell_info2[row + 1] = new cellstruct[columns];
167 for (i = 0; i < columns; ++i) {
168 cell_info2[row + 1][i].width_of_cell = 0;
169 cell_info2[row + 1][i] = cell_info2[row][i];
173 cell_info = cell_info2;
175 row_info = row_info2;
183 void LyXTable::DeleteRow(int cell)
185 int row = row_of_cell(cell);
186 while(!row_info[row].is_cont_row && RowHasContRow(cell))
187 DeleteRow(cell_info[row+1][0].cellno);
188 rowstruct * row_info2 = new rowstruct[rows - 1];
189 cellstruct ** cell_info2 = new cellstruct * [rows - 1];
191 delete[] cell_info[row];
193 for (; i < row; ++i) {
194 cell_info2[i] = cell_info[i];
195 row_info2[i] = row_info[i];
197 if (row_info[i].is_cont_row)
198 row_info2[i - 1].bottom_line = row_info[i].bottom_line;
199 for (i = row; i < rows - 1; ++i) {
200 cell_info2[i] = cell_info[i + 1];
201 row_info2[i] = row_info[i + 1];
205 cell_info = cell_info2;
207 row_info = row_info2;
215 void LyXTable::AppendColumn(int cell)
218 columnstruct * column_info2 = new columnstruct[columns + 1];
219 int column = right_column_of_cell(cell);
222 for (; i <= column; ++i) {
223 column_info2[i] = column_info[i];
225 for (i = columns - 1; i >= column; --i) {
226 column_info2[i + 1] = column_info[i];
229 delete[] column_info;
230 column_info = column_info2;
232 for (i = 0; i < rows; ++i) {
233 cellstruct * tmp = cell_info[i];
234 cell_info[i] = new cellstruct[columns + 1];
235 for (j = 0; j <= column; ++j) {
236 cell_info[i][j] = tmp[j];
238 for (j = column; j < columns; ++j) {
239 cell_info[i][j + 1] = tmp[j];
241 // care about multicolumns
242 if (cell_info[i][column + 1].multicolumn
243 == LyXTable::CELL_BEGIN_OF_MULTICOLUMN){
244 cell_info[i][column + 1].multicolumn =
245 LyXTable::CELL_PART_OF_MULTICOLUMN;
247 if (column + 1 == columns
248 || cell_info[i][column + 2].multicolumn
249 != LyXTable::CELL_PART_OF_MULTICOLUMN){
250 cell_info[i][column + 1].multicolumn =
251 LyXTable::CELL_NORMAL;
261 void LyXTable::Reinit()
266 for (; i < rows; ++i) {
267 for (j = 0; j < columns; ++j) {
268 cell_info[i][j].width_of_cell = 0;
269 if ((i + 1 < rows) && !row_info[i+1].is_cont_row)
270 cell_info[i][j].has_cont_row = false;
274 for (i = 0; i < columns; ++i) {
275 calculate_width_of_column(i);
277 calculate_width_of_table();
279 set_row_column_number_info();
283 void LyXTable::set_row_column_number_info()
289 for (; row < rows; ++row) {
290 for (column = 0; column<columns; ++column) {
291 if (cell_info[row][column].multicolumn
292 != LyXTable::CELL_PART_OF_MULTICOLUMN)
294 cell_info[row][column].cellno = numberofcells;
297 ++numberofcells; // because this is one more than as we start from 0
302 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);
328 if (column1 == 0 && column2 == columns - 1)
331 for (int column = column1; column <= column2; ++column) {
332 delete_column(column1);
338 int LyXTable::GetNumberOfCells()
340 return numberofcells;
344 int LyXTable::NumberOfCellsInRow(int cell)
346 int row = row_of_cell(cell);
348 for (int i = 0; i < columns; ++i) {
349 if (cell_info[row][i].multicolumn != LyXTable::CELL_PART_OF_MULTICOLUMN)
356 int LyXTable::AppendCellAfterCell(int append_cell, int question_cell)
358 return (right_column_of_cell(append_cell) ==
359 right_column_of_cell(question_cell));
363 int LyXTable::DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell)
365 if (column_of_cell(delete_column_cell) == 0 &&
366 right_column_of_cell(delete_column_cell) == columns - 1)
370 (column_of_cell(cell) >= column_of_cell(delete_column_cell) &&
371 column_of_cell(cell) <= right_column_of_cell(delete_column_cell));
375 /* returns 1 if there is a topline, returns 0 if not */
376 bool LyXTable::TopLine(int cell)
378 int row = row_of_cell(cell);
381 return TopLine(cell_info[row-1][column_of_cell(cell)].cellno);
382 if (IsMultiColumn(cell))
383 return cellinfo_of_cell(cell)->top_line;
384 return row_info[row].top_line;
388 bool LyXTable::BottomLine(int cell)
390 //no bottom line underneath non-existent cells if you please
391 if(cell >= numberofcells)
394 int row = row_of_cell(cell);
396 if (RowHasContRow(cell))
397 return BottomLine(cell_info[row+1][column_of_cell(cell)].cellno);
398 if (IsMultiColumn(cell))
399 return cellinfo_of_cell(cell)->bottom_line;
400 return row_info[row_of_cell(cell)].bottom_line;
404 bool LyXTable::LeftLine(int cell)
406 return column_info[column_of_cell(cell)].left_line;
410 bool LyXTable::RightLine(int cell)
412 return column_info[right_column_of_cell(cell)].right_line;
416 bool LyXTable::TopAlreadyDrawed(int cell)
418 if (AdditionalHeight(cell))
420 int row = row_of_cell(cell);
422 int column = column_of_cell(cell);
424 && cell_info[row-1][column].multicolumn
425 == LyXTable::CELL_PART_OF_MULTICOLUMN)
427 if (cell_info[row-1][column].multicolumn
428 == LyXTable::CELL_NORMAL)
429 return row_info[row-1].bottom_line;
431 return cell_info[row-1][column].bottom_line;
437 bool LyXTable::VeryLastRow(int cell)
439 return (row_of_cell(cell) == rows - 1);
443 int LyXTable::AdditionalHeight(int cell)
445 int row = row_of_cell(cell);
448 int top = 1; // bool top = true; ??
449 int bottom = 1; // bool bottom = true; ??
452 for (column = 0; column < columns - 1 && bottom; ++column) {
453 switch (cell_info[row - 1][column].multicolumn) {
454 case LyXTable::CELL_BEGIN_OF_MULTICOLUMN:
455 bottom = cell_info[row - 1][column].bottom_line;
457 case LyXTable::CELL_NORMAL:
458 bottom = row_info[row - 1].bottom_line;
461 for (column = 0; column < columns - 1 && top; ++column) {
462 switch (cell_info[row][column].multicolumn){
463 case LyXTable::CELL_BEGIN_OF_MULTICOLUMN:
464 top = cell_info[row][column].top_line;
466 case LyXTable::CELL_NORMAL:
467 top = row_info[row].top_line;
471 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 <= 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);
518 // first set columns to 0 so we can calculate the right width
520 for (; i <= column2; ++i) {
521 cell_info[row][i].width_of_cell = 0;
523 // set the width to MAX_WIDTH until width > 0
524 int width = (new_width + 2 * WIDTH_OF_LINE);
525 for (i = column1; (i < column2) && (width > 0); ++i) {
526 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
527 width -= column_info[i].width_of_column;
530 cell_info[row][i].width_of_cell = width;
536 void LyXTable::recalculateMulticolCells(int cell, int new_width)
538 int row = row_of_cell(cell);
539 int column1 = column_of_cell(cell);
540 int column2 = right_column_of_cell(cell);
542 // first set columns to 0 so we can calculate the right width
544 for (; i <= column2; ++i)
545 cell_info[row][i].width_of_cell = 0;
546 for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
548 if (i < numberofcells)
549 recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
550 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, string 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 if (!width.empty()) // do this only if there is a width
608 SetAlignment(cell, LYX_ALIGN_LEFT);
613 bool LyXTable::SetAlignSpecial(int cell, string special, int what)
615 if (what == SET_SPECIAL_MULTI)
616 cellinfo_of_cell(cell)->align_special = special;
618 column_info[column_of_cell(cell)].align_special = special;
622 bool LyXTable::SetAllLines(int cell, bool line)
624 SetTopLine(cell, line);
625 SetBottomLine(cell, line);
626 SetRightLine(cell, line);
627 SetLeftLine(cell, line);
631 bool LyXTable::SetTopLine(int cell, bool line)
633 int row = row_of_cell(cell);
636 SetTopLine(cell_info[row-1][column_of_cell(cell)].cellno, line);
637 else if (!IsMultiColumn(cell))
638 row_info[row].top_line = line;
640 cellinfo_of_cell(cell)->top_line = line;
645 bool LyXTable::SetBottomLine(int cell, bool line)
647 int row = row_of_cell(cell);
649 if (RowHasContRow(cell))
650 SetBottomLine(cell_info[row+1][column_of_cell(cell)].cellno, line);
651 else if (!IsMultiColumn(cell))
652 row_info[row_of_cell(cell)].bottom_line = line;
654 cellinfo_of_cell(cell)->bottom_line = line;
659 bool LyXTable::SetLeftLine(int cell, bool line)
661 column_info[column_of_cell(cell)].left_line = line;
666 bool LyXTable::SetRightLine(int cell, bool line)
668 column_info[right_column_of_cell(cell)].right_line = line;
673 char LyXTable::GetAlignment(int cell)
675 if (IsMultiColumn(cell))
676 return cellinfo_of_cell(cell)->alignment;
678 return column_info[column_of_cell(cell)].alignment;
681 string LyXTable::GetPWidth(int cell)
683 int fvcell = FirstVirtualCell(cell);
685 if (IsMultiColumn(fvcell)) // && !cellinfo_of_cell(cell)->p_width.empty())
686 return cellinfo_of_cell(fvcell)->p_width;
687 return column_info[column_of_cell(fvcell)].p_width;
690 string LyXTable::GetAlignSpecial(int cell, int what)
692 if (what == SET_SPECIAL_MULTI)
693 return cellinfo_of_cell(cell)->align_special;
694 return column_info[column_of_cell(cell)].align_special;
697 int LyXTable::GetWidthOfCell(int cell)
699 int row = row_of_cell(cell);
700 int column1 = column_of_cell(cell);
701 int column2 = right_column_of_cell(cell);
704 for (; i <= column2; ++i) {
705 result += cell_info[row][i].width_of_cell;
708 result += AdditionalWidth(cell);
714 int LyXTable::GetBeginningOfTextInCell(int cell)
718 switch (GetAlignment(cell)){
719 case LYX_ALIGN_CENTER:
720 x += (WidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
722 case LYX_ALIGN_RIGHT:
723 x += WidthOfColumn(cell) - GetWidthOfCell(cell) + AdditionalWidth(cell);
725 default: /* LYX_ALIGN_LEFT: nothing :-) */
735 bool LyXTable::IsFirstCell(int cell)
737 return (column_of_cell(cell) == 0);
740 bool LyXTable::IsLastCell(int cell)
742 return (right_column_of_cell(cell) == (columns - 1));
746 bool LyXTable::calculate_width_of_column(int column)
748 int old_column_width = column_info[column].width_of_column;
751 for (int i = 0; i < rows; ++i) {
752 maximum = max(cell_info[i][column].width_of_cell, maximum);
754 column_info[column].width_of_column = maximum;
755 return (column_info[column].width_of_column != old_column_width);
758 bool LyXTable::calculate_width_of_column_NMC(int column)
760 int old_column_width = column_info[column].width_of_column;
762 for (int 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()
775 for (int i = 0; i < columns; ++i) {
776 width_of_table += column_info[i].width_of_column;
781 int LyXTable::row_of_cell(int cell)
783 if (cell >= numberofcells)
787 return rowofcell[cell];
791 int LyXTable::column_of_cell(int cell)
793 if (cell >= numberofcells)
797 return columnofcell[cell];
801 int LyXTable::right_column_of_cell(int cell)
803 int row = row_of_cell(cell);
804 int column = column_of_cell(cell);
805 while (column < columns - 1 &&
806 cell_info[row][column+1].multicolumn == LyXTable::CELL_PART_OF_MULTICOLUMN)
812 void LyXTable::Write(ostream & os)
816 << rows << " " << columns << " " << is_long_table << " "
817 << rotate << " " << endhead << " " << endfirsthead << " "
818 << endfoot << " " << endlastfoot << "\n";
819 for (i = 0; i < rows; ++i) {
820 os << row_info[i].top_line << " "
821 << row_info[i].bottom_line << " "
822 << row_info[i].is_cont_row << " "
823 << row_info[i].newpage << "\n";
825 for (i = 0; i < columns; ++i) {
826 os << column_info[i].alignment << " "
827 << column_info[i].left_line << " "
828 << column_info[i].right_line << " \""
829 << VSpace(column_info[i].p_width).asLyXCommand() << "\" \""
830 << column_info[i].align_special << "\"\n";
833 for (i = 0; i < rows; ++i) {
834 for (j = 0; j < columns; ++j) {
835 os << 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 << "\" \""
843 << cell_info[i][j].p_width << "\"\n";
849 void LyXTable::Read(istream & is)
855 int is_long_table_arg = false;
856 int rotate_arg = false;
869 version = atoi(s.c_str() + 8);
873 #warning Insert a error message window here that this format is not supported anymore
876 lyxerr << "Tabular format < 5 is not supported anymore\n"
877 "Get an older version of LyX (< 1.1.x) for conversion!"
880 is >> rows_arg >> columns_arg >> is_long_table_arg
881 >> rotate_arg >> a >> b >> c >> d;
883 is >> rows_arg >> columns_arg;
884 Init(rows_arg, columns_arg);
885 SetLongTable(is_long_table_arg);
886 SetRotateTable(rotate_arg);
888 for (i = 0; i < rows; ++i) {
891 for (i = 0; i < columns; ++i) {
894 for (i = 0; i < rows; ++i) {
895 for (j = 0; j < columns; ++j) {
899 set_row_column_number_info();
902 is >> rows_arg >> columns_arg >> is_long_table_arg
903 >> rotate_arg >> a >> b >> c >> d;
904 Init(rows_arg, columns_arg);
905 SetLongTable(is_long_table_arg);
906 SetRotateTable(rotate_arg);
911 for (i = 0; i < rows; ++i) {
912 a = b = c = d = e = f = g = h = 0;
913 is >> a >> b >> c >> d;
914 row_info[i].top_line = a;
915 row_info[i].bottom_line = b;
916 row_info[i].is_cont_row = c;
917 row_info[i].newpage = d;
919 for (i = 0; i < columns; ++i) {
925 getline(is, s1, '"');
926 is >> ch; // skip '"'
927 getline(is, s2, '"');
928 column_info[i].alignment = static_cast<char>(a);
929 column_info[i].left_line = b;
930 column_info[i].right_line = c;
931 column_info[i].p_width = s1;
932 column_info[i].align_special = s2;
934 for (i = 0; i < rows; ++i) {
935 for (j = 0; j < columns; ++j) {
938 is >> a >> b >> c >> d >> e >> f >> g;
940 is >> ch; // skip '"'
941 getline(is, s1, '"');
942 is >> ch; // skip '"'
943 getline(is, s2, '"');
944 cell_info[i][j].multicolumn = static_cast<char>(a);
945 cell_info[i][j].alignment = static_cast<char>(b);
946 cell_info[i][j].top_line = static_cast<char>(c);
947 cell_info[i][j].bottom_line = static_cast<char>(d);
948 cell_info[i][j].has_cont_row = static_cast<bool>(e);
949 cell_info[i][j].rotate = static_cast<bool>(f);
950 cell_info[i][j].linebreaks = static_cast<bool>(g);
951 cell_info[i][j].align_special = s1;
952 cell_info[i][j].p_width = s2;
955 set_row_column_number_info();
959 #ifdef USE_OSTREAM_ONLY
960 // cell <0 will tex the preamble
961 // returns the number of printed newlines
962 int LyXTable::TexEndOfCell(ostream & os, int cell)
968 if (ShouldBeVeryLastCell(cell)) {
969 // the very end at the very beginning
970 if (Linebreaks(cell))
971 os << "\\smallskip{}}";
972 if (IsMultiColumn(cell))
974 if (RotateCell(cell)) {
975 os << "\n\\end{sideways}";
983 while (!IsFirstCell(fcell)) --fcell;
984 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
985 if (BottomLine(fcell + i))
988 if (tmp == NumberOfCellsInRow(fcell)) {
992 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
993 if (BottomLine(fcell + i)) {
995 << column_of_cell(fcell + i) + 1
997 << right_column_of_cell(fcell + i) + 1
1008 os << "\\end{longtable}";
1010 os << "\\end{tabular}";
1012 os << "\n\\end{sideways}";
1016 nvcell = NextVirtualCell(cell + 1);
1020 os << "\\begin{sideways}\n";
1024 os << "\\begin{longtable}{";
1026 os << "\\begin{tabular}{";
1027 for (i = 0; i < columns; ++i) {
1028 if (column_info[i].left_line)
1030 if (!column_info[i].align_special.empty()) {
1031 os << column_info[i].align_special;
1032 } else if (!column_info[i].p_width.empty()) {
1034 << column_info[i].p_width
1037 switch (column_info[i].alignment) {
1038 case LYX_ALIGN_LEFT:
1041 case LYX_ALIGN_RIGHT:
1049 if (column_info[i].right_line)
1055 if (GetNumberOfCells()) {
1057 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1058 if (TopLine(fcell + i))
1061 if (tmp == NumberOfCellsInRow(fcell)){
1065 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1066 if (TopLine(fcell + i)) {
1068 << column_of_cell(fcell + i) + 1
1070 << right_column_of_cell(fcell + i) + 1
1081 if (RotateCell(0)) {
1082 os << "\\begin{sideways}\n";
1087 if (Linebreaks(cell))
1088 os << "\\smallskip{}}";
1089 if (IsMultiColumn(cell)){
1092 if (RotateCell(cell)) {
1093 os << "\n\\end{sideways}";
1096 if (IsLastCell(cell)) {
1097 int row = row_of_cell(cell);
1098 string hline1, hline2;
1099 bool print_hline = true;
1100 bool flag1 = IsLongTable() &&
1101 ((row == endhead) || (row == endfirsthead) ||
1102 (row == endfoot) || (row == endlastfoot));
1104 bool flag2 = IsLongTable() &&
1105 ((row <= endhead) || (row <= endfirsthead) ||
1106 (row <= endfoot) || (row <= endlastfoot));
1108 // print the bottom hline only if (otherwise it is doubled):
1109 // - is no LongTable
1110 // - there IS a first-header
1111 // - the next row is no special header/footer
1112 // & this row is no special header/footer
1113 // - the next row is a special header/footer
1114 // & this row is a special header/footer
1115 bool pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1116 (endfirsthead == endhead);
1121 while (!IsFirstCell(fcell))
1123 for (i = 0; i < NumberOfCellsInRow(cell); ++i) {
1124 if (BottomLine(fcell + i))
1127 if (tmp == NumberOfCellsInRow(cell)){
1129 hline1 = "\\hline ";
1132 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1133 if (BottomLine(fcell + i)){
1135 << column_of_cell(fcell + i) + 1
1137 << right_column_of_cell(fcell + i) + 1
1139 hline1 += "\\cline{";
1140 hline1 += tostr(column_of_cell(fcell + i) + 1);
1142 hline1 += tostr(right_column_of_cell(fcell + i) + 1);
1152 if (IsLongTable() && (row == endfoot)) {
1153 os << "\\endfoot\n";
1155 print_hline = false; // no double line below footer
1157 if (IsLongTable() && (row == endlastfoot)) {
1158 os << "\\endlastfoot\n";
1160 print_hline = false; // no double line below footer
1162 if (IsLongTable() && row_info[row].newpage) {
1163 os << "\\newpage\n";
1165 print_hline = false; // no line below a \\newpage-command
1168 if (nvcell < numberofcells
1169 && (cell < GetNumberOfCells() - 1)
1170 && !ShouldBeVeryLastCell(cell)) {
1172 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1173 if (TopLine(fcell + i))
1176 if (tmp == NumberOfCellsInRow(fcell)) {
1179 hline2 = "\\hline ";
1182 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1183 if (TopLine(fcell + i)) {
1186 << column_of_cell(fcell + i) + 1
1188 << right_column_of_cell(fcell + i) + 1
1191 hline2 += "\\cline{";
1192 hline2 += tostr(column_of_cell(fcell+i)+1);
1194 hline2 += tostr(right_column_of_cell(fcell+i)+1);
1200 if (tmp && print_hline){
1205 // the order here is important as if one defines two
1206 // or more things in one line only the first entry is
1207 // displayed the other are set to an empty-row. This
1208 // is important if I have a footer and want that the
1209 // lastfooter is NOT displayed!!!
1210 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1211 (row == endfoot) || (row == endlastfoot);
1213 // sflag2 = IsLongTable() && (row >= 0) &&
1214 // (sflag2 || (row == endhead) || (row == endfirsthead));
1216 bool sflag1 = IsLongTable() && (row != endhead) &&
1217 (row != endfirsthead) &&
1218 ((row == endfoot) || (row == endlastfoot));
1220 if (IsLongTable() && (row == endhead)) {
1221 os << "\\endhead\n";
1224 if (IsLongTable() && (row == endfirsthead)) {
1225 os << "\\endfirsthead\n";
1228 if (sflag1) { // add the \hline for next foot row
1229 if (!hline1.empty()) {
1230 os << hline1 + '\n';
1234 // add the \hline for the first row
1235 if (pr_top_hline && sflag2) {
1236 if (!hline2.empty()) {
1237 os << hline2 + '\n';
1241 if (nvcell < numberofcells && RotateCell(nvcell)) {
1242 os << "\\begin{sideways}\n";
1248 if (nvcell < numberofcells && RotateCell(nvcell)) {
1249 os << "\\begin{sideways}\n";
1254 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1255 os << "\\multicolumn{"
1256 << cells_in_multicolumn(nvcell)
1258 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1259 os << cellinfo_of_cell(cell+1)->align_special
1262 if (LeftLine(nvcell))
1264 if (!GetPWidth(nvcell).empty()) {
1266 << GetPWidth(nvcell)
1269 switch (GetAlignment(nvcell)) {
1270 case LYX_ALIGN_LEFT: os << 'l'; break;
1271 case LYX_ALIGN_RIGHT: os << 'r'; break;
1272 default: os << 'c'; break;
1275 if (RightLine(nvcell))
1277 //if (column_of_cell(cell+2)!= 0 && LeftLine(cell+2))
1278 if (((nvcell + 1) < numberofcells) &&
1279 (NextVirtualCell(nvcell+1) < numberofcells) &&
1280 (column_of_cell(NextVirtualCell(nvcell+1))!= 0) &&
1281 LeftLine(NextVirtualCell(nvcell+1)))
1287 if (nvcell < numberofcells && Linebreaks(nvcell)) {
1288 // !column_info[column_of_cell(nvcell)].p_width.empty()) {
1290 << GetPWidth(nvcell)
1291 << "}{\\smallskip{}";
1297 // cell <0 will tex the preamble
1298 // returns the number of printed newlines
1299 int LyXTable::TexEndOfCell(string & file, int cell)
1305 if (ShouldBeVeryLastCell(cell)) {
1306 // the very end at the very beginning
1307 if (Linebreaks(cell))
1308 file += "\\smallskip{}}";
1309 if (IsMultiColumn(cell))
1311 if (RotateCell(cell)) {
1312 file += "\n\\end{sideways}";
1320 while (!IsFirstCell(fcell)) --fcell;
1321 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1322 if (BottomLine(fcell + i))
1325 if (tmp == NumberOfCellsInRow(fcell)) {
1329 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1330 if (BottomLine(fcell + i)) {
1332 file += tostr(column_of_cell(fcell + i) + 1);
1334 file += tostr(right_column_of_cell(fcell + i) + 1);
1345 file += "\\end{longtable}";
1347 file += "\\end{tabular}";
1349 file += "\n\\end{sideways}";
1353 nvcell = NextVirtualCell(cell + 1);
1357 file += "\\begin{sideways}\n";
1361 file += "\\begin{longtable}{";
1363 file += "\\begin{tabular}{";
1364 for (i = 0; i < columns; ++i) {
1365 if (column_info[i].left_line)
1367 if (!column_info[i].align_special.empty()) {
1368 file += column_info[i].align_special.c_str();
1369 } else if (!column_info[i].p_width.empty()) {
1371 file += column_info[i].p_width;
1374 switch (column_info[i].alignment) {
1375 case LYX_ALIGN_LEFT:
1378 case LYX_ALIGN_RIGHT:
1386 if (column_info[i].right_line)
1392 if (GetNumberOfCells()) {
1394 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1395 if (TopLine(fcell + i))
1398 if (tmp == NumberOfCellsInRow(fcell)){
1402 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1403 if (TopLine(fcell + i)) {
1405 file += tostr(column_of_cell(fcell + i) + 1);
1407 file += tostr(right_column_of_cell(fcell + i) + 1);
1418 if (RotateCell(0)) {
1419 file += "\\begin{sideways}\n";
1424 if (Linebreaks(cell))
1425 file += "\\smallskip{}}";
1426 if (IsMultiColumn(cell)){
1429 if (RotateCell(cell)) {
1430 file += "\n\\end{sideways}";
1433 if (IsLastCell(cell)) {
1434 int row = row_of_cell(cell);
1435 string hline1, hline2;
1436 bool print_hline = true;
1437 bool flag1 = IsLongTable() &&
1438 ((row == endhead) || (row == endfirsthead) ||
1439 (row == endfoot) || (row == endlastfoot));
1441 bool flag2 = IsLongTable() &&
1442 ((row <= endhead) || (row <= endfirsthead) ||
1443 (row <= endfoot) || (row <= endlastfoot));
1445 // print the bottom hline only if (otherwise it is doubled):
1446 // - is no LongTable
1447 // - there IS a first-header
1448 // - the next row is no special header/footer
1449 // & this row is no special header/footer
1450 // - the next row is a special header/footer
1451 // & this row is a special header/footer
1452 bool pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1453 (endfirsthead == endhead);
1458 while (!IsFirstCell(fcell))
1460 for (i = 0; i < NumberOfCellsInRow(cell); ++i) {
1461 if (BottomLine(fcell + i))
1464 if (tmp == NumberOfCellsInRow(cell)){
1466 hline1 = "\\hline ";
1469 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1470 if (BottomLine(fcell + i)){
1472 file += tostr(column_of_cell(fcell + i) + 1);
1474 file += tostr(right_column_of_cell(fcell + i) + 1);
1476 hline1 += "\\cline{";
1477 hline1 += tostr(column_of_cell(fcell + i) + 1);
1479 hline1 += tostr(right_column_of_cell(fcell + i) + 1);
1489 if (IsLongTable() && (row == endfoot)) {
1490 file += "\\endfoot\n";
1492 print_hline = false; // no double line below footer
1494 if (IsLongTable() && (row == endlastfoot)) {
1495 file += "\\endlastfoot\n";
1497 print_hline = false; // no double line below footer
1499 if (IsLongTable() && row_info[row].newpage) {
1500 file += "\\newpage\n";
1502 print_hline = false; // no line below a \\newpage-command
1505 if (nvcell < numberofcells && (cell < GetNumberOfCells() - 1) &&
1506 !ShouldBeVeryLastCell(cell)) {
1508 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1509 if (TopLine(fcell + i))
1512 if (tmp == NumberOfCellsInRow(fcell)) {
1515 hline2 = "\\hline ";
1518 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1519 if (TopLine(fcell + i)) {
1522 file += tostr(column_of_cell(fcell+i)+1);
1524 file += tostr(right_column_of_cell(fcell+i)+1);
1527 hline2 += "\\cline{";
1528 hline2 += tostr(column_of_cell(fcell+i)+1);
1530 hline2 += tostr(right_column_of_cell(fcell+i)+1);
1536 if (tmp && print_hline){
1541 // the order here is important as if one defines two
1542 // or more things in one line only the first entry is
1543 // displayed the other are set to an empty-row. This
1544 // is important if I have a footer and want that the
1545 // lastfooter is NOT displayed!!!
1546 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1547 (row == endfoot) || (row == endlastfoot);
1549 // sflag2 = IsLongTable() && (row >= 0) &&
1550 // (sflag2 || (row == endhead) || (row == endfirsthead));
1552 bool sflag1 = IsLongTable() && (row != endhead) &&
1553 (row != endfirsthead) &&
1554 ((row == endfoot) || (row == endlastfoot));
1556 if (IsLongTable() && (row == endhead)) {
1557 file += "\\endhead\n";
1560 if (IsLongTable() && (row == endfirsthead)) {
1561 file += "\\endfirsthead\n";
1564 if (sflag1) { // add the \hline for next foot row
1565 if (!hline1.empty()) {
1566 file += hline1 + '\n';
1570 // add the \hline for the first row
1571 if (pr_top_hline && sflag2) {
1572 if (!hline2.empty()) {
1573 file += hline2 + '\n';
1577 if (nvcell < numberofcells && RotateCell(nvcell)) {
1578 file += "\\begin{sideways}\n";
1584 if (nvcell < numberofcells && RotateCell(nvcell)) {
1585 file += "\\begin{sideways}\n";
1590 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1591 file += "\\multicolumn{";
1592 file += tostr(cells_in_multicolumn(nvcell));
1594 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1595 file += cellinfo_of_cell(cell+1)->align_special;
1598 if (LeftLine(nvcell))
1600 if (!GetPWidth(nvcell).empty()) {
1602 file += GetPWidth(nvcell);
1605 switch (GetAlignment(nvcell)) {
1606 case LYX_ALIGN_LEFT: file += 'l'; break;
1607 case LYX_ALIGN_RIGHT: file += 'r'; break;
1608 default: file += 'c'; break;
1611 if (RightLine(nvcell))
1613 //if (column_of_cell(cell+2)!= 0 && LeftLine(cell+2))
1614 if (((nvcell+1) < numberofcells) &&
1615 (NextVirtualCell(nvcell+1) < numberofcells) &&
1616 (column_of_cell(NextVirtualCell(nvcell+1))!= 0) &&
1617 LeftLine(NextVirtualCell(nvcell+1)))
1622 if (nvcell < numberofcells && Linebreaks(nvcell)) {
1623 // !column_info[column_of_cell(nvcell)].p_width.empty()) {
1624 file += "\\parbox{";
1625 file += GetPWidth(nvcell);
1626 file += "}{\\smallskip{}";
1635 // cell <0 will tex the preamble
1636 // returns the number of printed newlines
1637 int LyXTable::RoffEndOfCell(ostream & os, int cell)
1641 if (cell == GetNumberOfCells() - 1){
1642 // the very end at the very beginning
1643 if (CellHasContRow(cell) >= 0) {
1649 if (row_info[row_of_cell(cell)].bottom_line) {
1653 os << ".TE\n.pl 1c";
1658 os << "\n.pl 500c\n.TS\n";
1659 for (int j = 0; j < rows; ++j) {
1660 for (int i = 0; i < columns; ++i, ++fcell) {
1661 if (column_info[i].left_line)
1663 if (cell_info[j][i].multicolumn == CELL_PART_OF_MULTICOLUMN)
1666 switch (column_info[i].alignment) {
1667 case LYX_ALIGN_LEFT:
1670 case LYX_ALIGN_RIGHT:
1678 if (!column_info[i].p_width.empty())
1679 os << "w(" << column_info[i].p_width << ")";
1680 if (column_info[i].right_line)
1683 if ((j + 1) < rows) {
1690 if (row_info[0].top_line) {
1694 if (CellHasContRow(0) >= 0) {
1700 if (CellHasContRow(cell) >= 0) {
1704 if (right_column_of_cell(cell) == columns -1){
1707 int row = row_of_cell(cell);
1708 if (row_info[row++].bottom_line) {
1712 if ((row < rows) && row_info[row].top_line) {
1718 if ((cell < GetNumberOfCells() - 1) &&
1719 (CellHasContRow(cell+1) >= 0)) {
1730 char const *LyXTable::getDocBookAlign(int cell, bool isColumn)
1736 i = column_of_cell(cell);
1737 if (!isColumn && IsMultiColumn(cell)) {
1738 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1739 return cellinfo_of_cell(cell)->align_special.c_str();
1741 switch (GetAlignment(cell)) {
1742 case LYX_ALIGN_LEFT:
1744 case LYX_ALIGN_RIGHT:
1751 if (!column_info[i].align_special.empty()) {
1752 return column_info[i].align_special.c_str();
1754 #ifdef IGNORE_THIS_FOR_NOW
1755 else if (!column_info[i].p_width.empty()) {
1757 file += column_info[i].p_width;
1762 switch (column_info[i].alignment) {
1763 case LYX_ALIGN_LEFT:
1765 case LYX_ALIGN_RIGHT:
1775 #ifdef USE_OSTREAM_ONLY
1776 // cell <0 will tex the preamble
1777 // returns the number of printed newlines
1778 int LyXTable::DocBookEndOfCell(ostream & os, int cell, int &depth)
1782 //int tmp; // tmp2; //Â unused
1783 int nvcell; // fcell; //Â unused
1784 if (ShouldBeVeryLastCell(cell)) {
1785 os << newlineAndDepth(--depth)
1787 << newlineAndDepth(--depth)
1789 << newlineAndDepth(--depth)
1791 << newlineAndDepth(--depth);
1796 << newlineAndDepth(--depth);
1799 nvcell = NextVirtualCell(cell + 1);
1808 << "' COLSEP='1' ROWSEP='1'>"
1809 << newlineAndDepth(++depth);
1811 for (i = 0; i < columns; ++i) {
1812 os << "<COLSPEC ALIGN='"
1813 << getDocBookAlign(i, true)
1819 if (i == (columns-1)) {
1822 if (column_info[i].right_line ||
1823 column_info[i+1].left_line)
1829 << newlineAndDepth(depth);
1831 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1832 if (column_info[i].left_line)
1837 << newlineAndDepth(++depth)
1839 << newlineAndDepth(++depth)
1841 << getDocBookAlign(0)
1843 if (IsMultiColumn(0)) {
1844 os << " NAMEST='col1' NAMEEND='col"
1845 << cells_in_multicolumn(0)
1849 << newlineAndDepth(++depth);
1852 if (IsLastCell(cell)) {
1853 os << newlineAndDepth(--depth)
1855 << newlineAndDepth(--depth)
1857 << newlineAndDepth(depth)
1859 << newlineAndDepth(++depth)
1861 << getDocBookAlign(cell + 1)
1862 << "' VALIGN='middle'";
1863 if (IsMultiColumn(cell + 1)) {
1864 os << " NAMEST='col"
1865 << column_of_cell(cell+1) + 1
1867 << column_of_cell(cell + 1) +
1868 cells_in_multicolumn(cell + 1)
1872 << newlineAndDepth(++depth);
1875 os << newlineAndDepth(--depth)
1877 << newlineAndDepth(depth)
1879 << getDocBookAlign(cell + 1)
1880 << "' VALIGN='middle'";
1881 if (IsMultiColumn(cell + 1)) {
1882 os << " NAMEST='col"
1883 << column_of_cell(cell+1) + 1
1885 << column_of_cell(cell+1) +
1886 cells_in_multicolumn(cell+1)
1890 << newlineAndDepth(++depth);
1898 // cell <0 will tex the preamble
1899 // returns the number of printed newlines
1900 int LyXTable::DocBookEndOfCell(string & file, int cell, int &depth)
1904 //int tmp; // tmp2; //Â unused
1905 int nvcell; // fcell; //Â unused
1906 if (ShouldBeVeryLastCell(cell)) {
1907 addNewlineAndDepth(file,--depth);
1909 addNewlineAndDepth(file,--depth);
1911 addNewlineAndDepth(file,--depth);
1913 addNewlineAndDepth(file,--depth);
1915 file += "</TGROUP>";
1917 file += "</TGROUP>";
1918 addNewlineAndDepth(file,--depth);
1921 nvcell = NextVirtualCell(cell+1);
1929 file += tostr(columns);
1930 file += "' COLSEP='1' ROWSEP='1'>";
1931 addNewlineAndDepth(file,++depth);
1933 for (i = 0; i < columns; ++i) {
1934 file += "<COLSPEC ALIGN='";
1935 file += getDocBookAlign(i, true);
1936 file += "' COLNAME='col";
1938 file += "' COLNUM='";
1940 file += "' COLSEP='";
1941 if (i == (columns-1)) {
1944 if (column_info[i].right_line ||
1945 column_info[i+1].left_line)
1951 addNewlineAndDepth(file, depth);
1953 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1954 if (column_info[i].left_line)
1959 addNewlineAndDepth(file,++depth);
1961 addNewlineAndDepth(file,++depth);
1962 file += "<ENTRY ALIGN='";
1963 file += getDocBookAlign(0);
1965 if (IsMultiColumn(0)) {
1966 file += " NAMEST='col1' NAMEEND='col";
1967 file += tostr(cells_in_multicolumn(0));
1971 addNewlineAndDepth(file,++depth);
1974 if (IsLastCell(cell)) {
1975 addNewlineAndDepth(file,--depth);
1977 addNewlineAndDepth(file,--depth);
1979 addNewlineAndDepth(file, depth);
1981 addNewlineAndDepth(file,++depth);
1982 file += "<ENTRY ALIGN='";
1983 file += getDocBookAlign(cell+1);
1984 file += "' VALIGN='middle'";
1985 if (IsMultiColumn(cell+1)) {
1986 file += " NAMEST='col";
1987 file += tostr(column_of_cell(cell+1) + 1);
1988 file += "' NAMEEND='col";
1989 file += tostr(column_of_cell(cell+1) +
1990 cells_in_multicolumn(cell+1));
1994 addNewlineAndDepth(file,++depth);
1997 addNewlineAndDepth(file,--depth);
1999 addNewlineAndDepth(file, depth);
2000 file += "<ENTRY ALIGN='";
2001 file += getDocBookAlign(cell+1);
2002 file += "' VALIGN='middle'";
2003 if (IsMultiColumn(cell+1)) {
2004 file += " NAMEST='col";
2005 file += tostr(column_of_cell(cell+1) + 1);
2006 file += "' NAMEEND='col";
2007 file += tostr(column_of_cell(cell+1) +
2008 cells_in_multicolumn(cell+1));
2012 addNewlineAndDepth(file,++depth);
2022 bool LyXTable::IsMultiColumn(int cell)
2024 int fvcell = FirstVirtualCell(cell);
2026 return (cellinfo_of_cell(fvcell)->multicolumn != LyXTable::CELL_NORMAL);
2030 LyXTable::cellstruct* LyXTable::cellinfo_of_cell(int cell)
2032 int row = row_of_cell(cell);
2033 int column = column_of_cell(cell);
2034 return &cell_info[row][column];
2038 void LyXTable::SetMultiColumn(int cell, int number)
2040 int fvcell = FirstVirtualCell(cell);
2041 int new_width = cellinfo_of_cell(fvcell)->width_of_cell;
2043 cellinfo_of_cell(fvcell)->multicolumn = LyXTable::CELL_BEGIN_OF_MULTICOLUMN;
2044 cellinfo_of_cell(fvcell)->alignment = column_info[column_of_cell(fvcell)].alignment;
2045 cellinfo_of_cell(fvcell)->top_line = row_info[row_of_cell(fvcell)].top_line;
2046 cellinfo_of_cell(fvcell)->bottom_line = row_info[row_of_cell(fvcell)].bottom_line;
2047 for (number--; number > 0; --number) {
2048 cellinfo_of_cell(fvcell+number)->multicolumn =
2049 LyXTable::CELL_PART_OF_MULTICOLUMN;
2050 new_width += cellinfo_of_cell(fvcell+number)->width_of_cell;
2052 set_row_column_number_info();
2053 SetWidthOfCell(fvcell, new_width);
2057 int LyXTable::cells_in_multicolumn(int cell)
2059 int row = row_of_cell(cell);
2060 int column = column_of_cell(cell);
2063 while (column < columns && cell_info[row][column].multicolumn
2064 == LyXTable::CELL_PART_OF_MULTICOLUMN){
2072 int LyXTable::UnsetMultiColumn(int cell)
2074 int fvcell = FirstVirtualCell(cell);
2075 int row = row_of_cell(fvcell);
2076 int column = column_of_cell(fvcell);
2080 if (cell_info[row][column].multicolumn
2081 == LyXTable::CELL_BEGIN_OF_MULTICOLUMN){
2082 cell_info[row][column].multicolumn = LyXTable::CELL_NORMAL;
2084 while (column < columns &&
2085 cell_info[row][column].multicolumn
2086 == LyXTable::CELL_PART_OF_MULTICOLUMN){
2087 cell_info[row][column].multicolumn =
2088 LyXTable::CELL_NORMAL;
2093 set_row_column_number_info();
2098 void LyXTable::delete_column(int column)
2101 columnstruct * column_info2 = new columnstruct[columns-1];
2103 for (i = 0; i < column; ++i) {
2104 column_info2[i] = column_info[i];
2106 for (i = column; i < columns - 1; ++i) {
2107 column_info2[i] = column_info[i + 1];
2110 delete[] column_info;
2111 column_info = column_info2;
2113 for (i = 0; i < rows; ++i) {
2114 cellstruct * tmp = cell_info[i];
2115 cell_info[i] = new cellstruct[columns - 1];
2116 for (j = 0; j < column; ++j) {
2117 cell_info[i][j] = tmp[j];
2119 for (j = column; j < columns - 1; ++j) {
2120 cell_info[i][j] = tmp[j + 1];
2130 void LyXTable::SetLongTable(int what)
2132 is_long_table = what;
2136 bool LyXTable::IsLongTable()
2138 return is_long_table;
2141 void LyXTable::SetRotateTable(int what)
2146 bool LyXTable::RotateTable()
2151 void LyXTable::SetRotateCell(int cell, int what)
2153 cellinfo_of_cell(cell)->rotate = what;
2156 bool LyXTable::RotateCell(int cell)
2158 return cellinfo_of_cell(cell)->rotate;
2161 bool LyXTable::NeedRotating()
2165 for (int i = 0; i < rows; ++i) {
2166 for (int j = 0; j < columns; ++j) {
2167 if (cell_info[i][j].rotate)
2174 void LyXTable::AppendContRow(int cell)
2176 int row = row_of_cell(cell)+1;
2178 if (!RowHasContRow(cell) || (CellHasContRow(cell)>= 0))
2180 row_info[row].is_cont_row = true;
2181 row_info[row].top_line = false;
2182 cell_info[row-1][column_of_cell(cell)].has_cont_row = true;
2186 bool LyXTable::IsContRow(int cell)
2188 return row_info[row_of_cell(cell)].is_cont_row;
2191 int LyXTable::CellHasContRow(int cell)
2193 int row = row_of_cell(cell);
2195 if (VeryLastRow(cell))
2197 if (cell_info[row][column_of_cell(cell)].has_cont_row)
2198 return cell_info[row+1][column_of_cell(cell)].cellno;
2202 bool LyXTable::RowHasContRow(int cell)
2204 int row = row_of_cell(cell) + 1;
2207 return row_info[row].is_cont_row;
2211 int LyXTable::FirstVirtualCell(int cell)
2213 if (!IsContRow(cell))
2215 int row = row_of_cell(cell);
2216 int column = column_of_cell(cell);
2217 for(; (row > 0) && IsContRow(cell_info[row][column].cellno); --row)
2219 return cell_info[row][column].cellno;
2223 int LyXTable::NextVirtualCell(int cell)
2225 if (!IsContRow(cell))
2227 int row = row_of_cell(cell);
2228 for(;(row < rows - 1) && IsContRow(cell_info[row][0].cellno); ++row)
2230 // what if(row >= rows) ?
2231 return cell_info[row][0].cellno;
2235 bool LyXTable::ShouldBeVeryLastCell(int cell)
2236 // "very last cell" ..of what? the row? the table?
2237 // "Cell" in this context appears to not count `virtual' cells
2239 int fcell = cell + 1;
2241 if (cell == GetNumberOfCells() - 1)
2242 return true; // not really sure if I should return false here
2243 if (!IsContRow(fcell))
2245 while((fcell < GetNumberOfCells() - 1) && IsContRow(fcell))
2247 if (fcell < GetNumberOfCells() - 1)
2252 bool LyXTable::ShouldBeVeryLastRow(int cell)
2254 if (CellHasContRow(cell)>= 0)
2256 int row = row_of_cell(cell) + 1;
2257 int column = column_of_cell(cell);
2258 while((row < rows) && IsContRow(cell_info[row][column].cellno))
2261 return false; // found another valid row
2262 // I do not have any valid row after the actual
2266 int LyXTable::GetCellAbove(int cell)
2268 int row = row_of_cell(cell);
2271 return cell_info[row-1][column_of_cell(cell)].cellno;
2275 int LyXTable::GetCellNumber(int column, int row)
2277 if (column >= columns)
2278 column = columns - 1;
2279 else if (column < 0)
2286 return cell_info[row][column].cellno;
2289 void LyXTable::SetLinebreaks(int cell, bool what)
2291 cellinfo_of_cell(FirstVirtualCell(cell))->linebreaks = what;
2294 bool LyXTable::Linebreaks(int cell)
2296 int fvcell = FirstVirtualCell(cell);
2298 if (column_info[column_of_cell(fvcell)].p_width.empty() &&
2299 !(IsMultiColumn(fvcell) && !cellinfo_of_cell(fvcell)->p_width.empty()))
2301 return cellinfo_of_cell(fvcell)->linebreaks;
2304 void LyXTable::SetLTHead(int cell, bool first)
2306 int row = row_of_cell(cell);
2309 if (row == endfirsthead)
2321 bool LyXTable::RowOfLTHead(int cell)
2323 if ((endhead+1) > rows)
2325 return (row_of_cell(cell) == endhead);
2328 bool LyXTable::RowOfLTFirstHead(int cell)
2330 if ((endfirsthead+1) > rows)
2332 return (row_of_cell(cell) == endfirsthead);
2335 void LyXTable::SetLTFoot(int cell, bool last)
2337 int row = row_of_cell(cell);
2340 if (row == endlastfoot)
2352 bool LyXTable::RowOfLTFoot(int cell)
2354 if ((endfoot+1) > rows) {
2358 return (row_of_cell(cell) == endfoot);
2361 bool LyXTable::RowOfLTLastFoot(int cell)
2363 if ((endlastfoot+1) > rows)
2365 return (row_of_cell(cell) == endlastfoot);
2368 void LyXTable::SetLTNewPage(int cell, bool what)
2370 row_info[row_of_cell(cell)].newpage = what;
2373 bool LyXTable::LTNewPage(int cell)
2375 return row_info[row_of_cell(cell)].newpage;