1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000-2001 The LyX Team.
8 * @author: Jürgen Vigna
10 * ======================================================
16 #pragma implementation
26 #include "lyx_gui_misc.h"
28 #include "BufferView.h"
30 #include "LaTeXFeatures.h"
31 #include "support/lstrings.h"
32 #include "support/lyxmanip.h"
33 #include "support/LAssert.h"
34 #include "insets/insettabular.h"
35 #include "insets/insettext.h"
45 #ifndef CXX_GLOBAL_CSTD
51 int const WIDTH_OF_LINE = 5;
55 /// Define a few methods for the inner structs
57 LyXTabular::cellstruct::cellstruct()
61 multicolumn = LyXTabular::CELL_NORMAL;
62 alignment = LYX_ALIGN_CENTER;
63 valignment = LYX_VALIGN_TOP;
73 LyXTabular::rowstruct::rowstruct()
83 LyXTabular::columnstruct::columnstruct()
87 alignment = LYX_ALIGN_CENTER;
88 valignment = LYX_VALIGN_TOP;
94 LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg)
98 Init(rows_arg, columns_arg);
102 LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt)
106 Init(lt.rows_, lt.columns_, <);
109 #warning Jürgen, can you make it the other way round. So that copy assignment depends on the copy constructor and not the other way. (Lgb)
116 LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex)
124 LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
127 #warning This while method should look like this: (Lgb)
132 // If this and lt is not of the same size we have a serious bug
133 // So then it is ok to throw an exception, or for now
135 lyx::Assert(rows_ == lt.rows_ && columns_ == lt.columns_);
137 cell_info = lt.cell_info;
138 row_info = lt.row_info;
139 column_info = lt.column_info;
141 // long tabular stuff
142 SetLongTabular(lt.is_long_tabular);
143 endhead = lt.endhead;
144 endfoot = lt.endfoot;
145 endfirsthead = lt.endfirsthead;
146 endlastfoot = lt.endlastfoot;
156 LyXTabular * LyXTabular::clone(InsetTabular * inset)
158 LyXTabular * result = new LyXTabular(inset, *this);
160 // don't know if this is good but I need to Clone also
161 // the text-insets here, this is for the Undo-facility!
162 for (int i = 0; i < rows_; ++i) {
163 for (int j = 0; j < columns_; ++j) {
164 result->cell_info[i][j].inset = cell_info[i][j].inset;
165 result->cell_info[i][j].inset.setOwner(inset);
173 /* activates all lines and sets all widths to 0 */
174 void LyXTabular::Init(int rows_arg, int columns_arg, LyXTabular const * lt)
177 columns_ = columns_arg;
178 row_info = row_vector(rows_, rowstruct());
179 column_info = column_vector(columns_, columnstruct());
180 cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct()));
188 for (int i = 0; i < rows_; ++i) {
189 for (int j = 0; j < columns_; ++j) {
190 cell_info[i][j].inset.setOwner(owner_);
191 cell_info[i][j].inset.setDrawFrame(0, InsetText::LOCKED);
192 cell_info[i][j].cellno = cellno++;
194 cell_info[i].back().right_line = true;
196 row_info.back().bottom_line = true;
197 row_info.front().bottom_line = true;
199 for (int i = 0; i < columns_; ++i) {
200 calculate_width_of_column(i);
202 column_info.back().right_line = true;
204 calculate_width_of_tabular();
206 rowofcell = vector<int>();
207 columnofcell = vector<int>();
208 set_row_column_number_info();
209 is_long_tabular = false;
218 void LyXTabular::AppendRow(int cell)
222 int row = row_of_cell(cell);
224 row_vector::iterator rit = row_info.begin() + row;
225 row_info.insert(rit, rowstruct());
226 // now set the values of the row before
227 row_info[row] = row_info[row+1];
230 cell_vvector::iterator cit = cell_info.begin() + row;
231 cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
233 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
236 for (int i = 0; i <= row; ++i) {
237 for (int j = 0; j < columns_; ++j) {
238 c_info[i][j] = cell_info[i][j];
241 for (int i = row + 1; i < rows_; ++i) {
242 for (int j = 0; j < columns_; ++j) {
243 c_info[i][j] = cell_info[i-1][j];
248 for (int j = 0; j < columns_; ++j) {
249 cell_info[row][j].inset.clear();
256 void LyXTabular::DeleteRow(int row)
258 // Why make it so hard? (Lgb)
261 if (rows_ == 1) return; // Not allowed to delete last row
263 row_info.erase(row_info.begin() + row); //&row_info[row]);
264 cell_info.erase(cell_info.begin() + row); //&cell_info[row]);
270 void LyXTabular::AppendColumn(int cell)
274 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
276 int const column = column_of_cell(cell);
277 column_vector::iterator cit = column_info.begin() + column + 1;
278 column_info.insert(cit, columnstruct());
279 // set the column values of the column before
280 column_info[column+1] = column_info[column];
282 for (int i = 0; i < rows_; ++i) {
283 for (int j = 0; j <= column; ++j) {
284 c_info[i][j] = cell_info[i][j];
286 for (int j = column + 1; j < columns_; ++j) {
287 c_info[i][j] = cell_info[i][j - 1];
289 // care about multicolumns
290 if (cell_info[i][column + 1].multicolumn==CELL_BEGIN_OF_MULTICOLUMN) {
291 cell_info[i][column + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
293 if ((column + 1) == columns_ ||
294 cell_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN) {
295 cell_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL;
300 for (int i = 0; i < rows_; ++i) {
301 //cell_info[i][column].inset.clear();
302 cell_info[i][column + 1].inset.clear();
308 void LyXTabular::DeleteColumn(int column)
310 // Similar to DeleteRow
311 //if (!(columns_ - 1))
313 if (columns_ == 1) return; // Not allowed to delete last column
315 column_info.erase(column_info.begin() + column);
316 for (int i = 0; i < rows_; ++i) {
317 cell_info[i].erase(cell_info[i].begin() + column);
324 void LyXTabular::Reinit()
326 for (int i = 0; i < rows_; ++i) {
327 for (int j = 0; j < columns_; ++j) {
328 cell_info[i][j].width_of_cell = 0;
329 cell_info[i][j].inset.setOwner(owner_);
333 for (int i = 0; i < columns_; ++i) {
334 calculate_width_of_column(i);
336 calculate_width_of_tabular();
338 set_row_column_number_info();
342 void LyXTabular::set_row_column_number_info(bool oldformat)
345 for (int row = 0; row < rows_; ++row) {
346 for (int column = 0; column<columns_; ++column) {
347 if (cell_info[row][column].multicolumn
348 != LyXTabular::CELL_PART_OF_MULTICOLUMN)
350 cell_info[row][column].cellno = numberofcells;
353 ++numberofcells; // because this is one more than as we start from 0
355 rowofcell.resize(numberofcells);
356 columnofcell.resize(numberofcells);
358 for (int row = 0, column = 0, c = 0;
359 c < numberofcells && row < rows_ && column < columns_;) {
361 columnofcell[c] = column;
365 } while (column < columns_ &&
366 cell_info[row][column].multicolumn
367 == LyXTabular::CELL_PART_OF_MULTICOLUMN);
368 if (column == columns_) {
374 for (int row = 0; row < rows_; ++row) {
375 for (int column = 0; column < columns_; ++column) {
376 if (IsPartOfMultiColumn(row,column))
378 // now set the right line of multicolumns right for oldformat read
380 cell_info[row][column].multicolumn==CELL_BEGIN_OF_MULTICOLUMN)
382 int cn=cells_in_multicolumn(cell_info[row][column].cellno);
383 cell_info[row][column].right_line =
384 cell_info[row][column+cn-1].right_line;
386 cell_info[row][column].inset.setAutoBreakRows(
387 !GetPWidth(GetCellNumber(row, column)).empty());
393 int LyXTabular::GetNumberOfCells() const
395 return numberofcells;
399 int LyXTabular::NumberOfCellsInRow(int cell) const
401 int const row = row_of_cell(cell);
403 for (int i = 0; i < columns_; ++i) {
404 if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
411 /* returns 1 if there is a topline, returns 0 if not */
412 bool LyXTabular::TopLine(int cell, bool onlycolumn) const
414 int const row = row_of_cell(cell);
416 if (!onlycolumn && IsMultiColumn(cell))
417 return cellinfo_of_cell(cell)->top_line;
418 return row_info[row].top_line;
422 bool LyXTabular::BottomLine(int cell, bool onlycolumn) const
424 // no bottom line underneath non-existent cells if you please
425 // Isn't that a programming error? Is so this should
426 // be an Assert instead. (Lgb)
427 if (cell >= numberofcells)
430 if (!onlycolumn && IsMultiColumn(cell))
431 return cellinfo_of_cell(cell)->bottom_line;
432 return row_info[row_of_cell(cell)].bottom_line;
436 bool LyXTabular::LeftLine(int cell, bool onlycolumn) const
438 if (!onlycolumn && IsMultiColumn(cell))
439 return cellinfo_of_cell(cell)->left_line;
440 return column_info[column_of_cell(cell)].left_line;
444 bool LyXTabular::RightLine(int cell, bool onlycolumn) const
446 if (!onlycolumn && IsMultiColumn(cell))
447 return cellinfo_of_cell(cell)->right_line;
448 return column_info[right_column_of_cell(cell)].right_line;
452 bool LyXTabular::TopAlreadyDrawed(int cell) const
454 int row = row_of_cell(cell);
455 if ((row > 0) && !GetAdditionalHeight(row)) {
456 int column = column_of_cell(cell);
459 && cell_info[row][column].multicolumn
460 == LyXTabular::CELL_PART_OF_MULTICOLUMN)
462 if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL)
463 return row_info[row].bottom_line;
465 return cell_info[row][column].bottom_line;
471 bool LyXTabular::LeftAlreadyDrawed(int cell) const
473 int column = column_of_cell(cell);
475 int row = row_of_cell(cell);
477 (cell_info[row][column].multicolumn ==
478 LyXTabular::CELL_PART_OF_MULTICOLUMN));
479 if (GetAdditionalWidth(cell_info[row][column].cellno))
481 return column_info[column].right_line;
487 bool LyXTabular::IsLastRow(int cell) const
489 return (row_of_cell(cell) == rows_ - 1);
493 int LyXTabular::GetAdditionalHeight(int row) const
495 if (!row || row >= rows_)
501 for (int column = 0; column < columns_ - 1 && bottom; ++column) {
502 switch (cell_info[row - 1][column].multicolumn) {
503 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
504 bottom = cell_info[row - 1][column].bottom_line;
506 case LyXTabular::CELL_NORMAL:
507 bottom = row_info[row - 1].bottom_line;
510 for (int column = 0; column < columns_ - 1 && top; ++column) {
511 switch (cell_info[row][column].multicolumn){
512 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
513 top = cell_info[row][column].top_line;
515 case LyXTabular::CELL_NORMAL:
516 top = row_info[row].top_line;
520 return WIDTH_OF_LINE;
525 int LyXTabular::GetAdditionalWidth(int cell) const
527 // internally already set in SetWidthOfCell
528 // used to get it back in text.C
529 int const col = right_column_of_cell(cell);
530 if (col < columns_ - 1 && column_info[col].right_line &&
531 column_info[col+1].left_line)
532 return WIDTH_OF_LINE;
538 // returns the maximum over all rows
539 int LyXTabular::GetWidthOfColumn(int cell) const
541 int const column1 = column_of_cell(cell);
542 int const column2 = right_column_of_cell(cell);
544 for (int i = column1; i <= column2; ++i) {
545 result += column_info[i].width_of_column;
551 int LyXTabular::GetWidthOfTabular() const
553 return width_of_tabular;
557 /* returns 1 if a complete update is necessary, otherwise 0 */
558 bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
560 if (!IsMultiColumn(cell))
563 int const row = row_of_cell(cell);
564 int const column1 = column_of_cell(cell);
565 int const column2 = right_column_of_cell(cell);
567 // first set columns to 0 so we can calculate the right width
568 for (int i = column1; i <= column2; ++i) {
569 cell_info[row][i].width_of_cell = 0;
571 // set the width to MAX_WIDTH until width > 0
572 int width = (new_width + 2 * WIDTH_OF_LINE);
575 for (; i < column2 && width > column_info[i].width_of_column; ++i) {
576 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
577 width -= column_info[i].width_of_column;
580 cell_info[row][i].width_of_cell = width;
586 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
588 int const row = row_of_cell(cell);
589 int const column1 = column_of_cell(cell);
590 int const column2 = right_column_of_cell(cell);
592 // first set columns to 0 so we can calculate the right width
594 for (; i <= column2; ++i)
595 cell_info[row][i].width_of_cell = 0;
596 for (i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
598 if (i < numberofcells)
599 recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
600 SetWidthOfMulticolCell(cell, new_width);
604 /* returns 1 if a complete update is necessary, otherwise 0 */
605 bool LyXTabular::SetWidthOfCell(int cell, int new_width)
607 int const row = row_of_cell(cell);
608 int const column1 = column_of_cell(cell);
612 if (GetWidthOfCell(cell) == (new_width+2*WIDTH_OF_LINE))
614 if (IsMultiColumn(cell, true)) {
615 tmp = SetWidthOfMulticolCell(cell, new_width);
617 width = (new_width + 2*WIDTH_OF_LINE);
618 cell_info[row][column1].width_of_cell = width;
619 if (column_info[column1].right_line && (column1 < columns_-1) &&
620 column_info[column1+1].left_line) // additional width
621 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
622 tmp = calculate_width_of_column_NMC(column1);
626 for (; i<columns_; ++i)
627 calculate_width_of_column_NMC(i);
628 for (i = 0; (i < numberofcells) && !IsMultiColumn(i); ++i)
630 if (i < numberofcells)
631 recalculateMulticolCells(i, GetWidthOfCell(i)-(2 * WIDTH_OF_LINE));
632 for (i = 0; i < columns_; ++i)
633 calculate_width_of_column(i);
634 calculate_width_of_tabular();
641 bool LyXTabular::SetAlignment(int cell, LyXAlignment align, bool onlycolumn)
643 if (!IsMultiColumn(cell) || onlycolumn)
644 column_info[column_of_cell(cell)].alignment = align;
646 cellinfo_of_cell(cell)->alignment = align;
651 bool LyXTabular::SetVAlignment(int cell, VAlignment align, bool onlycolumn)
653 if (!IsMultiColumn(cell) || onlycolumn)
654 column_info[column_of_cell(cell)].valignment = align;
656 cellinfo_of_cell(cell)->valignment = align;
661 bool LyXTabular::SetColumnPWidth(int cell, string const & width)
663 bool flag = !width.empty();
664 int const j = column_of_cell(cell);
666 column_info[j].p_width = width;
667 if (flag) // do this only if there is a width
668 SetAlignment(cell, LYX_ALIGN_LEFT);
669 for (int i = 0; i < rows_; ++i) {
670 int c = GetCellNumber(i, j);
671 flag = !GetPWidth(c).empty(); // because of multicolumns!
672 GetCellInset(c)->setAutoBreakRows(flag);
678 bool LyXTabular::SetMColumnPWidth(int cell, string const & width)
680 bool const flag = !width.empty();
682 cellinfo_of_cell(cell)->p_width = width;
683 if (IsMultiColumn(cell)) {
684 GetCellInset(cell)->setAutoBreakRows(flag);
691 bool LyXTabular::SetAlignSpecial(int cell, string const & special,
692 LyXTabular::Feature what)
694 if (what == SET_SPECIAL_MULTI)
695 cellinfo_of_cell(cell)->align_special = special;
697 column_info[column_of_cell(cell)].align_special = special;
702 bool LyXTabular::SetAllLines(int cell, bool line)
704 SetTopLine(cell, line);
705 SetBottomLine(cell, line);
706 SetRightLine(cell, line);
707 SetLeftLine(cell, line);
712 bool LyXTabular::SetTopLine(int cell, bool line, bool onlycolumn)
714 int const row = row_of_cell(cell);
716 if (onlycolumn || !IsMultiColumn(cell))
717 row_info[row].top_line = line;
719 cellinfo_of_cell(cell)->top_line = line;
724 bool LyXTabular::SetBottomLine(int cell, bool line, bool onlycolumn)
726 if (onlycolumn || !IsMultiColumn(cell))
727 row_info[row_of_cell(cell)].bottom_line = line;
729 cellinfo_of_cell(cell)->bottom_line = line;
734 bool LyXTabular::SetLeftLine(int cell, bool line, bool onlycolumn)
736 if (onlycolumn || !IsMultiColumn(cell))
737 column_info[column_of_cell(cell)].left_line = line;
739 cellinfo_of_cell(cell)->left_line = line;
744 bool LyXTabular::SetRightLine(int cell, bool line, bool onlycolumn)
746 if (onlycolumn || !IsMultiColumn(cell))
747 column_info[right_column_of_cell(cell)].right_line = line;
749 cellinfo_of_cell(cell)->right_line = line;
754 LyXAlignment LyXTabular::GetAlignment(int cell, bool onlycolumn) const
756 if (!onlycolumn && IsMultiColumn(cell))
757 return cellinfo_of_cell(cell)->alignment;
759 return column_info[column_of_cell(cell)].alignment;
763 LyXTabular::VAlignment
764 LyXTabular::GetVAlignment(int cell, bool onlycolumn) const
766 if (!onlycolumn && IsMultiColumn(cell))
767 return cellinfo_of_cell(cell)->valignment;
769 return column_info[column_of_cell(cell)].valignment;
773 string const LyXTabular::GetPWidth(int cell) const
775 if (IsMultiColumn(cell))
776 return cellinfo_of_cell(cell)->p_width;
777 return column_info[column_of_cell(cell)].p_width;
781 string const LyXTabular::GetColumnPWidth(int cell) const
783 return column_info[column_of_cell(cell)].p_width;
787 string const LyXTabular::GetMColumnPWidth(int cell) const
789 if (IsMultiColumn(cell))
790 return cellinfo_of_cell(cell)->p_width;
795 string const LyXTabular::GetAlignSpecial(int cell, int what) const
797 if (what == SET_SPECIAL_MULTI)
798 return cellinfo_of_cell(cell)->align_special;
799 return column_info[column_of_cell(cell)].align_special;
803 int LyXTabular::GetWidthOfCell(int cell) const
805 int const row = row_of_cell(cell);
806 int const column1 = column_of_cell(cell);
807 int const column2 = right_column_of_cell(cell);
809 for (int i = column1; i <= column2; ++i) {
810 result += cell_info[row][i].width_of_cell;
816 int LyXTabular::GetBeginningOfTextInCell(int cell) const
820 switch (GetAlignment(cell)){
821 case LYX_ALIGN_CENTER:
822 x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
824 case LYX_ALIGN_RIGHT:
825 x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
826 // + GetAdditionalWidth(cell);
828 default: /* LYX_ALIGN_LEFT: nothing :-) */
838 bool LyXTabular::IsFirstCellInRow(int cell) const
840 return column_of_cell(cell) == 0;
844 int LyXTabular::GetFirstCellInRow(int row) const
848 return cell_info[row][0].cellno;
851 bool LyXTabular::IsLastCellInRow(int cell) const
853 return (right_column_of_cell(cell) == (columns_ - 1));
857 int LyXTabular::GetLastCellInRow(int row) const
861 return cell_info[row][columns_-1].cellno;
865 bool LyXTabular::calculate_width_of_column(int column)
867 int const old_column_width = column_info[column].width_of_column;
870 for (int i = 0; i < rows_; ++i) {
871 maximum = max(cell_info[i][column].width_of_cell, maximum);
873 column_info[column].width_of_column = maximum;
874 return (column_info[column].width_of_column != old_column_width);
879 // calculate the with of the column without regarding REAL MultiColumn
880 // cells. This means MultiColumn-cells spanning more than 1 column.
882 bool LyXTabular::calculate_width_of_column_NMC(int column)
884 int const old_column_width = column_info[column].width_of_column;
886 for (int i = 0; i < rows_; ++i) {
887 if (!IsMultiColumn(GetCellNumber(i, column), true) &&
888 (cell_info[i][column].width_of_cell > max)) {
889 max = cell_info[i][column].width_of_cell;
892 column_info[column].width_of_column = max;
893 return (column_info[column].width_of_column != old_column_width);
897 void LyXTabular::calculate_width_of_tabular()
899 width_of_tabular = 0;
900 for (int i = 0; i < columns_; ++i) {
901 width_of_tabular += column_info[i].width_of_column;
906 int LyXTabular::row_of_cell(int cell) const
908 if (cell >= numberofcells)
912 return rowofcell[cell];
916 int LyXTabular::column_of_cell(int cell) const
918 if (cell >= numberofcells)
922 return columnofcell[cell];
926 int LyXTabular::right_column_of_cell(int cell) const
928 int const row = row_of_cell(cell);
929 int column = column_of_cell(cell);
930 while (column < (columns_ - 1) &&
931 cell_info[row][column + 1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
937 // Perfect case for a template... (Lgb)
941 string const write_attribute(string const & name, T const & t)
943 string str = " " + name + "=\"" + tostr(t) + "\"";
948 string const write_attribute(string const & name, bool const & b)
950 return write_attribute(name, int(b));
955 string const write_attribute(string const & name, int value)
957 string str = " " + name + "=\"" + tostr(value) + "\"";
962 string const write_attribute(string const & name, string const & value)
964 string str = " " + name + "=\"" + value + "\"";
969 string const write_attribute(string const & name, bool value)
971 string str = " " + name + "=\"" + tostr(static_cast<int>(value)) + "\"";
979 string const tostr(LyXAlignment const & num)
984 case LYX_ALIGN_BLOCK:
988 case LYX_ALIGN_CENTER:
990 case LYX_ALIGN_RIGHT:
992 case LYX_ALIGN_LAYOUT:
994 case LYX_ALIGN_SPECIAL:
1003 string const tostr(LyXTabular::VAlignment const & num)
1006 case LyXTabular::LYX_VALIGN_TOP:
1008 case LyXTabular::LYX_VALIGN_CENTER:
1010 case LyXTabular::LYX_VALIGN_BOTTOM:
1019 string const tostr(LyXTabular::BoxType const & num)
1022 case LyXTabular::BOX_NONE:
1024 case LyXTabular::BOX_PARBOX:
1026 case LyXTabular::BOX_MINIPAGE:
1033 void LyXTabular::Write(Buffer const * buf, ostream & os) const
1037 << write_attribute("version", 2)
1038 << write_attribute("rows", rows_)
1039 << write_attribute("columns", columns_)
1041 // global longtable options
1043 << write_attribute("rotate", tostr(rotate))
1044 << write_attribute("islongtable", tostr(is_long_tabular))
1045 << write_attribute("endhead", endhead)
1046 << write_attribute("endfirsthead", endfirsthead)
1047 << write_attribute("endfoot", endfoot)
1048 << write_attribute("endlastfoot", endlastfoot)
1050 for (int j = 0; j < columns_; ++j) {
1052 << write_attribute("alignment", tostr(column_info[j].alignment))
1053 << write_attribute("valignment", tostr(column_info[j].valignment))
1054 << write_attribute("leftline", tostr(column_info[j].left_line))
1055 << write_attribute("rightline", tostr(column_info[j].right_line))
1056 << write_attribute("width",
1057 VSpace(column_info[j].p_width)
1059 << write_attribute("special", column_info[j].align_special)
1062 for (int i = 0; i < rows_; ++i) {
1064 << write_attribute("topline", tostr(row_info[i].top_line))
1065 << write_attribute("bottomline", tostr(row_info[i].bottom_line))
1066 << write_attribute("newpage", tostr(row_info[i].newpage))
1068 for (int j = 0; j < columns_; ++j) {
1070 << write_attribute("multicolumn", cell_info[i][j].multicolumn)
1071 << write_attribute("alignment", tostr(cell_info[i][j].alignment))
1072 << write_attribute("valignment", tostr(cell_info[i][j].valignment))
1073 << write_attribute("topline", tostr(cell_info[i][j].top_line))
1074 << write_attribute("bottomline", tostr(cell_info[i][j].bottom_line))
1075 << write_attribute("leftline", tostr(cell_info[i][j].left_line))
1076 << write_attribute("rightline", tostr(cell_info[i][j].right_line))
1077 << write_attribute("rotate", tostr(cell_info[i][j].rotate))
1078 << write_attribute("usebox", tostr(cell_info[i][j].usebox))
1079 << write_attribute("width", cell_info[i][j].p_width)
1080 << write_attribute("special", cell_info[i][j].align_special)
1082 os << "\\begin_inset ";
1083 cell_info[i][j].inset.write(buf, os);
1084 os << "\n\\end_inset \n"
1089 os << "</lyxtabular>\n";
1095 // I would have liked a fromstr template a lot better. (Lgb)
1098 bool string2type(string const str, LyXAlignment & num)
1101 num = LYX_ALIGN_NONE;
1102 else if (str == "block")
1103 num = LYX_ALIGN_BLOCK;
1104 else if (str == "left")
1105 num = LYX_ALIGN_LEFT;
1106 else if (str == "center")
1107 num = LYX_ALIGN_CENTER;
1108 else if (str == "right")
1109 num = LYX_ALIGN_RIGHT;
1117 bool string2type(string const str, LyXTabular::VAlignment & num)
1120 num = LyXTabular::LYX_VALIGN_TOP;
1121 else if (str == "center")
1122 num = LyXTabular::LYX_VALIGN_CENTER;
1123 else if (str == "bottom")
1124 num = LyXTabular::LYX_VALIGN_BOTTOM;
1132 bool string2type(string const str, LyXTabular::BoxType & num)
1135 num = LyXTabular::BOX_NONE;
1136 else if (str == "parbox")
1137 num = LyXTabular::BOX_PARBOX;
1138 else if (str == "minipage")
1139 num = LyXTabular::BOX_MINIPAGE;
1147 bool string2type(string const str, bool & num)
1151 else if (str == "false")
1159 bool getTokenValue(string const & str, const char * token, string & ret)
1161 size_t token_length = strlen(token);
1162 string::size_type pos = str.find(token);
1164 if (pos == string::npos || pos + token_length + 1 >= str.length()
1165 || str[pos + token_length] != '=')
1168 pos += token_length + 1;
1170 if ((ch != '"') && (ch != '\'')) { // only read till next space
1174 while((pos < str.length() - 1) && (str[++pos] != ch))
1181 bool getTokenValue(string const & str, const char * token, int & num)
1184 if (!getTokenValue(str, token, tmp))
1186 num = strToInt(tmp);
1191 bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
1194 if (!getTokenValue(str, token, tmp))
1196 return string2type(tmp, num);
1200 bool getTokenValue(string const & str, const char * token,
1201 LyXTabular::VAlignment & num)
1204 if (!getTokenValue(str, token, tmp))
1206 return string2type(tmp, num);
1210 bool getTokenValue(string const & str, const char * token,
1211 LyXTabular::BoxType & num)
1214 if (!getTokenValue(str, token, tmp))
1216 return string2type(tmp, num);
1220 bool getTokenValue(string const & str, const char * token, bool & flag)
1223 if (!getTokenValue(str, token, tmp))
1225 return string2type(tmp, flag);
1230 void l_getline(istream & is, string & str)
1233 while (str.empty()) {
1235 if (!str.empty() && str[str.length() - 1] == '\r')
1236 str.erase(str.length() - 1);
1243 void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
1246 istream & is = lex.getStream();
1248 l_getline(is, line);
1249 if (!prefixIs(line, "<lyxtabular ")
1250 && !prefixIs(line, "<LyXTabular ")) {
1251 OldFormatRead(lex, line);
1256 if (!getTokenValue(line, "version", version))
1259 ReadOld(buf, is, lex, line);
1260 else if (version == 2)
1261 ReadNew(buf, is, lex, line);
1265 void LyXTabular::ReadNew(Buffer const * buf, istream & is,
1266 LyXLex & lex, string const & l)
1270 if (!getTokenValue(line, "rows", rows_arg))
1273 if (!getTokenValue(line, "columns", columns_arg))
1275 Init(rows_arg, columns_arg);
1276 l_getline(is, line);
1277 if (!prefixIs(line, "<features")) {
1278 lyxerr << "Wrong tabular format (expected <features ...> got" <<
1279 line << ")" << endl;
1282 getTokenValue(line, "rotate", rotate);
1283 getTokenValue(line, "islongtable", is_long_tabular);
1284 getTokenValue(line, "endhead", endhead);
1285 getTokenValue(line, "endfirsthead", endfirsthead);
1286 getTokenValue(line, "endfoot", endfoot);
1287 getTokenValue(line, "endlastfoot", endlastfoot);
1289 for (int j = 0; j < columns_; ++j) {
1291 if (!prefixIs(line,"<column")) {
1292 lyxerr << "Wrong tabular format (expected <column ...> got" <<
1293 line << ")" << endl;
1296 getTokenValue(line, "alignment", column_info[j].alignment);
1297 getTokenValue(line, "valignment", column_info[j].valignment);
1298 getTokenValue(line, "leftline", column_info[j].left_line);
1299 getTokenValue(line, "rightline", column_info[j].right_line);
1300 getTokenValue(line, "width", column_info[j].p_width);
1301 getTokenValue(line, "special", column_info[j].align_special);
1304 for (int i = 0; i < rows_; ++i) {
1305 l_getline(is, line);
1306 if (!prefixIs(line, "<row")) {
1307 lyxerr << "Wrong tabular format (expected <row ...> got" <<
1308 line << ")" << endl;
1311 getTokenValue(line, "topline", row_info[i].top_line);
1312 getTokenValue(line, "bottomline", row_info[i].bottom_line);
1313 getTokenValue(line, "newpage", row_info[i].newpage);
1314 for (int j = 0; j < columns_; ++j) {
1315 l_getline(is, line);
1316 if (!prefixIs(line, "<cell")) {
1317 lyxerr << "Wrong tabular format (expected <cell ...> got" <<
1318 line << ")" << endl;
1321 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1322 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1323 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1324 getTokenValue(line, "topline", cell_info[i][j].top_line);
1325 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1326 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1327 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1328 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1329 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1330 getTokenValue(line, "width", cell_info[i][j].p_width);
1331 getTokenValue(line, "special", cell_info[i][j].align_special);
1332 l_getline(is, line);
1333 if (prefixIs(line, "\\begin_inset")) {
1334 cell_info[i][j].inset.read(buf, lex);
1335 l_getline(is, line);
1337 if (!prefixIs(line, "</cell>")) {
1338 lyxerr << "Wrong tabular format (expected </cell> got" <<
1339 line << ")" << endl;
1343 l_getline(is, line);
1344 if (!prefixIs(line, "</row>")) {
1345 lyxerr << "Wrong tabular format (expected </row> got" <<
1346 line << ")" << endl;
1350 while (!prefixIs(line, "</lyxtabular>")) {
1351 l_getline(is, line);
1353 set_row_column_number_info();
1357 void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
1363 int columns_arg = 0;
1364 int is_long_tabular_arg = false;
1365 int rotate_arg = false;
1374 istream & is = lex.getStream();
1377 version = lyx::atoi(s.substr(8, string::npos));
1381 vector<int> cont_row_info;
1384 lyxerr << "Tabular format < 5 is not supported anymore\n"
1385 "Get an older version of LyX (< 1.1.x) for conversion!"
1387 WriteAlert(_("Warning:"),
1388 _("Tabular format < 5 is not supported anymore\n"),
1389 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1391 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1392 >> rotate_arg >> a >> b >> c >> d;
1394 is >> rows_arg >> columns_arg;
1395 Init(rows_arg, columns_arg);
1396 cont_row_info = vector<int>(rows_arg);
1397 SetLongTabular(is_long_tabular_arg);
1398 SetRotateTabular(rotate_arg);
1400 for (i = 0; i < rows_; ++i) {
1402 cont_row_info[i] = false;
1404 for (i = 0; i < columns_; ++i) {
1407 for (i = 0; i < rows_; ++i) {
1408 for (j = 0; j < columns_; ++j) {
1413 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1414 >> rotate_arg >> a >> b >> c >> d;
1415 Init(rows_arg, columns_arg);
1416 cont_row_info = vector<int>(rows_arg);
1417 SetLongTabular(is_long_tabular_arg);
1418 SetRotateTabular(rotate_arg);
1420 endfirsthead = b + 1;
1422 endlastfoot = d + 1;
1423 for (i = 0; i < rows_; ++i) {
1424 a = b = c = d = e = f = g = 0;
1425 is >> a >> b >> c >> d;
1426 row_info[i].top_line = a;
1427 row_info[i].bottom_line = b;
1428 cont_row_info[i] = c;
1429 row_info[i].newpage = d;
1431 for (i = 0; i < columns_; ++i) {
1436 char ch; // skip '"'
1439 // ignore is buggy but we will use it later (Lgb)
1440 is.ignore(); // skip '"'
1442 getline(is, s1, '"');
1444 is >> ch; // skip '"'
1446 // ignore is buggy but we will use it later (Lgb)
1447 is.ignore(); // skip '"'
1449 getline(is, s2, '"');
1450 column_info[i].alignment = static_cast<LyXAlignment>(a);
1451 column_info[i].left_line = b;
1452 column_info[i].right_line = c;
1453 column_info[i].p_width = s1;
1454 column_info[i].align_special = s2;
1456 for (i = 0; i < rows_; ++i) {
1457 for (j = 0; j < columns_; ++j) {
1460 is >> a >> b >> c >> d >> e >> f >> g;
1463 is >> ch; // skip '"'
1465 // ignore is buggy but we will use it later (Lgb)
1466 is.ignore(); // skip '"'
1468 getline(is, s1, '"');
1470 is >> ch; // skip '"'
1472 // ignore is buggy but we will use it later (Lgb)
1473 is.ignore(); // skip '"'
1475 getline(is, s2, '"');
1476 cell_info[i][j].multicolumn = static_cast<char>(a);
1477 cell_info[i][j].alignment = static_cast<LyXAlignment>(b);
1478 cell_info[i][j].top_line = static_cast<char>(c);
1479 cell_info[i][j].bottom_line = static_cast<char>(d);
1480 cell_info[i][j].left_line = column_info[j].left_line;
1481 cell_info[i][j].right_line = column_info[j].right_line;
1482 cell_info[i][j].rotate = static_cast<bool>(f);
1483 cell_info[i][j].usebox = static_cast<BoxType>(g);
1484 cell_info[i][j].align_special = s1;
1485 cell_info[i][j].p_width = s2;
1489 set_row_column_number_info(true);
1491 Paragraph * par = new Paragraph;
1492 Paragraph * return_par = 0;
1496 Paragraph::depth_type depth = 0;
1497 LyXFont font(LyXFont::ALL_INHERIT);
1498 font.setLanguage(owner_->bufferOwner()->getLanguage());
1500 while (lex.IsOK()) {
1502 string const token = lex.GetString();
1505 if (token == "\\layout"
1506 || token == "\\end_float"
1507 || token == "\\end_deeper") {
1508 lex.pushToken(token);
1509 // Here we need to insert the inset_ert_contents into the last
1510 // cell of the tabular.
1511 owner_->bufferOwner()->insertErtContents(par, pos, font);
1515 if (owner_->bufferOwner()->parseSingleLyXformat2Token(lex, par,
1520 lex.pushToken(token);
1524 lex.printError("New Paragraph allocated! This should not happen!");
1525 lex.pushToken(token);
1531 // now we have the par we should fill the insets with this!
1533 InsetText * inset = GetCellInset(cell);
1536 for (int i = 0; i < par->size(); ++i) {
1537 if (par->isNewline(i)) {
1539 if (cell > numberofcells) {
1540 lyxerr << "Some error in reading old table format occured!" <<
1541 endl << "Terminating when reading cell[" << cell << "]!" <<
1546 row = row_of_cell(cell);
1547 if (cont_row_info[row]) {
1549 cont_row_info.erase(cont_row_info.begin() + row); //&cont_row_info[row]);
1550 while(!IsFirstCellInRow(--cell));
1552 inset = GetCellInset(cell);
1555 inset = GetCellInset(cell);
1556 row = row_of_cell(cell);
1557 if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox)
1559 // insert a space instead
1561 par->insertChar(i, ' ');
1564 par->copyIntoMinibuffer(*owner_->bufferOwner(), i);
1565 inset->paragraph()->insertFromMinibuffer(inset->paragraph()->size());
1572 bool LyXTabular::IsMultiColumn(int cell, bool real) const
1574 return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&
1575 (cellinfo_of_cell(cell)->multicolumn != LyXTabular::CELL_NORMAL));
1579 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1581 int const row = row_of_cell(cell);
1582 int const column = column_of_cell(cell);
1583 return &cell_info[row][column];
1587 void LyXTabular::SetMultiColumn(int cell, int number)
1589 cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1590 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1591 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1592 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1593 for (number--; number > 0; --number) {
1594 cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
1596 set_row_column_number_info();
1600 int LyXTabular::cells_in_multicolumn(int cell) const
1602 int const row = row_of_cell(cell);
1603 int column = column_of_cell(cell);
1606 while ((column < columns_) &&
1607 cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
1616 int LyXTabular::UnsetMultiColumn(int cell)
1618 int const row = row_of_cell(cell);
1619 int column = column_of_cell(cell);
1623 if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
1624 cell_info[row][column].multicolumn = CELL_NORMAL;
1626 while ((column < columns_) &&
1627 (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN))
1629 cell_info[row][column].multicolumn = CELL_NORMAL;
1634 set_row_column_number_info();
1639 void LyXTabular::SetLongTabular(bool what)
1641 is_long_tabular = what;
1645 bool LyXTabular::IsLongTabular() const
1647 return is_long_tabular;
1651 void LyXTabular::SetRotateTabular(bool flag)
1657 bool LyXTabular::GetRotateTabular() const
1663 void LyXTabular::SetRotateCell(int cell, bool flag)
1665 cellinfo_of_cell(cell)->rotate = flag;
1669 bool LyXTabular::GetRotateCell(int cell) const
1671 return cellinfo_of_cell(cell)->rotate;
1675 bool LyXTabular::NeedRotating() const
1679 for (int i = 0; i < rows_; ++i) {
1680 for (int j = 0; j < columns_; ++j) {
1681 if (cell_info[i][j].rotate)
1689 bool LyXTabular::IsLastCell(int cell) const
1691 if ((cell + 1) < numberofcells)
1697 int LyXTabular::GetCellAbove(int cell) const
1699 if (row_of_cell(cell) > 0)
1700 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
1705 int LyXTabular::GetCellBelow(int cell) const
1707 if (row_of_cell(cell) + 1 < rows_)
1708 return cell_info[row_of_cell(cell)+1][column_of_cell(cell)].cellno;
1713 int LyXTabular::GetLastCellAbove(int cell) const
1715 if (row_of_cell(cell) <= 0)
1717 if (!IsMultiColumn(cell))
1718 return GetCellAbove(cell);
1719 return cell_info[row_of_cell(cell) - 1][right_column_of_cell(cell)].cellno;
1723 int LyXTabular::GetLastCellBelow(int cell) const
1725 if (row_of_cell(cell) + 1 >= rows_)
1727 if (!IsMultiColumn(cell))
1728 return GetCellBelow(cell);
1729 return cell_info[row_of_cell(cell) + 1][right_column_of_cell(cell)].cellno;
1733 int LyXTabular::GetCellNumber(int row, int column) const
1736 if (column >= columns_)
1737 column = columns_ - 1;
1738 else if (column < 0)
1745 lyx::Assert(column >= 0 || column < columns_ || row >= 0 || row < rows_);
1747 return cell_info[row][column].cellno;
1751 void LyXTabular::SetUsebox(int cell, BoxType type)
1753 cellinfo_of_cell(cell)->usebox = type;
1757 LyXTabular::BoxType LyXTabular::GetUsebox(int cell) const
1759 if (column_info[column_of_cell(cell)].p_width.empty() &&
1760 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
1762 if (cellinfo_of_cell(cell)->usebox > 1)
1763 return cellinfo_of_cell(cell)->usebox;
1764 return UseParbox(cell);
1768 void LyXTabular::SetLTHead(int cell, bool first)
1770 int const row = row_of_cell(cell);
1771 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1774 if (endfirsthead == val)
1787 bool LyXTabular::GetRowOfLTHead(int cell, int & row) const
1790 if (abs(endhead) > rows_)
1792 return (row_of_cell(cell) == abs(endhead) - 1);
1796 bool LyXTabular::GetRowOfLTFirstHead(int cell, int & row) const
1799 if (abs(endfirsthead) > rows_)
1801 return (row_of_cell(cell) == abs(endfirsthead) - 1);
1805 void LyXTabular::SetLTFoot(int cell, bool last)
1807 int const row = row_of_cell(cell);
1808 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1811 if (endlastfoot == val)
1824 bool LyXTabular::GetRowOfLTFoot(int cell, int & row) const
1827 if ((endfoot + 1) > rows_)
1829 return (row_of_cell(cell) == abs(endfoot) - 1);
1833 bool LyXTabular::GetRowOfLTLastFoot(int cell, int & row) const
1836 if (abs(endlastfoot) > rows_)
1838 return (row_of_cell(cell) == (abs(endlastfoot)-1));
1842 void LyXTabular::SetLTNewPage(int cell, bool what)
1844 row_info[row_of_cell(cell)].newpage = what;
1848 bool LyXTabular::GetLTNewPage(int cell) const
1850 return row_info[row_of_cell(cell)].newpage;
1854 bool LyXTabular::SetAscentOfRow(int row, int height)
1856 if ((row >= rows_) || (row_info[row].ascent_of_row == height))
1858 row_info[row].ascent_of_row = height;
1863 bool LyXTabular::SetDescentOfRow(int row, int height)
1865 if ((row >= rows_) || (row_info[row].descent_of_row == height))
1867 row_info[row].descent_of_row = height;
1872 int LyXTabular::GetAscentOfRow(int row) const
1876 return row_info[row].ascent_of_row;
1880 int LyXTabular::GetDescentOfRow(int row) const
1884 return row_info[row].descent_of_row;
1888 int LyXTabular::GetHeightOfTabular() const
1892 for (int row = 0; row < rows_; ++row)
1893 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
1894 GetAdditionalHeight(row);
1899 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
1901 if ((row >= rows_) || (column >= columns_))
1903 return (cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN);
1907 int LyXTabular::TeXTopHLine(ostream & os, int row) const
1909 if ((row < 0) || (row >= rows_))
1912 int const fcell = GetFirstCellInRow(row);
1913 int const n = NumberOfCellsInRow(fcell) + fcell;
1916 for (int i = fcell; i < n; ++i) {
1920 if (tmp == (n - fcell)){
1923 for (int i = fcell; i < n; ++i) {
1926 << column_of_cell(i) + 1
1928 << right_column_of_cell(i) + 1
1940 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
1942 if ((row < 0) || (row >= rows_))
1945 int const fcell = GetFirstCellInRow(row);
1946 int const n = NumberOfCellsInRow(fcell) + fcell;
1949 for (int i = fcell; i < n; ++i) {
1953 if (tmp == (n-fcell)){
1956 for (int i = fcell; i < n; ++i) {
1957 if (BottomLine(i)) {
1959 << column_of_cell(i) + 1
1961 << right_column_of_cell(i) + 1
1973 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
1977 if (GetRotateCell(cell)) {
1978 os << "\\begin{sideways}\n";
1981 if (IsMultiColumn(cell)) {
1982 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
1983 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1984 os << cellinfo_of_cell(cell)->align_special << "}{";
1986 if (LeftLine(cell) &&
1987 (IsFirstCellInRow(cell) ||
1988 (!IsMultiColumn(cell-1) && !LeftLine(cell, true) &&
1989 !RightLine(cell-1, true))))
1993 if (!GetPWidth(cell).empty()) {
1994 switch (GetVAlignment(cell)) {
1995 case LYX_VALIGN_TOP:
1998 case LYX_VALIGN_CENTER:
2001 case LYX_VALIGN_BOTTOM:
2005 os << "{" << GetPWidth(cell) << '}';
2007 switch (GetAlignment(cell)) {
2008 case LYX_ALIGN_LEFT:
2011 case LYX_ALIGN_RIGHT:
2019 if (RightLine(cell))
2021 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
2027 if (GetUsebox(cell) == BOX_PARBOX) {
2029 switch (GetVAlignment(cell)) {
2030 case LYX_VALIGN_TOP:
2033 case LYX_VALIGN_CENTER:
2036 case LYX_VALIGN_BOTTOM:
2040 os << "]{" << GetPWidth(cell) << "}{";
2041 } else if (GetUsebox(cell) == BOX_MINIPAGE) {
2042 os << "\\begin{minipage}[";
2043 switch (GetVAlignment(cell)) {
2044 case LYX_VALIGN_TOP:
2047 case LYX_VALIGN_CENTER:
2050 case LYX_VALIGN_BOTTOM:
2054 os << "]{" << GetPWidth(cell) << "}\n";
2061 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
2066 if (GetUsebox(cell) == BOX_PARBOX)
2068 else if (GetUsebox(cell) == BOX_MINIPAGE) {
2069 os << "%\n\\end{minipage}";
2072 if (IsMultiColumn(cell)){
2075 if (GetRotateCell(cell)) {
2076 os << "%\n\\end{sideways}";
2083 int LyXTabular::Latex(Buffer const * buf,
2084 ostream & os, bool fragile, bool fp) const
2089 //+---------------------------------------------------------------------
2090 //+ first the opening preamble +
2091 //+---------------------------------------------------------------------
2094 os << "\\begin{sideways}\n";
2097 if (is_long_tabular)
2098 os << "\\begin{longtable}{";
2100 os << "\\begin{tabular}{";
2101 for (int i = 0; i < columns_; ++i) {
2102 if (column_info[i].left_line)
2104 if (!column_info[i].align_special.empty()) {
2105 os << column_info[i].align_special;
2106 } else if (!column_info[i].p_width.empty()) {
2107 switch (column_info[i].valignment) {
2108 case LYX_VALIGN_TOP:
2111 case LYX_VALIGN_CENTER:
2114 case LYX_VALIGN_BOTTOM:
2119 << column_info[i].p_width
2122 switch (column_info[i].alignment) {
2123 case LYX_ALIGN_LEFT:
2126 case LYX_ALIGN_RIGHT:
2134 if (column_info[i].right_line)
2140 //+---------------------------------------------------------------------
2141 //+ the single row and columns (cells) +
2142 //+---------------------------------------------------------------------
2144 for (int i = 0; i < rows_; ++i) {
2145 ret += TeXTopHLine(os, i);
2147 if (IsLongTabular()) {
2148 if ((endhead < 0) && (i == (abs(endhead)-1))) {
2149 os << "\\endhead\n";
2152 if ((endfirsthead < 0) && (i == (abs(endfirsthead)-1))) {
2153 os << "\\endfirsthead\n";
2156 if ((endfoot < 0) && (i == (abs(endfoot)-1))) {
2157 os << "\\endfoot\n";
2160 if ((endlastfoot < 0) && (i == (abs(endlastfoot)-1))) {
2161 os << "\\endlastfoot\n";
2166 ret += TeXBottomHLine(os, i-1);
2167 ret += TeXTopHLine(os, i);
2169 for (int j = 0; j < columns_; ++j) {
2170 if (IsPartOfMultiColumn(i,j))
2172 ret += TeXCellPreamble(os, cell);
2173 InsetText * inset = GetCellInset(cell);
2175 bool rtl = inset->paragraph()->isRightToLeftPar(buf->params) &&
2176 inset->paragraph()->size() > 0 && GetPWidth(cell).empty();
2180 ret += inset->latex(buf, os, fragile, fp);
2184 ret += TeXCellPostamble(os, cell);
2185 if (!IsLastCellInRow(cell)) { // not last cell in row
2192 ret += TeXBottomHLine(os, i);
2194 if (IsLongTabular()) {
2195 if ((endhead > 0) && (i == (endhead - 1))) {
2196 os << "\\endhead\n";
2199 if ((endfirsthead > 0) && (i == (endfirsthead - 1))) {
2200 os << "\\endfirsthead\n";
2203 if ((endfoot > 0) && (i == (endfoot - 1))) {
2204 os << "\\endfoot\n";
2207 if ((endlastfoot > 0) && (i == (endlastfoot - 1))) {
2208 os << "\\endlastfoot\n";
2212 // ret += TeXBottomHLine(os, i);
2213 if (row_info[i].newpage) {
2214 os << "\\newpage\n";
2220 //+---------------------------------------------------------------------
2221 //+ the closing of the tabular +
2222 //+---------------------------------------------------------------------
2224 if (is_long_tabular)
2225 os << "\\end{longtable}";
2227 os << "\\end{tabular}";
2229 os << "\n\\end{sideways}";
2237 int LyXTabular::DocBook(Buffer const * buf, ostream & os) const
2241 //+---------------------------------------------------------------------
2242 //+ first the opening preamble +
2243 //+---------------------------------------------------------------------
2245 os << "<tgroup cols=\"" << columns_
2246 << "\" colsep=\"1\" rowsep=\"1\">\n";
2248 for (int i = 0; i < columns_; ++i) {
2249 os << "<colspec colname=\"col" << i << "\" align=\"";
2250 switch (column_info[i].alignment) {
2251 case LYX_ALIGN_LEFT:
2254 case LYX_ALIGN_RIGHT:
2265 //+---------------------------------------------------------------------
2266 //+ the single row and columns (cells) +
2267 //+---------------------------------------------------------------------
2271 for (int i = 0; i < rows_; ++i) {
2273 for (int j = 0; j < columns_; ++j) {
2274 if (IsPartOfMultiColumn(i, j))
2277 os << "<entry align=\"";
2278 switch (GetAlignment(cell)) {
2279 case LYX_ALIGN_LEFT:
2282 case LYX_ALIGN_RIGHT:
2290 os << "\" valign=\"";
2291 switch (GetVAlignment(cell)) {
2292 case LYX_VALIGN_TOP:
2295 case LYX_VALIGN_BOTTOM:
2298 case LYX_VALIGN_CENTER:
2303 if (IsMultiColumn(cell)) {
2304 os << " namest=\"col" << j << "\" ";
2305 os << "nameend=\"col" << j + cells_in_multicolumn(cell) - 1<< "\"";
2309 ret += GetCellInset(cell)->docBook(buf, os);
2316 //+---------------------------------------------------------------------
2317 //+ the closing of the tabular +
2318 //+---------------------------------------------------------------------
2330 void print_n_chars(ostream & os, unsigned char ch, int n)
2332 os << string(n, ch);
2338 int LyXTabular::AsciiTopHLine(ostream & os, int row,
2339 vector<unsigned int> const & clen) const
2341 int const fcell = GetFirstCellInRow(row);
2342 int const n = NumberOfCellsInRow(fcell) + fcell;
2345 for (int i = fcell; i < n; ++i) {
2355 for (int i = fcell; i < n; ++i) {
2366 int column = column_of_cell(i);
2367 int len = clen[column];
2368 while(IsPartOfMultiColumn(row, ++column))
2369 len += clen[column] + 4;
2370 print_n_chars(os, ch, len);
2385 int LyXTabular::AsciiBottomHLine(ostream & os, int row,
2386 vector<unsigned int> const & clen) const
2388 int const fcell = GetFirstCellInRow(row);
2389 int const n = NumberOfCellsInRow(fcell) + fcell;
2392 for (int i = fcell; i < n; ++i) {
2393 if (BottomLine(i)) {
2402 for (int i = fcell; i < n; ++i) {
2403 if (BottomLine(i)) {
2413 int column = column_of_cell(i);
2414 int len = clen[column];
2415 while(IsPartOfMultiColumn(row, ++column))
2416 len += clen[column] + 4;
2417 print_n_chars(os, ch, len);
2418 if (BottomLine(i)) {
2432 int LyXTabular::AsciiPrintCell(Buffer const * buf, ostream & os,
2433 int cell, int row, int column,
2434 vector<unsigned int> const & clen) const
2437 int ret = GetCellInset(cell)->ascii(buf, sstr, 0);
2444 unsigned int len1 = sstr.str().length();
2445 unsigned int len2 = clen[column];
2446 while(IsPartOfMultiColumn(row, ++column))
2447 len2 += clen[column] + 4;
2450 switch (GetAlignment(cell)) {
2452 case LYX_ALIGN_LEFT:
2455 case LYX_ALIGN_RIGHT:
2459 case LYX_ALIGN_CENTER:
2465 for (unsigned int i = 0; i < len1; ++i)
2468 for (unsigned int i = 0; i < len2; ++i)
2470 if (RightLine(cell))
2479 int LyXTabular::Ascii(Buffer const * buf, ostream & os) const
2483 //+---------------------------------------------------------------------
2484 //+ first calculate the width of the single columns +
2485 //+---------------------------------------------------------------------
2486 vector<unsigned int> clen(columns_);
2488 // first all non (real) multicolumn cells!
2489 for (int j = 0; j < columns_; ++j) {
2491 for (int i = 0; i < rows_; ++i) {
2492 int cell = GetCellNumber(i, j);
2493 if (IsMultiColumn(cell, true))
2496 GetCellInset(cell)->ascii(buf, sstr, 0);
2497 if (clen[j] < sstr.str().length())
2498 clen[j] = sstr.str().length();
2501 // then all (real) multicolumn cells!
2502 for (int j = 0; j < columns_; ++j) {
2503 for (int i = 0; i < rows_; ++i) {
2504 int cell = GetCellNumber(i, j);
2505 if (!IsMultiColumn(cell, true) || IsPartOfMultiColumn(i, j))
2508 GetCellInset(cell)->ascii(buf, sstr, 0);
2509 int len = int(sstr.str().length());
2510 int const n = cells_in_multicolumn(cell);
2511 for (int k = j; (len > 0) && (k < (j + n - 1)); ++k)
2513 if (len > int(clen[j + n - 1]))
2514 clen[j + n - 1] = len;
2518 for (int i = 0; i < rows_; ++i) {
2519 AsciiTopHLine(os, i, clen);
2520 for (int j = 0; j < columns_; ++j) {
2521 if (IsPartOfMultiColumn(i,j))
2523 ret += AsciiPrintCell(buf, os, cell, i, j, clen);
2527 AsciiBottomHLine(os, i, clen);
2533 InsetText * LyXTabular::GetCellInset(int cell) const
2536 return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
2540 InsetText * LyXTabular::GetCellInset(int row, int column) const
2542 cur_cell = GetCellNumber(row, column);
2543 return & cell_info[row][column].inset;
2547 void LyXTabular::Validate(LaTeXFeatures & features) const
2549 if (IsLongTabular())
2550 features.longtable = true;
2552 features.rotating = true;
2553 for (int cell = 0; !features.array && (cell < numberofcells); ++cell) {
2554 if (GetVAlignment(cell) != LYX_VALIGN_TOP)
2555 features.array = true;
2556 GetCellInset(cell)->validate(features);
2561 std::vector<string> const LyXTabular::getLabelList() const
2563 std::vector<string> label_list;
2564 for (int i = 0; i < rows_; ++i)
2565 for (int j = 0; j < columns_; ++j) {
2566 std::vector<string> const l =
2567 GetCellInset(i, j)->getLabelList();
2568 label_list.insert(label_list.end(),
2569 l.begin(), l.end());
2575 LyXTabular::BoxType LyXTabular::UseParbox(int cell) const
2577 Paragraph * par = GetCellInset(cell)->paragraph();
2579 for (; par; par = par->next()) {
2580 for (int i = 0; i < par->size(); ++i) {
2581 if (par->getChar(i) == Paragraph::META_NEWLINE)