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"
25 #include "support/lstrings.h"
26 #include "support/lyxmanip.h"
27 #include "insets/insettabular.h"
28 #include "insets/insettext.h"
37 static int const WIDTH_OF_LINE = 5;
39 /// Define a few methods for the inner structs
41 LyXTabular::cellstruct::cellstruct()
43 cellno = 0; //should be initilaized correctly later.
45 multicolumn = LyXTabular::CELL_NORMAL;
46 alignment = LYX_ALIGN_CENTER;
55 LyXTabular::cellstruct::~cellstruct()
61 LyXTabular::cellstruct::cellstruct(cellstruct const & cs)
64 width_of_cell = cs.width_of_cell;
65 multicolumn = cs.multicolumn;
66 alignment = cs.alignment;
67 top_line = cs.top_line;
68 bottom_line = cs.bottom_line;
70 linebreaks = cs.linebreaks;
75 LyXTabular::cellstruct &
76 LyXTabular::cellstruct::operator=(cellstruct const & cs)
79 width_of_cell = cs.width_of_cell;
80 multicolumn = cs.multicolumn;
81 alignment = cs.alignment;
82 top_line = cs.top_line;
83 bottom_line = cs.bottom_line;
85 linebreaks = cs.linebreaks;
90 LyXTabular::rowstruct::rowstruct()
100 LyXTabular::columnstruct::columnstruct()
104 alignment = LYX_ALIGN_CENTER;
110 LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg)
113 Init(rows_arg, columns_arg);
117 LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt)
120 Init(lt.rows_, lt.columns_);
126 LyXTabular::LyXTabular(InsetTabular * inset, LyXLex & lex)
133 LyXTabular::~LyXTabular()
136 delete[] columnofcell;
140 LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
142 // If this and lt is not of the same size we have a serious bug
143 // So then it is ok to throw an exception, or for now
145 Assert(rows_ == lt.rows_ && columns_ == lt.columns_);
147 cell_info = lt.cell_info;
148 row_info = lt.row_info;
149 column_info = lt.column_info;
151 // long tabular stuff
152 SetLongTabular(lt.is_long_tabular);
153 endhead = lt.endhead;
154 endfoot = lt.endfoot;
155 endfirsthead = lt.endfirsthead;
156 endlastfoot = lt.endlastfoot;
166 LyXTabular * LyXTabular::Clone(InsetTabular * inset)
168 LyXTabular * result = new LyXTabular(inset, *this);
170 // don't know if this is good but I need to Clone also
171 // the text-insets here, this is for the Undo-facility!
174 for(i=0; i < rows_; ++i) {
175 for(j=0; j < columns_; ++j) {
176 delete result->cell_info[i][j].inset;
177 result->cell_info[i][j].inset=new InsetText(*cell_info[i][j].inset,
178 inset->BufferOwner());
179 result->cell_info[i][j].inset->setOwner(inset);
186 /* activates all lines and sets all widths to 0 */
187 void LyXTabular::Init(int rows_arg, int columns_arg)
193 columns_ = columns_arg;
194 row_info = vector<rowstruct>(rows_, rowstruct());
195 column_info = vector<columnstruct>(columns_, columnstruct());
196 cell_info = vector<vector<cellstruct> >
197 (rows_, vector<cellstruct>(columns_, cellstruct()));
199 // Jürgen, use iterators.
200 for (i = 0; i < rows_; ++i) {
201 for (j = 0; j < columns_; ++j) {
202 cell_info[i][j].inset = new InsetText(owner_->BufferOwner());
203 cell_info[i][j].inset->setOwner(owner_);
204 cell_info[i][j].inset->SetDrawLockedFrame(true);
205 cell_info[i][j].cellno = cellno++;
208 row_info[i-1].bottom_line = true;
209 row_info[0].bottom_line = true;
211 for (i = 0; i < columns_; ++i) {
212 calculate_width_of_column(i);
214 column_info[columns_-1].right_line = true;
216 calculate_width_of_tabular();
220 set_row_column_number_info();
221 is_long_tabular = false;
230 void LyXTabular::AppendRow(int /* cell */)
233 int row = row_of_cell(cell);
234 rowstruct * row_info2 = new rowstruct[rows_ + 1];
235 cellstruct ** cell_info2 = new cellstruct * [rows_ + 1];
238 for (i = 0; i <= row; ++i) {
239 cell_info2[i] = cell_info[i];
240 row_info2[i] = row_info[i];
242 for (i = rows_ - 1; i >= row; --i) {
243 cell_info2[i + 1] = cell_info[i];
244 row_info2[i + 1] = row_info[i];
246 row_info2[row + 1].top_line = row_info[i].top_line;
247 cell_info2[row + 1] = new cellstruct[columns_](owner_->BufferOwner());
248 for (i = 0; i < columns_; ++i) {
249 cell_info2[row + 1][i].width_of_cell = 0;
250 cell_info2[row + 1][i] = cell_info2[row][i];
254 cell_info = cell_info2;
256 row_info = row_info2;
265 void LyXTabular::DeleteRow(int /*cell*/)
268 int row = row_of_cell(cell);
269 rowstruct * row_info2 = new rowstruct[rows_ - 1];
270 cellstruct ** cell_info2 = new cellstruct * [rows_ - 1];
272 delete[] cell_info[row];
274 for (; i < row; ++i) {
275 cell_info2[i] = cell_info[i];
276 row_info2[i] = row_info[i];
278 for (i = row; i < rows_ - 1; ++i) {
279 cell_info2[i] = cell_info[i + 1];
280 row_info2[i] = row_info[i + 1];
284 cell_info = cell_info2;
286 row_info = row_info2;
295 void LyXTabular::AppendColumn(int /*cell*/)
299 columnstruct * column_info2 = new columnstruct[columns_ + 1];
300 int column = right_column_of_cell(cell);
303 for (; i <= column; ++i) {
304 column_info2[i] = column_info[i];
306 for (i = columns_ - 1; i >= column; --i) {
307 column_info2[i + 1] = column_info[i];
310 delete[] column_info;
311 column_info = column_info2;
313 for (i = 0; i < rows_; ++i) {
314 cellstruct * tmp = cell_info[i];
315 cell_info[i] = new cellstruct[columns_ + 1](owner_->BufferOwner());
316 for (j = 0; j <= column; ++j) {
317 cell_info[i][j] = tmp[j];
319 for (j = column; j < columns_; ++j) {
320 cell_info[i][j + 1] = tmp[j];
322 // care about multicolumns
323 if (cell_info[i][column + 1].multicolumn
324 == LyXTabular::CELL_BEGIN_OF_MULTICOLUMN){
325 cell_info[i][column + 1].multicolumn =
326 LyXTabular::CELL_PART_OF_MULTICOLUMN;
328 if (column + 1 == columns_
329 || cell_info[i][column + 2].multicolumn
330 != LyXTabular::CELL_PART_OF_MULTICOLUMN){
331 cell_info[i][column + 1].multicolumn =
332 LyXTabular::CELL_NORMAL;
343 void LyXTabular::DeleteColumn(int /*cell*/)
346 int column1 = column_of_cell(cell);
347 int column2 = right_column_of_cell(cell);
349 if (column1 == 0 && column2 == columns_ - 1)
352 for (int column = column1; column <= column2; ++column) {
353 delete_column(column1);
360 void LyXTabular::delete_column(int /*column*/)
364 columnstruct * column_info2 = new columnstruct[columns_-1];
366 for (i = 0; i < column; ++i) {
367 column_info2[i] = column_info[i];
369 for (i = column; i < columns_ - 1; ++i) {
370 column_info2[i] = column_info[i + 1];
373 delete[] column_info;
374 column_info = column_info2;
376 for (i = 0; i < rows_; ++i) {
377 cellstruct * tmp = cell_info[i];
378 cell_info[i] = new cellstruct[columns_ - 1](owner_->BufferOwner());
379 for (j = 0; j < column; ++j) {
380 cell_info[i][j] = tmp[j];
382 for (j = column; j < columns_ - 1; ++j) {
383 cell_info[i][j] = tmp[j + 1];
394 void LyXTabular::Reinit()
400 // Jürgen, use iterators.
401 for (; i < rows_; ++i) {
402 for (j = 0; j < columns_; ++j) {
403 cell_info[i][j].width_of_cell = 0;
407 for (i = 0; i < columns_; ++i) {
408 calculate_width_of_column(i);
410 calculate_width_of_tabular();
412 set_row_column_number_info();
416 void LyXTabular::set_row_column_number_info()
422 for (; row < rows_; ++row) {
423 for (column = 0; column<columns_; ++column) {
424 if (cell_info[row][column].multicolumn
425 != LyXTabular::CELL_PART_OF_MULTICOLUMN)
427 cell_info[row][column].cellno = numberofcells;
430 ++numberofcells; // because this is one more than as we start from 0
435 rowofcell = new int[numberofcells];
436 delete [] columnofcell;
437 columnofcell = new int[numberofcells];
439 while (c < numberofcells && row < rows_ && column < columns_) {
441 columnofcell[c] = column;
445 } while (column < columns_ &&
446 cell_info[row][column].multicolumn
447 == LyXTabular::CELL_PART_OF_MULTICOLUMN);
448 if (column == columns_) {
456 int LyXTabular::GetNumberOfCells() const
458 return numberofcells;
462 int LyXTabular::NumberOfCellsInRow(int cell) const
464 int row = row_of_cell(cell);
466 for (int i = 0; i < columns_; ++i) {
467 if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
474 int LyXTabular::AppendCellAfterCell(int append_cell, int question_cell)
476 return (right_column_of_cell(append_cell) ==
477 right_column_of_cell(question_cell));
481 int LyXTabular::DeleteCellIfColumnIsDeleted(int cell, int delete_column_cell)
483 if (column_of_cell(delete_column_cell) == 0 &&
484 right_column_of_cell(delete_column_cell) == columns_ - 1)
488 (column_of_cell(cell) >= column_of_cell(delete_column_cell) &&
489 column_of_cell(cell) <= right_column_of_cell(delete_column_cell));
493 /* returns 1 if there is a topline, returns 0 if not */
494 bool LyXTabular::TopLine(int cell) const
496 int row = row_of_cell(cell);
498 if (IsMultiColumn(cell))
499 return cellinfo_of_cell(cell)->top_line;
500 return row_info[row].top_line;
504 bool LyXTabular::BottomLine(int cell) const
506 //no bottom line underneath non-existent cells if you please
507 if(cell >= numberofcells)
510 if (IsMultiColumn(cell))
511 return cellinfo_of_cell(cell)->bottom_line;
512 return row_info[row_of_cell(cell)].bottom_line;
516 bool LyXTabular::LeftLine(int cell) const
518 return column_info[column_of_cell(cell)].left_line;
522 bool LyXTabular::RightLine(int cell) const
524 return column_info[right_column_of_cell(cell)].right_line;
528 bool LyXTabular::TopAlreadyDrawed(int cell) const
530 if (GetAdditionalHeight(cell))
532 int row = row_of_cell(cell);
534 int column = column_of_cell(cell);
537 && cell_info[row][column].multicolumn
538 == LyXTabular::CELL_PART_OF_MULTICOLUMN)
540 if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL)
541 return row_info[row].bottom_line;
543 return cell_info[row][column].bottom_line;
549 bool LyXTabular::LeftAlreadyDrawed(int cell) const
551 int column = column_of_cell(cell);
553 int row = row_of_cell(cell);
555 (cell_info[row][column].multicolumn ==
556 LyXTabular::CELL_PART_OF_MULTICOLUMN));
557 if (GetAdditionalWidth(cell_info[row][column].cellno))
559 return column_info[column].right_line;
565 bool LyXTabular::IsLastRow(int cell) const
567 return (row_of_cell(cell) == rows_ - 1);
571 int LyXTabular::GetAdditionalHeight(int cell) const
573 int row = row_of_cell(cell);
576 int top = 1; // bool top = true; ??
577 int bottom = 1; // bool bottom = true; ??
580 for (column = 0; column < columns_ - 1 && bottom; ++column) {
581 switch (cell_info[row - 1][column].multicolumn) {
582 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
583 bottom = cell_info[row - 1][column].bottom_line;
585 case LyXTabular::CELL_NORMAL:
586 bottom = row_info[row - 1].bottom_line;
589 for (column = 0; column < columns_ - 1 && top; ++column) {
590 switch (cell_info[row][column].multicolumn){
591 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
592 top = cell_info[row][column].top_line;
594 case LyXTabular::CELL_NORMAL:
595 top = row_info[row].top_line;
599 return WIDTH_OF_LINE;
604 int LyXTabular::GetAdditionalWidth(int cell) const
606 // internally already set in SetWidthOfCell
607 // used to get it back in text.C
608 int col = right_column_of_cell(cell);
609 if (col < columns_ - 1 && column_info[col].right_line &&
610 column_info[col+1].left_line)
611 return WIDTH_OF_LINE;
617 // returns the maximum over all rows
618 int LyXTabular::GetWidthOfColumn(int cell) const
620 int column1 = column_of_cell(cell);
621 int column2 = right_column_of_cell(cell);
624 for (; i <= column2; ++i) {
625 result += column_info[i].width_of_column;
631 int LyXTabular::GetWidthOfTabular() const
633 return width_of_tabular;
637 /* returns 1 if a complete update is necessary, otherwise 0 */
638 bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
640 if (!IsMultiColumn(cell))
643 int row = row_of_cell(cell);
644 int column1 = column_of_cell(cell);
645 int column2 = right_column_of_cell(cell);
647 // first set columns to 0 so we can calculate the right width
649 for (; i <= column2; ++i) {
650 cell_info[row][i].width_of_cell = 0;
652 // set the width to MAX_WIDTH until width > 0
653 int width = (new_width + 2 * WIDTH_OF_LINE);
654 for (i = column1; (i < column2) && (width > 0); ++i) {
655 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
656 width -= column_info[i].width_of_column;
659 cell_info[row][i].width_of_cell = width;
665 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
667 int row = row_of_cell(cell);
668 int column1 = column_of_cell(cell);
669 int column2 = right_column_of_cell(cell);
671 // first set columns to 0 so we can calculate the right width
673 for (; i <= column2; ++i)
674 cell_info[row][i].width_of_cell = 0;
675 for(i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
677 if (i < numberofcells)
678 recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
679 SetWidthOfMulticolCell(cell, new_width);
683 /* returns 1 if a complete update is necessary, otherwise 0 */
684 bool LyXTabular::SetWidthOfCell(int cell, int new_width)
686 int row = row_of_cell(cell);
687 int column1 = column_of_cell(cell);
691 if (IsMultiColumn(cell)) {
692 tmp = SetWidthOfMulticolCell(cell, new_width);
694 width = (new_width + 2*WIDTH_OF_LINE);
695 cell_info[row][column1].width_of_cell = width;
696 if (column_info[column1].right_line && (column1 < columns_-1) &&
697 column_info[column1+1].left_line) // additional width
698 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
699 tmp = calculate_width_of_column_NMC(column1);
703 for(i = 0; i<columns_;++i)
704 calculate_width_of_column_NMC(i);
705 for(i = 0; (i<numberofcells) && !IsMultiColumn(i); ++i)
708 recalculateMulticolCells(i, GetWidthOfCell(i)-(2*WIDTH_OF_LINE));
709 for(i = 0; i<columns_;++i)
710 calculate_width_of_column(i);
711 calculate_width_of_tabular();
718 bool LyXTabular::SetAlignment(int cell, char align)
720 if (!IsMultiColumn(cell))
721 column_info[column_of_cell(cell)].alignment = align;
722 cellinfo_of_cell(cell)->alignment = align;
727 bool LyXTabular::SetPWidth(int cell, string width)
729 bool flag = !width.empty();
731 if (IsMultiColumn(cell)) {
732 cellinfo_of_cell(cell)->p_width = width;
733 GetCellInset(cell)->SetAutoBreakRows(flag);
735 int j = column_of_cell(cell);
737 column_info[j].p_width = width;
738 if (flag) // do this only if there is a width
739 SetAlignment(cell, LYX_ALIGN_LEFT);
740 for(int i=0; i < rows_; ++i) {
741 c = GetCellNumber(i, j);
742 flag = !GetPWidth(c).empty(); // because of multicolumns!
743 GetCellInset(c)->SetAutoBreakRows(flag);
750 bool LyXTabular::SetAlignSpecial(int cell, string special, int what)
752 if (what == SET_SPECIAL_MULTI)
753 cellinfo_of_cell(cell)->align_special = special;
755 column_info[column_of_cell(cell)].align_special = special;
760 bool LyXTabular::SetAllLines(int cell, bool line)
762 SetTopLine(cell, line);
763 SetBottomLine(cell, line);
764 SetRightLine(cell, line);
765 SetLeftLine(cell, line);
770 bool LyXTabular::SetTopLine(int cell, bool line)
772 int row = row_of_cell(cell);
774 if (!IsMultiColumn(cell))
775 row_info[row].top_line = line;
777 cellinfo_of_cell(cell)->top_line = line;
782 bool LyXTabular::SetBottomLine(int cell, bool line)
784 if (!IsMultiColumn(cell))
785 row_info[row_of_cell(cell)].bottom_line = line;
787 cellinfo_of_cell(cell)->bottom_line = line;
792 bool LyXTabular::SetLeftLine(int cell, bool line)
794 column_info[column_of_cell(cell)].left_line = line;
799 bool LyXTabular::SetRightLine(int cell, bool line)
801 column_info[right_column_of_cell(cell)].right_line = line;
806 char LyXTabular::GetAlignment(int cell) const
808 if (IsMultiColumn(cell))
809 return cellinfo_of_cell(cell)->alignment;
811 return column_info[column_of_cell(cell)].alignment;
815 string LyXTabular::GetPWidth(int cell) const
817 if (IsMultiColumn(cell))
818 return cellinfo_of_cell(cell)->p_width;
819 return column_info[column_of_cell(cell)].p_width;
823 string LyXTabular::GetAlignSpecial(int cell, int what) const
825 if (what == SET_SPECIAL_MULTI)
826 return cellinfo_of_cell(cell)->align_special;
827 return column_info[column_of_cell(cell)].align_special;
831 int LyXTabular::GetWidthOfCell(int cell) const
833 int row = row_of_cell(cell);
834 int column1 = column_of_cell(cell);
835 int column2 = right_column_of_cell(cell);
838 for (; i <= column2; ++i) {
839 result += cell_info[row][i].width_of_cell;
842 // result += GetAdditionalWidth(cell);
847 int LyXTabular::GetBeginningOfTextInCell(int cell) const
851 switch (GetAlignment(cell)){
852 case LYX_ALIGN_CENTER:
853 x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
855 case LYX_ALIGN_RIGHT:
856 x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
857 // + GetAdditionalWidth(cell);
859 default: /* LYX_ALIGN_LEFT: nothing :-) */
869 bool LyXTabular::IsFirstCellInRow(int cell) const
871 return (column_of_cell(cell) == 0);
875 int LyXTabular::GetFirstCellInRow(int row) const
879 return cell_info[row][0].cellno;
882 bool LyXTabular::IsLastCellInRow(int cell) const
884 return (right_column_of_cell(cell) == (columns_ - 1));
888 int LyXTabular::GetLastCellInRow(int row) const
892 return cell_info[row][columns_-1].cellno;
896 bool LyXTabular::calculate_width_of_column(int column)
898 int old_column_width = column_info[column].width_of_column;
901 for (int i = 0; i < rows_; ++i) {
902 maximum = max(cell_info[i][column].width_of_cell, maximum);
904 column_info[column].width_of_column = maximum;
905 return (column_info[column].width_of_column != old_column_width);
909 bool LyXTabular::calculate_width_of_column_NMC(int column)
911 int old_column_width = column_info[column].width_of_column;
913 for (int i = 0; i < rows_; ++i) {
914 if (!IsMultiColumn(GetCellNumber(i, column)) &&
915 (cell_info[i][column].width_of_cell > max)) {
916 max = cell_info[i][column].width_of_cell;
919 column_info[column].width_of_column = max;
920 return (column_info[column].width_of_column != old_column_width);
924 void LyXTabular::calculate_width_of_tabular()
926 width_of_tabular = 0;
927 for (int i = 0; i < columns_; ++i) {
928 width_of_tabular += column_info[i].width_of_column;
933 int LyXTabular::row_of_cell(int cell) const
935 if (cell >= numberofcells)
939 return rowofcell[cell];
943 int LyXTabular::column_of_cell(int cell) const
945 if (cell >= numberofcells)
949 return columnofcell[cell];
953 int LyXTabular::right_column_of_cell(int cell) const
955 int row = row_of_cell(cell);
956 int column = column_of_cell(cell);
957 while (column < (columns_ - 1) &&
958 cell_info[row][column+1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
964 void LyXTabular::Write(ostream & os) const
969 os << "<LyXTabular version=1 rows=" << rows_ << " columns=" << columns_ <<
971 // global longtable options
972 os << "<Features rotate=" << rotate <<
973 " islongtable=" << is_long_tabular <<
974 " endhead=" << endhead << " endfirsthead=" << endfirsthead <<
975 " endfoot=" << endfoot << " endlastfoot=" << endlastfoot <<
977 for (i = 0; i < rows_; ++i) {
978 os << "<Row topline=" << row_info[i].top_line <<
979 " bottomline=" << row_info[i].bottom_line <<
980 " newpage=" << row_info[i].newpage <<
982 for (j = 0; j < columns_; ++j) {
984 os << "<Column alignment=" << column_info[j].alignment <<
985 " leftline=" << column_info[j].left_line <<
986 " rightline=" << column_info[j].right_line <<
987 " width=\"" << VSpace(column_info[j].p_width).asLyXCommand() <<
988 "\" special=\"" << column_info[j].align_special <<
991 os << "<Column>" << endl;
993 os << "<Cell multicolumn=" << cell_info[i][j].multicolumn <<
994 " alignment=" << cell_info[i][j].alignment <<
995 " topline=" << cell_info[i][j].top_line <<
996 " bottomline=" << cell_info[i][j].bottom_line <<
997 " rotate=" << cell_info[i][j].rotate <<
998 " linebreaks=" << cell_info[i][j].linebreaks <<
999 " width=\"" << cell_info[i][j].p_width <<
1000 "\" special=\"" << cell_info[i][j].align_special <<
1002 os << "\\begin_inset ";
1003 cell_info[i][j].inset->Write(os);
1004 os << "\n\\end_inset " << endl;
1005 os << "</Cell>" << endl;
1006 os << "</Column>" << endl;
1008 os << "</Row>" << endl;
1010 os << "</LyXTabular>" << endl;
1015 bool getTokenValue(string const str, const char * token, string & ret)
1017 int pos = str.find(token);
1018 char ch = str[pos+strlen(token)];
1020 if ((pos < 0) || (ch != '='))
1023 pos += strlen(token)+1;
1025 if ((ch != '"') && (ch != '\'')) { // only read till next space
1029 while((pos < int(str.length()-1)) && (str[++pos] != ch))
1037 bool getTokenValue(string const str, const char * token, int & num)
1040 int pos = str.find(token);
1041 char ch = str[pos+strlen(token)];
1043 if ((pos < 0) || (ch != '='))
1046 pos += strlen(token)+1;
1048 if ((ch != '"') && (ch != '\'')) { // only read till next space
1054 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1057 num = strToInt(ret);
1063 bool getTokenValue(string const str, const char * token, bool & flag)
1066 int pos = str.find(token);
1067 char ch = str[pos+strlen(token)];
1069 if ((pos < 0) || (ch != '='))
1072 pos += strlen(token)+1;
1074 if ((ch != '"') && (ch != '\'')) { // only read till next space
1080 while((pos < int(str.length()-1)) && isdigit(str[pos]))
1083 flag = strToInt(ret);
1088 void l_getline(istream & is, string & str)
1096 void LyXTabular::Read(LyXLex & lex)
1099 istream & is = lex.getStream();
1101 l_getline(is, line);
1102 if (!prefixIs(line, "<LyXTabular ")) {
1103 OldFormatRead(is, line);
1110 if (!getTokenValue(line, "version", version))
1112 if (!getTokenValue(line, "rows", rows_arg))
1114 if (!getTokenValue(line, "columns", columns_arg))
1116 Init(rows_arg, columns_arg);
1117 l_getline(is, line);
1118 if (!prefixIs(line, "<Features ")) {
1119 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
1120 line << ")" << endl;
1123 (void)getTokenValue(line, "islongtable", is_long_tabular);
1124 (void)getTokenValue(line, "endhead", endhead);
1125 (void)getTokenValue(line, "endfirsthead", endfirsthead);
1126 (void)getTokenValue(line, "endfoot", endfoot);
1127 (void)getTokenValue(line, "endlastfoot", endlastfoot);
1129 for(i = 0; i < rows_; ++i) {
1130 l_getline(is, line);
1131 if (!prefixIs(line, "<Row ")) {
1132 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
1133 line << ")" << endl;
1136 (void)getTokenValue(line, "topline", row_info[i].top_line);
1137 (void)getTokenValue(line, "bottomline", row_info[i].bottom_line);
1138 (void)getTokenValue(line, "newpage", row_info[i].newpage);
1139 for (j = 0; j < columns_; ++j) {
1141 if (!prefixIs(line,"<Column")) {
1142 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
1143 line << ")" << endl;
1147 (void)getTokenValue(line, "alignment", column_info[j].alignment);
1148 (void)getTokenValue(line, "leftline", column_info[j].left_line);
1149 (void)getTokenValue(line, "rightline", column_info[j].right_line);
1150 (void)getTokenValue(line, "width", column_info[j].p_width);
1151 (void)getTokenValue(line, "special", column_info[j].align_special);
1153 l_getline(is, line);
1154 if (!prefixIs(line, "<Cell")) {
1155 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
1156 line << ")" << endl;
1159 (void)getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1160 (void)getTokenValue(line, "alignment", cell_info[i][j].alignment);
1161 (void)getTokenValue(line, "topline", cell_info[i][j].top_line);
1162 (void)getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1163 (void)getTokenValue(line, "rotate", cell_info[i][j].rotate);
1164 (void)getTokenValue(line, "linebreaks", cell_info[i][j].linebreaks);
1165 (void)getTokenValue(line, "width", cell_info[i][j].p_width);
1166 if (!(cell_info[i][j].p_width.empty() &&
1167 column_info[j].p_width.empty()))
1168 cell_info[i][j].inset->SetAutoBreakRows(true);
1169 (void)getTokenValue(line, "special", cell_info[i][j].align_special);
1170 l_getline(is, line);
1171 if (prefixIs(line, "\\begin_inset")) {
1172 cell_info[i][j].inset->Read(lex);
1173 l_getline(is, line);
1175 if (line != "</Cell>") {
1176 lyxerr << "Wrong tabular format (expected </Cell> got" <<
1177 line << ")" << endl;
1180 l_getline(is, line);
1181 if (line != "</Column>") {
1182 lyxerr << "Wrong tabular format (expected </Column> got" <<
1183 line << ")" << endl;
1187 l_getline(is, line);
1188 if (line != "</Row>") {
1189 lyxerr << "Wrong tabular format (expected </Row> got" <<
1190 line << ")" << endl;
1194 while (line != "</LyXTabular>") {
1195 l_getline(is, line);
1197 set_row_column_number_info();
1201 void LyXTabular::OldFormatRead(istream & is, string fl)
1206 int columns_arg = 0;
1207 int is_long_tabular_arg = false;
1208 int rotate_arg = false;
1221 version = atoi(s.c_str() + 8);
1225 lyxerr << "Tabular format < 5 is not supported anymore\n"
1226 "Get an older version of LyX (< 1.1.x) for conversion!"
1228 WriteAlert(_("Warning:"),
1229 _("Tabular format < 5 is not supported anymore\n"),
1230 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1232 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1233 >> rotate_arg >> a >> b >> c >> d;
1235 is >> rows_arg >> columns_arg;
1236 Init(rows_arg, columns_arg);
1237 SetLongTabular(is_long_tabular_arg);
1238 SetRotateTabular(rotate_arg);
1240 for (i = 0; i < rows_; ++i) {
1243 for (i = 0; i < columns_; ++i) {
1246 for (i = 0; i < rows_; ++i) {
1247 for (j = 0; j < columns_; ++j) {
1251 set_row_column_number_info();
1254 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1255 >> rotate_arg >> a >> b >> c >> d;
1256 Init(rows_arg, columns_arg);
1257 SetLongTabular(is_long_tabular_arg);
1258 SetRotateTabular(rotate_arg);
1263 for (i = 0; i < rows_; ++i) {
1264 a = b = c = d = e = f = g = h = 0;
1265 is >> a >> b >> c >> d;
1266 row_info[i].top_line = a;
1267 row_info[i].bottom_line = b;
1268 // row_info[i].is_cont_row = c;
1269 row_info[i].newpage = d;
1271 for (i = 0; i < columns_; ++i) {
1275 char ch; // skip '"'
1277 getline(is, s1, '"');
1278 is >> ch; // skip '"'
1279 getline(is, s2, '"');
1280 column_info[i].alignment = static_cast<char>(a);
1281 column_info[i].left_line = b;
1282 column_info[i].right_line = c;
1283 column_info[i].p_width = s1;
1284 column_info[i].align_special = s2;
1286 for (i = 0; i < rows_; ++i) {
1287 for (j = 0; j < columns_; ++j) {
1290 is >> a >> b >> c >> d >> e >> f >> g;
1292 is >> ch; // skip '"'
1293 getline(is, s1, '"');
1294 is >> ch; // skip '"'
1295 getline(is, s2, '"');
1296 cell_info[i][j].multicolumn = static_cast<char>(a);
1297 cell_info[i][j].alignment = static_cast<char>(b);
1298 cell_info[i][j].top_line = static_cast<char>(c);
1299 cell_info[i][j].bottom_line = static_cast<char>(d);
1300 // cell_info[i][j].has_cont_row = static_cast<bool>(e);
1301 cell_info[i][j].rotate = static_cast<bool>(f);
1302 cell_info[i][j].linebreaks = static_cast<bool>(g);
1303 cell_info[i][j].align_special = s1;
1304 cell_info[i][j].p_width = s2;
1307 set_row_column_number_info();
1312 // cell < 0 will tex the preamble
1313 // returns the number of printed newlines
1314 int LyXTabular::TexEndOfCell(ostream & os, int cell) const
1320 if (IsLastCell(cell)) {
1321 // the very end at the very beginning
1322 if (GetLinebreaks(cell))
1323 os << "\\smallskip{}}";
1324 if (IsMultiColumn(cell))
1326 if (GetRotateCell(cell)) {
1327 os << "\n\\end{sideways}";
1335 while (!IsFirstCellInRow(fcell)) --fcell;
1336 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1337 if (BottomLine(fcell + i))
1340 if (tmp == NumberOfCellsInRow(fcell)) {
1344 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1345 if (BottomLine(fcell + i)) {
1347 << column_of_cell(fcell + i) + 1
1349 << right_column_of_cell(fcell + i) + 1
1359 if (is_long_tabular)
1360 os << "\\end{longtable}";
1362 os << "\\end{tabular}";
1364 os << "\n\\end{sideways}";
1372 os << "\\begin{sideways}\n";
1375 if (is_long_tabular)
1376 os << "\\begin{longtable}{";
1378 os << "\\begin{tabular}{";
1379 for (i = 0; i < columns_; ++i) {
1380 if (column_info[i].left_line)
1382 if (!column_info[i].align_special.empty()) {
1383 os << column_info[i].align_special;
1384 } else if (!column_info[i].p_width.empty()) {
1386 << column_info[i].p_width
1389 switch (column_info[i].alignment) {
1390 case LYX_ALIGN_LEFT:
1393 case LYX_ALIGN_RIGHT:
1401 if (column_info[i].right_line)
1407 if (GetNumberOfCells()) {
1409 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1410 if (TopLine(fcell + i))
1413 if (tmp == NumberOfCellsInRow(fcell)){
1417 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1418 if (TopLine(fcell + i)) {
1420 << column_of_cell(fcell + i) + 1
1422 << right_column_of_cell(fcell + i) + 1
1433 if (GetRotateCell(0)) {
1434 os << "\\begin{sideways}\n";
1439 if (GetLinebreaks(cell))
1440 os << "\\smallskip{}}";
1441 if (IsMultiColumn(cell)){
1444 if (GetRotateCell(cell)) {
1445 os << "\n\\end{sideways}";
1448 if (IsLastCellInRow(cell)) {
1449 int row = row_of_cell(cell);
1450 string hline1, hline2;
1451 bool print_hline = true;
1452 bool flag1 = IsLongTabular() &&
1453 ((row == endhead) || (row == endfirsthead) ||
1454 (row == endfoot) || (row == endlastfoot));
1456 bool flag2 = IsLongTabular() &&
1457 ((row <= endhead) || (row <= endfirsthead) ||
1458 (row <= endfoot) || (row <= endlastfoot));
1460 // print the bottom hline only if (otherwise it is doubled):
1461 // - is no LongTabular
1462 // - there IS a first-header
1463 // - the next row is no special header/footer
1464 // & this row is no special header/footer
1465 // - the next row is a special header/footer
1466 // & this row is a special header/footer
1467 bool pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1468 (endfirsthead == endhead);
1473 while (!IsFirstCellInRow(fcell))
1475 for (i = 0; i < NumberOfCellsInRow(cell); ++i) {
1476 if (BottomLine(fcell + i))
1479 if (tmp == NumberOfCellsInRow(cell)){
1481 hline1 = "\\hline ";
1484 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1485 if (BottomLine(fcell + i)){
1487 << column_of_cell(fcell + i) + 1
1489 << right_column_of_cell(fcell + i) + 1
1491 hline1 += "\\cline{";
1492 hline1 += tostr(column_of_cell(fcell + i) + 1);
1494 hline1 += tostr(right_column_of_cell(fcell + i) + 1);
1504 if (IsLongTabular() && (row == endfoot)) {
1505 os << "\\endfoot\n";
1507 print_hline = false; // no double line below footer
1509 if (IsLongTabular() && (row == endlastfoot)) {
1510 os << "\\endlastfoot\n";
1512 print_hline = false; // no double line below footer
1514 if (IsLongTabular() && row_info[row].newpage) {
1515 os << "\\newpage\n";
1517 print_hline = false; // no line below a \\newpage-command
1520 if ((nvcell < numberofcells) &&
1521 (cell < GetNumberOfCells() - 1) && !IsLastCell(cell)) {
1523 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1524 if (TopLine(fcell + i))
1527 if (tmp == NumberOfCellsInRow(fcell)) {
1530 hline2 = "\\hline ";
1533 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1534 if (TopLine(fcell + i)) {
1537 << column_of_cell(fcell + i) + 1
1539 << right_column_of_cell(fcell + i) + 1
1542 hline2 += "\\cline{";
1543 hline2 += tostr(column_of_cell(fcell+i)+1);
1545 hline2 += tostr(right_column_of_cell(fcell+i)+1);
1551 if (tmp && print_hline){
1556 // the order here is important as if one defines two
1557 // or more things in one line only the first entry is
1558 // displayed the other are set to an empty-row. This
1559 // is important if I have a footer and want that the
1560 // lastfooter is NOT displayed!!!
1561 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1562 (row == endfoot) || (row == endlastfoot);
1565 bool sflag1 = IsLongTabular() && (row != endhead) &&
1566 (row != endfirsthead) &&
1567 ((row == endfoot) || (row == endlastfoot));
1569 if (IsLongTabular() && (row == endhead)) {
1570 os << "\\endhead\n";
1573 if (IsLongTabular() && (row == endfirsthead)) {
1574 os << "\\endfirsthead\n";
1577 if (sflag1) { // add the \hline for next foot row
1578 if (!hline1.empty()) {
1579 os << hline1 + '\n';
1583 // add the \hline for the first row
1584 if (pr_top_hline && sflag2) {
1585 if (!hline2.empty()) {
1586 os << hline2 + '\n';
1590 if (nvcell < numberofcells && GetRotateCell(nvcell)) {
1591 os << "\\begin{sideways}\n";
1597 if (nvcell < numberofcells && GetRotateCell(nvcell)) {
1598 os << "\\begin{sideways}\n";
1603 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1604 os << "\\multicolumn{"
1605 << cells_in_multicolumn(nvcell)
1607 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1608 os << cellinfo_of_cell(cell+1)->align_special
1611 if (LeftLine(nvcell))
1613 if (!GetPWidth(nvcell).empty()) {
1615 << GetPWidth(nvcell)
1618 switch (GetAlignment(nvcell)) {
1619 case LYX_ALIGN_LEFT: os << 'l'; break;
1620 case LYX_ALIGN_RIGHT: os << 'r'; break;
1621 default: os << 'c'; break;
1624 if (RightLine(nvcell))
1626 //if (column_of_cell(cell+2)!= 0 && LeftLine(cell+2))
1627 if (((nvcell + 1) < numberofcells) &&
1628 ((nvcell+1) < numberofcells) &&
1629 (column_of_cell(nvcell+1)!= 0) &&
1636 if (nvcell < numberofcells && GetLinebreaks(nvcell)) {
1637 os << "\\parbox[t]{"
1638 << GetPWidth(nvcell)
1639 << "}{\\smallskip{}";
1646 // cell <0 will tex the preamble
1647 // returns the number of printed newlines
1648 int LyXTabular::RoffEndOfCell(ostream & os, int cell)
1652 if (cell == GetNumberOfCells() - 1){
1653 // the very end at the very beginning
1654 // if (CellHasContRow(cell) >= 0) {
1660 if (row_info[row_of_cell(cell)].bottom_line) {
1664 os << ".TE\n.pl 1c";
1669 os << "\n.pl 500c\n.TS\n";
1670 for (int j = 0; j < rows_; ++j) {
1671 for (int i = 0; i < columns_; ++i, ++fcell) {
1672 if (column_info[i].left_line)
1674 if (cell_info[j][i].multicolumn == CELL_PART_OF_MULTICOLUMN)
1677 switch (column_info[i].alignment) {
1678 case LYX_ALIGN_LEFT:
1681 case LYX_ALIGN_RIGHT:
1689 if (!column_info[i].p_width.empty())
1690 os << "w(" << column_info[i].p_width << ")";
1691 if (column_info[i].right_line)
1694 if ((j + 1) < rows_) {
1701 if (row_info[0].top_line) {
1705 // if (CellHasContRow(0) >= 0) {
1711 // if (CellHasContRow(cell) >= 0) {
1715 if (right_column_of_cell(cell) == columns_ -1){
1718 int row = row_of_cell(cell);
1719 if (row_info[row++].bottom_line) {
1723 if ((row < rows_) && row_info[row].top_line) {
1729 // if ((cell < GetNumberOfCells() - 1) &&
1730 // (CellHasContRow(cell+1) >= 0)) {
1742 char const * LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
1744 int i = isColumn ? cell : column_of_cell(cell);
1749 //i = column_of_cell(cell);
1750 if (!isColumn && IsMultiColumn(cell)) {
1751 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1752 return cellinfo_of_cell(cell)->align_special.c_str();
1754 switch (GetAlignment(cell)) {
1755 case LYX_ALIGN_LEFT:
1757 case LYX_ALIGN_RIGHT:
1764 if (!column_info[i].align_special.empty()) {
1765 return column_info[i].align_special.c_str();
1767 #ifdef IGNORE_THIS_FOR_NOW
1768 else if (!column_info[i].p_width.empty()) {
1770 file += column_info[i].p_width;
1775 switch (column_info[i].alignment) {
1776 case LYX_ALIGN_LEFT:
1778 case LYX_ALIGN_RIGHT:
1788 // cell <0 will tex the preamble
1789 // returns the number of printed newlines
1790 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1794 //int tmp; // tmp2; // unused
1795 int nvcell; // fcell; // unused
1796 if (IsLastCell(cell)) {
1797 os << newlineAndDepth(--depth)
1799 << newlineAndDepth(--depth)
1801 << newlineAndDepth(--depth)
1803 << newlineAndDepth(--depth);
1804 if (is_long_tabular)
1808 << newlineAndDepth(--depth);
1814 if (is_long_tabular)
1820 << "' COLSEP='1' ROWSEP='1'>"
1821 << newlineAndDepth(++depth);
1823 for (i = 0; i < columns_; ++i) {
1824 os << "<COLSPEC ALIGN='"
1825 << GetDocBookAlign(i, true)
1831 if (i == (columns_-1)) {
1834 if (column_info[i].right_line ||
1835 column_info[i+1].left_line)
1841 << newlineAndDepth(depth);
1843 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1844 if (column_info[i].left_line)
1849 << newlineAndDepth(++depth)
1851 << newlineAndDepth(++depth)
1853 << GetDocBookAlign(0)
1855 if (IsMultiColumn(0)) {
1856 os << " NAMEST='col1' NAMEEND='col"
1857 << cells_in_multicolumn(0)
1861 << newlineAndDepth(++depth);
1864 if (IsLastCellInRow(cell)) {
1865 os << newlineAndDepth(--depth)
1867 << newlineAndDepth(--depth)
1869 << newlineAndDepth(depth)
1871 << newlineAndDepth(++depth)
1873 << GetDocBookAlign(cell + 1)
1874 << "' VALIGN='middle'";
1875 if (IsMultiColumn(cell + 1)) {
1876 os << " NAMEST='col"
1877 << column_of_cell(cell+1) + 1
1879 << column_of_cell(cell + 1) +
1880 cells_in_multicolumn(cell + 1)
1884 << newlineAndDepth(++depth);
1887 os << newlineAndDepth(--depth)
1889 << newlineAndDepth(depth)
1891 << GetDocBookAlign(cell + 1)
1892 << "' VALIGN='middle'";
1893 if (IsMultiColumn(cell + 1)) {
1894 os << " NAMEST='col"
1895 << column_of_cell(cell+1) + 1
1897 << column_of_cell(cell+1) +
1898 cells_in_multicolumn(cell+1)
1902 << newlineAndDepth(++depth);
1911 bool LyXTabular::IsMultiColumn(int cell) const
1913 return (cellinfo_of_cell(cell)->multicolumn != LyXTabular::CELL_NORMAL);
1917 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1919 int row = row_of_cell(cell);
1920 int column = column_of_cell(cell);
1921 return &cell_info[row][column];
1925 void LyXTabular::SetMultiColumn(int cell, int number)
1927 int new_width = cellinfo_of_cell(cell)->width_of_cell;
1929 cellinfo_of_cell(cell)->multicolumn = LyXTabular::CELL_BEGIN_OF_MULTICOLUMN;
1930 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1931 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1932 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1933 for (number--; number > 0; --number) {
1934 cellinfo_of_cell(cell+number)->multicolumn =
1935 LyXTabular::CELL_PART_OF_MULTICOLUMN;
1936 new_width += cellinfo_of_cell(cell+number)->width_of_cell;
1938 set_row_column_number_info();
1939 SetWidthOfCell(cell, new_width);
1940 if (GetPWidth(cell).empty())
1941 GetCellInset(cell)->SetAutoBreakRows(false);
1945 int LyXTabular::cells_in_multicolumn(int cell) const
1947 int row = row_of_cell(cell);
1948 int column = column_of_cell(cell);
1951 while (column < columns_ && cell_info[row][column].multicolumn
1952 == LyXTabular::CELL_PART_OF_MULTICOLUMN){
1960 int LyXTabular::UnsetMultiColumn(int cell)
1962 int row = row_of_cell(cell);
1963 int column = column_of_cell(cell);
1967 if (cell_info[row][column].multicolumn
1968 == LyXTabular::CELL_BEGIN_OF_MULTICOLUMN){
1969 cell_info[row][column].multicolumn = LyXTabular::CELL_NORMAL;
1971 while (column < columns_ &&
1972 cell_info[row][column].multicolumn
1973 == LyXTabular::CELL_PART_OF_MULTICOLUMN){
1974 cell_info[row][column].multicolumn =
1975 LyXTabular::CELL_NORMAL;
1980 set_row_column_number_info();
1981 if (GetPWidth(cell).empty())
1982 GetCellInset(cell)->SetAutoBreakRows(false);
1987 void LyXTabular::SetLongTabular(int what)
1989 is_long_tabular = what;
1993 bool LyXTabular::IsLongTabular() const
1995 return is_long_tabular;
1999 void LyXTabular::SetRotateTabular(int what)
2005 bool LyXTabular::GetRotateTabular() const
2011 void LyXTabular::SetRotateCell(int cell, int what)
2013 cellinfo_of_cell(cell)->rotate = what;
2017 bool LyXTabular::GetRotateCell(int cell) const
2019 return cellinfo_of_cell(cell)->rotate;
2023 bool LyXTabular::NeedRotating() const
2027 for (int i = 0; i < rows_; ++i) {
2028 for (int j = 0; j < columns_; ++j) {
2029 if (cell_info[i][j].rotate)
2037 bool LyXTabular::IsLastCell(int cell) const
2039 if (cell < GetNumberOfCells())
2045 int LyXTabular::GetCellAbove(int cell) const
2047 if (row_of_cell(cell) > 0)
2048 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
2053 int LyXTabular::GetCellNumber(int row, int column) const
2055 if (column >= columns_)
2056 column = columns_ - 1;
2057 else if (column < 0)
2064 return cell_info[row][column].cellno;
2068 void LyXTabular::SetLinebreaks(int cell, bool what)
2070 cellinfo_of_cell(cell)->linebreaks = what;
2074 bool LyXTabular::GetLinebreaks(int cell) const
2076 if (column_info[column_of_cell(cell)].p_width.empty() &&
2077 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
2079 return cellinfo_of_cell(cell)->linebreaks;
2083 void LyXTabular::SetLTHead(int cell, bool first)
2085 int row = row_of_cell(cell);
2088 if (row == endfirsthead)
2101 bool LyXTabular::GetRowOfLTHead(int cell) const
2103 if ((endhead+1) > rows_)
2105 return (row_of_cell(cell) == endhead);
2109 bool LyXTabular::GetRowOfLTFirstHead(int cell) const
2111 if ((endfirsthead+1) > rows_)
2113 return (row_of_cell(cell) == endfirsthead);
2117 void LyXTabular::SetLTFoot(int cell, bool last)
2119 int row = row_of_cell(cell);
2122 if (row == endlastfoot)
2135 bool LyXTabular::GetRowOfLTFoot(int cell) const
2137 if ((endfoot+1) > rows_)
2139 return (row_of_cell(cell) == endfoot);
2142 bool LyXTabular::GetRowOfLTLastFoot(int cell) const
2144 if ((endlastfoot+1) > rows_)
2146 return (row_of_cell(cell) == endlastfoot);
2150 void LyXTabular::SetLTNewPage(int cell, bool what)
2152 row_info[row_of_cell(cell)].newpage = what;
2156 bool LyXTabular::GetLTNewPage(int cell) const
2158 return row_info[row_of_cell(cell)].newpage;
2162 void LyXTabular::SetAscentOfRow(int row, int height)
2166 row_info[row].ascent_of_row = height;
2170 void LyXTabular::SetDescentOfRow(int row, int height)
2174 row_info[row].descent_of_row = height;
2178 int LyXTabular::GetAscentOfRow(int row) const
2182 return row_info[row].ascent_of_row;
2186 int LyXTabular::GetDescentOfRow(int row) const
2190 return row_info[row].descent_of_row;
2194 int LyXTabular::GetHeightOfTabular() const
2198 for(int row = 0; row < rows_; ++row)
2199 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
2200 GetAdditionalHeight(GetCellNumber(row, 0));
2205 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
2207 if ((row >= rows_) || (column >= columns_))
2209 return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
2213 int LyXTabular::TeXTopHLine(ostream & os, int row) const
2215 int fcell = GetFirstCellInRow(row);
2216 int n = NumberOfCellsInRow(fcell) + fcell;
2220 for (i = fcell; i < n; ++i) {
2224 if (tmp == (n - fcell)){
2227 for (i = fcell; i < n; ++i) {
2230 << column_of_cell(i) + 1
2232 << right_column_of_cell(i) + 1
2245 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
2247 int fcell = GetFirstCellInRow(row);
2248 int n = NumberOfCellsInRow(fcell) + fcell;
2252 for (i = fcell; i < n; ++i) {
2256 if (tmp == (n-fcell)){
2259 for (i = fcell; i < n; ++i) {
2260 if (BottomLine(i)) {
2262 << column_of_cell(i) + 1
2264 << right_column_of_cell(i) + 1
2277 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
2281 if (GetRotateCell(cell)) {
2282 os << "\\begin{sideways}" << endl;
2285 if (IsMultiColumn(cell)) {
2286 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
2287 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
2288 os << cellinfo_of_cell(cell+1)->align_special << "}{";
2292 if (!GetPWidth(cell).empty()) {
2293 os << "p{" << GetPWidth(cell) << '}';
2295 switch (GetAlignment(cell)) {
2296 case LYX_ALIGN_LEFT:
2299 case LYX_ALIGN_RIGHT:
2307 if (RightLine(cell))
2309 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
2315 if (GetLinebreaks(cell)) {
2316 os << "\\parbox[t]{" << GetPWidth(cell) << "}{\\smallskip{}";
2322 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
2327 if (GetLinebreaks(cell))
2328 os << "\\smallskip{}}";
2329 if (IsMultiColumn(cell)){
2332 if (GetRotateCell(cell)) {
2333 os << endl << "\\end{sideways}";
2340 int LyXTabular::Latex(ostream & os, bool fragile, bool fp) const
2346 //+---------------------------------------------------------------------
2347 //+ first the opening preamble +
2348 //+---------------------------------------------------------------------
2351 os << "\\begin{sideways}" << endl;
2354 if (is_long_tabular)
2355 os << "\\begin{longtable}{";
2357 os << "\\begin{tabular}{";
2358 for (i = 0; i < columns_; ++i) {
2359 if (column_info[i].left_line)
2361 if (!column_info[i].align_special.empty()) {
2362 os << column_info[i].align_special;
2363 } else if (!column_info[i].p_width.empty()) {
2365 << column_info[i].p_width
2368 switch (column_info[i].alignment) {
2369 case LYX_ALIGN_LEFT:
2372 case LYX_ALIGN_RIGHT:
2380 if (column_info[i].right_line)
2386 //+---------------------------------------------------------------------
2387 //+ the single row and columns (cells) +
2388 //+---------------------------------------------------------------------
2390 for(i=0; i < rows_; ++i) {
2391 ret += TeXTopHLine(os, i);
2392 for(j=0; j < columns_; ++j) {
2393 if (IsPartOfMultiColumn(i,j))
2395 ret += TeXCellPreamble(os, cell);
2396 ret += GetCellInset(cell)->Latex(os, fragile, fp);
2397 ret += TeXCellPostamble(os, cell);
2398 if (j < (columns_ - 1)) { // not last cell in row
2404 os << "\\\\" << endl;
2405 ret += TeXBottomHLine(os, i);
2406 if (IsLongTabular()) {
2408 os << "\\endhead\n";
2411 if (i == endfirsthead) {
2412 os << "\\endfirsthead\n";
2416 os << "\\endfoot\n";
2419 if (i == endlastfoot) {
2420 os << "\\endlastfoot\n";
2423 if (row_info[i].newpage) {
2424 os << "\\newpage\n";
2430 //+---------------------------------------------------------------------
2431 //+ the closing of the tabular +
2432 //+---------------------------------------------------------------------
2434 if (is_long_tabular)
2435 os << "\\end{longtable}";
2437 os << "\\end{tabular}";
2439 os << "\n\\end{sideways}";
2447 InsetText * LyXTabular::GetCellInset(int cell) const
2449 return cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;