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);
1346 if (!isColumn && IsMultiColumn(cell)) {
1347 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1348 return cellinfo_of_cell(cell)->align_special;
1350 switch (GetAlignment(cell)) {
1351 case LYX_ALIGN_LEFT:
1353 case LYX_ALIGN_RIGHT:
1360 if (!column_info[i].align_special.empty()) {
1361 return column_info[i].align_special;
1363 #ifdef IGNORE_THIS_FOR_NOW
1364 else if (!column_info[i].p_width.empty()) {
1366 file += column_info[i].p_width;
1371 switch (column_info[i].alignment) {
1372 case LYX_ALIGN_LEFT:
1374 case LYX_ALIGN_RIGHT:
1384 // cell <0 will tex the preamble
1385 // returns the number of printed newlines
1386 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1390 if (IsLastCell(cell)) {
1391 os << newlineAndDepth(--depth)
1393 << newlineAndDepth(--depth)
1395 << newlineAndDepth(--depth)
1397 << newlineAndDepth(--depth);
1398 if (is_long_tabular)
1402 << newlineAndDepth(--depth);
1408 if (is_long_tabular)
1414 << "' COLSEP='1' ROWSEP='1'>"
1415 << newlineAndDepth(++depth);
1417 for (int i = 0; i < columns_; ++i) {
1418 os << "<COLSPEC ALIGN='"
1419 << GetDocBookAlign(i, true)
1425 if (i == (columns_-1)) {
1428 if (column_info[i].right_line ||
1429 column_info[i+1].left_line)
1435 << newlineAndDepth(depth);
1437 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1438 if (column_info[i].left_line)
1443 << newlineAndDepth(++depth)
1445 << newlineAndDepth(++depth)
1447 << GetDocBookAlign(0)
1449 if (IsMultiColumn(0)) {
1450 os << " NAMEST='col1' NAMEEND='col"
1451 << cells_in_multicolumn(0)
1455 << newlineAndDepth(++depth);
1458 if (IsLastCellInRow(cell)) {
1459 os << newlineAndDepth(--depth)
1461 << newlineAndDepth(--depth)
1463 << newlineAndDepth(depth)
1465 << newlineAndDepth(++depth)
1467 << GetDocBookAlign(cell + 1)
1468 << "' VALIGN='middle'";
1469 if (IsMultiColumn(cell + 1)) {
1470 os << " NAMEST='col"
1471 << column_of_cell(cell + 1) + 1
1473 << column_of_cell(cell + 1) +
1474 cells_in_multicolumn(cell + 1)
1478 << newlineAndDepth(++depth);
1481 os << newlineAndDepth(--depth)
1483 << newlineAndDepth(depth)
1485 << GetDocBookAlign(cell + 1)
1486 << "' VALIGN='middle'";
1487 if (IsMultiColumn(cell + 1)) {
1488 os << " NAMEST='col"
1489 << column_of_cell(cell + 1) + 1
1491 << column_of_cell(cell + 1) +
1492 cells_in_multicolumn(cell + 1)
1496 << newlineAndDepth(++depth);
1505 bool LyXTabular::IsMultiColumn(int cell, bool real) const
1507 return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&
1508 (cellinfo_of_cell(cell)->multicolumn !=LyXTabular::CELL_NORMAL));
1512 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1514 int const row = row_of_cell(cell);
1515 int const column = column_of_cell(cell);
1516 return &cell_info[row][column];
1520 void LyXTabular::SetMultiColumn(int cell, int number)
1522 cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1523 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1524 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1525 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1526 for (number--; number > 0; --number) {
1527 cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
1529 set_row_column_number_info();
1533 int LyXTabular::cells_in_multicolumn(int cell) const
1535 int const row = row_of_cell(cell);
1536 int column = column_of_cell(cell);
1539 while ((column < columns_) &&
1540 cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
1549 int LyXTabular::UnsetMultiColumn(int cell)
1551 int const row = row_of_cell(cell);
1552 int column = column_of_cell(cell);
1556 if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
1557 cell_info[row][column].multicolumn = CELL_NORMAL;
1559 while ((column < columns_) &&
1560 (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN))
1562 cell_info[row][column].multicolumn = CELL_NORMAL;
1567 set_row_column_number_info();
1572 void LyXTabular::SetLongTabular(int what)
1574 is_long_tabular = what;
1578 bool LyXTabular::IsLongTabular() const
1580 return is_long_tabular;
1584 void LyXTabular::SetRotateTabular(bool flag)
1590 bool LyXTabular::GetRotateTabular() const
1596 void LyXTabular::SetRotateCell(int cell, bool flag)
1598 cellinfo_of_cell(cell)->rotate = flag;
1602 bool LyXTabular::GetRotateCell(int cell) const
1604 return cellinfo_of_cell(cell)->rotate;
1608 bool LyXTabular::NeedRotating() const
1612 for (int i = 0; i < rows_; ++i) {
1613 for (int j = 0; j < columns_; ++j) {
1614 if (cell_info[i][j].rotate)
1622 bool LyXTabular::IsLastCell(int cell) const
1624 if ((cell + 1) < GetNumberOfCells())
1630 int LyXTabular::GetCellAbove(int cell) const
1632 if (row_of_cell(cell) > 0)
1633 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
1638 int LyXTabular::GetCellBelow(int cell) const
1640 if (row_of_cell(cell) + 1 < rows_)
1641 return cell_info[row_of_cell(cell)+1][column_of_cell(cell)].cellno;
1646 int LyXTabular::GetLastCellAbove(int cell) const
1648 if (row_of_cell(cell) <= 0)
1650 if (!IsMultiColumn(cell))
1651 return GetCellAbove(cell);
1652 return cell_info[row_of_cell(cell) - 1][right_column_of_cell(cell)].cellno;
1656 int LyXTabular::GetLastCellBelow(int cell) const
1658 if (row_of_cell(cell) + 1 >= rows_)
1660 if (!IsMultiColumn(cell))
1661 return GetCellBelow(cell);
1662 return cell_info[row_of_cell(cell) + 1][right_column_of_cell(cell)].cellno;
1666 int LyXTabular::GetCellNumber(int row, int column) const
1668 if (column >= columns_)
1669 column = columns_ - 1;
1670 else if (column < 0)
1677 return cell_info[row][column].cellno;
1681 void LyXTabular::SetUsebox(int cell, BoxType type)
1683 cellinfo_of_cell(cell)->usebox = type;
1687 int LyXTabular::GetUsebox(int cell) const
1689 if (column_info[column_of_cell(cell)].p_width.empty() &&
1690 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
1692 if (cellinfo_of_cell(cell)->usebox > 1)
1693 return cellinfo_of_cell(cell)->usebox;
1694 return UseParbox(cell);
1698 void LyXTabular::SetLTHead(int cell, bool first)
1700 int const row = row_of_cell(cell);
1701 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1704 if (endfirsthead == val)
1717 bool LyXTabular::GetRowOfLTHead(int cell, int & row) const
1720 if (abs(endhead) > rows_)
1722 return (row_of_cell(cell) == abs(endhead) - 1);
1726 bool LyXTabular::GetRowOfLTFirstHead(int cell, int & row) const
1729 if (abs(endfirsthead) > rows_)
1731 return (row_of_cell(cell) == abs(endfirsthead) - 1);
1735 void LyXTabular::SetLTFoot(int cell, bool last)
1737 int const row = row_of_cell(cell);
1738 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1741 if (endlastfoot == val)
1754 bool LyXTabular::GetRowOfLTFoot(int cell, int & row) const
1757 if ((endfoot + 1) > rows_)
1759 return (row_of_cell(cell) == abs(endfoot) - 1);
1763 bool LyXTabular::GetRowOfLTLastFoot(int cell, int & row) const
1766 if (abs(endlastfoot) > rows_)
1768 return (row_of_cell(cell) == (abs(endlastfoot)-1));
1772 void LyXTabular::SetLTNewPage(int cell, bool what)
1774 row_info[row_of_cell(cell)].newpage = what;
1778 bool LyXTabular::GetLTNewPage(int cell) const
1780 return row_info[row_of_cell(cell)].newpage;
1784 bool LyXTabular::SetAscentOfRow(int row, int height)
1786 if ((row >= rows_) || (row_info[row].ascent_of_row == height))
1788 row_info[row].ascent_of_row = height;
1793 bool LyXTabular::SetDescentOfRow(int row, int height)
1795 if ((row >= rows_) || (row_info[row].descent_of_row == height))
1797 row_info[row].descent_of_row = height;
1802 int LyXTabular::GetAscentOfRow(int row) const
1806 return row_info[row].ascent_of_row;
1810 int LyXTabular::GetDescentOfRow(int row) const
1814 return row_info[row].descent_of_row;
1818 int LyXTabular::GetHeightOfTabular() const
1822 for(int row = 0; row < rows_; ++row)
1823 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
1824 GetAdditionalHeight(GetCellNumber(row, 0));
1829 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
1831 if ((row >= rows_) || (column >= columns_))
1833 return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
1837 int LyXTabular::TeXTopHLine(ostream & os, int row) const
1839 #warning should this return a bool? (Lgb)
1840 int const fcell = GetFirstCellInRow(row);
1841 int const n = NumberOfCellsInRow(fcell) + fcell;
1844 for (int i = fcell; i < n; ++i) {
1848 if (tmp == (n - fcell)){
1851 for (int i = fcell; i < n; ++i) {
1854 << column_of_cell(i) + 1
1856 << right_column_of_cell(i) + 1
1869 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
1871 #warning should this return a bool? (Lgb)
1872 int const fcell = GetFirstCellInRow(row);
1873 int const n = NumberOfCellsInRow(fcell) + fcell;
1876 for (int i = fcell; i < n; ++i) {
1880 if (tmp == (n-fcell)){
1883 for (int i = fcell; i < n; ++i) {
1884 if (BottomLine(i)) {
1886 << column_of_cell(i) + 1
1888 << right_column_of_cell(i) + 1
1901 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
1905 if (GetRotateCell(cell)) {
1906 os << "\\begin{sideways}" << endl;
1909 if (IsMultiColumn(cell)) {
1910 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
1911 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1912 os << cellinfo_of_cell(cell+1)->align_special << "}{";
1916 if (!GetPWidth(cell).empty()) {
1917 switch(GetVAlignment(cell)) {
1918 case LYX_VALIGN_TOP:
1921 case LYX_VALIGN_CENTER:
1924 case LYX_VALIGN_BOTTOM:
1928 os << "{" << GetPWidth(cell) << '}';
1930 switch (GetAlignment(cell)) {
1931 case LYX_ALIGN_LEFT:
1934 case LYX_ALIGN_RIGHT:
1942 if (RightLine(cell))
1944 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
1950 if (GetUsebox(cell) == BOX_PARBOX) {
1952 switch(GetVAlignment(cell)) {
1953 case LYX_VALIGN_TOP:
1956 case LYX_VALIGN_CENTER:
1959 case LYX_VALIGN_BOTTOM:
1963 os << "]{" << GetPWidth(cell) << "}{";
1964 } else if (GetUsebox(cell) == BOX_MINIPAGE) {
1965 os << "\\begin{minipage}[";
1966 switch(GetVAlignment(cell)) {
1967 case LYX_VALIGN_TOP:
1970 case LYX_VALIGN_CENTER:
1973 case LYX_VALIGN_BOTTOM:
1977 os << "]{" << GetPWidth(cell) << "}\n";
1984 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
1989 if (GetUsebox(cell) == BOX_PARBOX)
1991 else if (GetUsebox(cell) == BOX_MINIPAGE) {
1992 os << "%\n\\end{minipage}";
1995 if (IsMultiColumn(cell)){
1998 if (GetRotateCell(cell)) {
1999 os << "%\n\\end{sideways}";
2006 int LyXTabular::Latex(Buffer const * buf,
2007 ostream & os, bool fragile, bool fp) const
2013 //+---------------------------------------------------------------------
2014 //+ first the opening preamble +
2015 //+---------------------------------------------------------------------
2018 os << "\\begin{sideways}" << endl;
2021 if (is_long_tabular)
2022 os << "\\begin{longtable}{";
2024 os << "\\begin{tabular}{";
2025 for (i = 0; i < columns_; ++i) {
2026 if (column_info[i].left_line)
2028 if (!column_info[i].align_special.empty()) {
2029 os << column_info[i].align_special;
2030 } else if (!column_info[i].p_width.empty()) {
2031 switch(column_info[i].valignment) {
2032 case LYX_VALIGN_TOP:
2035 case LYX_VALIGN_CENTER:
2038 case LYX_VALIGN_BOTTOM:
2043 << column_info[i].p_width
2046 switch (column_info[i].alignment) {
2047 case LYX_ALIGN_LEFT:
2050 case LYX_ALIGN_RIGHT:
2058 if (column_info[i].right_line)
2064 //+---------------------------------------------------------------------
2065 //+ the single row and columns (cells) +
2066 //+---------------------------------------------------------------------
2069 for(i=0; i < rows_; ++i) {
2070 ret += TeXTopHLine(os, i);
2072 if (IsLongTabular()) {
2073 if ((endhead < 0) && (i == (abs(endhead)-1))) {
2074 os << "\\endhead\n";
2077 if ((endfirsthead < 0) && (i == (abs(endfirsthead)-1))) {
2078 os << "\\endfirsthead\n";
2081 if ((endfoot < 0) && (i == (abs(endfoot)-1))) {
2082 os << "\\endfoot\n";
2085 if ((endlastfoot < 0) && (i == (abs(endlastfoot)-1))) {
2086 os << "\\endlastfoot\n";
2092 ret += TeXBottomHLine(os, i-1);
2093 ret += TeXTopHLine(os, i);
2095 for(j=0; j < columns_; ++j) {
2096 if (IsPartOfMultiColumn(i,j))
2098 ret += TeXCellPreamble(os, cell);
2099 ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
2100 ret += TeXCellPostamble(os, cell);
2101 if (!IsLastCellInRow(cell)) { // not last cell in row
2107 os << "\\\\" << endl;
2108 ret += TeXBottomHLine(os, i);
2110 if (IsLongTabular()) {
2111 if ((endhead > 0) && (i == (endhead-1))) {
2112 os << "\\endhead\n";
2115 if ((endfirsthead > 0) && (i == (endfirsthead-1))) {
2116 os << "\\endfirsthead\n";
2119 if ((endfoot > 0) && (i == (endfoot-1))) {
2120 os << "\\endfoot\n";
2123 if ((endlastfoot > 0) && (i == (endlastfoot-1))) {
2124 os << "\\endlastfoot\n";
2128 ret += TeXBottomHLine(os, i);
2129 if (row_info[i].newpage) {
2130 os << "\\newpage\n";
2136 //+---------------------------------------------------------------------
2137 //+ the closing of the tabular +
2138 //+---------------------------------------------------------------------
2140 if (is_long_tabular)
2141 os << "\\end{longtable}";
2143 os << "\\end{tabular}";
2145 os << "\n\\end{sideways}";
2153 InsetText * LyXTabular::GetCellInset(int cell) const
2155 return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
2159 void LyXTabular::Validate(LaTeXFeatures & features) const
2161 if (IsLongTabular())
2162 features.longtable = true;
2164 features.rotating = true;
2165 for(int cell = 0; cell < numberofcells; ++cell) {
2166 if (GetVAlignment(cell) != LYX_VALIGN_TOP)
2167 features.array = true;
2168 GetCellInset(cell)->Validate(features);
2173 bool LyXTabular::UseParbox(int cell) const
2175 LyXParagraph * par = GetCellInset(cell)->par;
2177 for(; par; par = par->next) {
2178 for(int i = 0; i < par->Last(); ++i) {
2179 if (par->GetChar(i) == LyXParagraph::META_NEWLINE)