1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 2000 The LyX Team.
8 * @author: Jürgen Vigna
10 * ======================================================
16 #pragma implementation
26 #include "lyx_gui_misc.h"
28 #include "BufferView.h"
30 #include "LaTeXFeatures.h"
31 #include "support/lstrings.h"
32 #include "support/lyxmanip.h"
33 #include "insets/insettabular.h"
34 #include "insets/insettext.h"
43 static int const WIDTH_OF_LINE = 5;
45 /// Define a few methods for the inner structs
47 LyXTabular::cellstruct::cellstruct()
51 multicolumn = LyXTabular::CELL_NORMAL;
52 alignment = LYX_ALIGN_CENTER;
53 valignment = LYX_VALIGN_TOP;
63 LyXTabular::rowstruct::rowstruct()
73 LyXTabular::columnstruct::columnstruct()
77 alignment = LYX_ALIGN_CENTER;
78 valignment = LYX_VALIGN_TOP;
84 LyXTabular::LyXTabular(InsetTabular * inset, int rows_arg, int columns_arg)
87 Init(rows_arg, columns_arg);
91 LyXTabular::LyXTabular(InsetTabular * inset, LyXTabular const & lt)
94 Init(lt.rows_, lt.columns_);
96 #warning Jürgen, can you make it the other way round. So that copy assignment depends on the copy constructor and not the other way. (Lgb)
102 LyXTabular::LyXTabular(Buffer const * buf, InsetTabular * inset, LyXLex & lex)
109 LyXTabular & LyXTabular::operator=(LyXTabular const & lt)
111 // If this and lt is not of the same size we have a serious bug
112 // So then it is ok to throw an exception, or for now
114 Assert(rows_ == lt.rows_ && columns_ == lt.columns_);
116 cell_info = lt.cell_info;
117 row_info = lt.row_info;
118 column_info = lt.column_info;
120 // long tabular stuff
121 SetLongTabular(lt.is_long_tabular);
122 endhead = lt.endhead;
123 endfoot = lt.endfoot;
124 endfirsthead = lt.endfirsthead;
125 endlastfoot = lt.endlastfoot;
135 LyXTabular * LyXTabular::Clone(InsetTabular * inset)
137 LyXTabular * result = new LyXTabular(inset, *this);
138 // don't know if this is good but I need to Clone also
139 // the text-insets here, this is for the Undo-facility!
140 for (int i = 0; i < rows_; ++i) {
141 for (int j = 0; j < columns_; ++j) {
142 result->cell_info[i][j].inset = cell_info[i][j].inset;
143 result->cell_info[i][j].inset.setOwner(inset);
150 /* activates all lines and sets all widths to 0 */
151 void LyXTabular::Init(int rows_arg, int columns_arg)
154 columns_ = columns_arg;
155 row_info = row_vector(rows_, rowstruct());
156 column_info = column_vector(columns_, columnstruct());
157 cell_info = cell_vvector(rows_, cell_vector(columns_, cellstruct()));
160 for (int i = 0; i < rows_; ++i) {
161 for (int j = 0; j < columns_; ++j) {
162 cell_info[i][j].inset.setOwner(owner_);
163 cell_info[i][j].inset.SetDrawFrame(0, InsetText::LOCKED);
164 cell_info[i][j].cellno = cellno++;
166 cell_info[i].back().right_line = true;
168 row_info.back().bottom_line = true;
169 row_info.front().bottom_line = true;
171 for (int i = 0; i < columns_; ++i) {
172 calculate_width_of_column(i);
174 column_info.back().right_line = true;
176 calculate_width_of_tabular();
178 rowofcell = vector<int>();
179 columnofcell = vector<int>();
180 set_row_column_number_info();
181 is_long_tabular = false;
190 void LyXTabular::AppendRow(int cell)
194 int row = row_of_cell(cell);
196 row_vector::iterator rit = row_info.begin() + row;
197 row_info.insert(rit, rowstruct());
200 cell_vvector::iterator cit = cell_info.begin() + row;
201 cell_info.insert(cit, vector<cellstruct>(columns_, cellstruct()));
203 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
206 for (int i = 0; i <= row; ++i) {
207 for (int j = 0; j < columns_; ++j) {
208 c_info[i][j] = cell_info[i][j];
211 for (int i = row + 1; i < rows_; ++i) {
212 for (int j = 0; j < columns_; ++j) {
213 c_info[i][j] = cell_info[i-1][j];
218 for (int j = 0; j < columns_; ++j) {
219 cell_info[row][j].inset.clear();
226 void LyXTabular::DeleteRow(int row)
228 // Why make it so hard? (Lgb)
231 if (rows_ == 1) return; // Not allowed to delete last row
233 row_info.erase(row_info.begin() + row); //&row_info[row]);
234 cell_info.erase(cell_info.begin() + row); //&cell_info[row]);
240 void LyXTabular::AppendColumn(int cell)
244 cell_vvector c_info = cell_vvector(rows_, cell_vector(columns_,
246 int const column = column_of_cell(cell);
247 column_vector::iterator cit = column_info.begin() + column + 1;
248 column_info.insert(cit, columnstruct());
250 for (int i = 0; i < rows_; ++i) {
251 for (int j = 0; j <= column; ++j) {
252 c_info[i][j] = cell_info[i][j];
254 for (int j = column + 1; j < columns_; ++j) {
255 c_info[i][j] = cell_info[i][j - 1];
257 // care about multicolumns
258 if (cell_info[i][column + 1].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
259 cell_info[i][column + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
261 if ((column + 1) == columns_ ||
262 cell_info[i][column + 2].multicolumn != CELL_PART_OF_MULTICOLUMN) {
263 cell_info[i][column + 1].multicolumn = LyXTabular::CELL_NORMAL;
268 for (int i = 0; i < rows_; ++i) {
269 //cell_info[i][column].inset.clear();
270 cell_info[i][column + 1].inset.clear();
276 void LyXTabular::DeleteColumn(int column)
278 // Similar to DeleteRow
279 //if (!(columns_ - 1))
281 if (columns_ == 1) return; // Not allowed to delete last column
283 column_info.erase(column_info.begin() + column);
284 for (int i = 0; i < rows_; ++i) {
285 cell_info[i].erase(cell_info[i].begin() + column);
292 void LyXTabular::Reinit()
294 for (int i = 0; i < rows_; ++i) {
295 for (int j = 0; j < columns_; ++j) {
296 cell_info[i][j].width_of_cell = 0;
297 cell_info[i][j].inset.setOwner(owner_);
301 for (int i = 0; i < columns_; ++i) {
302 calculate_width_of_column(i);
304 calculate_width_of_tabular();
306 set_row_column_number_info();
310 void LyXTabular::set_row_column_number_info(bool oldformat)
313 for (int row = 0; row < rows_; ++row) {
314 for (int column = 0; column<columns_; ++column) {
315 if (cell_info[row][column].multicolumn
316 != LyXTabular::CELL_PART_OF_MULTICOLUMN)
318 cell_info[row][column].cellno = numberofcells;
321 ++numberofcells; // because this is one more than as we start from 0
323 rowofcell.resize(numberofcells);
324 columnofcell.resize(numberofcells);
331 while (c < numberofcells && row < rows_ && column < columns_) {
333 columnofcell[c] = column;
337 } while (column < columns_ &&
338 cell_info[row][column].multicolumn
339 == LyXTabular::CELL_PART_OF_MULTICOLUMN);
340 if (column == columns_) {
346 // Isn't this the same as the while above? (Lgb)
348 #warning Please check this Jürgen.
350 // if ok please delete the #if 0 section above. (Lgb)
351 for (int row = 0, column = 0, c = 0;
352 c < numberofcells && row < rows_ && column < columns_;) {
354 columnofcell[c] = column;
358 } while (column < columns_ &&
359 cell_info[row][column].multicolumn
360 == LyXTabular::CELL_PART_OF_MULTICOLUMN);
361 if (column == columns_) {
368 for (int row = 0; row < rows_; ++row) {
369 for (int column = 0; column < columns_; ++column) {
370 if (IsPartOfMultiColumn(row,column))
372 // now set the right line of multicolumns right for oldformat read
374 cell_info[row][column].multicolumn==CELL_BEGIN_OF_MULTICOLUMN)
376 int cn=cells_in_multicolumn(cell_info[row][column].cellno);
377 cell_info[row][column].right_line =
378 cell_info[row][column+cn-1].right_line;
380 cell_info[row][column].inset.SetAutoBreakRows(
381 !GetPWidth(GetCellNumber(row, column)).empty());
387 int LyXTabular::GetNumberOfCells() const
389 return numberofcells;
393 int LyXTabular::NumberOfCellsInRow(int cell) const
395 int const row = row_of_cell(cell);
397 for (int i = 0; i < columns_; ++i) {
398 if (cell_info[row][i].multicolumn != LyXTabular::CELL_PART_OF_MULTICOLUMN)
405 /* returns 1 if there is a topline, returns 0 if not */
406 bool LyXTabular::TopLine(int cell, bool onlycolumn) const
408 int const row = row_of_cell(cell);
410 if (!onlycolumn && IsMultiColumn(cell))
411 return cellinfo_of_cell(cell)->top_line;
412 return row_info[row].top_line;
416 bool LyXTabular::BottomLine(int cell, bool onlycolumn) const
418 // no bottom line underneath non-existent cells if you please
419 // Isn't that a programming error? Is so this should
420 // be an Assert instead. (Lgb)
421 if (cell >= numberofcells)
424 if (!onlycolumn && IsMultiColumn(cell))
425 return cellinfo_of_cell(cell)->bottom_line;
426 return row_info[row_of_cell(cell)].bottom_line;
430 bool LyXTabular::LeftLine(int cell, bool onlycolumn) const
432 if (!onlycolumn && IsMultiColumn(cell))
433 return cellinfo_of_cell(cell)->left_line;
434 return column_info[column_of_cell(cell)].left_line;
438 bool LyXTabular::RightLine(int cell, bool onlycolumn) const
440 if (!onlycolumn && IsMultiColumn(cell))
441 return cellinfo_of_cell(cell)->right_line;
442 return column_info[right_column_of_cell(cell)].right_line;
446 bool LyXTabular::TopAlreadyDrawed(int cell) const
448 if (GetAdditionalHeight(cell))
450 int row = row_of_cell(cell);
452 int column = column_of_cell(cell);
455 && cell_info[row][column].multicolumn
456 == LyXTabular::CELL_PART_OF_MULTICOLUMN)
458 if (cell_info[row][column].multicolumn == LyXTabular::CELL_NORMAL)
459 return row_info[row].bottom_line;
461 return cell_info[row][column].bottom_line;
467 bool LyXTabular::LeftAlreadyDrawed(int cell) const
469 int column = column_of_cell(cell);
471 int row = row_of_cell(cell);
473 (cell_info[row][column].multicolumn ==
474 LyXTabular::CELL_PART_OF_MULTICOLUMN));
475 if (GetAdditionalWidth(cell_info[row][column].cellno))
477 return column_info[column].right_line;
483 bool LyXTabular::IsLastRow(int cell) const
485 return (row_of_cell(cell) == rows_ - 1);
489 int LyXTabular::GetAdditionalHeight(int cell) const
491 int const row = row_of_cell(cell);
497 for (int column = 0; column < columns_ - 1 && bottom; ++column) {
498 switch (cell_info[row - 1][column].multicolumn) {
499 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
500 bottom = cell_info[row - 1][column].bottom_line;
502 case LyXTabular::CELL_NORMAL:
503 bottom = row_info[row - 1].bottom_line;
506 for (int column = 0; column < columns_ - 1 && top; ++column) {
507 switch (cell_info[row][column].multicolumn){
508 case LyXTabular::CELL_BEGIN_OF_MULTICOLUMN:
509 top = cell_info[row][column].top_line;
511 case LyXTabular::CELL_NORMAL:
512 top = row_info[row].top_line;
516 return WIDTH_OF_LINE;
521 int LyXTabular::GetAdditionalWidth(int cell) const
523 // internally already set in SetWidthOfCell
524 // used to get it back in text.C
525 int const col = right_column_of_cell(cell);
526 if (col < columns_ - 1 && column_info[col].right_line &&
527 column_info[col+1].left_line)
528 return WIDTH_OF_LINE;
534 // returns the maximum over all rows
535 int LyXTabular::GetWidthOfColumn(int cell) const
537 int const column1 = column_of_cell(cell);
538 int const column2 = right_column_of_cell(cell);
540 for (int i = column1; i <= column2; ++i) {
541 result += column_info[i].width_of_column;
547 int LyXTabular::GetWidthOfTabular() const
549 return width_of_tabular;
553 /* returns 1 if a complete update is necessary, otherwise 0 */
554 bool LyXTabular::SetWidthOfMulticolCell(int cell, int new_width)
556 if (!IsMultiColumn(cell))
559 int const row = row_of_cell(cell);
560 int const column1 = column_of_cell(cell);
561 int const column2 = right_column_of_cell(cell);
563 // first set columns to 0 so we can calculate the right width
564 for (int i = column1; i <= column2; ++i) {
565 cell_info[row][i].width_of_cell = 0;
567 // set the width to MAX_WIDTH until width > 0
568 int width = (new_width + 2 * WIDTH_OF_LINE);
571 for (; i < column2 && width > column_info[i].width_of_column; ++i) {
572 cell_info[row][i].width_of_cell = column_info[i].width_of_column;
573 width -= column_info[i].width_of_column;
576 cell_info[row][i].width_of_cell = width;
582 void LyXTabular::recalculateMulticolCells(int cell, int new_width)
584 int const row = row_of_cell(cell);
585 int const column1 = column_of_cell(cell);
586 int const column2 = right_column_of_cell(cell);
588 // first set columns to 0 so we can calculate the right width
590 for (; i <= column2; ++i)
591 cell_info[row][i].width_of_cell = 0;
592 for (i = cell + 1; (i < numberofcells) && (!IsMultiColumn(i)); ++i)
594 if (i < numberofcells)
595 recalculateMulticolCells(i, GetWidthOfCell(i) - (2 * WIDTH_OF_LINE));
596 SetWidthOfMulticolCell(cell, new_width);
600 /* returns 1 if a complete update is necessary, otherwise 0 */
601 bool LyXTabular::SetWidthOfCell(int cell, int new_width)
603 int const row = row_of_cell(cell);
604 int const column1 = column_of_cell(cell);
608 if (GetWidthOfCell(cell) == (new_width+2*WIDTH_OF_LINE))
610 if (IsMultiColumn(cell, true)) {
611 tmp = SetWidthOfMulticolCell(cell, new_width);
613 width = (new_width + 2*WIDTH_OF_LINE);
614 cell_info[row][column1].width_of_cell = width;
615 if (column_info[column1].right_line && (column1 < columns_-1) &&
616 column_info[column1+1].left_line) // additional width
617 cell_info[row][column1].width_of_cell += WIDTH_OF_LINE;
618 tmp = calculate_width_of_column_NMC(column1);
622 for (; i<columns_; ++i)
623 calculate_width_of_column_NMC(i);
624 for (i = 0; (i < numberofcells) && !IsMultiColumn(i); ++i)
626 if (i < numberofcells)
627 recalculateMulticolCells(i, GetWidthOfCell(i)-(2 * WIDTH_OF_LINE));
628 for (i = 0; i < columns_; ++i)
629 calculate_width_of_column(i);
630 calculate_width_of_tabular();
637 bool LyXTabular::SetAlignment(int cell, LyXAlignment align, bool onlycolumn)
639 if (!IsMultiColumn(cell) || onlycolumn)
640 column_info[column_of_cell(cell)].alignment = align;
642 cellinfo_of_cell(cell)->alignment = align;
647 bool LyXTabular::SetVAlignment(int cell, VAlignment align, bool onlycolumn)
649 if (!IsMultiColumn(cell) || onlycolumn)
650 column_info[column_of_cell(cell)].valignment = align;
652 cellinfo_of_cell(cell)->valignment = align;
657 bool LyXTabular::SetColumnPWidth(int cell, string const & width)
659 bool flag = !width.empty();
660 int const j = column_of_cell(cell);
662 column_info[j].p_width = width;
663 if (flag) // do this only if there is a width
664 SetAlignment(cell, LYX_ALIGN_LEFT);
665 for (int i = 0; i < rows_; ++i) {
666 int c = GetCellNumber(i, j);
667 flag = !GetPWidth(c).empty(); // because of multicolumns!
668 GetCellInset(c)->SetAutoBreakRows(flag);
674 bool LyXTabular::SetMColumnPWidth(int cell, string const & width)
676 bool const flag = !width.empty();
678 cellinfo_of_cell(cell)->p_width = width;
679 if (IsMultiColumn(cell)) {
680 GetCellInset(cell)->SetAutoBreakRows(flag);
687 bool LyXTabular::SetAlignSpecial(int cell, string const & special,
688 LyXTabular::Feature what)
690 if (what == SET_SPECIAL_MULTI)
691 cellinfo_of_cell(cell)->align_special = special;
693 column_info[column_of_cell(cell)].align_special = special;
698 bool LyXTabular::SetAllLines(int cell, bool line)
700 SetTopLine(cell, line);
701 SetBottomLine(cell, line);
702 SetRightLine(cell, line);
703 SetLeftLine(cell, line);
708 bool LyXTabular::SetTopLine(int cell, bool line, bool onlycolumn)
710 int const row = row_of_cell(cell);
712 if (onlycolumn || !IsMultiColumn(cell))
713 row_info[row].top_line = line;
715 cellinfo_of_cell(cell)->top_line = line;
720 bool LyXTabular::SetBottomLine(int cell, bool line, bool onlycolumn)
722 if (onlycolumn || !IsMultiColumn(cell))
723 row_info[row_of_cell(cell)].bottom_line = line;
725 cellinfo_of_cell(cell)->bottom_line = line;
730 bool LyXTabular::SetLeftLine(int cell, bool line, bool onlycolumn)
732 if (onlycolumn || !IsMultiColumn(cell))
733 column_info[column_of_cell(cell)].left_line = line;
735 cellinfo_of_cell(cell)->left_line = line;
740 bool LyXTabular::SetRightLine(int cell, bool line, bool onlycolumn)
742 if (onlycolumn || !IsMultiColumn(cell))
743 column_info[right_column_of_cell(cell)].right_line = line;
745 cellinfo_of_cell(cell)->right_line = line;
750 LyXAlignment LyXTabular::GetAlignment(int cell, bool onlycolumn) const
752 if (!onlycolumn && IsMultiColumn(cell))
753 return cellinfo_of_cell(cell)->alignment;
755 return column_info[column_of_cell(cell)].alignment;
759 LyXTabular::VAlignment
760 LyXTabular::GetVAlignment(int cell, bool onlycolumn) const
762 if (!onlycolumn && IsMultiColumn(cell))
763 return cellinfo_of_cell(cell)->valignment;
765 return column_info[column_of_cell(cell)].valignment;
769 string const LyXTabular::GetPWidth(int cell) const
771 if (IsMultiColumn(cell))
772 return cellinfo_of_cell(cell)->p_width;
773 return column_info[column_of_cell(cell)].p_width;
777 string const LyXTabular::GetColumnPWidth(int cell) const
779 return column_info[column_of_cell(cell)].p_width;
783 string const LyXTabular::GetMColumnPWidth(int cell) const
785 if (IsMultiColumn(cell))
786 return cellinfo_of_cell(cell)->p_width;
791 string const LyXTabular::GetAlignSpecial(int cell, int what) const
793 if (what == SET_SPECIAL_MULTI)
794 return cellinfo_of_cell(cell)->align_special;
795 return column_info[column_of_cell(cell)].align_special;
799 int LyXTabular::GetWidthOfCell(int cell) const
801 int const row = row_of_cell(cell);
802 int const column1 = column_of_cell(cell);
803 int const column2 = right_column_of_cell(cell);
805 for (int i = column1; i <= column2; ++i) {
806 result += cell_info[row][i].width_of_cell;
812 int LyXTabular::GetBeginningOfTextInCell(int cell) const
816 switch (GetAlignment(cell)){
817 case LYX_ALIGN_CENTER:
818 x += (GetWidthOfColumn(cell) - GetWidthOfCell(cell)) / 2;
820 case LYX_ALIGN_RIGHT:
821 x += GetWidthOfColumn(cell) - GetWidthOfCell(cell);
822 // + GetAdditionalWidth(cell);
824 default: /* LYX_ALIGN_LEFT: nothing :-) */
834 bool LyXTabular::IsFirstCellInRow(int cell) const
836 return column_of_cell(cell) == 0;
840 int LyXTabular::GetFirstCellInRow(int row) const
844 return cell_info[row][0].cellno;
847 bool LyXTabular::IsLastCellInRow(int cell) const
849 return (right_column_of_cell(cell) == (columns_ - 1));
853 int LyXTabular::GetLastCellInRow(int row) const
857 return cell_info[row][columns_-1].cellno;
861 bool LyXTabular::calculate_width_of_column(int column)
863 int const old_column_width = column_info[column].width_of_column;
866 for (int i = 0; i < rows_; ++i) {
867 maximum = max(cell_info[i][column].width_of_cell, maximum);
869 column_info[column].width_of_column = maximum;
870 return (column_info[column].width_of_column != old_column_width);
875 // calculate the with of the column without regarding REAL MultiColumn
876 // cells. This means MultiColumn-cells spanning more than 1 column.
878 bool LyXTabular::calculate_width_of_column_NMC(int column)
880 int const old_column_width = column_info[column].width_of_column;
882 for (int i = 0; i < rows_; ++i) {
883 if (!IsMultiColumn(GetCellNumber(i, column), true) &&
884 (cell_info[i][column].width_of_cell > max)) {
885 max = cell_info[i][column].width_of_cell;
888 column_info[column].width_of_column = max;
889 return (column_info[column].width_of_column != old_column_width);
893 void LyXTabular::calculate_width_of_tabular()
895 width_of_tabular = 0;
896 for (int i = 0; i < columns_; ++i) {
897 width_of_tabular += column_info[i].width_of_column;
902 int LyXTabular::row_of_cell(int cell) const
904 if (cell >= numberofcells)
908 return rowofcell[cell];
912 int LyXTabular::column_of_cell(int cell) const
914 if (cell >= numberofcells)
918 return columnofcell[cell];
922 int LyXTabular::right_column_of_cell(int cell) const
924 int const row = row_of_cell(cell);
925 int column = column_of_cell(cell);
926 while (column < (columns_ - 1) &&
927 cell_info[row][column + 1].multicolumn == LyXTabular::CELL_PART_OF_MULTICOLUMN)
933 // Perfect case for a template... (Lgb)
936 string const write_attribute(string const & name, T const & t)
938 string str = " " + name + "=\"" + tostr(t) + "\"";
943 string const write_attribute(string const & name, bool const & b)
945 return write_attribute(name, int(b));
950 string const write_attribute(string const & name, int value)
952 string str = " " + name + "=\"" + tostr(value) + "\"";
957 string const write_attribute(string const & name, string const & value)
959 string str = " " + name + "=\"" + value + "\"";
964 string const write_attribute(string const & name, bool value)
966 string str = " " + name + "=\"" + tostr(static_cast<int>(value)) + "\"";
972 void LyXTabular::Write(Buffer const * buf, ostream & os) const
976 << write_attribute("version", 1)
977 << write_attribute("rows", rows_)
978 << write_attribute("columns", columns_)
980 // global longtable options
982 << write_attribute("rotate", rotate)
983 << write_attribute("islongtable", is_long_tabular)
984 << write_attribute("endhead", endhead)
985 << write_attribute("endfirsthead", endfirsthead)
986 << write_attribute("endfoot", endfoot)
987 << write_attribute("endlastfoot", endlastfoot)
989 for (int i = 0; i < rows_; ++i) {
991 << write_attribute("topline", row_info[i].top_line)
992 << write_attribute("bottomline", row_info[i].bottom_line)
993 << write_attribute("newpage", row_info[i].newpage)
995 for (int j = 0; j < columns_; ++j) {
998 << write_attribute("alignment", column_info[j].alignment)
999 << write_attribute("valignment", column_info[j].valignment)
1000 << write_attribute("leftline", column_info[j].left_line)
1001 << write_attribute("rightline", column_info[j].right_line)
1002 << write_attribute("width",
1003 VSpace(column_info[j].p_width)
1005 << write_attribute("special", column_info[j].align_special)
1011 << write_attribute("multicolumn", cell_info[i][j].multicolumn)
1012 << write_attribute("alignment", cell_info[i][j].alignment)
1013 << write_attribute("valignment", cell_info[i][j].valignment)
1014 << write_attribute("topline", cell_info[i][j].top_line)
1015 << write_attribute("bottomline", cell_info[i][j].bottom_line)
1016 << write_attribute("leftline", cell_info[i][j].left_line)
1017 << write_attribute("rightline", cell_info[i][j].right_line)
1018 << write_attribute("rotate", cell_info[i][j].rotate)
1019 << write_attribute("usebox", cell_info[i][j].usebox)
1020 << write_attribute("width", cell_info[i][j].p_width)
1021 << write_attribute("special", cell_info[i][j].align_special)
1023 os << "\\begin_inset ";
1024 cell_info[i][j].inset.Write(buf, os);
1025 os << "\n\\end_inset \n"
1031 os << "</LyXTabular>\n";
1036 bool getTokenValue(string const & str, const char * token, string & ret)
1038 string::size_type pos = str.find(token);
1039 char ch = str[pos + strlen(token)];
1041 if ((pos == string::npos) || (ch != '='))
1044 pos += strlen(token) + 1;
1046 if ((ch != '"') && (ch != '\'')) { // only read till next space
1050 while((pos < str.length() - 1) && (str[++pos] != ch))
1058 bool getTokenValue(string const & str, const char * token, int & num)
1060 string::size_type pos = str.find(token);
1061 char ch = str[pos + strlen(token)];
1063 if ((pos == string::npos) || (ch != '='))
1066 pos += strlen(token) + 1;
1068 if ((ch != '"') && (ch != '\'')) { // only read till next space
1074 while((pos < str.length() - 1) && isdigit(str[pos]))
1077 num = strToInt(ret);
1083 bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
1086 bool const ret = getTokenValue(str, token, tmp);
1087 num = static_cast<LyXAlignment>(tmp);
1093 bool getTokenValue(string const & str, const char * token,
1094 LyXTabular::VAlignment & num)
1097 bool const ret = getTokenValue(str, token, tmp);
1098 num = static_cast<LyXTabular::VAlignment>(tmp);
1104 bool getTokenValue(string const & str, const char * token,
1105 LyXTabular::BoxType & num)
1108 bool ret = getTokenValue(str, token, tmp);
1109 num = static_cast<LyXTabular::BoxType>(tmp);
1115 bool getTokenValue(string const & str, const char * token, bool & flag)
1117 string::size_type pos = str.find(token);
1118 char ch = str[pos + strlen(token)];
1120 if ((pos == string::npos) || (ch != '='))
1123 pos += strlen(token) + 1;
1125 if ((ch != '"') && (ch != '\'')) { // only read till next space
1131 while((pos < str.length() - 1) && isdigit(str[pos]))
1134 flag = strToInt(ret);
1140 void l_getline(istream & is, string & str)
1148 void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
1151 istream & is = lex.getStream();
1153 l_getline(is, line);
1154 if (!prefixIs(line, "<LyXTabular ")) {
1155 OldFormatRead(lex, line);
1162 if (!getTokenValue(line, "version", version))
1164 if (!getTokenValue(line, "rows", rows_arg))
1166 if (!getTokenValue(line, "columns", columns_arg))
1168 Init(rows_arg, columns_arg);
1169 l_getline(is, line);
1170 if (!prefixIs(line, "<Features ")) {
1171 lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
1172 line << ")" << endl;
1175 getTokenValue(line, "islongtable", is_long_tabular);
1176 getTokenValue(line, "endhead", endhead);
1177 getTokenValue(line, "endfirsthead", endfirsthead);
1178 getTokenValue(line, "endfoot", endfoot);
1179 getTokenValue(line, "endlastfoot", endlastfoot);
1181 for (int i = 0; i < rows_; ++i) {
1182 l_getline(is, line);
1183 if (!prefixIs(line, "<Row ")) {
1184 lyxerr << "Wrong tabular format (expected <Row ...> got" <<
1185 line << ")" << endl;
1188 getTokenValue(line, "topline", row_info[i].top_line);
1189 getTokenValue(line, "bottomline", row_info[i].bottom_line);
1190 getTokenValue(line, "newpage", row_info[i].newpage);
1191 for (int j = 0; j < columns_; ++j) {
1193 if (!prefixIs(line,"<Column")) {
1194 lyxerr << "Wrong tabular format (expected <Column ...> got" <<
1195 line << ")" << endl;
1199 getTokenValue(line, "alignment", column_info[j].alignment);
1200 getTokenValue(line, "valignment", column_info[j].valignment);
1201 getTokenValue(line, "leftline", column_info[j].left_line);
1202 getTokenValue(line, "rightline", column_info[j].right_line);
1203 getTokenValue(line, "width", column_info[j].p_width);
1204 getTokenValue(line, "special", column_info[j].align_special);
1206 l_getline(is, line);
1207 if (!prefixIs(line, "<Cell")) {
1208 lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
1209 line << ")" << endl;
1212 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1213 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1214 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1215 getTokenValue(line, "topline", cell_info[i][j].top_line);
1216 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1217 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1218 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1219 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1220 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1221 getTokenValue(line, "width", cell_info[i][j].p_width);
1222 getTokenValue(line, "special", cell_info[i][j].align_special);
1223 l_getline(is, line);
1224 if (prefixIs(line, "\\begin_inset")) {
1225 cell_info[i][j].inset.Read(buf, lex);
1226 l_getline(is, line);
1228 if (line != "</Cell>") {
1229 lyxerr << "Wrong tabular format (expected </Cell> got" <<
1230 line << ")" << endl;
1233 l_getline(is, line);
1234 if (line != "</Column>") {
1235 lyxerr << "Wrong tabular format (expected </Column> got" <<
1236 line << ")" << endl;
1240 l_getline(is, line);
1241 if (line != "</Row>") {
1242 lyxerr << "Wrong tabular format (expected </Row> got" <<
1243 line << ")" << endl;
1247 while (line != "</LyXTabular>") {
1248 l_getline(is, line);
1250 set_row_column_number_info();
1254 void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
1259 int columns_arg = 0;
1260 int is_long_tabular_arg = false;
1261 int rotate_arg = false;
1270 istream & is = lex.getStream();
1273 version = lyx::atoi(s.substr(8, string::npos));
1277 vector<int> cont_row_info;
1280 lyxerr << "Tabular format < 5 is not supported anymore\n"
1281 "Get an older version of LyX (< 1.1.x) for conversion!"
1283 WriteAlert(_("Warning:"),
1284 _("Tabular format < 5 is not supported anymore\n"),
1285 _("Get an older version of LyX (< 1.1.x) for conversion!"));
1287 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1288 >> rotate_arg >> a >> b >> c >> d;
1290 is >> rows_arg >> columns_arg;
1291 Init(rows_arg, columns_arg);
1292 cont_row_info = vector<int>(rows_arg);
1293 SetLongTabular(is_long_tabular_arg);
1294 SetRotateTabular(rotate_arg);
1296 for (i = 0; i < rows_; ++i) {
1298 cont_row_info[i] = false;
1300 for (i = 0; i < columns_; ++i) {
1303 for (i = 0; i < rows_; ++i) {
1304 for (j = 0; j < columns_; ++j) {
1309 is >> rows_arg >> columns_arg >> is_long_tabular_arg
1310 >> rotate_arg >> a >> b >> c >> d;
1311 Init(rows_arg, columns_arg);
1312 cont_row_info = vector<int>(rows_arg);
1313 SetLongTabular(is_long_tabular_arg);
1314 SetRotateTabular(rotate_arg);
1319 for (i = 0; i < rows_; ++i) {
1320 a = b = c = d = e = f = g = 0;
1321 is >> a >> b >> c >> d;
1322 row_info[i].top_line = a;
1323 row_info[i].bottom_line = b;
1324 cont_row_info[i] = c;
1325 row_info[i].newpage = d;
1327 for (i = 0; i < columns_; ++i) {
1332 char ch; // skip '"'
1335 // ignore is buggy but we will use it later (Lgb)
1336 is.ignore(); // skip '"'
1338 getline(is, s1, '"');
1340 is >> ch; // skip '"'
1342 // ignore is buggy but we will use it later (Lgb)
1343 is.ignore(); // skip '"'
1345 getline(is, s2, '"');
1346 column_info[i].alignment = static_cast<LyXAlignment>(a);
1347 column_info[i].left_line = b;
1348 column_info[i].right_line = c;
1349 column_info[i].p_width = s1;
1350 column_info[i].align_special = s2;
1352 for (i = 0; i < rows_; ++i) {
1353 for (j = 0; j < columns_; ++j) {
1356 is >> a >> b >> c >> d >> e >> f >> g;
1359 is >> ch; // skip '"'
1361 // ignore is buggy but we will use it later (Lgb)
1362 is.ignore(); // skip '"'
1364 getline(is, s1, '"');
1366 is >> ch; // skip '"'
1368 // ignore is buggy but we will use it later (Lgb)
1369 is.ignore(); // skip '"'
1371 getline(is, s2, '"');
1372 cell_info[i][j].multicolumn = static_cast<char>(a);
1373 cell_info[i][j].alignment = static_cast<LyXAlignment>(b);
1374 cell_info[i][j].top_line = static_cast<char>(c);
1375 cell_info[i][j].bottom_line = static_cast<char>(d);
1376 cell_info[i][j].left_line = column_info[j].left_line;
1377 cell_info[i][j].right_line = column_info[j].right_line;
1378 cell_info[i][j].rotate = static_cast<bool>(f);
1379 cell_info[i][j].usebox = static_cast<BoxType>(g);
1380 cell_info[i][j].align_special = s1;
1381 cell_info[i][j].p_width = s2;
1385 set_row_column_number_info(true);
1387 LyXParagraph * par = new LyXParagraph;
1388 LyXParagraph * return_par = 0;
1390 LyXParagraph::footnote_flag footnoteflag = LyXParagraph::NO_FOOTNOTE;
1391 LyXParagraph::footnote_kind footnotekind = LyXParagraph::FOOTNOTE;
1396 LyXFont font(LyXFont::ALL_SANE);
1397 font.setLanguage(owner_->BufferOwner()->GetLanguage());
1399 while (lex.IsOK()) {
1401 string const token = lex.GetString();
1404 if (token == "\\layout"
1405 || token == "\\end_float"
1406 || token == "\\end_deeper") {
1407 lex.pushToken(token);
1410 if (owner_->BufferOwner()->parseSingleLyXformat2Token(lex, par,
1422 lex.pushToken(token);
1426 lex.printError("New Paragraph allocated! This should not happen!");
1427 lex.pushToken(token);
1433 // now we have the par we should fill the insets with this!
1435 InsetText * inset = GetCellInset(cell);
1438 for (int i = 0; i < par->Last(); ++i) {
1439 if (par->IsNewline(i)) {
1441 if (cell > GetNumberOfCells()) {
1442 lyxerr << "Some error in reading old table format occured!" <<
1443 endl << "Terminating when reading cell[" << cell << "]!" <<
1448 row = row_of_cell(cell);
1449 if (cont_row_info[row]) {
1451 cont_row_info.erase(cont_row_info.begin() + row); //&cont_row_info[row]);
1452 while(!IsFirstCellInRow(--cell));
1454 inset = GetCellInset(cell);
1457 inset = GetCellInset(cell);
1458 row = row_of_cell(cell);
1459 if (!cell_info[row_of_cell(cell)][column_of_cell(cell)].usebox)
1461 // insert a space instead
1463 par->InsertChar(i, ' ');
1466 par->CopyIntoMinibuffer(owner_->BufferOwner()->params, i);
1467 inset->par->InsertFromMinibuffer(inset->par->Last());
1474 string const LyXTabular::GetDocBookAlign(int cell, bool isColumn) const
1476 int const i = isColumn ? cell : column_of_cell(cell);
1478 if (!isColumn && IsMultiColumn(cell)) {
1479 if (!cellinfo_of_cell(cell)->align_special.empty()) {
1480 return cellinfo_of_cell(cell)->align_special;
1482 switch (GetAlignment(cell)) {
1483 case LYX_ALIGN_LEFT:
1485 case LYX_ALIGN_RIGHT:
1492 if (!column_info[i].align_special.empty()) {
1493 return column_info[i].align_special;
1495 #ifdef IGNORE_THIS_FOR_NOW
1496 else if (!column_info[i].p_width.empty()) {
1498 file += column_info[i].p_width;
1503 switch (column_info[i].alignment) {
1504 case LYX_ALIGN_LEFT:
1506 case LYX_ALIGN_RIGHT:
1516 // cell <0 will tex the preamble
1517 // returns the number of printed newlines
1518 int LyXTabular::DocBookEndOfCell(ostream & os, int cell, int & depth) const
1521 if (IsLastCell(cell)) {
1522 os << newlineAndDepth(--depth)
1524 << newlineAndDepth(--depth)
1526 << newlineAndDepth(--depth)
1528 << newlineAndDepth(--depth);
1529 if (is_long_tabular)
1533 << newlineAndDepth(--depth);
1538 if (is_long_tabular)
1544 << "' COLSEP='1' ROWSEP='1'>"
1545 << newlineAndDepth(++depth);
1547 for (int i = 0; i < columns_; ++i) {
1548 os << "<COLSPEC ALIGN='"
1549 << GetDocBookAlign(i, true)
1555 if (i == (columns_-1)) {
1558 if (column_info[i].right_line ||
1559 column_info[i+1].left_line)
1565 << newlineAndDepth(depth);
1567 #ifdef NOT_HANDLED_YET_AS_I_DONT_KNOW_HOW
1568 if (column_info[i].left_line)
1573 << newlineAndDepth(++depth)
1575 << newlineAndDepth(++depth)
1577 << GetDocBookAlign(0)
1579 if (IsMultiColumn(0)) {
1580 os << " NAMEST='col1' NAMEEND='col"
1581 << cells_in_multicolumn(0)
1585 << newlineAndDepth(++depth);
1588 if (IsLastCellInRow(cell)) {
1589 os << newlineAndDepth(--depth)
1591 << newlineAndDepth(--depth)
1593 << newlineAndDepth(depth)
1595 << newlineAndDepth(++depth)
1597 << GetDocBookAlign(cell + 1)
1598 << "' VALIGN='middle'";
1599 if (IsMultiColumn(cell + 1)) {
1600 os << " NAMEST='col"
1601 << column_of_cell(cell + 1) + 1
1603 << column_of_cell(cell + 1) +
1604 cells_in_multicolumn(cell + 1)
1608 << newlineAndDepth(++depth);
1611 os << newlineAndDepth(--depth)
1613 << newlineAndDepth(depth)
1615 << GetDocBookAlign(cell + 1)
1616 << "' VALIGN='middle'";
1617 if (IsMultiColumn(cell + 1)) {
1618 os << " NAMEST='col"
1619 << column_of_cell(cell + 1) + 1
1621 << column_of_cell(cell + 1) +
1622 cells_in_multicolumn(cell + 1)
1626 << newlineAndDepth(++depth);
1635 bool LyXTabular::IsMultiColumn(int cell, bool real) const
1637 return ((!real || (column_of_cell(cell) != right_column_of_cell(cell))) &&
1638 (cellinfo_of_cell(cell)->multicolumn != LyXTabular::CELL_NORMAL));
1642 LyXTabular::cellstruct * LyXTabular::cellinfo_of_cell(int cell) const
1644 int const row = row_of_cell(cell);
1645 int const column = column_of_cell(cell);
1646 return &cell_info[row][column];
1650 void LyXTabular::SetMultiColumn(int cell, int number)
1652 cellinfo_of_cell(cell)->multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1653 cellinfo_of_cell(cell)->alignment = column_info[column_of_cell(cell)].alignment;
1654 cellinfo_of_cell(cell)->top_line = row_info[row_of_cell(cell)].top_line;
1655 cellinfo_of_cell(cell)->bottom_line = row_info[row_of_cell(cell)].bottom_line;
1656 for (number--; number > 0; --number) {
1657 cellinfo_of_cell(cell+number)->multicolumn = CELL_PART_OF_MULTICOLUMN;
1659 set_row_column_number_info();
1663 int LyXTabular::cells_in_multicolumn(int cell) const
1665 int const row = row_of_cell(cell);
1666 int column = column_of_cell(cell);
1669 while ((column < columns_) &&
1670 cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
1679 int LyXTabular::UnsetMultiColumn(int cell)
1681 int const row = row_of_cell(cell);
1682 int column = column_of_cell(cell);
1686 if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
1687 cell_info[row][column].multicolumn = CELL_NORMAL;
1689 while ((column < columns_) &&
1690 (cell_info[row][column].multicolumn ==CELL_PART_OF_MULTICOLUMN))
1692 cell_info[row][column].multicolumn = CELL_NORMAL;
1697 set_row_column_number_info();
1702 void LyXTabular::SetLongTabular(bool what)
1704 is_long_tabular = what;
1708 bool LyXTabular::IsLongTabular() const
1710 return is_long_tabular;
1714 void LyXTabular::SetRotateTabular(bool flag)
1720 bool LyXTabular::GetRotateTabular() const
1726 void LyXTabular::SetRotateCell(int cell, bool flag)
1728 cellinfo_of_cell(cell)->rotate = flag;
1732 bool LyXTabular::GetRotateCell(int cell) const
1734 return cellinfo_of_cell(cell)->rotate;
1738 bool LyXTabular::NeedRotating() const
1742 for (int i = 0; i < rows_; ++i) {
1743 for (int j = 0; j < columns_; ++j) {
1744 if (cell_info[i][j].rotate)
1752 bool LyXTabular::IsLastCell(int cell) const
1754 if ((cell + 1) < GetNumberOfCells())
1760 int LyXTabular::GetCellAbove(int cell) const
1762 if (row_of_cell(cell) > 0)
1763 return cell_info[row_of_cell(cell)-1][column_of_cell(cell)].cellno;
1768 int LyXTabular::GetCellBelow(int cell) const
1770 if (row_of_cell(cell) + 1 < rows_)
1771 return cell_info[row_of_cell(cell)+1][column_of_cell(cell)].cellno;
1776 int LyXTabular::GetLastCellAbove(int cell) const
1778 if (row_of_cell(cell) <= 0)
1780 if (!IsMultiColumn(cell))
1781 return GetCellAbove(cell);
1782 return cell_info[row_of_cell(cell) - 1][right_column_of_cell(cell)].cellno;
1786 int LyXTabular::GetLastCellBelow(int cell) const
1788 if (row_of_cell(cell) + 1 >= rows_)
1790 if (!IsMultiColumn(cell))
1791 return GetCellBelow(cell);
1792 return cell_info[row_of_cell(cell) + 1][right_column_of_cell(cell)].cellno;
1796 int LyXTabular::GetCellNumber(int row, int column) const
1798 if (column >= columns_)
1799 column = columns_ - 1;
1800 else if (column < 0)
1807 return cell_info[row][column].cellno;
1811 void LyXTabular::SetUsebox(int cell, BoxType type)
1813 cellinfo_of_cell(cell)->usebox = type;
1817 LyXTabular::BoxType LyXTabular::GetUsebox(int cell) const
1819 if (column_info[column_of_cell(cell)].p_width.empty() &&
1820 !(IsMultiColumn(cell) && !cellinfo_of_cell(cell)->p_width.empty()))
1822 if (cellinfo_of_cell(cell)->usebox > 1)
1823 return cellinfo_of_cell(cell)->usebox;
1824 return UseParbox(cell);
1828 void LyXTabular::SetLTHead(int cell, bool first)
1830 int const row = row_of_cell(cell);
1831 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1834 if (endfirsthead == val)
1847 bool LyXTabular::GetRowOfLTHead(int cell, int & row) const
1850 if (abs(endhead) > rows_)
1852 return (row_of_cell(cell) == abs(endhead) - 1);
1856 bool LyXTabular::GetRowOfLTFirstHead(int cell, int & row) const
1859 if (abs(endfirsthead) > rows_)
1861 return (row_of_cell(cell) == abs(endfirsthead) - 1);
1865 void LyXTabular::SetLTFoot(int cell, bool last)
1867 int const row = row_of_cell(cell);
1868 int const val = (row + 1) * (column_of_cell(cell) ? 1 : -1);
1871 if (endlastfoot == val)
1884 bool LyXTabular::GetRowOfLTFoot(int cell, int & row) const
1887 if ((endfoot + 1) > rows_)
1889 return (row_of_cell(cell) == abs(endfoot) - 1);
1893 bool LyXTabular::GetRowOfLTLastFoot(int cell, int & row) const
1896 if (abs(endlastfoot) > rows_)
1898 return (row_of_cell(cell) == (abs(endlastfoot)-1));
1902 void LyXTabular::SetLTNewPage(int cell, bool what)
1904 row_info[row_of_cell(cell)].newpage = what;
1908 bool LyXTabular::GetLTNewPage(int cell) const
1910 return row_info[row_of_cell(cell)].newpage;
1914 bool LyXTabular::SetAscentOfRow(int row, int height)
1916 if ((row >= rows_) || (row_info[row].ascent_of_row == height))
1918 row_info[row].ascent_of_row = height;
1923 bool LyXTabular::SetDescentOfRow(int row, int height)
1925 if ((row >= rows_) || (row_info[row].descent_of_row == height))
1927 row_info[row].descent_of_row = height;
1932 int LyXTabular::GetAscentOfRow(int row) const
1936 return row_info[row].ascent_of_row;
1940 int LyXTabular::GetDescentOfRow(int row) const
1944 return row_info[row].descent_of_row;
1948 int LyXTabular::GetHeightOfTabular() const
1952 for (int row = 0; row < rows_; ++row)
1953 height += GetAscentOfRow(row) + GetDescentOfRow(row) +
1954 GetAdditionalHeight(GetCellNumber(row, 0));
1959 bool LyXTabular::IsPartOfMultiColumn(int row, int column) const
1961 if ((row >= rows_) || (column >= columns_))
1963 return (cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN);
1967 int LyXTabular::TeXTopHLine(ostream & os, int row) const
1969 int const fcell = GetFirstCellInRow(row);
1970 int const n = NumberOfCellsInRow(fcell) + fcell;
1973 for (int i = fcell; i < n; ++i) {
1977 if (tmp == (n - fcell)){
1980 for (int i = fcell; i < n; ++i) {
1983 << column_of_cell(i) + 1
1985 << right_column_of_cell(i) + 1
1997 int LyXTabular::TeXBottomHLine(ostream & os, int row) const
1999 int const fcell = GetFirstCellInRow(row);
2000 int const n = NumberOfCellsInRow(fcell) + fcell;
2003 for (int i = fcell; i < n; ++i) {
2007 if (tmp == (n-fcell)){
2010 for (int i = fcell; i < n; ++i) {
2011 if (BottomLine(i)) {
2013 << column_of_cell(i) + 1
2015 << right_column_of_cell(i) + 1
2027 int LyXTabular::TeXCellPreamble(ostream & os, int cell) const
2031 if (GetRotateCell(cell)) {
2032 os << "\\begin{sideways}\n";
2035 if (IsMultiColumn(cell)) {
2036 os << "\\multicolumn{" << cells_in_multicolumn(cell) << "}{";
2037 if (!cellinfo_of_cell(cell+1)->align_special.empty()) {
2038 os << cellinfo_of_cell(cell+1)->align_special << "}{";
2042 if (!GetPWidth(cell).empty()) {
2043 switch (GetVAlignment(cell)) {
2044 case LYX_VALIGN_TOP:
2047 case LYX_VALIGN_CENTER:
2050 case LYX_VALIGN_BOTTOM:
2054 os << "{" << GetPWidth(cell) << '}';
2056 switch (GetAlignment(cell)) {
2057 case LYX_ALIGN_LEFT:
2060 case LYX_ALIGN_RIGHT:
2068 if (RightLine(cell))
2070 if (((cell + 1) < numberofcells) && !IsFirstCellInRow(cell+1) &&
2076 if (GetUsebox(cell) == BOX_PARBOX) {
2078 switch (GetVAlignment(cell)) {
2079 case LYX_VALIGN_TOP:
2082 case LYX_VALIGN_CENTER:
2085 case LYX_VALIGN_BOTTOM:
2089 os << "]{" << GetPWidth(cell) << "}{";
2090 } else if (GetUsebox(cell) == BOX_MINIPAGE) {
2091 os << "\\begin{minipage}[";
2092 switch (GetVAlignment(cell)) {
2093 case LYX_VALIGN_TOP:
2096 case LYX_VALIGN_CENTER:
2099 case LYX_VALIGN_BOTTOM:
2103 os << "]{" << GetPWidth(cell) << "}\n";
2110 int LyXTabular::TeXCellPostamble(ostream & os, int cell) const
2115 if (GetUsebox(cell) == BOX_PARBOX)
2117 else if (GetUsebox(cell) == BOX_MINIPAGE) {
2118 os << "%\n\\end{minipage}";
2121 if (IsMultiColumn(cell)){
2124 if (GetRotateCell(cell)) {
2125 os << "%\n\\end{sideways}";
2132 int LyXTabular::Latex(Buffer const * buf,
2133 ostream & os, bool fragile, bool fp) const
2138 //+---------------------------------------------------------------------
2139 //+ first the opening preamble +
2140 //+---------------------------------------------------------------------
2143 os << "\\begin{sideways}\n";
2146 if (is_long_tabular)
2147 os << "\\begin{longtable}{";
2149 os << "\\begin{tabular}{";
2150 for (int i = 0; i < columns_; ++i) {
2151 if (column_info[i].left_line)
2153 if (!column_info[i].align_special.empty()) {
2154 os << column_info[i].align_special;
2155 } else if (!column_info[i].p_width.empty()) {
2156 switch (column_info[i].valignment) {
2157 case LYX_VALIGN_TOP:
2160 case LYX_VALIGN_CENTER:
2163 case LYX_VALIGN_BOTTOM:
2168 << column_info[i].p_width
2171 switch (column_info[i].alignment) {
2172 case LYX_ALIGN_LEFT:
2175 case LYX_ALIGN_RIGHT:
2183 if (column_info[i].right_line)
2189 //+---------------------------------------------------------------------
2190 //+ the single row and columns (cells) +
2191 //+---------------------------------------------------------------------
2194 for (int i = 0; i < rows_; ++i) {
2195 ret += TeXTopHLine(os, i);
2197 if (IsLongTabular()) {
2198 if ((endhead < 0) && (i == (abs(endhead)-1))) {
2199 os << "\\endhead\n";
2202 if ((endfirsthead < 0) && (i == (abs(endfirsthead)-1))) {
2203 os << "\\endfirsthead\n";
2206 if ((endfoot < 0) && (i == (abs(endfoot)-1))) {
2207 os << "\\endfoot\n";
2210 if ((endlastfoot < 0) && (i == (abs(endlastfoot)-1))) {
2211 os << "\\endlastfoot\n";
2217 ret += TeXBottomHLine(os, i-1);
2218 ret += TeXTopHLine(os, i);
2220 for (int j = 0; j < columns_; ++j) {
2221 if (IsPartOfMultiColumn(i,j))
2223 ret += TeXCellPreamble(os, cell);
2224 ret += GetCellInset(cell)->Latex(buf, os, fragile, fp);
2225 ret += TeXCellPostamble(os, cell);
2226 if (!IsLastCellInRow(cell)) { // not last cell in row
2233 ret += TeXBottomHLine(os, i);
2235 if (IsLongTabular()) {
2236 if ((endhead > 0) && (i == (endhead - 1))) {
2237 os << "\\endhead\n";
2240 if ((endfirsthead > 0) && (i == (endfirsthead - 1))) {
2241 os << "\\endfirsthead\n";
2244 if ((endfoot > 0) && (i == (endfoot - 1))) {
2245 os << "\\endfoot\n";
2248 if ((endlastfoot > 0) && (i == (endlastfoot - 1))) {
2249 os << "\\endlastfoot\n";
2253 ret += TeXBottomHLine(os, i);
2254 if (row_info[i].newpage) {
2255 os << "\\newpage\n";
2261 //+---------------------------------------------------------------------
2262 //+ the closing of the tabular +
2263 //+---------------------------------------------------------------------
2265 if (is_long_tabular)
2266 os << "\\end{longtable}";
2268 os << "\\end{tabular}";
2270 os << "\n\\end{sideways}";
2278 int LyXTabular::DocBook(Buffer const * buf, ostream & os) const
2282 //+---------------------------------------------------------------------
2283 //+ first the opening preamble +
2284 //+---------------------------------------------------------------------
2286 os << "<tgroup cols=\"" << columns_
2287 << "\" colsep=\"1\" rowsep=\"1\">\n";
2289 for (int i = 0; i < columns_; ++i) {
2290 os << "<colspec colname=\"col" << i << "\" align=\"";
2291 switch (column_info[i].alignment) {
2292 case LYX_ALIGN_LEFT:
2295 case LYX_ALIGN_RIGHT:
2306 //+---------------------------------------------------------------------
2307 //+ the single row and columns (cells) +
2308 //+---------------------------------------------------------------------
2312 for (int i = 0; i < rows_; ++i) {
2314 for (int j = 0; j < columns_; ++j) {
2315 if (IsPartOfMultiColumn(i, j))
2318 os << "<entry align=\"";
2319 switch (GetAlignment(cell)) {
2320 case LYX_ALIGN_LEFT:
2323 case LYX_ALIGN_RIGHT:
2331 os << "\" valign=\"";
2332 switch (GetVAlignment(cell)) {
2333 case LYX_VALIGN_TOP:
2336 case LYX_VALIGN_BOTTOM:
2339 case LYX_VALIGN_CENTER:
2344 if (IsMultiColumn(cell)) {
2345 os << " namest=\"col" << j << "\" ";
2346 os << "nameend=\"col" << j + cells_in_multicolumn(cell) - 1<< "\"";
2350 ret += GetCellInset(cell)->DocBook(buf, os);
2357 //+---------------------------------------------------------------------
2358 //+ the closing of the tabular +
2359 //+---------------------------------------------------------------------
2370 void print_n_chars(ostream & os, unsigned char ch, int n)
2372 os << string(n, ch);
2376 int LyXTabular::AsciiTopHLine(ostream & os, int row,
2377 vector<unsigned int> const & clen) const
2379 int const fcell = GetFirstCellInRow(row);
2380 int const n = NumberOfCellsInRow(fcell) + fcell;
2385 for (int i = fcell; i < n; ++i) {
2392 // Isn't this equivalent? (Lgb)
2393 #ifdef WITH_WARNINGS
2394 #warning Please check this Jürgen.
2396 // If ok please delete the abofe #if 0 section. (Lgb)
2397 for (int i = fcell; i < n; ++i) {
2404 for (int i = fcell; i < n; ++i) {
2415 int column = column_of_cell(i);
2416 int len = clen[column];
2417 while(IsPartOfMultiColumn(row, ++column))
2418 len += clen[column] + 4;
2419 print_n_chars(os, ch, len);
2434 int LyXTabular::AsciiBottomHLine(ostream & os, int row,
2435 vector<unsigned int> const & clen) const
2437 int const fcell = GetFirstCellInRow(row);
2438 int const n = NumberOfCellsInRow(fcell) + fcell;
2443 for (int i = fcell; i < n; ++i) {
2450 // Isn't this equivalent? (Lgb)
2451 #ifdef WITH_WARNINGS
2452 #warning Please check this Jürgen.
2454 // If ok, please delete the above #if 0 section. (Lgb)
2455 for (int i = fcell; i < n; ++i) {
2461 for (int i = fcell; i < n; ++i) {
2462 if (BottomLine(i)) {
2472 int column = column_of_cell(i);
2473 int len = clen[column];
2474 while(IsPartOfMultiColumn(row, ++column))
2475 len += clen[column] + 4;
2476 print_n_chars(os, ch, len);
2477 if (BottomLine(i)) {
2491 int LyXTabular::AsciiPrintCell(Buffer const * buf, ostream & os,
2492 int cell, int row, int column,
2493 vector<unsigned int> const & clen) const
2496 int ret = GetCellInset(cell)->Ascii(buf, sstr, 0);
2503 unsigned int len1 = sstr.str().length();
2504 unsigned int len2 = clen[column];
2505 while(IsPartOfMultiColumn(row, ++column))
2506 len2 += clen[column] + 4;
2509 switch (GetAlignment(cell)) {
2511 case LYX_ALIGN_LEFT:
2514 case LYX_ALIGN_RIGHT:
2518 case LYX_ALIGN_CENTER:
2524 for (unsigned int i = 0; i < len1; ++i)
2527 for (unsigned int i = 0; i < len2; ++i)
2529 if (RightLine(cell))
2534 return ret * 0; // eh? (Lgb)
2538 int LyXTabular::Ascii(Buffer const * buf, ostream & os) const
2542 //+---------------------------------------------------------------------
2543 //+ first calculate the width of the single columns +
2544 //+---------------------------------------------------------------------
2545 vector<unsigned int> clen(columns_);
2547 // first all non (real) multicolumn cells!
2548 for (int j = 0; j < columns_; ++j) {
2550 for (int i = 0; i < rows_; ++i) {
2551 int cell = GetCellNumber(i, j);
2552 if (IsMultiColumn(cell, true))
2555 GetCellInset(cell)->Ascii(buf, sstr, 0);
2556 if (clen[j] < sstr.str().length())
2557 clen[j] = sstr.str().length();
2560 // then all (real) multicolumn cells!
2561 for (int j = 0; j < columns_; ++j) {
2562 for (int i = 0; i < rows_; ++i) {
2563 int cell = GetCellNumber(i, j);
2564 if (!IsMultiColumn(cell, true) || IsPartOfMultiColumn(i, j))
2567 GetCellInset(cell)->Ascii(buf, sstr, 0);
2568 int len = int(sstr.str().length());
2569 int const n = cells_in_multicolumn(cell);
2570 for (int k = j; (len > 0) && (k < (j + n - 1)); ++k)
2572 if (len > int(clen[j + n - 1]))
2573 clen[j + n - 1] = len;
2577 for (int i = 0; i < rows_; ++i) {
2578 AsciiTopHLine(os, i, clen);
2579 for (int j = 0; j < columns_; ++j) {
2580 if (IsPartOfMultiColumn(i,j))
2582 ret += AsciiPrintCell(buf, os, cell, i, j, clen);
2586 AsciiBottomHLine(os, i, clen);
2592 InsetText * LyXTabular::GetCellInset(int cell) const
2594 return & cell_info[row_of_cell(cell)][column_of_cell(cell)].inset;
2598 void LyXTabular::Validate(LaTeXFeatures & features) const
2600 if (IsLongTabular())
2601 features.longtable = true;
2603 features.rotating = true;
2604 for (int cell = 0; cell < numberofcells; ++cell) {
2605 if (GetVAlignment(cell) != LYX_VALIGN_TOP)
2606 features.array = true;
2607 GetCellInset(cell)->Validate(features);
2612 LyXTabular::BoxType LyXTabular::UseParbox(int cell) const
2614 LyXParagraph * par = GetCellInset(cell)->par;
2616 for (; par; par = par->next) {
2617 for (int i = 0; i < par->Last(); ++i) {
2618 if (par->GetChar(i) == LyXParagraph::META_NEWLINE)