1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * ======================================================
17 #pragma implementation
24 #include "lyx_gui_misc.h"
26 #include "BufferView.h"
28 #include "LaTeXFeatures.h"
29 #include "support/lstrings.h"
30 #include "support/lyxmanip.h"
31 #include "insets/insettabular.h"
32 #include "insets/insettext.h"
41 static int const WIDTH_OF_LINE = 5;
43 extern BufferView * current_view;
45 /// Define a few methods for the inner structs
47 LyXTabular::cellstruct::cellstruct()
49 cellno = 0; //should be initilaized correctly later.
51 multicolumn = LyXTabular::CELL_NORMAL;
52 alignment = LYX_ALIGN_CENTER;
60 LyXTabular::rowstruct::rowstruct()
70 LyXTabular::columnstruct::columnstruct()
74 alignment = LYX_ALIGN_CENTER;
80 LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg)
83 Init(rows_arg, columns_arg);
87 LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt)
90 Init(lt.rows_, lt.columns_);
96 LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex)
103 LyXTabular::~LyXTabular()
106 delete[] columnofcell;
110 LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
112 // If this and lt is not of the same size we have a serious bug
113 // So then it is ok to throw an exception, or for now
115 Assert(rows_ == lt.rows_ && columns_ == lt.columns_);
117 cell_info = lt.cell_info;
118 row_info = lt.row_info;
119 column_info = lt.column_info;
121 // long tabular stuff
122 SetLongTabular(lt.is_long_tabular);
123 endhead = lt.endhead;
124 endfoot = lt.endfoot;
125 endfirsthead = lt.endfirsthead;
126 endlastfoot = lt.endlastfoot;
136 LyXTabular * LyXTabular::Clone(InsetTabular * inset)
138 LyXTabular * result = new LyXTabular(inset, *this);
140 // don't know if this is good but I need to Clone also
141 // the text-insets here, this is for the Undo-facility!
144 for(i=0; i < rows_; ++i) {
145 for(j=0; j < columns_; ++j) {
146 result->cell_info[i][j].inset = cell_info[i][j].inset;
147 result->cell_info[i][j].inset.setOwner(inset);
154 /* activates all lines and sets all widths to 0 */
155 void LyXTabular::Init(int rows_arg, int columns_arg)
161 columns_ = columns_arg;
162 row_info = vector<rowstruct>(rows_, rowstruct());
163 column_info = vector<columnstruct>(columns_, columnstruct());
164 cell_info = vector<vector<cellstruct> >
165 (rows_, vector<cellstruct>(columns_, cellstruct()));
167 // Jürgen, use iterators.
168 for (i = 0; i < rows_; ++i) {
169 for (j = 0; j < columns_; ++j) {
170 cell_info[i][j].inset.setOwner(owner_);
171 cell_info[i][j].inset.SetDrawFrame(0, InsetText::LOCKED);
172 cell_info[i][j].cellno = cellno++;
175 row_info[i-1].bottom_line = true;
176 row_info[0].bottom_line = true;
178 for (i = 0; i < columns_; ++i) {
179 calculate_width_of_column(i);
181 column_info[columns_-1].right_line = true;
183 calculate_width_of_tabular();
187 set_row_column_number_info();
188 is_long_tabular = false;
197 void LyXTabular::AppendRow(int cell )
201 int row = row_of_cell(cell);
203 row_vector::iterator rit = row_info.begin() + row;
204 row_info.insert(rit, rowstruct());
207 cell_vvector::iterator cit = cell_info.begin() + row;
208 cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
210 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
213 for(int i = 0; i <= row; ++i) {
214 for(int j = 0; j < columns_; ++j) {
215 c_info[i][j] = cell_info[i][j];
218 for(int i = row+1; i < rows_; ++i) {
219 for(int j = 0; j < columns_; ++j) {
220 c_info[i][j] = cell_info[i-1][j];
225 for (int j = 0; j < columns_; ++j) {
226 cell_info[row][j].inset.clear();
233 void LyXTabular::DeleteRow(int row)
237 row_info.erase(row_info.begin() + row); //&row_info[row]);
238 cell_info.erase(cell_info.begin() + row); //&cell_info[row]);
244 void LyXTabular::AppendColumn(int cell)
248 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
250 int column = column_of_cell(cell);
252 column_vector::iterator cit = column_info.begin() + column + 1;
253 column_info.insert(cit, columnstruct());
255 for (i = 0; i < rows_; ++i) {
256 for (j = 0; j <= column; ++j) {
257 c_info[i][j] = cell_info[i][j];
259 for (j = column+1; j < columns_; ++j) {
260 c_info[i][j] = cell_info[i][j-1];
262 // care about multicolumns
263 if (cell_info[i][column+1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
264 cell_info[i][column+1].multicolumn = CELL_PART_OF_MULTICOLUMN;
266 if (((column+1) == columns_) ||
267 (cell_info[i][column+2].multicolumn != CELL_PART_OF_MULTICOLUMN)) {
268 cell_info[i][column+1].multicolumn = LyXTabular::CELL_NORMAL;
273 for (i = 0; i < rows_; ++i) {
274 cell_info[i][column].inset.clear();
280 void LyXTabular::DeleteColumn(int column)
284 column_info.erase(column_info.begin() + column);
285 for (int i = 0; i < rows_; ++i) {
286 cell_info[i].erase(cell_info[i].begin() + column);
293 void LyXTabular::Reinit()
299 // Jürgen, use iterators.
300 for (; i < rows_; ++i) {
301 for (j = 0; j < columns_; ++j) {
302 cell_info[i][j].width_of_cell = 0;
303 cell_info[i][j].inset.setOwner(owner_);
307 for (i = 0; i < columns_; ++i) {
308 calculate_width_of_column(i);
310 calculate_width_of_tabular();
312 set_row_column_number_info();
316 void LyXTabular::set_row_column_number_info()
322 for (; row < rows_; ++row) {
323 for (column = 0; column<columns_; ++column) {
324 if (cell_info[row][column].multicolumn
325 != LyXTabular::CELL_PART_OF_MULTICOLUMN)
327 cell_info[row][column].cellno = numberofcells;
330 ++numberofcells; // because this is one more than as we start from 0
335 rowofcell = new int[numberofcells];
336 delete [] columnofcell;
337 columnofcell = new int[numberofcells];
339 while (c < numberofcells && row < rows_ && column < columns_) {
341 columnofcell[c] = column;
345 } while (column < columns_ &&
346 cell_info[row][column].multicolumn
347 == LyXTabular::CELL_PART_OF_MULTICOLUMN);
348 if (column == columns_) {
353 for (row = 0; row < rows_; ++row) {
354 for (column = 0; column<columns_; ++column) {
355 if (IsPartOfMultiColumn(row,column))
357 cell_info[row][column].inset.SetAutoBreakRows(
358 !GetPWidth(GetCellNumber(row, column)).empty());
364 int LyXTabular::GetNumberOfCells() const
366 return numberofcells;
370 int LyXTabular::NumberOfCellsInRow(int cell) const
372 int row = row_of_cell(cell);
374 for (int i = 0; i < columns_; ++i) {
375 if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
382 /* returns 1 if there is a topline, returns 0 if not */
383 bool LyXTabular::TopLine(int cell, bool onlycolumn) const
385 int row = row_of_cell(cell);
387 if (!onlycolumn && IsMultiColumn(cell))
388 return cellinfo_of_cell(cell)->top_line;
389 return row_info[row].top_line;
393 bool LyXTabular::BottomLine(int cell, bool onlycolumn) const
395 //no bottom line underneath non-existent cells if you please
396 if(cell >= numberofcells)
399 if (!onlycolumn && IsMultiColumn(cell))
400 return cellinfo_of_cell(cell)->bottom_line;
401 return row_info[row_of_cell(cell)].bottom_line;
405 bool LyXTabular::LeftLine(int cell, bool onlycolumn) const
407 if (!onlycolumn && IsMultiColumn(cell))
408 return cellinfo_of_cell(cell)->left_line;
409 return column_info[column_of_cell(cell)].left_line;
413 bool LyXTabular::RightLine(int cell, bool onlycolumn) const
415 if (!onlycolumn && IsMultiColumn(cell))
416 return cellinfo_of_cell(cell)->right_line;
417 return column_info[right_column_of_cell(cell)].right_line;
421 bool LyXTabular::TopAlreadyDrawed(int cell) const
423 if (GetAdditionalHeight(cell))
425 int row = row_of_cell(cell);
427 int column = column_of_cell(cell);
430 && cell_info[row][column].multicolumn
431 == LyXTabular::CELL_PART_OF_MULTICOLUMN)
433 if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL)
434 return row_info[row].bottom_line;
436 return cell_info[row][column].bottom_line;
442 bool LyXTabular::LeftAlreadyDrawed(int cell) const
444 int column = column_of_cell(cell);
446 int row = row_of_cell(cell);
448 (cell_info[row][column].multicolumn ==
449 LyXTabular::CELL_PART_OF_MULTICOLUMN));
450 if (GetAdditionalWidth(cell_info[row][column].cellno))
452 return column_info[column].right_line;
458 bool LyXTabular::IsLastRow(int cell) const
460 return (row_of_cell(cell) == rows_ - 1);
464 int LyXTabular::GetAdditionalHeight(int cell) const
466 int row = row_of_cell(cell);
469 int top = 1; // bool top = true; ??
470 int bottom = 1; // bool bottom = true; ??
473 for (column = 0; column < columns_ - 1 && bottom; ++column) {
474 switch (cell_info[row - 1][column].multicolumn) {
475 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
476 bottom = cell_info[row - 1][column].bottom_line;
478 case LyXTabular::CELL_NORMAL:
479 bottom = row_info[row - 1].bottom_line;
482 for (column = 0; column < columns_ - 1 && top; ++column) {
483 switch (cell_info[row][column].multicolumn){
484 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
485 top = cell_info[row][column].top_line;
487 case LyXTabular::CELL_NORMAL:
488 top = row_info[row].top_line;
492 return WIDTH_OF_LINE;
497 int LyXTabular::GetAdditionalWidth(int cell) const
499 // internally already set in SetWidthOfCell
500 // used to get it back in text.C
501 int col = right_column_of_cell(cell);
502 if (col < columns_ - 1 && column_info[col].right_line &&
503 column_info[col+1].left_line)
504 return WIDTH_OF_LINE;
510 // returns the maximum over all rows
511 int LyXTabular::GetWidthOfColumn(int cell) const
513 int column1 = column_of_cell(cell);
514 int column2 = right_column_of_cell(cell);
517 for (; i <= column2; ++i) {
518 result += column_info[i].width_of_column;
524 int LyXTabular::GetWidthOfTabular() const
526 return width_of_tabular;
530 /* returns 1 if a complete update is necessary, otherwise 0 */
531 bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
533 if (!IsMultiColumn(cell))
536 int row = row_of_cell(cell);
537 int column1 = column_of_cell(cell);
538 int column2 = right_column_of_cell(cell);
540 // first set columns to 0 so we can calculate the right width
542 for (; i <= column2; ++i) {
543 cell_info[row][i].width_of_cell = 0;
545 // set the width to MAX_WIDTH until width > 0
546 int width = (new_width + 2 * WIDTH_OF_LINE);
547 for (i = column1; (i < column2) && (width>column_info[i].width_of_column);
550 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
551 width -= column_info[i].width_of_column;
554 cell_info[row][i].width_of_cell = width;
560 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
562 int row = row_of_cell(cell);
563 int column1 = column_of_cell(cell);
564 int column2 = right_column_of_cell(cell);
566 // first set columns to 0 so we can calculate the right width
568 for (; i <= column2; ++i)
569 cell_info[row][i].width_of_cell = 0;
570 for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
572 if (i < numberofcells)
573 recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
574 SetWidthOfMulticolCell(cell, new_width);
578 /* returns 1 if a complete update is necessary, otherwise 0 */
579 bool LyXTabular::SetWidthOfCell(int cell, int new_width)
581 int row = row_of_cell(cell);
582 int column1 = column_of_cell(cell);
586 if (GetWidthOfCell(cell) == (new_width+2*WIDTH_OF_LINE))
588 if (IsMultiColumn(cell, true)) {
589 tmp = SetWidthOfMulticolCell(cell, new_width);
591 width = (new_width + 2*WIDTH_OF_LINE);
592 cell_info[row][column1].width_of_cell = width;
593 if (column_info[column1].right_line && (column1 < columns_-1) &&
594 column_info[column1+1].left_line) // additional width
595 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
596 tmp = calculate_width_of_column_NMC(column1);
600 for(i = 0; i<columns_;++i)
601 calculate_width_of_column_NMC(i);
602 for(i = 0; (i<numberofcells) && !IsMultiColumn(i); ++i)
605 recalculateMulticolCells(i, GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
606 for(i = 0; i<columns_;++i)
607 calculate_width_of_column(i);
608 calculate_width_of_tabular();
615 bool LyXTabular::SetAlignment(int cell, char align, bool onlycolumn)
617 if (!IsMultiColumn(cell) || onlycolumn)
618 column_info[column_of_cell(cell)].alignment = align;
620 cellinfo_of_cell(cell)->alignment = align;
625 bool LyXTabular::SetVAlignment(int cell, char align, bool onlycolumn)
627 if (!IsMultiColumn(cell) || onlycolumn)
628 column_info[column_of_cell(cell)].valignment = align;
630 cellinfo_of_cell(cell)->valignment = align;
635 bool LyXTabular::SetColumnPWidth(int cell, string const & width)
637 bool flag = !width.empty();
639 int j = column_of_cell(cell);
641 column_info[j].p_width = width;
642 if (flag) // do this only if there is a width
643 SetAlignment(cell, LYX_ALIGN_LEFT);
644 for(int i=0; i < rows_; ++i) {
645 c = GetCellNumber(i, j);
646 flag = !GetPWidth(c).empty(); // because of multicolumns!
647 GetCellInset(c)->SetAutoBreakRows(flag);
653 bool LyXTabular::SetMColumnPWidth(int cell, string const & width)
655 bool flag = !width.empty();
657 cellinfo_of_cell(cell)->p_width = width;
658 if (IsMultiColumn(cell)) {
659 GetCellInset(cell)->SetAutoBreakRows(flag);
666 bool LyXTabular::SetAlignSpecial(int cell, string const & special, int what)
668 if (what == SET_SPECIAL_MULTI)
669 cellinfo_of_cell(cell)->align_special = special;
671 column_info[column_of_cell(cell)].align_special = special;
676 bool LyXTabular::SetAllLines(int cell, bool line)
678 SetTopLine(cell, line);
679 SetBottomLine(cell, line);
680 SetRightLine(cell, line);
681 SetLeftLine(cell, line);
686 bool LyXTabular::SetTopLine(int cell, bool line, bool onlycolumn)
688 int row = row_of_cell(cell);
690 if (onlycolumn || !IsMultiColumn(cell))
691 row_info[row].top_line = line;
693 cellinfo_of_cell(cell)->top_line = line;
698 bool LyXTabular::SetBottomLine(int cell, bool line, bool onlycolumn)
700 if (onlycolumn || !IsMultiColumn(cell))
701 row_info[row_of_cell(cell)].bottom_line = line;
703 cellinfo_of_cell(cell)->bottom_line = line;
708 bool LyXTabular::SetLeftLine(int cell, bool line, bool onlycolumn)
710 if (onlycolumn || !IsMultiColumn(cell))
711 column_info[column_of_cell(cell)].left_line = line;
713 cellinfo_of_cell(cell)->left_line = line;
718 bool LyXTabular::SetRightLine(int cell, bool line, bool onlycolumn)
720 if (onlycolumn || !IsMultiColumn(cell))
721 column_info[right_column_of_cell(cell)].right_line = line;
723 cellinfo_of_cell(cell)->right_line = line;
728 char LyXTabular::GetAlignment(int cell, bool onlycolumn) const
730 if (!onlycolumn && IsMultiColumn(cell))
731 return cellinfo_of_cell(cell)->alignment;
733 return column_info[column_of_cell(cell)].alignment;
737 char LyXTabular::GetVAlignment(int cell, bool onlycolumn) const
739 if (!onlycolumn && IsMultiColumn(cell))
740 return cellinfo_of_cell(cell)->valignment;
742 return column_info[column_of_cell(cell)].valignment;
746 string LyXTabular::GetPWidth(int cell) const
748 if (IsMultiColumn(cell))
749 return cellinfo_of_cell(cell)->p_width;
750 return column_info[column_of_cell(cell)].p_width;
754 string LyXTabular::GetColumnPWidth(int cell) const
756 return column_info[column_of_cell(cell)].p_width;
760 string LyXTabular::GetMColumnPWidth(int cell) const
762 if (IsMultiColumn(cell))
763 return cellinfo_of_cell(cell)->p_width;
768 string LyXTabular::GetAlignSpecial(int cell, int what) const
770 if (what == SET_SPECIAL_MULTI)
771 return cellinfo_of_cell(cell)->align_special;
772 return column_info[column_of_cell(cell)].align_special;
776 int LyXTabular::GetWidthOfCell(int cell) const
778 int row = row_of_cell(cell);
779 int column1 = column_of_cell(cell);
780 int column2 = right_column_of_cell(cell);
783 for (; i <= column2; ++i) {
784 result += cell_info[row][i].width_of_cell;
789 int LyXTabular::GetBeginningOfTextInCell(int cell) const
793 switch (GetAlignment(cell)){
794 case LYX_ALIGN_CENTER:
795 x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
797 case LYX_ALIGN_RIGHT:
798 x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
799 // + GetAdditionalWidth(cell);
801 default: /* LYX_ALIGN_LEFT: nothing :-) */
811 bool LyXTabular::IsFirstCellInRow(int cell) const
813 return (column_of_cell(cell) == 0);
817 int LyXTabular::GetFirstCellInRow(int row) const
821 return cell_info[row][0].cellno;
824 bool LyXTabular::IsLastCellInRow(int cell) const
826 return (right_column_of_cell(cell) == (columns_ - 1));
830 int LyXTabular::GetLastCellInRow(int row) const
834 return cell_info[row][columns_-1].cellno;
838 bool LyXTabular::calculate_width_of_column(int column)
840 int old_column_width = column_info[column].width_of_column;
843 for (int i = 0; i < rows_; ++i) {
844 maximum = max(cell_info[i][column].width_of_cell, maximum);
846 column_info[column].width_of_column = maximum;
847 return (column_info[column].width_of_column != old_column_width);
852 /// calculate the with of the column without regarding REAL MultiColumn
853 /// cells. This means MultiColumn-cells spanning more than 1 column.
855 bool LyXTabular::calculate_width_of_column_NMC(int column)
857 int old_column_width = column_info[column].width_of_column;
859 for (int i = 0; i < rows_; ++i) {
860 if (!IsMultiColumn(GetCellNumber(i, column), true) &&
861 (cell_info[i][column].width_of_cell > max)) {
862 max = cell_info[i][column].width_of_cell;
865 column_info[column].width_of_column = max;
866 return (column_info[column].width_of_column != old_column_width);
870 void LyXTabular::calculate_width_of_tabular()
872 width_of_tabular = 0;
873 for (int i = 0; i < columns_; ++i) {
874 width_of_tabular += column_info[i].width_of_column;
879 int LyXTabular::row_of_cell(int cell) const
881 if (cell >= numberofcells)
885 return rowofcell[cell];
889 int LyXTabular::column_of_cell(int cell) const
891 if (cell >= numberofcells)
895 return columnofcell[cell];
899 int LyXTabular::right_column_of_cell(int cell) const
901 int row = row_of_cell(cell);
902 int column = column_of_cell(cell);
903 while (column < (columns_ - 1) &&
904 cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
910 void LyXTabular::Write(Buffer const * buf, ostream & os) const
915 os << "<LyXTabular version=1 rows=" << rows_ << " columns=" << columns_ <<
917 // global longtable options
918 os << "<Features rotate=" << rotate <<
919 " islongtable=" << is_long_tabular <<
920 " endhead=" << endhead << " endfirsthead=" << endfirsthead <<
921 " endfoot=" << endfoot << " endlastfoot=" << endlastfoot <<
923 for (i = 0; i < rows_; ++i) {
924 os << "<Row topline=" << row_info[i].top_line <<
925 " bottomline=" << row_info[i].bottom_line <<
926 " newpage=" << row_info[i].newpage <<
928 for (j = 0; j < columns_; ++j) {
930 os << "<Column alignment=" << column_info[j].alignment <<
931 " valignment=" << column_info[j].valignment <<
932 " leftline=" << column_info[j].left_line <<
933 " rightline=" << column_info[j].right_line <<
934 " width=\"" << VSpace(column_info[j].p_width).asLyXCommand() <<
935 "\" special=\"" << column_info[j].align_special <<
938 os << "<Column>" << endl;
940 os << "<Cell multicolumn=" << cell_info[i][j].multicolumn <<
941 " alignment=" << cell_info[i][j].alignment <<
942 " valignment=" << cell_info[i][j].valignment <<
943 " topline=" << cell_info[i][j].top_line <<
944 " bottomline=" << cell_info[i][j].bottom_line <<
945 " leftline=" << cell_info[i][j].left_line <<
946 " rightline=" << cell_info[i][j].right_line <<
947 " rotate=" << cell_info[i][j].rotate <<
948 " usebox=" << cell_info[i][j].usebox <<
949 " width=\"" << cell_info[i][j].p_width <<
950 "\" special=\"" << cell_info[i][j].align_special <<
952 os << "\\begin_inset ";
953 cell_info[i][j].inset.Write(buf, os);
954 os << "\n\\end_inset " << endl;
955 os << "</Cell>" << endl;
956 os << "</Column>" << endl;
958 os << "</Row>" << endl;
960 os << "</LyXTabular>" << endl;
965 bool getTokenValue(string const str, const char * token, string & ret)
967 int pos = str.find(token);
968 char ch = str[pos+strlen(token)];
970 if ((pos < 0) || (ch != '='))
973 pos += strlen(token)+1;
975 if ((ch != '"') && (ch != '\'')) { // only read till next space
979 while((pos < int(str.length()-1)) && (str[++pos] != ch))
987 bool getTokenValue(string const str, const char * token, int & num)
990 int pos = str.find(token);
991 char ch = str[pos+strlen(token)];
993 if ((pos < 0) || (ch != '='))
996 pos += strlen(token)+1;
998 if ((ch != '"') && (ch != '\'')) { // only read till next space
1004 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1007 num = strToInt(ret);
1013 bool getTokenValue(string const str, const char * token, bool & flag)
1016 int pos = str.find(token);
1017 char ch = str[pos+strlen(token)];
1019 if ((pos < 0) || (ch != '='))
1022 pos += strlen(token)+1;
1024 if ((ch != '"') && (ch != '\'')) { // only read till next space
1030 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1033 flag = strToInt(ret);
1038 void l_getline(istream & is, string & str)
1046 void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
1049 istream & is = lex.getStream();
1051 l_getline(is, line);
1052 if (!prefixIs(line, "<LyXTabular ")) {
1053 OldFormatRead(lex, line);
1060 if (!getTokenValue(line, "version", version))
1062 if (!getTokenValue(line, "rows", rows_arg))
1064 if (!getTokenValue(line, "columns", columns_arg))
1066 Init(rows_arg, columns_arg);
1067 l_getline(is, line);
1068 if (!prefixIs(line, "<Features ")) {
1069 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
1070 line << ")" << endl;
1073 (void)getTokenValue(line, "islongtable", is_long_tabular);
1074 (void)getTokenValue(line, "endhead", endhead);
1075 (void)getTokenValue(line, "endfirsthead", endfirsthead);
1076 (void)getTokenValue(line, "endfoot", endfoot);
1077 (void)getTokenValue(line, "endlastfoot", endlastfoot);
1079 for(i = 0; i < rows_; ++i) {
1080 l_getline(is, line);
1081 if (!prefixIs(line, "<Row ")) {
1082 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
1083 line << ")" << endl;
1086 (void)getTokenValue(line, "topline", row_info[i].top_line);
1087 (void)getTokenValue(line, "bottomline", row_info[i].bottom_line);
1088 (void)getTokenValue(line, "newpage", row_info[i].newpage);
1089 for (j = 0; j < columns_; ++j) {
1091 if (!prefixIs(line,"<Column")) {
1092 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
1093 line << ")" << endl;
1097 (void)getTokenValue(line, "alignment", column_info[j].alignment);
1098 (void)getTokenValue(line, "valignment", column_info[j].valignment);
1099 (void)getTokenValue(line, "leftline", column_info[j].left_line);
1100 (void)getTokenValue(line, "rightline", column_info[j].right_line);
1101 (void)getTokenValue(line, "width", column_info[j].p_width);
1102 (void)getTokenValue(line, "special", column_info[j].align_special);
1104 l_getline(is, line);
1105 if (!prefixIs(line, "<Cell")) {
1106 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
1107 line << ")" << endl;
1110 (void)getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1111 (void)getTokenValue(line, "alignment", cell_info[i][j].alignment);
1112 (void)getTokenValue(line, "valignment", cell_info[i][j].valignment);
1113 (void)getTokenValue(line, "topline", cell_info[i][j].top_line);
1114 (void)getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1115 (void)getTokenValue(line, "leftline", cell_info[i][j].left_line);
1116 (void)getTokenValue(line, "rightline", cell_info[i][j].right_line);
1117 (void)getTokenValue(line, "rotate", cell_info[i][j].rotate);
1118 (void)getTokenValue(line, "usebox", cell_info[i][j].usebox);
1119 (void)getTokenValue(line, "width", cell_info[i][j].p_width);
1120 (void)getTokenValue(line, "special", cell_info[i][j].align_special);
1121 l_getline(is, line);
1122 if (prefixIs(line, "\\begin_inset")) {
1123 cell_info[i][j].inset.Read(buf, lex);
1124 l_getline(is, line);
1126 if (line != "</Cell>") {
1127 lyxerr << "Wrong tabular format (expected </Cell> got" <<
1128 line << ")" << endl;
1131 l_getline(is, line);
1132 if (line != "</Column>") {
1133 lyxerr << "Wrong tabular format (expected </Column> got" <<
1134 line << ")" << endl;
1138 l_getline(is, line);
1139 if (line != "</Row>") {
1140 lyxerr << "Wrong tabular format (expected </Row> got" <<
1141 line << ")" << endl;
1145 while (line != "</LyXTabular>") {
1146 l_getline(is, line);
1148 set_row_column_number_info();
1152 void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
1157 int columns_arg = 0;
1158 int is_long_tabular_arg = false;
1159 int rotate_arg = false;
1169 istream & is = lex.getStream();
1172 version = atoi(s.c_str() + 8);
1176 vector<int> cont_row_info;
1179 lyxerr << "Tabular format < 5 is not supported anymore\n"
1180 "Get an older version of LyX (< 1.1.x) for conversion!"
1182 WriteAlert(_("Warning:"),
1183 _("Tabular format < 5 is not supported anymore\n"),
1184 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1186 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1187 >> rotate_arg >> a >> b >> c >> d;
1189 is >> rows_arg >> columns_arg;
1190 Init(rows_arg, columns_arg);
1191 cont_row_info = vector<int>(rows_arg);
1192 SetLongTabular(is_long_tabular_arg);
1193 SetRotateTabular(rotate_arg);
1195 for (i = 0; i < rows_; ++i) {
1197 cont_row_info[i] = false;
1199 for (i = 0; i < columns_; ++i) {
1202 for (i = 0; i < rows_; ++i) {
1203 for (j = 0; j < columns_; ++j) {
1208 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1209 >> rotate_arg >> a >> b >> c >> d;
1210 Init(rows_arg, columns_arg);
1211 cont_row_info = vector<int>(rows_arg);
1212 SetLongTabular(is_long_tabular_arg);
1213 SetRotateTabular(rotate_arg);
1218 for (i = 0; i < rows_; ++i) {
1219 a = b = c = d = e = f = g = h = 0;
1220 is >> a >> b >> c >> d;
1221 row_info[i].top_line = a;
1222 row_info[i].bottom_line = b;
1223 cont_row_info[i] = c;
1224 row_info[i].newpage = d;
1226 for (i = 0; i < columns_; ++i) {
1230 char ch; // skip '"'
1232 getline(is, s1, '"');
1233 is >> ch; // skip '"'
1234 getline(is, s2, '"');
1235 column_info[i].alignment = static_cast<char>(a);
1236 column_info[i].left_line = b;
1237 column_info[i].right_line = c;
1238 column_info[i].p_width = s1;
1239 column_info[i].align_special = s2;
1241 for (i = 0; i < rows_; ++i) {
1242 for (j = 0; j < columns_; ++j) {
1245 is >> a >> b >> c >> d >> e >> f >> g;
1247 is >> ch; // skip '"'
1248 getline(is, s1, '"');
1249 is >> ch; // skip '"'
1250 getline(is, s2, '"');
1251 cell_info[i][j].multicolumn = static_cast<char>(a);
1252 cell_info[i][j].alignment = static_cast<char>(b);
1253 cell_info[i][j].top_line = static_cast<char>(c);
1254 cell_info[i][j].bottom_line = static_cast<char>(d);
1255 cell_info[i][j].rotate = static_cast<bool>(f);
1256 cell_info[i][j].usebox = static_cast<bool>(g);
1257 cell_info[i][j].align_special = s1;
1258 cell_info[i][j].p_width = s2;
1262 set_row_column_number_info();
1264 LyXParagraph * par = new LyXParagraph;
1265 LyXParagraph * return_par = 0;
1267 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1268 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
1270 string token, tmptok;
1273 LyXFont font(LyXFont::ALL_SANE);
1275 while (lex.IsOK()) {
1277 token = lex.GetString();
1280 if ((token == "\\layout") || (token == "\\end_float") ||
1281 (token == "\\end_deeper"))
1283 lex.pushToken(token);
1286 if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
1298 lex.pushToken(token);
1302 lex.printError("New Paragraph allocated! This should not happen!");
1303 lex.pushToken(token);
1309 // now we have the par we should fill the insets with this!
1311 InsetText * inset = GetCellInset(cell);
1314 for(int i = 0; i < par->Last(); ++i) {
1315 if (par->IsNewline(i)) {
1317 if (cell > GetNumberOfCells()) {
1318 lyxerr << "Some error in reading old table format occured!" <<
1319 endl << "Terminating when reading cell[" << cell << "]!" <<
1323 row = row_of_cell(cell);
1324 if (cont_row_info[row]) {
1326 cont_row_info.erase(cont_row_info.begin() + row); //&cont_row_info[row]);
1327 while(!IsFirstCellInRow(--cell));
1329 inset = GetCellInset(cell);
1332 inset = GetCellInset(cell);
1333 row = row_of_cell(cell);
1334 if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox)
1336 // insert a space instead
1338 par->InsertChar(i, ' ');
1341 par->CopyIntoMinibuffer(current_view->buffer()->params, i);
1342 inset->par->InsertFromMinibuffer(inset->par->Last());
1348 char const * LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
1350 int i = isColumn ? cell : column_of_cell(cell);
1355 //i = column_of_cell(cell);
1356 if (!isColumn && IsMultiColumn(cell)) {
1357 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1358 return cellinfo_of_cell(cell)->align_special.c_str();
1360 switch (GetAlignment(cell)) {
1361 case LYX_ALIGN_LEFT:
1363 case LYX_ALIGN_RIGHT:
1370 if (!column_info[i].align_special.empty()) {
1371 return column_info[i].align_special.c_str();
1373 #ifdef IGNORE_THIS_FOR_NOW
1374 else if (!column_info[i].p_width.empty()) {
1376 file += column_info[i].p_width;
1381 switch (column_info[i].alignment) {
1382 case LYX_ALIGN_LEFT:
1384 case LYX_ALIGN_RIGHT:
1394 // cell <0 will tex the preamble
1395 // returns the number of printed newlines
1396 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1400 //int tmp; // tmp2; // unused
1401 int nvcell; // fcell; // unused
1402 if (IsLastCell(cell)) {
1403 os << newlineAndDepth(--depth)
1405 << newlineAndDepth(--depth)
1407 << newlineAndDepth(--depth)
1409 << newlineAndDepth(--depth);
1410 if (is_long_tabular)
1414 << newlineAndDepth(--depth);
1420 if (is_long_tabular)
1426 << "' COLSEP='1' ROWSEP='1'>"
1427 << newlineAndDepth(++depth);
1429 for (i = 0; i < columns_; ++i) {
1430 os << "<COLSPEC ALIGN='"
1431 << GetDocBookAlign(i, true)
1437 if (i == (columns_-1)) {
1440 if (column_info[i].right_line ||
1441 column_info[i+1].left_line)
1447 << newlineAndDepth(depth);
1449 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1450 if (column_info[i].left_line)
1455 << newlineAndDepth(++depth)
1457 << newlineAndDepth(++depth)
1459 << GetDocBookAlign(0)
1461 if (IsMultiColumn(0)) {
1462 os << " NAMEST='col1' NAMEEND='col"
1463 << cells_in_multicolumn(0)
1467 << newlineAndDepth(++depth);
1470 if (IsLastCellInRow(cell)) {
1471 os << newlineAndDepth(--depth)
1473 << newlineAndDepth(--depth)
1475 << newlineAndDepth(depth)
1477 << newlineAndDepth(++depth)
1479 << GetDocBookAlign(cell + 1)
1480 << "' VALIGN='middle'";
1481 if (IsMultiColumn(cell + 1)) {
1482 os << " NAMEST='col"
1483 << column_of_cell(cell+1) + 1
1485 << column_of_cell(cell + 1) +
1486 cells_in_multicolumn(cell + 1)
1490 << newlineAndDepth(++depth);
1493 os << newlineAndDepth(--depth)
1495 << newlineAndDepth(depth)
1497 << GetDocBookAlign(cell + 1)
1498 << "' VALIGN='middle'";
1499 if (IsMultiColumn(cell + 1)) {
1500 os << " NAMEST='col"
1501 << column_of_cell(cell+1) + 1
1503 << column_of_cell(cell+1) +
1504 cells_in_multicolumn(cell+1)
1508 << newlineAndDepth(++depth);
1517 bool LyXTabular::IsMultiColumn(int cell, bool real) const
1519 return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&
1520 (cellinfo_of_cell(cell)->multicolumn !=LyXTabular::CELL_NORMAL));
1524 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1526 int row = row_of_cell(cell);
1527 int column = column_of_cell(cell);
1528 return &cell_info[row][column];
1532 void LyXTabular::SetMultiColumn(int cell, int number)
1534 cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1535 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1536 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1537 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1538 for (number--; number > 0; --number) {
1539 cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
1541 set_row_column_number_info();
1545 int LyXTabular::cells_in_multicolumn(int cell) const
1547 int row = row_of_cell(cell);
1548 int column = column_of_cell(cell);
1551 while ((column < columns_) &&
1552 cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
1561 int LyXTabular::UnsetMultiColumn(int cell)
1563 int row = row_of_cell(cell);
1564 int column = column_of_cell(cell);
1568 if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
1569 cell_info[row][column].multicolumn = CELL_NORMAL;
1571 while ((column < columns_) &&
1572 (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN))
1574 cell_info[row][column].multicolumn = CELL_NORMAL;
1579 set_row_column_number_info();
1584 void LyXTabular::SetLongTabular(int what)
1586 is_long_tabular = what;
1590 bool LyXTabular::IsLongTabular() const
1592 return is_long_tabular;
1596 void LyXTabular::SetRotateTabular(int what)
1602 bool LyXTabular::GetRotateTabular() const
1608 void LyXTabular::SetRotateCell(int cell, int what)
1610 cellinfo_of_cell(cell)->rotate = what;
1614 bool LyXTabular::GetRotateCell(int cell) const
1616 return cellinfo_of_cell(cell)->rotate;
1620 bool LyXTabular::NeedRotating() const
1624 for (int i = 0; i < rows_; ++i) {
1625 for (int j = 0; j < columns_; ++j) {
1626 if (cell_info[i][j].rotate)
1634 bool LyXTabular::IsLastCell(int cell) const
1636 if ((cell+1) < GetNumberOfCells())
1642 int LyXTabular::GetCellAbove(int cell) const
1644 if (row_of_cell(cell) > 0)
1645 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
1650 int LyXTabular::GetCellBelow(int cell) const
1652 if (row_of_cell(cell)+1 < rows_)
1653 return cell_info[row_of_cell(cell)+1][column_of_cell(cell)].cellno;
1658 int LyXTabular::GetLastCellAbove(int cell) const
1660 if (row_of_cell(cell) <= 0)
1662 if (!IsMultiColumn(cell))
1663 return GetCellAbove(cell);
1664 return cell_info[row_of_cell(cell)-1][right_column_of_cell(cell)].cellno;
1668 int LyXTabular::GetLastCellBelow(int cell) const
1670 if (row_of_cell(cell)+1 >= rows_)
1672 if (!IsMultiColumn(cell))
1673 return GetCellBelow(cell);
1674 return cell_info[row_of_cell(cell)+1][right_column_of_cell(cell)].cellno;
1678 int LyXTabular::GetCellNumber(int row, int column) const
1680 if (column >= columns_)
1681 column = columns_ - 1;
1682 else if (column < 0)
1689 return cell_info[row][column].cellno;
1693 void LyXTabular::SetUsebox(int cell, int what)
1695 cellinfo_of_cell(cell)->usebox = what;
1699 int LyXTabular::GetUsebox(int cell) const
1701 if (column_info[column_of_cell(cell)].p_width.empty() &&
1702 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
1704 if (cellinfo_of_cell(cell)->usebox > 1)
1705 return cellinfo_of_cell(cell)->usebox;
1706 return UseParbox(cell);
1710 void LyXTabular::SetLTHead(int cell, bool first)
1712 int row = row_of_cell(cell);
1713 int val = (row+1) * (column_of_cell(cell)? 1:-1);
1716 if (endfirsthead == val)
1729 bool LyXTabular::GetRowOfLTHead(int cell, int & row) const
1732 if (abs(endhead) > rows_)
1734 return (row_of_cell(cell) == (abs(endhead)-1));
1738 bool LyXTabular::GetRowOfLTFirstHead(int cell, int & row) const
1741 if (abs(endfirsthead) > rows_)
1743 return (row_of_cell(cell) == (abs(endfirsthead)-1));
1747 void LyXTabular::SetLTFoot(int cell, bool last)
1749 int row = row_of_cell(cell);
1750 int val = (row + 1) * (column_of_cell(cell)? 1:-1);
1753 if (endlastfoot == val)
1766 bool LyXTabular::GetRowOfLTFoot(int cell, int & row) const
1769 if ((endfoot+1) > rows_)
1771 return (row_of_cell(cell) == (abs(endfoot)-1));
1774 bool LyXTabular::GetRowOfLTLastFoot(int cell, int & row) const
1777 if (abs(endlastfoot) > rows_)
1779 return (row_of_cell(cell) == (abs(endlastfoot)-1));
1783 void LyXTabular::SetLTNewPage(int cell, bool what)
1785 row_info[row_of_cell(cell)].newpage = what;
1789 bool LyXTabular::GetLTNewPage(int cell) const
1791 return row_info[row_of_cell(cell)].newpage;
1795 bool LyXTabular::SetAscentOfRow(int row, int height)
1797 if ((row >= rows_) || (row_info[row].ascent_of_row == height))
1799 row_info[row].ascent_of_row = height;
1804 bool LyXTabular::SetDescentOfRow(int row, int height)
1806 if ((row >= rows_) || (row_info[row].descent_of_row == height))
1808 row_info[row].descent_of_row = height;
1813 int LyXTabular::GetAscentOfRow(int row) const
1817 return row_info[row].ascent_of_row;
1821 int LyXTabular::GetDescentOfRow(int row) const
1825 return row_info[row].descent_of_row;
1829 int LyXTabular::GetHeightOfTabular() const
1833 for(int row = 0; row < rows_; ++row)
1834 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
1835 GetAdditionalHeight(GetCellNumber(row, 0));
1840 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
1842 if ((row >= rows_) || (column >= columns_))
1844 return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
1848 int LyXTabular::TeXTopHLine(ostream & os, int row) const
1850 int fcell = GetFirstCellInRow(row);
1851 int n = NumberOfCellsInRow(fcell) + fcell;
1855 for (i = fcell; i < n; ++i) {
1859 if (tmp == (n - fcell)){
1862 for (i = fcell; i < n; ++i) {
1865 << column_of_cell(i) + 1
1867 << right_column_of_cell(i) + 1
1880 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
1882 int fcell = GetFirstCellInRow(row);
1883 int n = NumberOfCellsInRow(fcell) + fcell;
1887 for (i = fcell; i < n; ++i) {
1891 if (tmp == (n-fcell)){
1894 for (i = fcell; i < n; ++i) {
1895 if (BottomLine(i)) {
1897 << column_of_cell(i) + 1
1899 << right_column_of_cell(i) + 1
1912 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
1916 if (GetRotateCell(cell)) {
1917 os << "\\begin{sideways}" << endl;
1920 if (IsMultiColumn(cell)) {
1921 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
1922 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1923 os << cellinfo_of_cell(cell+1)->align_special << "}{";
1927 if (!GetPWidth(cell).empty()) {
1928 switch(GetVAlignment(cell)) {
1929 case LYX_VALIGN_TOP:
1932 case LYX_VALIGN_CENTER:
1935 case LYX_VALIGN_BOTTOM:
1939 os << "{" << GetPWidth(cell) << '}';
1941 switch (GetAlignment(cell)) {
1942 case LYX_ALIGN_LEFT:
1945 case LYX_ALIGN_RIGHT:
1953 if (RightLine(cell))
1955 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
1961 if (GetUsebox(cell) == 1) {
1963 switch(GetVAlignment(cell)) {
1964 case LYX_VALIGN_TOP:
1967 case LYX_VALIGN_CENTER:
1970 case LYX_VALIGN_BOTTOM:
1974 os << "]{" << GetPWidth(cell) << "}{";
1975 } else if (GetUsebox(cell) == 2) {
1976 os << "\\begin{minipage}[";
1977 switch(GetVAlignment(cell)) {
1978 case LYX_VALIGN_TOP:
1981 case LYX_VALIGN_CENTER:
1984 case LYX_VALIGN_BOTTOM:
1988 os << "]{" << GetPWidth(cell) << "}\n";
1995 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
2000 if (GetUsebox(cell) == 1)
2002 else if (GetUsebox(cell) == 2) {
2003 os << "%\n\\end{minipage}";
2006 if (IsMultiColumn(cell)){
2009 if (GetRotateCell(cell)) {
2010 os << "%\n\\end{sideways}";
2017 int LyXTabular::Latex(Buffer const * buf, ostream & os, bool fragile, bool fp) const
2023 //+---------------------------------------------------------------------
2024 //+ first the opening preamble +
2025 //+---------------------------------------------------------------------
2028 os << "\\begin{sideways}" << endl;
2031 if (is_long_tabular)
2032 os << "\\begin{longtable}{";
2034 os << "\\begin{tabular}{";
2035 for (i = 0; i < columns_; ++i) {
2036 if (column_info[i].left_line)
2038 if (!column_info[i].align_special.empty()) {
2039 os << column_info[i].align_special;
2040 } else if (!column_info[i].p_width.empty()) {
2041 switch(column_info[i].valignment) {
2042 case LYX_VALIGN_TOP:
2045 case LYX_VALIGN_CENTER:
2048 case LYX_VALIGN_BOTTOM:
2053 << column_info[i].p_width
2056 switch (column_info[i].alignment) {
2057 case LYX_ALIGN_LEFT:
2060 case LYX_ALIGN_RIGHT:
2068 if (column_info[i].right_line)
2074 //+---------------------------------------------------------------------
2075 //+ the single row and columns (cells) +
2076 //+---------------------------------------------------------------------
2079 for(i=0; i < rows_; ++i) {
2080 ret += TeXTopHLine(os, i);
2082 if (IsLongTabular()) {
2083 if ((endhead < 0) && (i == (abs(endhead)-1))) {
2084 os << "\\endhead\n";
2087 if ((endfirsthead < 0) && (i == (abs(endfirsthead)-1))) {
2088 os << "\\endfirsthead\n";
2091 if ((endfoot < 0) && (i == (abs(endfoot)-1))) {
2092 os << "\\endfoot\n";
2095 if ((endlastfoot < 0) && (i == (abs(endlastfoot)-1))) {
2096 os << "\\endlastfoot\n";
2102 ret += TeXBottomHLine(os, i-1);
2103 ret += TeXTopHLine(os, i);
2105 for(j=0; j < columns_; ++j) {
2106 if (IsPartOfMultiColumn(i,j))
2108 ret += TeXCellPreamble(os, cell);
2109 ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
2110 ret += TeXCellPostamble(os, cell);
2111 if (!IsLastCellInRow(cell)) { // not last cell in row
2117 os << "\\\\" << endl;
2118 ret += TeXBottomHLine(os, i);
2120 if (IsLongTabular()) {
2121 if ((endhead > 0) && (i == (endhead-1))) {
2122 os << "\\endhead\n";
2125 if ((endfirsthead > 0) && (i == (endfirsthead-1))) {
2126 os << "\\endfirsthead\n";
2129 if ((endfoot > 0) && (i == (endfoot-1))) {
2130 os << "\\endfoot\n";
2133 if ((endlastfoot > 0) && (i == (endlastfoot-1))) {
2134 os << "\\endlastfoot\n";
2138 ret += TeXBottomHLine(os, i);
2139 if (row_info[i].newpage) {
2140 os << "\\newpage\n";
2146 //+---------------------------------------------------------------------
2147 //+ the closing of the tabular +
2148 //+---------------------------------------------------------------------
2150 if (is_long_tabular)
2151 os << "\\end{longtable}";
2153 os << "\\end{tabular}";
2155 os << "\n\\end{sideways}";
2163 InsetText * LyXTabular::GetCellInset(int cell) const
2165 return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
2168 void LyXTabular::Validate(LaTeXFeatures & features) const
2170 if (IsLongTabular())
2171 features.longtable = true;
2173 features.rotating = true;
2174 for(int cell = 0; cell < numberofcells; ++cell) {
2175 if (GetVAlignment(cell) != LYX_VALIGN_TOP)
2176 features.array = true;
2177 GetCellInset(cell)->Validate(features);
2182 bool LyXTabular::UseParbox(int cell) const
2184 LyXParagraph *par = GetCellInset(cell)->par;
2186 for(;par; par = par->next) {
2187 for(int i = 0; i < par->Last(); ++i) {
2188 if (par->GetChar(i) == LyXParagraph::META_NEWLINE)