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, LyXAlignment 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 const string write_attribute(const string name, const int value)
923 string str = " " + name + "=\"" + tostr(value) + "\"";
928 const string write_attribute(string name, const string & value)
930 string str = " " + name + "=\"" + value + "\"";
935 const string write_attribute(string name, const bool value)
937 string str = " " + name + "=\"" + tostr((int)value) + "\"";
942 void LyXTabular::Write(Buffer const * buf, ostream & os) const
945 os << "<LyXTabular" <<
946 write_attribute("version", 1) <<
947 write_attribute("rows", rows_) <<
948 write_attribute("columns", columns_) <<
950 // global longtable options
952 write_attribute("rotate", rotate) <<
953 write_attribute("islongtable", is_long_tabular) <<
954 write_attribute("endhead", endhead) <<
955 write_attribute("endfirsthead", endfirsthead) <<
956 write_attribute("endfoot", endfoot) <<
957 write_attribute("endlastfoot", endlastfoot) <<
959 for (int i = 0; i < rows_; ++i) {
961 write_attribute("topline", row_info[i].top_line) <<
962 write_attribute("bottomline", row_info[i].bottom_line) <<
963 write_attribute("newpage", row_info[i].newpage) <<
965 for (int j = 0; j < columns_; ++j) {
968 write_attribute("alignment", column_info[j].alignment) <<
969 write_attribute("valignment", column_info[j].valignment) <<
970 write_attribute("leftline", column_info[j].left_line) <<
971 write_attribute("rightline", column_info[j].right_line) <<
972 write_attribute("width", VSpace(column_info[j].p_width).asLyXCommand()) <<
973 write_attribute("special", column_info[j].align_special) <<
979 write_attribute("multicolumn", cell_info[i][j].multicolumn) <<
980 write_attribute("alignment", cell_info[i][j].alignment) <<
981 write_attribute("valignment", cell_info[i][j].valignment) <<
982 write_attribute("topline", cell_info[i][j].top_line) <<
983 write_attribute("bottomline", cell_info[i][j].bottom_line) <<
984 write_attribute("leftline", cell_info[i][j].left_line) <<
985 write_attribute("rightline", cell_info[i][j].right_line) <<
986 write_attribute("rotate", cell_info[i][j].rotate) <<
987 write_attribute("usebox", (int)cell_info[i][j].usebox) <<
988 write_attribute("width", cell_info[i][j].p_width) <<
989 write_attribute("special", cell_info[i][j].align_special) <<
991 os << "\\begin_inset ";
992 cell_info[i][j].inset.Write(buf, os);
993 os << "\n\\end_inset \n"
999 os << "</LyXTabular>\n";
1004 bool getTokenValue(string const str, const char * token, string & ret)
1006 int pos = str.find(token);
1007 char ch = str[pos+strlen(token)];
1009 if ((pos < 0) || (ch != '='))
1012 pos += strlen(token)+1;
1014 if ((ch != '"') && (ch != '\'')) { // only read till next space
1018 while((pos < int(str.length()-1)) && (str[++pos] != ch))
1026 bool getTokenValue(string const str, const char * token, int & num)
1028 int pos = str.find(token);
1029 char ch = str[pos+strlen(token)];
1031 if ((pos < 0) || (ch != '='))
1034 //ret.erase(); // why? (Lgb)
1035 pos += strlen(token)+1;
1037 if ((ch != '"') && (ch != '\'')) { // only read till next space
1043 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1046 num = strToInt(ret);
1052 bool getTokenValue(string const str, const char * token, bool & flag)
1054 int pos = str.find(token);
1055 char ch = str[pos+strlen(token)];
1057 if ((pos < 0) || (ch != '='))
1060 //ret.erase(); // Why? (Lgb)
1061 pos += strlen(token)+1;
1063 if ((ch != '"') && (ch != '\'')) { // only read till next space
1069 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1072 flag = strToInt(ret);
1078 void l_getline(istream & is, string & str)
1086 void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
1089 istream & is = lex.getStream();
1091 l_getline(is, line);
1092 if (!prefixIs(line, "<LyXTabular ")) {
1093 OldFormatRead(lex, line);
1100 if (!getTokenValue(line, "version", version))
1102 if (!getTokenValue(line, "rows", rows_arg))
1104 if (!getTokenValue(line, "columns", columns_arg))
1106 Init(rows_arg, columns_arg);
1107 l_getline(is, line);
1108 if (!prefixIs(line, "<Features ")) {
1109 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
1110 line << ")" << endl;
1113 getTokenValue(line, "islongtable", is_long_tabular);
1114 getTokenValue(line, "endhead", endhead);
1115 getTokenValue(line, "endfirsthead", endfirsthead);
1116 getTokenValue(line, "endfoot", endfoot);
1117 getTokenValue(line, "endlastfoot", endlastfoot);
1119 for(i = 0; i < rows_; ++i) {
1120 l_getline(is, line);
1121 if (!prefixIs(line, "<Row ")) {
1122 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
1123 line << ")" << endl;
1126 getTokenValue(line, "topline", row_info[i].top_line);
1127 getTokenValue(line, "bottomline", row_info[i].bottom_line);
1128 getTokenValue(line, "newpage", row_info[i].newpage);
1129 for (j = 0; j < columns_; ++j) {
1131 if (!prefixIs(line,"<Column")) {
1132 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
1133 line << ")" << endl;
1137 getTokenValue(line, "alignment", column_info[j].alignment);
1138 getTokenValue(line, "valignment", column_info[j].valignment);
1139 getTokenValue(line, "leftline", column_info[j].left_line);
1140 getTokenValue(line, "rightline", column_info[j].right_line);
1141 getTokenValue(line, "width", column_info[j].p_width);
1142 getTokenValue(line, "special", column_info[j].align_special);
1144 l_getline(is, line);
1145 if (!prefixIs(line, "<Cell")) {
1146 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
1147 line << ")" << endl;
1150 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1151 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1152 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1153 getTokenValue(line, "topline", cell_info[i][j].top_line);
1154 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1155 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1156 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1157 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1158 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1159 getTokenValue(line, "width", cell_info[i][j].p_width);
1160 getTokenValue(line, "special", cell_info[i][j].align_special);
1161 l_getline(is, line);
1162 if (prefixIs(line, "\\begin_inset")) {
1163 cell_info[i][j].inset.Read(buf, lex);
1164 l_getline(is, line);
1166 if (line != "</Cell>") {
1167 lyxerr << "Wrong tabular format (expected </Cell> got" <<
1168 line << ")" << endl;
1171 l_getline(is, line);
1172 if (line != "</Column>") {
1173 lyxerr << "Wrong tabular format (expected </Column> got" <<
1174 line << ")" << endl;
1178 l_getline(is, line);
1179 if (line != "</Row>") {
1180 lyxerr << "Wrong tabular format (expected </Row> got" <<
1181 line << ")" << endl;
1185 while (line != "</LyXTabular>") {
1186 l_getline(is, line);
1188 set_row_column_number_info();
1192 void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
1197 int columns_arg = 0;
1198 int is_long_tabular_arg = false;
1199 int rotate_arg = false;
1209 istream & is = lex.getStream();
1212 version = lyx::atoi(s.substr(8, string::npos));
1216 vector<int> cont_row_info;
1219 lyxerr << "Tabular format < 5 is not supported anymore\n"
1220 "Get an older version of LyX (< 1.1.x) for conversion!"
1222 WriteAlert(_("Warning:"),
1223 _("Tabular format < 5 is not supported anymore\n"),
1224 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1226 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1227 >> rotate_arg >> a >> b >> c >> d;
1229 is >> rows_arg >> columns_arg;
1230 Init(rows_arg, columns_arg);
1231 cont_row_info = vector<int>(rows_arg);
1232 SetLongTabular(is_long_tabular_arg);
1233 SetRotateTabular(rotate_arg);
1235 for (i = 0; i < rows_; ++i) {
1237 cont_row_info[i] = false;
1239 for (i = 0; i < columns_; ++i) {
1242 for (i = 0; i < rows_; ++i) {
1243 for (j = 0; j < columns_; ++j) {
1248 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1249 >> rotate_arg >> a >> b >> c >> d;
1250 Init(rows_arg, columns_arg);
1251 cont_row_info = vector<int>(rows_arg);
1252 SetLongTabular(is_long_tabular_arg);
1253 SetRotateTabular(rotate_arg);
1258 for (i = 0; i < rows_; ++i) {
1259 a = b = c = d = e = f = g = h = 0;
1260 is >> a >> b >> c >> d;
1261 row_info[i].top_line = a;
1262 row_info[i].bottom_line = b;
1263 cont_row_info[i] = c;
1264 row_info[i].newpage = d;
1266 for (i = 0; i < columns_; ++i) {
1270 char ch; // skip '"'
1272 getline(is, s1, '"');
1273 is >> ch; // skip '"'
1274 getline(is, s2, '"');
1275 column_info[i].alignment = static_cast<char>(a);
1276 column_info[i].left_line = b;
1277 column_info[i].right_line = c;
1278 column_info[i].p_width = s1;
1279 column_info[i].align_special = s2;
1281 for (i = 0; i < rows_; ++i) {
1282 for (j = 0; j < columns_; ++j) {
1285 is >> a >> b >> c >> d >> e >> f >> g;
1287 is >> ch; // skip '"'
1288 getline(is, s1, '"');
1289 is >> ch; // skip '"'
1290 getline(is, s2, '"');
1291 cell_info[i][j].multicolumn = static_cast<char>(a);
1292 cell_info[i][j].alignment = static_cast<char>(b);
1293 cell_info[i][j].top_line = static_cast<char>(c);
1294 cell_info[i][j].bottom_line = static_cast<char>(d);
1295 cell_info[i][j].rotate = static_cast<bool>(f);
1296 cell_info[i][j].usebox = static_cast<bool>(g);
1297 cell_info[i][j].align_special = s1;
1298 cell_info[i][j].p_width = s2;
1302 set_row_column_number_info();
1304 LyXParagraph * par = new LyXParagraph;
1305 LyXParagraph * return_par = 0;
1307 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1308 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
1313 LyXFont font(LyXFont::ALL_SANE);
1315 while (lex.IsOK()) {
1317 string const token = lex.GetString();
1320 if (token == "\\layout"
1321 || token == "\\end_float"
1322 || token == "\\end_deeper") {
1323 lex.pushToken(token);
1326 if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
1338 lex.pushToken(token);
1342 lex.printError("New Paragraph allocated! This should not happen!");
1343 lex.pushToken(token);
1349 // now we have the par we should fill the insets with this!
1351 InsetText * inset = GetCellInset(cell);
1354 for(int i = 0; i < par->Last(); ++i) {
1355 if (par->IsNewline(i)) {
1357 if (cell > GetNumberOfCells()) {
1358 lyxerr << "Some error in reading old table format occured!" <<
1359 endl << "Terminating when reading cell[" << cell << "]!" <<
1364 row = row_of_cell(cell);
1365 if (cont_row_info[row]) {
1367 cont_row_info.erase(cont_row_info.begin() + row); //&cont_row_info[row]);
1368 while(!IsFirstCellInRow(--cell));
1370 inset = GetCellInset(cell);
1373 inset = GetCellInset(cell);
1374 row = row_of_cell(cell);
1375 if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox)
1377 // insert a space instead
1379 par->InsertChar(i, ' ');
1382 par->CopyIntoMinibuffer(current_view->buffer()->params, i);
1383 inset->par->InsertFromMinibuffer(inset->par->Last());
1390 string const LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
1392 int const i = isColumn ? cell : column_of_cell(cell);
1394 if (!isColumn && IsMultiColumn(cell)) {
1395 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1396 return cellinfo_of_cell(cell)->align_special;
1398 switch (GetAlignment(cell)) {
1399 case LYX_ALIGN_LEFT:
1401 case LYX_ALIGN_RIGHT:
1408 if (!column_info[i].align_special.empty()) {
1409 return column_info[i].align_special;
1411 #ifdef IGNORE_THIS_FOR_NOW
1412 else if (!column_info[i].p_width.empty()) {
1414 file += column_info[i].p_width;
1419 switch (column_info[i].alignment) {
1420 case LYX_ALIGN_LEFT:
1422 case LYX_ALIGN_RIGHT:
1432 // cell <0 will tex the preamble
1433 // returns the number of printed newlines
1434 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1437 if (IsLastCell(cell)) {
1438 os << newlineAndDepth(--depth)
1440 << newlineAndDepth(--depth)
1442 << newlineAndDepth(--depth)
1444 << newlineAndDepth(--depth);
1445 if (is_long_tabular)
1449 << newlineAndDepth(--depth);
1454 if (is_long_tabular)
1460 << "' COLSEP='1' ROWSEP='1'>"
1461 << newlineAndDepth(++depth);
1463 for (int i = 0; i < columns_; ++i) {
1464 os << "<COLSPEC ALIGN='"
1465 << GetDocBookAlign(i, true)
1471 if (i == (columns_-1)) {
1474 if (column_info[i].right_line ||
1475 column_info[i+1].left_line)
1481 << newlineAndDepth(depth);
1483 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1484 if (column_info[i].left_line)
1489 << newlineAndDepth(++depth)
1491 << newlineAndDepth(++depth)
1493 << GetDocBookAlign(0)
1495 if (IsMultiColumn(0)) {
1496 os << " NAMEST='col1' NAMEEND='col"
1497 << cells_in_multicolumn(0)
1501 << newlineAndDepth(++depth);
1504 if (IsLastCellInRow(cell)) {
1505 os << newlineAndDepth(--depth)
1507 << newlineAndDepth(--depth)
1509 << newlineAndDepth(depth)
1511 << newlineAndDepth(++depth)
1513 << GetDocBookAlign(cell + 1)
1514 << "' VALIGN='middle'";
1515 if (IsMultiColumn(cell + 1)) {
1516 os << " NAMEST='col"
1517 << column_of_cell(cell + 1) + 1
1519 << column_of_cell(cell + 1) +
1520 cells_in_multicolumn(cell + 1)
1524 << newlineAndDepth(++depth);
1527 os << newlineAndDepth(--depth)
1529 << newlineAndDepth(depth)
1531 << GetDocBookAlign(cell + 1)
1532 << "' VALIGN='middle'";
1533 if (IsMultiColumn(cell + 1)) {
1534 os << " NAMEST='col"
1535 << column_of_cell(cell + 1) + 1
1537 << column_of_cell(cell + 1) +
1538 cells_in_multicolumn(cell + 1)
1542 << newlineAndDepth(++depth);
1551 bool LyXTabular::IsMultiColumn(int cell, bool real) const
1553 return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&
1554 (cellinfo_of_cell(cell)->multicolumn !=LyXTabular::CELL_NORMAL));
1558 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1560 int const row = row_of_cell(cell);
1561 int const column = column_of_cell(cell);
1562 return &cell_info[row][column];
1566 void LyXTabular::SetMultiColumn(int cell, int number)
1568 cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1569 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1570 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1571 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1572 for (number--; number > 0; --number) {
1573 cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
1575 set_row_column_number_info();
1579 int LyXTabular::cells_in_multicolumn(int cell) const
1581 int const row = row_of_cell(cell);
1582 int column = column_of_cell(cell);
1585 while ((column < columns_) &&
1586 cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
1595 int LyXTabular::UnsetMultiColumn(int cell)
1597 int const row = row_of_cell(cell);
1598 int column = column_of_cell(cell);
1602 if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
1603 cell_info[row][column].multicolumn = CELL_NORMAL;
1605 while ((column < columns_) &&
1606 (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN))
1608 cell_info[row][column].multicolumn = CELL_NORMAL;
1613 set_row_column_number_info();
1618 void LyXTabular::SetLongTabular(int what)
1620 #warning Should what be bool? (Lgb)
1621 is_long_tabular = what;
1625 bool LyXTabular::IsLongTabular() const
1627 return is_long_tabular;
1631 void LyXTabular::SetRotateTabular(bool flag)
1637 bool LyXTabular::GetRotateTabular() const
1643 void LyXTabular::SetRotateCell(int cell, bool flag)
1645 cellinfo_of_cell(cell)->rotate = flag;
1649 bool LyXTabular::GetRotateCell(int cell) const
1651 return cellinfo_of_cell(cell)->rotate;
1655 bool LyXTabular::NeedRotating() const
1659 for (int i = 0; i < rows_; ++i) {
1660 for (int j = 0; j < columns_; ++j) {
1661 if (cell_info[i][j].rotate)
1669 bool LyXTabular::IsLastCell(int cell) const
1671 if ((cell + 1) < GetNumberOfCells())
1677 int LyXTabular::GetCellAbove(int cell) const
1679 if (row_of_cell(cell) > 0)
1680 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
1685 int LyXTabular::GetCellBelow(int cell) const
1687 if (row_of_cell(cell) + 1 < rows_)
1688 return cell_info[row_of_cell(cell)+1][column_of_cell(cell)].cellno;
1693 int LyXTabular::GetLastCellAbove(int cell) const
1695 if (row_of_cell(cell) <= 0)
1697 if (!IsMultiColumn(cell))
1698 return GetCellAbove(cell);
1699 return cell_info[row_of_cell(cell) - 1][right_column_of_cell(cell)].cellno;
1703 int LyXTabular::GetLastCellBelow(int cell) const
1705 if (row_of_cell(cell) + 1 >= rows_)
1707 if (!IsMultiColumn(cell))
1708 return GetCellBelow(cell);
1709 return cell_info[row_of_cell(cell) + 1][right_column_of_cell(cell)].cellno;
1713 int LyXTabular::GetCellNumber(int row, int column) const
1715 if (column >= columns_)
1716 column = columns_ - 1;
1717 else if (column < 0)
1724 return cell_info[row][column].cellno;
1728 void LyXTabular::SetUsebox(int cell, BoxType type)
1730 cellinfo_of_cell(cell)->usebox = type;
1734 int LyXTabular::GetUsebox(int cell) const
1736 #warning should the return type change? (Lgb)
1737 if (column_info[column_of_cell(cell)].p_width.empty() &&
1738 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
1740 if (cellinfo_of_cell(cell)->usebox > 1)
1741 return cellinfo_of_cell(cell)->usebox;
1742 return UseParbox(cell);
1746 void LyXTabular::SetLTHead(int cell, bool first)
1748 int const row = row_of_cell(cell);
1749 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1752 if (endfirsthead == val)
1765 bool LyXTabular::GetRowOfLTHead(int cell, int & row) const
1768 if (abs(endhead) > rows_)
1770 return (row_of_cell(cell) == abs(endhead) - 1);
1774 bool LyXTabular::GetRowOfLTFirstHead(int cell, int & row) const
1777 if (abs(endfirsthead) > rows_)
1779 return (row_of_cell(cell) == abs(endfirsthead) - 1);
1783 void LyXTabular::SetLTFoot(int cell, bool last)
1785 int const row = row_of_cell(cell);
1786 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1789 if (endlastfoot == val)
1802 bool LyXTabular::GetRowOfLTFoot(int cell, int & row) const
1805 if ((endfoot + 1) > rows_)
1807 return (row_of_cell(cell) == abs(endfoot) - 1);
1811 bool LyXTabular::GetRowOfLTLastFoot(int cell, int & row) const
1814 if (abs(endlastfoot) > rows_)
1816 return (row_of_cell(cell) == (abs(endlastfoot)-1));
1820 void LyXTabular::SetLTNewPage(int cell, bool what)
1822 row_info[row_of_cell(cell)].newpage = what;
1826 bool LyXTabular::GetLTNewPage(int cell) const
1828 return row_info[row_of_cell(cell)].newpage;
1832 bool LyXTabular::SetAscentOfRow(int row, int height)
1834 if ((row >= rows_) || (row_info[row].ascent_of_row == height))
1836 row_info[row].ascent_of_row = height;
1841 bool LyXTabular::SetDescentOfRow(int row, int height)
1843 if ((row >= rows_) || (row_info[row].descent_of_row == height))
1845 row_info[row].descent_of_row = height;
1850 int LyXTabular::GetAscentOfRow(int row) const
1854 return row_info[row].ascent_of_row;
1858 int LyXTabular::GetDescentOfRow(int row) const
1862 return row_info[row].descent_of_row;
1866 int LyXTabular::GetHeightOfTabular() const
1870 for(int row = 0; row < rows_; ++row)
1871 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
1872 GetAdditionalHeight(GetCellNumber(row, 0));
1877 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
1879 if ((row >= rows_) || (column >= columns_))
1881 return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
1885 int LyXTabular::TeXTopHLine(ostream & os, int row) const
1887 #warning should this return a bool? (Lgb)
1888 int const fcell = GetFirstCellInRow(row);
1889 int const n = NumberOfCellsInRow(fcell) + fcell;
1892 for (int i = fcell; i < n; ++i) {
1896 if (tmp == (n - fcell)){
1899 for (int i = fcell; i < n; ++i) {
1902 << column_of_cell(i) + 1
1904 << right_column_of_cell(i) + 1
1917 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
1919 #warning should this return a bool? (Lgb)
1920 int const fcell = GetFirstCellInRow(row);
1921 int const n = NumberOfCellsInRow(fcell) + fcell;
1924 for (int i = fcell; i < n; ++i) {
1928 if (tmp == (n-fcell)){
1931 for (int i = fcell; i < n; ++i) {
1932 if (BottomLine(i)) {
1934 << column_of_cell(i) + 1
1936 << right_column_of_cell(i) + 1
1949 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
1953 if (GetRotateCell(cell)) {
1954 os << "\\begin{sideways}" << endl;
1957 if (IsMultiColumn(cell)) {
1958 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
1959 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1960 os << cellinfo_of_cell(cell+1)->align_special << "}{";
1964 if (!GetPWidth(cell).empty()) {
1965 switch(GetVAlignment(cell)) {
1966 case LYX_VALIGN_TOP:
1969 case LYX_VALIGN_CENTER:
1972 case LYX_VALIGN_BOTTOM:
1976 os << "{" << GetPWidth(cell) << '}';
1978 switch (GetAlignment(cell)) {
1979 case LYX_ALIGN_LEFT:
1982 case LYX_ALIGN_RIGHT:
1990 if (RightLine(cell))
1992 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
1998 if (GetUsebox(cell) == BOX_PARBOX) {
2000 switch(GetVAlignment(cell)) {
2001 case LYX_VALIGN_TOP:
2004 case LYX_VALIGN_CENTER:
2007 case LYX_VALIGN_BOTTOM:
2011 os << "]{" << GetPWidth(cell) << "}{";
2012 } else if (GetUsebox(cell) == BOX_MINIPAGE) {
2013 os << "\\begin{minipage}[";
2014 switch(GetVAlignment(cell)) {
2015 case LYX_VALIGN_TOP:
2018 case LYX_VALIGN_CENTER:
2021 case LYX_VALIGN_BOTTOM:
2025 os << "]{" << GetPWidth(cell) << "}\n";
2032 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
2037 if (GetUsebox(cell) == BOX_PARBOX)
2039 else if (GetUsebox(cell) == BOX_MINIPAGE) {
2040 os << "%\n\\end{minipage}";
2043 if (IsMultiColumn(cell)){
2046 if (GetRotateCell(cell)) {
2047 os << "%\n\\end{sideways}";
2054 int LyXTabular::Latex(Buffer const * buf,
2055 ostream & os, bool fragile, bool fp) const
2060 //+---------------------------------------------------------------------
2061 //+ first the opening preamble +
2062 //+---------------------------------------------------------------------
2065 os << "\\begin{sideways}" << endl;
2068 if (is_long_tabular)
2069 os << "\\begin{longtable}{";
2071 os << "\\begin{tabular}{";
2072 for (int i = 0; i < columns_; ++i) {
2073 if (column_info[i].left_line)
2075 if (!column_info[i].align_special.empty()) {
2076 os << column_info[i].align_special;
2077 } else if (!column_info[i].p_width.empty()) {
2078 switch(column_info[i].valignment) {
2079 case LYX_VALIGN_TOP:
2082 case LYX_VALIGN_CENTER:
2085 case LYX_VALIGN_BOTTOM:
2090 << column_info[i].p_width
2093 switch (column_info[i].alignment) {
2094 case LYX_ALIGN_LEFT:
2097 case LYX_ALIGN_RIGHT:
2105 if (column_info[i].right_line)
2111 //+---------------------------------------------------------------------
2112 //+ the single row and columns (cells) +
2113 //+---------------------------------------------------------------------
2116 for(int i = 0; i < rows_; ++i) {
2117 ret += TeXTopHLine(os, i);
2119 if (IsLongTabular()) {
2120 if ((endhead < 0) && (i == (abs(endhead)-1))) {
2121 os << "\\endhead\n";
2124 if ((endfirsthead < 0) && (i == (abs(endfirsthead)-1))) {
2125 os << "\\endfirsthead\n";
2128 if ((endfoot < 0) && (i == (abs(endfoot)-1))) {
2129 os << "\\endfoot\n";
2132 if ((endlastfoot < 0) && (i == (abs(endlastfoot)-1))) {
2133 os << "\\endlastfoot\n";
2139 ret += TeXBottomHLine(os, i-1);
2140 ret += TeXTopHLine(os, i);
2142 for(int j = 0; j < columns_; ++j) {
2143 if (IsPartOfMultiColumn(i,j))
2145 ret += TeXCellPreamble(os, cell);
2146 ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
2147 ret += TeXCellPostamble(os, cell);
2148 if (!IsLastCellInRow(cell)) { // not last cell in row
2154 os << "\\\\" << endl;
2155 ret += TeXBottomHLine(os, i);
2157 if (IsLongTabular()) {
2158 if ((endhead > 0) && (i == (endhead - 1))) {
2159 os << "\\endhead\n";
2162 if ((endfirsthead > 0) && (i == (endfirsthead - 1))) {
2163 os << "\\endfirsthead\n";
2166 if ((endfoot > 0) && (i == (endfoot - 1))) {
2167 os << "\\endfoot\n";
2170 if ((endlastfoot > 0) && (i == (endlastfoot - 1))) {
2171 os << "\\endlastfoot\n";
2175 ret += TeXBottomHLine(os, i);
2176 if (row_info[i].newpage) {
2177 os << "\\newpage\n";
2183 //+---------------------------------------------------------------------
2184 //+ the closing of the tabular +
2185 //+---------------------------------------------------------------------
2187 if (is_long_tabular)
2188 os << "\\end{longtable}";
2190 os << "\\end{tabular}";
2192 os << "\n\\end{sideways}";
2200 InsetText * LyXTabular::GetCellInset(int cell) const
2202 return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
2206 void LyXTabular::Validate(LaTeXFeatures & features) const
2208 if (IsLongTabular())
2209 features.longtable = true;
2211 features.rotating = true;
2212 for(int cell = 0; cell < numberofcells; ++cell) {
2213 if (GetVAlignment(cell) != LYX_VALIGN_TOP)
2214 features.array = true;
2215 GetCellInset(cell)->Validate(features);
2220 bool LyXTabular::UseParbox(int cell) const
2222 LyXParagraph * par = GetCellInset(cell)->par;
2224 for(; par; par = par->next) {
2225 for(int i = 0; i < par->Last(); ++i) {
2226 if (par->GetChar(i) == LyXParagraph::META_NEWLINE)