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 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 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 fl)
1207 int columns_arg = 0;
1208 int is_long_tabular_arg = false;
1209 int rotate_arg = false;
1219 istream & is = lex.getStream();
1223 version = atoi(s.c_str() + 8);
1227 int * cont_row_info;
1230 lyxerr << "Tabular format < 5 is not supported anymore\n"
1231 "Get an older version of LyX (< 1.1.x) for conversion!"
1233 WriteAlert(_("Warning:"),
1234 _("Tabular format < 5 is not supported anymore\n"),
1235 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1237 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1238 >> rotate_arg >> a >> b >> c >> d;
1240 is >> rows_arg >> columns_arg;
1241 Init(rows_arg, columns_arg);
1242 SetLongTabular(is_long_tabular_arg);
1243 SetRotateTabular(rotate_arg);
1245 for (i = 0; i < rows_; ++i) {
1248 for (i = 0; i < columns_; ++i) {
1251 for (i = 0; i < rows_; ++i) {
1252 for (j = 0; j < columns_; ++j) {
1257 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1258 >> rotate_arg >> a >> b >> c >> d;
1259 Init(rows_arg, columns_arg);
1260 SetLongTabular(is_long_tabular_arg);
1261 SetRotateTabular(rotate_arg);
1266 for (i = 0; i < rows_; ++i) {
1267 a = b = c = d = e = f = g = h = 0;
1268 is >> a >> b >> c >> d;
1269 row_info[i].top_line = a;
1270 row_info[i].bottom_line = b;
1271 // row_info[i].is_cont_row = c;
1272 row_info[i].newpage = d;
1274 for (i = 0; i < columns_; ++i) {
1278 char ch; // skip '"'
1280 getline(is, s1, '"');
1281 is >> ch; // skip '"'
1282 getline(is, s2, '"');
1283 column_info[i].alignment = static_cast<char>(a);
1284 column_info[i].left_line = b;
1285 column_info[i].right_line = c;
1286 column_info[i].p_width = s1;
1287 column_info[i].align_special = s2;
1289 for (i = 0; i < rows_; ++i) {
1290 for (j = 0; j < columns_; ++j) {
1293 is >> a >> b >> c >> d >> e >> f >> g;
1295 is >> ch; // skip '"'
1296 getline(is, s1, '"');
1297 is >> ch; // skip '"'
1298 getline(is, s2, '"');
1299 cell_info[i][j].multicolumn = static_cast<char>(a);
1300 cell_info[i][j].alignment = static_cast<char>(b);
1301 cell_info[i][j].top_line = static_cast<char>(c);
1302 cell_info[i][j].bottom_line = static_cast<char>(d);
1303 // cell_info[i][j].has_cont_row = static_cast<bool>(e);
1304 cell_info[i][j].rotate = static_cast<bool>(f);
1305 cell_info[i][j].linebreaks = static_cast<bool>(g);
1306 cell_info[i][j].align_special = s1;
1307 cell_info[i][j].p_width = s2;
1311 set_row_column_number_info();
1312 LyXParagraph * par = new LyXParagraph;
1313 LyXParagraph * return_par = 0;
1314 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1315 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
1316 string token, tmptok;
1319 LyXFont font(LyXFont::ALL_INHERIT);
1321 while (lex.IsOK()) {
1323 token = lex.GetString();
1326 if ((token == "\\layout") || (token == "\\end_float")) {
1327 lex.pushToken(token);
1330 if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
1338 lex.pushToken(token);
1342 lex.printError("New Paragraph allocated! This should not happen!");
1343 lex.pushToken(token);
1349 // now we have the par we should fill the insets with this!
1351 InsetText *inset = GetCellInset(cell);
1353 for(int i=0; i < par->Last(); ++i) {
1354 if (par->IsNewline(i)) {
1356 if (cell > GetNumberOfCells()) {
1357 lyxerr << "Some error in reading old table format occured!" <<
1358 endl << "Terminating when reading cell[" << cell << "]!" <<
1362 inset = GetCellInset(cell);
1365 par->CopyIntoMinibuffer(i);
1366 inset->par->InsertFromMinibuffer(inset->par->Last());
1372 // cell < 0 will tex the preamble
1373 // returns the number of printed newlines
1374 int LyXTabular::TexEndOfCell(ostream & os, int cell) const
1380 if (IsLastCell(cell)) {
1381 // the very end at the very beginning
1382 if (GetLinebreaks(cell))
1383 os << "\\smallskip{}}";
1384 if (IsMultiColumn(cell))
1386 if (GetRotateCell(cell)) {
1387 os << "\n\\end{sideways}";
1395 while (!IsFirstCellInRow(fcell)) --fcell;
1396 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1397 if (BottomLine(fcell + i))
1400 if (tmp == NumberOfCellsInRow(fcell)) {
1404 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1405 if (BottomLine(fcell + i)) {
1407 << column_of_cell(fcell + i) + 1
1409 << right_column_of_cell(fcell + i) + 1
1419 if (is_long_tabular)
1420 os << "\\end{longtable}";
1422 os << "\\end{tabular}";
1424 os << "\n\\end{sideways}";
1432 os << "\\begin{sideways}\n";
1435 if (is_long_tabular)
1436 os << "\\begin{longtable}{";
1438 os << "\\begin{tabular}{";
1439 for (i = 0; i < columns_; ++i) {
1440 if (column_info[i].left_line)
1442 if (!column_info[i].align_special.empty()) {
1443 os << column_info[i].align_special;
1444 } else if (!column_info[i].p_width.empty()) {
1446 << column_info[i].p_width
1449 switch (column_info[i].alignment) {
1450 case LYX_ALIGN_LEFT:
1453 case LYX_ALIGN_RIGHT:
1461 if (column_info[i].right_line)
1467 if (GetNumberOfCells()) {
1469 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1470 if (TopLine(fcell + i))
1473 if (tmp == NumberOfCellsInRow(fcell)){
1477 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1478 if (TopLine(fcell + i)) {
1480 << column_of_cell(fcell + i) + 1
1482 << right_column_of_cell(fcell + i) + 1
1493 if (GetRotateCell(0)) {
1494 os << "\\begin{sideways}\n";
1499 if (GetLinebreaks(cell))
1500 os << "\\smallskip{}}";
1501 if (IsMultiColumn(cell)){
1504 if (GetRotateCell(cell)) {
1505 os << "\n\\end{sideways}";
1508 if (IsLastCellInRow(cell)) {
1509 int row = row_of_cell(cell);
1510 string hline1, hline2;
1511 bool print_hline = true;
1512 bool flag1 = IsLongTabular() &&
1513 ((row == endhead) || (row == endfirsthead) ||
1514 (row == endfoot) || (row == endlastfoot));
1516 bool flag2 = IsLongTabular() &&
1517 ((row <= endhead) || (row <= endfirsthead) ||
1518 (row <= endfoot) || (row <= endlastfoot));
1520 // print the bottom hline only if (otherwise it is doubled):
1521 // - is no LongTabular
1522 // - there IS a first-header
1523 // - the next row is no special header/footer
1524 // & this row is no special header/footer
1525 // - the next row is a special header/footer
1526 // & this row is a special header/footer
1527 bool pr_top_hline = (flag1 && flag2) || (!flag1 && !flag2) ||
1528 (endfirsthead == endhead);
1533 while (!IsFirstCellInRow(fcell))
1535 for (i = 0; i < NumberOfCellsInRow(cell); ++i) {
1536 if (BottomLine(fcell + i))
1539 if (tmp == NumberOfCellsInRow(cell)){
1541 hline1 = "\\hline ";
1544 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1545 if (BottomLine(fcell + i)){
1547 << column_of_cell(fcell + i) + 1
1549 << right_column_of_cell(fcell + i) + 1
1551 hline1 += "\\cline{";
1552 hline1 += tostr(column_of_cell(fcell + i) + 1);
1554 hline1 += tostr(right_column_of_cell(fcell + i) + 1);
1564 if (IsLongTabular() && (row == endfoot)) {
1565 os << "\\endfoot\n";
1567 print_hline = false; // no double line below footer
1569 if (IsLongTabular() && (row == endlastfoot)) {
1570 os << "\\endlastfoot\n";
1572 print_hline = false; // no double line below footer
1574 if (IsLongTabular() && row_info[row].newpage) {
1575 os << "\\newpage\n";
1577 print_hline = false; // no line below a \\newpage-command
1580 if ((nvcell < numberofcells) &&
1581 (cell < GetNumberOfCells() - 1) && !IsLastCell(cell)) {
1583 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1584 if (TopLine(fcell + i))
1587 if (tmp == NumberOfCellsInRow(fcell)) {
1590 hline2 = "\\hline ";
1593 for (i = 0; i < NumberOfCellsInRow(fcell); ++i) {
1594 if (TopLine(fcell + i)) {
1597 << column_of_cell(fcell + i) + 1
1599 << right_column_of_cell(fcell + i) + 1
1602 hline2 += "\\cline{";
1603 hline2 += tostr(column_of_cell(fcell+i)+1);
1605 hline2 += tostr(right_column_of_cell(fcell+i)+1);
1611 if (tmp && print_hline){
1616 // the order here is important as if one defines two
1617 // or more things in one line only the first entry is
1618 // displayed the other are set to an empty-row. This
1619 // is important if I have a footer and want that the
1620 // lastfooter is NOT displayed!!!
1621 bool sflag2 = (row == endhead) || (row == endfirsthead) ||
1622 (row == endfoot) || (row == endlastfoot);
1625 bool sflag1 = IsLongTabular() && (row != endhead) &&
1626 (row != endfirsthead) &&
1627 ((row == endfoot) || (row == endlastfoot));
1629 if (IsLongTabular() && (row == endhead)) {
1630 os << "\\endhead\n";
1633 if (IsLongTabular() && (row == endfirsthead)) {
1634 os << "\\endfirsthead\n";
1637 if (sflag1) { // add the \hline for next foot row
1638 if (!hline1.empty()) {
1639 os << hline1 + '\n';
1643 // add the \hline for the first row
1644 if (pr_top_hline && sflag2) {
1645 if (!hline2.empty()) {
1646 os << hline2 + '\n';
1650 if (nvcell < numberofcells && GetRotateCell(nvcell)) {
1651 os << "\\begin{sideways}\n";
1657 if (nvcell < numberofcells && GetRotateCell(nvcell)) {
1658 os << "\\begin{sideways}\n";
1663 if (nvcell < numberofcells && IsMultiColumn(nvcell)) {
1664 os << "\\multicolumn{"
1665 << cells_in_multicolumn(nvcell)
1667 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
1668 os << cellinfo_of_cell(cell+1)->align_special
1671 if (LeftLine(nvcell))
1673 if (!GetPWidth(nvcell).empty()) {
1675 << GetPWidth(nvcell)
1678 switch (GetAlignment(nvcell)) {
1679 case LYX_ALIGN_LEFT: os << 'l'; break;
1680 case LYX_ALIGN_RIGHT: os << 'r'; break;
1681 default: os << 'c'; break;
1684 if (RightLine(nvcell))
1686 //if (column_of_cell(cell+2)!= 0 && LeftLine(cell+2))
1687 if (((nvcell + 1) < numberofcells) &&
1688 ((nvcell+1) < numberofcells) &&
1689 (column_of_cell(nvcell+1)!= 0) &&
1696 if (nvcell < numberofcells && GetLinebreaks(nvcell)) {
1697 os << "\\parbox[t]{"
1698 << GetPWidth(nvcell)
1699 << "}{\\smallskip{}";
1706 // cell <0 will tex the preamble
1707 // returns the number of printed newlines
1708 int LyXTabular::RoffEndOfCell(ostream & os, int cell)
1712 if (cell == GetNumberOfCells() - 1){
1713 // the very end at the very beginning
1714 // if (CellHasContRow(cell) >= 0) {
1720 if (row_info[row_of_cell(cell)].bottom_line) {
1724 os << ".TE\n.pl 1c";
1729 os << "\n.pl 500c\n.TS\n";
1730 for (int j = 0; j < rows_; ++j) {
1731 for (int i = 0; i < columns_; ++i, ++fcell) {
1732 if (column_info[i].left_line)
1734 if (cell_info[j][i].multicolumn == CELL_PART_OF_MULTICOLUMN)
1737 switch (column_info[i].alignment) {
1738 case LYX_ALIGN_LEFT:
1741 case LYX_ALIGN_RIGHT:
1749 if (!column_info[i].p_width.empty())
1750 os << "w(" << column_info[i].p_width << ")";
1751 if (column_info[i].right_line)
1754 if ((j + 1) < rows_) {
1761 if (row_info[0].top_line) {
1765 // if (CellHasContRow(0) >= 0) {
1771 // if (CellHasContRow(cell) >= 0) {
1775 if (right_column_of_cell(cell) == columns_ -1){
1778 int row = row_of_cell(cell);
1779 if (row_info[row++].bottom_line) {
1783 if ((row < rows_) && row_info[row].top_line) {
1789 // if ((cell < GetNumberOfCells() - 1) &&
1790 // (CellHasContRow(cell+1) >= 0)) {
1802 char const * LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
1804 int i = isColumn ? cell : column_of_cell(cell);
1809 //i = column_of_cell(cell);
1810 if (!isColumn && IsMultiColumn(cell)) {
1811 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1812 return cellinfo_of_cell(cell)->align_special.c_str();
1814 switch (GetAlignment(cell)) {
1815 case LYX_ALIGN_LEFT:
1817 case LYX_ALIGN_RIGHT:
1824 if (!column_info[i].align_special.empty()) {
1825 return column_info[i].align_special.c_str();
1827 #ifdef IGNORE_THIS_FOR_NOW
1828 else if (!column_info[i].p_width.empty()) {
1830 file += column_info[i].p_width;
1835 switch (column_info[i].alignment) {
1836 case LYX_ALIGN_LEFT:
1838 case LYX_ALIGN_RIGHT:
1848 // cell <0 will tex the preamble
1849 // returns the number of printed newlines
1850 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1854 //int tmp; // tmp2; // unused
1855 int nvcell; // fcell; // unused
1856 if (IsLastCell(cell)) {
1857 os << newlineAndDepth(--depth)
1859 << newlineAndDepth(--depth)
1861 << newlineAndDepth(--depth)
1863 << newlineAndDepth(--depth);
1864 if (is_long_tabular)
1868 << newlineAndDepth(--depth);
1874 if (is_long_tabular)
1880 << "' COLSEP='1' ROWSEP='1'>"
1881 << newlineAndDepth(++depth);
1883 for (i = 0; i < columns_; ++i) {
1884 os << "<COLSPEC ALIGN='"
1885 << GetDocBookAlign(i, true)
1891 if (i == (columns_-1)) {
1894 if (column_info[i].right_line ||
1895 column_info[i+1].left_line)
1901 << newlineAndDepth(depth);
1903 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1904 if (column_info[i].left_line)
1909 << newlineAndDepth(++depth)
1911 << newlineAndDepth(++depth)
1913 << GetDocBookAlign(0)
1915 if (IsMultiColumn(0)) {
1916 os << " NAMEST='col1' NAMEEND='col"
1917 << cells_in_multicolumn(0)
1921 << newlineAndDepth(++depth);
1924 if (IsLastCellInRow(cell)) {
1925 os << newlineAndDepth(--depth)
1927 << newlineAndDepth(--depth)
1929 << newlineAndDepth(depth)
1931 << newlineAndDepth(++depth)
1933 << GetDocBookAlign(cell + 1)
1934 << "' VALIGN='middle'";
1935 if (IsMultiColumn(cell + 1)) {
1936 os << " NAMEST='col"
1937 << column_of_cell(cell+1) + 1
1939 << column_of_cell(cell + 1) +
1940 cells_in_multicolumn(cell + 1)
1944 << newlineAndDepth(++depth);
1947 os << newlineAndDepth(--depth)
1949 << newlineAndDepth(depth)
1951 << GetDocBookAlign(cell + 1)
1952 << "' VALIGN='middle'";
1953 if (IsMultiColumn(cell + 1)) {
1954 os << " NAMEST='col"
1955 << column_of_cell(cell+1) + 1
1957 << column_of_cell(cell+1) +
1958 cells_in_multicolumn(cell+1)
1962 << newlineAndDepth(++depth);
1971 bool LyXTabular::IsMultiColumn(int cell) const
1973 return (cellinfo_of_cell(cell)->multicolumn != LyXTabular::CELL_NORMAL);
1977 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1979 int row = row_of_cell(cell);
1980 int column = column_of_cell(cell);
1981 return &cell_info[row][column];
1985 void LyXTabular::SetMultiColumn(int cell, int number)
1987 int new_width = cellinfo_of_cell(cell)->width_of_cell;
1989 cellinfo_of_cell(cell)->multicolumn = LyXTabular::CELL_BEGIN_OF_MULTICOLUMN;
1990 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1991 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1992 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1993 for (number--; number > 0; --number) {
1994 cellinfo_of_cell(cell+number)->multicolumn =
1995 LyXTabular::CELL_PART_OF_MULTICOLUMN;
1996 new_width += cellinfo_of_cell(cell+number)->width_of_cell;
1998 set_row_column_number_info();
1999 SetWidthOfCell(cell, new_width);
2000 if (GetPWidth(cell).empty())
2001 GetCellInset(cell)->SetAutoBreakRows(false);
2005 int LyXTabular::cells_in_multicolumn(int cell) const
2007 int row = row_of_cell(cell);
2008 int column = column_of_cell(cell);
2011 while (column < columns_ && cell_info[row][column].multicolumn
2012 == LyXTabular::CELL_PART_OF_MULTICOLUMN){
2020 int LyXTabular::UnsetMultiColumn(int cell)
2022 int row = row_of_cell(cell);
2023 int column = column_of_cell(cell);
2027 if (cell_info[row][column].multicolumn
2028 == LyXTabular::CELL_BEGIN_OF_MULTICOLUMN){
2029 cell_info[row][column].multicolumn = LyXTabular::CELL_NORMAL;
2031 while (column < columns_ &&
2032 cell_info[row][column].multicolumn
2033 == LyXTabular::CELL_PART_OF_MULTICOLUMN){
2034 cell_info[row][column].multicolumn =
2035 LyXTabular::CELL_NORMAL;
2040 set_row_column_number_info();
2041 if (GetPWidth(cell).empty())
2042 GetCellInset(cell)->SetAutoBreakRows(false);
2047 void LyXTabular::SetLongTabular(int what)
2049 is_long_tabular = what;
2053 bool LyXTabular::IsLongTabular() const
2055 return is_long_tabular;
2059 void LyXTabular::SetRotateTabular(int what)
2065 bool LyXTabular::GetRotateTabular() const
2071 void LyXTabular::SetRotateCell(int cell, int what)
2073 cellinfo_of_cell(cell)->rotate = what;
2077 bool LyXTabular::GetRotateCell(int cell) const
2079 return cellinfo_of_cell(cell)->rotate;
2083 bool LyXTabular::NeedRotating() const
2087 for (int i = 0; i < rows_; ++i) {
2088 for (int j = 0; j < columns_; ++j) {
2089 if (cell_info[i][j].rotate)
2097 bool LyXTabular::IsLastCell(int cell) const
2099 if (cell < GetNumberOfCells())
2105 int LyXTabular::GetCellAbove(int cell) const
2107 if (row_of_cell(cell) > 0)
2108 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
2113 int LyXTabular::GetCellNumber(int row, int column) const
2115 if (column >= columns_)
2116 column = columns_ - 1;
2117 else if (column < 0)
2124 return cell_info[row][column].cellno;
2128 void LyXTabular::SetLinebreaks(int cell, bool what)
2130 cellinfo_of_cell(cell)->linebreaks = what;
2134 bool LyXTabular::GetLinebreaks(int cell) const
2136 if (column_info[column_of_cell(cell)].p_width.empty() &&
2137 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
2139 return cellinfo_of_cell(cell)->linebreaks;
2143 void LyXTabular::SetLTHead(int cell, bool first)
2145 int row = row_of_cell(cell);
2148 if (row == endfirsthead)
2161 bool LyXTabular::GetRowOfLTHead(int cell) const
2163 if ((endhead+1) > rows_)
2165 return (row_of_cell(cell) == endhead);
2169 bool LyXTabular::GetRowOfLTFirstHead(int cell) const
2171 if ((endfirsthead+1) > rows_)
2173 return (row_of_cell(cell) == endfirsthead);
2177 void LyXTabular::SetLTFoot(int cell, bool last)
2179 int row = row_of_cell(cell);
2182 if (row == endlastfoot)
2195 bool LyXTabular::GetRowOfLTFoot(int cell) const
2197 if ((endfoot+1) > rows_)
2199 return (row_of_cell(cell) == endfoot);
2202 bool LyXTabular::GetRowOfLTLastFoot(int cell) const
2204 if ((endlastfoot+1) > rows_)
2206 return (row_of_cell(cell) == endlastfoot);
2210 void LyXTabular::SetLTNewPage(int cell, bool what)
2212 row_info[row_of_cell(cell)].newpage = what;
2216 bool LyXTabular::GetLTNewPage(int cell) const
2218 return row_info[row_of_cell(cell)].newpage;
2222 void LyXTabular::SetAscentOfRow(int row, int height)
2226 row_info[row].ascent_of_row = height;
2230 void LyXTabular::SetDescentOfRow(int row, int height)
2234 row_info[row].descent_of_row = height;
2238 int LyXTabular::GetAscentOfRow(int row) const
2242 return row_info[row].ascent_of_row;
2246 int LyXTabular::GetDescentOfRow(int row) const
2250 return row_info[row].descent_of_row;
2254 int LyXTabular::GetHeightOfTabular() const
2258 for(int row = 0; row < rows_; ++row)
2259 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
2260 GetAdditionalHeight(GetCellNumber(row, 0));
2265 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
2267 if ((row >= rows_) || (column >= columns_))
2269 return (cell_info[row][column].multicolumn==CELL_PART_OF_MULTICOLUMN);
2273 int LyXTabular::TeXTopHLine(ostream & os, int row) const
2275 int fcell = GetFirstCellInRow(row);
2276 int n = NumberOfCellsInRow(fcell) + fcell;
2280 for (i = fcell; i < n; ++i) {
2284 if (tmp == (n - fcell)){
2287 for (i = fcell; i < n; ++i) {
2290 << column_of_cell(i) + 1
2292 << right_column_of_cell(i) + 1
2305 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
2307 int fcell = GetFirstCellInRow(row);
2308 int n = NumberOfCellsInRow(fcell) + fcell;
2312 for (i = fcell; i < n; ++i) {
2316 if (tmp == (n-fcell)){
2319 for (i = fcell; i < n; ++i) {
2320 if (BottomLine(i)) {
2322 << column_of_cell(i) + 1
2324 << right_column_of_cell(i) + 1
2337 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
2341 if (GetRotateCell(cell)) {
2342 os << "\\begin{sideways}" << endl;
2345 if (IsMultiColumn(cell)) {
2346 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
2347 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
2348 os << cellinfo_of_cell(cell+1)->align_special << "}{";
2352 if (!GetPWidth(cell).empty()) {
2353 os << "p{" << GetPWidth(cell) << '}';
2355 switch (GetAlignment(cell)) {
2356 case LYX_ALIGN_LEFT:
2359 case LYX_ALIGN_RIGHT:
2367 if (RightLine(cell))
2369 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
2375 if (GetLinebreaks(cell)) {
2376 os << "\\parbox[t]{" << GetPWidth(cell) << "}{\\smallskip{}";
2382 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
2387 if (GetLinebreaks(cell))
2388 os << "\\smallskip{}}";
2389 if (IsMultiColumn(cell)){
2392 if (GetRotateCell(cell)) {
2393 os << endl << "\\end{sideways}";
2400 int LyXTabular::Latex(ostream & os, bool fragile, bool fp) const
2406 //+---------------------------------------------------------------------
2407 //+ first the opening preamble +
2408 //+---------------------------------------------------------------------
2411 os << "\\begin{sideways}" << endl;
2414 if (is_long_tabular)
2415 os << "\\begin{longtable}{";
2417 os << "\\begin{tabular}{";
2418 for (i = 0; i < columns_; ++i) {
2419 if (column_info[i].left_line)
2421 if (!column_info[i].align_special.empty()) {
2422 os << column_info[i].align_special;
2423 } else if (!column_info[i].p_width.empty()) {
2425 << column_info[i].p_width
2428 switch (column_info[i].alignment) {
2429 case LYX_ALIGN_LEFT:
2432 case LYX_ALIGN_RIGHT:
2440 if (column_info[i].right_line)
2446 //+---------------------------------------------------------------------
2447 //+ the single row and columns (cells) +
2448 //+---------------------------------------------------------------------
2450 for(i=0; i < rows_; ++i) {
2451 ret += TeXTopHLine(os, i);
2452 for(j=0; j < columns_; ++j) {
2453 if (IsPartOfMultiColumn(i,j))
2455 ret += TeXCellPreamble(os, cell);
2456 ret += GetCellInset(cell)->Latex(os, fragile, fp);
2457 ret += TeXCellPostamble(os, cell);
2458 if (!IsLastCellInRow(cell)) { // not last cell in row
2464 os << "\\\\" << endl;
2465 ret += TeXBottomHLine(os, i);
2466 if (IsLongTabular()) {
2468 os << "\\endhead\n";
2471 if (i == endfirsthead) {
2472 os << "\\endfirsthead\n";
2476 os << "\\endfoot\n";
2479 if (i == endlastfoot) {
2480 os << "\\endlastfoot\n";
2483 if (row_info[i].newpage) {
2484 os << "\\newpage\n";
2490 //+---------------------------------------------------------------------
2491 //+ the closing of the tabular +
2492 //+---------------------------------------------------------------------
2494 if (is_long_tabular)
2495 os << "\\end{longtable}";
2497 os << "\\end{tabular}";
2499 os << "\n\\end{sideways}";
2507 InsetText * LyXTabular::GetCellInset(int cell) const
2509 return cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;