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++;
175 cell_info[i][columns_-1].right_line = true;
177 //row_info[i - 1].bottom_line = true;
178 //row_info[0].bottom_line = true;
179 row_info.back().bottom_line = true;
180 row_info.front().bottom_line = true;
182 for (int i = 0; i < columns_; ++i) {
183 calculate_width_of_column(i);
185 //column_info[columns_ - 1].right_line = true;
186 column_info.back().right_line = true;
188 calculate_width_of_tabular();
192 set_row_column_number_info();
193 is_long_tabular = false;
202 void LyXTabular::AppendRow(int cell)
206 int row = row_of_cell(cell);
208 row_vector::iterator rit = row_info.begin() + row;
209 row_info.insert(rit, rowstruct());
212 cell_vvector::iterator cit = cell_info.begin() + row;
213 cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
215 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
218 for(int i = 0; i <= row; ++i) {
219 for(int j = 0; j < columns_; ++j) {
220 c_info[i][j] = cell_info[i][j];
223 for(int i = row + 1; i < rows_; ++i) {
224 for(int j = 0; j < columns_; ++j) {
225 c_info[i][j] = cell_info[i-1][j];
230 for (int j = 0; j < columns_; ++j) {
231 cell_info[row][j].inset.clear();
238 void LyXTabular::DeleteRow(int row)
240 // Why make it so hard? (Lgb)
243 if (rows_ == 1) return; // Not allowed to delete last row
245 row_info.erase(row_info.begin() + row); //&row_info[row]);
246 cell_info.erase(cell_info.begin() + row); //&cell_info[row]);
252 void LyXTabular::AppendColumn(int cell)
256 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
258 int column = column_of_cell(cell);
259 column_vector::iterator cit = column_info.begin() + column + 1;
260 column_info.insert(cit, columnstruct());
262 for (int i = 0; i < rows_; ++i) {
263 for (int j = 0; j <= column; ++j) {
264 c_info[i][j] = cell_info[i][j];
266 for (int j = column + 1; j < columns_; ++j) {
267 c_info[i][j] = cell_info[i][j - 1];
269 // care about multicolumns
270 if (cell_info[i][column + 1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
271 cell_info[i][column + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
273 if ((column + 1) == columns_ ||
274 cell_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN) {
275 cell_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL;
280 for (int i = 0; i < rows_; ++i) {
281 cell_info[i][column].inset.clear();
287 void LyXTabular::DeleteColumn(int column)
289 // Similar to DeleteRow
290 //if (!(columns_ - 1))
292 if (columns_ == 1) return; // Not allowed to delete last column
294 column_info.erase(column_info.begin() + column);
295 for (int i = 0; i < rows_; ++i) {
296 cell_info[i].erase(cell_info[i].begin() + column);
303 void LyXTabular::Reinit()
305 // Jürgen, use iterators.
306 for (int i = 0; i < rows_; ++i) {
307 for (int j = 0; j < columns_; ++j) {
308 cell_info[i][j].width_of_cell = 0;
309 cell_info[i][j].inset.setOwner(owner_);
313 for (int i = 0; i < columns_; ++i) {
314 calculate_width_of_column(i);
316 calculate_width_of_tabular();
318 set_row_column_number_info();
322 void LyXTabular::set_row_column_number_info(bool oldformat)
328 for (; row < rows_; ++row) {
329 for (column = 0; column<columns_; ++column) {
330 if (cell_info[row][column].multicolumn
331 != LyXTabular::CELL_PART_OF_MULTICOLUMN)
333 cell_info[row][column].cellno = numberofcells;
336 ++numberofcells; // because this is one more than as we start from 0
341 rowofcell = new int[numberofcells];
342 delete [] columnofcell;
343 columnofcell = new int[numberofcells];
345 while (c < numberofcells && row < rows_ && column < columns_) {
347 columnofcell[c] = column;
351 } while (column < columns_ &&
352 cell_info[row][column].multicolumn
353 == LyXTabular::CELL_PART_OF_MULTICOLUMN);
354 if (column == columns_) {
359 for (row = 0; row < rows_; ++row) {
360 for (column = 0; column<columns_; ++column) {
361 if (IsPartOfMultiColumn(row,column))
363 // now set the right line of multicolumns right for oldformat read
365 cell_info[row][column].multicolumn==CELL_BEGIN_OF_MULTICOLUMN)
367 int cn=cells_in_multicolumn(cell_info[row][column].cellno);
368 cell_info[row][column].right_line =
369 cell_info[row][column+cn-1].right_line;
371 cell_info[row][column].inset.SetAutoBreakRows(
372 !GetPWidth(GetCellNumber(row, column)).empty());
378 int LyXTabular::GetNumberOfCells() const
380 return numberofcells;
384 int LyXTabular::NumberOfCellsInRow(int cell) const
386 int const row = row_of_cell(cell);
388 for (int i = 0; i < columns_; ++i) {
389 if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
396 /* returns 1 if there is a topline, returns 0 if not */
397 bool LyXTabular::TopLine(int cell, bool onlycolumn) const
399 int const row = row_of_cell(cell);
401 if (!onlycolumn && IsMultiColumn(cell))
402 return cellinfo_of_cell(cell)->top_line;
403 return row_info[row].top_line;
407 bool LyXTabular::BottomLine(int cell, bool onlycolumn) const
409 // no bottom line underneath non-existent cells if you please
410 // Isn't that a programming error? Is so this should
411 // be an Assert instead. (Lgb)
412 if(cell >= numberofcells)
415 if (!onlycolumn && IsMultiColumn(cell))
416 return cellinfo_of_cell(cell)->bottom_line;
417 return row_info[row_of_cell(cell)].bottom_line;
421 bool LyXTabular::LeftLine(int cell, bool onlycolumn) const
423 if (!onlycolumn && IsMultiColumn(cell))
424 return cellinfo_of_cell(cell)->left_line;
425 return column_info[column_of_cell(cell)].left_line;
429 bool LyXTabular::RightLine(int cell, bool onlycolumn) const
431 if (!onlycolumn && IsMultiColumn(cell))
432 return cellinfo_of_cell(cell)->right_line;
433 return column_info[right_column_of_cell(cell)].right_line;
437 bool LyXTabular::TopAlreadyDrawed(int cell) const
439 if (GetAdditionalHeight(cell))
441 int row = row_of_cell(cell);
443 int column = column_of_cell(cell);
446 && cell_info[row][column].multicolumn
447 == LyXTabular::CELL_PART_OF_MULTICOLUMN)
449 if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL)
450 return row_info[row].bottom_line;
452 return cell_info[row][column].bottom_line;
458 bool LyXTabular::LeftAlreadyDrawed(int cell) const
460 int column = column_of_cell(cell);
462 int row = row_of_cell(cell);
464 (cell_info[row][column].multicolumn ==
465 LyXTabular::CELL_PART_OF_MULTICOLUMN));
466 if (GetAdditionalWidth(cell_info[row][column].cellno))
468 return column_info[column].right_line;
474 bool LyXTabular::IsLastRow(int cell) const
476 return (row_of_cell(cell) == rows_ - 1);
480 int LyXTabular::GetAdditionalHeight(int cell) const
482 int const row = row_of_cell(cell);
488 for (int column = 0; column < columns_ - 1 && bottom; ++column) {
489 switch (cell_info[row - 1][column].multicolumn) {
490 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
491 bottom = cell_info[row - 1][column].bottom_line;
493 case LyXTabular::CELL_NORMAL:
494 bottom = row_info[row - 1].bottom_line;
497 for (int column = 0; column < columns_ - 1 && top; ++column) {
498 switch (cell_info[row][column].multicolumn){
499 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
500 top = cell_info[row][column].top_line;
502 case LyXTabular::CELL_NORMAL:
503 top = row_info[row].top_line;
507 return WIDTH_OF_LINE;
512 int LyXTabular::GetAdditionalWidth(int cell) const
514 // internally already set in SetWidthOfCell
515 // used to get it back in text.C
516 int const col = right_column_of_cell(cell);
517 if (col < columns_ - 1 && column_info[col].right_line &&
518 column_info[col+1].left_line)
519 return WIDTH_OF_LINE;
525 // returns the maximum over all rows
526 int LyXTabular::GetWidthOfColumn(int cell) const
528 int const column1 = column_of_cell(cell);
529 int const column2 = right_column_of_cell(cell);
532 for (; i <= column2; ++i) {
533 result += column_info[i].width_of_column;
539 int LyXTabular::GetWidthOfTabular() const
541 return width_of_tabular;
545 /* returns 1 if a complete update is necessary, otherwise 0 */
546 bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
548 if (!IsMultiColumn(cell))
551 int const row = row_of_cell(cell);
552 int const column1 = column_of_cell(cell);
553 int const column2 = right_column_of_cell(cell);
555 // first set columns to 0 so we can calculate the right width
557 for (; i <= column2; ++i) {
558 cell_info[row][i].width_of_cell = 0;
560 // set the width to MAX_WIDTH until width > 0
561 int width = (new_width + 2 * WIDTH_OF_LINE);
563 i < column2 && width > column_info[i].width_of_column;
565 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
566 width -= column_info[i].width_of_column;
569 cell_info[row][i].width_of_cell = width;
575 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
577 int const row = row_of_cell(cell);
578 int const column1 = column_of_cell(cell);
579 int const column2 = right_column_of_cell(cell);
581 // first set columns to 0 so we can calculate the right width
583 for (; i <= column2; ++i)
584 cell_info[row][i].width_of_cell = 0;
585 for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
587 if (i < numberofcells)
588 recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
589 SetWidthOfMulticolCell(cell, new_width);
593 /* returns 1 if a complete update is necessary, otherwise 0 */
594 bool LyXTabular::SetWidthOfCell(int cell, int new_width)
596 int const row = row_of_cell(cell);
597 int const column1 = column_of_cell(cell);
601 if (GetWidthOfCell(cell) == (new_width+2*WIDTH_OF_LINE))
603 if (IsMultiColumn(cell, true)) {
604 tmp = SetWidthOfMulticolCell(cell, new_width);
606 width = (new_width + 2*WIDTH_OF_LINE);
607 cell_info[row][column1].width_of_cell = width;
608 if (column_info[column1].right_line && (column1 < columns_-1) &&
609 column_info[column1+1].left_line) // additional width
610 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
611 tmp = calculate_width_of_column_NMC(column1);
615 for(; i<columns_; ++i)
616 calculate_width_of_column_NMC(i);
617 for(i = 0; (i < numberofcells) && !IsMultiColumn(i); ++i)
619 if (i < numberofcells)
620 recalculateMulticolCells(i, GetWidthOfCell(i)-(2 * WIDTH_OF_LINE));
621 for(i = 0; i < columns_; ++i)
622 calculate_width_of_column(i);
623 calculate_width_of_tabular();
630 bool LyXTabular::SetAlignment(int cell, LyXAlignment align, bool onlycolumn)
632 if (!IsMultiColumn(cell) || onlycolumn)
633 column_info[column_of_cell(cell)].alignment = align;
635 cellinfo_of_cell(cell)->alignment = align;
640 bool LyXTabular::SetVAlignment(int cell, VAlignment align, bool onlycolumn)
642 if (!IsMultiColumn(cell) || onlycolumn)
643 column_info[column_of_cell(cell)].valignment = align;
645 cellinfo_of_cell(cell)->valignment = align;
650 bool LyXTabular::SetColumnPWidth(int cell, string const & width)
652 bool flag = !width.empty();
653 int const j = column_of_cell(cell);
655 column_info[j].p_width = width;
656 if (flag) // do this only if there is a width
657 SetAlignment(cell, LYX_ALIGN_LEFT);
658 for(int i = 0; i < rows_; ++i) {
659 int c = GetCellNumber(i, j);
660 flag = !GetPWidth(c).empty(); // because of multicolumns!
661 GetCellInset(c)->SetAutoBreakRows(flag);
667 bool LyXTabular::SetMColumnPWidth(int cell, string const & width)
669 bool const flag = !width.empty();
671 cellinfo_of_cell(cell)->p_width = width;
672 if (IsMultiColumn(cell)) {
673 GetCellInset(cell)->SetAutoBreakRows(flag);
680 bool LyXTabular::SetAlignSpecial(int cell, string const & special,
681 LyXTabular::Feature what)
683 if (what == SET_SPECIAL_MULTI)
684 cellinfo_of_cell(cell)->align_special = special;
686 column_info[column_of_cell(cell)].align_special = special;
691 bool LyXTabular::SetAllLines(int cell, bool line)
693 SetTopLine(cell, line);
694 SetBottomLine(cell, line);
695 SetRightLine(cell, line);
696 SetLeftLine(cell, line);
701 bool LyXTabular::SetTopLine(int cell, bool line, bool onlycolumn)
703 int const row = row_of_cell(cell);
705 if (onlycolumn || !IsMultiColumn(cell))
706 row_info[row].top_line = line;
708 cellinfo_of_cell(cell)->top_line = line;
713 bool LyXTabular::SetBottomLine(int cell, bool line, bool onlycolumn)
715 if (onlycolumn || !IsMultiColumn(cell))
716 row_info[row_of_cell(cell)].bottom_line = line;
718 cellinfo_of_cell(cell)->bottom_line = line;
723 bool LyXTabular::SetLeftLine(int cell, bool line, bool onlycolumn)
725 if (onlycolumn || !IsMultiColumn(cell))
726 column_info[column_of_cell(cell)].left_line = line;
728 cellinfo_of_cell(cell)->left_line = line;
733 bool LyXTabular::SetRightLine(int cell, bool line, bool onlycolumn)
735 if (onlycolumn || !IsMultiColumn(cell))
736 column_info[right_column_of_cell(cell)].right_line = line;
738 cellinfo_of_cell(cell)->right_line = line;
743 LyXAlignment LyXTabular::GetAlignment(int cell, bool onlycolumn) const
745 if (!onlycolumn && IsMultiColumn(cell))
746 return cellinfo_of_cell(cell)->alignment;
748 return column_info[column_of_cell(cell)].alignment;
752 LyXTabular::VAlignment LyXTabular::GetVAlignment(int cell, bool onlycolumn) const
754 if (!onlycolumn && IsMultiColumn(cell))
755 return cellinfo_of_cell(cell)->valignment;
757 return column_info[column_of_cell(cell)].valignment;
761 string const LyXTabular::GetPWidth(int cell) const
763 if (IsMultiColumn(cell))
764 return cellinfo_of_cell(cell)->p_width;
765 return column_info[column_of_cell(cell)].p_width;
769 string const LyXTabular::GetColumnPWidth(int cell) const
771 return column_info[column_of_cell(cell)].p_width;
775 string const LyXTabular::GetMColumnPWidth(int cell) const
777 if (IsMultiColumn(cell))
778 return cellinfo_of_cell(cell)->p_width;
783 string const LyXTabular::GetAlignSpecial(int cell, int what) const
785 if (what == SET_SPECIAL_MULTI)
786 return cellinfo_of_cell(cell)->align_special;
787 return column_info[column_of_cell(cell)].align_special;
791 int LyXTabular::GetWidthOfCell(int cell) const
793 int const row = row_of_cell(cell);
794 int const column1 = column_of_cell(cell);
795 int const column2 = right_column_of_cell(cell);
797 for (int i = column1; i <= column2; ++i) {
798 result += cell_info[row][i].width_of_cell;
804 int LyXTabular::GetBeginningOfTextInCell(int cell) const
808 switch (GetAlignment(cell)){
809 case LYX_ALIGN_CENTER:
810 x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
812 case LYX_ALIGN_RIGHT:
813 x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
814 // + GetAdditionalWidth(cell);
816 default: /* LYX_ALIGN_LEFT: nothing :-) */
826 bool LyXTabular::IsFirstCellInRow(int cell) const
828 return column_of_cell(cell) == 0;
832 int LyXTabular::GetFirstCellInRow(int row) const
836 return cell_info[row][0].cellno;
839 bool LyXTabular::IsLastCellInRow(int cell) const
841 return (right_column_of_cell(cell) == (columns_ - 1));
845 int LyXTabular::GetLastCellInRow(int row) const
849 return cell_info[row][columns_-1].cellno;
853 bool LyXTabular::calculate_width_of_column(int column)
855 int const old_column_width = column_info[column].width_of_column;
858 for (int i = 0; i < rows_; ++i) {
859 maximum = max(cell_info[i][column].width_of_cell, maximum);
861 column_info[column].width_of_column = maximum;
862 return (column_info[column].width_of_column != old_column_width);
867 // calculate the with of the column without regarding REAL MultiColumn
868 // cells. This means MultiColumn-cells spanning more than 1 column.
870 bool LyXTabular::calculate_width_of_column_NMC(int column)
872 int const old_column_width = column_info[column].width_of_column;
874 for (int i = 0; i < rows_; ++i) {
875 if (!IsMultiColumn(GetCellNumber(i, column), true) &&
876 (cell_info[i][column].width_of_cell > max)) {
877 max = cell_info[i][column].width_of_cell;
880 column_info[column].width_of_column = max;
881 return (column_info[column].width_of_column != old_column_width);
885 void LyXTabular::calculate_width_of_tabular()
887 width_of_tabular = 0;
888 for (int i = 0; i < columns_; ++i) {
889 width_of_tabular += column_info[i].width_of_column;
894 int LyXTabular::row_of_cell(int cell) const
896 if (cell >= numberofcells)
900 return rowofcell[cell];
904 int LyXTabular::column_of_cell(int cell) const
906 if (cell >= numberofcells)
910 return columnofcell[cell];
914 int LyXTabular::right_column_of_cell(int cell) const
916 int const row = row_of_cell(cell);
917 int column = column_of_cell(cell);
918 while (column < (columns_ - 1) &&
919 cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
925 const string write_attribute(const string name, const int value)
927 string str = " " + name + "=\"" + tostr(value) + "\"";
932 const string write_attribute(string name, const string & value)
934 string str = " " + name + "=\"" + value + "\"";
939 const string write_attribute(string name, const bool value)
941 string str = " " + name + "=\"" + tostr((int)value) + "\"";
946 void LyXTabular::Write(Buffer const * buf, ostream & os) const
949 os << "<LyXTabular" <<
950 write_attribute("version", 1) <<
951 write_attribute("rows", rows_) <<
952 write_attribute("columns", columns_) <<
954 // global longtable options
956 write_attribute("rotate", rotate) <<
957 write_attribute("islongtable", is_long_tabular) <<
958 write_attribute("endhead", endhead) <<
959 write_attribute("endfirsthead", endfirsthead) <<
960 write_attribute("endfoot", endfoot) <<
961 write_attribute("endlastfoot", endlastfoot) <<
963 for (int i = 0; i < rows_; ++i) {
965 write_attribute("topline", row_info[i].top_line) <<
966 write_attribute("bottomline", row_info[i].bottom_line) <<
967 write_attribute("newpage", row_info[i].newpage) <<
969 for (int j = 0; j < columns_; ++j) {
972 write_attribute("alignment", column_info[j].alignment) <<
973 write_attribute("valignment", column_info[j].valignment) <<
974 write_attribute("leftline", column_info[j].left_line) <<
975 write_attribute("rightline", column_info[j].right_line) <<
976 write_attribute("width", VSpace(column_info[j].p_width).asLyXCommand()) <<
977 write_attribute("special", column_info[j].align_special) <<
983 write_attribute("multicolumn", cell_info[i][j].multicolumn) <<
984 write_attribute("alignment", cell_info[i][j].alignment) <<
985 write_attribute("valignment", cell_info[i][j].valignment) <<
986 write_attribute("topline", cell_info[i][j].top_line) <<
987 write_attribute("bottomline", cell_info[i][j].bottom_line) <<
988 write_attribute("leftline", cell_info[i][j].left_line) <<
989 write_attribute("rightline", cell_info[i][j].right_line) <<
990 write_attribute("rotate", cell_info[i][j].rotate) <<
991 write_attribute("usebox", (int)cell_info[i][j].usebox) <<
992 write_attribute("width", cell_info[i][j].p_width) <<
993 write_attribute("special", cell_info[i][j].align_special) <<
995 os << "\\begin_inset ";
996 cell_info[i][j].inset.Write(buf, os);
997 os << "\n\\end_inset \n"
1003 os << "</LyXTabular>\n";
1008 bool getTokenValue(string const str, const char * token, string & ret)
1010 int pos = str.find(token);
1011 char ch = str[pos+strlen(token)];
1013 if ((pos < 0) || (ch != '='))
1016 pos += strlen(token)+1;
1018 if ((ch != '"') && (ch != '\'')) { // only read till next space
1022 while((pos < int(str.length()-1)) && (str[++pos] != ch))
1030 bool getTokenValue(string const str, const char * token, int & num)
1032 int pos = str.find(token);
1033 char ch = str[pos+strlen(token)];
1035 if ((pos < 0) || (ch != '='))
1038 //ret.erase(); // why? (Lgb)
1039 pos += strlen(token)+1;
1041 if ((ch != '"') && (ch != '\'')) { // only read till next space
1047 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1050 num = strToInt(ret);
1056 bool getTokenValue(string const str, const char * token, LyXAlignment & num)
1059 bool ret = getTokenValue(str, token, tmp);
1060 num = static_cast<LyXAlignment>(tmp);
1066 bool getTokenValue(string const str, const char * token,
1067 LyXTabular::VAlignment & num)
1070 bool ret = getTokenValue(str, token, tmp);
1071 num = static_cast<LyXTabular::VAlignment>(tmp);
1077 bool getTokenValue(string const str, const char * token,
1078 LyXTabular::BoxType & num)
1081 bool ret = getTokenValue(str, token, tmp);
1082 num = static_cast<LyXTabular::BoxType>(tmp);
1088 bool getTokenValue(string const str, const char * token, bool & flag)
1090 int pos = str.find(token);
1091 char ch = str[pos+strlen(token)];
1093 if ((pos < 0) || (ch != '='))
1096 //ret.erase(); // Why? (Lgb)
1097 pos += strlen(token)+1;
1099 if ((ch != '"') && (ch != '\'')) { // only read till next space
1105 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1108 flag = strToInt(ret);
1114 void l_getline(istream & is, string & str)
1122 void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
1125 istream & is = lex.getStream();
1127 l_getline(is, line);
1128 if (!prefixIs(line, "<LyXTabular ")) {
1129 OldFormatRead(lex, line);
1136 if (!getTokenValue(line, "version", version))
1138 if (!getTokenValue(line, "rows", rows_arg))
1140 if (!getTokenValue(line, "columns", columns_arg))
1142 Init(rows_arg, columns_arg);
1143 l_getline(is, line);
1144 if (!prefixIs(line, "<Features ")) {
1145 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
1146 line << ")" << endl;
1149 getTokenValue(line, "islongtable", is_long_tabular);
1150 getTokenValue(line, "endhead", endhead);
1151 getTokenValue(line, "endfirsthead", endfirsthead);
1152 getTokenValue(line, "endfoot", endfoot);
1153 getTokenValue(line, "endlastfoot", endlastfoot);
1155 for(i = 0; i < rows_; ++i) {
1156 l_getline(is, line);
1157 if (!prefixIs(line, "<Row ")) {
1158 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
1159 line << ")" << endl;
1162 getTokenValue(line, "topline", row_info[i].top_line);
1163 getTokenValue(line, "bottomline", row_info[i].bottom_line);
1164 getTokenValue(line, "newpage", row_info[i].newpage);
1165 for (j = 0; j < columns_; ++j) {
1167 if (!prefixIs(line,"<Column")) {
1168 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
1169 line << ")" << endl;
1173 getTokenValue(line, "alignment", column_info[j].alignment);
1174 getTokenValue(line, "valignment", column_info[j].valignment);
1175 getTokenValue(line, "leftline", column_info[j].left_line);
1176 getTokenValue(line, "rightline", column_info[j].right_line);
1177 getTokenValue(line, "width", column_info[j].p_width);
1178 getTokenValue(line, "special", column_info[j].align_special);
1180 l_getline(is, line);
1181 if (!prefixIs(line, "<Cell")) {
1182 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
1183 line << ")" << endl;
1186 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1187 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1188 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1189 getTokenValue(line, "topline", cell_info[i][j].top_line);
1190 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1191 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1192 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1193 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1194 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1195 getTokenValue(line, "width", cell_info[i][j].p_width);
1196 getTokenValue(line, "special", cell_info[i][j].align_special);
1197 l_getline(is, line);
1198 if (prefixIs(line, "\\begin_inset")) {
1199 cell_info[i][j].inset.Read(buf, lex);
1200 l_getline(is, line);
1202 if (line != "</Cell>") {
1203 lyxerr << "Wrong tabular format (expected </Cell> got" <<
1204 line << ")" << endl;
1207 l_getline(is, line);
1208 if (line != "</Column>") {
1209 lyxerr << "Wrong tabular format (expected </Column> got" <<
1210 line << ")" << endl;
1214 l_getline(is, line);
1215 if (line != "</Row>") {
1216 lyxerr << "Wrong tabular format (expected </Row> got" <<
1217 line << ")" << endl;
1221 while (line != "</LyXTabular>") {
1222 l_getline(is, line);
1224 set_row_column_number_info();
1228 void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
1233 int columns_arg = 0;
1234 int is_long_tabular_arg = false;
1235 int rotate_arg = false;
1245 istream & is = lex.getStream();
1248 version = lyx::atoi(s.substr(8, string::npos));
1252 vector<int> cont_row_info;
1255 lyxerr << "Tabular format < 5 is not supported anymore\n"
1256 "Get an older version of LyX (< 1.1.x) for conversion!"
1258 WriteAlert(_("Warning:"),
1259 _("Tabular format < 5 is not supported anymore\n"),
1260 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1262 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1263 >> rotate_arg >> a >> b >> c >> d;
1265 is >> rows_arg >> columns_arg;
1266 Init(rows_arg, columns_arg);
1267 cont_row_info = vector<int>(rows_arg);
1268 SetLongTabular(is_long_tabular_arg);
1269 SetRotateTabular(rotate_arg);
1271 for (i = 0; i < rows_; ++i) {
1273 cont_row_info[i] = false;
1275 for (i = 0; i < columns_; ++i) {
1278 for (i = 0; i < rows_; ++i) {
1279 for (j = 0; j < columns_; ++j) {
1284 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1285 >> rotate_arg >> a >> b >> c >> d;
1286 Init(rows_arg, columns_arg);
1287 cont_row_info = vector<int>(rows_arg);
1288 SetLongTabular(is_long_tabular_arg);
1289 SetRotateTabular(rotate_arg);
1294 for (i = 0; i < rows_; ++i) {
1295 a = b = c = d = e = f = g = h = 0;
1296 is >> a >> b >> c >> d;
1297 row_info[i].top_line = a;
1298 row_info[i].bottom_line = b;
1299 cont_row_info[i] = c;
1300 row_info[i].newpage = d;
1302 for (i = 0; i < columns_; ++i) {
1306 char ch; // skip '"'
1308 getline(is, s1, '"');
1309 is >> ch; // skip '"'
1310 getline(is, s2, '"');
1311 column_info[i].alignment = static_cast<LyXAlignment>(a);
1312 column_info[i].left_line = b;
1313 column_info[i].right_line = c;
1314 column_info[i].p_width = s1;
1315 column_info[i].align_special = s2;
1317 for (i = 0; i < rows_; ++i) {
1318 for (j = 0; j < columns_; ++j) {
1321 is >> a >> b >> c >> d >> e >> f >> g;
1323 is >> ch; // skip '"'
1324 getline(is, s1, '"');
1325 is >> ch; // skip '"'
1326 getline(is, s2, '"');
1327 cell_info[i][j].multicolumn = static_cast<char>(a);
1328 cell_info[i][j].alignment = static_cast<LyXAlignment>(b);
1329 cell_info[i][j].top_line = static_cast<char>(c);
1330 cell_info[i][j].bottom_line = static_cast<char>(d);
1331 cell_info[i][j].left_line = column_info[j].left_line;
1332 cell_info[i][j].right_line = column_info[j].right_line;
1333 cell_info[i][j].rotate = static_cast<bool>(f);
1334 cell_info[i][j].usebox = static_cast<BoxType>(g);
1335 cell_info[i][j].align_special = s1;
1336 cell_info[i][j].p_width = s2;
1340 set_row_column_number_info(true);
1342 LyXParagraph * par = new LyXParagraph;
1343 LyXParagraph * return_par = 0;
1345 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1346 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
1351 LyXFont font(LyXFont::ALL_SANE);
1353 while (lex.IsOK()) {
1355 string const token = lex.GetString();
1358 if (token == "\\layout"
1359 || token == "\\end_float"
1360 || token == "\\end_deeper") {
1361 lex.pushToken(token);
1364 if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
1376 lex.pushToken(token);
1380 lex.printError("New Paragraph allocated! This should not happen!");
1381 lex.pushToken(token);
1387 // now we have the par we should fill the insets with this!
1389 InsetText * inset = GetCellInset(cell);
1392 for(int i = 0; i < par->Last(); ++i) {
1393 if (par->IsNewline(i)) {
1395 if (cell > GetNumberOfCells()) {
1396 lyxerr << "Some error in reading old table format occured!" <<
1397 endl << "Terminating when reading cell[" << cell << "]!" <<
1402 row = row_of_cell(cell);
1403 if (cont_row_info[row]) {
1405 cont_row_info.erase(cont_row_info.begin() + row); //&cont_row_info[row]);
1406 while(!IsFirstCellInRow(--cell));
1408 inset = GetCellInset(cell);
1411 inset = GetCellInset(cell);
1412 row = row_of_cell(cell);
1413 if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox)
1415 // insert a space instead
1417 par->InsertChar(i, ' ');
1420 par->CopyIntoMinibuffer(owner_->BufferOwner()->params, i);
1421 inset->par->InsertFromMinibuffer(inset->par->Last());
1428 string const LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
1430 int const i = isColumn ? cell : column_of_cell(cell);
1432 if (!isColumn && IsMultiColumn(cell)) {
1433 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1434 return cellinfo_of_cell(cell)->align_special;
1436 switch (GetAlignment(cell)) {
1437 case LYX_ALIGN_LEFT:
1439 case LYX_ALIGN_RIGHT:
1446 if (!column_info[i].align_special.empty()) {
1447 return column_info[i].align_special;
1449 #ifdef IGNORE_THIS_FOR_NOW
1450 else if (!column_info[i].p_width.empty()) {
1452 file += column_info[i].p_width;
1457 switch (column_info[i].alignment) {
1458 case LYX_ALIGN_LEFT:
1460 case LYX_ALIGN_RIGHT:
1470 // cell <0 will tex the preamble
1471 // returns the number of printed newlines
1472 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1475 if (IsLastCell(cell)) {
1476 os << newlineAndDepth(--depth)
1478 << newlineAndDepth(--depth)
1480 << newlineAndDepth(--depth)
1482 << newlineAndDepth(--depth);
1483 if (is_long_tabular)
1487 << newlineAndDepth(--depth);
1492 if (is_long_tabular)
1498 << "' COLSEP='1' ROWSEP='1'>"
1499 << newlineAndDepth(++depth);
1501 for (int i = 0; i < columns_; ++i) {
1502 os << "<COLSPEC ALIGN='"
1503 << GetDocBookAlign(i, true)
1509 if (i == (columns_-1)) {
1512 if (column_info[i].right_line ||
1513 column_info[i+1].left_line)
1519 << newlineAndDepth(depth);
1521 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1522 if (column_info[i].left_line)
1527 << newlineAndDepth(++depth)
1529 << newlineAndDepth(++depth)
1531 << GetDocBookAlign(0)
1533 if (IsMultiColumn(0)) {
1534 os << " NAMEST='col1' NAMEEND='col"
1535 << cells_in_multicolumn(0)
1539 << newlineAndDepth(++depth);
1542 if (IsLastCellInRow(cell)) {
1543 os << newlineAndDepth(--depth)
1545 << newlineAndDepth(--depth)
1547 << newlineAndDepth(depth)
1549 << newlineAndDepth(++depth)
1551 << GetDocBookAlign(cell + 1)
1552 << "' VALIGN='middle'";
1553 if (IsMultiColumn(cell + 1)) {
1554 os << " NAMEST='col"
1555 << column_of_cell(cell + 1) + 1
1557 << column_of_cell(cell + 1) +
1558 cells_in_multicolumn(cell + 1)
1562 << newlineAndDepth(++depth);
1565 os << newlineAndDepth(--depth)
1567 << newlineAndDepth(depth)
1569 << GetDocBookAlign(cell + 1)
1570 << "' VALIGN='middle'";
1571 if (IsMultiColumn(cell + 1)) {
1572 os << " NAMEST='col"
1573 << column_of_cell(cell + 1) + 1
1575 << column_of_cell(cell + 1) +
1576 cells_in_multicolumn(cell + 1)
1580 << newlineAndDepth(++depth);
1589 bool LyXTabular::IsMultiColumn(int cell, bool real) const
1591 return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&
1592 (cellinfo_of_cell(cell)->multicolumn !=LyXTabular::CELL_NORMAL));
1596 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1598 int const row = row_of_cell(cell);
1599 int const column = column_of_cell(cell);
1600 return &cell_info[row][column];
1604 void LyXTabular::SetMultiColumn(int cell, int number)
1606 cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1607 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1608 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1609 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1610 for (number--; number > 0; --number) {
1611 cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
1613 set_row_column_number_info();
1617 int LyXTabular::cells_in_multicolumn(int cell) const
1619 int const row = row_of_cell(cell);
1620 int column = column_of_cell(cell);
1623 while ((column < columns_) &&
1624 cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
1633 int LyXTabular::UnsetMultiColumn(int cell)
1635 int const row = row_of_cell(cell);
1636 int column = column_of_cell(cell);
1640 if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
1641 cell_info[row][column].multicolumn = CELL_NORMAL;
1643 while ((column < columns_) &&
1644 (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN))
1646 cell_info[row][column].multicolumn = CELL_NORMAL;
1651 set_row_column_number_info();
1656 void LyXTabular::SetLongTabular(bool what)
1658 is_long_tabular = what;
1662 bool LyXTabular::IsLongTabular() const
1664 return is_long_tabular;
1668 void LyXTabular::SetRotateTabular(bool flag)
1674 bool LyXTabular::GetRotateTabular() const
1680 void LyXTabular::SetRotateCell(int cell, bool flag)
1682 cellinfo_of_cell(cell)->rotate = flag;
1686 bool LyXTabular::GetRotateCell(int cell) const
1688 return cellinfo_of_cell(cell)->rotate;
1692 bool LyXTabular::NeedRotating() const
1696 for (int i = 0; i < rows_; ++i) {
1697 for (int j = 0; j < columns_; ++j) {
1698 if (cell_info[i][j].rotate)
1706 bool LyXTabular::IsLastCell(int cell) const
1708 if ((cell + 1) < GetNumberOfCells())
1714 int LyXTabular::GetCellAbove(int cell) const
1716 if (row_of_cell(cell) > 0)
1717 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
1722 int LyXTabular::GetCellBelow(int cell) const
1724 if (row_of_cell(cell) + 1 < rows_)
1725 return cell_info[row_of_cell(cell)+1][column_of_cell(cell)].cellno;
1730 int LyXTabular::GetLastCellAbove(int cell) const
1732 if (row_of_cell(cell) <= 0)
1734 if (!IsMultiColumn(cell))
1735 return GetCellAbove(cell);
1736 return cell_info[row_of_cell(cell) - 1][right_column_of_cell(cell)].cellno;
1740 int LyXTabular::GetLastCellBelow(int cell) const
1742 if (row_of_cell(cell) + 1 >= rows_)
1744 if (!IsMultiColumn(cell))
1745 return GetCellBelow(cell);
1746 return cell_info[row_of_cell(cell) + 1][right_column_of_cell(cell)].cellno;
1750 int LyXTabular::GetCellNumber(int row, int column) const
1752 if (column >= columns_)
1753 column = columns_ - 1;
1754 else if (column < 0)
1761 return cell_info[row][column].cellno;
1765 void LyXTabular::SetUsebox(int cell, BoxType type)
1767 cellinfo_of_cell(cell)->usebox = type;
1771 LyXTabular::BoxType LyXTabular::GetUsebox(int cell) const
1773 if (column_info[column_of_cell(cell)].p_width.empty() &&
1774 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
1776 if (cellinfo_of_cell(cell)->usebox > 1)
1777 return cellinfo_of_cell(cell)->usebox;
1778 return UseParbox(cell);
1782 void LyXTabular::SetLTHead(int cell, bool first)
1784 int const row = row_of_cell(cell);
1785 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1788 if (endfirsthead == val)
1801 bool LyXTabular::GetRowOfLTHead(int cell, int & row) const
1804 if (abs(endhead) > rows_)
1806 return (row_of_cell(cell) == abs(endhead) - 1);
1810 bool LyXTabular::GetRowOfLTFirstHead(int cell, int & row) const
1813 if (abs(endfirsthead) > rows_)
1815 return (row_of_cell(cell) == abs(endfirsthead) - 1);
1819 void LyXTabular::SetLTFoot(int cell, bool last)
1821 int const row = row_of_cell(cell);
1822 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1825 if (endlastfoot == val)
1838 bool LyXTabular::GetRowOfLTFoot(int cell, int & row) const
1841 if ((endfoot + 1) > rows_)
1843 return (row_of_cell(cell) == abs(endfoot) - 1);
1847 bool LyXTabular::GetRowOfLTLastFoot(int cell, int & row) const
1850 if (abs(endlastfoot) > rows_)
1852 return (row_of_cell(cell) == (abs(endlastfoot)-1));
1856 void LyXTabular::SetLTNewPage(int cell, bool what)
1858 row_info[row_of_cell(cell)].newpage = what;
1862 bool LyXTabular::GetLTNewPage(int cell) const
1864 return row_info[row_of_cell(cell)].newpage;
1868 bool LyXTabular::SetAscentOfRow(int row, int height)
1870 if ((row >= rows_) || (row_info[row].ascent_of_row == height))
1872 row_info[row].ascent_of_row = height;
1877 bool LyXTabular::SetDescentOfRow(int row, int height)
1879 if ((row >= rows_) || (row_info[row].descent_of_row == height))
1881 row_info[row].descent_of_row = height;
1886 int LyXTabular::GetAscentOfRow(int row) const
1890 return row_info[row].ascent_of_row;
1894 int LyXTabular::GetDescentOfRow(int row) const
1898 return row_info[row].descent_of_row;
1902 int LyXTabular::GetHeightOfTabular() const
1906 for(int row = 0; row < rows_; ++row)
1907 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
1908 GetAdditionalHeight(GetCellNumber(row, 0));
1913 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
1915 if ((row >= rows_) || (column >= columns_))
1917 return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
1921 int LyXTabular::TeXTopHLine(ostream & os, int row) const
1923 int const fcell = GetFirstCellInRow(row);
1924 int const n = NumberOfCellsInRow(fcell) + fcell;
1927 for (int i = fcell; i < n; ++i) {
1931 if (tmp == (n - fcell)){
1934 for (int i = fcell; i < n; ++i) {
1937 << column_of_cell(i) + 1
1939 << right_column_of_cell(i) + 1
1952 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
1954 int const fcell = GetFirstCellInRow(row);
1955 int const n = NumberOfCellsInRow(fcell) + fcell;
1958 for (int i = fcell; i < n; ++i) {
1962 if (tmp == (n-fcell)){
1965 for (int i = fcell; i < n; ++i) {
1966 if (BottomLine(i)) {
1968 << column_of_cell(i) + 1
1970 << right_column_of_cell(i) + 1
1983 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
1987 if (GetRotateCell(cell)) {
1988 os << "\\begin{sideways}" << endl;
1991 if (IsMultiColumn(cell)) {
1992 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
1993 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1994 os << cellinfo_of_cell(cell+1)->align_special << "}{";
1998 if (!GetPWidth(cell).empty()) {
1999 switch(GetVAlignment(cell)) {
2000 case LYX_VALIGN_TOP:
2003 case LYX_VALIGN_CENTER:
2006 case LYX_VALIGN_BOTTOM:
2010 os << "{" << GetPWidth(cell) << '}';
2012 switch (GetAlignment(cell)) {
2013 case LYX_ALIGN_LEFT:
2016 case LYX_ALIGN_RIGHT:
2024 if (RightLine(cell))
2026 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
2032 if (GetUsebox(cell) == BOX_PARBOX) {
2034 switch(GetVAlignment(cell)) {
2035 case LYX_VALIGN_TOP:
2038 case LYX_VALIGN_CENTER:
2041 case LYX_VALIGN_BOTTOM:
2045 os << "]{" << GetPWidth(cell) << "}{";
2046 } else if (GetUsebox(cell) == BOX_MINIPAGE) {
2047 os << "\\begin{minipage}[";
2048 switch(GetVAlignment(cell)) {
2049 case LYX_VALIGN_TOP:
2052 case LYX_VALIGN_CENTER:
2055 case LYX_VALIGN_BOTTOM:
2059 os << "]{" << GetPWidth(cell) << "}\n";
2066 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
2071 if (GetUsebox(cell) == BOX_PARBOX)
2073 else if (GetUsebox(cell) == BOX_MINIPAGE) {
2074 os << "%\n\\end{minipage}";
2077 if (IsMultiColumn(cell)){
2080 if (GetRotateCell(cell)) {
2081 os << "%\n\\end{sideways}";
2088 int LyXTabular::Latex(Buffer const * buf,
2089 ostream & os, bool fragile, bool fp) const
2094 //+---------------------------------------------------------------------
2095 //+ first the opening preamble +
2096 //+---------------------------------------------------------------------
2099 os << "\\begin{sideways}" << endl;
2102 if (is_long_tabular)
2103 os << "\\begin{longtable}{";
2105 os << "\\begin{tabular}{";
2106 for (int i = 0; i < columns_; ++i) {
2107 if (column_info[i].left_line)
2109 if (!column_info[i].align_special.empty()) {
2110 os << column_info[i].align_special;
2111 } else if (!column_info[i].p_width.empty()) {
2112 switch(column_info[i].valignment) {
2113 case LYX_VALIGN_TOP:
2116 case LYX_VALIGN_CENTER:
2119 case LYX_VALIGN_BOTTOM:
2124 << column_info[i].p_width
2127 switch (column_info[i].alignment) {
2128 case LYX_ALIGN_LEFT:
2131 case LYX_ALIGN_RIGHT:
2139 if (column_info[i].right_line)
2145 //+---------------------------------------------------------------------
2146 //+ the single row and columns (cells) +
2147 //+---------------------------------------------------------------------
2150 for(int i = 0; i < rows_; ++i) {
2151 ret += TeXTopHLine(os, i);
2153 if (IsLongTabular()) {
2154 if ((endhead < 0) && (i == (abs(endhead)-1))) {
2155 os << "\\endhead\n";
2158 if ((endfirsthead < 0) && (i == (abs(endfirsthead)-1))) {
2159 os << "\\endfirsthead\n";
2162 if ((endfoot < 0) && (i == (abs(endfoot)-1))) {
2163 os << "\\endfoot\n";
2166 if ((endlastfoot < 0) && (i == (abs(endlastfoot)-1))) {
2167 os << "\\endlastfoot\n";
2173 ret += TeXBottomHLine(os, i-1);
2174 ret += TeXTopHLine(os, i);
2176 for(int j = 0; j < columns_; ++j) {
2177 if (IsPartOfMultiColumn(i,j))
2179 ret += TeXCellPreamble(os, cell);
2180 ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
2181 ret += TeXCellPostamble(os, cell);
2182 if (!IsLastCellInRow(cell)) { // not last cell in row
2188 os << "\\\\" << endl;
2189 ret += TeXBottomHLine(os, i);
2191 if (IsLongTabular()) {
2192 if ((endhead > 0) && (i == (endhead - 1))) {
2193 os << "\\endhead\n";
2196 if ((endfirsthead > 0) && (i == (endfirsthead - 1))) {
2197 os << "\\endfirsthead\n";
2200 if ((endfoot > 0) && (i == (endfoot - 1))) {
2201 os << "\\endfoot\n";
2204 if ((endlastfoot > 0) && (i == (endlastfoot - 1))) {
2205 os << "\\endlastfoot\n";
2209 ret += TeXBottomHLine(os, i);
2210 if (row_info[i].newpage) {
2211 os << "\\newpage\n";
2217 //+---------------------------------------------------------------------
2218 //+ the closing of the tabular +
2219 //+---------------------------------------------------------------------
2221 if (is_long_tabular)
2222 os << "\\end{longtable}";
2224 os << "\\end{tabular}";
2226 os << "\n\\end{sideways}";
2234 InsetText * LyXTabular::GetCellInset(int cell) const
2236 return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
2240 void LyXTabular::Validate(LaTeXFeatures & features) const
2242 if (IsLongTabular())
2243 features.longtable = true;
2245 features.rotating = true;
2246 for(int cell = 0; cell < numberofcells; ++cell) {
2247 if (GetVAlignment(cell) != LYX_VALIGN_TOP)
2248 features.array = true;
2249 GetCellInset(cell)->Validate(features);
2254 LyXTabular::BoxType LyXTabular::UseParbox(int cell) const
2256 LyXParagraph * par = GetCellInset(cell)->par;
2258 for(; par; par = par->next) {
2259 for(int i = 0; i < par->Last(); ++i) {
2260 if (par->GetChar(i) == LyXParagraph::META_NEWLINE)