1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * @author: Jürgen Vigna
10 * ======================================================
16 #pragma implementation
26 #include "lyx_gui_misc.h"
28 #include "BufferView.h"
30 #include "LaTeXFeatures.h"
31 #include "support/lstrings.h"
32 #include "support/lyxmanip.h"
33 #include "insets/insettabular.h"
34 #include "insets/insettext.h"
43 static int const WIDTH_OF_LINE = 5;
45 extern BufferView * current_view;
47 /// Define a few methods for the inner structs
49 LyXTabular::cellstruct::cellstruct()
53 multicolumn = LyXTabular::CELL_NORMAL;
54 alignment = LYX_ALIGN_CENTER;
55 valignment = LYX_VALIGN_TOP;
65 LyXTabular::rowstruct::rowstruct()
75 LyXTabular::columnstruct::columnstruct()
79 alignment = LYX_ALIGN_CENTER;
80 valignment = LYX_VALIGN_TOP;
86 LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg)
89 Init(rows_arg, columns_arg);
93 LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt)
96 Init(lt.rows_, lt.columns_);
97 #warning Jürgen, can you make it the other way round. So that copy assignment depends on the copy constructor and not the other way. (Lgb)
102 LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex)
109 LyXTabular::~LyXTabular()
112 delete[] columnofcell;
116 LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
118 // If this and lt is not of the same size we have a serious bug
119 // So then it is ok to throw an exception, or for now
121 Assert(rows_ == lt.rows_ && columns_ == lt.columns_);
123 cell_info = lt.cell_info;
124 row_info = lt.row_info;
125 column_info = lt.column_info;
127 // long tabular stuff
128 SetLongTabular(lt.is_long_tabular);
129 endhead = lt.endhead;
130 endfoot = lt.endfoot;
131 endfirsthead = lt.endfirsthead;
132 endlastfoot = lt.endlastfoot;
142 LyXTabular * LyXTabular::Clone(InsetTabular * inset)
144 LyXTabular * result = new LyXTabular(inset, *this);
145 // don't know if this is good but I need to Clone also
146 // the text-insets here, this is for the Undo-facility!
147 for(int i = 0; i < rows_; ++i) {
148 for(int j = 0; j < columns_; ++j) {
149 result->cell_info[i][j].inset = cell_info[i][j].inset;
150 result->cell_info[i][j].inset.setOwner(inset);
157 /* activates all lines and sets all widths to 0 */
158 void LyXTabular::Init(int rows_arg, int columns_arg)
162 columns_ = columns_arg;
163 row_info = vector<rowstruct>(rows_, rowstruct());
164 column_info = vector<columnstruct>(columns_, columnstruct());
165 cell_info = vector<vector<cellstruct> >
166 (rows_, vector<cellstruct>(columns_, cellstruct()));
168 // Jürgen, use iterators.
171 for (; i < rows_; ++i) {
172 for (int j = 0; j < columns_; ++j) {
173 cell_info[i][j].inset.setOwner(owner_);
174 cell_info[i][j].inset.SetDrawFrame(0, InsetText::LOCKED);
175 cell_info[i][j].cellno = cellno++;
178 row_info[i - 1].bottom_line = true;
179 row_info[0].bottom_line = true;
181 for (i = 0; i < columns_; ++i) {
182 calculate_width_of_column(i);
184 column_info[columns_ - 1].right_line = true;
186 calculate_width_of_tabular();
190 set_row_column_number_info();
191 is_long_tabular = false;
200 void LyXTabular::AppendRow(int cell )
204 int row = row_of_cell(cell);
206 row_vector::iterator rit = row_info.begin() + row;
207 row_info.insert(rit, rowstruct());
210 cell_vvector::iterator cit = cell_info.begin() + row;
211 cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
213 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
216 for(int i = 0; i <= row; ++i) {
217 for(int j = 0; j < columns_; ++j) {
218 c_info[i][j] = cell_info[i][j];
221 for(int i = row + 1; i < rows_; ++i) {
222 for(int j = 0; j < columns_; ++j) {
223 c_info[i][j] = cell_info[i-1][j];
228 for (int j = 0; j < columns_; ++j) {
229 cell_info[row][j].inset.clear();
236 void LyXTabular::DeleteRow(int row)
240 row_info.erase(row_info.begin() + row); //&row_info[row]);
241 cell_info.erase(cell_info.begin() + row); //&cell_info[row]);
247 void LyXTabular::AppendColumn(int cell)
251 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
253 int column = column_of_cell(cell);
254 column_vector::iterator cit = column_info.begin() + column + 1;
255 column_info.insert(cit, columnstruct());
257 for (int i = 0; i < rows_; ++i) {
258 for (int j = 0; j <= column; ++j) {
259 c_info[i][j] = cell_info[i][j];
261 for (int j = column + 1; j < columns_; ++j) {
262 c_info[i][j] = cell_info[i][j - 1];
264 // care about multicolumns
265 if (cell_info[i][column + 1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
266 cell_info[i][column + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
268 if ((column + 1) == columns_ ||
269 cell_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN) {
270 cell_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL;
275 for (int i = 0; i < rows_; ++i) {
276 cell_info[i][column].inset.clear();
282 void LyXTabular::DeleteColumn(int column)
286 column_info.erase(column_info.begin() + column);
287 for (int i = 0; i < rows_; ++i) {
288 cell_info[i].erase(cell_info[i].begin() + column);
295 void LyXTabular::Reinit()
297 // Jürgen, use iterators.
298 for (int i = 0; i < rows_; ++i) {
299 for (int j = 0; j < columns_; ++j) {
300 cell_info[i][j].width_of_cell = 0;
301 cell_info[i][j].inset.setOwner(owner_);
305 for (int i = 0; i < columns_; ++i) {
306 calculate_width_of_column(i);
308 calculate_width_of_tabular();
310 set_row_column_number_info();
314 void LyXTabular::set_row_column_number_info()
320 for (; row < rows_; ++row) {
321 for (column = 0; column<columns_; ++column) {
322 if (cell_info[row][column].multicolumn
323 != LyXTabular::CELL_PART_OF_MULTICOLUMN)
325 cell_info[row][column].cellno = numberofcells;
328 ++numberofcells; // because this is one more than as we start from 0
333 rowofcell = new int[numberofcells];
334 delete [] columnofcell;
335 columnofcell = new int[numberofcells];
337 while (c < numberofcells && row < rows_ && column < columns_) {
339 columnofcell[c] = column;
343 } while (column < columns_ &&
344 cell_info[row][column].multicolumn
345 == LyXTabular::CELL_PART_OF_MULTICOLUMN);
346 if (column == columns_) {
351 for (row = 0; row < rows_; ++row) {
352 for (column = 0; column<columns_; ++column) {
353 if (IsPartOfMultiColumn(row,column))
355 cell_info[row][column].inset.SetAutoBreakRows(
356 !GetPWidth(GetCellNumber(row, column)).empty());
362 int LyXTabular::GetNumberOfCells() const
364 return numberofcells;
368 int LyXTabular::NumberOfCellsInRow(int cell) const
370 int row = row_of_cell(cell);
372 for (int i = 0; i < columns_; ++i) {
373 if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
380 /* returns 1 if there is a topline, returns 0 if not */
381 bool LyXTabular::TopLine(int cell, bool onlycolumn) const
383 int row = row_of_cell(cell);
385 if (!onlycolumn && IsMultiColumn(cell))
386 return cellinfo_of_cell(cell)->top_line;
387 return row_info[row].top_line;
391 bool LyXTabular::BottomLine(int cell, bool onlycolumn) const
393 //no bottom line underneath non-existent cells if you please
394 if(cell >= numberofcells)
397 if (!onlycolumn && IsMultiColumn(cell))
398 return cellinfo_of_cell(cell)->bottom_line;
399 return row_info[row_of_cell(cell)].bottom_line;
403 bool LyXTabular::LeftLine(int cell, bool onlycolumn) const
405 if (!onlycolumn && IsMultiColumn(cell))
406 return cellinfo_of_cell(cell)->left_line;
407 return column_info[column_of_cell(cell)].left_line;
411 bool LyXTabular::RightLine(int cell, bool onlycolumn) const
413 if (!onlycolumn && IsMultiColumn(cell))
414 return cellinfo_of_cell(cell)->right_line;
415 return column_info[right_column_of_cell(cell)].right_line;
419 bool LyXTabular::TopAlreadyDrawed(int cell) const
421 if (GetAdditionalHeight(cell))
423 int row = row_of_cell(cell);
425 int column = column_of_cell(cell);
428 && cell_info[row][column].multicolumn
429 == LyXTabular::CELL_PART_OF_MULTICOLUMN)
431 if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL)
432 return row_info[row].bottom_line;
434 return cell_info[row][column].bottom_line;
440 bool LyXTabular::LeftAlreadyDrawed(int cell) const
442 int column = column_of_cell(cell);
444 int row = row_of_cell(cell);
446 (cell_info[row][column].multicolumn ==
447 LyXTabular::CELL_PART_OF_MULTICOLUMN));
448 if (GetAdditionalWidth(cell_info[row][column].cellno))
450 return column_info[column].right_line;
456 bool LyXTabular::IsLastRow(int cell) const
458 return (row_of_cell(cell) == rows_ - 1);
462 int LyXTabular::GetAdditionalHeight(int cell) const
464 int row = row_of_cell(cell);
467 int top = 1; // bool top = true; ??
468 int bottom = 1; // bool bottom = true; ??
470 for (int column = 0; column < columns_ - 1 && bottom; ++column) {
471 switch (cell_info[row - 1][column].multicolumn) {
472 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
473 bottom = cell_info[row - 1][column].bottom_line;
475 case LyXTabular::CELL_NORMAL:
476 bottom = row_info[row - 1].bottom_line;
479 for (int column = 0; column < columns_ - 1 && top; ++column) {
480 switch (cell_info[row][column].multicolumn){
481 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
482 top = cell_info[row][column].top_line;
484 case LyXTabular::CELL_NORMAL:
485 top = row_info[row].top_line;
489 return WIDTH_OF_LINE;
494 int LyXTabular::GetAdditionalWidth(int cell) const
496 // internally already set in SetWidthOfCell
497 // used to get it back in text.C
498 int col = right_column_of_cell(cell);
499 if (col < columns_ - 1 && column_info[col].right_line &&
500 column_info[col+1].left_line)
501 return WIDTH_OF_LINE;
507 // returns the maximum over all rows
508 int LyXTabular::GetWidthOfColumn(int cell) const
510 int const column1 = column_of_cell(cell);
511 int const column2 = right_column_of_cell(cell);
514 for (; i <= column2; ++i) {
515 result += column_info[i].width_of_column;
521 int LyXTabular::GetWidthOfTabular() const
523 return width_of_tabular;
527 /* returns 1 if a complete update is necessary, otherwise 0 */
528 bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
530 if (!IsMultiColumn(cell))
533 int const row = row_of_cell(cell);
534 int const column1 = column_of_cell(cell);
535 int const column2 = right_column_of_cell(cell);
537 // first set columns to 0 so we can calculate the right width
539 for (; i <= column2; ++i) {
540 cell_info[row][i].width_of_cell = 0;
542 // set the width to MAX_WIDTH until width > 0
543 int width = (new_width + 2 * WIDTH_OF_LINE);
544 for (i = column1; (i < column2) && (width>column_info[i].width_of_column);
547 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
548 width -= column_info[i].width_of_column;
551 cell_info[row][i].width_of_cell = width;
557 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
559 int const row = row_of_cell(cell);
560 int const column1 = column_of_cell(cell);
561 int const column2 = right_column_of_cell(cell);
563 // first set columns to 0 so we can calculate the right width
565 for (; i <= column2; ++i)
566 cell_info[row][i].width_of_cell = 0;
567 for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
569 if (i < numberofcells)
570 recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
571 SetWidthOfMulticolCell(cell, new_width);
575 /* returns 1 if a complete update is necessary, otherwise 0 */
576 bool LyXTabular::SetWidthOfCell(int cell, int new_width)
578 int const row = row_of_cell(cell);
579 int const column1 = column_of_cell(cell);
583 if (GetWidthOfCell(cell) == (new_width+2*WIDTH_OF_LINE))
585 if (IsMultiColumn(cell, true)) {
586 tmp = SetWidthOfMulticolCell(cell, new_width);
588 width = (new_width + 2*WIDTH_OF_LINE);
589 cell_info[row][column1].width_of_cell = width;
590 if (column_info[column1].right_line && (column1 < columns_-1) &&
591 column_info[column1+1].left_line) // additional width
592 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
593 tmp = calculate_width_of_column_NMC(column1);
597 for(; i<columns_; ++i)
598 calculate_width_of_column_NMC(i);
599 for(i = 0; (i < numberofcells) && !IsMultiColumn(i); ++i)
601 if (i < numberofcells)
602 recalculateMulticolCells(i, GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
603 for(i = 0; i < columns_; ++i)
604 calculate_width_of_column(i);
605 calculate_width_of_tabular();
612 bool LyXTabular::SetAlignment(int cell, char align, bool onlycolumn)
614 if (!IsMultiColumn(cell) || onlycolumn)
615 column_info[column_of_cell(cell)].alignment = align;
617 cellinfo_of_cell(cell)->alignment = align;
622 bool LyXTabular::SetVAlignment(int cell, char align, bool onlycolumn)
624 if (!IsMultiColumn(cell) || onlycolumn)
625 column_info[column_of_cell(cell)].valignment = align;
627 cellinfo_of_cell(cell)->valignment = align;
632 bool LyXTabular::SetColumnPWidth(int cell, string const & width)
634 bool flag = !width.empty();
635 int const j = column_of_cell(cell);
637 column_info[j].p_width = width;
638 if (flag) // do this only if there is a width
639 SetAlignment(cell, LYX_ALIGN_LEFT);
640 for(int i = 0; i < rows_; ++i) {
641 int c = GetCellNumber(i, j);
642 flag = !GetPWidth(c).empty(); // because of multicolumns!
643 GetCellInset(c)->SetAutoBreakRows(flag);
649 bool LyXTabular::SetMColumnPWidth(int cell, string const & width)
651 bool const flag = !width.empty();
653 cellinfo_of_cell(cell)->p_width = width;
654 if (IsMultiColumn(cell)) {
655 GetCellInset(cell)->SetAutoBreakRows(flag);
662 bool LyXTabular::SetAlignSpecial(int cell, string const & special, int what)
664 if (what == SET_SPECIAL_MULTI)
665 cellinfo_of_cell(cell)->align_special = special;
667 column_info[column_of_cell(cell)].align_special = special;
672 bool LyXTabular::SetAllLines(int cell, bool line)
674 SetTopLine(cell, line);
675 SetBottomLine(cell, line);
676 SetRightLine(cell, line);
677 SetLeftLine(cell, line);
682 bool LyXTabular::SetTopLine(int cell, bool line, bool onlycolumn)
684 int const row = row_of_cell(cell);
686 if (onlycolumn || !IsMultiColumn(cell))
687 row_info[row].top_line = line;
689 cellinfo_of_cell(cell)->top_line = line;
694 bool LyXTabular::SetBottomLine(int cell, bool line, bool onlycolumn)
696 if (onlycolumn || !IsMultiColumn(cell))
697 row_info[row_of_cell(cell)].bottom_line = line;
699 cellinfo_of_cell(cell)->bottom_line = line;
704 bool LyXTabular::SetLeftLine(int cell, bool line, bool onlycolumn)
706 if (onlycolumn || !IsMultiColumn(cell))
707 column_info[column_of_cell(cell)].left_line = line;
709 cellinfo_of_cell(cell)->left_line = line;
714 bool LyXTabular::SetRightLine(int cell, bool line, bool onlycolumn)
716 if (onlycolumn || !IsMultiColumn(cell))
717 column_info[right_column_of_cell(cell)].right_line = line;
719 cellinfo_of_cell(cell)->right_line = line;
724 char LyXTabular::GetAlignment(int cell, bool onlycolumn) const
726 if (!onlycolumn && IsMultiColumn(cell))
727 return cellinfo_of_cell(cell)->alignment;
729 return column_info[column_of_cell(cell)].alignment;
733 char LyXTabular::GetVAlignment(int cell, bool onlycolumn) const
735 if (!onlycolumn && IsMultiColumn(cell))
736 return cellinfo_of_cell(cell)->valignment;
738 return column_info[column_of_cell(cell)].valignment;
742 string const LyXTabular::GetPWidth(int cell) const
744 if (IsMultiColumn(cell))
745 return cellinfo_of_cell(cell)->p_width;
746 return column_info[column_of_cell(cell)].p_width;
750 string const LyXTabular::GetColumnPWidth(int cell) const
752 return column_info[column_of_cell(cell)].p_width;
756 string const LyXTabular::GetMColumnPWidth(int cell) const
758 if (IsMultiColumn(cell))
759 return cellinfo_of_cell(cell)->p_width;
764 string const LyXTabular::GetAlignSpecial(int cell, int what) const
766 if (what == SET_SPECIAL_MULTI)
767 return cellinfo_of_cell(cell)->align_special;
768 return column_info[column_of_cell(cell)].align_special;
772 int LyXTabular::GetWidthOfCell(int cell) const
774 int const row = row_of_cell(cell);
775 int const column1 = column_of_cell(cell);
776 int const column2 = right_column_of_cell(cell);
778 for (int i = column1; i <= column2; ++i) {
779 result += cell_info[row][i].width_of_cell;
784 int LyXTabular::GetBeginningOfTextInCell(int cell) const
788 switch (GetAlignment(cell)){
789 case LYX_ALIGN_CENTER:
790 x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
792 case LYX_ALIGN_RIGHT:
793 x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
794 // + GetAdditionalWidth(cell);
796 default: /* LYX_ALIGN_LEFT: nothing :-) */
806 bool LyXTabular::IsFirstCellInRow(int cell) const
808 return (column_of_cell(cell) == 0);
812 int LyXTabular::GetFirstCellInRow(int row) const
816 return cell_info[row][0].cellno;
819 bool LyXTabular::IsLastCellInRow(int cell) const
821 return (right_column_of_cell(cell) == (columns_ - 1));
825 int LyXTabular::GetLastCellInRow(int row) const
829 return cell_info[row][columns_-1].cellno;
833 bool LyXTabular::calculate_width_of_column(int column)
835 int const old_column_width = column_info[column].width_of_column;
838 for (int i = 0; i < rows_; ++i) {
839 maximum = max(cell_info[i][column].width_of_cell, maximum);
841 column_info[column].width_of_column = maximum;
842 return (column_info[column].width_of_column != old_column_width);
847 // calculate the with of the column without regarding REAL MultiColumn
848 // cells. This means MultiColumn-cells spanning more than 1 column.
850 bool LyXTabular::calculate_width_of_column_NMC(int column)
852 int const old_column_width = column_info[column].width_of_column;
854 for (int i = 0; i < rows_; ++i) {
855 if (!IsMultiColumn(GetCellNumber(i, column), true) &&
856 (cell_info[i][column].width_of_cell > max)) {
857 max = cell_info[i][column].width_of_cell;
860 column_info[column].width_of_column = max;
861 return (column_info[column].width_of_column != old_column_width);
865 void LyXTabular::calculate_width_of_tabular()
867 width_of_tabular = 0;
868 for (int i = 0; i < columns_; ++i) {
869 width_of_tabular += column_info[i].width_of_column;
874 int LyXTabular::row_of_cell(int cell) const
876 if (cell >= numberofcells)
880 return rowofcell[cell];
884 int LyXTabular::column_of_cell(int cell) const
886 if (cell >= numberofcells)
890 return columnofcell[cell];
894 int LyXTabular::right_column_of_cell(int cell) const
896 int const row = row_of_cell(cell);
897 int column = column_of_cell(cell);
898 while (column < (columns_ - 1) &&
899 cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
905 void LyXTabular::Write(Buffer const * buf, ostream & os) const
908 os << "<LyXTabular version=1 rows=" << rows_ << " columns=" << columns_ <<
910 // global longtable options
911 os << "<Features rotate=" << rotate <<
912 " islongtable=" << is_long_tabular <<
913 " endhead=" << endhead << " endfirsthead=" << endfirsthead <<
914 " endfoot=" << endfoot << " endlastfoot=" << endlastfoot <<
916 for (int i = 0; i < rows_; ++i) {
917 os << "<Row topline=" << row_info[i].top_line <<
918 " bottomline=" << row_info[i].bottom_line <<
919 " newpage=" << row_info[i].newpage <<
921 for (int j = 0; j < columns_; ++j) {
923 os << "<Column alignment=" << column_info[j].alignment <<
924 " valignment=" << column_info[j].valignment <<
925 " leftline=" << column_info[j].left_line <<
926 " rightline=" << column_info[j].right_line <<
927 " width=\"" << VSpace(column_info[j].p_width).asLyXCommand() <<
928 "\" special=\"" << column_info[j].align_special <<
931 os << "<Column>" << endl;
933 os << "<Cell multicolumn=" << cell_info[i][j].multicolumn <<
934 " alignment=" << cell_info[i][j].alignment <<
935 " valignment=" << cell_info[i][j].valignment <<
936 " topline=" << cell_info[i][j].top_line <<
937 " bottomline=" << cell_info[i][j].bottom_line <<
938 " leftline=" << cell_info[i][j].left_line <<
939 " rightline=" << cell_info[i][j].right_line <<
940 " rotate=" << cell_info[i][j].rotate <<
941 " usebox=" << (int)cell_info[i][j].usebox <<
942 " width=\"" << cell_info[i][j].p_width <<
943 "\" special=\"" << cell_info[i][j].align_special <<
945 os << "\\begin_inset ";
946 cell_info[i][j].inset.Write(buf, os);
947 os << "\n\\end_inset " << endl;
948 os << "</Cell>" << endl;
949 os << "</Column>" << endl;
951 os << "</Row>" << endl;
953 os << "</LyXTabular>" << endl;
958 bool getTokenValue(string const str, const char * token, string & ret)
960 int pos = str.find(token);
961 char ch = str[pos+strlen(token)];
963 if ((pos < 0) || (ch != '='))
966 pos += strlen(token)+1;
968 if ((ch != '"') && (ch != '\'')) { // only read till next space
972 while((pos < int(str.length()-1)) && (str[++pos] != ch))
980 bool getTokenValue(string const str, const char * token, int & num)
983 int pos = str.find(token);
984 char ch = str[pos+strlen(token)];
986 if ((pos < 0) || (ch != '='))
989 pos += strlen(token)+1;
991 if ((ch != '"') && (ch != '\'')) { // only read till next space
997 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1000 num = strToInt(ret);
1006 bool getTokenValue(string const str, const char * token, bool & flag)
1009 int pos = str.find(token);
1010 char ch = str[pos+strlen(token)];
1012 if ((pos < 0) || (ch != '='))
1015 pos += strlen(token)+1;
1017 if ((ch != '"') && (ch != '\'')) { // only read till next space
1023 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1026 flag = strToInt(ret);
1032 void l_getline(istream & is, string & str)
1040 void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
1043 istream & is = lex.getStream();
1045 l_getline(is, line);
1046 if (!prefixIs(line, "<LyXTabular ")) {
1047 OldFormatRead(lex, line);
1054 if (!getTokenValue(line, "version", version))
1056 if (!getTokenValue(line, "rows", rows_arg))
1058 if (!getTokenValue(line, "columns", columns_arg))
1060 Init(rows_arg, columns_arg);
1061 l_getline(is, line);
1062 if (!prefixIs(line, "<Features ")) {
1063 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
1064 line << ")" << endl;
1067 getTokenValue(line, "islongtable", is_long_tabular);
1068 getTokenValue(line, "endhead", endhead);
1069 getTokenValue(line, "endfirsthead", endfirsthead);
1070 getTokenValue(line, "endfoot", endfoot);
1071 getTokenValue(line, "endlastfoot", endlastfoot);
1073 for(i = 0; i < rows_; ++i) {
1074 l_getline(is, line);
1075 if (!prefixIs(line, "<Row ")) {
1076 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
1077 line << ")" << endl;
1080 getTokenValue(line, "topline", row_info[i].top_line);
1081 getTokenValue(line, "bottomline", row_info[i].bottom_line);
1082 getTokenValue(line, "newpage", row_info[i].newpage);
1083 for (j = 0; j < columns_; ++j) {
1085 if (!prefixIs(line,"<Column")) {
1086 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
1087 line << ")" << endl;
1091 getTokenValue(line, "alignment", column_info[j].alignment);
1092 getTokenValue(line, "valignment", column_info[j].valignment);
1093 getTokenValue(line, "leftline", column_info[j].left_line);
1094 getTokenValue(line, "rightline", column_info[j].right_line);
1095 getTokenValue(line, "width", column_info[j].p_width);
1096 getTokenValue(line, "special", column_info[j].align_special);
1098 l_getline(is, line);
1099 if (!prefixIs(line, "<Cell")) {
1100 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
1101 line << ")" << endl;
1104 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1105 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1106 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1107 getTokenValue(line, "topline", cell_info[i][j].top_line);
1108 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1109 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1110 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1111 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1112 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1113 getTokenValue(line, "width", cell_info[i][j].p_width);
1114 getTokenValue(line, "special", cell_info[i][j].align_special);
1115 l_getline(is, line);
1116 if (prefixIs(line, "\\begin_inset")) {
1117 cell_info[i][j].inset.Read(buf, lex);
1118 l_getline(is, line);
1120 if (line != "</Cell>") {
1121 lyxerr << "Wrong tabular format (expected </Cell> got" <<
1122 line << ")" << endl;
1125 l_getline(is, line);
1126 if (line != "</Column>") {
1127 lyxerr << "Wrong tabular format (expected </Column> got" <<
1128 line << ")" << endl;
1132 l_getline(is, line);
1133 if (line != "</Row>") {
1134 lyxerr << "Wrong tabular format (expected </Row> got" <<
1135 line << ")" << endl;
1139 while (line != "</LyXTabular>") {
1140 l_getline(is, line);
1142 set_row_column_number_info();
1146 void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
1151 int columns_arg = 0;
1152 int is_long_tabular_arg = false;
1153 int rotate_arg = false;
1163 istream & is = lex.getStream();
1166 version = atoi(s.c_str() + 8);
1170 vector<int> cont_row_info;
1173 lyxerr << "Tabular format < 5 is not supported anymore\n"
1174 "Get an older version of LyX (< 1.1.x) for conversion!"
1176 WriteAlert(_("Warning:"),
1177 _("Tabular format < 5 is not supported anymore\n"),
1178 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1180 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1181 >> rotate_arg >> a >> b >> c >> d;
1183 is >> rows_arg >> columns_arg;
1184 Init(rows_arg, columns_arg);
1185 cont_row_info = vector<int>(rows_arg);
1186 SetLongTabular(is_long_tabular_arg);
1187 SetRotateTabular(rotate_arg);
1189 for (i = 0; i < rows_; ++i) {
1191 cont_row_info[i] = false;
1193 for (i = 0; i < columns_; ++i) {
1196 for (i = 0; i < rows_; ++i) {
1197 for (j = 0; j < columns_; ++j) {
1202 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1203 >> rotate_arg >> a >> b >> c >> d;
1204 Init(rows_arg, columns_arg);
1205 cont_row_info = vector<int>(rows_arg);
1206 SetLongTabular(is_long_tabular_arg);
1207 SetRotateTabular(rotate_arg);
1212 for (i = 0; i < rows_; ++i) {
1213 a = b = c = d = e = f = g = h = 0;
1214 is >> a >> b >> c >> d;
1215 row_info[i].top_line = a;
1216 row_info[i].bottom_line = b;
1217 cont_row_info[i] = c;
1218 row_info[i].newpage = d;
1220 for (i = 0; i < columns_; ++i) {
1224 char ch; // skip '"'
1226 getline(is, s1, '"');
1227 is >> ch; // skip '"'
1228 getline(is, s2, '"');
1229 column_info[i].alignment = static_cast<char>(a);
1230 column_info[i].left_line = b;
1231 column_info[i].right_line = c;
1232 column_info[i].p_width = s1;
1233 column_info[i].align_special = s2;
1235 for (i = 0; i < rows_; ++i) {
1236 for (j = 0; j < columns_; ++j) {
1239 is >> a >> b >> c >> d >> e >> f >> g;
1241 is >> ch; // skip '"'
1242 getline(is, s1, '"');
1243 is >> ch; // skip '"'
1244 getline(is, s2, '"');
1245 cell_info[i][j].multicolumn = static_cast<char>(a);
1246 cell_info[i][j].alignment = static_cast<char>(b);
1247 cell_info[i][j].top_line = static_cast<char>(c);
1248 cell_info[i][j].bottom_line = static_cast<char>(d);
1249 cell_info[i][j].rotate = static_cast<bool>(f);
1250 cell_info[i][j].usebox = static_cast<bool>(g);
1251 cell_info[i][j].align_special = s1;
1252 cell_info[i][j].p_width = s2;
1256 set_row_column_number_info();
1258 LyXParagraph * par = new LyXParagraph;
1259 LyXParagraph * return_par = 0;
1261 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1262 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
1264 string token, tmptok;
1267 LyXFont font(LyXFont::ALL_SANE);
1269 while (lex.IsOK()) {
1271 token = lex.GetString();
1274 if ((token == "\\layout") || (token == "\\end_float") ||
1275 (token == "\\end_deeper"))
1277 lex.pushToken(token);
1280 if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
1292 lex.pushToken(token);
1296 lex.printError("New Paragraph allocated! This should not happen!");
1297 lex.pushToken(token);
1303 // now we have the par we should fill the insets with this!
1305 InsetText * inset = GetCellInset(cell);
1308 for(int i = 0; i < par->Last(); ++i) {
1309 if (par->IsNewline(i)) {
1311 if (cell > GetNumberOfCells()) {
1312 lyxerr << "Some error in reading old table format occured!" <<
1313 endl << "Terminating when reading cell[" << cell << "]!" <<
1317 row = row_of_cell(cell);
1318 if (cont_row_info[row]) {
1320 cont_row_info.erase(cont_row_info.begin() + row); //&cont_row_info[row]);
1321 while(!IsFirstCellInRow(--cell));
1323 inset = GetCellInset(cell);
1326 inset = GetCellInset(cell);
1327 row = row_of_cell(cell);
1328 if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox)
1330 // insert a space instead
1332 par->InsertChar(i, ' ');
1335 par->CopyIntoMinibuffer(current_view->buffer()->params, i);
1336 inset->par->InsertFromMinibuffer(inset->par->Last());
1342 string const LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
1344 int i = isColumn ? cell : column_of_cell(cell);
1349 //i = column_of_cell(cell);
1350 if (!isColumn && IsMultiColumn(cell)) {
1351 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1352 return cellinfo_of_cell(cell)->align_special;
1354 switch (GetAlignment(cell)) {
1355 case LYX_ALIGN_LEFT:
1357 case LYX_ALIGN_RIGHT:
1364 if (!column_info[i].align_special.empty()) {
1365 return column_info[i].align_special;
1367 #ifdef IGNORE_THIS_FOR_NOW
1368 else if (!column_info[i].p_width.empty()) {
1370 file += column_info[i].p_width;
1375 switch (column_info[i].alignment) {
1376 case LYX_ALIGN_LEFT:
1378 case LYX_ALIGN_RIGHT:
1388 // cell <0 will tex the preamble
1389 // returns the number of printed newlines
1390 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1394 //int tmp; // tmp2; // unused
1395 int nvcell; // fcell; // unused
1396 if (IsLastCell(cell)) {
1397 os << newlineAndDepth(--depth)
1399 << newlineAndDepth(--depth)
1401 << newlineAndDepth(--depth)
1403 << newlineAndDepth(--depth);
1404 if (is_long_tabular)
1408 << newlineAndDepth(--depth);
1414 if (is_long_tabular)
1420 << "' COLSEP='1' ROWSEP='1'>"
1421 << newlineAndDepth(++depth);
1423 for (i = 0; i < columns_; ++i) {
1424 os << "<COLSPEC ALIGN='"
1425 << GetDocBookAlign(i, true)
1431 if (i == (columns_-1)) {
1434 if (column_info[i].right_line ||
1435 column_info[i+1].left_line)
1441 << newlineAndDepth(depth);
1443 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1444 if (column_info[i].left_line)
1449 << newlineAndDepth(++depth)
1451 << newlineAndDepth(++depth)
1453 << GetDocBookAlign(0)
1455 if (IsMultiColumn(0)) {
1456 os << " NAMEST='col1' NAMEEND='col"
1457 << cells_in_multicolumn(0)
1461 << newlineAndDepth(++depth);
1464 if (IsLastCellInRow(cell)) {
1465 os << newlineAndDepth(--depth)
1467 << newlineAndDepth(--depth)
1469 << newlineAndDepth(depth)
1471 << newlineAndDepth(++depth)
1473 << GetDocBookAlign(cell + 1)
1474 << "' VALIGN='middle'";
1475 if (IsMultiColumn(cell + 1)) {
1476 os << " NAMEST='col"
1477 << column_of_cell(cell+1) + 1
1479 << column_of_cell(cell + 1) +
1480 cells_in_multicolumn(cell + 1)
1484 << newlineAndDepth(++depth);
1487 os << newlineAndDepth(--depth)
1489 << newlineAndDepth(depth)
1491 << GetDocBookAlign(cell + 1)
1492 << "' VALIGN='middle'";
1493 if (IsMultiColumn(cell + 1)) {
1494 os << " NAMEST='col"
1495 << column_of_cell(cell+1) + 1
1497 << column_of_cell(cell+1) +
1498 cells_in_multicolumn(cell+1)
1502 << newlineAndDepth(++depth);
1511 bool LyXTabular::IsMultiColumn(int cell, bool real) const
1513 return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&
1514 (cellinfo_of_cell(cell)->multicolumn !=LyXTabular::CELL_NORMAL));
1518 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1520 int row = row_of_cell(cell);
1521 int column = column_of_cell(cell);
1522 return &cell_info[row][column];
1526 void LyXTabular::SetMultiColumn(int cell, int number)
1528 cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1529 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1530 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1531 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1532 for (number--; number > 0; --number) {
1533 cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
1535 set_row_column_number_info();
1539 int LyXTabular::cells_in_multicolumn(int cell) const
1541 int row = row_of_cell(cell);
1542 int column = column_of_cell(cell);
1545 while ((column < columns_) &&
1546 cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
1555 int LyXTabular::UnsetMultiColumn(int cell)
1557 int row = row_of_cell(cell);
1558 int column = column_of_cell(cell);
1562 if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
1563 cell_info[row][column].multicolumn = CELL_NORMAL;
1565 while ((column < columns_) &&
1566 (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN))
1568 cell_info[row][column].multicolumn = CELL_NORMAL;
1573 set_row_column_number_info();
1578 void LyXTabular::SetLongTabular(int what)
1580 is_long_tabular = what;
1584 bool LyXTabular::IsLongTabular() const
1586 return is_long_tabular;
1590 void LyXTabular::SetRotateTabular(bool flag)
1596 bool LyXTabular::GetRotateTabular() const
1602 void LyXTabular::SetRotateCell(int cell, bool flag)
1604 cellinfo_of_cell(cell)->rotate = flag;
1608 bool LyXTabular::GetRotateCell(int cell) const
1610 return cellinfo_of_cell(cell)->rotate;
1614 bool LyXTabular::NeedRotating() const
1618 for (int i = 0; i < rows_; ++i) {
1619 for (int j = 0; j < columns_; ++j) {
1620 if (cell_info[i][j].rotate)
1628 bool LyXTabular::IsLastCell(int cell) const
1630 if ((cell+1) < GetNumberOfCells())
1636 int LyXTabular::GetCellAbove(int cell) const
1638 if (row_of_cell(cell) > 0)
1639 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
1644 int LyXTabular::GetCellBelow(int cell) const
1646 if (row_of_cell(cell)+1 < rows_)
1647 return cell_info[row_of_cell(cell)+1][column_of_cell(cell)].cellno;
1652 int LyXTabular::GetLastCellAbove(int cell) const
1654 if (row_of_cell(cell) <= 0)
1656 if (!IsMultiColumn(cell))
1657 return GetCellAbove(cell);
1658 return cell_info[row_of_cell(cell)-1][right_column_of_cell(cell)].cellno;
1662 int LyXTabular::GetLastCellBelow(int cell) const
1664 if (row_of_cell(cell)+1 >= rows_)
1666 if (!IsMultiColumn(cell))
1667 return GetCellBelow(cell);
1668 return cell_info[row_of_cell(cell)+1][right_column_of_cell(cell)].cellno;
1672 int LyXTabular::GetCellNumber(int row, int column) const
1674 if (column >= columns_)
1675 column = columns_ - 1;
1676 else if (column < 0)
1683 return cell_info[row][column].cellno;
1687 void LyXTabular::SetUsebox(int cell, BoxType type)
1689 cellinfo_of_cell(cell)->usebox = type;
1693 int LyXTabular::GetUsebox(int cell) const
1695 if (column_info[column_of_cell(cell)].p_width.empty() &&
1696 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
1698 if (cellinfo_of_cell(cell)->usebox > 1)
1699 return cellinfo_of_cell(cell)->usebox;
1700 return UseParbox(cell);
1704 void LyXTabular::SetLTHead(int cell, bool first)
1706 int const row = row_of_cell(cell);
1707 int const val = (row+1) * (column_of_cell(cell)? 1:-1);
1710 if (endfirsthead == val)
1723 bool LyXTabular::GetRowOfLTHead(int cell, int & row) const
1726 if (abs(endhead) > rows_)
1728 return (row_of_cell(cell) == (abs(endhead)-1));
1732 bool LyXTabular::GetRowOfLTFirstHead(int cell, int & row) const
1735 if (abs(endfirsthead) > rows_)
1737 return (row_of_cell(cell) == (abs(endfirsthead)-1));
1741 void LyXTabular::SetLTFoot(int cell, bool last)
1743 int const row = row_of_cell(cell);
1744 int const val = (row + 1) * (column_of_cell(cell)? 1:-1);
1747 if (endlastfoot == val)
1760 bool LyXTabular::GetRowOfLTFoot(int cell, int & row) const
1763 if ((endfoot+1) > rows_)
1765 return (row_of_cell(cell) == (abs(endfoot)-1));
1769 bool LyXTabular::GetRowOfLTLastFoot(int cell, int & row) const
1772 if (abs(endlastfoot) > rows_)
1774 return (row_of_cell(cell) == (abs(endlastfoot)-1));
1778 void LyXTabular::SetLTNewPage(int cell, bool what)
1780 row_info[row_of_cell(cell)].newpage = what;
1784 bool LyXTabular::GetLTNewPage(int cell) const
1786 return row_info[row_of_cell(cell)].newpage;
1790 bool LyXTabular::SetAscentOfRow(int row, int height)
1792 if ((row >= rows_) || (row_info[row].ascent_of_row == height))
1794 row_info[row].ascent_of_row = height;
1799 bool LyXTabular::SetDescentOfRow(int row, int height)
1801 if ((row >= rows_) || (row_info[row].descent_of_row == height))
1803 row_info[row].descent_of_row = height;
1808 int LyXTabular::GetAscentOfRow(int row) const
1812 return row_info[row].ascent_of_row;
1816 int LyXTabular::GetDescentOfRow(int row) const
1820 return row_info[row].descent_of_row;
1824 int LyXTabular::GetHeightOfTabular() const
1828 for(int row = 0; row < rows_; ++row)
1829 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
1830 GetAdditionalHeight(GetCellNumber(row, 0));
1835 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
1837 if ((row >= rows_) || (column >= columns_))
1839 return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
1843 int LyXTabular::TeXTopHLine(ostream & os, int row) const
1845 int fcell = GetFirstCellInRow(row);
1846 int n = NumberOfCellsInRow(fcell) + fcell;
1850 for (i = fcell; i < n; ++i) {
1854 if (tmp == (n - fcell)){
1857 for (i = fcell; i < n; ++i) {
1860 << column_of_cell(i) + 1
1862 << right_column_of_cell(i) + 1
1875 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
1877 int const fcell = GetFirstCellInRow(row);
1878 int const n = NumberOfCellsInRow(fcell) + fcell;
1881 for (int i = fcell; i < n; ++i) {
1885 if (tmp == (n-fcell)){
1888 for (int i = fcell; i < n; ++i) {
1889 if (BottomLine(i)) {
1891 << column_of_cell(i) + 1
1893 << right_column_of_cell(i) + 1
1906 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
1910 if (GetRotateCell(cell)) {
1911 os << "\\begin{sideways}" << endl;
1914 if (IsMultiColumn(cell)) {
1915 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
1916 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1917 os << cellinfo_of_cell(cell+1)->align_special << "}{";
1921 if (!GetPWidth(cell).empty()) {
1922 switch(GetVAlignment(cell)) {
1923 case LYX_VALIGN_TOP:
1926 case LYX_VALIGN_CENTER:
1929 case LYX_VALIGN_BOTTOM:
1933 os << "{" << GetPWidth(cell) << '}';
1935 switch (GetAlignment(cell)) {
1936 case LYX_ALIGN_LEFT:
1939 case LYX_ALIGN_RIGHT:
1947 if (RightLine(cell))
1949 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
1955 if (GetUsebox(cell) == BOX_PARBOX) {
1957 switch(GetVAlignment(cell)) {
1958 case LYX_VALIGN_TOP:
1961 case LYX_VALIGN_CENTER:
1964 case LYX_VALIGN_BOTTOM:
1968 os << "]{" << GetPWidth(cell) << "}{";
1969 } else if (GetUsebox(cell) == BOX_MINIPAGE) {
1970 os << "\\begin{minipage}[";
1971 switch(GetVAlignment(cell)) {
1972 case LYX_VALIGN_TOP:
1975 case LYX_VALIGN_CENTER:
1978 case LYX_VALIGN_BOTTOM:
1982 os << "]{" << GetPWidth(cell) << "}\n";
1989 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
1994 if (GetUsebox(cell) == BOX_PARBOX)
1996 else if (GetUsebox(cell) == BOX_MINIPAGE) {
1997 os << "%\n\\end{minipage}";
2000 if (IsMultiColumn(cell)){
2003 if (GetRotateCell(cell)) {
2004 os << "%\n\\end{sideways}";
2011 int LyXTabular::Latex(Buffer const * buf,
2012 ostream & os, bool fragile, bool fp) const
2014 #warning Jürgen, this func should be split into more funcs (Lgb)
2019 //+---------------------------------------------------------------------
2020 //+ first the opening preamble +
2021 //+---------------------------------------------------------------------
2024 os << "\\begin{sideways}" << endl;
2027 if (is_long_tabular)
2028 os << "\\begin{longtable}{";
2030 os << "\\begin{tabular}{";
2031 for (i = 0; i < columns_; ++i) {
2032 if (column_info[i].left_line)
2034 if (!column_info[i].align_special.empty()) {
2035 os << column_info[i].align_special;
2036 } else if (!column_info[i].p_width.empty()) {
2037 switch(column_info[i].valignment) {
2038 case LYX_VALIGN_TOP:
2041 case LYX_VALIGN_CENTER:
2044 case LYX_VALIGN_BOTTOM:
2049 << column_info[i].p_width
2052 switch (column_info[i].alignment) {
2053 case LYX_ALIGN_LEFT:
2056 case LYX_ALIGN_RIGHT:
2064 if (column_info[i].right_line)
2070 //+---------------------------------------------------------------------
2071 //+ the single row and columns (cells) +
2072 //+---------------------------------------------------------------------
2075 for(i=0; i < rows_; ++i) {
2076 ret += TeXTopHLine(os, i);
2078 if (IsLongTabular()) {
2079 if ((endhead < 0) && (i == (abs(endhead)-1))) {
2080 os << "\\endhead\n";
2083 if ((endfirsthead < 0) && (i == (abs(endfirsthead)-1))) {
2084 os << "\\endfirsthead\n";
2087 if ((endfoot < 0) && (i == (abs(endfoot)-1))) {
2088 os << "\\endfoot\n";
2091 if ((endlastfoot < 0) && (i == (abs(endlastfoot)-1))) {
2092 os << "\\endlastfoot\n";
2098 ret += TeXBottomHLine(os, i-1);
2099 ret += TeXTopHLine(os, i);
2101 for(j=0; j < columns_; ++j) {
2102 if (IsPartOfMultiColumn(i,j))
2104 ret += TeXCellPreamble(os, cell);
2105 ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
2106 ret += TeXCellPostamble(os, cell);
2107 if (!IsLastCellInRow(cell)) { // not last cell in row
2113 os << "\\\\" << endl;
2114 ret += TeXBottomHLine(os, i);
2116 if (IsLongTabular()) {
2117 if ((endhead > 0) && (i == (endhead-1))) {
2118 os << "\\endhead\n";
2121 if ((endfirsthead > 0) && (i == (endfirsthead-1))) {
2122 os << "\\endfirsthead\n";
2125 if ((endfoot > 0) && (i == (endfoot-1))) {
2126 os << "\\endfoot\n";
2129 if ((endlastfoot > 0) && (i == (endlastfoot-1))) {
2130 os << "\\endlastfoot\n";
2134 ret += TeXBottomHLine(os, i);
2135 if (row_info[i].newpage) {
2136 os << "\\newpage\n";
2142 //+---------------------------------------------------------------------
2143 //+ the closing of the tabular +
2144 //+---------------------------------------------------------------------
2146 if (is_long_tabular)
2147 os << "\\end{longtable}";
2149 os << "\\end{tabular}";
2151 os << "\n\\end{sideways}";
2159 InsetText * LyXTabular::GetCellInset(int cell) const
2161 return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
2165 void LyXTabular::Validate(LaTeXFeatures & features) const
2167 if (IsLongTabular())
2168 features.longtable = true;
2170 features.rotating = true;
2171 for(int cell = 0; cell < numberofcells; ++cell) {
2172 if (GetVAlignment(cell) != LYX_VALIGN_TOP)
2173 features.array = true;
2174 GetCellInset(cell)->Validate(features);
2179 bool LyXTabular::UseParbox(int cell) const
2181 LyXParagraph *par = GetCellInset(cell)->par;
2183 for(;par; par = par->next) {
2184 for(int i = 0; i < par->Last(); ++i) {
2185 if (par->GetChar(i) == LyXParagraph::META_NEWLINE)