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 = row_vector(rows_, rowstruct());
164 column_info = column_vector(columns_, columnstruct());
165 cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct()));
167 // Jürgen, use iterators.
169 for (int i = 0; i < rows_; ++i) {
170 for (int j = 0; j < columns_; ++j) {
171 cell_info[i][j].inset.setOwner(owner_);
172 cell_info[i][j].inset.SetDrawFrame(0, InsetText::LOCKED);
173 cell_info[i][j].cellno = cellno++;
176 //row_info[i - 1].bottom_line = true;
177 //row_info[0].bottom_line = true;
178 row_info.back().bottom_line = true;
179 row_info.front().bottom_line = true;
181 for (int i = 0; i < columns_; ++i) {
182 calculate_width_of_column(i);
184 //column_info[columns_ - 1].right_line = true;
185 column_info.back().right_line = true;
187 calculate_width_of_tabular();
191 set_row_column_number_info();
192 is_long_tabular = false;
201 void LyXTabular::AppendRow(int cell)
205 int row = row_of_cell(cell);
207 row_vector::iterator rit = row_info.begin() + row;
208 row_info.insert(rit, rowstruct());
211 cell_vvector::iterator cit = cell_info.begin() + row;
212 cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
214 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
217 for(int i = 0; i <= row; ++i) {
218 for(int j = 0; j < columns_; ++j) {
219 c_info[i][j] = cell_info[i][j];
222 for(int i = row + 1; i < rows_; ++i) {
223 for(int j = 0; j < columns_; ++j) {
224 c_info[i][j] = cell_info[i-1][j];
229 for (int j = 0; j < columns_; ++j) {
230 cell_info[row][j].inset.clear();
237 void LyXTabular::DeleteRow(int row)
239 // Why make it so hard? (Lgb)
242 if (rows_ == 1) return; // Not allowed to delete last row
244 row_info.erase(row_info.begin() + row); //&row_info[row]);
245 cell_info.erase(cell_info.begin() + row); //&cell_info[row]);
251 void LyXTabular::AppendColumn(int cell)
255 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
257 int column = column_of_cell(cell);
258 column_vector::iterator cit = column_info.begin() + column + 1;
259 column_info.insert(cit, columnstruct());
261 for (int i = 0; i < rows_; ++i) {
262 for (int j = 0; j <= column; ++j) {
263 c_info[i][j] = cell_info[i][j];
265 for (int j = column + 1; j < columns_; ++j) {
266 c_info[i][j] = cell_info[i][j - 1];
268 // care about multicolumns
269 if (cell_info[i][column + 1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
270 cell_info[i][column + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
272 if ((column + 1) == columns_ ||
273 cell_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN) {
274 cell_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL;
279 for (int i = 0; i < rows_; ++i) {
280 cell_info[i][column].inset.clear();
286 void LyXTabular::DeleteColumn(int column)
288 // Similar to DeleteRow
289 //if (!(columns_ - 1))
291 if (columns_ == 1) return; // Not allowed to delete last column
293 column_info.erase(column_info.begin() + column);
294 for (int i = 0; i < rows_; ++i) {
295 cell_info[i].erase(cell_info[i].begin() + column);
302 void LyXTabular::Reinit()
304 // Jürgen, use iterators.
305 for (int i = 0; i < rows_; ++i) {
306 for (int j = 0; j < columns_; ++j) {
307 cell_info[i][j].width_of_cell = 0;
308 cell_info[i][j].inset.setOwner(owner_);
312 for (int i = 0; i < columns_; ++i) {
313 calculate_width_of_column(i);
315 calculate_width_of_tabular();
317 set_row_column_number_info();
321 void LyXTabular::set_row_column_number_info()
327 for (; row < rows_; ++row) {
328 for (column = 0; column<columns_; ++column) {
329 if (cell_info[row][column].multicolumn
330 != LyXTabular::CELL_PART_OF_MULTICOLUMN)
332 cell_info[row][column].cellno = numberofcells;
335 ++numberofcells; // because this is one more than as we start from 0
340 rowofcell = new int[numberofcells];
341 delete [] columnofcell;
342 columnofcell = new int[numberofcells];
344 while (c < numberofcells && row < rows_ && column < columns_) {
346 columnofcell[c] = column;
350 } while (column < columns_ &&
351 cell_info[row][column].multicolumn
352 == LyXTabular::CELL_PART_OF_MULTICOLUMN);
353 if (column == columns_) {
358 for (row = 0; row < rows_; ++row) {
359 for (column = 0; column<columns_; ++column) {
360 if (IsPartOfMultiColumn(row,column))
362 cell_info[row][column].inset.SetAutoBreakRows(
363 !GetPWidth(GetCellNumber(row, column)).empty());
369 int LyXTabular::GetNumberOfCells() const
371 return numberofcells;
375 int LyXTabular::NumberOfCellsInRow(int cell) const
377 int const row = row_of_cell(cell);
379 for (int i = 0; i < columns_; ++i) {
380 if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
387 /* returns 1 if there is a topline, returns 0 if not */
388 bool LyXTabular::TopLine(int cell, bool onlycolumn) const
390 int const row = row_of_cell(cell);
392 if (!onlycolumn && IsMultiColumn(cell))
393 return cellinfo_of_cell(cell)->top_line;
394 return row_info[row].top_line;
398 bool LyXTabular::BottomLine(int cell, bool onlycolumn) const
400 // no bottom line underneath non-existent cells if you please
401 // Isn't that a programming error? Is so this should
402 // be an Assert instead. (Lgb)
403 if(cell >= numberofcells)
406 if (!onlycolumn && IsMultiColumn(cell))
407 return cellinfo_of_cell(cell)->bottom_line;
408 return row_info[row_of_cell(cell)].bottom_line;
412 bool LyXTabular::LeftLine(int cell, bool onlycolumn) const
414 if (!onlycolumn && IsMultiColumn(cell))
415 return cellinfo_of_cell(cell)->left_line;
416 return column_info[column_of_cell(cell)].left_line;
420 bool LyXTabular::RightLine(int cell, bool onlycolumn) const
422 if (!onlycolumn && IsMultiColumn(cell))
423 return cellinfo_of_cell(cell)->right_line;
424 return column_info[right_column_of_cell(cell)].right_line;
428 bool LyXTabular::TopAlreadyDrawed(int cell) const
430 if (GetAdditionalHeight(cell))
432 int row = row_of_cell(cell);
434 int column = column_of_cell(cell);
437 && cell_info[row][column].multicolumn
438 == LyXTabular::CELL_PART_OF_MULTICOLUMN)
440 if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL)
441 return row_info[row].bottom_line;
443 return cell_info[row][column].bottom_line;
449 bool LyXTabular::LeftAlreadyDrawed(int cell) const
451 int column = column_of_cell(cell);
453 int row = row_of_cell(cell);
455 (cell_info[row][column].multicolumn ==
456 LyXTabular::CELL_PART_OF_MULTICOLUMN));
457 if (GetAdditionalWidth(cell_info[row][column].cellno))
459 return column_info[column].right_line;
465 bool LyXTabular::IsLastRow(int cell) const
467 return (row_of_cell(cell) == rows_ - 1);
471 int LyXTabular::GetAdditionalHeight(int cell) const
473 int const row = row_of_cell(cell);
476 #warning Jürgen, should the types change? (Lgb)
477 int top = 1; // bool top = true; ??
478 int bottom = 1; // bool bottom = true; ??
480 for (int column = 0; column < columns_ - 1 && bottom; ++column) {
481 switch (cell_info[row - 1][column].multicolumn) {
482 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
483 bottom = cell_info[row - 1][column].bottom_line;
485 case LyXTabular::CELL_NORMAL:
486 bottom = row_info[row - 1].bottom_line;
489 for (int column = 0; column < columns_ - 1 && top; ++column) {
490 switch (cell_info[row][column].multicolumn){
491 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
492 top = cell_info[row][column].top_line;
494 case LyXTabular::CELL_NORMAL:
495 top = row_info[row].top_line;
499 return WIDTH_OF_LINE;
504 int LyXTabular::GetAdditionalWidth(int cell) const
506 // internally already set in SetWidthOfCell
507 // used to get it back in text.C
508 int const col = right_column_of_cell(cell);
509 if (col < columns_ - 1 && column_info[col].right_line &&
510 column_info[col+1].left_line)
511 return WIDTH_OF_LINE;
517 // returns the maximum over all rows
518 int LyXTabular::GetWidthOfColumn(int cell) const
520 int const column1 = column_of_cell(cell);
521 int const column2 = right_column_of_cell(cell);
524 for (; i <= column2; ++i) {
525 result += column_info[i].width_of_column;
531 int LyXTabular::GetWidthOfTabular() const
533 return width_of_tabular;
537 /* returns 1 if a complete update is necessary, otherwise 0 */
538 bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
540 if (!IsMultiColumn(cell))
543 int const row = row_of_cell(cell);
544 int const column1 = column_of_cell(cell);
545 int const column2 = right_column_of_cell(cell);
547 // first set columns to 0 so we can calculate the right width
549 for (; i <= column2; ++i) {
550 cell_info[row][i].width_of_cell = 0;
552 // set the width to MAX_WIDTH until width > 0
553 int width = (new_width + 2 * WIDTH_OF_LINE);
555 i < column2 && width > column_info[i].width_of_column;
557 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
558 width -= column_info[i].width_of_column;
561 cell_info[row][i].width_of_cell = width;
567 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
569 int const row = row_of_cell(cell);
570 int const column1 = column_of_cell(cell);
571 int const column2 = right_column_of_cell(cell);
573 // first set columns to 0 so we can calculate the right width
575 for (; i <= column2; ++i)
576 cell_info[row][i].width_of_cell = 0;
577 for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
579 if (i < numberofcells)
580 recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
581 SetWidthOfMulticolCell(cell, new_width);
585 /* returns 1 if a complete update is necessary, otherwise 0 */
586 bool LyXTabular::SetWidthOfCell(int cell, int new_width)
588 int const row = row_of_cell(cell);
589 int const column1 = column_of_cell(cell);
593 if (GetWidthOfCell(cell) == (new_width+2*WIDTH_OF_LINE))
595 if (IsMultiColumn(cell, true)) {
596 tmp = SetWidthOfMulticolCell(cell, new_width);
598 width = (new_width + 2*WIDTH_OF_LINE);
599 cell_info[row][column1].width_of_cell = width;
600 if (column_info[column1].right_line && (column1 < columns_-1) &&
601 column_info[column1+1].left_line) // additional width
602 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
603 tmp = calculate_width_of_column_NMC(column1);
607 for(; i<columns_; ++i)
608 calculate_width_of_column_NMC(i);
609 for(i = 0; (i < numberofcells) && !IsMultiColumn(i); ++i)
611 if (i < numberofcells)
612 recalculateMulticolCells(i, GetWidthOfCell(i)-(2 * WIDTH_OF_LINE));
613 for(i = 0; i < columns_; ++i)
614 calculate_width_of_column(i);
615 calculate_width_of_tabular();
622 bool LyXTabular::SetAlignment(int cell, char align, bool onlycolumn)
624 #warning Please fix align type. (Lgb)
625 if (!IsMultiColumn(cell) || onlycolumn)
626 column_info[column_of_cell(cell)].alignment = align;
628 cellinfo_of_cell(cell)->alignment = align;
633 bool LyXTabular::SetVAlignment(int cell, char align, bool onlycolumn)
635 #warning Please fix align type. (Lgb)
636 if (!IsMultiColumn(cell) || onlycolumn)
637 column_info[column_of_cell(cell)].valignment = align;
639 cellinfo_of_cell(cell)->valignment = align;
644 bool LyXTabular::SetColumnPWidth(int cell, string const & width)
646 bool flag = !width.empty();
647 int const j = column_of_cell(cell);
649 column_info[j].p_width = width;
650 if (flag) // do this only if there is a width
651 SetAlignment(cell, LYX_ALIGN_LEFT);
652 for(int i = 0; i < rows_; ++i) {
653 int c = GetCellNumber(i, j);
654 flag = !GetPWidth(c).empty(); // because of multicolumns!
655 GetCellInset(c)->SetAutoBreakRows(flag);
661 bool LyXTabular::SetMColumnPWidth(int cell, string const & width)
663 bool const flag = !width.empty();
665 cellinfo_of_cell(cell)->p_width = width;
666 if (IsMultiColumn(cell)) {
667 GetCellInset(cell)->SetAutoBreakRows(flag);
674 bool LyXTabular::SetAlignSpecial(int cell, string const & special, int what)
676 #warning Fix the "what" type. (Lgb)
677 if (what == SET_SPECIAL_MULTI)
678 cellinfo_of_cell(cell)->align_special = special;
680 column_info[column_of_cell(cell)].align_special = special;
685 bool LyXTabular::SetAllLines(int cell, bool line)
687 SetTopLine(cell, line);
688 SetBottomLine(cell, line);
689 SetRightLine(cell, line);
690 SetLeftLine(cell, line);
695 bool LyXTabular::SetTopLine(int cell, bool line, bool onlycolumn)
697 int const row = row_of_cell(cell);
699 if (onlycolumn || !IsMultiColumn(cell))
700 row_info[row].top_line = line;
702 cellinfo_of_cell(cell)->top_line = line;
707 bool LyXTabular::SetBottomLine(int cell, bool line, bool onlycolumn)
709 if (onlycolumn || !IsMultiColumn(cell))
710 row_info[row_of_cell(cell)].bottom_line = line;
712 cellinfo_of_cell(cell)->bottom_line = line;
717 bool LyXTabular::SetLeftLine(int cell, bool line, bool onlycolumn)
719 if (onlycolumn || !IsMultiColumn(cell))
720 column_info[column_of_cell(cell)].left_line = line;
722 cellinfo_of_cell(cell)->left_line = line;
727 bool LyXTabular::SetRightLine(int cell, bool line, bool onlycolumn)
729 if (onlycolumn || !IsMultiColumn(cell))
730 column_info[right_column_of_cell(cell)].right_line = line;
732 cellinfo_of_cell(cell)->right_line = line;
737 char LyXTabular::GetAlignment(int cell, bool onlycolumn) const
739 #warning Fix return type. (Lgb)
740 if (!onlycolumn && IsMultiColumn(cell))
741 return cellinfo_of_cell(cell)->alignment;
743 return column_info[column_of_cell(cell)].alignment;
747 char LyXTabular::GetVAlignment(int cell, bool onlycolumn) const
749 #warning Fix return type. (Lgb)
750 if (!onlycolumn && IsMultiColumn(cell))
751 return cellinfo_of_cell(cell)->valignment;
753 return column_info[column_of_cell(cell)].valignment;
757 string const LyXTabular::GetPWidth(int cell) const
759 if (IsMultiColumn(cell))
760 return cellinfo_of_cell(cell)->p_width;
761 return column_info[column_of_cell(cell)].p_width;
765 string const LyXTabular::GetColumnPWidth(int cell) const
767 return column_info[column_of_cell(cell)].p_width;
771 string const LyXTabular::GetMColumnPWidth(int cell) const
773 if (IsMultiColumn(cell))
774 return cellinfo_of_cell(cell)->p_width;
779 string const LyXTabular::GetAlignSpecial(int cell, int what) const
781 if (what == SET_SPECIAL_MULTI)
782 return cellinfo_of_cell(cell)->align_special;
783 return column_info[column_of_cell(cell)].align_special;
787 int LyXTabular::GetWidthOfCell(int cell) const
789 int const row = row_of_cell(cell);
790 int const column1 = column_of_cell(cell);
791 int const column2 = right_column_of_cell(cell);
793 for (int i = column1; i <= column2; ++i) {
794 result += cell_info[row][i].width_of_cell;
800 int LyXTabular::GetBeginningOfTextInCell(int cell) const
804 switch (GetAlignment(cell)){
805 case LYX_ALIGN_CENTER:
806 x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
808 case LYX_ALIGN_RIGHT:
809 x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
810 // + GetAdditionalWidth(cell);
812 default: /* LYX_ALIGN_LEFT: nothing :-) */
822 bool LyXTabular::IsFirstCellInRow(int cell) const
824 return column_of_cell(cell) == 0;
828 int LyXTabular::GetFirstCellInRow(int row) const
832 return cell_info[row][0].cellno;
835 bool LyXTabular::IsLastCellInRow(int cell) const
837 return (right_column_of_cell(cell) == (columns_ - 1));
841 int LyXTabular::GetLastCellInRow(int row) const
845 return cell_info[row][columns_-1].cellno;
849 bool LyXTabular::calculate_width_of_column(int column)
851 int const old_column_width = column_info[column].width_of_column;
854 for (int i = 0; i < rows_; ++i) {
855 maximum = max(cell_info[i][column].width_of_cell, maximum);
857 column_info[column].width_of_column = maximum;
858 return (column_info[column].width_of_column != old_column_width);
863 // calculate the with of the column without regarding REAL MultiColumn
864 // cells. This means MultiColumn-cells spanning more than 1 column.
866 bool LyXTabular::calculate_width_of_column_NMC(int column)
868 int const old_column_width = column_info[column].width_of_column;
870 for (int i = 0; i < rows_; ++i) {
871 if (!IsMultiColumn(GetCellNumber(i, column), true) &&
872 (cell_info[i][column].width_of_cell > max)) {
873 max = cell_info[i][column].width_of_cell;
876 column_info[column].width_of_column = max;
877 return (column_info[column].width_of_column != old_column_width);
881 void LyXTabular::calculate_width_of_tabular()
883 width_of_tabular = 0;
884 for (int i = 0; i < columns_; ++i) {
885 width_of_tabular += column_info[i].width_of_column;
890 int LyXTabular::row_of_cell(int cell) const
892 if (cell >= numberofcells)
896 return rowofcell[cell];
900 int LyXTabular::column_of_cell(int cell) const
902 if (cell >= numberofcells)
906 return columnofcell[cell];
910 int LyXTabular::right_column_of_cell(int cell) const
912 int const row = row_of_cell(cell);
913 int column = column_of_cell(cell);
914 while (column < (columns_ - 1) &&
915 cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
921 void LyXTabular::Write(Buffer const * buf, ostream & os) const
924 os << "<LyXTabular version=1 rows=" << rows_
925 << " columns=" << columns_ << ">\n";
926 // global longtable options
927 os << "<Features rotate=" << rotate
928 << " islongtable=" << is_long_tabular
929 << " endhead=" << endhead
930 << " endfirsthead=" << endfirsthead
931 << " endfoot=" << endfoot
932 << " endlastfoot=" << endlastfoot << ">\n\n";
933 for (int i = 0; i < rows_; ++i) {
934 os << "<Row topline=" << row_info[i].top_line
935 << " bottomline=" << row_info[i].bottom_line
936 << " newpage=" << row_info[i].newpage << ">\n";
937 for (int j = 0; j < columns_; ++j) {
939 os << "<Column alignment=" << column_info[j].alignment
940 << " valignment=" << column_info[j].valignment
941 << " leftline=" << column_info[j].left_line
942 << " rightline=" << column_info[j].right_line
943 << " width=\"" << VSpace(column_info[j].p_width).asLyXCommand()
944 << "\" special=\"" << column_info[j].align_special
949 os << "<Cell multicolumn=" << cell_info[i][j].multicolumn
950 << " alignment=" << cell_info[i][j].alignment
951 << " valignment=" << cell_info[i][j].valignment
952 << " topline=" << cell_info[i][j].top_line
953 << " bottomline=" << cell_info[i][j].bottom_line
954 << " leftline=" << cell_info[i][j].left_line
955 << " rightline=" << cell_info[i][j].right_line
956 << " rotate=" << cell_info[i][j].rotate
957 << " usebox=" << (int)cell_info[i][j].usebox
958 << " width=\"" << cell_info[i][j].p_width
959 << "\" special=\"" << cell_info[i][j].align_special
961 os << "\\begin_inset ";
962 cell_info[i][j].inset.Write(buf, os);
963 os << "\n\\end_inset \n"
969 os << "</LyXTabular>\n";
974 bool getTokenValue(string const str, const char * token, string & ret)
976 int pos = str.find(token);
977 char ch = str[pos+strlen(token)];
979 if ((pos < 0) || (ch != '='))
982 pos += strlen(token)+1;
984 if ((ch != '"') && (ch != '\'')) { // only read till next space
988 while((pos < int(str.length()-1)) && (str[++pos] != ch))
996 bool getTokenValue(string const str, const char * token, int & num)
998 int pos = str.find(token);
999 char ch = str[pos+strlen(token)];
1001 if ((pos < 0) || (ch != '='))
1004 //ret.erase(); // why? (Lgb)
1005 pos += strlen(token)+1;
1007 if ((ch != '"') && (ch != '\'')) { // only read till next space
1013 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1016 num = strToInt(ret);
1022 bool getTokenValue(string const str, const char * token, bool & flag)
1024 int pos = str.find(token);
1025 char ch = str[pos+strlen(token)];
1027 if ((pos < 0) || (ch != '='))
1030 //ret.erase(); // Why? (Lgb)
1031 pos += strlen(token)+1;
1033 if ((ch != '"') && (ch != '\'')) { // only read till next space
1039 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1042 flag = strToInt(ret);
1048 void l_getline(istream & is, string & str)
1056 void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
1059 istream & is = lex.getStream();
1061 l_getline(is, line);
1062 if (!prefixIs(line, "<LyXTabular ")) {
1063 OldFormatRead(lex, line);
1070 if (!getTokenValue(line, "version", version))
1072 if (!getTokenValue(line, "rows", rows_arg))
1074 if (!getTokenValue(line, "columns", columns_arg))
1076 Init(rows_arg, columns_arg);
1077 l_getline(is, line);
1078 if (!prefixIs(line, "<Features ")) {
1079 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
1080 line << ")" << endl;
1083 getTokenValue(line, "islongtable", is_long_tabular);
1084 getTokenValue(line, "endhead", endhead);
1085 getTokenValue(line, "endfirsthead", endfirsthead);
1086 getTokenValue(line, "endfoot", endfoot);
1087 getTokenValue(line, "endlastfoot", endlastfoot);
1089 for(i = 0; i < rows_; ++i) {
1090 l_getline(is, line);
1091 if (!prefixIs(line, "<Row ")) {
1092 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
1093 line << ")" << endl;
1096 getTokenValue(line, "topline", row_info[i].top_line);
1097 getTokenValue(line, "bottomline", row_info[i].bottom_line);
1098 getTokenValue(line, "newpage", row_info[i].newpage);
1099 for (j = 0; j < columns_; ++j) {
1101 if (!prefixIs(line,"<Column")) {
1102 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
1103 line << ")" << endl;
1107 getTokenValue(line, "alignment", column_info[j].alignment);
1108 getTokenValue(line, "valignment", column_info[j].valignment);
1109 getTokenValue(line, "leftline", column_info[j].left_line);
1110 getTokenValue(line, "rightline", column_info[j].right_line);
1111 getTokenValue(line, "width", column_info[j].p_width);
1112 getTokenValue(line, "special", column_info[j].align_special);
1114 l_getline(is, line);
1115 if (!prefixIs(line, "<Cell")) {
1116 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
1117 line << ")" << endl;
1120 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1121 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1122 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1123 getTokenValue(line, "topline", cell_info[i][j].top_line);
1124 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1125 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1126 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1127 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1128 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1129 getTokenValue(line, "width", cell_info[i][j].p_width);
1130 getTokenValue(line, "special", cell_info[i][j].align_special);
1131 l_getline(is, line);
1132 if (prefixIs(line, "\\begin_inset")) {
1133 cell_info[i][j].inset.Read(buf, lex);
1134 l_getline(is, line);
1136 if (line != "</Cell>") {
1137 lyxerr << "Wrong tabular format (expected </Cell> got" <<
1138 line << ")" << endl;
1141 l_getline(is, line);
1142 if (line != "</Column>") {
1143 lyxerr << "Wrong tabular format (expected </Column> got" <<
1144 line << ")" << endl;
1148 l_getline(is, line);
1149 if (line != "</Row>") {
1150 lyxerr << "Wrong tabular format (expected </Row> got" <<
1151 line << ")" << endl;
1155 while (line != "</LyXTabular>") {
1156 l_getline(is, line);
1158 set_row_column_number_info();
1162 void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
1167 int columns_arg = 0;
1168 int is_long_tabular_arg = false;
1169 int rotate_arg = false;
1179 istream & is = lex.getStream();
1182 version = lyx::atoi(s.substr(8, string::npos));
1186 vector<int> cont_row_info;
1189 lyxerr << "Tabular format < 5 is not supported anymore\n"
1190 "Get an older version of LyX (< 1.1.x) for conversion!"
1192 WriteAlert(_("Warning:"),
1193 _("Tabular format < 5 is not supported anymore\n"),
1194 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1196 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1197 >> rotate_arg >> a >> b >> c >> d;
1199 is >> rows_arg >> columns_arg;
1200 Init(rows_arg, columns_arg);
1201 cont_row_info = vector<int>(rows_arg);
1202 SetLongTabular(is_long_tabular_arg);
1203 SetRotateTabular(rotate_arg);
1205 for (i = 0; i < rows_; ++i) {
1207 cont_row_info[i] = false;
1209 for (i = 0; i < columns_; ++i) {
1212 for (i = 0; i < rows_; ++i) {
1213 for (j = 0; j < columns_; ++j) {
1218 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1219 >> rotate_arg >> a >> b >> c >> d;
1220 Init(rows_arg, columns_arg);
1221 cont_row_info = vector<int>(rows_arg);
1222 SetLongTabular(is_long_tabular_arg);
1223 SetRotateTabular(rotate_arg);
1228 for (i = 0; i < rows_; ++i) {
1229 a = b = c = d = e = f = g = h = 0;
1230 is >> a >> b >> c >> d;
1231 row_info[i].top_line = a;
1232 row_info[i].bottom_line = b;
1233 cont_row_info[i] = c;
1234 row_info[i].newpage = d;
1236 for (i = 0; i < columns_; ++i) {
1240 char ch; // skip '"'
1242 getline(is, s1, '"');
1243 is >> ch; // skip '"'
1244 getline(is, s2, '"');
1245 column_info[i].alignment = static_cast<char>(a);
1246 column_info[i].left_line = b;
1247 column_info[i].right_line = c;
1248 column_info[i].p_width = s1;
1249 column_info[i].align_special = s2;
1251 for (i = 0; i < rows_; ++i) {
1252 for (j = 0; j < columns_; ++j) {
1255 is >> a >> b >> c >> d >> e >> f >> g;
1257 is >> ch; // skip '"'
1258 getline(is, s1, '"');
1259 is >> ch; // skip '"'
1260 getline(is, s2, '"');
1261 cell_info[i][j].multicolumn = static_cast<char>(a);
1262 cell_info[i][j].alignment = static_cast<char>(b);
1263 cell_info[i][j].top_line = static_cast<char>(c);
1264 cell_info[i][j].bottom_line = static_cast<char>(d);
1265 cell_info[i][j].rotate = static_cast<bool>(f);
1266 cell_info[i][j].usebox = static_cast<bool>(g);
1267 cell_info[i][j].align_special = s1;
1268 cell_info[i][j].p_width = s2;
1272 set_row_column_number_info();
1274 LyXParagraph * par = new LyXParagraph;
1275 LyXParagraph * return_par = 0;
1277 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1278 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
1283 LyXFont font(LyXFont::ALL_SANE);
1285 while (lex.IsOK()) {
1287 string const token = lex.GetString();
1290 if (token == "\\layout"
1291 || token == "\\end_float"
1292 || token == "\\end_deeper") {
1293 lex.pushToken(token);
1296 if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
1308 lex.pushToken(token);
1312 lex.printError("New Paragraph allocated! This should not happen!");
1313 lex.pushToken(token);
1319 // now we have the par we should fill the insets with this!
1321 InsetText * inset = GetCellInset(cell);
1324 for(int i = 0; i < par->Last(); ++i) {
1325 if (par->IsNewline(i)) {
1327 if (cell > GetNumberOfCells()) {
1328 lyxerr << "Some error in reading old table format occured!" <<
1329 endl << "Terminating when reading cell[" << cell << "]!" <<
1334 row = row_of_cell(cell);
1335 if (cont_row_info[row]) {
1337 cont_row_info.erase(cont_row_info.begin() + row); //&cont_row_info[row]);
1338 while(!IsFirstCellInRow(--cell));
1340 inset = GetCellInset(cell);
1343 inset = GetCellInset(cell);
1344 row = row_of_cell(cell);
1345 if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox)
1347 // insert a space instead
1349 par->InsertChar(i, ' ');
1352 par->CopyIntoMinibuffer(current_view->buffer()->params, i);
1353 inset->par->InsertFromMinibuffer(inset->par->Last());
1360 string const LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
1362 int const i = isColumn ? cell : column_of_cell(cell);
1364 if (!isColumn && IsMultiColumn(cell)) {
1365 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1366 return cellinfo_of_cell(cell)->align_special;
1368 switch (GetAlignment(cell)) {
1369 case LYX_ALIGN_LEFT:
1371 case LYX_ALIGN_RIGHT:
1378 if (!column_info[i].align_special.empty()) {
1379 return column_info[i].align_special;
1381 #ifdef IGNORE_THIS_FOR_NOW
1382 else if (!column_info[i].p_width.empty()) {
1384 file += column_info[i].p_width;
1389 switch (column_info[i].alignment) {
1390 case LYX_ALIGN_LEFT:
1392 case LYX_ALIGN_RIGHT:
1402 // cell <0 will tex the preamble
1403 // returns the number of printed newlines
1404 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1407 if (IsLastCell(cell)) {
1408 os << newlineAndDepth(--depth)
1410 << newlineAndDepth(--depth)
1412 << newlineAndDepth(--depth)
1414 << newlineAndDepth(--depth);
1415 if (is_long_tabular)
1419 << newlineAndDepth(--depth);
1424 if (is_long_tabular)
1430 << "' COLSEP='1' ROWSEP='1'>"
1431 << newlineAndDepth(++depth);
1433 for (int i = 0; i < columns_; ++i) {
1434 os << "<COLSPEC ALIGN='"
1435 << GetDocBookAlign(i, true)
1441 if (i == (columns_-1)) {
1444 if (column_info[i].right_line ||
1445 column_info[i+1].left_line)
1451 << newlineAndDepth(depth);
1453 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1454 if (column_info[i].left_line)
1459 << newlineAndDepth(++depth)
1461 << newlineAndDepth(++depth)
1463 << GetDocBookAlign(0)
1465 if (IsMultiColumn(0)) {
1466 os << " NAMEST='col1' NAMEEND='col"
1467 << cells_in_multicolumn(0)
1471 << newlineAndDepth(++depth);
1474 if (IsLastCellInRow(cell)) {
1475 os << newlineAndDepth(--depth)
1477 << newlineAndDepth(--depth)
1479 << newlineAndDepth(depth)
1481 << newlineAndDepth(++depth)
1483 << GetDocBookAlign(cell + 1)
1484 << "' VALIGN='middle'";
1485 if (IsMultiColumn(cell + 1)) {
1486 os << " NAMEST='col"
1487 << column_of_cell(cell + 1) + 1
1489 << column_of_cell(cell + 1) +
1490 cells_in_multicolumn(cell + 1)
1494 << newlineAndDepth(++depth);
1497 os << newlineAndDepth(--depth)
1499 << newlineAndDepth(depth)
1501 << GetDocBookAlign(cell + 1)
1502 << "' VALIGN='middle'";
1503 if (IsMultiColumn(cell + 1)) {
1504 os << " NAMEST='col"
1505 << column_of_cell(cell + 1) + 1
1507 << column_of_cell(cell + 1) +
1508 cells_in_multicolumn(cell + 1)
1512 << newlineAndDepth(++depth);
1521 bool LyXTabular::IsMultiColumn(int cell, bool real) const
1523 return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&
1524 (cellinfo_of_cell(cell)->multicolumn !=LyXTabular::CELL_NORMAL));
1528 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1530 int const row = row_of_cell(cell);
1531 int const column = column_of_cell(cell);
1532 return &cell_info[row][column];
1536 void LyXTabular::SetMultiColumn(int cell, int number)
1538 cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1539 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1540 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1541 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1542 for (number--; number > 0; --number) {
1543 cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
1545 set_row_column_number_info();
1549 int LyXTabular::cells_in_multicolumn(int cell) const
1551 int const row = row_of_cell(cell);
1552 int column = column_of_cell(cell);
1555 while ((column < columns_) &&
1556 cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
1565 int LyXTabular::UnsetMultiColumn(int cell)
1567 int const row = row_of_cell(cell);
1568 int column = column_of_cell(cell);
1572 if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
1573 cell_info[row][column].multicolumn = CELL_NORMAL;
1575 while ((column < columns_) &&
1576 (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN))
1578 cell_info[row][column].multicolumn = CELL_NORMAL;
1583 set_row_column_number_info();
1588 void LyXTabular::SetLongTabular(int what)
1590 #warning Should what be bool? (Lgb)
1591 is_long_tabular = what;
1595 bool LyXTabular::IsLongTabular() const
1597 return is_long_tabular;
1601 void LyXTabular::SetRotateTabular(bool flag)
1607 bool LyXTabular::GetRotateTabular() const
1613 void LyXTabular::SetRotateCell(int cell, bool flag)
1615 cellinfo_of_cell(cell)->rotate = flag;
1619 bool LyXTabular::GetRotateCell(int cell) const
1621 return cellinfo_of_cell(cell)->rotate;
1625 bool LyXTabular::NeedRotating() const
1629 for (int i = 0; i < rows_; ++i) {
1630 for (int j = 0; j < columns_; ++j) {
1631 if (cell_info[i][j].rotate)
1639 bool LyXTabular::IsLastCell(int cell) const
1641 if ((cell + 1) < GetNumberOfCells())
1647 int LyXTabular::GetCellAbove(int cell) const
1649 if (row_of_cell(cell) > 0)
1650 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
1655 int LyXTabular::GetCellBelow(int cell) const
1657 if (row_of_cell(cell) + 1 < rows_)
1658 return cell_info[row_of_cell(cell)+1][column_of_cell(cell)].cellno;
1663 int LyXTabular::GetLastCellAbove(int cell) const
1665 if (row_of_cell(cell) <= 0)
1667 if (!IsMultiColumn(cell))
1668 return GetCellAbove(cell);
1669 return cell_info[row_of_cell(cell) - 1][right_column_of_cell(cell)].cellno;
1673 int LyXTabular::GetLastCellBelow(int cell) const
1675 if (row_of_cell(cell) + 1 >= rows_)
1677 if (!IsMultiColumn(cell))
1678 return GetCellBelow(cell);
1679 return cell_info[row_of_cell(cell) + 1][right_column_of_cell(cell)].cellno;
1683 int LyXTabular::GetCellNumber(int row, int column) const
1685 if (column >= columns_)
1686 column = columns_ - 1;
1687 else if (column < 0)
1694 return cell_info[row][column].cellno;
1698 void LyXTabular::SetUsebox(int cell, BoxType type)
1700 cellinfo_of_cell(cell)->usebox = type;
1704 int LyXTabular::GetUsebox(int cell) const
1706 #warning should the return type change? (Lgb)
1707 if (column_info[column_of_cell(cell)].p_width.empty() &&
1708 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
1710 if (cellinfo_of_cell(cell)->usebox > 1)
1711 return cellinfo_of_cell(cell)->usebox;
1712 return UseParbox(cell);
1716 void LyXTabular::SetLTHead(int cell, bool first)
1718 int const row = row_of_cell(cell);
1719 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1722 if (endfirsthead == val)
1735 bool LyXTabular::GetRowOfLTHead(int cell, int & row) const
1738 if (abs(endhead) > rows_)
1740 return (row_of_cell(cell) == abs(endhead) - 1);
1744 bool LyXTabular::GetRowOfLTFirstHead(int cell, int & row) const
1747 if (abs(endfirsthead) > rows_)
1749 return (row_of_cell(cell) == abs(endfirsthead) - 1);
1753 void LyXTabular::SetLTFoot(int cell, bool last)
1755 int const row = row_of_cell(cell);
1756 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1759 if (endlastfoot == val)
1772 bool LyXTabular::GetRowOfLTFoot(int cell, int & row) const
1775 if ((endfoot + 1) > rows_)
1777 return (row_of_cell(cell) == abs(endfoot) - 1);
1781 bool LyXTabular::GetRowOfLTLastFoot(int cell, int & row) const
1784 if (abs(endlastfoot) > rows_)
1786 return (row_of_cell(cell) == (abs(endlastfoot)-1));
1790 void LyXTabular::SetLTNewPage(int cell, bool what)
1792 row_info[row_of_cell(cell)].newpage = what;
1796 bool LyXTabular::GetLTNewPage(int cell) const
1798 return row_info[row_of_cell(cell)].newpage;
1802 bool LyXTabular::SetAscentOfRow(int row, int height)
1804 if ((row >= rows_) || (row_info[row].ascent_of_row == height))
1806 row_info[row].ascent_of_row = height;
1811 bool LyXTabular::SetDescentOfRow(int row, int height)
1813 if ((row >= rows_) || (row_info[row].descent_of_row == height))
1815 row_info[row].descent_of_row = height;
1820 int LyXTabular::GetAscentOfRow(int row) const
1824 return row_info[row].ascent_of_row;
1828 int LyXTabular::GetDescentOfRow(int row) const
1832 return row_info[row].descent_of_row;
1836 int LyXTabular::GetHeightOfTabular() const
1840 for(int row = 0; row < rows_; ++row)
1841 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
1842 GetAdditionalHeight(GetCellNumber(row, 0));
1847 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
1849 if ((row >= rows_) || (column >= columns_))
1851 return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
1855 int LyXTabular::TeXTopHLine(ostream & os, int row) const
1857 #warning should this return a bool? (Lgb)
1858 int const fcell = GetFirstCellInRow(row);
1859 int const n = NumberOfCellsInRow(fcell) + fcell;
1862 for (int i = fcell; i < n; ++i) {
1866 if (tmp == (n - fcell)){
1869 for (int i = fcell; i < n; ++i) {
1872 << column_of_cell(i) + 1
1874 << right_column_of_cell(i) + 1
1887 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
1889 #warning should this return a bool? (Lgb)
1890 int const fcell = GetFirstCellInRow(row);
1891 int const n = NumberOfCellsInRow(fcell) + fcell;
1894 for (int i = fcell; i < n; ++i) {
1898 if (tmp == (n-fcell)){
1901 for (int i = fcell; i < n; ++i) {
1902 if (BottomLine(i)) {
1904 << column_of_cell(i) + 1
1906 << right_column_of_cell(i) + 1
1919 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
1923 if (GetRotateCell(cell)) {
1924 os << "\\begin{sideways}" << endl;
1927 if (IsMultiColumn(cell)) {
1928 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
1929 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1930 os << cellinfo_of_cell(cell+1)->align_special << "}{";
1934 if (!GetPWidth(cell).empty()) {
1935 switch(GetVAlignment(cell)) {
1936 case LYX_VALIGN_TOP:
1939 case LYX_VALIGN_CENTER:
1942 case LYX_VALIGN_BOTTOM:
1946 os << "{" << GetPWidth(cell) << '}';
1948 switch (GetAlignment(cell)) {
1949 case LYX_ALIGN_LEFT:
1952 case LYX_ALIGN_RIGHT:
1960 if (RightLine(cell))
1962 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
1968 if (GetUsebox(cell) == BOX_PARBOX) {
1970 switch(GetVAlignment(cell)) {
1971 case LYX_VALIGN_TOP:
1974 case LYX_VALIGN_CENTER:
1977 case LYX_VALIGN_BOTTOM:
1981 os << "]{" << GetPWidth(cell) << "}{";
1982 } else if (GetUsebox(cell) == BOX_MINIPAGE) {
1983 os << "\\begin{minipage}[";
1984 switch(GetVAlignment(cell)) {
1985 case LYX_VALIGN_TOP:
1988 case LYX_VALIGN_CENTER:
1991 case LYX_VALIGN_BOTTOM:
1995 os << "]{" << GetPWidth(cell) << "}\n";
2002 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
2007 if (GetUsebox(cell) == BOX_PARBOX)
2009 else if (GetUsebox(cell) == BOX_MINIPAGE) {
2010 os << "%\n\\end{minipage}";
2013 if (IsMultiColumn(cell)){
2016 if (GetRotateCell(cell)) {
2017 os << "%\n\\end{sideways}";
2024 int LyXTabular::Latex(Buffer const * buf,
2025 ostream & os, bool fragile, bool fp) const
2030 //+---------------------------------------------------------------------
2031 //+ first the opening preamble +
2032 //+---------------------------------------------------------------------
2035 os << "\\begin{sideways}" << endl;
2038 if (is_long_tabular)
2039 os << "\\begin{longtable}{";
2041 os << "\\begin{tabular}{";
2042 for (int i = 0; i < columns_; ++i) {
2043 if (column_info[i].left_line)
2045 if (!column_info[i].align_special.empty()) {
2046 os << column_info[i].align_special;
2047 } else if (!column_info[i].p_width.empty()) {
2048 switch(column_info[i].valignment) {
2049 case LYX_VALIGN_TOP:
2052 case LYX_VALIGN_CENTER:
2055 case LYX_VALIGN_BOTTOM:
2060 << column_info[i].p_width
2063 switch (column_info[i].alignment) {
2064 case LYX_ALIGN_LEFT:
2067 case LYX_ALIGN_RIGHT:
2075 if (column_info[i].right_line)
2081 //+---------------------------------------------------------------------
2082 //+ the single row and columns (cells) +
2083 //+---------------------------------------------------------------------
2086 for(int i = 0; i < rows_; ++i) {
2087 ret += TeXTopHLine(os, i);
2089 if (IsLongTabular()) {
2090 if ((endhead < 0) && (i == (abs(endhead)-1))) {
2091 os << "\\endhead\n";
2094 if ((endfirsthead < 0) && (i == (abs(endfirsthead)-1))) {
2095 os << "\\endfirsthead\n";
2098 if ((endfoot < 0) && (i == (abs(endfoot)-1))) {
2099 os << "\\endfoot\n";
2102 if ((endlastfoot < 0) && (i == (abs(endlastfoot)-1))) {
2103 os << "\\endlastfoot\n";
2109 ret += TeXBottomHLine(os, i-1);
2110 ret += TeXTopHLine(os, i);
2112 for(int j = 0; j < columns_; ++j) {
2113 if (IsPartOfMultiColumn(i,j))
2115 ret += TeXCellPreamble(os, cell);
2116 ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
2117 ret += TeXCellPostamble(os, cell);
2118 if (!IsLastCellInRow(cell)) { // not last cell in row
2124 os << "\\\\" << endl;
2125 ret += TeXBottomHLine(os, i);
2127 if (IsLongTabular()) {
2128 if ((endhead > 0) && (i == (endhead - 1))) {
2129 os << "\\endhead\n";
2132 if ((endfirsthead > 0) && (i == (endfirsthead - 1))) {
2133 os << "\\endfirsthead\n";
2136 if ((endfoot > 0) && (i == (endfoot - 1))) {
2137 os << "\\endfoot\n";
2140 if ((endlastfoot > 0) && (i == (endlastfoot - 1))) {
2141 os << "\\endlastfoot\n";
2145 ret += TeXBottomHLine(os, i);
2146 if (row_info[i].newpage) {
2147 os << "\\newpage\n";
2153 //+---------------------------------------------------------------------
2154 //+ the closing of the tabular +
2155 //+---------------------------------------------------------------------
2157 if (is_long_tabular)
2158 os << "\\end{longtable}";
2160 os << "\\end{tabular}";
2162 os << "\n\\end{sideways}";
2170 InsetText * LyXTabular::GetCellInset(int cell) const
2172 return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
2176 void LyXTabular::Validate(LaTeXFeatures & features) const
2178 if (IsLongTabular())
2179 features.longtable = true;
2181 features.rotating = true;
2182 for(int cell = 0; cell < numberofcells; ++cell) {
2183 if (GetVAlignment(cell) != LYX_VALIGN_TOP)
2184 features.array = true;
2185 GetCellInset(cell)->Validate(features);
2190 bool LyXTabular::UseParbox(int cell) const
2192 LyXParagraph * par = GetCellInset(cell)->par;
2194 for(; par; par = par->next) {
2195 for(int i = 0; i < par->Last(); ++i) {
2196 if (par->GetChar(i) == LyXParagraph::META_NEWLINE)