1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * ======================================================
17 #pragma implementation
24 #include "lyx_gui_misc.h"
26 #include "support/lstrings.h"
27 #include "support/lyxmanip.h"
28 #include "insets/insettabular.h"
29 #include "insets/insettext.h"
38 static int const WIDTH_OF_LINE = 5;
40 /// Define a few methods for the inner structs
42 LyXTabular::cellstruct::cellstruct()
44 cellno = 0; //should be initilaized correctly later.
46 multicolumn = LyXTabular::CELL_NORMAL;
47 alignment = LYX_ALIGN_CENTER;
56 LyXTabular::cellstruct::~cellstruct()
62 LyXTabular::cellstruct::cellstruct(cellstruct const & cs)
65 width_of_cell = cs.width_of_cell;
66 multicolumn = cs.multicolumn;
67 alignment = cs.alignment;
68 top_line = cs.top_line;
69 bottom_line = cs.bottom_line;
71 linebreaks = cs.linebreaks;
76 LyXTabular::cellstruct &
77 LyXTabular::cellstruct::operator=(cellstruct const & cs)
80 width_of_cell = cs.width_of_cell;
81 multicolumn = cs.multicolumn;
82 alignment = cs.alignment;
83 top_line = cs.top_line;
84 bottom_line = cs.bottom_line;
86 linebreaks = cs.linebreaks;
91 LyXTabular::rowstruct::rowstruct()
101 LyXTabular::columnstruct::columnstruct()
105 alignment = LYX_ALIGN_CENTER;
111 LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg)
114 Init(rows_arg, columns_arg);
118 LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt)
121 Init(lt.rows_, lt.columns_);
127 LyXTabular::LyXTabular(InsetTabular * inset, LyXLex & lex)
134 LyXTabular::~LyXTabular()
137 delete[] columnofcell;
141 LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
143 // If this and lt is not of the same size we have a serious bug
144 // So then it is ok to throw an exception, or for now
146 Assert(rows_ == lt.rows_ && columns_ == lt.columns_);
148 cell_info = lt.cell_info;
149 row_info = lt.row_info;
150 column_info = lt.column_info;
152 // long tabular stuff
153 SetLongTabular(lt.is_long_tabular);
154 endhead = lt.endhead;
155 endfoot = lt.endfoot;
156 endfirsthead = lt.endfirsthead;
157 endlastfoot = lt.endlastfoot;
167 LyXTabular * LyXTabular::Clone(InsetTabular * inset)
169 LyXTabular * result = new LyXTabular(inset, *this);
171 // don't know if this is good but I need to Clone also
172 // the text-insets here, this is for the Undo-facility!
175 for(i=0; i < rows_; ++i) {
176 for(j=0; j < columns_; ++j) {
177 delete result->cell_info[i][j].inset;
178 result->cell_info[i][j].inset=new InsetText(*cell_info[i][j].inset,
179 inset->BufferOwner());
180 result->cell_info[i][j].inset->setOwner(inset);
187 /* activates all lines and sets all widths to 0 */
188 void LyXTabular::Init(int rows_arg, int columns_arg)
194 columns_ = columns_arg;
195 row_info = vector<rowstruct>(rows_, rowstruct());
196 column_info = vector<columnstruct>(columns_, columnstruct());
197 cell_info = vector<vector<cellstruct> >
198 (rows_, vector<cellstruct>(columns_, cellstruct()));
200 // Jürgen, use iterators.
201 for (i = 0; i < rows_; ++i) {
202 for (j = 0; j < columns_; ++j) {
203 cell_info[i][j].inset = new InsetText(owner_->BufferOwner());
204 cell_info[i][j].inset->setOwner(owner_);
205 cell_info[i][j].inset->SetDrawLockedFrame(true);
206 cell_info[i][j].cellno = cellno++;
209 row_info[i-1].bottom_line = true;
210 row_info[0].bottom_line = true;
212 for (i = 0; i < columns_; ++i) {
213 calculate_width_of_column(i);
215 column_info[columns_-1].right_line = true;
217 calculate_width_of_tabular();
221 set_row_column_number_info();
222 is_long_tabular = false;
231 void LyXTabular::AppendRow(int /* cell */)
234 int row = row_of_cell(cell);
235 rowstruct * row_info2 = new rowstruct[rows_ + 1];
236 cellstruct ** cell_info2 = new cellstruct * [rows_ + 1];
239 for (i = 0; i <= row; ++i) {
240 cell_info2[i] = cell_info[i];
241 row_info2[i] = row_info[i];
243 for (i = rows_ - 1; i >= row; --i) {
244 cell_info2[i + 1] = cell_info[i];
245 row_info2[i + 1] = row_info[i];
247 row_info2[row + 1].top_line = row_info[i].top_line;
248 cell_info2[row + 1] = new cellstruct[columns_](owner_->BufferOwner());
249 for (i = 0; i < columns_; ++i) {
250 cell_info2[row + 1][i].width_of_cell = 0;
251 cell_info2[row + 1][i] = cell_info2[row][i];
255 cell_info = cell_info2;
257 row_info = row_info2;
266 void LyXTabular::DeleteRow(int /*cell*/)
269 int row = row_of_cell(cell);
270 rowstruct * row_info2 = new rowstruct[rows_ - 1];
271 cellstruct ** cell_info2 = new cellstruct * [rows_ - 1];
273 delete[] cell_info[row];
275 for (; i < row; ++i) {
276 cell_info2[i] = cell_info[i];
277 row_info2[i] = row_info[i];
279 for (i = row; i < rows_ - 1; ++i) {
280 cell_info2[i] = cell_info[i + 1];
281 row_info2[i] = row_info[i + 1];
285 cell_info = cell_info2;
287 row_info = row_info2;
296 void LyXTabular::AppendColumn(int /*cell*/)
300 columnstruct * column_info2 = new columnstruct[columns_ + 1];
301 int column = right_column_of_cell(cell);
304 for (; i <= column; ++i) {
305 column_info2[i] = column_info[i];
307 for (i = columns_ - 1; i >= column; --i) {
308 column_info2[i + 1] = column_info[i];
311 delete[] column_info;
312 column_info = column_info2;
314 for (i = 0; i < rows_; ++i) {
315 cellstruct * tmp = cell_info[i];
316 cell_info[i] = new cellstruct[columns_ + 1](owner_->BufferOwner());
317 for (j = 0; j <= column; ++j) {
318 cell_info[i][j] = tmp[j];
320 for (j = column; j < columns_; ++j) {
321 cell_info[i][j + 1] = tmp[j];
323 // care about multicolumns
324 if (cell_info[i][column + 1].multicolumn
325 == LyXTabular::CELL_BEGIN_OF_MULTICOLUMN){
326 cell_info[i][column + 1].multicolumn =
327 LyXTabular::CELL_PART_OF_MULTICOLUMN;
329 if (column + 1 == columns_
330 || cell_info[i][column + 2].multicolumn
331 != LyXTabular::CELL_PART_OF_MULTICOLUMN){
332 cell_info[i][column + 1].multicolumn =
333 LyXTabular::CELL_NORMAL;
344 void LyXTabular::DeleteColumn(int /*cell*/)
347 int column1 = column_of_cell(cell);
348 int column2 = right_column_of_cell(cell);
350 if (column1 == 0 && column2 == columns_ - 1)
353 for (int column = column1; column <= column2; ++column) {
354 delete_column(column1);
361 void LyXTabular::delete_column(int /*column*/)
365 columnstruct * column_info2 = new columnstruct[columns_-1];
367 for (i = 0; i < column; ++i) {
368 column_info2[i] = column_info[i];
370 for (i = column; i < columns_ - 1; ++i) {
371 column_info2[i] = column_info[i + 1];
374 delete[] column_info;
375 column_info = column_info2;
377 for (i = 0; i < rows_; ++i) {
378 cellstruct * tmp = cell_info[i];
379 cell_info[i] = new cellstruct[columns_ - 1](owner_->BufferOwner());
380 for (j = 0; j < column; ++j) {
381 cell_info[i][j] = tmp[j];
383 for (j = column; j < columns_ - 1; ++j) {
384 cell_info[i][j] = tmp[j + 1];
395 void LyXTabular::Reinit()
401 // Jürgen, use iterators.
402 for (; i < rows_; ++i) {
403 for (j = 0; j < columns_; ++j) {
404 cell_info[i][j].width_of_cell = 0;
408 for (i = 0; i < columns_; ++i) {
409 calculate_width_of_column(i);
411 calculate_width_of_tabular();
413 set_row_column_number_info();
417 void LyXTabular::set_row_column_number_info()
423 for (; row < rows_; ++row) {
424 for (column = 0; column<columns_; ++column) {
425 if (cell_info[row][column].multicolumn
426 != LyXTabular::CELL_PART_OF_MULTICOLUMN)
428 cell_info[row][column].cellno = numberofcells;
431 ++numberofcells; // because this is one more than as we start from 0
436 rowofcell = new int[numberofcells];
437 delete [] columnofcell;
438 columnofcell = new int[numberofcells];
440 while (c < numberofcells && row < rows_ && column < columns_) {
442 columnofcell[c] = column;
446 } while (column < columns_ &&
447 cell_info[row][column].multicolumn
448 == LyXTabular::CELL_PART_OF_MULTICOLUMN);
449 if (column == columns_) {
457 int LyXTabular::GetNumberOfCells() const
459 return numberofcells;
463 int LyXTabular::NumberOfCellsInRow(int cell) const
465 int row = row_of_cell(cell);
467 for (int i = 0; i < columns_; ++i) {
468 if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
475 int LyXTabular::AppendCellAfterCell(int append_cell, int question_cell)
477 return (right_column_of_cell(append_cell) ==
478 right_column_of_cell(question_cell));
482 int LyXTabular::DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell)
484 if (column_of_cell(delete_column_cell) == 0 &&
485 right_column_of_cell(delete_column_cell) == columns_ - 1)
489 (column_of_cell(cell) >= column_of_cell(delete_column_cell) &&
490 column_of_cell(cell) <= right_column_of_cell(delete_column_cell));
494 /* returns 1 if there is a topline, returns 0 if not */
495 bool LyXTabular::TopLine(int cell) const
497 int row = row_of_cell(cell);
499 if (IsMultiColumn(cell))
500 return cellinfo_of_cell(cell)->top_line;
501 return row_info[row].top_line;
505 bool LyXTabular::BottomLine(int cell) const
507 //no bottom line underneath non-existent cells if you please
508 if(cell >= numberofcells)
511 if (IsMultiColumn(cell))
512 return cellinfo_of_cell(cell)->bottom_line;
513 return row_info[row_of_cell(cell)].bottom_line;
517 bool LyXTabular::LeftLine(int cell) const
519 return column_info[column_of_cell(cell)].left_line;
523 bool LyXTabular::RightLine(int cell) const
525 return column_info[right_column_of_cell(cell)].right_line;
529 bool LyXTabular::TopAlreadyDrawed(int cell) const
531 if (GetAdditionalHeight(cell))
533 int row = row_of_cell(cell);
535 int column = column_of_cell(cell);
538 && cell_info[row][column].multicolumn
539 == LyXTabular::CELL_PART_OF_MULTICOLUMN)
541 if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL)
542 return row_info[row].bottom_line;
544 return cell_info[row][column].bottom_line;
550 bool LyXTabular::LeftAlreadyDrawed(int cell) const
552 int column = column_of_cell(cell);
554 int row = row_of_cell(cell);
556 (cell_info[row][column].multicolumn ==
557 LyXTabular::CELL_PART_OF_MULTICOLUMN));
558 if (GetAdditionalWidth(cell_info[row][column].cellno))
560 return column_info[column].right_line;
566 bool LyXTabular::IsLastRow(int cell) const
568 return (row_of_cell(cell) == rows_ - 1);
572 int LyXTabular::GetAdditionalHeight(int cell) const
574 int row = row_of_cell(cell);
577 int top = 1; // bool top = true; ??
578 int bottom = 1; // bool bottom = true; ??
581 for (column = 0; column < columns_ - 1 && bottom; ++column) {
582 switch (cell_info[row - 1][column].multicolumn) {
583 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
584 bottom = cell_info[row - 1][column].bottom_line;
586 case LyXTabular::CELL_NORMAL:
587 bottom = row_info[row - 1].bottom_line;
590 for (column = 0; column < columns_ - 1 && top; ++column) {
591 switch (cell_info[row][column].multicolumn){
592 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
593 top = cell_info[row][column].top_line;
595 case LyXTabular::CELL_NORMAL:
596 top = row_info[row].top_line;
600 return WIDTH_OF_LINE;
605 int LyXTabular::GetAdditionalWidth(int cell) const
607 // internally already set in SetWidthOfCell
608 // used to get it back in text.C
609 int col = right_column_of_cell(cell);
610 if (col < columns_ - 1 && column_info[col].right_line &&
611 column_info[col+1].left_line)
612 return WIDTH_OF_LINE;
618 // returns the maximum over all rows
619 int LyXTabular::GetWidthOfColumn(int cell) const
621 int column1 = column_of_cell(cell);
622 int column2 = right_column_of_cell(cell);
625 for (; i <= column2; ++i) {
626 result += column_info[i].width_of_column;
632 int LyXTabular::GetWidthOfTabular() const
634 return width_of_tabular;
638 /* returns 1 if a complete update is necessary, otherwise 0 */
639 bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
641 if (!IsMultiColumn(cell))
644 int row = row_of_cell(cell);
645 int column1 = column_of_cell(cell);
646 int column2 = right_column_of_cell(cell);
648 // first set columns to 0 so we can calculate the right width
650 for (; i <= column2; ++i) {
651 cell_info[row][i].width_of_cell = 0;
653 // set the width to MAX_WIDTH until width > 0
654 int width = (new_width + 2 * WIDTH_OF_LINE);
655 for (i = column1; (i < column2) && (width > 0); ++i) {
656 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
657 width -= column_info[i].width_of_column;
660 cell_info[row][i].width_of_cell = width;
666 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
668 int row = row_of_cell(cell);
669 int column1 = column_of_cell(cell);
670 int column2 = right_column_of_cell(cell);
672 // first set columns to 0 so we can calculate the right width
674 for (; i <= column2; ++i)
675 cell_info[row][i].width_of_cell = 0;
676 for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
678 if (i < numberofcells)
679 recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
680 SetWidthOfMulticolCell(cell, new_width);
684 /* returns 1 if a complete update is necessary, otherwise 0 */
685 bool LyXTabular::SetWidthOfCell(int cell, int new_width)
687 int row = row_of_cell(cell);
688 int column1 = column_of_cell(cell);
692 if (IsMultiColumn(cell)) {
693 tmp = SetWidthOfMulticolCell(cell, new_width);
695 width = (new_width + 2*WIDTH_OF_LINE);
696 cell_info[row][column1].width_of_cell = width;
697 if (column_info[column1].right_line && (column1 < columns_-1) &&
698 column_info[column1+1].left_line) // additional width
699 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
700 tmp = calculate_width_of_column_NMC(column1);
704 for(i = 0; i<columns_;++i)
705 calculate_width_of_column_NMC(i);
706 for(i = 0; (i<numberofcells) && !IsMultiColumn(i); ++i)
709 recalculateMulticolCells(i, GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
710 for(i = 0; i<columns_;++i)
711 calculate_width_of_column(i);
712 calculate_width_of_tabular();
719 bool LyXTabular::SetAlignment(int cell, char align)
721 if (!IsMultiColumn(cell))
722 column_info[column_of_cell(cell)].alignment = align;
723 cellinfo_of_cell(cell)->alignment = align;
728 bool LyXTabular::SetPWidth(int cell, string const & width)
730 bool flag = !width.empty();
732 if (IsMultiColumn(cell)) {
733 cellinfo_of_cell(cell)->p_width = width;
734 GetCellInset(cell)->SetAutoBreakRows(flag);
736 int j = column_of_cell(cell);
738 column_info[j].p_width = width;
739 if (flag) // do this only if there is a width
740 SetAlignment(cell, LYX_ALIGN_LEFT);
741 for(int i=0; i < rows_; ++i) {
742 c = GetCellNumber(i, j);
743 flag = !GetPWidth(c).empty(); // because of multicolumns!
744 GetCellInset(c)->SetAutoBreakRows(flag);
751 bool LyXTabular::SetAlignSpecial(int cell, string const & special, int what)
753 if (what == SET_SPECIAL_MULTI)
754 cellinfo_of_cell(cell)->align_special = special;
756 column_info[column_of_cell(cell)].align_special = special;
761 bool LyXTabular::SetAllLines(int cell, bool line)
763 SetTopLine(cell, line);
764 SetBottomLine(cell, line);
765 SetRightLine(cell, line);
766 SetLeftLine(cell, line);
771 bool LyXTabular::SetTopLine(int cell, bool line)
773 int row = row_of_cell(cell);
775 if (!IsMultiColumn(cell))
776 row_info[row].top_line = line;
778 cellinfo_of_cell(cell)->top_line = line;
783 bool LyXTabular::SetBottomLine(int cell, bool line)
785 if (!IsMultiColumn(cell))
786 row_info[row_of_cell(cell)].bottom_line = line;
788 cellinfo_of_cell(cell)->bottom_line = line;
793 bool LyXTabular::SetLeftLine(int cell, bool line)
795 column_info[column_of_cell(cell)].left_line = line;
800 bool LyXTabular::SetRightLine(int cell, bool line)
802 column_info[right_column_of_cell(cell)].right_line = line;
807 char LyXTabular::GetAlignment(int cell) const
809 if (IsMultiColumn(cell))
810 return cellinfo_of_cell(cell)->alignment;
812 return column_info[column_of_cell(cell)].alignment;
816 string LyXTabular::GetPWidth(int cell) const
818 if (IsMultiColumn(cell))
819 return cellinfo_of_cell(cell)->p_width;
820 return column_info[column_of_cell(cell)].p_width;
824 string LyXTabular::GetAlignSpecial(int cell, int what) const
826 if (what == SET_SPECIAL_MULTI)
827 return cellinfo_of_cell(cell)->align_special;
828 return column_info[column_of_cell(cell)].align_special;
832 int LyXTabular::GetWidthOfCell(int cell) const
834 int row = row_of_cell(cell);
835 int column1 = column_of_cell(cell);
836 int column2 = right_column_of_cell(cell);
839 for (; i <= column2; ++i) {
840 result += cell_info[row][i].width_of_cell;
843 // result += GetAdditionalWidth(cell);
848 int LyXTabular::GetBeginningOfTextInCell(int cell) const
852 switch (GetAlignment(cell)){
853 case LYX_ALIGN_CENTER:
854 x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
856 case LYX_ALIGN_RIGHT:
857 x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
858 // + GetAdditionalWidth(cell);
860 default: /* LYX_ALIGN_LEFT: nothing :-) */
870 bool LyXTabular::IsFirstCellInRow(int cell) const
872 return (column_of_cell(cell) == 0);
876 int LyXTabular::GetFirstCellInRow(int row) const
880 return cell_info[row][0].cellno;
883 bool LyXTabular::IsLastCellInRow(int cell) const
885 return (right_column_of_cell(cell) == (columns_ - 1));
889 int LyXTabular::GetLastCellInRow(int row) const
893 return cell_info[row][columns_-1].cellno;
897 bool LyXTabular::calculate_width_of_column(int column)
899 int old_column_width = column_info[column].width_of_column;
902 for (int i = 0; i < rows_; ++i) {
903 maximum = max(cell_info[i][column].width_of_cell, maximum);
905 column_info[column].width_of_column = maximum;
906 return (column_info[column].width_of_column != old_column_width);
910 bool LyXTabular::calculate_width_of_column_NMC(int column)
912 int old_column_width = column_info[column].width_of_column;
914 for (int i = 0; i < rows_; ++i) {
915 if (!IsMultiColumn(GetCellNumber(i, column)) &&
916 (cell_info[i][column].width_of_cell > max)) {
917 max = cell_info[i][column].width_of_cell;
920 column_info[column].width_of_column = max;
921 return (column_info[column].width_of_column != old_column_width);
925 void LyXTabular::calculate_width_of_tabular()
927 width_of_tabular = 0;
928 for (int i = 0; i < columns_; ++i) {
929 width_of_tabular += column_info[i].width_of_column;
934 int LyXTabular::row_of_cell(int cell) const
936 if (cell >= numberofcells)
940 return rowofcell[cell];
944 int LyXTabular::column_of_cell(int cell) const
946 if (cell >= numberofcells)
950 return columnofcell[cell];
954 int LyXTabular::right_column_of_cell(int cell) const
956 int row = row_of_cell(cell);
957 int column = column_of_cell(cell);
958 while (column < (columns_ - 1) &&
959 cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
965 void LyXTabular::Write(ostream & os) const
970 os << "<LyXTabular version=1 rows=" << rows_ << " columns=" << columns_ <<
972 // global longtable options
973 os << "<Features rotate=" << rotate <<
974 " islongtable=" << is_long_tabular <<
975 " endhead=" << endhead << " endfirsthead=" << endfirsthead <<
976 " endfoot=" << endfoot << " endlastfoot=" << endlastfoot <<
978 for (i = 0; i < rows_; ++i) {
979 os << "<Row topline=" << row_info[i].top_line <<
980 " bottomline=" << row_info[i].bottom_line <<
981 " newpage=" << row_info[i].newpage <<
983 for (j = 0; j < columns_; ++j) {
985 os << "<Column alignment=" << column_info[j].alignment <<
986 " leftline=" << column_info[j].left_line <<
987 " rightline=" << column_info[j].right_line <<
988 " width=\"" << VSpace(column_info[j].p_width).asLyXCommand() <<
989 "\" special=\"" << column_info[j].align_special <<
992 os << "<Column>" << endl;
994 os << "<Cell multicolumn=" << cell_info[i][j].multicolumn <<
995 " alignment=" << cell_info[i][j].alignment <<
996 " topline=" << cell_info[i][j].top_line <<
997 " bottomline=" << cell_info[i][j].bottom_line <<
998 " rotate=" << cell_info[i][j].rotate <<
999 " linebreaks=" << cell_info[i][j].linebreaks <<
1000 " width=\"" << cell_info[i][j].p_width <<
1001 "\" special=\"" << cell_info[i][j].align_special <<
1003 os << "\\begin_inset ";
1004 cell_info[i][j].inset->Write(os);
1005 os << "\n\\end_inset " << endl;
1006 os << "</Cell>" << endl;
1007 os << "</Column>" << endl;
1009 os << "</Row>" << endl;
1011 os << "</LyXTabular>" << endl;
1016 bool getTokenValue(string const str, const char * token, string & ret)
1018 int pos = str.find(token);
1019 char ch = str[pos+strlen(token)];
1021 if ((pos < 0) || (ch != '='))
1024 pos += strlen(token)+1;
1026 if ((ch != '"') && (ch != '\'')) { // only read till next space
1030 while((pos < int(str.length()-1)) && (str[++pos] != ch))
1038 bool getTokenValue(string const str, const char * token, int & num)
1041 int pos = str.find(token);
1042 char ch = str[pos+strlen(token)];
1044 if ((pos < 0) || (ch != '='))
1047 pos += strlen(token)+1;
1049 if ((ch != '"') && (ch != '\'')) { // only read till next space
1055 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1058 num = strToInt(ret);
1064 bool getTokenValue(string const str, const char * token, bool & flag)
1067 int pos = str.find(token);
1068 char ch = str[pos+strlen(token)];
1070 if ((pos < 0) || (ch != '='))
1073 pos += strlen(token)+1;
1075 if ((ch != '"') && (ch != '\'')) { // only read till next space
1081 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1084 flag = strToInt(ret);
1089 void l_getline(istream & is, string & str)
1097 void LyXTabular::Read(LyXLex & lex)
1100 istream & is = lex.getStream();
1102 l_getline(is, line);
1103 if (!prefixIs(line, "<LyXTabular ")) {
1104 OldFormatRead(lex, line);
1111 if (!getTokenValue(line, "version", version))
1113 if (!getTokenValue(line, "rows", rows_arg))
1115 if (!getTokenValue(line, "columns", columns_arg))
1117 Init(rows_arg, columns_arg);
1118 l_getline(is, line);
1119 if (!prefixIs(line, "<Features ")) {
1120 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
1121 line << ")" << endl;
1124 (void)getTokenValue(line, "islongtable", is_long_tabular);
1125 (void)getTokenValue(line, "endhead", endhead);
1126 (void)getTokenValue(line, "endfirsthead", endfirsthead);
1127 (void)getTokenValue(line, "endfoot", endfoot);
1128 (void)getTokenValue(line, "endlastfoot", endlastfoot);
1130 for(i = 0; i < rows_; ++i) {
1131 l_getline(is, line);
1132 if (!prefixIs(line, "<Row ")) {
1133 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
1134 line << ")" << endl;
1137 (void)getTokenValue(line, "topline", row_info[i].top_line);
1138 (void)getTokenValue(line, "bottomline", row_info[i].bottom_line);
1139 (void)getTokenValue(line, "newpage", row_info[i].newpage);
1140 for (j = 0; j < columns_; ++j) {
1142 if (!prefixIs(line,"<Column")) {
1143 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
1144 line << ")" << endl;
1148 (void)getTokenValue(line, "alignment", column_info[j].alignment);
1149 (void)getTokenValue(line, "leftline", column_info[j].left_line);
1150 (void)getTokenValue(line, "rightline", column_info[j].right_line);
1151 (void)getTokenValue(line, "width", column_info[j].p_width);
1152 (void)getTokenValue(line, "special", column_info[j].align_special);
1154 l_getline(is, line);
1155 if (!prefixIs(line, "<Cell")) {
1156 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
1157 line << ")" << endl;
1160 (void)getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1161 (void)getTokenValue(line, "alignment", cell_info[i][j].alignment);
1162 (void)getTokenValue(line, "topline", cell_info[i][j].top_line);
1163 (void)getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1164 (void)getTokenValue(line, "rotate", cell_info[i][j].rotate);
1165 (void)getTokenValue(line, "linebreaks", cell_info[i][j].linebreaks);
1166 (void)getTokenValue(line, "width", cell_info[i][j].p_width);
1167 if (!(cell_info[i][j].p_width.empty() &&
1168 column_info[j].p_width.empty()))
1169 cell_info[i][j].inset->SetAutoBreakRows(true);
1170 (void)getTokenValue(line, "special", cell_info[i][j].align_special);
1171 l_getline(is, line);
1172 if (prefixIs(line, "\\begin_inset")) {
1173 cell_info[i][j].inset->Read(lex);
1174 l_getline(is, line);
1176 if (line != "</Cell>") {
1177 lyxerr << "Wrong tabular format (expected </Cell> got" <<
1178 line << ")" << endl;
1181 l_getline(is, line);
1182 if (line != "</Column>") {
1183 lyxerr << "Wrong tabular format (expected </Column> got" <<
1184 line << ")" << endl;
1188 l_getline(is, line);
1189 if (line != "</Row>") {
1190 lyxerr << "Wrong tabular format (expected </Row> got" <<
1191 line << ")" << endl;
1195 while (line != "</LyXTabular>") {
1196 l_getline(is, line);
1198 set_row_column_number_info();
1202 void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
1207 int columns_arg = 0;
1208 int is_long_tabular_arg = false;
1209 int rotate_arg = false;
1219 istream & is = lex.getStream();
1222 version = atoi(s.c_str() + 8);
1226 //int * cont_row_info; // unused
1229 lyxerr << "Tabular format < 5 is not supported anymore\n"
1230 "Get an older version of LyX (< 1.1.x) for conversion!"
1232 WriteAlert(_("Warning:"),
1233 _("Tabular format < 5 is not supported anymore\n"),
1234 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1236 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1237 >> rotate_arg >> a >> b >> c >> d;
1239 is >> rows_arg >> columns_arg;
1240 Init(rows_arg, columns_arg);
1241 SetLongTabular(is_long_tabular_arg);
1242 SetRotateTabular(rotate_arg);
1244 for (i = 0; i < rows_; ++i) {
1247 for (i = 0; i < columns_; ++i) {
1250 for (i = 0; i < rows_; ++i) {
1251 for (j = 0; j < columns_; ++j) {
1256 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1257 >> rotate_arg >> a >> b >> c >> d;
1258 Init(rows_arg, columns_arg);
1259 SetLongTabular(is_long_tabular_arg);
1260 SetRotateTabular(rotate_arg);
1265 for (i = 0; i < rows_; ++i) {
1266 a = b = c = d = e = f = g = h = 0;
1267 is >> a >> b >> c >> d;
1268 row_info[i].top_line = a;
1269 row_info[i].bottom_line = b;
1270 // row_info[i].is_cont_row = c;
1271 row_info[i].newpage = d;
1273 for (i = 0; i < columns_; ++i) {
1277 char ch; // skip '"'
1279 getline(is, s1, '"');
1280 is >> ch; // skip '"'
1281 getline(is, s2, '"');
1282 column_info[i].alignment = static_cast<char>(a);
1283 column_info[i].left_line = b;
1284 column_info[i].right_line = c;
1285 column_info[i].p_width = s1;
1286 column_info[i].align_special = s2;
1288 for (i = 0; i < rows_; ++i) {
1289 for (j = 0; j < columns_; ++j) {
1292 is >> a >> b >> c >> d >> e >> f >> g;
1294 is >> ch; // skip '"'
1295 getline(is, s1, '"');
1296 is >> ch; // skip '"'
1297 getline(is, s2, '"');
1298 cell_info[i][j].multicolumn = static_cast<char>(a);
1299 cell_info[i][j].alignment = static_cast<char>(b);
1300 cell_info[i][j].top_line = static_cast<char>(c);
1301 cell_info[i][j].bottom_line = static_cast<char>(d);
1302 // cell_info[i][j].has_cont_row = static_cast<bool>(e);
1303 cell_info[i][j].rotate = static_cast<bool>(f);
1304 cell_info[i][j].linebreaks = static_cast<bool>(g);
1305 cell_info[i][j].align_special = s1;
1306 cell_info[i][j].p_width = s2;
1310 set_row_column_number_info();
1311 LyXParagraph * par = new LyXParagraph;
1312 LyXParagraph * return_par = 0;
1313 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1314 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
1315 string token, tmptok;
1318 LyXFont font(LyXFont::ALL_INHERIT);
1320 while (lex.IsOK()) {
1322 token = lex.GetString();
1325 if ((token == "\\layout") || (token == "\\end_float")) {
1326 lex.pushToken(token);
1329 if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
1337 lex.pushToken(token);
1341 lex.printError("New Paragraph allocated! This should not happen!");
1342 lex.pushToken(token);
1348 // now we have the par we should fill the insets with this!
1350 InsetText *inset = GetCellInset(cell);
1352 for(int i=0; i < par->Last(); ++i) {
1353 if (par->IsNewline(i)) {
1355 if (cell > GetNumberOfCells()) {
1356 lyxerr << "Some error in reading old table format occured!" <<
1357 endl << "Terminating when reading cell[" << cell << "]!" <<
1361 inset = GetCellInset(cell);
1364 par->CopyIntoMinibuffer(i);
1365 inset->par->InsertFromMinibuffer(inset->par->Last());
1371 // cell < 0 will tex the preamble
1372 // returns the number of printed newlines
1373 int LyXTabular::TexEndOfCell(ostream & os, int cell) const
1379 if (IsLastCell(cell)) {
1380 // the very end at the very beginning
1381 if (GetLinebreaks(cell))
1382 os << "\\smallskip{}}";
1383 if (IsMultiColumn(cell))
1385 if (GetRotateCell(cell)) {
1386 os << "\n\\end{sideways}";
1394 while (!IsFirstCellInRow(fcell)) --fcell;
1395 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1396 if (BottomLine(fcell + i))
1399 if (tmp == NumberOfCellsInRow(fcell)) {
1403 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1404 if (BottomLine(fcell + i)) {
1406 << column_of_cell(fcell + i) + 1
1408 << right_column_of_cell(fcell + i) + 1
1418 if (is_long_tabular)
1419 os << "\\end{longtable}";
1421 os << "\\end{tabular}";
1423 os << "\n\\end{sideways}";
1431 os << "\\begin{sideways}\n";
1434 if (is_long_tabular)
1435 os << "\\begin{longtable}{";
1437 os << "\\begin{tabular}{";
1438 for (i = 0; i < columns_; ++i) {
1439 if (column_info[i].left_line)
1441 if (!column_info[i].align_special.empty()) {
1442 os << column_info[i].align_special;
1443 } else if (!column_info[i].p_width.empty()) {
1445 << column_info[i].p_width
1448 switch (column_info[i].alignment) {
1449 case LYX_ALIGN_LEFT:
1452 case LYX_ALIGN_RIGHT:
1460 if (column_info[i].right_line)
1466 if (GetNumberOfCells()) {
1468 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1469 if (TopLine(fcell + i))
1472 if (tmp == NumberOfCellsInRow(fcell)){
1476 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1477 if (TopLine(fcell + i)) {
1479 << column_of_cell(fcell + i) + 1
1481 << right_column_of_cell(fcell + i) + 1
1492 if (GetRotateCell(0)) {
1493 os << "\\begin{sideways}\n";
1498 if (GetLinebreaks(cell))
1499 os << "\\smallskip{}}";
1500 if (IsMultiColumn(cell)){
1503 if (GetRotateCell(cell)) {
1504 os << "\n\\end{sideways}";
1507 if (IsLastCellInRow(cell)) {
1508 int row = row_of_cell(cell);
1509 string hline1, hline2;
1510 bool print_hline = true;
1511 bool flag1 = IsLongTabular() &&
1512 ((row == endhead) || (row == endfirsthead) ||
1513 (row == endfoot) || (row == endlastfoot));
1515 bool flag2 = IsLongTabular() &&
1516 ((row <= endhead) || (row <= endfirsthead) ||
1517 (row <= endfoot) || (row <= endlastfoot));
1519 // print the bottom hline only if (otherwise it is doubled):
1520 // - is no LongTabular
1521 // - there IS a first-header
1522 // - the next row is no special header/footer
1523 // & this row is no special header/footer
1524 // - the next row is a special header/footer
1525 // & this row is a special header/footer
1526 bool pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1527 (endfirsthead == endhead);
1532 while (!IsFirstCellInRow(fcell))
1534 for (i = 0; i < NumberOfCellsInRow(cell); ++i) {
1535 if (BottomLine(fcell + i))
1538 if (tmp == NumberOfCellsInRow(cell)){
1540 hline1 = "\\hline ";
1543 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1544 if (BottomLine(fcell + i)){
1546 << column_of_cell(fcell + i) + 1
1548 << right_column_of_cell(fcell + i) + 1
1550 hline1 += "\\cline{";
1551 hline1 += tostr(column_of_cell(fcell + i) + 1);
1553 hline1 += tostr(right_column_of_cell(fcell + i) + 1);
1563 if (IsLongTabular() && (row == endfoot)) {
1564 os << "\\endfoot\n";
1566 print_hline = false; // no double line below footer
1568 if (IsLongTabular() && (row == endlastfoot)) {
1569 os << "\\endlastfoot\n";
1571 print_hline = false; // no double line below footer
1573 if (IsLongTabular() && row_info[row].newpage) {
1574 os << "\\newpage\n";
1576 print_hline = false; // no line below a \\newpage-command
1579 if ((nvcell < numberofcells) &&
1580 (cell < GetNumberOfCells() - 1) && !IsLastCell(cell)) {
1582 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1583 if (TopLine(fcell + i))
1586 if (tmp == NumberOfCellsInRow(fcell)) {
1589 hline2 = "\\hline ";
1592 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1593 if (TopLine(fcell + i)) {
1596 << column_of_cell(fcell + i) + 1
1598 << right_column_of_cell(fcell + i) + 1
1601 hline2 += "\\cline{";
1602 hline2 += tostr(column_of_cell(fcell+i)+1);
1604 hline2 += tostr(right_column_of_cell(fcell+i)+1);
1610 if (tmp && print_hline){
1615 // the order here is important as if one defines two
1616 // or more things in one line only the first entry is
1617 // displayed the other are set to an empty-row. This
1618 // is important if I have a footer and want that the
1619 // lastfooter is NOT displayed!!!
1620 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1621 (row == endfoot) || (row == endlastfoot);
1624 bool sflag1 = IsLongTabular() && (row != endhead) &&
1625 (row != endfirsthead) &&
1626 ((row == endfoot) || (row == endlastfoot));
1628 if (IsLongTabular() && (row == endhead)) {
1629 os << "\\endhead\n";
1632 if (IsLongTabular() && (row == endfirsthead)) {
1633 os << "\\endfirsthead\n";
1636 if (sflag1) { // add the \hline for next foot row
1637 if (!hline1.empty()) {
1638 os << hline1 + '\n';
1642 // add the \hline for the first row
1643 if (pr_top_hline && sflag2) {
1644 if (!hline2.empty()) {
1645 os << hline2 + '\n';
1649 if (nvcell < numberofcells && GetRotateCell(nvcell)) {
1650 os << "\\begin{sideways}\n";
1656 if (nvcell < numberofcells && GetRotateCell(nvcell)) {
1657 os << "\\begin{sideways}\n";
1662 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1663 os << "\\multicolumn{"
1664 << cells_in_multicolumn(nvcell)
1666 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1667 os << cellinfo_of_cell(cell+1)->align_special
1670 if (LeftLine(nvcell))
1672 if (!GetPWidth(nvcell).empty()) {
1674 << GetPWidth(nvcell)
1677 switch (GetAlignment(nvcell)) {
1678 case LYX_ALIGN_LEFT: os << 'l'; break;
1679 case LYX_ALIGN_RIGHT: os << 'r'; break;
1680 default: os << 'c'; break;
1683 if (RightLine(nvcell))
1685 //if (column_of_cell(cell+2)!= 0 && LeftLine(cell+2))
1686 if (((nvcell + 1) < numberofcells) &&
1687 ((nvcell+1) < numberofcells) &&
1688 (column_of_cell(nvcell+1)!= 0) &&
1695 if (nvcell < numberofcells && GetLinebreaks(nvcell)) {
1696 os << "\\parbox[t]{"
1697 << GetPWidth(nvcell)
1698 << "}{\\smallskip{}";
1705 // cell <0 will tex the preamble
1706 // returns the number of printed newlines
1707 int LyXTabular::RoffEndOfCell(ostream & os, int cell)
1711 if (cell == GetNumberOfCells() - 1){
1712 // the very end at the very beginning
1713 // if (CellHasContRow(cell) >= 0) {
1719 if (row_info[row_of_cell(cell)].bottom_line) {
1723 os << ".TE\n.pl 1c";
1728 os << "\n.pl 500c\n.TS\n";
1729 for (int j = 0; j < rows_; ++j) {
1730 for (int i = 0; i < columns_; ++i, ++fcell) {
1731 if (column_info[i].left_line)
1733 if (cell_info[j][i].multicolumn == CELL_PART_OF_MULTICOLUMN)
1736 switch (column_info[i].alignment) {
1737 case LYX_ALIGN_LEFT:
1740 case LYX_ALIGN_RIGHT:
1748 if (!column_info[i].p_width.empty())
1749 os << "w(" << column_info[i].p_width << ")";
1750 if (column_info[i].right_line)
1753 if ((j + 1) < rows_) {
1760 if (row_info[0].top_line) {
1764 // if (CellHasContRow(0) >= 0) {
1770 // if (CellHasContRow(cell) >= 0) {
1774 if (right_column_of_cell(cell) == columns_ -1){
1777 int row = row_of_cell(cell);
1778 if (row_info[row++].bottom_line) {
1782 if ((row < rows_) && row_info[row].top_line) {
1788 // if ((cell < GetNumberOfCells() - 1) &&
1789 // (CellHasContRow(cell+1) >= 0)) {
1801 char const * LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
1803 int i = isColumn ? cell : column_of_cell(cell);
1808 //i = column_of_cell(cell);
1809 if (!isColumn && IsMultiColumn(cell)) {
1810 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1811 return cellinfo_of_cell(cell)->align_special.c_str();
1813 switch (GetAlignment(cell)) {
1814 case LYX_ALIGN_LEFT:
1816 case LYX_ALIGN_RIGHT:
1823 if (!column_info[i].align_special.empty()) {
1824 return column_info[i].align_special.c_str();
1826 #ifdef IGNORE_THIS_FOR_NOW
1827 else if (!column_info[i].p_width.empty()) {
1829 file += column_info[i].p_width;
1834 switch (column_info[i].alignment) {
1835 case LYX_ALIGN_LEFT:
1837 case LYX_ALIGN_RIGHT:
1847 // cell <0 will tex the preamble
1848 // returns the number of printed newlines
1849 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1853 //int tmp; // tmp2; // unused
1854 int nvcell; // fcell; // unused
1855 if (IsLastCell(cell)) {
1856 os << newlineAndDepth(--depth)
1858 << newlineAndDepth(--depth)
1860 << newlineAndDepth(--depth)
1862 << newlineAndDepth(--depth);
1863 if (is_long_tabular)
1867 << newlineAndDepth(--depth);
1873 if (is_long_tabular)
1879 << "' COLSEP='1' ROWSEP='1'>"
1880 << newlineAndDepth(++depth);
1882 for (i = 0; i < columns_; ++i) {
1883 os << "<COLSPEC ALIGN='"
1884 << GetDocBookAlign(i, true)
1890 if (i == (columns_-1)) {
1893 if (column_info[i].right_line ||
1894 column_info[i+1].left_line)
1900 << newlineAndDepth(depth);
1902 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1903 if (column_info[i].left_line)
1908 << newlineAndDepth(++depth)
1910 << newlineAndDepth(++depth)
1912 << GetDocBookAlign(0)
1914 if (IsMultiColumn(0)) {
1915 os << " NAMEST='col1' NAMEEND='col"
1916 << cells_in_multicolumn(0)
1920 << newlineAndDepth(++depth);
1923 if (IsLastCellInRow(cell)) {
1924 os << newlineAndDepth(--depth)
1926 << newlineAndDepth(--depth)
1928 << newlineAndDepth(depth)
1930 << newlineAndDepth(++depth)
1932 << GetDocBookAlign(cell + 1)
1933 << "' VALIGN='middle'";
1934 if (IsMultiColumn(cell + 1)) {
1935 os << " NAMEST='col"
1936 << column_of_cell(cell+1) + 1
1938 << column_of_cell(cell + 1) +
1939 cells_in_multicolumn(cell + 1)
1943 << newlineAndDepth(++depth);
1946 os << newlineAndDepth(--depth)
1948 << newlineAndDepth(depth)
1950 << GetDocBookAlign(cell + 1)
1951 << "' VALIGN='middle'";
1952 if (IsMultiColumn(cell + 1)) {
1953 os << " NAMEST='col"
1954 << column_of_cell(cell+1) + 1
1956 << column_of_cell(cell+1) +
1957 cells_in_multicolumn(cell+1)
1961 << newlineAndDepth(++depth);
1970 bool LyXTabular::IsMultiColumn(int cell) const
1972 return (cellinfo_of_cell(cell)->multicolumn != LyXTabular::CELL_NORMAL);
1976 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1978 int row = row_of_cell(cell);
1979 int column = column_of_cell(cell);
1980 return &cell_info[row][column];
1984 void LyXTabular::SetMultiColumn(int cell, int number)
1986 int new_width = cellinfo_of_cell(cell)->width_of_cell;
1988 cellinfo_of_cell(cell)->multicolumn = LyXTabular::CELL_BEGIN_OF_MULTICOLUMN;
1989 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1990 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1991 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1992 for (number--; number > 0; --number) {
1993 cellinfo_of_cell(cell+number)->multicolumn =
1994 LyXTabular::CELL_PART_OF_MULTICOLUMN;
1995 new_width += cellinfo_of_cell(cell+number)->width_of_cell;
1997 set_row_column_number_info();
1998 SetWidthOfCell(cell, new_width);
1999 if (GetPWidth(cell).empty())
2000 GetCellInset(cell)->SetAutoBreakRows(false);
2004 int LyXTabular::cells_in_multicolumn(int cell) const
2006 int row = row_of_cell(cell);
2007 int column = column_of_cell(cell);
2010 while (column < columns_ && cell_info[row][column].multicolumn
2011 == LyXTabular::CELL_PART_OF_MULTICOLUMN){
2019 int LyXTabular::UnsetMultiColumn(int cell)
2021 int row = row_of_cell(cell);
2022 int column = column_of_cell(cell);
2026 if (cell_info[row][column].multicolumn
2027 == LyXTabular::CELL_BEGIN_OF_MULTICOLUMN){
2028 cell_info[row][column].multicolumn = LyXTabular::CELL_NORMAL;
2030 while (column < columns_ &&
2031 cell_info[row][column].multicolumn
2032 == LyXTabular::CELL_PART_OF_MULTICOLUMN){
2033 cell_info[row][column].multicolumn =
2034 LyXTabular::CELL_NORMAL;
2039 set_row_column_number_info();
2040 if (GetPWidth(cell).empty())
2041 GetCellInset(cell)->SetAutoBreakRows(false);
2046 void LyXTabular::SetLongTabular(int what)
2048 is_long_tabular = what;
2052 bool LyXTabular::IsLongTabular() const
2054 return is_long_tabular;
2058 void LyXTabular::SetRotateTabular(int what)
2064 bool LyXTabular::GetRotateTabular() const
2070 void LyXTabular::SetRotateCell(int cell, int what)
2072 cellinfo_of_cell(cell)->rotate = what;
2076 bool LyXTabular::GetRotateCell(int cell) const
2078 return cellinfo_of_cell(cell)->rotate;
2082 bool LyXTabular::NeedRotating() const
2086 for (int i = 0; i < rows_; ++i) {
2087 for (int j = 0; j < columns_; ++j) {
2088 if (cell_info[i][j].rotate)
2096 bool LyXTabular::IsLastCell(int cell) const
2098 if (cell < GetNumberOfCells())
2104 int LyXTabular::GetCellAbove(int cell) const
2106 if (row_of_cell(cell) > 0)
2107 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
2112 int LyXTabular::GetCellNumber(int row, int column) const
2114 if (column >= columns_)
2115 column = columns_ - 1;
2116 else if (column < 0)
2123 return cell_info[row][column].cellno;
2127 void LyXTabular::SetLinebreaks(int cell, bool what)
2129 cellinfo_of_cell(cell)->linebreaks = what;
2133 bool LyXTabular::GetLinebreaks(int cell) const
2135 if (column_info[column_of_cell(cell)].p_width.empty() &&
2136 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
2138 return cellinfo_of_cell(cell)->linebreaks;
2142 void LyXTabular::SetLTHead(int cell, bool first)
2144 int row = row_of_cell(cell);
2147 if (row == endfirsthead)
2160 bool LyXTabular::GetRowOfLTHead(int cell) const
2162 if ((endhead+1) > rows_)
2164 return (row_of_cell(cell) == endhead);
2168 bool LyXTabular::GetRowOfLTFirstHead(int cell) const
2170 if ((endfirsthead+1) > rows_)
2172 return (row_of_cell(cell) == endfirsthead);
2176 void LyXTabular::SetLTFoot(int cell, bool last)
2178 int row = row_of_cell(cell);
2181 if (row == endlastfoot)
2194 bool LyXTabular::GetRowOfLTFoot(int cell) const
2196 if ((endfoot+1) > rows_)
2198 return (row_of_cell(cell) == endfoot);
2201 bool LyXTabular::GetRowOfLTLastFoot(int cell) const
2203 if ((endlastfoot+1) > rows_)
2205 return (row_of_cell(cell) == endlastfoot);
2209 void LyXTabular::SetLTNewPage(int cell, bool what)
2211 row_info[row_of_cell(cell)].newpage = what;
2215 bool LyXTabular::GetLTNewPage(int cell) const
2217 return row_info[row_of_cell(cell)].newpage;
2221 void LyXTabular::SetAscentOfRow(int row, int height)
2225 row_info[row].ascent_of_row = height;
2229 void LyXTabular::SetDescentOfRow(int row, int height)
2233 row_info[row].descent_of_row = height;
2237 int LyXTabular::GetAscentOfRow(int row) const
2241 return row_info[row].ascent_of_row;
2245 int LyXTabular::GetDescentOfRow(int row) const
2249 return row_info[row].descent_of_row;
2253 int LyXTabular::GetHeightOfTabular() const
2257 for(int row = 0; row < rows_; ++row)
2258 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
2259 GetAdditionalHeight(GetCellNumber(row, 0));
2264 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
2266 if ((row >= rows_) || (column >= columns_))
2268 return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
2272 int LyXTabular::TeXTopHLine(ostream & os, int row) const
2274 int fcell = GetFirstCellInRow(row);
2275 int n = NumberOfCellsInRow(fcell) + fcell;
2279 for (i = fcell; i < n; ++i) {
2283 if (tmp == (n - fcell)){
2286 for (i = fcell; i < n; ++i) {
2289 << column_of_cell(i) + 1
2291 << right_column_of_cell(i) + 1
2304 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
2306 int fcell = GetFirstCellInRow(row);
2307 int n = NumberOfCellsInRow(fcell) + fcell;
2311 for (i = fcell; i < n; ++i) {
2315 if (tmp == (n-fcell)){
2318 for (i = fcell; i < n; ++i) {
2319 if (BottomLine(i)) {
2321 << column_of_cell(i) + 1
2323 << right_column_of_cell(i) + 1
2336 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
2340 if (GetRotateCell(cell)) {
2341 os << "\\begin{sideways}" << endl;
2344 if (IsMultiColumn(cell)) {
2345 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
2346 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
2347 os << cellinfo_of_cell(cell+1)->align_special << "}{";
2351 if (!GetPWidth(cell).empty()) {
2352 os << "p{" << GetPWidth(cell) << '}';
2354 switch (GetAlignment(cell)) {
2355 case LYX_ALIGN_LEFT:
2358 case LYX_ALIGN_RIGHT:
2366 if (RightLine(cell))
2368 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
2374 if (GetLinebreaks(cell)) {
2375 os << "\\parbox[t]{" << GetPWidth(cell) << "}{\\smallskip{}";
2381 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
2386 if (GetLinebreaks(cell))
2387 os << "\\smallskip{}}";
2388 if (IsMultiColumn(cell)){
2391 if (GetRotateCell(cell)) {
2392 os << endl << "\\end{sideways}";
2399 int LyXTabular::Latex(ostream & os, bool fragile, bool fp) const
2405 //+---------------------------------------------------------------------
2406 //+ first the opening preamble +
2407 //+---------------------------------------------------------------------
2410 os << "\\begin{sideways}" << endl;
2413 if (is_long_tabular)
2414 os << "\\begin{longtable}{";
2416 os << "\\begin{tabular}{";
2417 for (i = 0; i < columns_; ++i) {
2418 if (column_info[i].left_line)
2420 if (!column_info[i].align_special.empty()) {
2421 os << column_info[i].align_special;
2422 } else if (!column_info[i].p_width.empty()) {
2424 << column_info[i].p_width
2427 switch (column_info[i].alignment) {
2428 case LYX_ALIGN_LEFT:
2431 case LYX_ALIGN_RIGHT:
2439 if (column_info[i].right_line)
2445 //+---------------------------------------------------------------------
2446 //+ the single row and columns (cells) +
2447 //+---------------------------------------------------------------------
2449 for(i=0; i < rows_; ++i) {
2450 ret += TeXTopHLine(os, i);
2451 for(j=0; j < columns_; ++j) {
2452 if (IsPartOfMultiColumn(i,j))
2454 ret += TeXCellPreamble(os, cell);
2455 ret += GetCellInset(cell)->Latex(os, fragile, fp);
2456 ret += TeXCellPostamble(os, cell);
2457 if (!IsLastCellInRow(cell)) { // not last cell in row
2463 os << "\\\\" << endl;
2464 ret += TeXBottomHLine(os, i);
2465 if (IsLongTabular()) {
2467 os << "\\endhead\n";
2470 if (i == endfirsthead) {
2471 os << "\\endfirsthead\n";
2475 os << "\\endfoot\n";
2478 if (i == endlastfoot) {
2479 os << "\\endlastfoot\n";
2482 if (row_info[i].newpage) {
2483 os << "\\newpage\n";
2489 //+---------------------------------------------------------------------
2490 //+ the closing of the tabular +
2491 //+---------------------------------------------------------------------
2493 if (is_long_tabular)
2494 os << "\\end{longtable}";
2496 os << "\\end{tabular}";
2498 os << "\n\\end{sideways}";
2506 InsetText * LyXTabular::GetCellInset(int cell) const
2508 return cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;