2 * \file InsetTabular.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Matthias Ettrich
9 * \author Jean-Marc Lasgouttes
10 * \author Angus Leeming
12 * \author André Pönitz
13 * \author Jürgen Vigna
15 * Full author contact details are available in file CREDITS.
20 #include "InsetTabular.h"
22 #include "buffer_funcs.h"
24 #include "BufferParams.h"
25 #include "BufferView.h"
26 #include "CoordCache.h"
29 #include "CutAndPaste.h"
30 #include "DispatchResult.h"
31 #include "FuncRequest.h"
32 #include "FuncStatus.h"
34 #include "LaTeXFeatures.h"
38 #include "MetricsInfo.h"
39 #include "OutputParams.h"
40 #include "paragraph_funcs.h"
41 #include "Paragraph.h"
42 #include "ParagraphParameters.h"
43 #include "ParIterator.h"
44 #include "TextClass.h"
45 #include "TextMetrics.h"
47 #include "frontends/Application.h"
48 #include "frontends/alert.h"
49 #include "frontends/Clipboard.h"
50 #include "frontends/Painter.h"
51 #include "frontends/Selection.h"
53 #include "support/convert.h"
54 #include "support/debug.h"
55 #include "support/docstream.h"
56 #include "support/FileName.h"
57 #include "support/gettext.h"
58 #include "support/lassert.h"
59 #include "support/lstrings.h"
61 #include <boost/scoped_ptr.hpp>
69 using namespace lyx::support;
71 using boost::shared_ptr;
72 using boost::dynamic_pointer_cast;
77 using cap::dirtyTabularStack;
78 using cap::tabularStackDirty;
80 using graphics::PreviewLoader;
82 using frontend::Painter;
83 using frontend::Clipboard;
85 namespace Alert = frontend::Alert;
90 int const ADD_TO_HEIGHT = 2; // in cell
91 int const ADD_TO_TABULAR_WIDTH = 6; // horiz space before and after the table
92 int const default_line_space = 10; // ?
93 int const WIDTH_OF_LINE = 5; // space between double lines
97 boost::scoped_ptr<Tabular> paste_tabular;
100 struct TabularFeature {
101 Tabular::Feature action;
106 TabularFeature tabularFeature[] =
108 { Tabular::APPEND_ROW, "append-row" },
109 { Tabular::APPEND_COLUMN, "append-column" },
110 { Tabular::DELETE_ROW, "delete-row" },
111 { Tabular::DELETE_COLUMN, "delete-column" },
112 { Tabular::COPY_ROW, "copy-row" },
113 { Tabular::COPY_COLUMN, "copy-column" },
114 { Tabular::TOGGLE_LINE_TOP, "toggle-line-top" },
115 { Tabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
116 { Tabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
117 { Tabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
118 { Tabular::ALIGN_LEFT, "align-left" },
119 { Tabular::ALIGN_RIGHT, "align-right" },
120 { Tabular::ALIGN_CENTER, "align-center" },
121 { Tabular::ALIGN_BLOCK, "align-block" },
122 { Tabular::VALIGN_TOP, "valign-top" },
123 { Tabular::VALIGN_BOTTOM, "valign-bottom" },
124 { Tabular::VALIGN_MIDDLE, "valign-middle" },
125 { Tabular::M_ALIGN_LEFT, "m-align-left" },
126 { Tabular::M_ALIGN_RIGHT, "m-align-right" },
127 { Tabular::M_ALIGN_CENTER, "m-align-center" },
128 { Tabular::M_VALIGN_TOP, "m-valign-top" },
129 { Tabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
130 { Tabular::M_VALIGN_MIDDLE, "m-valign-middle" },
131 { Tabular::MULTICOLUMN, "multicolumn" },
132 { Tabular::SET_ALL_LINES, "set-all-lines" },
133 { Tabular::UNSET_ALL_LINES, "unset-all-lines" },
134 { Tabular::SET_LONGTABULAR, "set-longtabular" },
135 { Tabular::UNSET_LONGTABULAR, "unset-longtabular" },
136 { Tabular::SET_PWIDTH, "set-pwidth" },
137 { Tabular::SET_MPWIDTH, "set-mpwidth" },
138 { Tabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
139 { Tabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
140 { Tabular::TOGGLE_ROTATE_TABULAR, "toggle-rotate-tabular" },
141 { Tabular::SET_ROTATE_CELL, "set-rotate-cell" },
142 { Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
143 { Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell" },
144 { Tabular::SET_USEBOX, "set-usebox" },
145 { Tabular::SET_LTHEAD, "set-lthead" },
146 { Tabular::UNSET_LTHEAD, "unset-lthead" },
147 { Tabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
148 { Tabular::UNSET_LTFIRSTHEAD, "unset-ltfirsthead" },
149 { Tabular::SET_LTFOOT, "set-ltfoot" },
150 { Tabular::UNSET_LTFOOT, "unset-ltfoot" },
151 { Tabular::SET_LTLASTFOOT, "set-ltlastfoot" },
152 { Tabular::UNSET_LTLASTFOOT, "unset-ltlastfoot" },
153 { Tabular::SET_LTNEWPAGE, "set-ltnewpage" },
154 { Tabular::TOGGLE_LTCAPTION, "toggle-ltcaption" },
155 { Tabular::SET_SPECIAL_COLUMN, "set-special-column" },
156 { Tabular::SET_SPECIAL_MULTI, "set-special-multi" },
157 { Tabular::SET_BOOKTABS, "set-booktabs" },
158 { Tabular::UNSET_BOOKTABS, "unset-booktabs" },
159 { Tabular::SET_TOP_SPACE, "set-top-space" },
160 { Tabular::SET_BOTTOM_SPACE, "set-bottom-space" },
161 { Tabular::SET_INTERLINE_SPACE, "set-interline-space" },
162 { Tabular::SET_BORDER_LINES, "set-border-lines" },
163 { Tabular::TABULAR_VALIGN_TOP, "tabular-valign-top"},
164 { Tabular::TABULAR_VALIGN_MIDDLE, "tabular-valign-middle"},
165 { Tabular::TABULAR_VALIGN_BOTTOM, "tabular-valign-bottom"},
166 { Tabular::LAST_ACTION, "" }
170 class FeatureEqual : public unary_function<TabularFeature, bool> {
172 FeatureEqual(Tabular::Feature feature)
173 : feature_(feature) {}
174 bool operator()(TabularFeature const & tf) const {
175 return tf.action == feature_;
178 Tabular::Feature feature_;
183 string const write_attribute(string const & name, T const & t)
185 string const s = tostr(t);
186 return s.empty() ? s : " " + name + "=\"" + s + "\"";
190 string const write_attribute(string const & name, string const & t)
192 return t.empty() ? t : " " + name + "=\"" + t + "\"";
197 string const write_attribute(string const & name, docstring const & t)
199 return t.empty() ? string() : " " + name + "=\"" + to_utf8(t) + "\"";
204 string const write_attribute(string const & name, bool const & b)
206 // we write only true attribute values so we remove a bit of the
207 // file format bloat for tabulars.
208 return b ? write_attribute(name, convert<string>(b)) : string();
213 string const write_attribute(string const & name, int const & i)
215 // we write only true attribute values so we remove a bit of the
216 // file format bloat for tabulars.
217 return i ? write_attribute(name, convert<string>(i)) : string();
222 string const write_attribute(string const & name, Tabular::idx_type const & i)
224 // we write only true attribute values so we remove a bit of the
225 // file format bloat for tabulars.
226 return i ? write_attribute(name, convert<string>(i)) : string();
231 string const write_attribute(string const & name, Length const & value)
233 // we write only the value if we really have one same reson as above.
234 return value.zero() ? string() : write_attribute(name, value.asString());
238 string const tostr(LyXAlignment const & num)
243 case LYX_ALIGN_BLOCK:
247 case LYX_ALIGN_CENTER:
249 case LYX_ALIGN_RIGHT:
251 case LYX_ALIGN_LAYOUT:
253 case LYX_ALIGN_SPECIAL:
260 string const tostr(Tabular::VAlignment const & num)
263 case Tabular::LYX_VALIGN_TOP:
265 case Tabular::LYX_VALIGN_MIDDLE:
267 case Tabular::LYX_VALIGN_BOTTOM:
274 string const tostr(Tabular::BoxType const & num)
277 case Tabular::BOX_NONE:
279 case Tabular::BOX_PARBOX:
281 case Tabular::BOX_MINIPAGE:
288 // I would have liked a fromstr template a lot better. (Lgb)
289 bool string2type(string const str, LyXAlignment & num)
292 num = LYX_ALIGN_NONE;
293 else if (str == "block")
294 num = LYX_ALIGN_BLOCK;
295 else if (str == "left")
296 num = LYX_ALIGN_LEFT;
297 else if (str == "center")
298 num = LYX_ALIGN_CENTER;
299 else if (str == "right")
300 num = LYX_ALIGN_RIGHT;
307 bool string2type(string const str, Tabular::VAlignment & num)
310 num = Tabular::LYX_VALIGN_TOP;
311 else if (str == "middle" )
312 num = Tabular::LYX_VALIGN_MIDDLE;
313 else if (str == "bottom")
314 num = Tabular::LYX_VALIGN_BOTTOM;
321 bool string2type(string const str, Tabular::BoxType & num)
324 num = Tabular::BOX_NONE;
325 else if (str == "parbox")
326 num = Tabular::BOX_PARBOX;
327 else if (str == "minipage")
328 num = Tabular::BOX_MINIPAGE;
335 bool string2type(string const str, bool & num)
339 else if (str == "false")
347 bool getTokenValue(string const & str, char const * token, string & ret)
350 size_t token_length = strlen(token);
351 size_t pos = str.find(token);
353 if (pos == string::npos || pos + token_length + 1 >= str.length()
354 || str[pos + token_length] != '=')
356 pos += token_length + 1;
358 if (ch != '"' && ch != '\'') { // only read till next space
362 while (pos < str.length() - 1 && str[++pos] != ch)
369 bool getTokenValue(string const & str, char const * token, docstring & ret)
372 bool const success = getTokenValue(str, token, tmp);
373 ret = from_utf8(tmp);
378 bool getTokenValue(string const & str, char const * token, int & num)
382 if (!getTokenValue(str, token, tmp))
384 num = convert<int>(tmp);
389 bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
392 return getTokenValue(str, token, tmp) && string2type(tmp, num);
396 bool getTokenValue(string const & str, char const * token,
397 Tabular::VAlignment & num)
400 return getTokenValue(str, token, tmp) && string2type(tmp, num);
404 bool getTokenValue(string const & str, char const * token,
405 Tabular::BoxType & num)
408 return getTokenValue(str, token, tmp) && string2type(tmp, num);
412 bool getTokenValue(string const & str, char const * token, bool & flag)
414 // set the flag always to false as this should be the default for bools
415 // not in the file-format.
418 return getTokenValue(str, token, tmp) && string2type(tmp, flag);
422 bool getTokenValue(string const & str, char const * token, Length & len)
424 // set the length to be zero() as default as this it should be if not
425 // in the file format.
428 return getTokenValue(str, token, tmp) && isValidLength(tmp, &len);
432 bool getTokenValue(string const & str, char const * token, Length & len, bool & flag)
437 if (!getTokenValue(str, token, tmp))
439 if (tmp == "default") {
443 return isValidLength(tmp, &len);
447 void l_getline(istream & is, string & str)
450 while (str.empty()) {
452 if (!str.empty() && str[str.length() - 1] == '\r')
453 str.erase(str.length() - 1);
460 string const featureAsString(Tabular::Feature feature)
462 TabularFeature * end = tabularFeature +
463 sizeof(tabularFeature) / sizeof(TabularFeature);
464 TabularFeature * it = find_if(tabularFeature, end,
465 FeatureEqual(feature));
466 return (it == end) ? string() : it->feature;
471 /////////////////////////////////////////////////////////////////////
475 /////////////////////////////////////////////////////////////////////
478 Tabular::CellData::CellData(Buffer & buf)
481 multicolumn(Tabular::CELL_NORMAL),
482 alignment(LYX_ALIGN_CENTER),
483 valignment(LYX_VALIGN_TOP),
490 inset(new InsetTableCell(buf))
492 inset->setBuffer(const_cast<Buffer &>(buf));
496 Tabular::CellData::CellData(CellData const & cs)
499 multicolumn(cs.multicolumn),
500 alignment(cs.alignment),
501 valignment(cs.valignment),
502 top_line(cs.top_line),
503 bottom_line(cs.bottom_line),
504 left_line(cs.left_line),
505 right_line(cs.right_line),
508 align_special(cs.align_special),
510 inset(dynamic_cast<InsetTableCell *>(cs.inset->clone()))
514 Tabular::CellData & Tabular::CellData::operator=(CellData cs)
520 void Tabular::CellData::swap(CellData & rhs)
522 std::swap(cellno, rhs.cellno);
523 std::swap(width, rhs.width);
524 std::swap(multicolumn, rhs.multicolumn);
525 std::swap(alignment, rhs.alignment);
526 std::swap(valignment, rhs.valignment);
527 std::swap(top_line, rhs.top_line);
528 std::swap(bottom_line, rhs.bottom_line);
529 std::swap(left_line, rhs.left_line);
530 std::swap(right_line, rhs.right_line);
531 std::swap(usebox, rhs.usebox);
532 std::swap(rotate, rhs.rotate);
533 std::swap(align_special, rhs.align_special);
534 p_width.swap(rhs.p_width);
535 inset.swap(rhs.inset);
539 Tabular::RowData::RowData()
542 top_space_default(false),
543 bottom_space_default(false),
544 interline_space_default(false),
554 Tabular::ColumnData::ColumnData()
555 : alignment(LYX_ALIGN_CENTER),
556 valignment(LYX_VALIGN_TOP),
562 Tabular::ltType::ltType()
569 Tabular::Tabular(Buffer & buffer, row_type rows_arg, col_type columns_arg)
571 init(buffer, rows_arg, columns_arg);
575 void Tabular::setBuffer(Buffer & buffer)
578 size_t row_count = row_info.size();
579 size_t column_count = column_info.size();
580 // set silly default lines
581 for (row_type i = 0; i < row_count; ++i)
582 for (col_type j = 0; j < column_count; ++j)
583 cell_info[i][j].inset->setBuffer(*buffer_);
587 // activates all lines and sets all widths to 0
588 void Tabular::init(Buffer & buf, row_type rows_arg,
589 col_type columns_arg)
592 row_info = row_vector(rows_arg);
593 column_info = column_vector(columns_arg);
594 cell_info = cell_vvector(rows_arg, cell_vector(columns_arg, CellData(buf)));
595 row_info.reserve(10);
596 column_info.reserve(10);
597 cell_info.reserve(100);
599 is_long_tabular = false;
600 tabular_valignment = LYX_VALIGN_MIDDLE;
602 use_booktabs = false;
603 size_t row_count = row_info.size();
604 size_t column_count = column_info.size();
605 // set silly default lines
606 for (row_type i = 0; i < row_count; ++i)
607 for (col_type j = 0; j < column_count; ++j) {
608 cell_info[i][j].inset->setBuffer(*buffer_);
609 cell_info[i][j].top_line = true;
610 cell_info[i][j].left_line = true;
611 cell_info[i][j].bottom_line = i == 0 || i == row_count - 1;
612 cell_info[i][j].right_line = j == column_count - 1;
617 void Tabular::appendRow(idx_type const cell)
619 BufferParams const & bp = buffer().params();
620 row_type const row = cellRow(cell);
622 row_vector::iterator rit = row_info.begin() + row;
623 row_info.insert(rit, RowData());
624 // now set the values of the row before
625 row_info[row] = row_info[row + 1];
627 row_type const nrows = row_info.size();
628 col_type const ncols = column_info.size();
630 cell_vvector old(nrows - 1);
631 for (row_type i = 0; i < nrows - 1; ++i)
632 swap(cell_info[i], old[i]);
634 cell_info = cell_vvector(nrows, cell_vector(ncols, CellData(buffer())));
636 for (row_type i = 0; i <= row; ++i)
637 swap(cell_info[i], old[i]);
638 for (row_type i = row + 2; i < nrows; ++i)
639 swap(cell_info[i], old[i - 1]);
642 for (col_type c = 0; c < ncols; ++c) {
643 // inherit line settings
644 idx_type const i = cellIndex(row + 1, c);
645 idx_type const j = cellIndex(row, c);
646 setLeftLine(i, leftLine(j));
647 setRightLine(i, rightLine(j));
648 setTopLine(i, topLine(j));
649 if (topLine(j) && bottomLine(j)) {
650 setBottomLine(i, true);
651 setBottomLine(j, false);
653 // mark track changes
655 cellInfo(i).inset->setChange(Change(Change::INSERTED));
660 void Tabular::deleteRow(row_type const row)
662 // Not allowed to delete last row
663 if (row_info.size() == 1)
666 row_info.erase(row_info.begin() + row);
667 cell_info.erase(cell_info.begin() + row);
672 void Tabular::copyRow(row_type const row)
674 row_info.insert(row_info.begin() + row, row_info[row]);
675 cell_info.insert(cell_info.begin() + row, cell_info[row]);
677 if (buffer().params().trackChanges)
678 for (col_type j = 0; j < column_info.size(); ++j)
679 cell_info[row + 1][j].inset->setChange(Change(Change::INSERTED));
685 void Tabular::appendColumn(idx_type const cell)
687 col_type const c = cellColumn(cell);
688 column_vector::iterator cit = column_info.begin() + c + 1;
689 column_info.insert(cit, ColumnData());
690 row_type const nrows = row_info.size();
691 // set the column values of the column before
692 column_info[c + 1] = column_info[c];
694 for (row_type r = 0; r < nrows; ++r) {
695 cell_info[r].insert(cell_info[r].begin() + c + 1,
698 // FIXME: This code does not work. It deletes the cell's content and
699 // it triggers an assertion if the cursor is at pos > 0.
700 if (cell_info[r][c].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
701 cell_info[r][c + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
703 cell_info[r][c + 1].multicolumn = cell_info[r][c].multicolumn;
707 for (row_type r = 0; r < nrows; ++r) {
708 // inherit line settings
709 idx_type const i = cellIndex(r, c + 1);
710 idx_type const j = cellIndex(r, c);
711 setBottomLine(i, bottomLine(j));
712 setTopLine(i, topLine(j));
713 setLeftLine(i, leftLine(j));
714 if (rightLine(j) && rightLine(j)) {
715 setRightLine(i, true);
716 setRightLine(j, false);
719 cellInfo(i).inset->clear();
720 if (buffer().params().trackChanges)
721 cellInfo(i).inset->setChange(Change(Change::INSERTED));
726 void Tabular::deleteColumn(col_type const column)
728 // Not allowed to delete last column
729 if (column_info.size() == 1)
732 size_t const row_count = row_info.size();
733 for (row_type i = 0; i < row_count; ++i) {
734 // Care about multicolumn cells
735 if (column + 1 < column_info.size() &&
736 cell_info[i][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN &&
737 cell_info[i][column + 1].multicolumn == CELL_PART_OF_MULTICOLUMN) {
738 cell_info[i][column + 1].multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
740 cell_info[i].erase(cell_info[i].begin() + column);
742 column_info.erase(column_info.begin() + column);
747 void Tabular::copyColumn(col_type const column)
749 BufferParams const & bp = buffer().params();
750 column_info.insert(column_info.begin() + column, column_info[column]);
752 size_t row_count = row_info.size();
753 for (row_type i = 0; i < row_count; ++i)
754 cell_info[i].insert(cell_info[i].begin() + column, cell_info[i][column]);
757 for (row_type i = 0; i < row_count; ++i)
758 cell_info[i][column + 1].inset->setChange(Change(Change::INSERTED));
763 void Tabular::updateIndexes()
765 col_type ncols = column_info.size();
766 row_type nrows = row_info.size();
768 for (row_type row = 0; row < nrows; ++row)
769 for (col_type column = 0; column < ncols; ++column) {
770 if (!isPartOfMultiColumn(row, column))
772 cell_info[row][column].cellno = numberofcells - 1;
775 rowofcell.resize(numberofcells);
776 columnofcell.resize(numberofcells);
778 for (row_type row = 0; row < nrows; ++row)
779 for (col_type column = 0; column < ncols; ++column) {
780 if (isPartOfMultiColumn(row, column))
783 columnofcell[i] = column;
784 setFixedWidth(row, column);
785 updateContentAlignment(row, column);
791 Tabular::idx_type Tabular::numberOfCellsInRow(idx_type const cell) const
793 row_type const row = cellRow(cell);
795 for (col_type i = 0; i < column_info.size(); ++i)
796 if (cell_info[row][i].multicolumn != Tabular::CELL_PART_OF_MULTICOLUMN)
802 bool Tabular::topLine(idx_type const cell) const
804 return cellInfo(cell).top_line;
808 bool Tabular::bottomLine(idx_type const cell) const
810 return cellInfo(cell).bottom_line;
814 bool Tabular::leftLine(idx_type cell) const
818 return cellInfo(cell).left_line;
822 bool Tabular::rightLine(idx_type cell) const
826 return cellInfo(cell).right_line;
830 bool Tabular::topAlreadyDrawn(idx_type cell) const
832 row_type row = cellRow(cell);
835 idx_type i = cellIndex(row - 1, cellColumn(cell));
836 return !rowTopLine(row) && bottomLine(i);
840 bool Tabular::leftAlreadyDrawn(idx_type cell) const
842 col_type col = cellColumn(cell);
845 idx_type i = cellIndex(cellRow(cell), col - 1);
846 return rightLine(i) && !leftLine(cell);
850 bool Tabular::isLastRow(idx_type cell) const
852 return cellRow(cell) == row_info.size() - 1;
856 int Tabular::getAdditionalHeight(row_type row) const
858 if (!row || row >= row_info.size())
861 int const interline_space = row_info[row - 1].interline_space_default ?
863 row_info[row - 1].interline_space.inPixels(width());
864 if (rowTopLine(row) && rowBottomLine(row - 1))
865 return interline_space + WIDTH_OF_LINE;
866 return interline_space;
870 int Tabular::getAdditionalWidth(idx_type cell) const
872 col_type const nextcol = cellColumn(cell) + columnSpan(cell);
874 && nextcol < column_info.size() && leftLine(cellIndex(cellRow(cell), nextcol)))
875 return WIDTH_OF_LINE;
880 int Tabular::columnWidth(idx_type cell) const
883 col_type const span = columnSpan(cell);
884 col_type const col = cellColumn(cell);
885 for(col_type c = col; c < col + span ; ++c)
886 w += column_info[c].width;
891 bool Tabular::updateColumnWidths()
893 col_type const ncols = column_info.size();
894 row_type const nrows = row_info.size();
896 // for each col get max of single col cells
897 for(col_type c = 0; c < ncols; ++c) {
899 for(row_type r = 0; r < nrows; ++r) {
900 idx_type const i = cellIndex(r, c);
901 if (columnSpan(i) == 1)
902 new_width = max(new_width, cellInfo(i).width);
905 if (column_info[c].width != new_width) {
906 column_info[c].width = new_width;
910 // update col widths to fit merged cells
911 for(col_type c = 0; c < ncols; ++c)
912 for(row_type r = 0; r < nrows; ++r) {
913 idx_type const i = cellIndex(r, c);
914 int const span = columnSpan(i);
915 if (span == 1 || c > cellColumn(i))
919 for(col_type j = c; j < c + span ; ++j)
920 old_width += column_info[j].width;
922 if (cellInfo(i).width > old_width) {
923 column_info[c + span - 1].width += cellInfo(i).width - old_width;
932 int Tabular::width() const
934 col_type const ncols = column_info.size();
936 for (col_type i = 0; i < ncols; ++i)
937 width += column_info[i].width;
942 void Tabular::setCellWidth(idx_type cell, int new_width)
944 cellInfo(cell).width = new_width + 2 * WIDTH_OF_LINE
945 + getAdditionalWidth(cell);
949 void Tabular::setAlignment(idx_type cell, LyXAlignment align,
952 if (!isMultiColumn(cell) || onlycolumn)
953 column_info[cellColumn(cell)].alignment = align;
955 cellInfo(cell).alignment = align;
956 cellInset(cell).get()->setContentAlignment(align);
960 void Tabular::setVAlignment(idx_type cell, VAlignment align,
963 if (!isMultiColumn(cell) || onlycolumn)
964 column_info[cellColumn(cell)].valignment = align;
966 cellInfo(cell).valignment = align;
973 * Allow line and paragraph breaks for fixed width cells or disallow them,
974 * merge cell paragraphs and reset layout to standard for variable width
977 void toggleFixedWidth(Cursor & cur, InsetTableCell * inset, bool fixedWidth)
979 inset->setAutoBreakRows(fixedWidth);
980 inset->toggleFixedWidth(fixedWidth);
984 // merge all paragraphs to one
985 BufferParams const & bp = cur.bv().buffer().params();
986 while (inset->paragraphs().size() > 1)
987 mergeParagraph(bp, inset->paragraphs(), 0);
991 // undo information has already been recorded
992 inset->getText(0)->setLayout(cur.bv().buffer(), 0, cur.lastpit() + 1,
993 bp.documentClass().plainLayoutName());
1000 void Tabular::setColumnPWidth(Cursor & cur, idx_type cell,
1001 Length const & width)
1003 col_type const j = cellColumn(cell);
1005 column_info[j].p_width = width;
1006 for (row_type i = 0; i < row_info.size(); ++i) {
1007 idx_type const cell = cellIndex(i, j);
1008 // because of multicolumns
1009 toggleFixedWidth(cur, cellInset(cell).get(),
1010 !getPWidth(cell).zero());
1012 // cur paragraph can become invalid after paragraphs were merged
1013 if (cur.pit() > cur.lastpit())
1014 cur.pit() = cur.lastpit();
1015 // cur position can become invalid after newlines were removed
1016 if (cur.pos() > cur.lastpos())
1017 cur.pos() = cur.lastpos();
1021 bool Tabular::setFixedWidth(row_type r, col_type c)
1023 bool const multicol = cell_info[r][c].multicolumn != CELL_NORMAL;
1024 bool const fixed_width = (!column_info[c].p_width.zero() && !multicol)
1025 || (multicol && !cell_info[r][c].p_width.zero());
1026 cell_info[r][c].inset->toggleFixedWidth(fixed_width);
1031 void Tabular::updateContentAlignment(row_type r, col_type c)
1033 cell_info[r][c].inset->setContentAlignment(
1034 getAlignment(cellIndex(r, c)));
1038 bool Tabular::setMColumnPWidth(Cursor & cur, idx_type cell,
1039 Length const & width)
1041 if (!isMultiColumn(cell))
1044 cellInfo(cell).p_width = width;
1045 toggleFixedWidth(cur, cellInset(cell).get(), !width.zero());
1046 // cur paragraph can become invalid after paragraphs were merged
1047 if (cur.pit() > cur.lastpit())
1048 cur.pit() = cur.lastpit();
1049 // cur position can become invalid after newlines were removed
1050 if (cur.pos() > cur.lastpos())
1051 cur.pos() = cur.lastpos();
1056 void Tabular::setAlignSpecial(idx_type cell, docstring const & special,
1057 Tabular::Feature what)
1059 if (what == SET_SPECIAL_MULTI)
1060 cellInfo(cell).align_special = special;
1062 column_info[cellColumn(cell)].align_special = special;
1066 void Tabular::setAllLines(idx_type cell, bool line)
1068 setTopLine(cell, line);
1069 setBottomLine(cell, line);
1070 setRightLine(cell, line);
1071 setLeftLine(cell, line);
1075 void Tabular::setTopLine(idx_type i, bool line)
1077 cellInfo(i).top_line = line;
1081 void Tabular::setBottomLine(idx_type i, bool line)
1083 cellInfo(i).bottom_line = line;
1087 void Tabular::setLeftLine(idx_type cell, bool line)
1089 cellInfo(cell).left_line = line;
1093 void Tabular::setRightLine(idx_type cell, bool line)
1095 cellInfo(cell).right_line = line;
1098 bool Tabular::rowTopLine(row_type r) const
1100 idx_type i0 = getFirstCellInRow(r);
1101 idx_type i1 = getLastCellInRow(r);
1102 bool all_rows_set = true;
1103 for (idx_type j = i0; all_rows_set && j <= i1; ++j)
1104 all_rows_set = cellInfo(j).top_line;
1105 return all_rows_set;
1109 bool Tabular::rowBottomLine(row_type r) const
1111 idx_type i0 = getFirstCellInRow(r);
1112 idx_type i1 = getLastCellInRow(r);
1113 bool all_rows_set = true;
1114 for (idx_type j = i0; all_rows_set && j <= i1; ++j)
1115 all_rows_set = cellInfo(j).bottom_line;
1116 return all_rows_set;
1120 bool Tabular::columnLeftLine(col_type c) const
1127 row_type const nrows = row_info.size();
1128 for (row_type r = 0; r < nrows; ++r) {
1129 idx_type i = cellIndex(r, c);
1130 if (c == cellColumn(i)) {
1132 bool right = c > 0 && cellInfo(cellIndex(r, c - 1)).right_line;
1133 if (cellInfo(i).left_line || right)
1137 return 2 * nrows_left >= total;
1141 bool Tabular::columnRightLine(col_type c) const
1146 int nrows_right = 0;
1148 row_type const nrows = row_info.size();
1149 for (row_type r = 0; r < nrows; ++r) {
1150 idx_type i = cellIndex(r, c);
1151 if (c == cellColumn(i) + columnSpan(i) - 1) {
1153 bool left = (c + 1 < column_info.size()
1154 && cellInfo(cellIndex(r, c + 1)).left_line)
1155 || c + 1 == column_info.size();
1156 if (cellInfo(i).right_line && left)
1160 return 2 * nrows_right >= total;
1164 LyXAlignment Tabular::getAlignment(idx_type cell, bool onlycolumn) const
1166 if (!onlycolumn && isMultiColumn(cell))
1167 return cellInfo(cell).alignment;
1168 return column_info[cellColumn(cell)].alignment;
1173 Tabular::getVAlignment(idx_type cell, bool onlycolumn) const
1175 if (!onlycolumn && isMultiColumn(cell))
1176 return cellInfo(cell).valignment;
1177 return column_info[cellColumn(cell)].valignment;
1181 Length const Tabular::getPWidth(idx_type cell) const
1183 if (isMultiColumn(cell))
1184 return cellInfo(cell).p_width;
1185 return column_info[cellColumn(cell)].p_width;
1189 int Tabular::cellWidth(idx_type cell) const
1191 return cellInfo(cell).width;
1195 int Tabular::getBeginningOfTextInCell(idx_type cell) const
1199 switch (getAlignment(cell)) {
1200 case LYX_ALIGN_CENTER:
1201 x += (columnWidth(cell) - cellWidth(cell)) / 2;
1203 case LYX_ALIGN_RIGHT:
1204 x += columnWidth(cell) - cellWidth(cell);
1205 // + getAdditionalWidth(cell);
1208 // LYX_ALIGN_LEFT: nothing :-)
1212 // the LaTeX Way :-(
1218 bool Tabular::isFirstCellInRow(idx_type cell) const
1220 return cellColumn(cell) == 0;
1224 Tabular::idx_type Tabular::getFirstCellInRow(row_type row) const
1226 if (row > row_info.size() - 1)
1227 row = row_info.size() - 1;
1228 return cell_info[row][0].cellno;
1232 bool Tabular::isLastCellInRow(idx_type cell) const
1234 return cellRightColumn(cell) == column_info.size() - 1;
1238 Tabular::idx_type Tabular::getLastCellInRow(row_type row) const
1240 if (row > row_info.size() - 1)
1241 row = row_info.size() - 1;
1242 return cell_info[row][column_info.size() - 1].cellno;
1246 Tabular::row_type Tabular::cellRow(idx_type cell) const
1248 if (cell >= numberofcells)
1249 return row_info.size() - 1;
1252 return rowofcell[cell];
1256 Tabular::col_type Tabular::cellColumn(idx_type cell) const
1258 if (cell >= numberofcells)
1259 return column_info.size() - 1;
1262 return columnofcell[cell];
1266 Tabular::col_type Tabular::cellRightColumn(idx_type cell) const
1268 row_type const row = cellRow(cell);
1269 col_type column = cellColumn(cell);
1270 while (column < column_info.size() - 1 &&
1271 cell_info[row][column + 1].multicolumn == CELL_PART_OF_MULTICOLUMN)
1277 void Tabular::write(ostream & os) const
1281 << write_attribute("version", 3)
1282 << write_attribute("rows", row_info.size())
1283 << write_attribute("columns", column_info.size())
1285 // global longtable options
1287 << write_attribute("rotate", rotate)
1288 << write_attribute("booktabs", use_booktabs)
1289 << write_attribute("islongtable", is_long_tabular)
1290 << write_attribute("tabularvalignment", tabular_valignment)
1291 << write_attribute("firstHeadTopDL", endfirsthead.topDL)
1292 << write_attribute("firstHeadBottomDL", endfirsthead.bottomDL)
1293 << write_attribute("firstHeadEmpty", endfirsthead.empty)
1294 << write_attribute("headTopDL", endhead.topDL)
1295 << write_attribute("headBottomDL", endhead.bottomDL)
1296 << write_attribute("footTopDL", endfoot.topDL)
1297 << write_attribute("footBottomDL", endfoot.bottomDL)
1298 << write_attribute("lastFootTopDL", endlastfoot.topDL)
1299 << write_attribute("lastFootBottomDL", endlastfoot.bottomDL)
1300 << write_attribute("lastFootEmpty", endlastfoot.empty)
1302 for (col_type j = 0; j < column_info.size(); ++j) {
1304 << write_attribute("alignment", column_info[j].alignment)
1305 << write_attribute("valignment", column_info[j].valignment)
1306 << write_attribute("width", column_info[j].p_width.asString())
1307 << write_attribute("special", column_info[j].align_special)
1310 for (row_type i = 0; i < row_info.size(); ++i) {
1311 static const string def("default");
1313 if (row_info[i].top_space_default)
1314 os << write_attribute("topspace", def);
1316 os << write_attribute("topspace", row_info[i].top_space);
1317 if (row_info[i].bottom_space_default)
1318 os << write_attribute("bottomspace", def);
1320 os << write_attribute("bottomspace", row_info[i].bottom_space);
1321 if (row_info[i].interline_space_default)
1322 os << write_attribute("interlinespace", def);
1324 os << write_attribute("interlinespace", row_info[i].interline_space);
1325 os << write_attribute("endhead", row_info[i].endhead)
1326 << write_attribute("endfirsthead", row_info[i].endfirsthead)
1327 << write_attribute("endfoot", row_info[i].endfoot)
1328 << write_attribute("endlastfoot", row_info[i].endlastfoot)
1329 << write_attribute("newpage", row_info[i].newpage)
1330 << write_attribute("caption", row_info[i].caption)
1332 for (col_type j = 0; j < column_info.size(); ++j) {
1334 << write_attribute("multicolumn", cell_info[i][j].multicolumn)
1335 << write_attribute("alignment", cell_info[i][j].alignment)
1336 << write_attribute("valignment", cell_info[i][j].valignment)
1337 << write_attribute("topline", cell_info[i][j].top_line)
1338 << write_attribute("bottomline", cell_info[i][j].bottom_line)
1339 << write_attribute("leftline", cell_info[i][j].left_line)
1340 << write_attribute("rightline", cell_info[i][j].right_line)
1341 << write_attribute("rotate", cell_info[i][j].rotate)
1342 << write_attribute("usebox", cell_info[i][j].usebox)
1343 << write_attribute("width", cell_info[i][j].p_width)
1344 << write_attribute("special", cell_info[i][j].align_special)
1346 os << "\\begin_inset ";
1347 cell_info[i][j].inset->write(os);
1348 os << "\n\\end_inset\n"
1353 os << "</lyxtabular>\n";
1357 void Tabular::read(Lexer & lex)
1360 istream & is = lex.getStream();
1362 l_getline(is, line);
1363 if (!prefixIs(line, "<lyxtabular ") && !prefixIs(line, "<Tabular ")) {
1364 LASSERT(false, /**/);
1369 if (!getTokenValue(line, "version", version))
1371 LASSERT(version >= 2, /**/);
1374 if (!getTokenValue(line, "rows", rows_arg))
1377 if (!getTokenValue(line, "columns", columns_arg))
1379 init(buffer(), rows_arg, columns_arg);
1380 l_getline(is, line);
1381 if (!prefixIs(line, "<features")) {
1382 lyxerr << "Wrong tabular format (expected <features ...> got"
1383 << line << ')' << endl;
1386 getTokenValue(line, "rotate", rotate);
1387 getTokenValue(line, "booktabs", use_booktabs);
1388 getTokenValue(line, "islongtable", is_long_tabular);
1389 getTokenValue(line, "tabularvalignment", tabular_valignment);
1390 getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
1391 getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
1392 getTokenValue(line, "firstHeadEmpty", endfirsthead.empty);
1393 getTokenValue(line, "headTopDL", endhead.topDL);
1394 getTokenValue(line, "headBottomDL", endhead.bottomDL);
1395 getTokenValue(line, "footTopDL", endfoot.topDL);
1396 getTokenValue(line, "footBottomDL", endfoot.bottomDL);
1397 getTokenValue(line, "lastFootTopDL", endlastfoot.topDL);
1398 getTokenValue(line, "lastFootBottomDL", endlastfoot.bottomDL);
1399 getTokenValue(line, "lastFootEmpty", endlastfoot.empty);
1401 for (col_type j = 0; j < column_info.size(); ++j) {
1403 if (!prefixIs(line,"<column")) {
1404 lyxerr << "Wrong tabular format (expected <column ...> got"
1405 << line << ')' << endl;
1408 getTokenValue(line, "alignment", column_info[j].alignment);
1409 getTokenValue(line, "valignment", column_info[j].valignment);
1410 getTokenValue(line, "width", column_info[j].p_width);
1411 getTokenValue(line, "special", column_info[j].align_special);
1414 for (row_type i = 0; i < row_info.size(); ++i) {
1415 l_getline(is, line);
1416 if (!prefixIs(line, "<row")) {
1417 lyxerr << "Wrong tabular format (expected <row ...> got"
1418 << line << ')' << endl;
1421 getTokenValue(line, "topspace", row_info[i].top_space,
1422 row_info[i].top_space_default);
1423 getTokenValue(line, "bottomspace", row_info[i].bottom_space,
1424 row_info[i].bottom_space_default);
1425 getTokenValue(line, "interlinespace", row_info[i].interline_space,
1426 row_info[i].interline_space_default);
1427 getTokenValue(line, "endfirsthead", row_info[i].endfirsthead);
1428 getTokenValue(line, "endhead", row_info[i].endhead);
1429 getTokenValue(line, "endfoot", row_info[i].endfoot);
1430 getTokenValue(line, "endlastfoot", row_info[i].endlastfoot);
1431 getTokenValue(line, "newpage", row_info[i].newpage);
1432 getTokenValue(line, "caption", row_info[i].caption);
1433 for (col_type j = 0; j < column_info.size(); ++j) {
1434 l_getline(is, line);
1435 if (!prefixIs(line, "<cell")) {
1436 lyxerr << "Wrong tabular format (expected <cell ...> got"
1437 << line << ')' << endl;
1440 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1441 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1442 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1443 getTokenValue(line, "topline", cell_info[i][j].top_line);
1444 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1445 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1446 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1447 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1448 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1449 getTokenValue(line, "width", cell_info[i][j].p_width);
1451 getTokenValue(line, "special", cell_info[i][j].align_special);
1452 l_getline(is, line);
1453 if (prefixIs(line, "\\begin_inset")) {
1454 cell_info[i][j].inset->setBuffer(*buffer_);
1455 cell_info[i][j].inset->read(lex);
1456 l_getline(is, line);
1458 if (!prefixIs(line, "</cell>")) {
1459 lyxerr << "Wrong tabular format (expected </cell> got"
1460 << line << ')' << endl;
1464 l_getline(is, line);
1465 if (!prefixIs(line, "</row>")) {
1466 lyxerr << "Wrong tabular format (expected </row> got"
1467 << line << ')' << endl;
1471 while (!prefixIs(line, "</lyxtabular>")) {
1472 l_getline(is, line);
1478 bool Tabular::isMultiColumn(idx_type cell) const
1480 return cellInfo(cell).multicolumn != CELL_NORMAL;
1484 bool Tabular::isMultiColumnReal(idx_type cell) const
1486 return cellColumn(cell) != cellRightColumn(cell) &&
1487 cellInfo(cell).multicolumn != CELL_NORMAL;
1491 Tabular::CellData & Tabular::cellInfo(idx_type cell) const
1493 return cell_info[cellRow(cell)][cellColumn(cell)];
1497 void Tabular::setMultiColumn(idx_type cell, idx_type number)
1499 CellData & cs = cellInfo(cell);
1500 cs.multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1501 cs.alignment = column_info[cellColumn(cell)].alignment;
1502 setRightLine(cell, rightLine(cell + number - 1));
1503 for (idx_type i = 1; i < number; ++i) {
1504 CellData & cs1 = cellInfo(cell + i);
1505 cs1.multicolumn = CELL_PART_OF_MULTICOLUMN;
1506 cs.inset->appendParagraphs(cs1.inset->paragraphs());
1513 Tabular::idx_type Tabular::columnSpan(idx_type cell) const
1515 row_type const row = cellRow(cell);
1516 col_type const ncols = column_info.size();
1517 idx_type result = 1;
1518 col_type column = cellColumn(cell) + 1;
1519 while (column < ncols && isPartOfMultiColumn(row, column)) {
1527 Tabular::idx_type Tabular::unsetMultiColumn(idx_type cell)
1529 row_type const row = cellRow(cell);
1530 col_type column = cellColumn(cell);
1532 idx_type result = 0;
1534 if (cell_info[row][column].multicolumn == CELL_BEGIN_OF_MULTICOLUMN) {
1535 cell_info[row][column].multicolumn = CELL_NORMAL;
1537 while (column < column_info.size() &&
1538 cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN)
1540 cell_info[row][column].multicolumn = CELL_NORMAL;
1550 void Tabular::setRotateCell(idx_type cell, bool flag)
1552 cellInfo(cell).rotate = flag;
1556 bool Tabular::getRotateCell(idx_type cell) const
1558 return cellInfo(cell).rotate;
1562 bool Tabular::needRotating() const
1566 for (row_type i = 0; i < row_info.size(); ++i)
1567 for (col_type j = 0; j < column_info.size(); ++j)
1568 if (cell_info[i][j].rotate)
1574 bool Tabular::isLastCell(idx_type cell) const
1576 if (cell + 1 < numberofcells)
1582 Tabular::idx_type Tabular::cellAbove(idx_type cell) const
1584 if (cellRow(cell) > 0)
1585 return cell_info[cellRow(cell)-1][cellColumn(cell)].cellno;
1590 Tabular::idx_type Tabular::cellBelow(idx_type cell) const
1592 if (cellRow(cell) + 1 < row_info.size())
1593 return cell_info[cellRow(cell)+1][cellColumn(cell)].cellno;
1598 Tabular::idx_type Tabular::cellIndex(row_type row,
1599 col_type column) const
1601 BOOST_ASSERT(column != npos && column < column_info.size()
1602 && row != npos && row < row_info.size());
1603 return cell_info[row][column].cellno;
1607 void Tabular::setUsebox(idx_type cell, BoxType type)
1609 cellInfo(cell).usebox = type;
1613 // FIXME: Remove this routine because we cannot insert \parboxes when the user
1614 // adds line breaks, see bug 4886.
1615 Tabular::BoxType Tabular::getUsebox(idx_type cell) const
1617 if ((!column_info[cellColumn(cell)].p_width.zero() && !isMultiColumn(cell)) ||
1618 (isMultiColumn(cell) && !cellInfo(cell).p_width.zero()))
1620 if (cellInfo(cell).usebox > 1)
1621 return cellInfo(cell).usebox;
1622 return useParbox(cell);
1627 // This are functions used for the longtable support
1629 void Tabular::setLTHead(row_type row, bool flag, ltType const & hd,
1635 row_info[row].endfirsthead = flag;
1639 row_info[row].endhead = flag;
1644 bool Tabular::getRowOfLTHead(row_type row, ltType & hd) const
1647 hd.set = haveLTHead();
1648 return row_info[row].endhead;
1652 bool Tabular::getRowOfLTFirstHead(row_type row, ltType & hd) const
1655 hd.set = haveLTFirstHead();
1656 return row_info[row].endfirsthead;
1660 void Tabular::setLTFoot(row_type row, bool flag, ltType const & fd,
1666 row_info[row].endlastfoot = flag;
1670 row_info[row].endfoot = flag;
1675 bool Tabular::getRowOfLTFoot(row_type row, ltType & fd) const
1678 fd.set = haveLTFoot();
1679 return row_info[row].endfoot;
1683 bool Tabular::getRowOfLTLastFoot(row_type row, ltType & fd) const
1686 fd.set = haveLTLastFoot();
1687 return row_info[row].endlastfoot;
1691 void Tabular::setLTNewPage(row_type row, bool what)
1693 row_info[row].newpage = what;
1697 bool Tabular::getLTNewPage(row_type row) const
1699 return row_info[row].newpage;
1703 bool Tabular::haveLTHead() const
1705 for (row_type i = 0; i < row_info.size(); ++i)
1706 if (row_info[i].endhead)
1712 bool Tabular::haveLTFirstHead() const
1714 if (endfirsthead.empty)
1716 for (row_type i = 0; i < row_info.size(); ++i)
1717 if (row_info[i].endfirsthead)
1723 bool Tabular::haveLTFoot() const
1725 for (row_type i = 0; i < row_info.size(); ++i)
1726 if (row_info[i].endfoot)
1732 bool Tabular::haveLTLastFoot() const
1734 if (endlastfoot.empty)
1736 for (row_type i = 0; i < row_info.size(); ++i)
1737 if (row_info[i].endlastfoot)
1743 Tabular::idx_type Tabular::setLTCaption(row_type row, bool what)
1745 idx_type i = getFirstCellInRow(row);
1747 setMultiColumn(i, numberOfCellsInRow(i));
1748 setTopLine(i, false);
1749 setBottomLine(i, false);
1750 setLeftLine(i, false);
1751 setRightLine(i, false);
1753 unsetMultiColumn(i);
1754 // FIXME: when unsetting a caption row, also all existing captions
1755 // in this row must be dissolved, see (bug 5754)
1756 // dispatch(FuncRequest(LFUN_INSET_DISSOLVE, "caption-insert"));
1758 row_info[row].caption = what;
1763 bool Tabular::ltCaption(row_type row) const
1765 return row_info[row].caption;
1769 bool Tabular::haveLTCaption() const
1771 for (row_type i = 0; i < row_info.size(); ++i)
1772 if (row_info[i].caption)
1778 // end longtable support functions
1780 void Tabular::setRowAscent(row_type row, int height)
1782 if (row >= row_info.size() || row_info[row].ascent == height)
1784 row_info[row].ascent = height;
1788 void Tabular::setRowDescent(row_type row, int height)
1790 if (row >= row_info.size() || row_info[row].descent == height)
1792 row_info[row].descent = height;
1796 int Tabular::rowAscent(row_type row) const
1798 if (row >= row_info.size())
1800 return row_info[row].ascent;
1804 int Tabular::rowDescent(row_type row) const
1806 LASSERT(row < row_info.size(), /**/);
1807 return row_info[row].descent;
1811 int Tabular::height() const
1814 for (row_type row = 0; row < row_info.size(); ++row)
1815 height += rowAscent(row) + rowDescent(row) +
1816 getAdditionalHeight(row);
1821 bool Tabular::isPartOfMultiColumn(row_type row, col_type column) const
1823 LASSERT(row < row_info.size(), /**/);
1824 LASSERT(column < column_info.size(), /**/);
1825 return cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN;
1829 int Tabular::TeXTopHLine(odocstream & os, row_type row, string const lang) const
1831 // we only output complete row lines and the 1st row here, the rest
1832 // is done in Tabular::TeXBottomHLine(...)
1834 // get for each column the topline (if any)
1835 col_type const ncols = column_info.size();
1836 vector<bool> topline;
1838 for (col_type c = 0; c < ncols; ++c) {
1839 topline.push_back(topLine(cellIndex(row, c)));
1844 // do nothing if empty first row, or incomplete row line after
1845 if ((row == 0 && nset == 0) || (row > 0 && nset != ncols))
1848 // only output complete row lines and the 1st row's clines
1849 if (nset == ncols) {
1851 os << (row == 0 ? "\\toprule " : "\\midrule ");
1855 } else if (row == 0) {
1856 for (col_type c = 0; c < ncols; ++c) {
1858 //babel makes the "-" character an active one, so we have to suppress this here
1859 //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
1860 if (lang == "slovak" || lang == "czech")
1861 os << (use_booktabs ? "\\expandafter\\cmidrule\\expandafter{\\expandafter" :
1862 "\\expandafter\\cline\\expandafter{\\expandafter")
1863 << c + 1 << "\\string-";
1865 os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 << '-';
1866 // get to last column of line span
1867 while (c < ncols && topline[c])
1878 int Tabular::TeXBottomHLine(odocstream & os, row_type row, string const lang) const
1880 // we output bottomlines of row r and the toplines of row r+1
1881 // if the latter do not span the whole tabular
1883 // get the bottomlines of row r, and toplines in next row
1884 bool lastrow = row == row_info.size() - 1;
1885 col_type const ncols = column_info.size();
1886 vector<bool> bottomline, topline;
1887 bool nextrowset = true;
1888 for (col_type c = 0; c < ncols; ++c) {
1889 bottomline.push_back(bottomLine(cellIndex(row, c)));
1890 topline.push_back(!lastrow && topLine(cellIndex(row + 1, c)));
1891 nextrowset &= topline[c];
1894 // combine this row's bottom lines and next row's toplines if necessary
1896 for (col_type c = 0; c < ncols; ++c) {
1898 bottomline[c] = bottomline[c] || topline[c];
1903 // do nothing if empty, OR incomplete row line with a topline in next row
1904 if (nset == 0 || (nextrowset && nset != ncols))
1907 if (nset == ncols) {
1909 os << (lastrow ? "\\bottomrule" : "\\midrule");
1913 for (col_type c = 0; c < ncols; ++c) {
1914 if (bottomline[c]) {
1915 //babel makes the "-" character an active one, so we have to suppress this here
1916 //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
1917 if (lang == "slovak" || lang == "czech")
1918 os << (use_booktabs ? "\\expandafter\\cmidrule\\expandafter{\\expandafter" :
1919 "\\expandafter\\cline\\expandafter{\\expandafter")
1920 << c + 1 << "\\string-";
1922 os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 << '-';
1923 // get to last column of line span
1924 while (c < ncols && bottomline[c])
1935 int Tabular::TeXCellPreamble(odocstream & os, idx_type cell, bool & ismulticol) const
1938 row_type const r = cellRow(cell);
1939 if (is_long_tabular && row_info[r].caption)
1942 Tabular::VAlignment valign = getVAlignment(cell, !isMultiColumn(cell));
1943 LyXAlignment align = getAlignment(cell, !isMultiColumn(cell));
1944 // figure out how to set the lines
1945 // we always set double lines to the right of the cell
1946 col_type const c = cellColumn(cell);
1947 col_type const nextcol = c + columnSpan(cell);
1948 bool colright = columnRightLine(c);
1949 bool colleft = columnLeftLine(c);
1950 bool nextcolleft = nextcol < column_info.size() && columnLeftLine(nextcol);
1951 bool nextcellleft = nextcol < column_info.size()
1952 && leftLine(cellIndex(r, nextcol));
1953 bool coldouble = colright && nextcolleft;
1954 bool celldouble = rightLine(cell) && nextcellleft;
1955 ismulticol = isMultiColumn(cell)
1956 || (c == 0 && colleft != leftLine(cell))
1957 || ((colright || nextcolleft) && !rightLine(cell) && !nextcellleft)
1958 || (!colright && !nextcolleft && (rightLine(cell) || nextcellleft))
1959 || (coldouble != celldouble);
1961 os << "\\multicolumn{" << columnSpan(cell) << "}{";
1962 if (c ==0 && leftLine(cell))
1964 if (!cellInfo(cell).align_special.empty()) {
1965 os << cellInfo(cell).align_special;
1967 if (!getPWidth(cell).zero()) {
1969 case LYX_ALIGN_LEFT:
1970 os << ">{\\raggedright}";
1972 case LYX_ALIGN_RIGHT:
1973 os << ">{\\raggedleft}";
1975 case LYX_ALIGN_CENTER:
1976 os << ">{\\centering}";
1982 case LYX_VALIGN_TOP:
1985 case LYX_VALIGN_MIDDLE:
1988 case LYX_VALIGN_BOTTOM:
1993 << from_ascii(getPWidth(cell).asLatexString())
1997 case LYX_ALIGN_LEFT:
2000 case LYX_ALIGN_RIGHT:
2007 } // end if else !getPWidth
2008 } // end if else !cellinfo_of_cell
2009 if (rightLine(cell) || nextcellleft)
2012 // add extra vertical line if we want a double one
2016 if (getRotateCell(cell)) {
2017 os << "\\begin{sideways}\n";
2020 if (getUsebox(cell) == BOX_PARBOX) {
2023 case LYX_VALIGN_TOP:
2026 case LYX_VALIGN_MIDDLE:
2029 case LYX_VALIGN_BOTTOM:
2033 os << "]{" << from_ascii(getPWidth(cell).asLatexString())
2035 } else if (getUsebox(cell) == BOX_MINIPAGE) {
2036 os << "\\begin{minipage}[";
2038 case LYX_VALIGN_TOP:
2041 case LYX_VALIGN_MIDDLE:
2044 case LYX_VALIGN_BOTTOM:
2048 os << "]{" << from_ascii(getPWidth(cell).asLatexString())
2056 int Tabular::TeXCellPostamble(odocstream & os, idx_type cell, bool ismulticol) const
2059 row_type const r = cellRow(cell);
2060 if (is_long_tabular && row_info[r].caption)
2064 if (getUsebox(cell) == BOX_PARBOX)
2066 else if (getUsebox(cell) == BOX_MINIPAGE) {
2067 os << "%\n\\end{minipage}";
2070 if (getRotateCell(cell)) {
2071 os << "%\n\\end{sideways}";
2081 int Tabular::TeXLongtableHeaderFooter(odocstream & os,
2082 OutputParams const & runparams) const
2084 if (!is_long_tabular)
2089 // the caption must be output befrore the headers
2090 if (haveLTCaption()) {
2091 for (row_type i = 0; i < row_info.size(); ++i) {
2092 if (row_info[i].caption) {
2093 ret += TeXRow(os, i, runparams);
2097 // output first header info
2098 // first header must be output before the header, otherwise the
2099 // correct caption placement becomes really wierd
2100 if (haveLTFirstHead()) {
2101 if (endfirsthead.topDL) {
2105 for (row_type i = 0; i < row_info.size(); ++i) {
2106 if (row_info[i].endfirsthead) {
2107 ret += TeXRow(os, i, runparams);
2110 if (endfirsthead.bottomDL) {
2114 os << "\\endfirsthead\n";
2117 // output header info
2119 if (endfirsthead.empty && !haveLTFirstHead()) {
2120 os << "\\endfirsthead\n";
2123 if (endhead.topDL) {
2127 for (row_type i = 0; i < row_info.size(); ++i) {
2128 if (row_info[i].endhead) {
2129 ret += TeXRow(os, i, runparams);
2132 if (endhead.bottomDL) {
2136 os << "\\endhead\n";
2139 // output footer info
2141 if (endfoot.topDL) {
2145 for (row_type i = 0; i < row_info.size(); ++i) {
2146 if (row_info[i].endfoot) {
2147 ret += TeXRow(os, i, runparams);
2150 if (endfoot.bottomDL) {
2154 os << "\\endfoot\n";
2156 if (endlastfoot.empty && !haveLTLastFoot()) {
2157 os << "\\endlastfoot\n";
2161 // output lastfooter info
2162 if (haveLTLastFoot()) {
2163 if (endlastfoot.topDL) {
2167 for (row_type i = 0; i < row_info.size(); ++i) {
2168 if (row_info[i].endlastfoot) {
2169 ret += TeXRow(os, i, runparams);
2172 if (endlastfoot.bottomDL) {
2176 os << "\\endlastfoot\n";
2183 bool Tabular::isValidRow(row_type row) const
2185 if (!is_long_tabular)
2187 return !row_info[row].endhead && !row_info[row].endfirsthead
2188 && !row_info[row].endfoot && !row_info[row].endlastfoot
2189 && !row_info[row].caption;
2193 int Tabular::TeXRow(odocstream & os, row_type i,
2194 OutputParams const & runparams) const
2196 idx_type cell = cellIndex(i, 0);
2197 shared_ptr<InsetTableCell> inset = cellInset(cell);
2198 Paragraph const & par = inset->paragraphs().front();
2199 string const lang = par.getParLanguage(buffer().params())->lang();
2201 //output the top line
2202 int ret = TeXTopHLine(os, i, lang);
2204 if (row_info[i].top_space_default) {
2206 os << "\\addlinespace\n";
2208 os << "\\noalign{\\vskip\\doublerulesep}\n";
2210 } else if(!row_info[i].top_space.zero()) {
2212 os << "\\addlinespace["
2213 << from_ascii(row_info[i].top_space.asLatexString())
2216 os << "\\noalign{\\vskip"
2217 << from_ascii(row_info[i].top_space.asLatexString())
2222 bool ismulticol = false;
2223 for (col_type j = 0; j < column_info.size(); ++j) {
2224 if (isPartOfMultiColumn(i, j))
2226 ret += TeXCellPreamble(os, cell, ismulticol);
2227 shared_ptr<InsetTableCell> inset = cellInset(cell);
2229 Paragraph const & par = inset->paragraphs().front();
2230 bool rtl = par.isRTL(buffer().params())
2232 && getPWidth(cell).zero();
2236 par.getParLanguage(buffer().params())->lang();
2237 if (lang == "farsi")
2239 else if (lang == "arabic_arabi")
2241 // currently, remaning RTL languages are
2242 // arabic_arabtex and hebrew
2246 // pass to the OutputParams that we are in a cell and
2247 // which alignment we have set.
2248 // InsetNewline needs this context information.
2249 OutputParams newrp(runparams);
2250 newrp.inTableCell = (getAlignment(cell) == LYX_ALIGN_BLOCK)
2251 ? OutputParams::PLAIN
2252 : OutputParams::ALIGNED;
2253 ret += inset->latex(os, newrp);
2254 runparams.encoding = newrp.encoding;
2258 ret += TeXCellPostamble(os, cell, ismulticol);
2259 if (!isLastCellInRow(cell)) { // not last cell in row
2264 os << "\\tabularnewline";
2265 if (row_info[i].bottom_space_default) {
2267 os << "\\addlinespace";
2269 os << "[\\doublerulesep]";
2270 } else if (!row_info[i].bottom_space.zero()) {
2272 os << "\\addlinespace";
2274 << from_ascii(row_info[i].bottom_space.asLatexString())
2280 //output the bottom line
2281 ret += TeXBottomHLine(os, i, lang);
2283 if (row_info[i].interline_space_default) {
2285 os << "\\addlinespace\n";
2287 os << "\\noalign{\\vskip\\doublerulesep}\n";
2289 } else if (!row_info[i].interline_space.zero()) {
2291 os << "\\addlinespace["
2292 << from_ascii(row_info[i].interline_space.asLatexString())
2295 os << "\\noalign{\\vskip"
2296 << from_ascii(row_info[i].interline_space.asLatexString())
2304 int Tabular::latex(odocstream & os, OutputParams const & runparams) const
2308 //+---------------------------------------------------------------------
2309 //+ first the opening preamble +
2310 //+---------------------------------------------------------------------
2313 os << "\\begin{sideways}\n";
2316 if (is_long_tabular)
2317 os << "\\begin{longtable}";
2319 os << "\\begin{tabular}";
2321 switch (tabular_valignment) {
2322 case LYX_VALIGN_TOP:
2325 case LYX_VALIGN_BOTTOM:
2328 case LYX_VALIGN_MIDDLE:
2334 for (col_type i = 0; i < column_info.size(); ++i) {
2335 if (columnLeftLine(i))
2337 if (!column_info[i].align_special.empty()) {
2338 os << column_info[i].align_special;
2340 if (!column_info[i].p_width.zero()) {
2341 switch (column_info[i].alignment) {
2342 case LYX_ALIGN_LEFT:
2343 os << ">{\\raggedright}";
2345 case LYX_ALIGN_RIGHT:
2346 os << ">{\\raggedleft}";
2348 case LYX_ALIGN_CENTER:
2349 os << ">{\\centering}";
2351 case LYX_ALIGN_NONE:
2352 case LYX_ALIGN_BLOCK:
2353 case LYX_ALIGN_LAYOUT:
2354 case LYX_ALIGN_SPECIAL:
2358 switch (column_info[i].valignment) {
2359 case LYX_VALIGN_TOP:
2362 case LYX_VALIGN_MIDDLE:
2365 case LYX_VALIGN_BOTTOM:
2370 << from_ascii(column_info[i].p_width.asLatexString())
2373 switch (column_info[i].alignment) {
2374 case LYX_ALIGN_LEFT:
2377 case LYX_ALIGN_RIGHT:
2384 } // end if else !column_info[i].p_width
2385 } // end if else !column_info[i].align_special
2386 if (columnRightLine(i))
2392 ret += TeXLongtableHeaderFooter(os, runparams);
2394 //+---------------------------------------------------------------------
2395 //+ the single row and columns (cells) +
2396 //+---------------------------------------------------------------------
2398 for (row_type i = 0; i < row_info.size(); ++i) {
2399 if (isValidRow(i)) {
2400 ret += TeXRow(os, i, runparams);
2401 if (is_long_tabular && row_info[i].newpage) {
2402 os << "\\newpage\n";
2408 //+---------------------------------------------------------------------
2409 //+ the closing of the tabular +
2410 //+---------------------------------------------------------------------
2412 if (is_long_tabular)
2413 os << "\\end{longtable}";
2415 os << "\\end{tabular}";
2417 os << "\n\\end{sideways}";
2425 int Tabular::docbookRow(odocstream & os, row_type row,
2426 OutputParams const & runparams) const
2429 idx_type cell = getFirstCellInRow(row);
2432 for (col_type j = 0; j < column_info.size(); ++j) {
2433 if (isPartOfMultiColumn(row, j))
2436 os << "<entry align=\"";
2437 switch (getAlignment(cell)) {
2438 case LYX_ALIGN_LEFT:
2441 case LYX_ALIGN_RIGHT:
2449 os << "\" valign=\"";
2450 switch (getVAlignment(cell)) {
2451 case LYX_VALIGN_TOP:
2454 case LYX_VALIGN_BOTTOM:
2457 case LYX_VALIGN_MIDDLE:
2462 if (isMultiColumn(cell)) {
2463 os << " namest=\"col" << j << "\" ";
2464 os << "nameend=\"col" << j + columnSpan(cell) - 1<< '"';
2468 ret += cellInset(cell)->docbook(os, runparams);
2477 int Tabular::docbook(odocstream & os, OutputParams const & runparams) const
2481 //+---------------------------------------------------------------------
2482 //+ first the opening preamble +
2483 //+---------------------------------------------------------------------
2485 os << "<tgroup cols=\"" << column_info.size()
2486 << "\" colsep=\"1\" rowsep=\"1\">\n";
2488 for (col_type i = 0; i < column_info.size(); ++i) {
2489 os << "<colspec colname=\"col" << i << "\" align=\"";
2490 switch (column_info[i].alignment) {
2491 case LYX_ALIGN_LEFT:
2494 case LYX_ALIGN_RIGHT:
2502 if (runparams.flavor == OutputParams::XML)
2508 //+---------------------------------------------------------------------
2509 //+ Long Tabular case +
2510 //+---------------------------------------------------------------------
2512 // output caption info
2513 if (haveLTCaption()) {
2514 os << "<caption>\n";
2516 for (row_type i = 0; i < row_info.size(); ++i) {
2517 if (row_info[i].caption) {
2518 ret += docbookRow(os, i, runparams);
2521 os << "</caption>\n";
2524 // output header info
2525 if (haveLTHead() || haveLTFirstHead()) {
2528 for (row_type i = 0; i < row_info.size(); ++i) {
2529 if (row_info[i].endhead || row_info[i].endfirsthead) {
2530 ret += docbookRow(os, i, runparams);
2536 // output footer info
2537 if (haveLTFoot() || haveLTLastFoot()) {
2540 for (row_type i = 0; i < row_info.size(); ++i) {
2541 if (row_info[i].endfoot || row_info[i].endlastfoot) {
2542 ret += docbookRow(os, i, runparams);
2549 //+---------------------------------------------------------------------
2550 //+ the single row and columns (cells) +
2551 //+---------------------------------------------------------------------
2555 for (row_type i = 0; i < row_info.size(); ++i) {
2556 if (isValidRow(i)) {
2557 ret += docbookRow(os, i, runparams);
2562 //+---------------------------------------------------------------------
2563 //+ the closing of the tabular +
2564 //+---------------------------------------------------------------------
2573 bool Tabular::plaintextTopHLine(odocstream & os, row_type row,
2574 vector<unsigned int> const & clen) const
2576 idx_type const fcell = getFirstCellInRow(row);
2577 idx_type const n = numberOfCellsInRow(fcell) + fcell;
2580 for (idx_type i = fcell; i < n; ++i) {
2590 for (idx_type i = fcell; i < n; ++i) {
2601 col_type column = cellColumn(i);
2602 int len = clen[column];
2603 while (column < column_info.size() - 1
2604 && isPartOfMultiColumn(row, ++column))
2605 len += clen[column] + 4;
2606 os << docstring(len, ch);
2621 bool Tabular::plaintextBottomHLine(odocstream & os, row_type row,
2622 vector<unsigned int> const & clen) const
2624 idx_type const fcell = getFirstCellInRow(row);
2625 idx_type const n = numberOfCellsInRow(fcell) + fcell;
2628 for (idx_type i = fcell; i < n; ++i) {
2629 if (bottomLine(i)) {
2638 for (idx_type i = fcell; i < n; ++i) {
2639 if (bottomLine(i)) {
2649 col_type column = cellColumn(i);
2650 int len = clen[column];
2651 while (column < column_info.size() -1
2652 && isPartOfMultiColumn(row, ++column))
2653 len += clen[column] + 4;
2654 os << docstring(len, ch);
2655 if (bottomLine(i)) {
2669 void Tabular::plaintextPrintCell(odocstream & os,
2670 OutputParams const & runparams,
2671 idx_type cell, row_type row, col_type column,
2672 vector<unsigned int> const & clen,
2673 bool onlydata) const
2675 odocstringstream sstr;
2676 cellInset(cell)->plaintext(sstr, runparams);
2688 unsigned int len1 = sstr.str().length();
2689 unsigned int len2 = clen[column];
2690 while (column < column_info.size() -1
2691 && isPartOfMultiColumn(row, ++column))
2692 len2 += clen[column] + 4;
2695 switch (getAlignment(cell)) {
2697 case LYX_ALIGN_LEFT:
2700 case LYX_ALIGN_RIGHT:
2704 case LYX_ALIGN_CENTER:
2710 os << docstring(len1, ' ') << sstr.str()
2711 << docstring(len2, ' ');
2713 if (rightLine(cell))
2720 void Tabular::plaintext(odocstream & os,
2721 OutputParams const & runparams, int const depth,
2722 bool onlydata, char_type delim) const
2724 // first calculate the width of the single columns
2725 vector<unsigned int> clen(column_info.size());
2728 // first all non (real) multicolumn cells!
2729 for (col_type j = 0; j < column_info.size(); ++j) {
2731 for (row_type i = 0; i < row_info.size(); ++i) {
2732 idx_type cell = cellIndex(i, j);
2733 if (isMultiColumnReal(cell))
2735 odocstringstream sstr;
2736 cellInset(cell)->plaintext(sstr, runparams);
2737 if (clen[j] < sstr.str().length())
2738 clen[j] = sstr.str().length();
2741 // then all (real) multicolumn cells!
2742 for (col_type j = 0; j < column_info.size(); ++j) {
2743 for (row_type i = 0; i < row_info.size(); ++i) {
2744 idx_type cell = cellIndex(i, j);
2745 if (!isMultiColumnReal(cell) || isPartOfMultiColumn(i, j))
2747 odocstringstream sstr;
2748 cellInset(cell)->plaintext(sstr, runparams);
2749 int len = int(sstr.str().length());
2750 idx_type const n = columnSpan(cell);
2751 for (col_type k = j; len > 0 && k < j + n - 1; ++k)
2753 if (len > int(clen[j + n - 1]))
2754 clen[j + n - 1] = len;
2759 for (row_type i = 0; i < row_info.size(); ++i) {
2760 if (!onlydata && plaintextTopHLine(os, i, clen))
2761 os << docstring(depth * 2, ' ');
2762 for (col_type j = 0; j < column_info.size(); ++j) {
2763 if (isPartOfMultiColumn(i, j))
2765 if (onlydata && j > 0)
2766 // we don't use operator<< for single UCS4 character.
2767 // see explanation in docstream.h
2769 plaintextPrintCell(os, runparams, cell, i, j, clen, onlydata);
2774 os << docstring(depth * 2, ' ');
2775 if (plaintextBottomHLine(os, i, clen))
2776 os << docstring(depth * 2, ' ');
2782 shared_ptr<InsetTableCell> Tabular::cellInset(idx_type cell) const
2784 return cell_info[cellRow(cell)][cellColumn(cell)].inset;
2788 shared_ptr<InsetTableCell> Tabular::cellInset(row_type row,
2789 col_type column) const
2791 return cell_info[row][column].inset;
2795 void Tabular::setCellInset(row_type row, col_type column,
2796 shared_ptr<InsetTableCell> ins) const
2798 CellData & cd = cell_info[row][column];
2803 void Tabular::validate(LaTeXFeatures & features) const
2805 features.require("NeedTabularnewline");
2807 features.require("booktabs");
2808 if (is_long_tabular)
2809 features.require("longtable");
2811 features.require("rotating");
2812 for (idx_type cell = 0; cell < numberofcells; ++cell) {
2813 if (getVAlignment(cell) != LYX_VALIGN_TOP
2814 || !getPWidth(cell).zero())
2815 features.require("array");
2816 cellInset(cell)->validate(features);
2821 Tabular::BoxType Tabular::useParbox(idx_type cell) const
2823 ParagraphList const & parlist = cellInset(cell)->paragraphs();
2824 ParagraphList::const_iterator cit = parlist.begin();
2825 ParagraphList::const_iterator end = parlist.end();
2827 for (; cit != end; ++cit)
2828 for (int i = 0; i < cit->size(); ++i)
2829 if (cit->isNewline(i))
2836 /////////////////////////////////////////////////////////////////////
2840 /////////////////////////////////////////////////////////////////////
2842 InsetTableCell::InsetTableCell(Buffer & buf)
2843 : InsetText(buf, InsetText::PlainLayout), isFixedWidth(false),
2844 contentAlign(LYX_ALIGN_CENTER)
2848 bool InsetTableCell::forcePlainLayout(idx_type) const
2850 return !isFixedWidth;
2854 bool InsetTableCell::allowParagraphCustomization(idx_type) const
2856 return isFixedWidth;
2860 bool InsetTableCell::getStatus(Cursor & cur, FuncRequest const & cmd,
2861 FuncStatus & status) const
2864 switch (cmd.action) {
2866 enabled = !forcePlainLayout();
2868 case LFUN_LAYOUT_PARAGRAPH:
2869 enabled = allowParagraphCustomization();
2872 return InsetText::getStatus(cur, cmd, status);
2874 status.setEnabled(enabled);
2878 docstring InsetTableCell::asString(bool intoInsets)
2881 if (paragraphs().empty())
2883 ParagraphList::const_iterator it = paragraphs().begin();
2884 ParagraphList::const_iterator en = paragraphs().end();
2886 for (; it != en; ++it) {
2891 retval += it->asString(intoInsets ? AS_STR_INSETS : AS_STR_NONE);
2898 /////////////////////////////////////////////////////////////////////
2902 /////////////////////////////////////////////////////////////////////
2904 InsetTabular::InsetTabular(Buffer & buf, row_type rows,
2906 : tabular(buf, max(rows, row_type(1)), max(columns, col_type(1))), scx_(0),
2907 rowselect_(false), colselect_(false)
2909 setBuffer(buf); // FIXME: remove later
2913 InsetTabular::InsetTabular(InsetTabular const & tab)
2914 : Inset(tab), tabular(tab.tabular), scx_(0)
2919 InsetTabular::~InsetTabular()
2921 hideDialogs("tabular", this);
2925 void InsetTabular::setBuffer(Buffer & buf)
2927 tabular.setBuffer(buf);
2928 Inset::setBuffer(buf);
2932 bool InsetTabular::insetAllowed(InsetCode code) const
2934 if (code == MATHMACRO_CODE
2935 || (code == CAPTION_CODE && !tabular.is_long_tabular))
2942 void InsetTabular::write(ostream & os) const
2944 os << "Tabular" << endl;
2949 docstring InsetTabular::contextMenu(BufferView const &, int, int) const
2951 // FIXME: depending on the selection state, we could offer a different menu.
2952 return from_ascii("context-tabular");
2956 void InsetTabular::read(Lexer & lex)
2958 //bool const old_format = (lex.getString() == "\\LyXTable");
2966 string token = lex.getString();
2967 while (lex && token != "\\end_inset") {
2969 token = lex.getString();
2972 lex.printError("Missing \\end_inset at this point. ");
2976 int InsetTabular::rowFromY(Cursor & cur, int y) const
2978 // top y coordinate of tabular
2979 int h = yo(cur.bv()) - tabular.rowAscent(0);
2980 size_t nrows = tabular.row_info.size();
2982 for (; r < nrows && y > h; ++r) {
2983 h += tabular.rowAscent(r);
2984 h += tabular.rowDescent(r);
2985 h += tabular.getAdditionalHeight(r);
2991 int InsetTabular::columnFromX(Cursor & cur, int x) const
2993 // left x coordinate of tabular
2994 int w = xo(cur.bv()) + ADD_TO_TABULAR_WIDTH;
2995 size_t ncols = tabular.column_info.size();
2997 for (; c < ncols && x > w; ++c)
2998 w += tabular.columnWidth(c);
3003 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
3005 //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
3006 // mi.base.textwidth << "\n";
3009 LASSERT(false, /**/);
3013 for (idx_type cell = 0; i < tabular.row_info.size(); ++i) {
3016 for (col_type j = 0; j < tabular.column_info.size(); ++j) {
3017 if (tabular.isPartOfMultiColumn(i, j))
3018 // Multicolumn cell, but not first one
3023 if (tabular.cell_info[i][j].multicolumn ==
3024 Tabular::CELL_BEGIN_OF_MULTICOLUMN)
3025 p_width = tabular.cellInfo(cell).p_width;
3027 p_width = tabular.column_info[j].p_width;
3028 if (!p_width.zero())
3029 m.base.textwidth = p_width.inPixels(mi.base.textwidth);
3030 tabular.cellInset(cell)->metrics(m, dim);
3031 if (!p_width.zero())
3032 dim.wid = m.base.textwidth;
3033 tabular.setCellWidth(cell, dim.wid);
3034 maxAsc = max(maxAsc, dim.asc);
3035 maxDesc = max(maxDesc, dim.des);
3038 int const top_space = tabular.row_info[i].top_space_default ?
3039 default_line_space :
3040 tabular.row_info[i].top_space.inPixels(mi.base.textwidth);
3041 tabular.setRowAscent(i, maxAsc + ADD_TO_HEIGHT + top_space);
3042 int const bottom_space = tabular.row_info[i].bottom_space_default ?
3043 default_line_space :
3044 tabular.row_info[i].bottom_space.inPixels(mi.base.textwidth);
3045 tabular.setRowDescent(i, maxDesc + ADD_TO_HEIGHT + bottom_space);
3047 tabular.updateColumnWidths();
3048 dim.asc = tabular.rowAscent(0);
3049 dim.des = tabular.height() - dim.asc;
3050 dim.wid = tabular.width() + 2 * ADD_TO_TABULAR_WIDTH;
3053 bool InsetTabular::isCellSelected(Cursor & cur, row_type row, col_type col)
3056 if (&cur.inset() == this && cur.selection()) {
3057 if (cur.selIsMultiCell()) {
3060 getSelection(cur, rs, re, cs, ce);
3062 if (col >= cs && col <= ce && row >= rs && row <= re)
3065 if (col == tabular.cellColumn(cur.idx())
3066 && row == tabular.cellRow(cur.idx())) {
3067 CursorSlice const & beg = cur.selBegin();
3068 CursorSlice const & end = cur.selEnd();
3070 if ((end.lastpos() > 0 || end.lastpit() > 0)
3071 && end.pos() == end.lastpos() && beg.pos() == 0
3072 && end.pit() == end.lastpit() && beg.pit() == 0)
3080 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
3082 //lyxerr << "InsetTabular::draw: " << x << " " << y << endl;
3083 BufferView * bv = pi.base.bv;
3084 Cursor & cur = pi.base.bv->cursor();
3086 // FIXME: As the full backrgound is painted in drawSelection(),
3087 // we have no choice but to do a full repaint for the Text cells.
3088 pi.full_repaint = true;
3090 resetPos(bv->cursor());
3093 x += ADD_TO_TABULAR_WIDTH;
3095 bool const original_drawing_state = pi.pain.isDrawingEnabled();
3096 bool const original_selection_state = pi.selected;
3099 first_visible_cell = Tabular::npos;
3100 for (row_type i = 0; i < tabular.row_info.size(); ++i) {
3102 int const a = tabular.rowAscent(i);
3103 int const d = tabular.rowDescent(i);
3104 idx = tabular.cellIndex(i, 0);
3105 for (col_type j = 0; j < tabular.column_info.size(); ++j) {
3106 if (tabular.isPartOfMultiColumn(i, j))
3108 if (first_visible_cell == Tabular::npos)
3109 first_visible_cell = idx;
3111 pi.selected |= isCellSelected(cur, i, j);
3112 int const cx = nx + tabular.getBeginningOfTextInCell(idx);
3113 // Cache the Inset position.
3114 bv->coordCache().insets().add(cell(idx).get(), cx, y);
3115 if (nx + tabular.columnWidth(idx) < 0
3116 || nx > bv->workWidth()
3118 || y - a > bv->workHeight()) {
3119 pi.pain.setDrawingEnabled(false);
3120 cell(idx)->draw(pi, cx, y);
3121 drawCellLines(pi.pain, nx, y, i, idx, pi.change_);
3122 pi.pain.setDrawingEnabled(original_drawing_state);
3124 cell(idx)->draw(pi, cx, y);
3125 drawCellLines(pi.pain, nx, y, i, idx, pi.change_);
3127 nx += tabular.columnWidth(idx);
3129 pi.selected = original_selection_state;
3132 if (i + 1 < tabular.row_info.size())
3133 y += d + tabular.rowAscent(i + 1) +
3134 tabular.getAdditionalHeight(i + 1);
3139 void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
3141 Cursor & cur = pi.base.bv->cursor();
3144 x += scx_ + ADD_TO_TABULAR_WIDTH;
3146 // FIXME: it is wrong to completely paint the background
3147 // if we want to do single row painting.
3149 // Paint background of current tabular
3150 int const w = tabular.width();
3151 int const h = tabular.height();
3152 int yy = y - tabular.rowAscent(0);
3153 pi.pain.fillRectangle(x, yy, w, h, pi.backgroundColor(this));
3155 if (!cur.selection())
3157 if (&cur.inset() != this)
3162 bool const full_cell_selected = isCellSelected(cur,
3163 tabular.cellRow(cur.idx()), tabular.cellColumn(cur.idx()));
3165 if (cur.selIsMultiCell() || full_cell_selected) {
3166 y -= tabular.rowAscent(0);
3167 for (row_type j = 0; j < tabular.row_info.size(); ++j) {
3168 int const a = tabular.rowAscent(j);
3169 int const h = a + tabular.rowDescent(j);
3171 y += tabular.getAdditionalHeight(j);
3172 for (col_type i = 0; i < tabular.column_info.size(); ++i) {
3173 if (tabular.isPartOfMultiColumn(j, i))
3175 idx_type const cell =
3176 tabular.cellIndex(j, i);
3177 int const w = tabular.columnWidth(cell);
3178 if (isCellSelected(cur, j, i))
3179 pi.pain.fillRectangle(xx, y, w, h, Color_selection);
3186 x += cellXPos(cur.idx());
3187 x += tabular.getBeginningOfTextInCell(cur.idx());
3188 cell(cur.idx())->drawSelection(pi, x, 0 /* ignored */);
3193 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
3194 row_type row, idx_type cell, Change const & change) const
3196 int x2 = x + tabular.columnWidth(cell);
3197 bool on_off = false;
3198 Color col = Color_tabularline;
3199 Color onoffcol = Color_tabularonoffline;
3201 if (change.changed()) {
3202 col = change.color();
3203 onoffcol = change.color();
3206 if (!tabular.topAlreadyDrawn(cell)) {
3207 on_off = !tabular.topLine(cell);
3208 pain.line(x, y - tabular.rowAscent(row),
3209 x2, y - tabular.rowAscent(row),
3210 on_off ? onoffcol : col,
3211 on_off ? Painter::line_onoffdash : Painter::line_solid);
3213 on_off = !tabular.bottomLine(cell);
3214 pain.line(x, y + tabular.rowDescent(row),
3215 x2, y + tabular.rowDescent(row),
3216 on_off ? onoffcol : col,
3217 on_off ? Painter::line_onoffdash : Painter::line_solid);
3218 if (!tabular.leftAlreadyDrawn(cell)) {
3219 on_off = !tabular.leftLine(cell);
3220 pain.line(x, y - tabular.rowAscent(row),
3221 x, y + tabular.rowDescent(row),
3222 on_off ? onoffcol : col,
3223 on_off ? Painter::line_onoffdash : Painter::line_solid);
3225 on_off = !tabular.rightLine(cell);
3226 pain.line(x2 - tabular.getAdditionalWidth(cell),
3227 y - tabular.rowAscent(row),
3228 x2 - tabular.getAdditionalWidth(cell),
3229 y + tabular.rowDescent(row),
3230 on_off ? onoffcol : col,
3231 on_off ? Painter::line_onoffdash : Painter::line_solid);
3235 docstring InsetTabular::editMessage() const
3237 return _("Opened table");
3241 void InsetTabular::edit(Cursor & cur, bool front, EntryDirection)
3243 //lyxerr << "InsetTabular::edit: " << this << endl;
3245 cur.setSelection(false);
3248 if (isRightToLeft(cur))
3249 cur.idx() = tabular.getLastCellInRow(0);
3255 if (isRightToLeft(cur))
3256 cur.idx() = tabular.getFirstCellInRow(tabular.row_info.size() - 1);
3258 cur.idx() = tabular.numberofcells - 1;
3260 cur.pos() = cur.lastpos(); // FIXME crude guess
3262 // FIXME: this accesses the position cache before it is initialized
3264 //cur.bv().fitCursor();
3268 void InsetTabular::updateLabels(ParIterator const & it)
3270 // In a longtable, tell captions what the current float is
3271 Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
3272 string const saveflt = cnts.current_float();
3273 if (tabular.is_long_tabular)
3274 cnts.current_float("table");
3276 ParIterator it2 = it;
3278 size_t const end = it2.nargs();
3279 for ( ; it2.idx() < end; it2.top().forwardIdx())
3280 buffer().updateLabels(it2);
3283 if (tabular.is_long_tabular)
3284 cnts.current_float(saveflt);
3288 void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
3290 LYXERR(Debug::DEBUG, "# InsetTabular::doDispatch: cmd: " << cmd
3291 << "\n cur:" << cur);
3292 CursorSlice sl = cur.top();
3293 Cursor & bvcur = cur.bv().cursor();
3295 switch (cmd.action) {
3297 case LFUN_MOUSE_PRESS: {
3298 //lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
3300 if (cmd.x < xo(cur.bv()) + ADD_TO_TABULAR_WIDTH
3301 || cmd.x > xo(cur.bv()) + tabular.width()) {
3302 row_type r = rowFromY(cur, cmd.y);
3303 cur.idx() = tabular.getFirstCellInRow(r);
3306 cur.idx() = tabular.getLastCellInRow(r);
3307 cur.pos() = cur.lastpos();
3308 cur.setSelection(true);
3314 int const y0 = yo(cur.bv()) - tabular.rowAscent(0);
3315 if (cmd.y < y0 + ADD_TO_TABULAR_WIDTH
3316 || cmd.y > y0 + tabular.height()) {
3317 col_type c = columnFromX(cur, cmd.x);
3318 cur.idx() = tabular.cellIndex(0, c);
3321 cur.idx() = tabular.cellIndex(tabular.row_info.size() - 1, c);
3322 cur.pos() = cur.lastpos();
3323 cur.setSelection(true);
3328 // do not reset cursor/selection if we have selected
3329 // some cells (bug 2715).
3330 if (cmd.button() == mouse_button::button3
3331 && &bvcur.selBegin().inset() == this
3332 && bvcur.selIsMultiCell())
3335 // Let InsetTableCell do it
3336 cell(cur.idx())->dispatch(cur, cmd);
3339 case LFUN_MOUSE_MOTION:
3340 //lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
3341 if (cmd.button() == mouse_button::button1) {
3342 // only accept motions to places not deeper nested than the real anchor
3343 if (!bvcur.anchor_.hasPart(cur)) {
3347 // select (additional) row
3349 row_type r = rowFromY(cur, cmd.y);
3350 cur.idx() = tabular.getLastCellInRow(r);
3351 // we need to reset the cursor's pit and pos now, as the old ones
3352 // may no longer be valid.
3355 bvcur.setCursor(cur);
3356 bvcur.setSelection(true);
3359 // select (additional) column
3361 col_type c = columnFromX(cur, cmd.x);
3362 cur.idx() = tabular.cellIndex(tabular.row_info.size() - 1, c);
3363 // we need to reset the cursor's pit and pos now, as the old ones
3364 // may no longer be valid.
3367 bvcur.setCursor(cur);
3368 bvcur.setSelection(true);
3371 // only update if selection changes
3372 if (bvcur.idx() == cur.idx() &&
3373 !(bvcur.anchor_.idx() == cur.idx() && bvcur.pos() != cur.pos()))
3375 setCursorFromCoordinates(cur, cmd.x, cmd.y);
3376 bvcur.setCursor(cur);
3377 bvcur.setSelection(true);
3378 // if this is a multicell selection, we just set the cursor to
3379 // the beginning of the cell's text.
3380 if (bvcur.selIsMultiCell()) {
3381 bvcur.pit() = bvcur.lastpit();
3382 bvcur.pos() = bvcur.lastpos();
3387 case LFUN_MOUSE_RELEASE:
3392 case LFUN_CELL_BACKWARD:
3394 cur.setSelection(false);
3397 case LFUN_CELL_FORWARD:
3399 cur.setSelection(false);
3402 case LFUN_CHAR_FORWARD_SELECT:
3403 case LFUN_CHAR_FORWARD:
3404 case LFUN_CHAR_BACKWARD_SELECT:
3405 case LFUN_CHAR_BACKWARD:
3406 case LFUN_CHAR_RIGHT_SELECT:
3407 case LFUN_CHAR_RIGHT:
3408 case LFUN_CHAR_LEFT_SELECT:
3409 case LFUN_CHAR_LEFT: {
3410 // determine whether we move to next or previous cell, where to enter
3411 // the new cell from, and which command to "finish" (i.e., exit the
3414 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE;
3415 FuncCode finish_lfun;
3417 if (cmd.action == LFUN_CHAR_FORWARD
3418 || cmd.action == LFUN_CHAR_FORWARD_SELECT) {
3420 finish_lfun = LFUN_FINISHED_FORWARD;
3422 else if (cmd.action == LFUN_CHAR_BACKWARD
3423 || cmd.action == LFUN_CHAR_BACKWARD_SELECT) {
3425 finish_lfun = LFUN_FINISHED_BACKWARD;
3427 // LEFT or RIGHT commands --- the interpretation will depend on the
3428 // table's direction.
3430 bool const right = cmd.action == LFUN_CHAR_RIGHT
3431 || cmd.action == LFUN_CHAR_RIGHT_SELECT;
3432 next_cell = isRightToLeft(cur) != right;
3434 if (lyxrc.visual_cursor)
3435 entry_from = right ? ENTRY_DIRECTION_LEFT:ENTRY_DIRECTION_RIGHT;
3437 finish_lfun = right ? LFUN_FINISHED_RIGHT : LFUN_FINISHED_LEFT;
3440 bool const select = cmd.action == LFUN_CHAR_FORWARD_SELECT ||
3441 cmd.action == LFUN_CHAR_BACKWARD_SELECT ||
3442 cmd.action == LFUN_CHAR_RIGHT_SELECT ||
3443 cmd.action == LFUN_CHAR_LEFT_SELECT;
3445 // If we have a multicell selection or we're
3446 // not doing some LFUN_*_SELECT thing anyway...
3447 if (!cur.selIsMultiCell() || !select) {
3448 col_type const c = tabular.cellColumn(cur.idx());
3449 row_type const r = tabular.cellRow(cur.idx());
3450 // Are we trying to select the whole cell and is the whole cell
3451 // not yet selected?
3452 bool const select_whole = select && !isCellSelected(cur, r, c) &&
3453 ((next_cell && cur.pit() == cur.lastpit()
3454 && cur.pos() == cur.lastpos())
3455 || (!next_cell && cur.pit() == 0 && cur.pos() == 0));
3457 // ...try to dispatch to the cell's inset.
3458 cell(cur.idx())->dispatch(cur, cmd);
3460 bool const empty_cell = cur.lastpos() == 0 && cur.lastpit() == 0;
3462 // When we already have a selection we want to select the whole cell
3463 // before going to the next cell.
3464 if (select_whole && !empty_cell){
3465 getText(cur.idx())->selectAll(cur);
3470 // FIXME: When we support the selection of an empty cell, remove
3471 // the !empty_cell from this condition. For now we jump to the next
3472 // cell if the current cell is empty.
3473 if (cur.result().dispatched() && !empty_cell)
3477 // move to next/prev cell, as appropriate
3478 // note that we will always do this if we're selecting and we have
3479 // a multicell selection
3480 LYXERR(Debug::RTL, "entering " << (next_cell ? "next" : "previous")
3481 << " cell from: " << int(entry_from));
3483 moveNextCell(cur, entry_from);
3485 movePrevCell(cur, entry_from);
3486 // if we're exiting the table, call the appropriate FINISHED lfun
3487 if (sl == cur.top())
3488 cmd = FuncRequest(finish_lfun);
3495 case LFUN_DOWN_SELECT:
3497 if (!(cur.selection() && cur.selIsMultiCell()))
3498 cell(cur.idx())->dispatch(cur, cmd);
3500 cur.dispatched(); // override the cell's decision
3501 if (sl == cur.top()) {
3502 // if our Text didn't do anything to the cursor
3503 // then we try to put the cursor into the cell below
3504 // setting also the right targetX.
3505 cur.selHandle(cmd.action == LFUN_DOWN_SELECT);
3506 if (tabular.cellRow(cur.idx()) != tabular.row_info.size() - 1) {
3507 cur.idx() = tabular.cellBelow(cur.idx());
3509 TextMetrics const & tm =
3510 cur.bv().textMetrics(cell(cur.idx())->getText(0));
3511 cur.pos() = tm.x2pos(cur.pit(), 0, cur.targetX());
3514 if (sl == cur.top()) {
3515 // we trick it to go to forward after leaving the
3517 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
3520 if (cur.selIsMultiCell()) {
3521 cur.pit() = cur.lastpit();
3522 cur.pos() = cur.lastpos();
3527 case LFUN_UP_SELECT:
3529 if (!(cur.selection() && cur.selIsMultiCell()))
3530 cell(cur.idx())->dispatch(cur, cmd);
3531 cur.dispatched(); // override the cell's decision
3532 if (sl == cur.top()) {
3533 // if our Text didn't do anything to the cursor
3534 // then we try to put the cursor into the cell above
3535 // setting also the right targetX.
3536 cur.selHandle(cmd.action == LFUN_UP_SELECT);
3537 if (tabular.cellRow(cur.idx()) != 0) {
3538 cur.idx() = tabular.cellAbove(cur.idx());
3539 cur.pit() = cur.lastpit();
3540 Text const * text = cell(cur.idx())->getText(0);
3541 TextMetrics const & tm = cur.bv().textMetrics(text);
3542 ParagraphMetrics const & pm =
3543 tm.parMetrics(cur.lastpit());
3544 cur.pos() = tm.x2pos(cur.pit(), pm.rows().size()-1, cur.targetX());
3547 if (sl == cur.top()) {
3548 cmd = FuncRequest(LFUN_UP);
3551 if (cur.selIsMultiCell()) {
3553 cur.pos() = cur.lastpos();
3558 // case LFUN_SCREEN_DOWN: {
3559 // //if (hasSelection())
3560 // // cur.selection() = false;
3561 // col_type const col = tabular.cellColumn(cur.idx());
3562 // int const t = cur.bv().top_y() + cur.bv().height();
3563 // if (t < yo() + tabular.getHeightOfTabular()) {
3564 // cur.bv().scrollDocView(t);
3565 // cur.idx() = tabular.cellBelow(first_visible_cell) + col;
3567 // cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + col;
3574 // case LFUN_SCREEN_UP: {
3575 // //if (hasSelection())
3576 // // cur.selection() = false;
3577 // col_type const col = tabular.cellColumn(cur.idx());
3578 // int const t = cur.bv().top_y() + cur.bv().height();
3580 // cur.bv().scrollDocView(t);
3584 // cur.idx() = tabular.cellBelow(first_visible_cell) + col;
3588 // cur.par() = cur.lastpar();
3589 // cur.pos() = cur.lastpos();
3593 case LFUN_LAYOUT_TABULAR:
3594 cur.bv().showDialog("tabular", params2string(*this), this);
3597 case LFUN_INSET_DIALOG_UPDATE:
3598 cur.bv().updateDialog("tabular", params2string(*this));
3601 case LFUN_TABULAR_FEATURE:
3602 if (!tabularFeatures(cur, to_utf8(cmd.argument())))
3606 // insert file functions
3607 case LFUN_FILE_INSERT_PLAINTEXT_PARA:
3608 case LFUN_FILE_INSERT_PLAINTEXT: {
3610 docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
3611 FileName(to_utf8(cmd.argument())));
3614 cur.recordUndoInset(INSERT_UNDO);
3615 if (insertPlaintextString(cur.bv(), tmpstr, false)) {
3616 // content has been replaced,
3617 // so cursor might be invalid
3618 cur.pos() = cur.lastpos();
3619 cur.pit() = cur.lastpit();
3620 bvcur.setCursor(cur);
3627 if (cur.selIsMultiCell()) {
3628 if (copySelection(cur)) {
3629 cur.recordUndoInset(DELETE_UNDO);
3634 cell(cur.idx())->dispatch(cur, cmd);
3637 case LFUN_SELF_INSERT:
3638 if (cur.selIsMultiCell()) {
3639 cur.recordUndoInset(DELETE_UNDO);
3642 cell(cur.idx())->dispatch(cur, cmd);
3645 case LFUN_CHAR_DELETE_BACKWARD:
3646 case LFUN_CHAR_DELETE_FORWARD:
3647 if (cur.selIsMultiCell()) {
3648 cur.recordUndoInset(DELETE_UNDO);
3652 cell(cur.idx())->dispatch(cur, cmd);
3656 if (!cur.selection())
3658 if (cur.selIsMultiCell()) {
3662 cell(cur.idx())->dispatch(cur, cmd);
3665 case LFUN_CLIPBOARD_PASTE:
3666 case LFUN_PRIMARY_SELECTION_PASTE: {
3667 docstring const clip = (cmd.action == LFUN_CLIPBOARD_PASTE) ?
3668 theClipboard().getAsText() :
3669 theSelection().get();
3672 // pass to InsertPlaintextString, but
3673 // only if we have multi-cell content
3674 if (clip.find_first_of(from_ascii("\t\n")) != docstring::npos) {
3675 cur.recordUndoInset(INSERT_UNDO);
3676 if (insertPlaintextString(cur.bv(), clip, false)) {
3677 // content has been replaced,
3678 // so cursor might be invalid
3679 cur.pos() = cur.lastpos();
3680 cur.pit() = cur.lastpit();
3681 bvcur.setCursor(cur);
3685 // Let the cell handle normal text
3686 cell(cur.idx())->dispatch(cur, cmd);
3691 if (!tabularStackDirty()) {
3692 cell(cur.idx())->dispatch(cur, cmd);
3695 if (theClipboard().isInternal() ||
3696 (!theClipboard().hasInternal() && theClipboard().hasLyXContents())) {
3697 cur.recordUndoInset(INSERT_UNDO);
3698 pasteClipboard(cur);
3702 case LFUN_FONT_EMPH:
3703 case LFUN_FONT_BOLD:
3704 case LFUN_FONT_BOLDSYMBOL:
3705 case LFUN_FONT_ROMAN:
3706 case LFUN_FONT_NOUN:
3707 case LFUN_FONT_ITAL:
3708 case LFUN_FONT_FRAK:
3709 case LFUN_FONT_TYPEWRITER:
3710 case LFUN_FONT_SANS:
3711 case LFUN_TEXTSTYLE_APPLY:
3712 case LFUN_TEXTSTYLE_UPDATE:
3713 case LFUN_FONT_SIZE:
3714 case LFUN_FONT_UNDERLINE:
3715 case LFUN_FONT_STRIKEOUT:
3716 case LFUN_FONT_UULINE:
3717 case LFUN_FONT_UWAVE:
3719 case LFUN_WORD_CAPITALIZE:
3720 case LFUN_WORD_UPCASE:
3721 case LFUN_WORD_LOWCASE:
3722 case LFUN_CHARS_TRANSPOSE:
3723 if (cur.selIsMultiCell()) {
3726 getSelection(cur, rs, re, cs, ce);
3727 Cursor tmpcur = cur;
3728 for (row_type i = rs; i <= re; ++i) {
3729 for (col_type j = cs; j <= ce; ++j) {
3730 // cursor follows cell:
3731 tmpcur.idx() = tabular.cellIndex(i, j);
3732 // select this cell only:
3735 tmpcur.resetAnchor();
3736 tmpcur.pit() = tmpcur.lastpit();
3737 tmpcur.pos() = tmpcur.top().lastpos();
3738 tmpcur.setCursor(tmpcur);
3739 tmpcur.setSelection();
3740 cell(tmpcur.idx())->dispatch(tmpcur, cmd);
3745 cell(cur.idx())->dispatch(cur, cmd);
3749 case LFUN_INSET_SETTINGS:
3750 // relay this lfun to Inset, not to the cell.
3751 Inset::doDispatch(cur, cmd);
3755 // we try to handle this event in the insets dispatch function.
3756 cell(cur.idx())->dispatch(cur, cmd);
3762 // function sets an object as defined in func_status.h:
3763 // states OK, Unknown, Disabled, On, Off.
3764 bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
3765 FuncStatus & status) const
3767 switch (cmd.action) {
3768 case LFUN_TABULAR_FEATURE: {
3769 int action = Tabular::LAST_ACTION;
3771 for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
3772 string const tmp = tabularFeature[i].feature;
3773 if (tmp == to_utf8(cmd.argument()).substr(0, tmp.length())) {
3774 action = tabularFeature[i].action;
3778 if (action == Tabular::LAST_ACTION) {
3780 status.unknown(true);
3784 string const argument
3785 = ltrim(to_utf8(cmd.argument()).substr(tabularFeature[i].feature.length()));
3787 row_type sel_row_start = 0;
3788 row_type sel_row_end = 0;
3789 col_type sel_col_start = 0;
3790 col_type sel_col_end = 0;
3791 Tabular::ltType dummyltt;
3794 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
3797 case Tabular::SET_PWIDTH:
3798 case Tabular::SET_MPWIDTH:
3799 case Tabular::SET_SPECIAL_COLUMN:
3800 case Tabular::SET_SPECIAL_MULTI:
3801 case Tabular::APPEND_ROW:
3802 case Tabular::APPEND_COLUMN:
3803 case Tabular::DELETE_ROW:
3804 case Tabular::DELETE_COLUMN:
3805 case Tabular::COPY_ROW:
3806 case Tabular::COPY_COLUMN:
3807 case Tabular::SET_TOP_SPACE:
3808 case Tabular::SET_BOTTOM_SPACE:
3809 case Tabular::SET_INTERLINE_SPACE:
3813 case Tabular::MULTICOLUMN:
3814 // When a row is set as longtable caption, it must not be allowed
3815 // to unset that this row is a multicolumn.
3816 status.setEnabled(sel_row_start == sel_row_end
3817 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
3818 status.setOnOff(tabular.isMultiColumn(cur.idx()));
3821 case Tabular::SET_ALL_LINES:
3822 case Tabular::UNSET_ALL_LINES:
3823 case Tabular::SET_BORDER_LINES:
3824 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
3827 case Tabular::TOGGLE_LINE_TOP:
3828 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
3829 status.setOnOff(tabular.topLine(cur.idx()));
3832 case Tabular::TOGGLE_LINE_BOTTOM:
3833 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
3834 status.setOnOff(tabular.bottomLine(cur.idx()));
3837 case Tabular::TOGGLE_LINE_LEFT:
3838 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
3839 status.setOnOff(tabular.leftLine(cur.idx()));
3842 case Tabular::TOGGLE_LINE_RIGHT:
3843 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
3844 status.setOnOff(tabular.rightLine(cur.idx()));
3847 case Tabular::M_ALIGN_LEFT:
3849 case Tabular::ALIGN_LEFT:
3850 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_LEFT);
3853 case Tabular::M_ALIGN_RIGHT:
3855 case Tabular::ALIGN_RIGHT:
3856 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_RIGHT);
3859 case Tabular::M_ALIGN_CENTER:
3861 case Tabular::ALIGN_CENTER:
3862 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_CENTER);
3865 case Tabular::ALIGN_BLOCK:
3866 status.setEnabled(!tabular.getPWidth(cur.idx()).zero());
3867 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_BLOCK);
3870 case Tabular::M_VALIGN_TOP:
3872 case Tabular::VALIGN_TOP:
3874 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_TOP);
3877 case Tabular::M_VALIGN_BOTTOM:
3879 case Tabular::VALIGN_BOTTOM:
3881 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_BOTTOM);
3884 case Tabular::M_VALIGN_MIDDLE:
3886 case Tabular::VALIGN_MIDDLE:
3888 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_MIDDLE);
3891 case Tabular::SET_LONGTABULAR:
3892 status.setOnOff(tabular.is_long_tabular);
3895 case Tabular::UNSET_LONGTABULAR:
3896 status.setOnOff(!tabular.is_long_tabular);
3899 case Tabular::TOGGLE_ROTATE_TABULAR:
3900 case Tabular::SET_ROTATE_TABULAR:
3901 status.setOnOff(tabular.rotate);
3904 case Tabular::TABULAR_VALIGN_TOP:
3905 status.setOnOff(tabular.tabular_valignment
3906 == Tabular::LYX_VALIGN_TOP);
3908 case Tabular::TABULAR_VALIGN_MIDDLE:
3909 status.setOnOff(tabular.tabular_valignment
3910 == Tabular::LYX_VALIGN_MIDDLE);
3912 case Tabular::TABULAR_VALIGN_BOTTOM:
3913 status.setOnOff(tabular.tabular_valignment
3914 == Tabular::LYX_VALIGN_BOTTOM);
3917 case Tabular::UNSET_ROTATE_TABULAR:
3918 status.setOnOff(!tabular.rotate);
3921 case Tabular::TOGGLE_ROTATE_CELL:
3922 case Tabular::SET_ROTATE_CELL:
3923 status.setOnOff(!oneCellHasRotationState(false,
3924 sel_row_start, sel_row_end, sel_col_start, sel_col_end));
3927 case Tabular::UNSET_ROTATE_CELL:
3928 status.setOnOff(!oneCellHasRotationState(true,
3929 sel_row_start, sel_row_end, sel_col_start, sel_col_end));
3932 case Tabular::SET_USEBOX:
3933 status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
3936 // every row can only be one thing:
3937 // either a footer or header or caption
3938 case Tabular::SET_LTFIRSTHEAD:
3939 status.setEnabled(sel_row_start == sel_row_end
3940 && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
3941 && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
3942 && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
3943 && !tabular.ltCaption(sel_row_start));
3944 status.setOnOff(tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
3947 case Tabular::UNSET_LTFIRSTHEAD:
3948 status.setOnOff(!tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
3951 case Tabular::SET_LTHEAD:
3952 status.setEnabled(sel_row_start == sel_row_end
3953 && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
3954 && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
3955 && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
3956 && !tabular.ltCaption(sel_row_start));
3957 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
3960 case Tabular::UNSET_LTHEAD:
3961 status.setOnOff(!tabular.getRowOfLTHead(sel_row_start, dummyltt));
3964 case Tabular::SET_LTFOOT:
3965 status.setEnabled(sel_row_start == sel_row_end
3966 && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
3967 && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
3968 && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
3969 && !tabular.ltCaption(sel_row_start));
3970 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
3973 case Tabular::UNSET_LTFOOT:
3974 status.setOnOff(!tabular.getRowOfLTFoot(sel_row_start, dummyltt));
3977 case Tabular::SET_LTLASTFOOT:
3978 status.setEnabled(sel_row_start == sel_row_end
3979 && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
3980 && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
3981 && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
3982 && !tabular.ltCaption(sel_row_start));
3983 status.setOnOff(tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
3986 case Tabular::UNSET_LTLASTFOOT:
3987 status.setOnOff(!tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
3990 case Tabular::SET_LTNEWPAGE:
3991 status.setOnOff(tabular.getLTNewPage(sel_row_start));
3994 // only one row can be the caption
3995 case Tabular::TOGGLE_LTCAPTION:
3996 status.setEnabled(sel_row_start == sel_row_end
3997 && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
3998 && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
3999 && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
4000 && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
4001 && (!tabular.haveLTCaption()
4002 || tabular.ltCaption(sel_row_start)));
4003 status.setOnOff(tabular.ltCaption(sel_row_start));
4006 case Tabular::SET_BOOKTABS:
4007 status.setOnOff(tabular.use_booktabs);
4010 case Tabular::UNSET_BOOKTABS:
4011 status.setOnOff(!tabular.use_booktabs);
4016 status.setEnabled(false);
4022 // These are only enabled inside tabular
4023 case LFUN_CELL_BACKWARD:
4024 case LFUN_CELL_FORWARD:
4025 status.setEnabled(true);
4028 // disable these with multiple cells selected
4029 case LFUN_INSET_INSERT:
4030 case LFUN_TABULAR_INSERT:
4031 case LFUN_FLEX_INSERT:
4032 case LFUN_FLOAT_INSERT:
4033 case LFUN_FLOAT_WIDE_INSERT:
4034 case LFUN_FOOTNOTE_INSERT:
4035 case LFUN_MARGINALNOTE_INSERT:
4036 case LFUN_MATH_INSERT:
4037 case LFUN_MATH_MODE:
4038 case LFUN_MATH_MUTATE:
4039 case LFUN_MATH_DISPLAY:
4040 case LFUN_NOTE_INSERT:
4041 case LFUN_OPTIONAL_INSERT:
4042 case LFUN_BOX_INSERT:
4043 case LFUN_BRANCH_INSERT:
4044 case LFUN_PHANTOM_INSERT:
4045 case LFUN_WRAP_INSERT:
4046 case LFUN_ERT_INSERT: {
4047 if (cur.selIsMultiCell()) {
4048 status.setEnabled(false);
4051 return cell(cur.idx())->getStatus(cur, cmd, status);
4054 // disable in non-fixed-width cells
4055 case LFUN_NEWLINE_INSERT:
4056 case LFUN_BREAK_PARAGRAPH: {
4057 if (tabular.getPWidth(cur.idx()).zero()) {
4058 status.setEnabled(false);
4061 return cell(cur.idx())->getStatus(cur, cmd, status);
4064 case LFUN_NEWPAGE_INSERT:
4065 status.setEnabled(false);
4069 if (cur.selIsMultiCell()) {
4070 status.setEnabled(false);
4071 status.message(_("You cannot paste into a multicell selection."));
4074 if (tabularStackDirty() && theClipboard().isInternal()) {
4075 status.setEnabled(true);
4078 return cell(cur.idx())->getStatus(cur, cmd, status);
4080 case LFUN_INSET_SETTINGS:
4081 // relay this lfun to Inset, not to the cell.
4082 return Inset::getStatus(cur, cmd, status);
4084 case LFUN_INSET_MODIFY:
4085 if (insetCode(cmd.getArg(0)) == TABULAR_CODE) {
4086 status.setEnabled(true);
4092 // we try to handle this event in the insets dispatch function.
4093 return cell(cur.idx())->getStatus(cur, cmd, status);
4098 int InsetTabular::latex(odocstream & os, OutputParams const & runparams) const
4100 return tabular.latex(os, runparams);
4104 int InsetTabular::plaintext(odocstream & os, OutputParams const & runparams) const
4106 os << '\n'; // output table on a new line
4107 int const dp = runparams.linelen > 0 ? runparams.depth : 0;
4108 tabular.plaintext(os, runparams, dp, false, 0);
4109 return PLAINTEXT_NEWLINE;
4113 int InsetTabular::docbook(odocstream & os, OutputParams const & runparams) const
4118 // FIXME: Why not pass a proper DocIterator here?
4120 // if the table is inside a float it doesn't need the informaltable
4121 // wrapper. Search for it.
4122 for (master = owner(); master; master = master->owner())
4123 if (master->lyxCode() == FLOAT_CODE)
4128 os << "<informaltable>";
4131 ret += tabular.docbook(os, runparams);
4133 os << "</informaltable>";
4140 void InsetTabular::validate(LaTeXFeatures & features) const
4142 tabular.validate(features);
4146 shared_ptr<InsetTableCell const> InsetTabular::cell(idx_type idx) const
4148 return tabular.cellInset(idx);
4152 shared_ptr<InsetTableCell> InsetTabular::cell(idx_type idx)
4154 return tabular.cellInset(idx);
4158 void InsetTabular::cursorPos(BufferView const & bv,
4159 CursorSlice const & sl, bool boundary, int & x, int & y) const
4161 cell(sl.idx())->cursorPos(bv, sl, boundary, x, y);
4163 // y offset correction
4164 int const row = tabular.cellRow(sl.idx());
4165 for (int i = 0; i <= row; ++i) {
4167 y += tabular.rowAscent(i);
4168 y += tabular.getAdditionalHeight(i);
4171 y += tabular.rowDescent(i);
4174 // x offset correction
4175 int const col = tabular.cellColumn(sl.idx());
4176 int idx = tabular.cellIndex(row, 0);
4177 for (int j = 0; j < col; ++j) {
4178 if (tabular.isPartOfMultiColumn(row, j))
4180 x += tabular.columnWidth(idx);
4183 x += tabular.getBeginningOfTextInCell(idx);
4184 x += ADD_TO_TABULAR_WIDTH;
4189 int InsetTabular::dist(BufferView & bv, idx_type const cell, int x, int y) const
4193 Inset const & inset = *tabular.cellInset(cell);
4194 Point o = bv.coordCache().getInsets().xy(&inset);
4195 int const xbeg = o.x_ - tabular.getBeginningOfTextInCell(cell);
4196 int const xend = xbeg + tabular.columnWidth(cell);
4197 row_type const row = tabular.cellRow(cell);
4198 int const ybeg = o.y_ - tabular.rowAscent(row) -
4199 tabular.getAdditionalHeight(row);
4200 int const yend = o.y_ + tabular.rowDescent(row);
4212 //lyxerr << " xbeg=" << xbeg << " xend=" << xend
4213 // << " ybeg=" << ybeg << " yend=" << yend
4214 // << " xx=" << xx << " yy=" << yy
4215 // << " dist=" << xx + yy << endl;
4220 Inset * InsetTabular::editXY(Cursor & cur, int x, int y)
4222 //lyxerr << "InsetTabular::editXY: " << this << endl;
4223 cur.setSelection(false);
4225 cur.idx() = getNearestCell(cur.bv(), x, y);
4227 return cur.bv().textMetrics(&cell(cur.idx())->text()).editXY(cur, x, y);
4231 void InsetTabular::setCursorFromCoordinates(Cursor & cur, int x, int y) const
4233 cur.idx() = getNearestCell(cur.bv(), x, y);
4234 cur.bv().textMetrics(&cell(cur.idx())->text()).setCursorFromCoordinates(cur, x, y);
4238 InsetTabular::idx_type InsetTabular::getNearestCell(BufferView & bv, int x, int y) const
4240 idx_type idx_min = 0;
4241 int dist_min = numeric_limits<int>::max();
4242 for (idx_type i = 0, n = nargs(); i != n; ++i) {
4243 if (bv.coordCache().getInsets().has(tabular.cellInset(i).get())) {
4244 int const d = dist(bv, i, x, y);
4255 int InsetTabular::cellXPos(idx_type const cell) const
4259 for (; !tabular.isFirstCellInRow(c); --c)
4262 for (; c < cell; ++c)
4263 lx += tabular.columnWidth(c);
4269 void InsetTabular::resetPos(Cursor & cur) const
4271 BufferView & bv = cur.bv();
4272 int const maxwidth = bv.workWidth();
4274 int const scx_old = scx_;
4275 int const i = cur.find(this);
4280 int const X2 = maxwidth;
4281 int const offset = ADD_TO_TABULAR_WIDTH + 2;
4282 int const x1 = xo(cur.bv()) + cellXPos(cur[i].idx()) + offset;
4283 int const x2 = x1 + tabular.columnWidth(cur[i].idx());
4286 scx_ = X1 + 20 - x1;
4288 scx_ = X2 - 20 - x2;
4293 // only update if offset changed
4294 if (scx_ != scx_old)
4295 cur.updateFlags(Update::Force | Update::FitCursor);
4299 void InsetTabular::moveNextCell(Cursor & cur, EntryDirection entry_from)
4301 if (isRightToLeft(cur)) {
4302 if (tabular.isFirstCellInRow(cur.idx())) {
4303 row_type const row = tabular.cellRow(cur.idx());
4304 if (row == tabular.row_info.size() - 1)
4306 cur.idx() = tabular.cellBelow(tabular.getLastCellInRow(row));
4313 if (tabular.isLastCell(cur.idx()))
4318 cur.boundary(false);
4320 if (cur.selIsMultiCell()) {
4321 cur.pit() = cur.lastpit();
4322 cur.pos() = cur.lastpos();
4330 // in visual mode, place cursor at extreme left or right
4332 switch(entry_from) {
4334 case ENTRY_DIRECTION_RIGHT:
4335 cur.posVisToRowExtremity(false /* !left */);
4337 case ENTRY_DIRECTION_LEFT:
4338 cur.posVisToRowExtremity(true /* left */);
4340 case ENTRY_DIRECTION_IGNORE:
4341 // nothing to do in this case
4350 void InsetTabular::movePrevCell(Cursor & cur, EntryDirection entry_from)
4352 if (isRightToLeft(cur)) {
4353 if (tabular.isLastCellInRow(cur.idx())) {
4354 row_type const row = tabular.cellRow(cur.idx());
4357 cur.idx() = tabular.getFirstCellInRow(row);
4358 cur.idx() = tabular.cellAbove(cur.idx());
4360 if (tabular.isLastCell(cur.idx()))
4365 if (cur.idx() == 0) // first cell
4370 if (cur.selIsMultiCell()) {
4371 cur.pit() = cur.lastpit();
4372 cur.pos() = cur.lastpos();
4377 cur.pit() = cur.lastpit();
4378 cur.pos() = cur.lastpos();
4380 // in visual mode, place cursor at extreme left or right
4382 switch(entry_from) {
4384 case ENTRY_DIRECTION_RIGHT:
4385 cur.posVisToRowExtremity(false /* !left */);
4387 case ENTRY_DIRECTION_LEFT:
4388 cur.posVisToRowExtremity(true /* left */);
4390 case ENTRY_DIRECTION_IGNORE:
4391 // nothing to do in this case
4400 bool InsetTabular::tabularFeatures(Cursor & cur, string const & what)
4402 Tabular::Feature action = Tabular::LAST_ACTION;
4405 for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
4406 string const tmp = tabularFeature[i].feature;
4408 if (tmp == what.substr(0, tmp.length())) {
4409 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
4410 //tabularFeatures[i].feature.length()))
4411 action = tabularFeature[i].action;
4415 if (action == Tabular::LAST_ACTION)
4419 ltrim(what.substr(tabularFeature[i].feature.length()));
4420 tabularFeatures(cur, action, val);
4425 static void checkLongtableSpecial(Tabular::ltType & ltt,
4426 string const & special, bool & flag)
4428 if (special == "dl_above") {
4431 } else if (special == "dl_below") {
4432 ltt.bottomDL = flag;
4434 } else if (special == "empty") {
4443 bool InsetTabular::oneCellHasRotationState(bool rotated,
4444 row_type row_start, row_type row_end,
4445 col_type col_start, col_type col_end) const {
4447 for (row_type i = row_start; i <= row_end; ++i) {
4448 for (col_type j = col_start; j <= col_end; ++j) {
4449 if (tabular.getRotateCell(tabular.cellIndex(i, j))
4458 void InsetTabular::tabularFeatures(Cursor & cur,
4459 Tabular::Feature feature, string const & value)
4461 col_type sel_col_start;
4462 col_type sel_col_end;
4463 row_type sel_row_start;
4464 row_type sel_row_end;
4465 bool setLines = false;
4466 LyXAlignment setAlign = LYX_ALIGN_LEFT;
4467 Tabular::VAlignment setVAlign = Tabular::LYX_VALIGN_TOP;
4471 case Tabular::M_ALIGN_LEFT:
4472 case Tabular::ALIGN_LEFT:
4473 setAlign = LYX_ALIGN_LEFT;
4476 case Tabular::M_ALIGN_RIGHT:
4477 case Tabular::ALIGN_RIGHT:
4478 setAlign = LYX_ALIGN_RIGHT;
4481 case Tabular::M_ALIGN_CENTER:
4482 case Tabular::ALIGN_CENTER:
4483 setAlign = LYX_ALIGN_CENTER;
4486 case Tabular::ALIGN_BLOCK:
4487 setAlign = LYX_ALIGN_BLOCK;
4490 case Tabular::M_VALIGN_TOP:
4491 case Tabular::VALIGN_TOP:
4492 setVAlign = Tabular::LYX_VALIGN_TOP;
4495 case Tabular::M_VALIGN_BOTTOM:
4496 case Tabular::VALIGN_BOTTOM:
4497 setVAlign = Tabular::LYX_VALIGN_BOTTOM;
4500 case Tabular::M_VALIGN_MIDDLE:
4501 case Tabular::VALIGN_MIDDLE:
4502 setVAlign = Tabular::LYX_VALIGN_MIDDLE;
4509 cur.recordUndoInset(ATOMIC_UNDO);
4511 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
4512 row_type const row = tabular.cellRow(cur.idx());
4513 col_type const column = tabular.cellColumn(cur.idx());
4515 Tabular::ltType ltt;
4519 case Tabular::SET_PWIDTH: {
4520 Length const len(value);
4521 tabular.setColumnPWidth(cur, cur.idx(), len);
4523 && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
4524 tabularFeatures(cur, Tabular::ALIGN_CENTER, string());
4528 case Tabular::SET_MPWIDTH:
4529 tabular.setMColumnPWidth(cur, cur.idx(), Length(value));
4532 case Tabular::SET_SPECIAL_COLUMN:
4533 case Tabular::SET_SPECIAL_MULTI:
4534 tabular.setAlignSpecial(cur.idx(), from_utf8(value), feature);
4537 case Tabular::APPEND_ROW:
4538 // append the row into the tabular
4539 tabular.appendRow(cur.idx());
4542 case Tabular::APPEND_COLUMN:
4543 // append the column into the tabular
4544 tabular.appendColumn(cur.idx());
4545 cur.idx() = tabular.cellIndex(row, column);
4548 case Tabular::DELETE_ROW:
4549 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4550 tabular.deleteRow(sel_row_start);
4551 if (sel_row_start >= tabular.row_info.size())
4553 cur.idx() = tabular.cellIndex(sel_row_start, column);
4556 cur.setSelection(false);
4559 case Tabular::DELETE_COLUMN:
4560 for (col_type i = sel_col_start; i <= sel_col_end; ++i)
4561 tabular.deleteColumn(sel_col_start);
4562 if (sel_col_start >= tabular.column_info.size())
4564 cur.idx() = tabular.cellIndex(row, sel_col_start);
4567 cur.setSelection(false);
4570 case Tabular::COPY_ROW:
4571 tabular.copyRow(row);
4574 case Tabular::COPY_COLUMN:
4575 tabular.copyColumn(column);
4576 cur.idx() = tabular.cellIndex(row, column);
4579 case Tabular::TOGGLE_LINE_TOP: {
4580 bool lineSet = !tabular.topLine(cur.idx());
4581 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4582 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4583 tabular.setTopLine(tabular.cellIndex(i, j), lineSet);
4587 case Tabular::TOGGLE_LINE_BOTTOM: {
4588 bool lineSet = !tabular.bottomLine(cur.idx());
4589 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4590 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4591 tabular.setBottomLine(tabular.cellIndex(i, j), lineSet);
4595 case Tabular::TOGGLE_LINE_LEFT: {
4596 bool lineSet = !tabular.leftLine(cur.idx());
4597 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4598 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4599 tabular.setLeftLine(tabular.cellIndex(i, j), lineSet);
4603 case Tabular::TOGGLE_LINE_RIGHT: {
4604 bool lineSet = !tabular.rightLine(cur.idx());
4605 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4606 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4607 tabular.setRightLine(tabular.cellIndex(i, j), lineSet);
4611 case Tabular::M_ALIGN_LEFT:
4612 case Tabular::M_ALIGN_RIGHT:
4613 case Tabular::M_ALIGN_CENTER:
4615 case Tabular::ALIGN_LEFT:
4616 case Tabular::ALIGN_RIGHT:
4617 case Tabular::ALIGN_CENTER:
4618 case Tabular::ALIGN_BLOCK:
4619 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4620 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4621 tabular.setAlignment(tabular.cellIndex(i, j), setAlign, flag);
4624 case Tabular::M_VALIGN_TOP:
4625 case Tabular::M_VALIGN_BOTTOM:
4626 case Tabular::M_VALIGN_MIDDLE:
4628 case Tabular::VALIGN_TOP:
4629 case Tabular::VALIGN_BOTTOM:
4630 case Tabular::VALIGN_MIDDLE:
4631 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4632 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4633 tabular.setVAlignment(tabular.cellIndex(i, j), setVAlign, flag);
4636 case Tabular::MULTICOLUMN: {
4637 if (!cur.selection()) {
4638 // just multicol for one single cell
4639 // check whether we are completely in a multicol
4640 if (tabular.isMultiColumn(cur.idx()))
4641 tabular.unsetMultiColumn(cur.idx());
4643 tabular.setMultiColumn(cur.idx(), 1);
4646 // we have a selection so this means we just add all this
4647 // cells to form a multicolumn cell
4648 idx_type const s_start = cur.selBegin().idx();
4649 idx_type const s_end = cur.selEnd().idx();
4650 tabular.setMultiColumn(s_start, s_end - s_start + 1);
4651 cur.idx() = s_start;
4654 cur.setSelection(false);
4658 case Tabular::SET_ALL_LINES:
4660 case Tabular::UNSET_ALL_LINES:
4661 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4662 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4663 tabular.setAllLines(
4664 tabular.cellIndex(i,j), setLines);
4667 case Tabular::SET_BORDER_LINES:
4668 for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
4669 tabular.setLeftLine(tabular.cellIndex(i, sel_col_start), true);
4670 tabular.setRightLine(tabular.cellIndex(i, sel_col_end), true);
4672 for (col_type j = sel_col_start; j <= sel_col_end; ++j) {
4673 tabular.setTopLine(tabular.cellIndex(sel_row_start, j), true);
4674 tabular.setBottomLine(tabular.cellIndex(sel_row_end, j), true);
4678 case Tabular::SET_LONGTABULAR:
4679 tabular.is_long_tabular = true;
4682 case Tabular::UNSET_LONGTABULAR:
4683 tabular.is_long_tabular = false;
4686 case Tabular::SET_ROTATE_TABULAR:
4687 tabular.rotate = true;
4690 case Tabular::UNSET_ROTATE_TABULAR:
4691 tabular.rotate = false;
4694 case Tabular::TOGGLE_ROTATE_TABULAR:
4695 tabular.rotate = !tabular.rotate;
4698 case Tabular::TABULAR_VALIGN_TOP:
4699 tabular.tabular_valignment = Tabular::LYX_VALIGN_TOP;
4702 case Tabular::TABULAR_VALIGN_MIDDLE:
4703 tabular.tabular_valignment = Tabular::LYX_VALIGN_MIDDLE;
4706 case Tabular::TABULAR_VALIGN_BOTTOM:
4707 tabular.tabular_valignment = Tabular::LYX_VALIGN_BOTTOM;
4710 case Tabular::SET_ROTATE_CELL:
4711 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4712 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4713 tabular.setRotateCell(
4714 tabular.cellIndex(i, j), true);
4717 case Tabular::UNSET_ROTATE_CELL:
4718 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4719 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4720 tabular.setRotateCell(tabular.cellIndex(i, j), false);
4723 case Tabular::TOGGLE_ROTATE_CELL:
4725 bool oneNotRotated = oneCellHasRotationState(false,
4726 sel_row_start, sel_row_end, sel_col_start, sel_col_end);
4728 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4729 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4730 tabular.setRotateCell(tabular.cellIndex(i, j),
4735 case Tabular::SET_USEBOX: {
4736 Tabular::BoxType val = Tabular::BoxType(convert<int>(value));
4737 if (val == tabular.getUsebox(cur.idx()))
4738 val = Tabular::BOX_NONE;
4739 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4740 for (col_type j = sel_col_start; j <= sel_col_end; ++j)
4741 tabular.setUsebox(tabular.cellIndex(i, j), val);
4745 case Tabular::UNSET_LTFIRSTHEAD:
4747 case Tabular::SET_LTFIRSTHEAD:
4748 tabular.getRowOfLTFirstHead(row, ltt);
4749 checkLongtableSpecial(ltt, value, flag);
4750 tabular.setLTHead(row, flag, ltt, true);
4753 case Tabular::UNSET_LTHEAD:
4755 case Tabular::SET_LTHEAD:
4756 tabular.getRowOfLTHead(row, ltt);
4757 checkLongtableSpecial(ltt, value, flag);
4758 tabular.setLTHead(row, flag, ltt, false);
4761 case Tabular::UNSET_LTFOOT:
4763 case Tabular::SET_LTFOOT:
4764 tabular.getRowOfLTFoot(row, ltt);
4765 checkLongtableSpecial(ltt, value, flag);
4766 tabular.setLTFoot(row, flag, ltt, false);
4769 case Tabular::UNSET_LTLASTFOOT:
4771 case Tabular::SET_LTLASTFOOT:
4772 tabular.getRowOfLTLastFoot(row, ltt);
4773 checkLongtableSpecial(ltt, value, flag);
4774 tabular.setLTFoot(row, flag, ltt, true);
4777 case Tabular::SET_LTNEWPAGE:
4778 tabular.setLTNewPage(row, !tabular.getLTNewPage(row));
4781 case Tabular::TOGGLE_LTCAPTION: {
4782 bool set = !tabular.ltCaption(row);
4783 cur.idx() = tabular.setLTCaption(row, set);
4786 cur.setSelection(false);
4787 // When a row is set as caption, then also insert a caption. Otherwise
4788 // the LaTeX output is broken, when the user doesn't add a caption.
4790 lyx::dispatch(FuncRequest(LFUN_CAPTION_INSERT));
4794 case Tabular::SET_BOOKTABS:
4795 tabular.use_booktabs = true;
4798 case Tabular::UNSET_BOOKTABS:
4799 tabular.use_booktabs = false;
4802 case Tabular::SET_TOP_SPACE: {
4804 if (value == "default")
4805 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4806 tabular.row_info[i].top_space_default = true;
4807 else if (isValidLength(value, &len))
4808 for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
4809 tabular.row_info[i].top_space_default = false;
4810 tabular.row_info[i].top_space = len;
4813 for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
4814 tabular.row_info[i].top_space_default = false;
4815 tabular.row_info[i].top_space = len;
4820 case Tabular::SET_BOTTOM_SPACE: {
4822 if (value == "default")
4823 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4824 tabular.row_info[i].bottom_space_default = true;
4825 else if (isValidLength(value, &len))
4826 for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
4827 tabular.row_info[i].bottom_space_default = false;
4828 tabular.row_info[i].bottom_space = len;
4831 for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
4832 tabular.row_info[i].bottom_space_default = false;
4833 tabular.row_info[i].bottom_space = len;
4838 case Tabular::SET_INTERLINE_SPACE: {
4840 if (value == "default")
4841 for (row_type i = sel_row_start; i <= sel_row_end; ++i)
4842 tabular.row_info[i].interline_space_default = true;
4843 else if (isValidLength(value, &len))
4844 for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
4845 tabular.row_info[i].interline_space_default = false;
4846 tabular.row_info[i].interline_space = len;
4849 for (row_type i = sel_row_start; i <= sel_row_end; ++i) {
4850 tabular.row_info[i].interline_space_default = false;
4851 tabular.row_info[i].interline_space = len;
4856 // dummy stuff just to avoid warnings
4857 case Tabular::LAST_ACTION:
4863 bool InsetTabular::showInsetDialog(BufferView * bv) const
4865 bv->showDialog("tabular", params2string(*this),
4866 const_cast<InsetTabular *>(this));
4871 void InsetTabular::openLayoutDialog(BufferView * bv) const
4873 bv->showDialog("tabular", params2string(*this),
4874 const_cast<InsetTabular *>(this));
4878 bool InsetTabular::copySelection(Cursor & cur)
4880 if (!cur.selection())
4885 getSelection(cur, rs, re, cs, ce);
4887 paste_tabular.reset(new Tabular(tabular));
4889 for (row_type i = 0; i < rs; ++i)
4890 paste_tabular->deleteRow(0);
4892 row_type const rows = re - rs + 1;
4893 while (paste_tabular->row_info.size() > rows)
4894 paste_tabular->deleteRow(rows);
4896 for (col_type i = 0; i < cs; ++i)
4897 paste_tabular->deleteColumn(0);
4899 col_type const columns = ce - cs + 1;
4900 while (paste_tabular->column_info.size() > columns)
4901 paste_tabular->deleteColumn(columns);
4903 paste_tabular->setBuffer(tabular.buffer());
4905 odocstringstream os;
4906 OutputParams const runparams(0);
4907 paste_tabular->plaintext(os, runparams, 0, true, '\t');
4908 // Needed for the "Edit->Paste recent" menu and the system clipboard.
4909 cap::copySelection(cur, os.str());
4911 // mark tabular stack dirty
4912 // FIXME: this is a workaround for bug 1919. Should be removed for 1.5,
4913 // when we (hopefully) have a one-for-all paste mechanism.
4914 // This must be called after cap::copySelection.
4915 dirtyTabularStack(true);
4921 bool InsetTabular::pasteClipboard(Cursor & cur)
4925 col_type const actcol = tabular.cellColumn(cur.idx());
4926 row_type const actrow = tabular.cellRow(cur.idx());
4927 for (row_type r1 = 0, r2 = actrow;
4928 r1 < paste_tabular->row_info.size() && r2 < tabular.row_info.size();
4930 for (col_type c1 = 0, c2 = actcol;
4931 c1 < paste_tabular->column_info.size() && c2 < tabular.column_info.size();
4933 if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
4934 tabular.isPartOfMultiColumn(r2, c2))
4936 if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
4940 if (tabular.isPartOfMultiColumn(r2, c2)) {
4944 shared_ptr<InsetTableCell> inset(
4945 new InsetTableCell(*paste_tabular->cellInset(r1, c1)));
4946 tabular.setCellInset(r2, c2, inset);
4947 // FIXME: change tracking (MG)
4948 inset->setChange(Change(buffer().params().trackChanges ?
4949 Change::INSERTED : Change::UNCHANGED));
4957 void InsetTabular::cutSelection(Cursor & cur)
4959 if (!cur.selection())
4964 getSelection(cur, rs, re, cs, ce);
4965 for (row_type i = rs; i <= re; ++i) {
4966 for (col_type j = cs; j <= ce; ++j) {
4967 shared_ptr<InsetTableCell> t
4968 = cell(tabular.cellIndex(i, j));
4969 if (buffer().params().trackChanges)
4970 // FIXME: Change tracking (MG)
4971 t->setChange(Change(Change::DELETED));
4977 // cursor position might be invalid now
4978 if (cur.pit() > cur.lastpit())
4979 cur.pit() = cur.lastpit();
4980 if (cur.pos() > cur.lastpos())
4981 cur.pos() = cur.lastpos();
4982 cur.clearSelection();
4986 bool InsetTabular::isRightToLeft(Cursor & cur) const
4988 LASSERT(cur.depth() > 1, /**/);
4989 Paragraph const & parentpar = cur[cur.depth() - 2].paragraph();
4990 pos_type const parentpos = cur[cur.depth() - 2].pos();
4991 return parentpar.getFontSettings(buffer().params(),
4992 parentpos).language()->rightToLeft();
4995 docstring InsetTabular::asString(idx_type stidx, idx_type enidx,
4998 LASSERT(stidx <= enidx, return docstring());
5000 col_type const col1 = tabular.cellColumn(stidx);
5001 col_type const col2 = tabular.cellColumn(enidx);
5002 row_type const row1 = tabular.cellRow(stidx);
5003 row_type const row2 = tabular.cellRow(enidx);
5005 for (col_type col = col1; col <= col2; col++)
5006 for (row_type row = row1; row <= row2; row++) {
5011 retval += tabular.cellInset(row, col)->asString(intoInsets);
5017 void InsetTabular::getSelection(Cursor & cur,
5018 row_type & rs, row_type & re, col_type & cs, col_type & ce) const
5020 CursorSlice const & beg = cur.selBegin();
5021 CursorSlice const & end = cur.selEnd();
5022 cs = tabular.cellColumn(beg.idx());
5023 ce = tabular.cellColumn(end.idx());
5026 cs = tabular.cellColumn(end.idx());
5028 ce = tabular.cellRightColumn(end.idx());
5031 rs = tabular.cellRow(beg.idx());
5032 re = tabular.cellRow(end.idx());
5038 Text * InsetTabular::getText(int idx) const
5040 return size_t(idx) < nargs() ? cell(idx)->getText(0) : 0;
5044 void InsetTabular::setChange(Change const & change)
5046 for (idx_type idx = 0; idx < nargs(); ++idx)
5047 cell(idx)->setChange(change);
5051 void InsetTabular::acceptChanges(BufferParams const & bparams)
5053 for (idx_type idx = 0; idx < nargs(); ++idx)
5054 cell(idx)->acceptChanges(bparams);
5058 void InsetTabular::rejectChanges(BufferParams const & bparams)
5060 for (idx_type idx = 0; idx < nargs(); ++idx)
5061 cell(idx)->rejectChanges(bparams);
5065 bool InsetTabular::allowParagraphCustomization(idx_type cell) const
5067 return tabular.getPWidth(cell).zero();
5071 bool InsetTabular::forcePlainLayout(idx_type cell) const
5073 return !tabular.getPWidth(cell).zero();
5077 bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
5080 if (buf.length() <= 0)
5085 col_type maxCols = 1;
5086 size_t const len = buf.length();
5090 (p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos) {
5098 maxCols = max(cols, maxCols);
5104 maxCols = max(cols, maxCols);
5110 paste_tabular.reset(new Tabular(buffer(), rows, maxCols));
5111 loctab = paste_tabular.get();
5113 dirtyTabularStack(true);
5116 cell = bv.cursor().idx();
5117 ocol = tabular.cellColumn(cell);
5118 row = tabular.cellRow(cell);
5122 idx_type const cells = loctab->numberofcells;
5125 rows = loctab->row_info.size();
5126 col_type const columns = loctab->column_info.size();
5128 while (cell < cells && p < len && row < rows &&
5129 (p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos)
5135 // we can only set this if we are not too far right
5136 if (cols < columns) {
5137 shared_ptr<InsetTableCell> inset = loctab->cellInset(cell);
5138 Font const font = bv.textMetrics(&inset->text()).
5140 inset->setText(buf.substr(op, p - op), font,
5141 buffer().params().trackChanges);
5147 // we can only set this if we are not too far right
5148 if (cols < columns) {
5149 shared_ptr<InsetTableCell> inset = tabular.cellInset(cell);
5150 Font const font = bv.textMetrics(&inset->text()).
5152 inset->setText(buf.substr(op, p - op), font,
5153 buffer().params().trackChanges);
5158 cell = loctab->cellIndex(row, cols);
5164 // check for the last cell if there is no trailing '\n'
5165 if (cell < cells && op < len) {
5166 shared_ptr<InsetTableCell> inset = loctab->cellInset(cell);
5167 Font const font = bv.textMetrics(&inset->text()).displayFont(0, 0);
5168 inset->setText(buf.substr(op, len - op), font,
5169 buffer().params().trackChanges);
5175 void InsetTabular::addPreview(PreviewLoader & loader) const
5177 row_type const rows = tabular.row_info.size();
5178 col_type const columns = tabular.column_info.size();
5179 for (row_type i = 0; i < rows; ++i) {
5180 for (col_type j = 0; j < columns; ++j)
5181 tabular.cellInset(i, j)->addPreview(loader);
5186 bool InsetTabular::completionSupported(Cursor const & cur) const
5188 Cursor const & bvCur = cur.bv().cursor();
5189 if (&bvCur.inset() != this)
5191 return cur.text()->completionSupported(cur);
5195 bool InsetTabular::inlineCompletionSupported(Cursor const & cur) const
5197 return completionSupported(cur);
5201 bool InsetTabular::automaticInlineCompletion() const
5203 return lyxrc.completion_inline_text;
5207 bool InsetTabular::automaticPopupCompletion() const
5209 return lyxrc.completion_popup_text;
5213 bool InsetTabular::showCompletionCursor() const
5215 return lyxrc.completion_cursor_text;
5219 CompletionList const * InsetTabular::createCompletionList(Cursor const & cur) const
5221 return completionSupported(cur) ? cur.text()->createCompletionList(cur) : 0;
5225 docstring InsetTabular::completionPrefix(Cursor const & cur) const
5227 if (!completionSupported(cur))
5229 return cur.text()->completionPrefix(cur);
5233 bool InsetTabular::insertCompletion(Cursor & cur, docstring const & s, bool finished)
5235 if (!completionSupported(cur))
5238 return cur.text()->insertCompletion(cur, s, finished);
5242 void InsetTabular::completionPosAndDim(Cursor const & cur, int & x, int & y,
5243 Dimension & dim) const
5245 TextMetrics const & tm = cur.bv().textMetrics(cur.text());
5246 tm.completionPosAndDim(cur, x, y, dim);
5250 void InsetTabular::string2params(string const & in, InsetTabular & inset)
5252 istringstream data(in);
5254 lex.setStream(data);
5261 if (!lex || token != "tabular") {
5262 LYXERR0("Expected arg 1 to be \"tabular\" in " << in);
5266 // This is part of the inset proper that is usually swallowed
5267 // by Buffer::readInset
5269 if (!lex || token != "Tabular") {
5270 LYXERR0("Expected arg 2 to be \"Tabular\" in " << in);
5278 string InsetTabular::params2string(InsetTabular const & inset)
5281 data << "tabular" << ' ';
5283 data << "\\end_inset\n";