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 * \author Edwin Leuven
16 * \author Scott Kostyshak
18 * Full author contact details are available in file CREDITS.
23 #include "InsetTabular.h"
25 #include "buffer_funcs.h"
27 #include "BufferParams.h"
28 #include "BufferView.h"
29 #include "CoordCache.h"
32 #include "CutAndPaste.h"
33 #include "DispatchResult.h"
34 #include "FuncRequest.h"
35 #include "FuncStatus.h"
36 #include "InsetIterator.h"
37 #include "InsetList.h"
39 #include "LaTeXFeatures.h"
43 #include "MetricsInfo.h"
44 #include "OutputParams.h"
45 #include "output_xhtml.h"
46 #include "Paragraph.h"
47 #include "ParagraphParameters.h"
48 #include "ParIterator.h"
50 #include "texstream.h"
51 #include "TextClass.h"
52 #include "TextMetrics.h"
54 #include "frontends/Application.h"
55 #include "frontends/alert.h"
56 #include "frontends/Clipboard.h"
57 #include "frontends/Painter.h"
58 #include "frontends/Selection.h"
60 #include "support/convert.h"
61 #include "support/debug.h"
62 #include "support/docstream.h"
63 #include "support/FileName.h"
64 #include "support/gettext.h"
65 #include "support/lassert.h"
66 #include "support/lstrings.h"
67 #include "support/unique_ptr.h"
76 using namespace lyx::support;
82 using cap::dirtyTabularStack;
83 using cap::tabularStackDirty;
85 using graphics::PreviewLoader;
87 using frontend::Painter;
88 using frontend::Clipboard;
90 namespace Alert = frontend::Alert;
95 int const ADD_TO_HEIGHT = 2; // in cell
96 int const ADD_TO_TABULAR_WIDTH = 6; // horizontal space before and after the table
97 int const default_line_space = 10; // ?
98 int const WIDTH_OF_LINE = 5; // space between double lines
102 unique_ptr<Tabular> paste_tabular;
105 struct TabularFeature {
106 Tabular::Feature action;
112 TabularFeature tabularFeature[] =
114 // the SET/UNSET actions are used by the table dialog,
115 // the TOGGLE actions by the table toolbar buttons
116 // FIXME: these values have been hardcoded in InsetMathGrid and other
118 { Tabular::APPEND_ROW, "append-row", false },
119 { Tabular::APPEND_COLUMN, "append-column", false },
120 { Tabular::DELETE_ROW, "delete-row", false },
121 { Tabular::DELETE_COLUMN, "delete-column", false },
122 { Tabular::COPY_ROW, "copy-row", false },
123 { Tabular::COPY_COLUMN, "copy-column", false },
124 { Tabular::MOVE_COLUMN_RIGHT, "move-column-right", false },
125 { Tabular::MOVE_COLUMN_LEFT, "move-column-left", false },
126 { Tabular::MOVE_ROW_DOWN, "move-row-down", false },
127 { Tabular::MOVE_ROW_UP, "move-row-up", false },
128 { Tabular::SET_LINE_TOP, "set-line-top", true },
129 { Tabular::SET_LINE_BOTTOM, "set-line-bottom", true },
130 { Tabular::SET_LINE_LEFT, "set-line-left", true },
131 { Tabular::SET_LINE_RIGHT, "set-line-right", true },
132 { Tabular::TOGGLE_LINE_TOP, "toggle-line-top", false },
133 { Tabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom", false },
134 { Tabular::TOGGLE_LINE_LEFT, "toggle-line-left", false },
135 { Tabular::TOGGLE_LINE_RIGHT, "toggle-line-right", false },
136 { Tabular::ALIGN_LEFT, "align-left", false },
137 { Tabular::ALIGN_RIGHT, "align-right", false },
138 { Tabular::ALIGN_CENTER, "align-center", false },
139 { Tabular::ALIGN_BLOCK, "align-block", false },
140 { Tabular::ALIGN_DECIMAL, "align-decimal", false },
141 { Tabular::VALIGN_TOP, "valign-top", false },
142 { Tabular::VALIGN_BOTTOM, "valign-bottom", false },
143 { Tabular::VALIGN_MIDDLE, "valign-middle", false },
144 { Tabular::M_ALIGN_LEFT, "m-align-left", false },
145 { Tabular::M_ALIGN_RIGHT, "m-align-right", false },
146 { Tabular::M_ALIGN_CENTER, "m-align-center", false },
147 { Tabular::M_VALIGN_TOP, "m-valign-top", false },
148 { Tabular::M_VALIGN_BOTTOM, "m-valign-bottom", false },
149 { Tabular::M_VALIGN_MIDDLE, "m-valign-middle", false },
150 { Tabular::MULTICOLUMN, "multicolumn", false },
151 { Tabular::SET_MULTICOLUMN, "set-multicolumn", false },
152 { Tabular::UNSET_MULTICOLUMN, "unset-multicolumn", false },
153 { Tabular::MULTIROW, "multirow", false },
154 { Tabular::SET_MULTIROW, "set-multirow", false },
155 { Tabular::UNSET_MULTIROW, "unset-multirow", false },
156 { Tabular::SET_MROFFSET, "set-mroffset", true },
157 { Tabular::SET_ALL_LINES, "set-all-lines", false },
158 { Tabular::UNSET_ALL_LINES, "unset-all-lines", false },
159 { Tabular::TOGGLE_LONGTABULAR, "toggle-longtabular", false },
160 { Tabular::SET_LONGTABULAR, "set-longtabular", false },
161 { Tabular::UNSET_LONGTABULAR, "unset-longtabular", false },
162 { Tabular::SET_PWIDTH, "set-pwidth", true },
163 { Tabular::SET_MPWIDTH, "set-mpwidth", true },
164 { Tabular::SET_ROTATE_TABULAR, "set-rotate-tabular", true },
165 { Tabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular", true },
166 { Tabular::TOGGLE_ROTATE_TABULAR, "toggle-rotate-tabular", true },
167 { Tabular::SET_ROTATE_CELL, "set-rotate-cell", true },
168 { Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell", true },
169 { Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell", true },
170 { Tabular::SET_USEBOX, "set-usebox", true },
171 { Tabular::SET_LTHEAD, "set-lthead", true },
172 { Tabular::UNSET_LTHEAD, "unset-lthead", true },
173 { Tabular::SET_LTFIRSTHEAD, "set-ltfirsthead", true },
174 { Tabular::UNSET_LTFIRSTHEAD, "unset-ltfirsthead", true },
175 { Tabular::SET_LTFOOT, "set-ltfoot", true },
176 { Tabular::UNSET_LTFOOT, "unset-ltfoot", true },
177 { Tabular::SET_LTLASTFOOT, "set-ltlastfoot", true },
178 { Tabular::UNSET_LTLASTFOOT, "unset-ltlastfoot", true },
179 { Tabular::SET_LTNEWPAGE, "set-ltnewpage", false },
180 { Tabular::UNSET_LTNEWPAGE, "unset-ltnewpage", false },
181 { Tabular::TOGGLE_LTCAPTION, "toggle-ltcaption", false },
182 { Tabular::SET_LTCAPTION, "set-ltcaption", false },
183 { Tabular::UNSET_LTCAPTION, "unset-ltcaption", false },
184 { Tabular::SET_SPECIAL_COLUMN, "set-special-column", true },
185 { Tabular::SET_SPECIAL_MULTICOLUMN, "set-special-multicolumn", true },
186 { Tabular::TOGGLE_BOOKTABS, "toggle-booktabs", false },
187 { Tabular::SET_BOOKTABS, "set-booktabs", false },
188 { Tabular::UNSET_BOOKTABS, "unset-booktabs", false },
189 { Tabular::SET_TOP_SPACE, "set-top-space", true },
190 { Tabular::SET_BOTTOM_SPACE, "set-bottom-space", true },
191 { Tabular::SET_INTERLINE_SPACE, "set-interline-space", true },
192 { Tabular::SET_BORDER_LINES, "set-border-lines", false },
193 { Tabular::TABULAR_VALIGN_TOP, "tabular-valign-top", false},
194 { Tabular::TABULAR_VALIGN_MIDDLE, "tabular-valign-middle", false},
195 { Tabular::TABULAR_VALIGN_BOTTOM, "tabular-valign-bottom", false},
196 { Tabular::LONGTABULAR_ALIGN_LEFT, "longtabular-align-left", false },
197 { Tabular::LONGTABULAR_ALIGN_CENTER, "longtabular-align-center", false },
198 { Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right", false },
199 { Tabular::SET_DECIMAL_POINT, "set-decimal-point", true },
200 { Tabular::SET_TABULAR_WIDTH, "set-tabular-width", true },
201 { Tabular::LAST_ACTION, "", false }
205 string const tostr(LyXAlignment const & num)
210 case LYX_ALIGN_BLOCK:
214 case LYX_ALIGN_CENTER:
216 case LYX_ALIGN_RIGHT:
218 case LYX_ALIGN_LAYOUT:
220 case LYX_ALIGN_SPECIAL:
222 case LYX_ALIGN_DECIMAL:
229 string const tostr(Tabular::HAlignment const & num)
232 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
234 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
236 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
243 string const tostr(Tabular::VAlignment const & num)
246 case Tabular::LYX_VALIGN_TOP:
248 case Tabular::LYX_VALIGN_MIDDLE:
250 case Tabular::LYX_VALIGN_BOTTOM:
257 string const tostr(Tabular::BoxType const & num)
260 case Tabular::BOX_NONE:
262 case Tabular::BOX_PARBOX:
264 case Tabular::BOX_MINIPAGE:
271 // I would have liked a fromstr template a lot better. (Lgb)
272 bool string2type(string const & str, LyXAlignment & num)
275 num = LYX_ALIGN_NONE;
276 else if (str == "block")
277 num = LYX_ALIGN_BLOCK;
278 else if (str == "left")
279 num = LYX_ALIGN_LEFT;
280 else if (str == "center")
281 num = LYX_ALIGN_CENTER;
282 else if (str == "right")
283 num = LYX_ALIGN_RIGHT;
284 else if (str == "decimal")
285 num = LYX_ALIGN_DECIMAL;
292 bool string2type(string const & str, Tabular::HAlignment & num)
295 num = Tabular::LYX_LONGTABULAR_ALIGN_LEFT;
296 else if (str == "center" )
297 num = Tabular::LYX_LONGTABULAR_ALIGN_CENTER;
298 else if (str == "right")
299 num = Tabular::LYX_LONGTABULAR_ALIGN_RIGHT;
306 bool string2type(string const & str, Tabular::VAlignment & num)
309 num = Tabular::LYX_VALIGN_TOP;
310 else if (str == "middle" )
311 num = Tabular::LYX_VALIGN_MIDDLE;
312 else if (str == "bottom")
313 num = Tabular::LYX_VALIGN_BOTTOM;
320 bool string2type(string const & str, Tabular::BoxType & num)
323 num = Tabular::BOX_NONE;
324 else if (str == "parbox")
325 num = Tabular::BOX_PARBOX;
326 else if (str == "minipage")
327 num = Tabular::BOX_MINIPAGE;
334 bool string2type(string const & str, bool & num)
338 else if (str == "false")
346 bool getTokenValue(string const & str, char const * token, string & ret)
349 size_t token_length = strlen(token);
350 size_t pos = str.find(token);
352 if (pos == string::npos || pos + token_length + 1 >= str.length()
353 || str[pos + token_length] != '=')
355 pos += token_length + 1;
357 if (ch != '"' && ch != '\'') { // only read till next space
361 while (pos < str.length() - 1 && str[++pos] != ch)
368 bool getTokenValue(string const & str, char const * token, docstring & ret)
371 bool const success = getTokenValue(str, token, tmp);
372 ret = from_utf8(tmp);
377 bool getTokenValue(string const & str, char const * token, int & num)
381 if (!getTokenValue(str, token, tmp))
383 num = convert<int>(tmp);
388 bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
391 return getTokenValue(str, token, tmp) && string2type(tmp, num);
395 bool getTokenValue(string const & str, char const * token,
396 Tabular::HAlignment & num)
399 return getTokenValue(str, token, tmp) && string2type(tmp, num);
403 bool getTokenValue(string const & str, char const * token,
404 Tabular::VAlignment & num)
407 return getTokenValue(str, token, tmp) && string2type(tmp, num);
411 bool getTokenValue(string const & str, char const * token,
412 Tabular::BoxType & num)
415 return getTokenValue(str, token, tmp) && string2type(tmp, num);
419 bool getTokenValue(string const & str, char const * token, bool & flag)
421 // set the flag always to false as this should be the default for bools
422 // not in the file-format.
425 return getTokenValue(str, token, tmp) && string2type(tmp, flag);
429 bool getTokenValue(string const & str, char const * token, Length & len)
431 // set the length to be zero() as default as this it should be if not
432 // in the file format.
435 return getTokenValue(str, token, tmp) && isValidLength(tmp, &len);
439 bool getTokenValue(string const & str, char const * token, Length & len, bool & flag)
444 if (!getTokenValue(str, token, tmp))
446 if (tmp == "default") {
450 return isValidLength(tmp, &len);
454 void l_getline(istream & is, string & str)
457 while (str.empty()) {
459 if (!str.empty() && str[str.length() - 1] == '\r')
460 str.erase(str.length() - 1);
465 string const write_attribute(string const & name, T const & t)
467 string const s = tostr(t);
468 return s.empty() ? s : " " + name + "=\"" + s + "\"";
472 string const write_attribute(string const & name, string const & t)
474 return t.empty() ? t : " " + name + "=\"" + t + "\"";
479 string const write_attribute(string const & name, docstring const & t)
481 return t.empty() ? string() : " " + name + "=\"" + to_utf8(t) + "\"";
486 string const write_attribute(string const & name, bool const & b)
488 // we write only true attribute values so we remove a bit of the
489 // file format bloat for tabulars.
490 return b ? write_attribute(name, convert<string>(b)) : string();
495 string const write_attribute(string const & name, int const & i)
497 // we write only true attribute values so we remove a bit of the
498 // file format bloat for tabulars.
499 return i ? write_attribute(name, convert<string>(i)) : string();
504 string const write_attribute(string const & name, Tabular::idx_type const & i)
506 // we write only true attribute values so we remove a bit of the
507 // file format bloat for tabulars.
508 return i ? write_attribute(name, convert<string>(i)) : string();
513 string const write_attribute(string const & name, Length const & value)
515 // we write only the value if we really have one same reson as above.
516 return value.zero() ? string() : write_attribute(name, value.asString());
522 string const featureAsString(Tabular::Feature action)
524 for (size_t i = 0; i != Tabular::LAST_ACTION; ++i) {
525 if (tabularFeature[i].action == action)
526 return tabularFeature[i].feature;
532 DocIterator separatorPos(InsetTableCell const * cell, docstring const & align_d)
534 DocIterator dit = doc_iterator_begin(&(cell->buffer()), cell);
535 for (; dit; dit.forwardChar())
536 if (dit.inTexted() && dit.depth() == 1
537 && dit.paragraph().find(align_d, false, false, dit.pos()))
544 InsetTableCell splitCell(InsetTableCell & head, docstring const & align_d, bool & hassep)
546 InsetTableCell tail = InsetTableCell(head);
547 DocIterator const dit = separatorPos(&head, align_d);
550 pit_type const psize = head.paragraphs().front().size();
551 head.paragraphs().front().eraseChars(dit.pos(), psize, false);
552 tail.paragraphs().front().eraseChars(0,
553 dit.pos() < psize ? dit.pos() + 1 : psize, false);
560 /////////////////////////////////////////////////////////////////////
564 /////////////////////////////////////////////////////////////////////
567 Tabular::CellData::CellData(Buffer * buf)
570 multicolumn(Tabular::CELL_NORMAL),
571 multirow(Tabular::CELL_NORMAL),
572 alignment(LYX_ALIGN_CENTER),
573 valignment(LYX_VALIGN_TOP),
583 inset(new InsetTableCell(buf))
585 inset->setBuffer(*buf);
589 Tabular::CellData::CellData(CellData const & cs)
592 multicolumn(cs.multicolumn),
593 multirow(cs.multirow),
594 mroffset(cs.mroffset),
595 alignment(cs.alignment),
596 valignment(cs.valignment),
597 decimal_hoffset(cs.decimal_hoffset),
598 decimal_width(cs.decimal_width),
600 top_line(cs.top_line),
601 bottom_line(cs.bottom_line),
602 left_line(cs.left_line),
603 right_line(cs.right_line),
606 align_special(cs.align_special),
608 inset(static_cast<InsetTableCell *>(cs.inset->clone()))
612 Tabular::CellData & Tabular::CellData::operator=(CellData const & cs)
618 multicolumn = cs.multicolumn;
619 multirow = cs.multirow;
620 mroffset = cs.mroffset;
621 alignment = cs.alignment;
622 valignment = cs.valignment;
623 decimal_hoffset = cs.decimal_hoffset;
624 decimal_width = cs.decimal_width;
625 voffset = cs.voffset;
626 top_line = cs.top_line;
627 bottom_line = cs.bottom_line;
628 left_line = cs.left_line;
629 right_line = cs.right_line;
632 align_special = cs.align_special;
633 p_width = cs.p_width;
634 inset.reset(static_cast<InsetTableCell *>(cs.inset->clone()));
638 Tabular::RowData::RowData()
641 top_space_default(false),
642 bottom_space_default(false),
643 interline_space_default(false),
653 Tabular::ColumnData::ColumnData()
654 : alignment(LYX_ALIGN_CENTER),
655 valignment(LYX_VALIGN_TOP),
661 Tabular::ltType::ltType()
662 : set(false), topDL(false),
668 Tabular::Tabular(Buffer * buffer, row_type rows_arg, col_type columns_arg)
670 init(buffer, rows_arg, columns_arg);
674 void Tabular::setBuffer(Buffer & buffer)
677 for (row_type i = 0; i < nrows(); ++i)
678 for (col_type j = 0; j < ncols(); ++j)
679 cell_info[i][j].inset->setBuffer(*buffer_);
683 // activates all lines and sets all widths to 0
684 void Tabular::init(Buffer * buf, row_type rows_arg,
685 col_type columns_arg)
688 row_info = row_vector(rows_arg);
689 column_info = column_vector(columns_arg);
690 cell_info = cell_vvector(rows_arg, cell_vector(columns_arg, CellData(buf)));
691 row_info.reserve(10);
692 column_info.reserve(10);
693 cell_info.reserve(100);
695 is_long_tabular = false;
696 tabular_valignment = LYX_VALIGN_MIDDLE;
697 tabular_width = Length();
698 longtabular_alignment = LYX_LONGTABULAR_ALIGN_CENTER;
700 use_booktabs = false;
701 // set silly default lines
702 for (row_type r = 0; r < nrows(); ++r)
703 for (col_type c = 0; c < ncols(); ++c) {
704 cell_info[r][c].inset->setBuffer(*buffer_);
705 cell_info[r][c].top_line = true;
706 cell_info[r][c].left_line = true;
707 cell_info[r][c].bottom_line = r == 0 || r == nrows() - 1;
708 cell_info[r][c].right_line = c == ncols() - 1;
713 void Tabular::deleteRow(row_type const row)
715 // Not allowed to delete last row
719 for (col_type c = 0; c < ncols(); ++c) {
720 // Care about multirow cells
721 if (row + 1 < nrows() &&
722 cell_info[row][c].multirow == CELL_BEGIN_OF_MULTIROW &&
723 cell_info[row + 1][c].multirow == CELL_PART_OF_MULTIROW) {
724 cell_info[row + 1][c].multirow = CELL_BEGIN_OF_MULTIROW;
727 row_info.erase(row_info.begin() + row);
728 cell_info.erase(cell_info.begin() + row);
733 void Tabular::copyRow(row_type const row)
735 insertRow(row, true);
739 void Tabular::appendRow(row_type row)
741 insertRow(row, false);
745 void Tabular::insertRow(row_type const row, bool copy)
747 row_info.insert(row_info.begin() + row + 1, RowData(row_info[row]));
748 cell_info.insert(cell_info.begin() + row + 1,
749 cell_vector(0, CellData(buffer_)));
751 for (col_type c = 0; c < ncols(); ++c) {
752 cell_info[row + 1].insert(cell_info[row + 1].begin() + c,
753 copy ? CellData(cell_info[row][c]) : CellData(buffer_));
754 if (buffer().params().track_changes)
755 cell_info[row + 1][c].inset->setChange(Change(Change::INSERTED));
756 if (cell_info[row][c].multirow == CELL_BEGIN_OF_MULTIROW)
757 cell_info[row + 1][c].multirow = CELL_PART_OF_MULTIROW;
761 for (col_type c = 0; c < ncols(); ++c) {
762 if (isPartOfMultiRow(row, c))
764 // inherit line settings
765 idx_type const i = cellIndex(row + 1, c);
766 idx_type const j = cellIndex(row, c);
767 setLeftLine(i, leftLine(j));
768 setRightLine(i, rightLine(j));
769 setTopLine(i, topLine(j));
770 if (topLine(j) && bottomLine(j)) {
771 setBottomLine(i, true);
772 setBottomLine(j, false);
774 // mark track changes
775 if (buffer().params().track_changes)
776 cellInfo(i).inset->setChange(Change(Change::INSERTED));
781 void Tabular::moveColumn(col_type col, ColDirection direction)
783 if (direction == Tabular::LEFT)
786 std::swap(column_info[col], column_info[col + 1]);
788 for (row_type r = 0; r < nrows(); ++r) {
789 std::swap(cell_info[r][col], cell_info[r][col + 1]);
790 std::swap(cell_info[r][col].left_line, cell_info[r][col + 1].left_line);
791 std::swap(cell_info[r][col].right_line, cell_info[r][col + 1].right_line);
793 // FIXME track changes is broken for tabular features (#8469)
794 idx_type const i = cellIndex(r, col);
795 idx_type const j = cellIndex(r, col + 1);
796 if (buffer().params().track_changes) {
797 cellInfo(i).inset->setChange(Change(Change::INSERTED));
798 cellInfo(j).inset->setChange(Change(Change::INSERTED));
805 void Tabular::moveRow(row_type row, RowDirection direction)
807 if (direction == Tabular::UP)
810 std::swap(row_info[row], row_info[row + 1]);
812 for (col_type c = 0; c < ncols(); ++c) {
813 std::swap(cell_info[row][c], cell_info[row + 1][c]);
814 std::swap(cell_info[row][c].top_line, cell_info[row + 1][c].top_line);
815 std::swap(cell_info[row][c].bottom_line, cell_info[row + 1][c].bottom_line);
817 // FIXME track changes is broken for tabular features (#8469)
818 idx_type const i = cellIndex(row, c);
819 idx_type const j = cellIndex(row + 1, c);
820 if (buffer().params().track_changes) {
821 cellInfo(i).inset->setChange(Change(Change::INSERTED));
822 cellInfo(j).inset->setChange(Change(Change::INSERTED));
829 void Tabular::deleteColumn(col_type const col)
831 // Not allowed to delete last column
835 for (row_type r = 0; r < nrows(); ++r) {
836 // Care about multicolumn cells
837 if (col + 1 < ncols() &&
838 cell_info[r][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN &&
839 cell_info[r][col + 1].multicolumn == CELL_PART_OF_MULTICOLUMN) {
840 cell_info[r][col + 1].multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
842 cell_info[r].erase(cell_info[r].begin() + col);
844 column_info.erase(column_info.begin() + col);
849 void Tabular::copyColumn(col_type const col)
851 insertColumn(col, true);
855 void Tabular::appendColumn(col_type col)
857 insertColumn(col, false);
861 void Tabular::insertColumn(col_type const col, bool copy)
863 BufferParams const & bp = buffer().params();
864 column_info.insert(column_info.begin() + col + 1, ColumnData(column_info[col]));
866 for (row_type r = 0; r < nrows(); ++r) {
867 cell_info[r].insert(cell_info[r].begin() + col + 1,
868 copy ? CellData(cell_info[r][col]) : CellData(buffer_));
869 if (bp.track_changes)
870 cell_info[r][col + 1].inset->setChange(Change(Change::INSERTED));
871 if (cell_info[r][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
872 cell_info[r][col + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
875 for (row_type r = 0; r < nrows(); ++r) {
876 // inherit line settings
877 idx_type const i = cellIndex(r, col + 1);
878 idx_type const j = cellIndex(r, col);
879 setBottomLine(i, bottomLine(j));
880 setTopLine(i, topLine(j));
881 setLeftLine(i, leftLine(j));
882 setRightLine(i, rightLine(j));
883 if (rightLine(i) && rightLine(j)) {
884 setRightLine(j, false);
886 if (buffer().params().track_changes)
887 cellInfo(i).inset->setChange(Change(Change::INSERTED));
892 void Tabular::updateIndexes()
897 for (row_type row = 0; row < nrows(); ++row)
898 for (col_type column = 0; column < ncols(); ++column) {
899 if (!isPartOfMultiColumn(row, column)
900 && !isPartOfMultiRow(row, column))
902 if (isPartOfMultiRow(row, column))
903 cell_info[row][column].cellno = cell_info[row - 1][column].cellno;
905 cell_info[row][column].cellno = numberofcells - 1;
908 rowofcell.resize(numberofcells);
909 columnofcell.resize(numberofcells);
911 // reset column and row of cells and update their width and alignment
912 for (row_type row = 0; row < nrows(); ++row)
913 for (col_type column = 0; column < ncols(); ++column) {
914 if (isPartOfMultiColumn(row, column))
916 // columnofcell needs to be called before setting width and aligment
917 // multirow cells inherit the width from the column width
918 if (!isPartOfMultiRow(row, column)) {
919 columnofcell[i] = column;
922 setFixedWidth(row, column);
923 if (isPartOfMultiRow(row, column))
925 cell_info[row][column].inset->setContentAlignment(
926 getAlignment(cellIndex(row, column)));
932 Tabular::idx_type Tabular::numberOfCellsInRow(row_type const row) const
935 for (col_type c = 0; c < ncols(); ++c)
936 if (cell_info[row][c].multicolumn != Tabular::CELL_PART_OF_MULTICOLUMN)
942 bool Tabular::topLine(idx_type const cell) const
944 return cellInfo(cell).top_line;
948 bool Tabular::bottomLine(idx_type const cell) const
950 return cellInfo(cell).bottom_line;
954 bool Tabular::leftLine(idx_type cell) const
958 return cellInfo(cell).left_line;
962 bool Tabular::rightLine(idx_type cell) const
966 return cellInfo(cell).right_line;
970 int Tabular::interRowSpace(row_type row) const
972 if (!row || row >= nrows())
975 int const interline_space = row_info[row - 1].interline_space_default ?
977 row_info[row - 1].interline_space.inPixels(width());
978 if (rowTopLine(row) && rowBottomLine(row - 1))
979 return interline_space + WIDTH_OF_LINE;
980 return interline_space;
984 int Tabular::interColumnSpace(idx_type cell) const
986 col_type const nextcol = cellColumn(cell) + columnSpan(cell);
987 if (rightLine(cell) && nextcol < ncols()
988 && leftLine(cellIndex(cellRow(cell), nextcol)))
989 return WIDTH_OF_LINE;
994 int Tabular::cellWidth(idx_type cell) const
997 col_type const span = columnSpan(cell);
998 col_type const col = cellColumn(cell);
999 for(col_type c = col; c < col + span ; ++c)
1000 w += column_info[c].width;
1005 int Tabular::cellHeight(idx_type cell) const
1007 row_type const span = rowSpan(cell);
1008 row_type const row = cellRow(cell);
1010 for(row_type r = row; r < row + span ; ++r) {
1011 h += rowAscent(r) + rowDescent(r);
1012 if (r != row + span - 1)
1013 h += interRowSpace(r + 1);
1020 bool Tabular::updateColumnWidths()
1022 vector<int> max_dwidth(ncols(), 0);
1023 for(col_type c = 0; c < ncols(); ++c)
1024 for(row_type r = 0; r < nrows(); ++r) {
1025 idx_type const i = cellIndex(r, c);
1026 if (getAlignment(i) == LYX_ALIGN_DECIMAL)
1027 max_dwidth[c] = max(max_dwidth[c], cell_info[r][c].decimal_width);
1030 bool update = false;
1031 // for each col get max of single col cells
1032 for(col_type c = 0; c < ncols(); ++c) {
1034 for(row_type r = 0; r < nrows(); ++r) {
1035 idx_type const i = cellIndex(r, c);
1036 if (columnSpan(i) == 1) {
1037 if (getAlignment(i) == LYX_ALIGN_DECIMAL
1038 && cell_info[r][c].decimal_width != 0)
1039 new_width = max(new_width, cellInfo(i).width
1040 + max_dwidth[c] - cellInfo(i).decimal_width);
1042 new_width = max(new_width, cellInfo(i).width);
1046 if (column_info[c].width != new_width) {
1047 column_info[c].width = new_width;
1051 // update col widths to fit merged cells
1052 for(col_type c = 0; c < ncols(); ++c)
1053 for(row_type r = 0; r < nrows(); ++r) {
1054 idx_type const i = cellIndex(r, c);
1055 int const span = columnSpan(i);
1056 if (span == 1 || c > cellColumn(i))
1060 for(col_type j = c; j < c + span ; ++j)
1061 old_width += column_info[j].width;
1063 if (cellInfo(i).width > old_width) {
1064 column_info[c + span - 1].width += cellInfo(i).width - old_width;
1073 int Tabular::width() const
1076 for (col_type c = 0; c < ncols(); ++c)
1077 width += column_info[c].width;
1082 void Tabular::setAlignment(idx_type cell, LyXAlignment align,
1085 col_type const col = cellColumn(cell);
1086 // set alignment for the whole row if we are not in a multicolumn cell,
1087 // exclude possible multicolumn cells in the row
1088 if (!isMultiColumn(cell)) {
1089 for (row_type r = 0; r < nrows(); ++r) {
1090 // only if the column has no width the multirow inherits the
1091 // alignment of the column, otherwise it is left aligned
1092 if (!(isMultiRow(cellIndex(r, col)) && has_width)
1093 && !isMultiColumn(cellIndex(r, col))) {
1094 cell_info[r][col].alignment = align;
1095 cell_info[r][col].inset->setContentAlignment(align);
1097 if ((isMultiRow(cellIndex(r, col)) && has_width)
1098 && !isMultiColumn(cellIndex(r, col))) {
1099 cell_info[r][col].alignment = LYX_ALIGN_LEFT;
1100 cell_info[r][col].inset->setContentAlignment(LYX_ALIGN_LEFT);
1103 column_info[col].alignment = align;
1104 docstring & dpoint = column_info[col].decimal_point;
1105 if (align == LYX_ALIGN_DECIMAL && dpoint.empty())
1106 dpoint = from_utf8(lyxrc.default_decimal_point);
1108 cellInfo(cell).alignment = align;
1109 cellInset(cell)->setContentAlignment(align);
1114 void Tabular::setVAlignment(idx_type cell, VAlignment align,
1117 if (!isMultiColumn(cell) || onlycolumn)
1118 column_info[cellColumn(cell)].valignment = align;
1120 cellInfo(cell).valignment = align;
1127 * Allow line and paragraph breaks for fixed width cells or disallow them,
1128 * merge cell paragraphs and reset layout to standard for variable width
1131 void toggleFixedWidth(Cursor & cur, InsetTableCell * inset, bool fixedWidth)
1133 inset->toggleFixedWidth(fixedWidth);
1137 // merge all paragraphs to one
1138 BufferParams const & bp = cur.bv().buffer().params();
1139 while (inset->paragraphs().size() > 1)
1140 mergeParagraph(bp, inset->paragraphs(), 0);
1144 // undo information has already been recorded
1145 inset->getText(0)->setLayout(0, cur.lastpit() + 1,
1146 bp.documentClass().plainLayoutName());
1153 void Tabular::setColumnPWidth(Cursor & cur, idx_type cell,
1154 Length const & width)
1156 col_type const c = cellColumn(cell);
1158 column_info[c].p_width = width;
1159 // reset the vertical alignment to top if the fixed width
1160 // is removed or zero because only fixed width columns can
1161 // have a vertical alignment
1162 if (column_info[c].p_width.zero())
1163 column_info[c].valignment = LYX_VALIGN_TOP;
1164 for (row_type r = 0; r < nrows(); ++r) {
1165 idx_type const cidx = cellIndex(r, c);
1166 // because of multicolumns
1167 toggleFixedWidth(cur, cellInset(cidx).get(),
1168 !getPWidth(cidx).zero());
1169 if (isMultiRow(cidx))
1170 setAlignment(cidx, LYX_ALIGN_LEFT, false);
1172 // cur paragraph can become invalid after paragraphs were merged
1173 if (cur.pit() > cur.lastpit())
1174 cur.pit() = cur.lastpit();
1175 // cur position can become invalid after newlines were removed
1176 if (cur.pos() > cur.lastpos())
1177 cur.pos() = cur.lastpos();
1181 bool Tabular::setFixedWidth(row_type r, col_type c)
1183 bool const multicol = cell_info[r][c].multicolumn != CELL_NORMAL;
1184 bool const fixed_width = (!column_info[c].p_width.zero() && !multicol)
1185 || (multicol && !cell_info[r][c].p_width.zero());
1186 cell_info[r][c].inset->toggleFixedWidth(fixed_width);
1191 bool Tabular::setMColumnPWidth(Cursor & cur, idx_type cell,
1192 Length const & width)
1194 if (!isMultiColumn(cell))
1197 cellInfo(cell).p_width = width;
1198 toggleFixedWidth(cur, cellInset(cell).get(), !width.zero());
1199 // cur paragraph can become invalid after paragraphs were merged
1200 if (cur.pit() > cur.lastpit())
1201 cur.pit() = cur.lastpit();
1202 // cur position can become invalid after newlines were removed
1203 if (cur.pos() > cur.lastpos())
1204 cur.pos() = cur.lastpos();
1209 bool Tabular::setMROffset(Cursor &, idx_type cell, Length const & mroffset)
1211 cellInfo(cell).mroffset = mroffset;
1216 void Tabular::setAlignSpecial(idx_type cell, docstring const & special,
1217 Tabular::Feature what)
1219 if (what == SET_SPECIAL_MULTICOLUMN)
1220 cellInfo(cell).align_special = special;
1222 column_info[cellColumn(cell)].align_special = special;
1226 void Tabular::setTopLine(idx_type i, bool line)
1228 cellInfo(i).top_line = line;
1232 void Tabular::setBottomLine(idx_type i, bool line)
1234 cellInfo(i).bottom_line = line;
1238 void Tabular::setLeftLine(idx_type cell, bool line)
1240 cellInfo(cell).left_line = line;
1244 void Tabular::setRightLine(idx_type cell, bool line)
1246 cellInfo(cell).right_line = line;
1249 bool Tabular::rowTopLine(row_type r) const
1251 bool all_rows_set = true;
1252 for (col_type c = 0; all_rows_set && c < ncols(); ++c)
1253 all_rows_set = cellInfo(cellIndex(r, c)).top_line;
1254 return all_rows_set;
1258 bool Tabular::rowBottomLine(row_type r) const
1260 bool all_rows_set = true;
1261 for (col_type c = 0; all_rows_set && c < ncols(); ++c)
1262 all_rows_set = cellInfo(cellIndex(r, c)).bottom_line;
1263 return all_rows_set;
1267 bool Tabular::columnLeftLine(col_type c) const
1274 for (row_type r = 0; r < nrows(); ++r) {
1275 idx_type const i = cellIndex(r, c);
1276 if (c == cellColumn(i)) {
1278 bool right = c > 0 && cellInfo(cellIndex(r, c - 1)).right_line;
1279 if (cellInfo(i).left_line || right)
1283 return 2 * nrows_left >= total;
1287 bool Tabular::columnRightLine(col_type c) const
1292 int nrows_right = 0;
1294 for (row_type r = 0; r < nrows(); ++r) {
1295 idx_type i = cellIndex(r, c);
1296 if (c == cellColumn(i) + columnSpan(i) - 1) {
1298 bool left = (c + 1 < ncols()
1299 && cellInfo(cellIndex(r, c + 1)).left_line)
1300 || c + 1 == ncols();
1301 if (cellInfo(i).right_line && left)
1305 return 2 * nrows_right >= total;
1309 LyXAlignment Tabular::getAlignment(idx_type cell, bool onlycolumn) const
1311 if (!onlycolumn && (isMultiColumn(cell) || isMultiRow(cell)))
1312 return cellInfo(cell).alignment;
1314 return column_info[cellColumn(cell)].alignment;
1319 Tabular::getVAlignment(idx_type cell, bool onlycolumn) const
1321 if (!onlycolumn && (isMultiColumn(cell) || isMultiRow(cell)))
1322 return cellInfo(cell).valignment;
1323 return column_info[cellColumn(cell)].valignment;
1327 int Tabular::offsetVAlignment() const
1329 // for top-alignment the first horizontal table line must be exactly at
1330 // the position of the base line of the surrounding text line
1331 // for bottom alignment, the same is for the last table line
1332 int offset_valign = 0;
1333 switch (tabular_valignment) {
1334 case Tabular::LYX_VALIGN_BOTTOM:
1335 offset_valign = rowAscent(0) - height();
1337 case Tabular::LYX_VALIGN_MIDDLE:
1338 offset_valign = (- height()) / 2 + rowAscent(0);
1340 case Tabular::LYX_VALIGN_TOP:
1341 offset_valign = rowAscent(0);
1344 return offset_valign;
1348 Length const Tabular::getPWidth(idx_type cell) const
1350 if (isMultiColumn(cell))
1351 return cellInfo(cell).p_width;
1352 return column_info[cellColumn(cell)].p_width;
1356 Length const Tabular::getMROffset(idx_type cell) const
1358 return cellInfo(cell).mroffset;
1362 int Tabular::textHOffset(idx_type cell) const
1364 // the LaTeX Way :-(
1365 int x = WIDTH_OF_LINE;
1367 int const w = cellWidth(cell) - cellInfo(cell).width;
1369 switch (getAlignment(cell)) {
1370 case LYX_ALIGN_CENTER:
1373 case LYX_ALIGN_RIGHT:
1376 case LYX_ALIGN_DECIMAL: {
1377 // we center when no decimal point
1378 if (cellInfo(cell).decimal_width == 0) {
1382 col_type const c = cellColumn(cell);
1383 int max_dhoffset = 0;
1384 for(row_type r = 0; r < row_info.size() ; ++r) {
1385 idx_type const i = cellIndex(r, c);
1386 if (getAlignment(i) == LYX_ALIGN_DECIMAL
1387 && cellInfo(i).decimal_width != 0)
1388 max_dhoffset = max(max_dhoffset, cellInfo(i).decimal_hoffset);
1390 x += max_dhoffset - cellInfo(cell).decimal_hoffset;
1393 // LYX_ALIGN_LEFT: nothing :-)
1401 int Tabular::textVOffset(idx_type cell) const
1403 int voffset = cellInfo(cell).voffset;
1404 if (isMultiRow(cell)) {
1405 row_type const row = cellRow(cell);
1406 voffset += (cellHeight(cell) - rowAscent(row) - rowDescent(row))/2;
1412 Tabular::idx_type Tabular::getFirstCellInRow(row_type row) const
1415 idx_type const numcells = numberOfCellsInRow(row);
1416 // we check against numcells to make sure we do not crash if all the
1417 // cells are multirow (bug #7535), but in that case our return value
1418 // is really invalid, i.e., it is NOT the first cell in the row. but
1419 // i do not know what to do here. (rgh)
1420 while (c < numcells - 1
1421 && cell_info[row][c].multirow == CELL_PART_OF_MULTIROW)
1423 return cell_info[row][c].cellno;
1427 Tabular::idx_type Tabular::getLastCellInRow(row_type row) const
1429 col_type c = ncols() - 1;
1430 // of course we check against 0 so we don't crash. but we have the same
1431 // problem as in the previous routine: if all the cells are part of a
1432 // multirow or part of a multi column, then our return value is invalid.
1434 && (cell_info[row][c].multirow == CELL_PART_OF_MULTIROW
1435 || cell_info[row][c].multicolumn == CELL_PART_OF_MULTICOLUMN))
1437 return cell_info[row][c].cellno;
1441 Tabular::row_type Tabular::cellRow(idx_type cell) const
1443 if (cell >= numberofcells)
1447 return rowofcell[cell];
1451 Tabular::col_type Tabular::cellColumn(idx_type cell) const
1453 if (cell >= numberofcells)
1457 return columnofcell[cell];
1461 void Tabular::write(ostream & os) const
1465 << write_attribute("version", 3)
1466 << write_attribute("rows", nrows())
1467 << write_attribute("columns", ncols())
1469 // global longtable options
1471 << write_attribute("rotate", rotate)
1472 << write_attribute("booktabs", use_booktabs)
1473 << write_attribute("islongtable", is_long_tabular)
1474 << write_attribute("firstHeadTopDL", endfirsthead.topDL)
1475 << write_attribute("firstHeadBottomDL", endfirsthead.bottomDL)
1476 << write_attribute("firstHeadEmpty", endfirsthead.empty)
1477 << write_attribute("headTopDL", endhead.topDL)
1478 << write_attribute("headBottomDL", endhead.bottomDL)
1479 << write_attribute("footTopDL", endfoot.topDL)
1480 << write_attribute("footBottomDL", endfoot.bottomDL)
1481 << write_attribute("lastFootTopDL", endlastfoot.topDL)
1482 << write_attribute("lastFootBottomDL", endlastfoot.bottomDL)
1483 << write_attribute("lastFootEmpty", endlastfoot.empty);
1484 // longtables cannot be aligned vertically
1485 if (!is_long_tabular) {
1486 os << write_attribute("tabularvalignment", tabular_valignment);
1487 os << write_attribute("tabularwidth", tabular_width);
1489 if (is_long_tabular)
1490 os << write_attribute("longtabularalignment", longtabular_alignment);
1492 for (col_type c = 0; c < ncols(); ++c) {
1494 << write_attribute("alignment", column_info[c].alignment);
1495 if (column_info[c].alignment == LYX_ALIGN_DECIMAL)
1496 os << write_attribute("decimal_point", column_info[c].decimal_point);
1497 os << write_attribute("valignment", column_info[c].valignment)
1498 << write_attribute("width", column_info[c].p_width.asString())
1499 << write_attribute("special", column_info[c].align_special)
1502 for (row_type r = 0; r < nrows(); ++r) {
1503 static const string def("default");
1505 if (row_info[r].top_space_default)
1506 os << write_attribute("topspace", def);
1508 os << write_attribute("topspace", row_info[r].top_space);
1509 if (row_info[r].bottom_space_default)
1510 os << write_attribute("bottomspace", def);
1512 os << write_attribute("bottomspace", row_info[r].bottom_space);
1513 if (row_info[r].interline_space_default)
1514 os << write_attribute("interlinespace", def);
1516 os << write_attribute("interlinespace", row_info[r].interline_space);
1517 os << write_attribute("endhead", row_info[r].endhead)
1518 << write_attribute("endfirsthead", row_info[r].endfirsthead)
1519 << write_attribute("endfoot", row_info[r].endfoot)
1520 << write_attribute("endlastfoot", row_info[r].endlastfoot)
1521 << write_attribute("newpage", row_info[r].newpage)
1522 << write_attribute("caption", row_info[r].caption)
1524 for (col_type c = 0; c < ncols(); ++c) {
1526 << write_attribute("multicolumn", cell_info[r][c].multicolumn)
1527 << write_attribute("multirow", cell_info[r][c].multirow)
1528 << write_attribute("mroffset", cell_info[r][c].mroffset)
1529 << write_attribute("alignment", cell_info[r][c].alignment)
1530 << write_attribute("valignment", cell_info[r][c].valignment)
1531 << write_attribute("topline", cell_info[r][c].top_line)
1532 << write_attribute("bottomline", cell_info[r][c].bottom_line)
1533 << write_attribute("leftline", cell_info[r][c].left_line)
1534 << write_attribute("rightline", cell_info[r][c].right_line)
1535 << write_attribute("rotate", cell_info[r][c].rotate)
1536 << write_attribute("usebox", cell_info[r][c].usebox)
1537 << write_attribute("width", cell_info[r][c].p_width)
1538 << write_attribute("special", cell_info[r][c].align_special)
1540 os << "\\begin_inset ";
1541 cell_info[r][c].inset->write(os);
1542 os << "\n\\end_inset\n"
1544 // FIXME This can be removed again once the mystery
1545 // crash has been resolved.
1550 os << "</lyxtabular>\n";
1554 void Tabular::read(Lexer & lex)
1557 istream & is = lex.getStream();
1559 l_getline(is, line);
1560 if (!prefixIs(line, "<lyxtabular ") && !prefixIs(line, "<Tabular ")) {
1561 LASSERT(false, return);
1565 if (!getTokenValue(line, "version", version))
1567 LATTEST(version >= 2);
1570 if (!getTokenValue(line, "rows", rows_arg))
1573 if (!getTokenValue(line, "columns", columns_arg))
1575 init(buffer_, rows_arg, columns_arg);
1576 l_getline(is, line);
1577 if (!prefixIs(line, "<features")) {
1578 lyxerr << "Wrong tabular format (expected <features ...> got"
1579 << line << ')' << endl;
1582 getTokenValue(line, "rotate", rotate);
1583 getTokenValue(line, "booktabs", use_booktabs);
1584 getTokenValue(line, "islongtable", is_long_tabular);
1585 getTokenValue(line, "tabularvalignment", tabular_valignment);
1586 getTokenValue(line, "tabularwidth", tabular_width);
1587 getTokenValue(line, "longtabularalignment", longtabular_alignment);
1588 getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
1589 getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
1590 getTokenValue(line, "firstHeadEmpty", endfirsthead.empty);
1591 getTokenValue(line, "headTopDL", endhead.topDL);
1592 getTokenValue(line, "headBottomDL", endhead.bottomDL);
1593 getTokenValue(line, "footTopDL", endfoot.topDL);
1594 getTokenValue(line, "footBottomDL", endfoot.bottomDL);
1595 getTokenValue(line, "lastFootTopDL", endlastfoot.topDL);
1596 getTokenValue(line, "lastFootBottomDL", endlastfoot.bottomDL);
1597 getTokenValue(line, "lastFootEmpty", endlastfoot.empty);
1599 for (col_type c = 0; c < ncols(); ++c) {
1601 if (!prefixIs(line,"<column")) {
1602 lyxerr << "Wrong tabular format (expected <column ...> got"
1603 << line << ')' << endl;
1606 getTokenValue(line, "alignment", column_info[c].alignment);
1607 getTokenValue(line, "decimal_point", column_info[c].decimal_point);
1608 getTokenValue(line, "valignment", column_info[c].valignment);
1609 getTokenValue(line, "width", column_info[c].p_width);
1610 getTokenValue(line, "special", column_info[c].align_special);
1613 for (row_type i = 0; i < nrows(); ++i) {
1614 l_getline(is, line);
1615 if (!prefixIs(line, "<row")) {
1616 lyxerr << "Wrong tabular format (expected <row ...> got"
1617 << line << ')' << endl;
1620 getTokenValue(line, "topspace", row_info[i].top_space,
1621 row_info[i].top_space_default);
1622 getTokenValue(line, "bottomspace", row_info[i].bottom_space,
1623 row_info[i].bottom_space_default);
1624 getTokenValue(line, "interlinespace", row_info[i].interline_space,
1625 row_info[i].interline_space_default);
1626 getTokenValue(line, "endfirsthead", row_info[i].endfirsthead);
1627 getTokenValue(line, "endhead", row_info[i].endhead);
1628 getTokenValue(line, "endfoot", row_info[i].endfoot);
1629 getTokenValue(line, "endlastfoot", row_info[i].endlastfoot);
1630 getTokenValue(line, "newpage", row_info[i].newpage);
1631 getTokenValue(line, "caption", row_info[i].caption);
1632 for (col_type j = 0; j < ncols(); ++j) {
1633 l_getline(is, line);
1634 if (!prefixIs(line, "<cell")) {
1635 lyxerr << "Wrong tabular format (expected <cell ...> got"
1636 << line << ')' << endl;
1639 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1640 getTokenValue(line, "multirow", cell_info[i][j].multirow);
1641 getTokenValue(line, "mroffset", cell_info[i][j].mroffset);
1642 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1643 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1644 getTokenValue(line, "topline", cell_info[i][j].top_line);
1645 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1646 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1647 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1648 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1649 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1650 getTokenValue(line, "width", cell_info[i][j].p_width);
1652 getTokenValue(line, "special", cell_info[i][j].align_special);
1653 l_getline(is, line);
1654 if (prefixIs(line, "\\begin_inset")) {
1655 cell_info[i][j].inset->setBuffer(*buffer_);
1656 cell_info[i][j].inset->read(lex);
1657 l_getline(is, line);
1659 if (!prefixIs(line, "</cell>")) {
1660 lyxerr << "Wrong tabular format (expected </cell> got"
1661 << line << ')' << endl;
1665 l_getline(is, line);
1666 if (!prefixIs(line, "</row>")) {
1667 lyxerr << "Wrong tabular format (expected </row> got"
1668 << line << ')' << endl;
1672 while (!prefixIs(line, "</lyxtabular>")) {
1673 l_getline(is, line);
1679 bool Tabular::isMultiColumn(idx_type cell) const
1681 return (cellInfo(cell).multicolumn == CELL_BEGIN_OF_MULTICOLUMN
1682 || cellInfo(cell).multicolumn == CELL_PART_OF_MULTICOLUMN);
1686 bool Tabular::hasMultiColumn(col_type c) const
1688 for (row_type r = 0; r < nrows(); ++r) {
1689 if (isMultiColumn(cellIndex(r, c)))
1696 Tabular::CellData const & Tabular::cellInfo(idx_type cell) const
1698 return cell_info[cellRow(cell)][cellColumn(cell)];
1702 Tabular::CellData & Tabular::cellInfo(idx_type cell)
1704 return cell_info[cellRow(cell)][cellColumn(cell)];
1708 Tabular::idx_type Tabular::setMultiColumn(idx_type cell, idx_type number,
1709 bool const right_border)
1711 idx_type const col = cellColumn(cell);
1712 idx_type const row = cellRow(cell);
1713 for (idx_type i = 0; i < number; ++i)
1714 unsetMultiRow(cellIndex(row, col + i));
1716 // unsetting of multirow may have invalidated cell index
1717 cell = cellIndex(row, col);
1718 CellData & cs = cellInfo(cell);
1719 cs.multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1720 if (column_info[col].alignment != LYX_ALIGN_DECIMAL)
1721 cs.alignment = column_info[col].alignment;
1722 setRightLine(cell, right_border);
1724 idx_type lastcell = cellIndex(row, col + number - 1);
1725 for (idx_type i = 1; i < lastcell - cell + 1; ++i) {
1726 CellData & cs1 = cellInfo(cell + i);
1727 cs1.multicolumn = CELL_PART_OF_MULTICOLUMN;
1728 cs.inset->appendParagraphs(cs1.inset->paragraphs());
1736 bool Tabular::isMultiRow(idx_type cell) const
1738 return (cellInfo(cell).multirow == CELL_BEGIN_OF_MULTIROW
1739 || cellInfo(cell).multirow == CELL_PART_OF_MULTIROW);
1742 bool Tabular::hasMultiRow(row_type r) const
1744 for (col_type c = 0; c < ncols(); ++c) {
1745 if (isMultiRow(cellIndex(r, c)))
1751 Tabular::idx_type Tabular::setMultiRow(idx_type cell, idx_type number,
1752 bool const bottom_border,
1753 LyXAlignment const halign)
1755 idx_type const col = cellColumn(cell);
1756 idx_type const row = cellRow(cell);
1757 for (idx_type i = 0; i < number; ++i)
1758 unsetMultiColumn(cellIndex(row + i, col));
1760 // unsetting of multirow may have invalidated cell index
1761 cell = cellIndex(row, col);
1762 CellData & cs = cellInfo(cell);
1763 cs.multirow = CELL_BEGIN_OF_MULTIROW;
1764 cs.valignment = LYX_VALIGN_MIDDLE;
1765 // the horizontal alignment of multirow cells can only
1766 // be changed for the whole table row,
1767 // support changing this only for the multirow cell can be done via
1769 if (getPWidth(cell).zero())
1770 cs.alignment = halign;
1772 cs.alignment = LYX_ALIGN_LEFT;
1774 // set the bottom line of the last selected cell
1775 setBottomLine(cell, bottom_border);
1777 for (idx_type i = 1; i < number; ++i) {
1778 CellData & cs1 = cell_info[row + i][col];
1779 cs1.multirow = CELL_PART_OF_MULTIROW;
1780 cs.inset->appendParagraphs(cs1.inset->paragraphs());
1788 Tabular::idx_type Tabular::columnSpan(idx_type cell) const
1790 row_type const row = cellRow(cell);
1791 col_type const col = cellColumn(cell);
1793 while (col + span < ncols() && isPartOfMultiColumn(row, col + span))
1800 Tabular::idx_type Tabular::rowSpan(idx_type cell) const
1802 col_type const column = cellColumn(cell);
1803 col_type row = cellRow(cell) + 1;
1804 while (row < nrows() && isPartOfMultiRow(row, column))
1807 return row - cellRow(cell);
1811 void Tabular::unsetMultiColumn(idx_type cell)
1813 if (!isMultiColumn(cell))
1816 row_type const row = cellRow(cell);
1817 col_type const col = cellColumn(cell);
1818 row_type const span = columnSpan(cell);
1819 for (col_type c = 0; c < span; ++c) {
1820 // in the table dialog the lines are set in every case
1821 // when unsetting a multicolumn this leads to an additional right
1822 // line for every cell that was part of the former multicolumn cell,
1823 // except if the cell is in the last column
1824 // therefore remove this line
1825 if (cell_info[row][col + c].multicolumn == CELL_BEGIN_OF_MULTICOLUMN
1826 && (col + c) < (col + span - 1))
1827 cell_info[row][col + c].right_line = false;
1828 cell_info[row][col + c].multicolumn = CELL_NORMAL;
1834 void Tabular::unsetMultiRow(idx_type cell)
1836 if (!isMultiRow(cell))
1839 cellInfo(cell).valignment = LYX_VALIGN_TOP;
1840 cellInfo(cell).alignment = LYX_ALIGN_CENTER;
1841 row_type const row = cellRow(cell);
1842 col_type const col = cellColumn(cell);
1843 row_type const span = rowSpan(cell);
1844 for (row_type r = 0; r < span; ++r)
1845 cell_info[row + r][col].multirow = CELL_NORMAL;
1850 void Tabular::setRotateCell(idx_type cell, int value)
1852 cellInfo(cell).rotate = value;
1856 int Tabular::getRotateCell(idx_type cell) const
1858 return cellInfo(cell).rotate;
1862 bool Tabular::needRotating() const
1864 if (rotate && !is_long_tabular)
1866 for (row_type r = 0; r < nrows(); ++r)
1867 for (col_type c = 0; c < ncols(); ++c)
1868 if (cell_info[r][c].rotate != 0)
1874 bool Tabular::isLastCell(idx_type cell) const
1876 if (cell + 1 < numberofcells)
1882 Tabular::idx_type Tabular::cellAbove(idx_type cell) const
1884 if (cellRow(cell) == 0)
1887 col_type const col = cellColumn(cell);
1888 row_type r = cellRow(cell) - 1;
1889 while (r > 0 && cell_info[r][col].multirow == CELL_PART_OF_MULTIROW)
1892 return cell_info[r][col].cellno;
1896 Tabular::idx_type Tabular::cellBelow(idx_type cell) const
1898 row_type const nextrow = cellRow(cell) + rowSpan(cell);
1899 if (nextrow < nrows())
1900 return cell_info[nextrow][cellColumn(cell)].cellno;
1905 Tabular::idx_type Tabular::cellIndex(row_type row, col_type column) const
1907 LASSERT(column != npos && column < ncols(), column = 0);
1908 LASSERT(row != npos && row < nrows(), row = 0);
1909 return cell_info[row][column].cellno;
1913 void Tabular::setUsebox(idx_type cell, BoxType type)
1915 cellInfo(cell).usebox = type;
1919 // FIXME: Remove this routine because we cannot insert \parboxes when the user
1920 // adds line breaks, see bug 4886.
1921 Tabular::BoxType Tabular::getUsebox(idx_type cell) const
1923 if ((!column_info[cellColumn(cell)].p_width.zero() && !isMultiColumn(cell)) ||
1924 (isMultiColumn(cell) && !cellInfo(cell).p_width.zero()))
1926 if (cellInfo(cell).usebox > 1)
1927 return cellInfo(cell).usebox;
1928 return useParbox(cell);
1933 // This are functions used for the longtable support
1935 void Tabular::setLTHead(row_type row, bool flag, ltType const & hd,
1941 row_info[row].endfirsthead = flag;
1945 row_info[row].endhead = flag;
1950 bool Tabular::getRowOfLTHead(row_type row, ltType & hd) const
1953 hd.set = haveLTHead();
1954 return row_info[row].endhead;
1958 bool Tabular::getRowOfLTFirstHead(row_type row, ltType & hd) const
1961 hd.set = haveLTFirstHead();
1962 return row_info[row].endfirsthead;
1966 void Tabular::setLTFoot(row_type row, bool flag, ltType const & fd,
1972 row_info[row].endlastfoot = flag;
1976 row_info[row].endfoot = flag;
1981 bool Tabular::getRowOfLTFoot(row_type row, ltType & fd) const
1984 fd.set = haveLTFoot();
1985 return row_info[row].endfoot;
1989 bool Tabular::getRowOfLTLastFoot(row_type row, ltType & fd) const
1992 fd.set = haveLTLastFoot();
1993 return row_info[row].endlastfoot;
1997 void Tabular::setLTNewPage(row_type row, bool what)
1999 row_info[row].newpage = what;
2003 bool Tabular::getLTNewPage(row_type row) const
2005 return row_info[row].newpage;
2009 bool Tabular::haveLTHead(bool withcaptions) const
2011 if (!is_long_tabular)
2013 for (row_type i = 0; i < nrows(); ++i)
2014 if (row_info[i].endhead &&
2015 (withcaptions || !row_info[i].caption))
2021 bool Tabular::haveLTFirstHead(bool withcaptions) const
2023 if (!is_long_tabular || endfirsthead.empty)
2025 for (row_type r = 0; r < nrows(); ++r)
2026 if (row_info[r].endfirsthead &&
2027 (withcaptions || !row_info[r].caption))
2033 bool Tabular::haveLTFoot(bool withcaptions) const
2035 if (!is_long_tabular)
2037 for (row_type r = 0; r < nrows(); ++r)
2038 if (row_info[r].endfoot &&
2039 (withcaptions || !row_info[r].caption))
2045 bool Tabular::haveLTLastFoot(bool withcaptions) const
2047 if (!is_long_tabular || endlastfoot.empty)
2049 for (row_type r = 0; r < nrows(); ++r)
2050 if (row_info[r].endlastfoot &&
2051 (withcaptions || !row_info[r].caption))
2057 Tabular::idx_type Tabular::setLTCaption(row_type row, bool what)
2059 idx_type i = getFirstCellInRow(row);
2061 setMultiColumn(i, numberOfCellsInRow(row), false);
2062 setTopLine(i, false);
2063 setBottomLine(i, false);
2064 setLeftLine(i, false);
2065 setRightLine(i, false);
2066 if (!row_info[row].endfirsthead && !row_info[row].endhead &&
2067 !row_info[row].endfoot && !row_info[row].endlastfoot) {
2068 setLTHead(row, true, endfirsthead, true);
2069 row_info[row].endfirsthead = true;
2072 unsetMultiColumn(i);
2073 // When unsetting a caption row, also all existing
2074 // captions in this row must be dissolved.
2076 row_info[row].caption = what;
2081 bool Tabular::ltCaption(row_type row) const
2083 return row_info[row].caption;
2087 bool Tabular::haveLTCaption(CaptionType captiontype) const
2089 if (!is_long_tabular)
2091 for (row_type r = 0; r < nrows(); ++r) {
2092 if (row_info[r].caption) {
2093 switch (captiontype) {
2094 case CAPTION_FIRSTHEAD:
2095 if (row_info[r].endfirsthead)
2099 if (row_info[r].endhead)
2103 if (row_info[r].endfoot)
2106 case CAPTION_LASTFOOT:
2107 if (row_info[r].endlastfoot)
2119 // end longtable support functions
2121 void Tabular::setRowAscent(row_type row, int height)
2123 if (row >= nrows() || row_info[row].ascent == height)
2125 row_info[row].ascent = height;
2129 void Tabular::setRowDescent(row_type row, int height)
2131 if (row >= nrows() || row_info[row].descent == height)
2133 row_info[row].descent = height;
2137 int Tabular::rowAscent(row_type row) const
2139 LASSERT(row < nrows(), row = 0);
2140 return row_info[row].ascent;
2144 int Tabular::rowDescent(row_type row) const
2146 LASSERT(row < nrows(), row = 0);
2147 return row_info[row].descent;
2151 int Tabular::height() const
2154 for (row_type row = 0; row < nrows(); ++row)
2155 height += rowAscent(row) + rowDescent(row) +
2161 bool Tabular::isPartOfMultiColumn(row_type row, col_type column) const
2163 LASSERT(row < nrows(), return false);
2164 LASSERT(column < ncols(), return false);
2165 return cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN;
2169 bool Tabular::isPartOfMultiRow(row_type row, col_type column) const
2171 LASSERT(row < nrows(), return false);
2172 LASSERT(column < ncols(), return false);
2173 return cell_info[row][column].multirow == CELL_PART_OF_MULTIROW;
2177 void Tabular::TeXTopHLine(otexstream & os, row_type row, string const & lang,
2178 list<col_type> columns) const
2180 // we only output complete row lines and the 1st row here, the rest
2181 // is done in Tabular::TeXBottomHLine(...)
2183 // get for each column the topline (if any)
2184 map<col_type, bool> topline;
2186 for (auto const & c : columns) {
2187 topline[c] = topLine(cellIndex(row, c));
2188 // If cell is part of a multirow and not the first cell of the
2189 // multirow, no line must be drawn.
2191 if (isMultiRow(cellIndex(row, c))
2192 && cell_info[row][c].multirow != CELL_BEGIN_OF_MULTIROW)
2194 if (topline.find(c) != topline.end() && topline.find(c)->second)
2198 // do nothing if empty first row, or incomplete row line after
2199 if ((row == 0 && nset == 0) || (row > 0 && nset != ncols()))
2202 // only output complete row lines and the 1st row's clines
2203 if (nset == ncols()) {
2205 os << (row == 0 ? "\\toprule " : "\\midrule ");
2209 } else if (row == 0) {
2210 for (auto & c : columns) {
2211 if (topline.find(c)->second) {
2212 col_type offset = 0;
2213 for (col_type j = 0 ; j < c; ++j)
2214 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2217 //babel makes the "-" character an active one, so we have to suppress this here
2218 //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
2219 if (lang == "slovak" || lang == "czech")
2220 os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline")
2221 << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
2223 os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
2225 col_type cstart = c;
2226 for ( ; c < ncols() && topline.find(c)->second; ++c) {}
2228 for (col_type j = cstart ; j < c ; ++j)
2229 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2232 os << c + offset << "} ";
2240 void Tabular::TeXBottomHLine(otexstream & os, row_type row, string const & lang,
2241 list<col_type> columns) const
2243 // we output bottomlines of row r and the toplines of row r+1
2244 // if the latter do not span the whole tabular
2246 // get the bottomlines of row r, and toplines in next row
2247 bool lastrow = row == nrows() - 1;
2248 map<col_type, bool> bottomline, topline;
2249 bool nextrowset = true;
2250 for (auto const & c : columns) {
2251 bottomline[c] = bottomLine(cellIndex(row, c));
2252 topline[c] = !lastrow && topLine(cellIndex(row + 1, c));
2253 // If cell is part of a multirow and not the last cell of the
2254 // multirow, no line must be drawn.
2256 if (isMultiRow(cellIndex(row, c))
2257 && isMultiRow(cellIndex(row + 1, c))
2258 && cell_info[row + 1][c].multirow != CELL_BEGIN_OF_MULTIROW) {
2259 bottomline[c] = false;
2262 nextrowset &= topline.find(c) != topline.end() && topline.find(c)->second;
2265 // combine this row's bottom lines and next row's toplines if necessary
2267 for (auto const & c : columns) {
2269 bottomline[c] = bottomline.find(c)->second || topline.find(c)->second;
2270 if (bottomline.find(c)->second)
2274 // do nothing if empty, OR incomplete row line with a topline in next row
2275 if (nset == 0 || (nextrowset && nset != ncols()))
2278 if (nset == ncols()) {
2280 os << (lastrow ? "\\bottomrule" : "\\midrule");
2284 for (auto & c : columns) {
2285 if (bottomline.find(c)->second) {
2286 col_type offset = 0;
2287 for (col_type j = 0 ; j < c; ++j)
2288 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2291 //babel makes the "-" character an active one, so we have to suppress this here
2292 //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
2293 if (lang == "slovak" || lang == "czech")
2294 os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline")
2295 << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
2297 os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
2299 col_type cstart = c;
2300 for ( ; c < ncols() && bottomline.find(c)->second; ++c) {}
2302 for (col_type j = cstart ; j < c ; ++j)
2303 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2306 os << c + offset << "} ";
2314 void Tabular::TeXCellPreamble(otexstream & os, idx_type cell,
2315 bool & ismulticol, bool & ismultirow,
2316 bool const bidi) const
2318 row_type const r = cellRow(cell);
2319 if (is_long_tabular && row_info[r].caption)
2322 Tabular::VAlignment valign = getVAlignment(cell, !isMultiColumn(cell));
2323 LyXAlignment align = getAlignment(cell, !isMultiColumn(cell));
2324 // figure out how to set the lines
2325 // we always set double lines to the right of the cell
2326 // or left in bidi RTL, respectively.
2327 col_type const c = cellColumn(cell);
2328 col_type const nextcol = c + columnSpan(cell);
2329 bool const decimal = column_info[c].alignment == LYX_ALIGN_DECIMAL;
2330 bool colright = columnRightLine(c);
2331 bool colleft = columnLeftLine(c);
2332 bool nextcolleft = nextcol < ncols() && columnLeftLine(nextcol);
2333 bool nextcellleft = nextcol < ncols()
2334 && leftLine(cellIndex(r, nextcol));
2335 bool coldouble = colright && nextcolleft;
2336 bool celldouble = rightLine(cell) && nextcellleft;
2338 ismulticol = (isMultiColumn(cell)
2339 || (c == 0 && colleft != leftLine(cell))
2340 || ((colright || nextcolleft) && !rightLine(cell) && !nextcellleft)
2341 || (!colright && !nextcolleft && (rightLine(cell) || nextcellleft))
2342 || (coldouble != celldouble))
2345 // we center in multicol when no decimal point
2347 docstring const align_d = column_info[c].decimal_point;
2348 DocIterator const dit = separatorPos(cellInset(cell), align_d);
2349 bool const nosep = !dit;
2350 ismulticol |= nosep;
2351 celldouble &= nosep;
2354 // up counter by 1 for each decimally aligned col since they use 2 latex cols
2355 int latexcolspan = columnSpan(cell);
2356 for (col_type col = c; col < c + columnSpan(cell); ++col)
2357 if (column_info[col].alignment == LYX_ALIGN_DECIMAL)
2361 os << "\\multicolumn{" << latexcolspan << "}{";
2362 if (((bidi && c == getLastCellInRow(cellRow(0)) && rightLine(cell))
2363 || (!bidi && c == 0 && leftLine(cell))))
2365 if (bidi && celldouble)
2366 // add extra vertical line if we want a double one
2368 if (!cellInfo(cell).align_special.empty()) {
2369 os << cellInfo(cell).align_special;
2371 if (!getPWidth(cell).zero()) {
2373 case LYX_ALIGN_LEFT:
2374 os << ">{\\raggedright}";
2376 case LYX_ALIGN_RIGHT:
2377 os << ">{\\raggedleft}";
2379 case LYX_ALIGN_CENTER:
2380 os << ">{\\centering}";
2386 case LYX_VALIGN_TOP:
2389 case LYX_VALIGN_MIDDLE:
2392 case LYX_VALIGN_BOTTOM:
2397 << from_ascii(getPWidth(cell).asLatexString())
2401 case LYX_ALIGN_LEFT:
2404 case LYX_ALIGN_RIGHT:
2411 } // end if else !getPWidth
2412 } // end if else !cellinfo_of_cell
2413 if ((bidi && leftLine(cell)) || (!bidi && rightLine(cell)) || nextcellleft)
2415 if (!bidi && celldouble)
2416 // add extra vertical line if we want a double one
2419 } // end if ismulticol
2421 // we only need code for the first multirow cell
2422 ismultirow = isMultiRow(cell);
2424 os << "\\multirow{" << rowSpan(cell) << "}{";
2425 if (!getPWidth(cell).zero())
2426 os << from_ascii(getPWidth(cell).asLatexString());
2428 // we need to set a default value
2431 if (!getMROffset(cell).zero())
2432 os << "[" << from_ascii(getMROffset(cell).asLatexString()) << "]";
2434 } // end if ismultirow
2436 if (getRotateCell(cell) != 0)
2437 os << "\\begin{turn}{" << convert<string>(getRotateCell(cell)) << "}\n";
2439 if (getUsebox(cell) == BOX_PARBOX) {
2442 case LYX_VALIGN_TOP:
2445 case LYX_VALIGN_MIDDLE:
2448 case LYX_VALIGN_BOTTOM:
2452 os << "]{" << from_ascii(getPWidth(cell).asLatexString())
2454 } else if (getUsebox(cell) == BOX_MINIPAGE) {
2455 os << "\\begin{minipage}[";
2457 case LYX_VALIGN_TOP:
2460 case LYX_VALIGN_MIDDLE:
2463 case LYX_VALIGN_BOTTOM:
2467 os << "]{" << from_ascii(getPWidth(cell).asLatexString())
2473 void Tabular::TeXCellPostamble(otexstream & os, idx_type cell,
2474 bool ismulticol, bool ismultirow) const
2476 row_type const r = cellRow(cell);
2477 if (is_long_tabular && row_info[r].caption)
2481 if (getUsebox(cell) == BOX_PARBOX)
2483 else if (getUsebox(cell) == BOX_MINIPAGE)
2484 os << breakln << "\\end{minipage}";
2485 if (getRotateCell(cell) != 0)
2486 os << breakln << "\\end{turn}";
2494 void Tabular::TeXLongtableHeaderFooter(otexstream & os,
2495 OutputParams const & runparams,
2496 list<col_type> columns) const
2498 if (!is_long_tabular)
2502 // output caption which is in no header or footer
2503 if (haveLTCaption()) {
2504 for (row_type r = 0; r < nrows(); ++r) {
2505 if (row_info[r].caption &&
2506 !row_info[r].endfirsthead && !row_info[r].endhead &&
2507 !row_info[r].endfoot && !row_info[r].endlastfoot)
2508 TeXRow(os, r, runparams, columns);
2511 // output first header info
2512 if (haveLTFirstHead()) {
2513 if (endfirsthead.topDL)
2515 for (row_type r = 0; r < nrows(); ++r) {
2516 if (row_info[r].endfirsthead)
2517 TeXRow(os, r, runparams, columns);
2519 if (endfirsthead.bottomDL)
2521 os << "\\endfirsthead\n";
2523 // output header info
2525 if (endfirsthead.empty && !haveLTFirstHead())
2526 os << "\\endfirsthead\n";
2529 for (row_type r = 0; r < nrows(); ++r) {
2530 if (row_info[r].endhead)
2531 TeXRow(os, r, runparams, columns);
2533 if (endhead.bottomDL)
2535 os << "\\endhead\n";
2537 // output footer info
2541 for (row_type r = 0; r < nrows(); ++r) {
2542 if (row_info[r].endfoot)
2543 TeXRow(os, r, runparams, columns);
2545 if (endfoot.bottomDL)
2547 os << "\\endfoot\n";
2548 if (endlastfoot.empty && !haveLTLastFoot())
2549 os << "\\endlastfoot\n";
2551 // output lastfooter info
2552 if (haveLTLastFoot()) {
2553 if (endlastfoot.topDL)
2555 for (row_type r = 0; r < nrows(); ++r) {
2556 if (row_info[r].endlastfoot)
2557 TeXRow(os, r, runparams, columns);
2559 if (endlastfoot.bottomDL)
2561 os << "\\endlastfoot\n";
2566 bool Tabular::isValidRow(row_type row) const
2568 if (!is_long_tabular)
2570 return !row_info[row].endhead && !row_info[row].endfirsthead
2571 && !row_info[row].endfoot && !row_info[row].endlastfoot
2572 && !row_info[row].caption;
2576 void Tabular::TeXRow(otexstream & os, row_type row,
2577 OutputParams const & runparams,
2578 list<col_type> columns) const
2580 idx_type cell = cellIndex(row, 0);
2581 InsetTableCell const * cinset = cellInset(cell);
2582 Paragraph const & cpar = cinset->paragraphs().front();
2583 string const clang = cpar.getParLanguage(buffer().params())->lang();
2585 //output the top line
2586 TeXTopHLine(os, row, clang, columns);
2588 if (row_info[row].top_space_default) {
2590 os << "\\addlinespace\n";
2592 os << "\\noalign{\\vskip\\doublerulesep}\n";
2593 } else if(!row_info[row].top_space.zero()) {
2595 os << "\\addlinespace["
2596 << from_ascii(row_info[row].top_space.asLatexString())
2599 os << "\\noalign{\\vskip"
2600 << from_ascii(row_info[row].top_space.asLatexString())
2604 bool ismulticol = false;
2605 bool ismultirow = false;
2607 // The bidi package (loaded by polyglossia) reverses RTL table columns
2608 bool const bidi_rtl =
2609 runparams.local_font->isRightToLeft()
2610 && runparams.use_polyglossia;
2612 bidi_rtl ? getFirstCellInRow(row) : getLastCellInRow(row);
2614 for (auto const & c : columns) {
2615 if (isPartOfMultiColumn(row, c))
2618 cell = cellIndex(row, c);
2620 if (isPartOfMultiRow(row, c)
2621 && column_info[c].alignment != LYX_ALIGN_DECIMAL) {
2622 if (cell != lastcell)
2627 TeXCellPreamble(os, cell, ismulticol, ismultirow, bidi_rtl);
2628 InsetTableCell const * inset = cellInset(cell);
2630 Paragraph const & par = inset->paragraphs().front();
2632 os.texrow().forceStart(par.id(), 0);
2634 bool rtl = par.isRTL(buffer().params())
2636 && getPWidth(cell).zero()
2637 && !runparams.use_polyglossia;
2641 par.getParLanguage(buffer().params())->lang();
2642 if (lang == "farsi")
2644 else if (lang == "arabic_arabi")
2646 // currently, remaining RTL languages are
2647 // arabic_arabtex and hebrew
2651 // pass to the OutputParams that we are in a cell and
2652 // which alignment we have set.
2653 // InsetNewline needs this context information.
2654 OutputParams newrp(runparams);
2655 newrp.inTableCell = (getAlignment(cell) == LYX_ALIGN_BLOCK)
2656 ? OutputParams::PLAIN
2657 : OutputParams::ALIGNED;
2659 if (getAlignment(cell) == LYX_ALIGN_DECIMAL) {
2660 // copy cell and split in 2
2661 InsetTableCell head = InsetTableCell(*cellInset(cell));
2662 head.setBuffer(const_cast<Buffer &>(buffer()));
2663 DocIterator dit = cellInset(cell)->getText(0)->macrocontextPosition();
2665 dit.push_back(CursorSlice(head));
2666 head.setMacrocontextPositionRecursive(dit);
2667 bool hassep = false;
2668 InsetTableCell tail = splitCell(head, column_info[c].decimal_point, hassep);
2670 tail.setBuffer(head.buffer());
2672 dit.push_back(CursorSlice(tail));
2673 tail.setMacrocontextPositionRecursive(dit);
2677 tail.latex(os, newrp);
2680 head.latex(os, newrp);
2682 head.latex(os, newrp);
2685 tail.latex(os, newrp);
2688 } else if (ltCaption(row)) {
2689 // Inside longtable caption rows, we must only output the caption inset
2690 // with its content and omit anything outside of that (see #10791)
2691 InsetIterator it = inset_iterator_begin(*const_cast<InsetTableCell *>(inset));
2692 InsetIterator i_end = inset_iterator_end(*const_cast<InsetTableCell *>(inset));
2693 for (; it != i_end; ++it) {
2694 if (it->lyxCode() != CAPTION_CODE)
2696 it->latex(os, runparams);
2699 } else if (!isPartOfMultiRow(row, c)) {
2700 if (!runparams.nice)
2701 os.texrow().start(par.id(), 0);
2702 inset->latex(os, newrp);
2705 runparams.encoding = newrp.encoding;
2709 TeXCellPostamble(os, cell, ismulticol, ismultirow);
2710 if (cell != lastcell) { // not last cell in row
2717 os << "\\tabularnewline";
2718 if (row_info[row].bottom_space_default) {
2720 os << "\\addlinespace";
2722 os << "[\\doublerulesep]";
2723 } else if (!row_info[row].bottom_space.zero()) {
2725 os << "\\addlinespace";
2727 << from_ascii(row_info[row].bottom_space.asLatexString())
2732 //output the bottom line
2733 TeXBottomHLine(os, row, clang, columns);
2735 if (row_info[row].interline_space_default) {
2737 os << "\\addlinespace\n";
2739 os << "\\noalign{\\vskip\\doublerulesep}\n";
2740 } else if (!row_info[row].interline_space.zero()) {
2742 os << "\\addlinespace["
2743 << from_ascii(row_info[row].interline_space.asLatexString())
2746 os << "\\noalign{\\vskip"
2747 << from_ascii(row_info[row].interline_space.asLatexString())
2753 void Tabular::latex(otexstream & os, OutputParams const & runparams) const
2755 bool const is_tabular_star = !tabular_width.zero();
2756 TexRow::RowEntry pos = TexRow::textEntry(runparams.lastid, runparams.lastpos);
2758 //+---------------------------------------------------------------------
2759 //+ first the opening preamble +
2760 //+---------------------------------------------------------------------
2763 if (!TexRow::isNone(pos))
2764 os.texrow().start(pos);
2766 if (rotate != 0 && !is_long_tabular)
2767 os << "\\begin{turn}{" << convert<string>(rotate) << "}\n";
2769 if (is_long_tabular) {
2770 os << "\\begin{longtable}";
2771 switch (longtabular_alignment) {
2772 case LYX_LONGTABULAR_ALIGN_LEFT:
2775 case LYX_LONGTABULAR_ALIGN_CENTER:
2777 case LYX_LONGTABULAR_ALIGN_RIGHT:
2782 if (is_tabular_star)
2783 os << "\\begin{tabular*}{" << from_ascii(tabular_width.asLatexString()) << "}";
2785 os << "\\begin{tabular}";
2786 switch (tabular_valignment) {
2787 case LYX_VALIGN_TOP:
2790 case LYX_VALIGN_MIDDLE:
2792 case LYX_VALIGN_BOTTOM:
2800 if (is_tabular_star)
2801 os << "@{\\extracolsep{\\fill}}";
2803 // The bidi package (loaded by polyglossia) swaps the column
2804 // order for RTL (#9686). Thus we use this list.
2805 bool const bidi_rtl =
2806 runparams.local_font->isRightToLeft()
2807 && runparams.use_polyglossia;
2808 list<col_type> columns;
2809 for (col_type cl = 0; cl < ncols(); ++cl) {
2811 columns.push_front(cl);
2813 columns.push_back(cl);
2816 for (auto const & c : columns) {
2817 if ((bidi_rtl && columnRightLine(c)) || (!bidi_rtl && columnLeftLine(c)))
2819 if (!column_info[c].align_special.empty()) {
2820 os << column_info[c].align_special;
2822 if (!column_info[c].p_width.zero()) {
2823 bool decimal = false;
2824 switch (column_info[c].alignment) {
2825 case LYX_ALIGN_LEFT:
2826 os << ">{\\raggedright}";
2828 case LYX_ALIGN_RIGHT:
2829 os << ">{\\raggedleft}";
2831 case LYX_ALIGN_CENTER:
2832 os << ">{\\centering}";
2834 case LYX_ALIGN_NONE:
2835 case LYX_ALIGN_BLOCK:
2836 case LYX_ALIGN_LAYOUT:
2837 case LYX_ALIGN_SPECIAL:
2839 case LYX_ALIGN_DECIMAL: {
2841 os << ">{\\raggedright}";
2843 os << ">{\\raggedleft}";
2850 switch (column_info[c].valignment) {
2851 case LYX_VALIGN_TOP:
2852 // this is the default
2854 case LYX_VALIGN_MIDDLE:
2857 case LYX_VALIGN_BOTTOM:
2863 // Fixed-width cells with alignment at decimal separator
2864 // are output as two cells of half the width with the decimal
2865 // separator as column sep. This effectively puts the content
2866 // centered, which differs from the normal decimal sep alignment
2867 // and is not ideal, but we cannot do better ATM (see #9568).
2868 // FIXME: Implement proper decimal sep alignment, e.g. via siunitx.
2870 docstring const halffixedwith =
2871 from_ascii(Length(column_info[c].p_width.value() / 2,
2872 column_info[c].p_width.unit()).asLatexString());
2876 << "@{\\extracolsep{0pt}" << column_info[c].decimal_point << "}"
2883 << from_ascii(column_info[c].p_width.asLatexString())
2886 switch (column_info[c].alignment) {
2887 case LYX_ALIGN_LEFT:
2890 case LYX_ALIGN_RIGHT:
2893 case LYX_ALIGN_DECIMAL:
2894 os << "r@{\\extracolsep{0pt}" << column_info[c].decimal_point << "}l";
2900 } // end if else !column_info[i].p_width
2901 } // end if else !column_info[i].align_special
2902 if ((bidi_rtl && columnLeftLine(c)) || (!bidi_rtl && columnRightLine(c)))
2907 TeXLongtableHeaderFooter(os, runparams, columns);
2909 //+---------------------------------------------------------------------
2910 //+ the single row and columns (cells) +
2911 //+---------------------------------------------------------------------
2913 for (row_type r = 0; r < nrows(); ++r) {
2914 if (isValidRow(r)) {
2915 TeXRow(os, r, runparams, columns);
2916 if (is_long_tabular && row_info[r].newpage)
2917 os << "\\newpage\n";
2921 //+---------------------------------------------------------------------
2922 //+ the closing of the tabular +
2923 //+---------------------------------------------------------------------
2925 if (is_long_tabular)
2926 os << "\\end{longtable}";
2928 if (is_tabular_star)
2929 os << "\\end{tabular*}";
2931 os << "\\end{tabular}";
2934 if (rotate != 0 && !is_long_tabular)
2935 os << breakln << "\\end{turn}";
2937 if (!TexRow::isNone(pos))
2938 os.texrow().start(pos);
2942 int Tabular::docbookRow(odocstream & os, row_type row,
2943 OutputParams const & runparams) const
2946 idx_type cell = getFirstCellInRow(row);
2949 for (col_type c = 0; c < ncols(); ++c) {
2950 if (isPartOfMultiColumn(row, c))
2953 os << "<entry align=\"";
2954 switch (getAlignment(cell)) {
2955 case LYX_ALIGN_LEFT:
2958 case LYX_ALIGN_RIGHT:
2966 os << "\" valign=\"";
2967 switch (getVAlignment(cell)) {
2968 case LYX_VALIGN_TOP:
2971 case LYX_VALIGN_BOTTOM:
2974 case LYX_VALIGN_MIDDLE:
2979 if (isMultiColumn(cell)) {
2980 os << " namest=\"col" << c << "\" ";
2981 os << "nameend=\"col" << c + columnSpan(cell) - 1 << '"';
2985 ret += cellInset(cell)->docbook(os, runparams);
2994 int Tabular::docbook(odocstream & os, OutputParams const & runparams) const
2998 //+---------------------------------------------------------------------
2999 //+ first the opening preamble +
3000 //+---------------------------------------------------------------------
3002 os << "<tgroup cols=\"" << ncols()
3003 << "\" colsep=\"1\" rowsep=\"1\">\n";
3005 for (col_type c = 0; c < ncols(); ++c) {
3006 os << "<colspec colname=\"col" << c << "\" align=\"";
3007 switch (column_info[c].alignment) {
3008 case LYX_ALIGN_LEFT:
3011 case LYX_ALIGN_RIGHT:
3019 if (runparams.flavor == OutputParams::XML)
3025 //+---------------------------------------------------------------------
3026 //+ Long Tabular case +
3027 //+---------------------------------------------------------------------
3029 // output caption info
3030 // The caption flag wins over head/foot
3031 if (haveLTCaption()) {
3032 os << "<caption>\n";
3034 for (row_type r = 0; r < nrows(); ++r) {
3035 if (row_info[r].caption) {
3036 ret += docbookRow(os, r, runparams);
3039 os << "</caption>\n";
3042 // output header info
3043 if (haveLTHead(false) || haveLTFirstHead(false)) {
3046 for (row_type r = 0; r < nrows(); ++r) {
3047 if ((row_info[r].endhead || row_info[r].endfirsthead) &&
3048 !row_info[r].caption) {
3049 ret += docbookRow(os, r, runparams);
3055 // output footer info
3056 if (haveLTFoot(false) || haveLTLastFoot(false)) {
3059 for (row_type r = 0; r < nrows(); ++r) {
3060 if ((row_info[r].endfoot || row_info[r].endlastfoot) &&
3061 !row_info[r].caption) {
3062 ret += docbookRow(os, r, runparams);
3069 //+---------------------------------------------------------------------
3070 //+ the single row and columns (cells) +
3071 //+---------------------------------------------------------------------
3075 for (row_type r = 0; r < nrows(); ++r) {
3076 if (isValidRow(r)) {
3077 ret += docbookRow(os, r, runparams);
3082 //+---------------------------------------------------------------------
3083 //+ the closing of the tabular +
3084 //+---------------------------------------------------------------------
3093 docstring Tabular::xhtmlRow(XHTMLStream & xs, row_type row,
3094 OutputParams const & runparams, bool header) const
3097 string const celltag = header ? "th" : "td";
3098 idx_type cell = getFirstCellInRow(row);
3100 xs << html::StartTag("tr");
3101 for (col_type c = 0; c < ncols(); ++c) {
3102 if (isPartOfMultiColumn(row, c) || isPartOfMultiRow(row, c))
3107 Length const cwidth = column_info[c].p_width;
3108 if (!cwidth.zero()) {
3109 string const hwidth = cwidth.asHTMLString();
3110 attr << "style =\"width: " << hwidth << ";\" ";
3114 switch (getAlignment(cell)) {
3115 case LYX_ALIGN_LEFT:
3118 case LYX_ALIGN_RIGHT:
3126 attr << " valign='";
3127 switch (getVAlignment(cell)) {
3128 case LYX_VALIGN_TOP:
3131 case LYX_VALIGN_BOTTOM:
3134 case LYX_VALIGN_MIDDLE:
3139 if (isMultiColumn(cell))
3140 attr << " colspan='" << columnSpan(cell) << "'";
3141 else if (isMultiRow(cell))
3142 attr << " rowspan='" << rowSpan(cell) << "'";
3144 xs << html::StartTag(celltag, attr.str(), true) << html::CR();
3145 ret += cellInset(cell)->xhtml(xs, runparams);
3146 xs << html::EndTag(celltag) << html::CR();
3149 xs << html::EndTag("tr");
3154 docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
3158 if (is_long_tabular) {
3159 // we'll wrap it in a div, so as to deal with alignment
3161 switch (longtabular_alignment) {
3162 case LYX_LONGTABULAR_ALIGN_LEFT:
3165 case LYX_LONGTABULAR_ALIGN_CENTER:
3168 case LYX_LONGTABULAR_ALIGN_RIGHT:
3172 xs << html::StartTag("div", "class='longtable' style='text-align: " + align + ";'")
3174 // The caption flag wins over head/foot
3175 if (haveLTCaption()) {
3176 xs << html::StartTag("div", "class='longtable-caption' style='text-align: " + align + ";'")
3178 for (row_type r = 0; r < nrows(); ++r)
3179 if (row_info[r].caption)
3180 ret += xhtmlRow(xs, r, runparams);
3181 xs << html::EndTag("div") << html::CR();
3185 xs << html::StartTag("table") << html::CR();
3187 // output header info
3188 bool const havefirsthead = haveLTFirstHead(false);
3189 // if we have a first head, then we are going to ignore the
3190 // headers for the additional pages, since there aren't any
3191 // in XHTML. this test accomplishes that.
3192 bool const havehead = !havefirsthead && haveLTHead(false);
3193 if (havehead || havefirsthead) {
3194 xs << html::StartTag("thead") << html::CR();
3195 for (row_type r = 0; r < nrows(); ++r) {
3196 if (((havefirsthead && row_info[r].endfirsthead) ||
3197 (havehead && row_info[r].endhead)) &&
3198 !row_info[r].caption) {
3199 ret += xhtmlRow(xs, r, runparams, true);
3202 xs << html::EndTag("thead") << html::CR();
3204 // output footer info
3205 bool const havelastfoot = haveLTLastFoot(false);
3207 bool const havefoot = !havelastfoot && haveLTFoot(false);
3208 if (havefoot || havelastfoot) {
3209 xs << html::StartTag("tfoot") << html::CR();
3210 for (row_type r = 0; r < nrows(); ++r) {
3211 if (((havelastfoot && row_info[r].endlastfoot) ||
3212 (havefoot && row_info[r].endfoot)) &&
3213 !row_info[r].caption) {
3214 ret += xhtmlRow(xs, r, runparams);
3217 xs << html::EndTag("tfoot") << html::CR();
3220 xs << html::StartTag("tbody") << html::CR();
3221 for (row_type r = 0; r < nrows(); ++r) {
3222 if (isValidRow(r)) {
3223 ret += xhtmlRow(xs, r, runparams);
3226 xs << html::EndTag("tbody")
3228 << html::EndTag("table")
3230 if (is_long_tabular)
3231 xs << html::EndTag("div") << html::CR();
3236 bool Tabular::plaintextTopHLine(odocstringstream & os, row_type row,
3237 vector<unsigned int> const & clen) const
3239 idx_type const fcell = getFirstCellInRow(row);
3240 idx_type const n = numberOfCellsInRow(row) + fcell;
3243 for (idx_type i = fcell; i < n; ++i) {
3253 for (idx_type i = fcell; i < n; ++i) {
3264 col_type column = cellColumn(i);
3265 int len = clen[column];
3266 while (column < ncols() - 1
3267 && isPartOfMultiColumn(row, ++column))
3268 len += clen[column] + 4;
3269 os << docstring(len, ch);
3284 bool Tabular::plaintextBottomHLine(odocstringstream & os, row_type row,
3285 vector<unsigned int> const & clen) const
3287 idx_type const fcell = getFirstCellInRow(row);
3288 idx_type const n = numberOfCellsInRow(row) + fcell;
3291 for (idx_type i = fcell; i < n; ++i) {
3292 if (bottomLine(i)) {
3301 for (idx_type i = fcell; i < n; ++i) {
3302 if (bottomLine(i)) {
3312 col_type column = cellColumn(i);
3313 int len = clen[column];
3314 while (column < ncols() - 1 && isPartOfMultiColumn(row, ++column))
3315 len += clen[column] + 4;
3316 os << docstring(len, ch);
3317 if (bottomLine(i)) {
3331 void Tabular::plaintextPrintCell(odocstringstream & os,
3332 OutputParams const & runparams,
3333 idx_type cell, row_type row, col_type column,
3334 vector<unsigned int> const & clen,
3335 bool onlydata, size_t max_length) const
3337 odocstringstream sstr;
3338 cellInset(cell)->plaintext(sstr, runparams, max_length);
3350 unsigned int len1 = sstr.str().length();
3351 unsigned int len2 = clen[column];
3352 while (column < ncols() - 1 && isPartOfMultiColumn(row, ++column))
3353 len2 += clen[column] + 4;
3356 switch (getAlignment(cell)) {
3358 case LYX_ALIGN_LEFT:
3361 case LYX_ALIGN_RIGHT:
3365 case LYX_ALIGN_CENTER:
3371 os << docstring(len1, ' ') << sstr.str()
3372 << docstring(len2, ' ');
3374 if (rightLine(cell))
3381 void Tabular::plaintext(odocstringstream & os,
3382 OutputParams const & runparams, int const depth,
3383 bool onlydata, char_type delim, size_t max_length) const
3385 // first calculate the width of the single columns
3386 vector<unsigned int> clen(ncols());
3389 // first all non multicolumn cells!
3390 for (col_type c = 0; c < ncols(); ++c) {
3392 for (row_type r = 0; r < nrows(); ++r) {
3393 idx_type cell = cellIndex(r, c);
3394 if (isMultiColumn(cell))
3396 odocstringstream sstr;
3397 cellInset(cell)->plaintext(sstr, runparams, max_length);
3398 if (clen[c] < sstr.str().length())
3399 clen[c] = sstr.str().length();
3402 // then all multicolumn cells!
3403 for (col_type c = 0; c < ncols(); ++c) {
3404 for (row_type r = 0; r < nrows(); ++r) {
3405 idx_type cell = cellIndex(r, c);
3406 if (cell_info[r][c].multicolumn != CELL_BEGIN_OF_MULTICOLUMN)
3408 odocstringstream sstr;
3409 cellInset(cell)->plaintext(sstr, runparams, max_length);
3410 int len = int(sstr.str().length());
3411 idx_type const n = columnSpan(cell);
3412 for (col_type k = c; len > 0 && k < c + n - 1; ++k)
3414 if (len > int(clen[c + n - 1]))
3415 clen[c + n - 1] = len;
3420 for (row_type r = 0; r < nrows(); ++r) {
3421 if (!onlydata && plaintextTopHLine(os, r, clen))
3422 os << docstring(depth * 2, ' ');
3423 for (col_type c = 0; c < ncols(); ++c) {
3424 if (isPartOfMultiColumn(r, c) || isPartOfMultiRow(r,c))
3426 if (onlydata && c > 0)
3427 // we don't use operator<< for single UCS4 character.
3428 // see explanation in docstream.h
3430 plaintextPrintCell(os, runparams, cell, r, c, clen, onlydata, max_length);
3432 if (os.str().size() > max_length)
3437 os << docstring(depth * 2, ' ');
3438 if (plaintextBottomHLine(os, r, clen))
3439 os << docstring(depth * 2, ' ');
3441 if (os.str().size() > max_length)
3447 shared_ptr<InsetTableCell> Tabular::cellInset(idx_type cell)
3449 return cell_info[cellRow(cell)][cellColumn(cell)].inset;
3453 shared_ptr<InsetTableCell> Tabular::cellInset(row_type row, col_type column)
3455 return cell_info[row][column].inset;
3459 InsetTableCell const * Tabular::cellInset(idx_type cell) const
3461 return cell_info[cellRow(cell)][cellColumn(cell)].inset.get();
3465 void Tabular::setCellInset(row_type row, col_type column,
3466 shared_ptr<InsetTableCell> ins)
3468 CellData & cd = cell_info[row][column];
3473 void Tabular::validate(LaTeXFeatures & features) const
3475 features.require("NeedTabularnewline");
3477 features.require("booktabs");
3478 if (is_long_tabular)
3479 features.require("longtable");
3481 features.require("rotating");
3482 for (idx_type cell = 0; cell < numberofcells; ++cell) {
3483 if (isMultiRow(cell))
3484 features.require("multirow");
3485 if (getVAlignment(cell) != LYX_VALIGN_TOP
3486 || !getPWidth(cell).zero())
3487 features.require("array");
3488 // Tell footnote that we need a savenote
3489 // environment in non-long tables or
3490 // longtable headers/footers
3491 else if (!is_long_tabular && !features.inFloat())
3492 features.saveNoteEnv("tabular");
3493 else if (!isValidRow(cellRow(cell)))
3494 features.saveNoteEnv("longtable");
3496 cellInset(cell)->validate(features);
3497 features.saveNoteEnv(string());
3502 Tabular::BoxType Tabular::useParbox(idx_type cell) const
3504 ParagraphList const & parlist = cellInset(cell)->paragraphs();
3505 ParagraphList::const_iterator cit = parlist.begin();
3506 ParagraphList::const_iterator end = parlist.end();
3508 for (; cit != end; ++cit)
3509 for (int i = 0; i < cit->size(); ++i)
3510 if (cit->isNewline(i))
3517 /////////////////////////////////////////////////////////////////////
3521 /////////////////////////////////////////////////////////////////////
3523 InsetTableCell::InsetTableCell(Buffer * buf)
3524 : InsetText(buf, InsetText::PlainLayout), isFixedWidth(false),
3525 contentAlign(LYX_ALIGN_CENTER)
3529 bool InsetTableCell::forcePlainLayout(idx_type) const
3531 return !isFixedWidth;
3535 bool InsetTableCell::allowParagraphCustomization(idx_type) const
3537 return isFixedWidth;
3541 bool InsetTableCell::forceLocalFontSwitch() const
3543 return isFixedWidth;
3547 bool InsetTableCell::getStatus(Cursor & cur, FuncRequest const & cmd,
3548 FuncStatus & status) const
3550 bool enabled = true;
3551 switch (cmd.action()) {
3552 case LFUN_MATH_DISPLAY:
3553 if (!hasFixedWidth()) {
3558 return InsetText::getStatus(cur, cmd, status);
3560 status.setEnabled(enabled);
3564 docstring InsetTableCell::asString(bool intoInsets)
3567 if (paragraphs().empty())
3569 ParagraphList::const_iterator it = paragraphs().begin();
3570 ParagraphList::const_iterator en = paragraphs().end();
3572 for (; it != en; ++it) {
3577 retval += it->asString(intoInsets ? AS_STR_INSETS : AS_STR_NONE);
3583 void InsetTableCell::addToToc(DocIterator const & di, bool output_active,
3584 UpdateType utype, TocBackend & backend) const
3586 InsetText::iterateForToc(di, output_active, utype, backend);
3590 docstring InsetTableCell::xhtml(XHTMLStream & xs, OutputParams const & rp) const
3593 return InsetText::insetAsXHTML(xs, rp, InsetText::JustText);
3594 return InsetText::xhtml(xs, rp);
3599 /////////////////////////////////////////////////////////////////////
3603 /////////////////////////////////////////////////////////////////////
3605 InsetTabular::InsetTabular(Buffer * buf, row_type rows,
3607 : Inset(buf), tabular(buf, max(rows, row_type(1)), max(columns, col_type(1))),
3608 rowselect_(false), colselect_(false)
3613 InsetTabular::InsetTabular(InsetTabular const & tab)
3614 : Inset(tab), tabular(tab.tabular),
3615 rowselect_(false), colselect_(false)
3620 InsetTabular::~InsetTabular()
3622 hideDialogs("tabular", this);
3626 void InsetTabular::setBuffer(Buffer & buf)
3628 tabular.setBuffer(buf);
3629 Inset::setBuffer(buf);
3633 bool InsetTabular::insetAllowed(InsetCode code) const
3638 case MATHMACRO_CODE:
3643 return tabular.is_long_tabular;
3651 bool InsetTabular::allowsCaptionVariation(std::string const & newtype) const
3653 return tabular.is_long_tabular &&
3654 (newtype == "Standard" || newtype == "Unnumbered");
3658 void InsetTabular::write(ostream & os) const
3660 os << "Tabular" << endl;
3665 string InsetTabular::contextMenu(BufferView const &, int, int) const
3667 // FIXME: depending on the selection state,
3668 // we could offer a different menu.
3669 return cell(0)->contextMenuName() + ";" + contextMenuName();
3673 string InsetTabular::contextMenuName() const
3675 return "context-tabular";
3679 void InsetTabular::read(Lexer & lex)
3681 //bool const old_format = (lex.getString() == "\\LyXTable");
3689 string token = lex.getString();
3690 while (lex && token != "\\end_inset") {
3692 token = lex.getString();
3695 lex.printError("Missing \\end_inset at this point. ");
3699 int InsetTabular::rowFromY(Cursor & cur, int y) const
3701 // top y coordinate of tabular
3702 int h = yo(cur.bv()) - tabular.rowAscent(0) + tabular.offsetVAlignment();
3704 for (; r < tabular.nrows() && y > h; ++r)
3705 h += tabular.rowAscent(r) + tabular.rowDescent(r)
3706 + tabular.interRowSpace(r);
3712 int InsetTabular::columnFromX(Cursor & cur, int x) const
3714 // left x coordinate of tabular
3715 int w = xo(cur.bv()) + ADD_TO_TABULAR_WIDTH;
3717 for (; c < tabular.ncols() && x > w; ++c)
3718 w += tabular.cellWidth(c);
3723 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
3725 //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
3726 // mi.base.textwidth << "\n";
3727 LBUFERR(mi.base.bv);
3729 for (row_type r = 0; r < tabular.nrows(); ++r) {
3732 for (col_type c = 0; c < tabular.ncols(); ++c) {
3733 if (tabular.isPartOfMultiColumn(r, c)
3734 || tabular.isPartOfMultiRow(r, c))
3735 // multicolumn or multirow cell, but not first one
3737 idx_type const cell = tabular.cellIndex(r, c);
3740 Length const p_width = tabular.getPWidth(cell);
3741 if (!p_width.zero())
3742 m.base.textwidth = mi.base.inPixels(p_width);
3743 tabular.cellInset(cell)->metrics(m, dim0);
3744 if (!p_width.zero())
3745 dim0.wid = m.base.textwidth;
3746 tabular.cellInfo(cell).width = dim0.wid + 2 * WIDTH_OF_LINE
3747 + tabular.interColumnSpace(cell);
3749 // FIXME(?): do we need a second metrics call?
3750 TextMetrics const & tm =
3751 mi.base.bv->textMetrics(tabular.cellInset(cell)->getText(0));
3753 // determine horizontal offset because of decimal align (if necessary)
3754 int decimal_width = 0;
3755 if (tabular.getAlignment(cell) == LYX_ALIGN_DECIMAL) {
3756 InsetTableCell tail = InsetTableCell(*tabular.cellInset(cell));
3757 tail.setBuffer(tabular.buffer());
3758 // we need to set macrocontext position everywhere
3759 // otherwise we crash with nested insets (e.g. footnotes)
3760 // after decimal point
3761 DocIterator dit = tabular.cellInset(cell)->getText(0)->macrocontextPosition();
3763 dit.push_back(CursorSlice(tail));
3764 tail.setMacrocontextPositionRecursive(dit);
3766 // remove text leading decimal point
3767 docstring const align_d = tabular.column_info[c].decimal_point;
3768 dit = separatorPos(&tail, align_d);
3770 pit_type const psize = tail.paragraphs().front().size();
3772 tail.paragraphs().front().eraseChars(0,
3773 dit.pos() < psize ? dit.pos() + 1 : psize, false);
3775 tail.metrics(m, dim1);
3776 decimal_width = dim1.width();
3779 tabular.cell_info[r][c].decimal_hoffset = tm.width() - decimal_width;
3780 tabular.cell_info[r][c].decimal_width = decimal_width;
3782 // with LYX_VALIGN_BOTTOM the descent is relative to the last par
3783 // = descent of text in last par + TEXT_TO_INSET_OFFSET:
3784 int const lastpardes = tm.last().second->descent()
3785 + TEXT_TO_INSET_OFFSET;
3787 switch (tabular.getVAlignment(cell)) {
3788 case Tabular::LYX_VALIGN_TOP:
3790 case Tabular::LYX_VALIGN_MIDDLE:
3791 offset = -(dim0.des - lastpardes)/2;
3793 case Tabular::LYX_VALIGN_BOTTOM:
3794 offset = -(dim0.des - lastpardes);
3797 tabular.cell_info[r][c].voffset = offset;
3798 maxasc = max(maxasc, dim0.asc - offset);
3799 maxdes = max(maxdes, dim0.des + offset);
3801 int const top_space = tabular.row_info[r].top_space_default ?
3802 default_line_space :
3803 mi.base.inPixels(tabular.row_info[r].top_space);
3804 tabular.setRowAscent(r, maxasc + ADD_TO_HEIGHT + top_space);
3805 int const bottom_space = tabular.row_info[r].bottom_space_default ?
3806 default_line_space :
3807 mi.base.inPixels(tabular.row_info[r].bottom_space);
3808 tabular.setRowDescent(r, maxdes + ADD_TO_HEIGHT + bottom_space);
3811 tabular.updateColumnWidths();
3812 dim.asc = tabular.rowAscent(0) - tabular.offsetVAlignment();
3813 dim.des = tabular.height() - dim.asc;
3814 dim.wid = tabular.width() + 2 * ADD_TO_TABULAR_WIDTH;
3818 bool InsetTabular::isCellSelected(Cursor & cur, row_type row, col_type col)
3821 if (&cur.inset() == this && cur.selection()) {
3822 if (cur.selIsMultiCell()) {
3825 getSelection(cur, rs, re, cs, ce);
3827 idx_type const cell = tabular.cellIndex(row, col);
3828 col_type const cspan = tabular.columnSpan(cell);
3829 row_type const rspan = tabular.rowSpan(cell);
3830 if (col + cspan - 1 >= cs && col <= ce
3831 && row + rspan - 1 >= rs && row <= re)
3834 if (col == tabular.cellColumn(cur.idx())
3835 && row == tabular.cellRow(cur.idx())) {
3836 CursorSlice const & beg = cur.selBegin();
3837 CursorSlice const & end = cur.selEnd();
3839 if ((end.lastpos() > 0 || end.lastpit() > 0)
3840 && end.pos() == end.lastpos() && beg.pos() == 0
3841 && end.pit() == end.lastpit() && beg.pit() == 0)
3849 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
3851 x += ADD_TO_TABULAR_WIDTH;
3853 BufferView * bv = pi.base.bv;
3854 Cursor & cur = pi.base.bv->cursor();
3856 // FIXME: As the full background is painted in drawBackground(),
3857 // we have no choice but to do a full repaint for the Text cells.
3858 pi.full_repaint = true;
3860 bool const original_selection_state = pi.selected;
3864 int yy = y + tabular.offsetVAlignment();
3865 for (row_type r = 0; r < tabular.nrows(); ++r) {
3867 for (col_type c = 0; c < tabular.ncols(); ++c) {
3868 if (tabular.isPartOfMultiColumn(r, c))
3871 idx = tabular.cellIndex(r, c);
3873 if (tabular.isPartOfMultiRow(r, c)) {
3874 nx += tabular.cellWidth(idx);
3878 pi.selected |= isCellSelected(cur, r, c);
3879 int const cx = nx + tabular.textHOffset(idx);
3880 int const cy = yy + tabular.textVOffset(idx);
3881 // Cache the Inset position.
3882 bv->coordCache().insets().add(cell(idx).get(), cx, cy);
3883 cell(idx)->draw(pi, cx, cy);
3884 drawCellLines(pi, nx, yy, r, idx);
3885 nx += tabular.cellWidth(idx);
3886 pi.selected = original_selection_state;
3889 if (r + 1 < tabular.nrows())
3890 yy += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
3891 + tabular.interRowSpace(r + 1);
3896 void InsetTabular::drawBackground(PainterInfo & pi, int x, int y) const
3898 x += ADD_TO_TABULAR_WIDTH;
3899 y += tabular.offsetVAlignment() - tabular.rowAscent(0);
3900 pi.pain.fillRectangle(x, y, tabular.width(), tabular.height(),
3901 pi.backgroundColor(this));
3905 void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
3907 Cursor & cur = pi.base.bv->cursor();
3909 x += ADD_TO_TABULAR_WIDTH;
3911 if (!cur.selection())
3913 if (&cur.inset() != this)
3918 bool const full_cell_selected = isCellSelected(cur,
3919 tabular.cellRow(cur.idx()), tabular.cellColumn(cur.idx()));
3921 if (cur.selIsMultiCell() || full_cell_selected) {
3922 for (row_type r = 0; r < tabular.nrows(); ++r) {
3924 for (col_type c = 0; c < tabular.ncols(); ++c) {
3925 if (tabular.isPartOfMultiColumn(r, c))
3928 idx_type const cell = tabular.cellIndex(r, c);
3930 if (tabular.isPartOfMultiRow(r, c)) {
3931 xx += tabular.cellWidth(cell);
3934 int const w = tabular.cellWidth(cell);
3935 int const h = tabular.cellHeight(cell);
3936 int const yy = y - tabular.rowAscent(r) + tabular.offsetVAlignment();
3937 if (isCellSelected(cur, r, c))
3938 pi.pain.fillRectangle(xx, yy, w, h, Color_selection);
3941 if (r + 1 < tabular.nrows())
3942 y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
3943 + tabular.interRowSpace(r + 1);
3947 // FIXME: This code has no effect because InsetTableCell does not handle
3948 // drawSelection other than the trivial implementation in Inset.
3950 // x += cellXPos(cur.idx());
3951 // x += tabular.textHOffset(cur.idx());
3952 // cell(cur.idx())->drawSelection(pi, x, 0 /* ignored */);
3957 void InsetTabular::drawCellLines(PainterInfo & pi, int x, int y,
3958 row_type row, idx_type cell) const
3960 y -= tabular.rowAscent(row);
3961 int const w = tabular.cellWidth(cell);
3962 int const h = tabular.cellHeight(cell);
3963 Color const linecolor = pi.textColor(Color_tabularline);
3964 Color const gridcolor = pi.textColor(Color_tabularonoffline);
3967 bool drawline = tabular.topLine(cell)
3968 || (row > 0 && tabular.bottomLine(tabular.cellAbove(cell)));
3969 pi.pain.line(x, y, x + w, y,
3970 drawline ? linecolor : gridcolor,
3971 drawline ? Painter::line_solid : Painter::line_onoffdash);
3974 drawline = tabular.bottomLine(cell);
3975 pi.pain.line(x, y + h, x + w, y + h,
3976 drawline ? linecolor : gridcolor,
3977 drawline ? Painter::line_solid : Painter::line_onoffdash);
3980 col_type const col = tabular.cellColumn(cell);
3981 drawline = tabular.leftLine(cell)
3982 || (col > 0 && tabular.rightLine(tabular.cellIndex(row, col - 1)));
3983 pi.pain.line(x, y, x, y + h,
3984 drawline ? linecolor : gridcolor,
3985 drawline ? Painter::line_solid : Painter::line_onoffdash);
3988 x -= tabular.interColumnSpace(cell);
3989 col_type next_cell_col = col + 1;
3990 while (next_cell_col < tabular.ncols()
3991 && tabular.isMultiColumn(tabular.cellIndex(row, next_cell_col)))
3993 drawline = tabular.rightLine(cell)
3994 || (next_cell_col < tabular.ncols()
3995 && tabular.leftLine(tabular.cellIndex(row, next_cell_col)));
3996 pi.pain.line(x + w, y, x + w, y + h,
3997 drawline ? linecolor : gridcolor,
3998 drawline ? Painter::line_solid : Painter::line_onoffdash);
4002 void InsetTabular::edit(Cursor & cur, bool front, EntryDirection)
4004 //lyxerr << "InsetTabular::edit: " << this << endl;
4008 if (isRightToLeft(cur))
4009 cur.idx() = tabular.getLastCellInRow(0);
4015 if (isRightToLeft(cur))
4016 cur.idx() = tabular.getFirstCellInRow(tabular.nrows() - 1);
4018 cur.idx() = tabular.numberofcells - 1;
4020 cur.pos() = cur.lastpos(); // FIXME crude guess
4022 cur.setCurrentFont();
4023 // FIXME: this accesses the position cache before it is initialized
4024 //cur.bv().fitCursor();
4028 void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype)
4030 // In a longtable, tell captions what the current float is
4031 Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
4032 string const saveflt = cnts.current_float();
4033 if (tabular.is_long_tabular) {
4034 cnts.current_float("table");
4035 // in longtables, we only step the counter once
4036 cnts.step(from_ascii("table"), utype);
4037 cnts.isLongtable(true);
4040 ParIterator it2 = it;
4042 size_t const end = it2.nargs();
4043 for ( ; it2.idx() < end; it2.top().forwardIdx())
4044 buffer().updateBuffer(it2, utype);
4047 if (tabular.is_long_tabular) {
4048 cnts.current_float(saveflt);
4049 cnts.isLongtable(false);
4054 void InsetTabular::addToToc(DocIterator const & cpit, bool output_active,
4055 UpdateType utype, TocBackend & backend) const
4057 DocIterator dit = cpit;
4059 size_t const end = dit.nargs();
4060 for ( ; dit.idx() < end; dit.top().forwardIdx())
4061 cell(dit.idx())->addToToc(dit, output_active, utype, backend);
4065 bool InsetTabular::hitSelectRow(BufferView const & bv, int x) const
4067 int const x0 = xo(bv) + ADD_TO_TABULAR_WIDTH;
4068 return x < x0 || x > x0 + tabular.width();
4072 bool InsetTabular::hitSelectColumn(BufferView const & bv, int y) const
4074 int const y0 = yo(bv) - tabular.rowAscent(0) + tabular.offsetVAlignment();
4075 // FIXME: using ADD_TO_TABULAR_WIDTH is not really correct since
4076 // there is no margin added vertically to tabular insets.
4077 // However, it works for now.
4078 return y < y0 + ADD_TO_TABULAR_WIDTH || y > y0 + tabular.height() - ADD_TO_TABULAR_WIDTH;
4082 bool InsetTabular::clickable(BufferView const & bv, int x, int y) const
4084 return hitSelectRow(bv, x) || hitSelectColumn(bv, y);
4088 void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
4090 LYXERR(Debug::DEBUG, "# InsetTabular::doDispatch: cmd: " << cmd
4091 << "\n cur:" << cur);
4092 CursorSlice sl = cur.top();
4093 Cursor & bvcur = cur.bv().cursor();
4095 FuncCode const act = cmd.action();
4099 case LFUN_MOUSE_PRESS: {
4100 //lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
4102 if (hitSelectRow(cur.bv(), cmd.x())) {
4103 row_type r = rowFromY(cur, cmd.y());
4104 cur.idx() = tabular.getFirstCellInRow(r);
4108 cur.idx() = tabular.getLastCellInRow(r);
4109 cur.pit() = cur.lastpit();
4110 cur.pos() = cur.lastpos();
4111 cur.selection(true);
4117 if (hitSelectColumn(cur.bv(), cmd.y())) {
4118 col_type c = columnFromX(cur, cmd.x());
4119 cur.idx() = tabular.cellIndex(0, c);
4123 cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c);
4124 cur.pit() = cur.lastpit();
4125 cur.pos() = cur.lastpos();
4126 cur.selection(true);
4131 // do not reset cursor/selection if we have selected
4132 // some cells (bug 2715).
4133 if (cmd.button() == mouse_button::button3
4134 && &bvcur.selBegin().inset() == this
4135 && bvcur.selIsMultiCell())
4138 // Let InsetTableCell do it
4139 cell(cur.idx())->dispatch(cur, cmd);
4142 case LFUN_MOUSE_MOTION:
4143 //lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
4144 if (cmd.button() == mouse_button::button1) {
4145 // only accept motions to places not deeper nested than the real anchor
4146 if (!bvcur.realAnchor().hasPart(cur)) {
4150 // select (additional) row
4152 row_type r = rowFromY(cur, cmd.y());
4153 cur.idx() = tabular.getLastCellInRow(r);
4154 // we need to reset the cursor's pit and pos now, as the old ones
4155 // may no longer be valid.
4158 bvcur.setCursor(cur);
4159 bvcur.selection(true);
4162 // select (additional) column
4164 col_type c = columnFromX(cur, cmd.x());
4165 cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c);
4166 // we need to reset the cursor's pit and pos now, as the old ones
4167 // may no longer be valid.
4170 bvcur.setCursor(cur);
4171 bvcur.selection(true);
4174 // only update if selection changes
4175 if (bvcur.idx() == cur.idx() &&
4176 !(bvcur.realAnchor().idx() == cur.idx() && bvcur.pos() != cur.pos()))
4177 cur.noScreenUpdate();
4178 setCursorFromCoordinates(cur, cmd.x(), cmd.y());
4179 bvcur.setCursor(cur);
4180 bvcur.selection(true);
4181 // if this is a multicell selection, we just set the cursor to
4182 // the beginning of the cell's text.
4183 if (bvcur.selIsMultiCell()) {
4184 bvcur.pit() = bvcur.lastpit();
4185 bvcur.pos() = bvcur.lastpos();
4190 case LFUN_MOUSE_RELEASE:
4195 case LFUN_CELL_BACKWARD:
4197 cur.selection(false);
4200 case LFUN_CELL_FORWARD:
4202 cur.selection(false);
4205 case LFUN_CHAR_FORWARD_SELECT:
4206 case LFUN_CHAR_FORWARD:
4207 case LFUN_CHAR_BACKWARD_SELECT:
4208 case LFUN_CHAR_BACKWARD:
4209 case LFUN_CHAR_RIGHT_SELECT:
4210 case LFUN_CHAR_RIGHT:
4211 case LFUN_CHAR_LEFT_SELECT:
4212 case LFUN_CHAR_LEFT:
4213 case LFUN_WORD_FORWARD:
4214 case LFUN_WORD_FORWARD_SELECT:
4215 case LFUN_WORD_BACKWARD:
4216 case LFUN_WORD_BACKWARD_SELECT:
4217 case LFUN_WORD_RIGHT:
4218 case LFUN_WORD_RIGHT_SELECT:
4219 case LFUN_WORD_LEFT:
4220 case LFUN_WORD_LEFT_SELECT: {
4221 // determine whether we move to next or previous cell, where to enter
4222 // the new cell from, and which command to "finish" (i.e., exit the
4225 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE;
4226 FuncCode finish_lfun;
4228 if (act == LFUN_CHAR_FORWARD
4229 || act == LFUN_CHAR_FORWARD_SELECT
4230 || act == LFUN_WORD_FORWARD
4231 || act == LFUN_WORD_FORWARD_SELECT) {
4233 finish_lfun = LFUN_FINISHED_FORWARD;
4235 else if (act == LFUN_CHAR_BACKWARD
4236 || act == LFUN_CHAR_BACKWARD_SELECT
4237 || act == LFUN_WORD_BACKWARD
4238 || act == LFUN_WORD_BACKWARD_SELECT) {
4240 finish_lfun = LFUN_FINISHED_BACKWARD;
4242 // LEFT or RIGHT commands --- the interpretation will depend on the
4243 // table's direction.
4245 bool const right = act == LFUN_CHAR_RIGHT
4246 || act == LFUN_CHAR_RIGHT_SELECT
4247 || act == LFUN_WORD_RIGHT
4248 || act == LFUN_WORD_RIGHT_SELECT;
4249 next_cell = isRightToLeft(cur) != right;
4251 if (lyxrc.visual_cursor)
4252 entry_from = right ? ENTRY_DIRECTION_LEFT:ENTRY_DIRECTION_RIGHT;
4254 finish_lfun = right ? LFUN_FINISHED_RIGHT : LFUN_FINISHED_LEFT;
4257 bool const select = act == LFUN_CHAR_FORWARD_SELECT
4258 || act == LFUN_CHAR_BACKWARD_SELECT
4259 || act == LFUN_CHAR_RIGHT_SELECT
4260 || act == LFUN_CHAR_LEFT_SELECT
4261 || act == LFUN_WORD_FORWARD_SELECT
4262 || act == LFUN_WORD_RIGHT_SELECT
4263 || act == LFUN_WORD_BACKWARD_SELECT
4264 || act == LFUN_WORD_LEFT_SELECT;
4266 // If we have a multicell selection or we're
4267 // not doing some LFUN_*_SELECT thing anyway...
4268 if (!cur.selIsMultiCell() || !select) {
4269 col_type const c = tabular.cellColumn(cur.idx());
4270 row_type const r = tabular.cellRow(cur.idx());
4271 // Are we trying to select the whole cell and is the whole cell
4272 // not yet selected?
4273 bool const select_whole = select && !isCellSelected(cur, r, c) &&
4274 ((next_cell && cur.pit() == cur.lastpit()
4275 && cur.pos() == cur.lastpos())
4276 || (!next_cell && cur.pit() == 0 && cur.pos() == 0));
4278 bool const empty_cell = cur.lastpos() == 0 && cur.lastpit() == 0;
4280 // ...try to dispatch to the cell's inset.
4281 cell(cur.idx())->dispatch(cur, cmd);
4283 // When we already have a selection we want to select the whole cell
4284 // before going to the next cell.
4285 if (select_whole && !empty_cell){
4286 getText(cur.idx())->selectAll(cur);
4288 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
4292 // FIXME: When we support the selection of an empty cell, remove
4293 // the !empty_cell from this condition. For now we jump to the next
4294 // cell if the current cell is empty.
4295 if (cur.result().dispatched() && !empty_cell)
4299 // move to next/prev cell, as appropriate
4300 // note that we will always do this if we're selecting and we have
4301 // a multicell selection
4302 LYXERR(Debug::RTL, "entering " << (next_cell ? "next" : "previous")
4303 << " cell from: " << int(entry_from));
4305 moveNextCell(cur, entry_from);
4307 movePrevCell(cur, entry_from);
4308 // if we're exiting the table, call the appropriate FINISHED lfun
4309 if (sl == cur.top()) {
4310 cmd = FuncRequest(finish_lfun);
4315 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
4320 case LFUN_DOWN_SELECT:
4322 if (!(cur.selection() && cur.selIsMultiCell()))
4323 cell(cur.idx())->dispatch(cur, cmd);
4325 cur.dispatched(); // override the cell's decision
4326 if (sl == cur.top()) {
4327 // if our Text didn't do anything to the cursor
4328 // then we try to put the cursor into the cell below
4329 // setting also the right targetX.
4330 cur.selHandle(act == LFUN_DOWN_SELECT);
4331 if (tabular.cellRow(cur.idx()) != tabular.nrows() - 1) {
4332 int const xtarget = cur.targetX();
4333 // WARNING: Once cur.idx() has been reset, the cursor is in
4334 // an inconsistent state until pos() has been set. Be careful
4335 // what you do with it!
4336 cur.idx() = tabular.cellBelow(cur.idx());
4338 TextMetrics const & tm =
4339 cur.bv().textMetrics(cell(cur.idx())->getText(0));
4340 cur.pos() = tm.x2pos(cur.pit(), 0, xtarget);
4341 cur.setCurrentFont();
4344 if (sl == cur.top()) {
4345 // we trick it to go to forward after leaving the
4347 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
4350 if (cur.selIsMultiCell()) {
4351 cur.pit() = cur.lastpit();
4352 cur.pos() = cur.lastpos();
4353 cur.setCurrentFont();
4354 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
4357 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
4360 case LFUN_UP_SELECT:
4362 if (!(cur.selection() && cur.selIsMultiCell()))
4363 cell(cur.idx())->dispatch(cur, cmd);
4364 cur.dispatched(); // override the cell's decision
4365 if (sl == cur.top()) {
4366 // if our Text didn't do anything to the cursor
4367 // then we try to put the cursor into the cell above
4368 // setting also the right targetX.
4369 cur.selHandle(act == LFUN_UP_SELECT);
4370 if (tabular.cellRow(cur.idx()) != 0) {
4371 int const xtarget = cur.targetX();
4372 // WARNING: Once cur.idx() has been reset, the cursor is in
4373 // an inconsistent state until pos() has been set. Be careful
4374 // what you do with it!
4375 cur.idx() = tabular.cellAbove(cur.idx());
4376 cur.pit() = cur.lastpit();
4377 Text const * text = cell(cur.idx())->getText(0);
4378 TextMetrics const & tm = cur.bv().textMetrics(text);
4379 ParagraphMetrics const & pm =
4380 tm.parMetrics(cur.lastpit());
4381 cur.pos() = tm.x2pos(cur.pit(), pm.rows().size()-1, xtarget);
4382 cur.setCurrentFont();
4385 if (sl == cur.top()) {
4386 cmd = FuncRequest(LFUN_UP);
4389 if (cur.selIsMultiCell()) {
4391 cur.pos() = cur.lastpos();
4392 cur.setCurrentFont();
4393 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
4396 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
4399 case LFUN_LAYOUT_TABULAR:
4400 cur.bv().showDialog("tabular");
4403 case LFUN_INSET_MODIFY:
4404 // we come from the dialog
4405 if (cmd.getArg(0) == "tabular")
4406 tabularFeatures(cur, cmd.getLongArg(1));
4411 case LFUN_TABULAR_FEATURE:
4412 tabularFeatures(cur, to_utf8(cmd.argument()));
4415 // insert file functions
4416 case LFUN_FILE_INSERT_PLAINTEXT_PARA:
4417 case LFUN_FILE_INSERT_PLAINTEXT:
4419 if (FileName::isAbsolute(to_utf8(cmd.argument()))) {
4420 docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
4421 FileName(to_utf8(cmd.argument())));
4424 cur.recordUndoInset();
4425 if (insertPlaintextString(cur.bv(), tmpstr, false)) {
4426 // content has been replaced,
4427 // so cursor might be invalid
4428 cur.pos() = cur.lastpos();
4429 cur.pit() = cur.lastpit();
4430 bvcur.setCursor(cur);
4437 if (cur.selIsMultiCell()) {
4438 if (copySelection(cur)) {
4439 cur.recordUndoInset();
4443 cell(cur.idx())->dispatch(cur, cmd);
4446 case LFUN_SELF_INSERT:
4447 if (cur.selIsMultiCell()) {
4448 cur.recordUndoInset();
4450 BufferView * bv = &cur.bv();
4451 docstring::const_iterator cit = cmd.argument().begin();
4452 docstring::const_iterator const end = cmd.argument().end();
4453 for (; cit != end; ++cit)
4454 bv->translateAndInsert(*cit, getText(cur.idx()), cur);
4457 bv->bookmarkEditPosition();
4459 cell(cur.idx())->dispatch(cur, cmd);
4462 case LFUN_CHAR_DELETE_BACKWARD:
4463 case LFUN_CHAR_DELETE_FORWARD:
4464 if (cur.selIsMultiCell()) {
4465 cur.recordUndoInset();
4468 cell(cur.idx())->dispatch(cur, cmd);
4472 if (!cur.selection())
4474 if (cur.selIsMultiCell()) {
4478 cell(cur.idx())->dispatch(cur, cmd);
4481 case LFUN_CLIPBOARD_PASTE:
4482 case LFUN_PRIMARY_SELECTION_PASTE: {
4483 docstring const clip = (act == LFUN_CLIPBOARD_PASTE) ?
4484 theClipboard().getAsText(Clipboard::PlainTextType) :
4485 theSelection().get();
4488 // pass to InsertPlaintextString, but
4489 // only if we have multi-cell content
4490 if (clip.find_first_of(from_ascii("\t\n")) != docstring::npos) {
4491 cur.recordUndoInset();
4492 if (insertPlaintextString(cur.bv(), clip, false)) {
4493 // content has been replaced,
4494 // so cursor might be invalid
4495 cur.pos() = cur.lastpos();
4496 cur.pit() = cur.lastpit();
4497 bvcur.setCursor(cur);
4501 // Let the cell handle normal text
4502 cell(cur.idx())->dispatch(cur, cmd);
4507 if (!tabularStackDirty()) {
4508 if (!cur.selIsMultiCell())
4509 cell(cur.idx())->dispatch(cur, cmd);
4512 if (theClipboard().isInternal()) {
4513 cur.recordUndoInset();
4514 pasteClipboard(cur);
4518 case LFUN_FONT_EMPH:
4519 case LFUN_FONT_BOLD:
4520 case LFUN_FONT_BOLDSYMBOL:
4521 case LFUN_FONT_ROMAN:
4522 case LFUN_FONT_NOUN:
4523 case LFUN_FONT_ITAL:
4524 case LFUN_FONT_FRAK:
4525 case LFUN_FONT_TYPEWRITER:
4526 case LFUN_FONT_SANS:
4527 case LFUN_TEXTSTYLE_APPLY:
4528 case LFUN_TEXTSTYLE_UPDATE:
4529 case LFUN_FONT_SIZE:
4530 case LFUN_FONT_UNDERLINE:
4531 case LFUN_FONT_STRIKEOUT:
4532 case LFUN_FONT_CROSSOUT:
4533 case LFUN_FONT_UNDERUNDERLINE:
4534 case LFUN_FONT_UNDERWAVE:
4536 case LFUN_PARAGRAPH_PARAMS_APPLY:
4537 case LFUN_PARAGRAPH_PARAMS:
4538 case LFUN_WORD_CAPITALIZE:
4539 case LFUN_WORD_UPCASE:
4540 case LFUN_WORD_LOWCASE:
4541 case LFUN_CHARS_TRANSPOSE:
4542 if (cur.selIsMultiCell()) {
4545 getSelection(cur, rs, re, cs, ce);
4546 Cursor tmpcur = cur;
4547 for (row_type r = rs; r <= re; ++r) {
4548 for (col_type c = cs; c <= ce; ++c) {
4549 // cursor follows cell:
4550 tmpcur.idx() = tabular.cellIndex(r, c);
4551 // select this cell only:
4554 tmpcur.resetAnchor();
4555 tmpcur.pit() = tmpcur.lastpit();
4556 tmpcur.pos() = tmpcur.top().lastpos();
4557 tmpcur.setCursor(tmpcur);
4558 tmpcur.setSelection();
4559 cell(tmpcur.idx())->dispatch(tmpcur, cmd);
4564 cell(cur.idx())->dispatch(cur, cmd);
4568 case LFUN_INSET_SETTINGS:
4569 // relay this lfun to Inset, not to the cell.
4570 Inset::doDispatch(cur, cmd);
4574 // we try to handle this event in the insets dispatch function.
4575 cell(cur.idx())->dispatch(cur, cmd);
4581 bool InsetTabular::getFeatureStatus(Cursor & cur, string const & s,
4582 string const & argument, FuncStatus & status) const
4585 int action = Tabular::LAST_ACTION;
4587 for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
4588 if (tabularFeature[i].feature == s) {
4589 action = tabularFeature[i].action;
4593 if (action == Tabular::LAST_ACTION) {
4595 status.setUnknown(true);
4599 row_type sel_row_start = 0;
4600 row_type sel_row_end = 0;
4601 col_type sel_col_start = 0;
4602 col_type sel_col_end = 0;
4603 Tabular::ltType dummyltt;
4606 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
4609 case Tabular::SET_PWIDTH:
4610 case Tabular::SET_MPWIDTH:
4611 case Tabular::SET_SPECIAL_COLUMN:
4612 case Tabular::SET_SPECIAL_MULTICOLUMN:
4613 case Tabular::APPEND_ROW:
4614 case Tabular::APPEND_COLUMN:
4615 case Tabular::DELETE_ROW:
4616 case Tabular::DELETE_COLUMN:
4617 case Tabular::COPY_ROW:
4618 case Tabular::COPY_COLUMN:
4619 case Tabular::SET_TOP_SPACE:
4620 case Tabular::SET_BOTTOM_SPACE:
4621 case Tabular::SET_INTERLINE_SPACE:
4625 case Tabular::SET_TABULAR_WIDTH:
4626 status.setEnabled(!tabular.rotate && !tabular.is_long_tabular
4627 && tabular.tabular_valignment == Tabular::LYX_VALIGN_MIDDLE);
4630 case Tabular::MOVE_COLUMN_RIGHT:
4631 case Tabular::MOVE_COLUMN_LEFT:
4632 case Tabular::MOVE_ROW_DOWN:
4633 case Tabular::MOVE_ROW_UP: {
4634 if (cur.selection()) {
4635 status.message(_("Selections not supported."));
4636 status.setEnabled(false);
4640 if ((action == Tabular::MOVE_COLUMN_RIGHT &&
4641 tabular.ncols() == tabular.cellColumn(cur.idx()) + 1) ||
4642 (action == Tabular::MOVE_COLUMN_LEFT &&
4643 tabular.cellColumn(cur.idx()) == 0) ||
4644 (action == Tabular::MOVE_ROW_DOWN &&
4645 tabular.nrows() == tabular.cellRow(cur.idx()) + 1) ||
4646 (action == Tabular::MOVE_ROW_UP &&
4647 tabular.cellRow(cur.idx()) == 0)) {
4648 status.setEnabled(false);
4652 if (action == Tabular::MOVE_COLUMN_RIGHT ||
4653 action == Tabular::MOVE_COLUMN_LEFT) {
4654 if (tabular.hasMultiColumn(tabular.cellColumn(cur.idx())) ||
4655 tabular.hasMultiColumn(tabular.cellColumn(cur.idx()) +
4656 (action == Tabular::MOVE_COLUMN_RIGHT ? 1 : -1))) {
4657 status.message(_("Multi-column in current or"
4658 " destination column."));
4659 status.setEnabled(false);
4664 if (action == Tabular::MOVE_ROW_DOWN ||
4665 action == Tabular::MOVE_ROW_UP) {
4666 if (tabular.hasMultiRow(tabular.cellRow(cur.idx())) ||
4667 tabular.hasMultiRow(tabular.cellRow(cur.idx()) +
4668 (action == Tabular::MOVE_ROW_DOWN ? 1 : -1))) {
4669 status.message(_("Multi-row in current or"
4670 " destination row."));
4671 status.setEnabled(false);
4676 status.setEnabled(true);
4680 case Tabular::SET_DECIMAL_POINT:
4682 tabular.getAlignment(cur.idx()) == LYX_ALIGN_DECIMAL);
4685 case Tabular::SET_MULTICOLUMN:
4686 case Tabular::UNSET_MULTICOLUMN:
4687 case Tabular::MULTICOLUMN:
4688 // If a row is set as longtable caption, it must not be allowed
4689 // to unset that this row is a multicolumn.
4690 status.setEnabled(sel_row_start == sel_row_end
4691 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
4692 status.setOnOff(tabular.isMultiColumn(cur.idx()));
4695 case Tabular::SET_MULTIROW:
4696 case Tabular::UNSET_MULTIROW:
4697 case Tabular::MULTIROW:
4698 // If a row is set as longtable caption, it must not be allowed
4699 // to unset that this row is a multirow.
4700 status.setEnabled(sel_col_start == sel_col_end
4701 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
4702 status.setOnOff(tabular.isMultiRow(cur.idx()));
4705 case Tabular::SET_ALL_LINES:
4706 case Tabular::UNSET_ALL_LINES:
4707 case Tabular::SET_BORDER_LINES:
4708 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4711 case Tabular::SET_LINE_TOP:
4712 case Tabular::SET_LINE_BOTTOM:
4713 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4716 case Tabular::SET_LINE_LEFT:
4717 case Tabular::SET_LINE_RIGHT:
4718 status.setEnabled(!tabular.use_booktabs
4719 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
4722 case Tabular::TOGGLE_LINE_TOP:
4723 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4724 status.setOnOff(tabular.topLine(cur.idx()));
4727 case Tabular::TOGGLE_LINE_BOTTOM:
4728 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4729 status.setOnOff(tabular.bottomLine(cur.idx()));
4732 case Tabular::TOGGLE_LINE_LEFT:
4733 status.setEnabled(!tabular.use_booktabs
4734 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
4735 status.setOnOff(tabular.leftLine(cur.idx()));
4738 case Tabular::TOGGLE_LINE_RIGHT:
4739 status.setEnabled(!tabular.use_booktabs
4740 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
4741 status.setOnOff(tabular.rightLine(cur.idx()));
4744 // multirow cells only inherit the alignment of the column if the column has
4745 // no width, otherwise they are left-aligned
4746 // therefore allow always left but right and center only if there is no width
4747 case Tabular::M_ALIGN_LEFT:
4750 case Tabular::ALIGN_LEFT:
4751 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_LEFT);
4754 case Tabular::M_ALIGN_RIGHT:
4757 case Tabular::ALIGN_RIGHT:
4758 status.setEnabled(!(tabular.isMultiRow(cur.idx())
4759 && !tabular.getPWidth(cur.idx()).zero()));
4760 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_RIGHT);
4763 case Tabular::M_ALIGN_CENTER:
4766 case Tabular::ALIGN_CENTER:
4767 status.setEnabled(!(tabular.isMultiRow(cur.idx())
4768 && !tabular.getPWidth(cur.idx()).zero()));
4769 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_CENTER);
4772 case Tabular::ALIGN_BLOCK:
4773 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4774 && !tabular.isMultiRow(cur.idx()));
4775 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_BLOCK);
4778 case Tabular::ALIGN_DECIMAL:
4779 status.setEnabled(!tabular.isMultiRow(cur.idx())
4780 && !tabular.isMultiColumn(cur.idx()));
4781 status.setOnOff(tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_DECIMAL);
4784 case Tabular::M_VALIGN_TOP:
4787 case Tabular::VALIGN_TOP:
4788 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4789 && !tabular.isMultiRow(cur.idx()));
4791 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_TOP);
4794 case Tabular::M_VALIGN_BOTTOM:
4797 case Tabular::VALIGN_BOTTOM:
4798 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4799 && !tabular.isMultiRow(cur.idx()));
4801 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_BOTTOM);
4804 case Tabular::M_VALIGN_MIDDLE:
4807 case Tabular::VALIGN_MIDDLE:
4808 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4809 && !tabular.isMultiRow(cur.idx()));
4811 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_MIDDLE);
4814 case Tabular::SET_LONGTABULAR:
4815 case Tabular::TOGGLE_LONGTABULAR:
4816 // setting as longtable is not allowed when table is inside a float
4817 if (cur.innerInsetOfType(FLOAT_CODE) != 0
4818 || cur.innerInsetOfType(WRAP_CODE) != 0)
4819 status.setEnabled(false);
4821 status.setEnabled(true);
4822 status.setOnOff(tabular.is_long_tabular);
4825 case Tabular::UNSET_LONGTABULAR:
4826 status.setOnOff(!tabular.is_long_tabular);
4829 case Tabular::TOGGLE_ROTATE_TABULAR:
4830 case Tabular::SET_ROTATE_TABULAR:
4831 status.setOnOff(tabular.rotate != 0);
4834 case Tabular::TABULAR_VALIGN_TOP:
4835 status.setEnabled(tabular.tabular_width.zero());
4836 status.setOnOff(tabular.tabular_valignment
4837 == Tabular::LYX_VALIGN_TOP);
4839 case Tabular::TABULAR_VALIGN_MIDDLE:
4840 status.setEnabled(tabular.tabular_width.zero());
4841 status.setOnOff(tabular.tabular_valignment
4842 == Tabular::LYX_VALIGN_MIDDLE);
4844 case Tabular::TABULAR_VALIGN_BOTTOM:
4845 status.setEnabled(tabular.tabular_width.zero());
4846 status.setOnOff(tabular.tabular_valignment
4847 == Tabular::LYX_VALIGN_BOTTOM);
4850 case Tabular::LONGTABULAR_ALIGN_LEFT:
4851 status.setOnOff(tabular.longtabular_alignment
4852 == Tabular::LYX_LONGTABULAR_ALIGN_LEFT);
4854 case Tabular::LONGTABULAR_ALIGN_CENTER:
4855 status.setOnOff(tabular.longtabular_alignment
4856 == Tabular::LYX_LONGTABULAR_ALIGN_CENTER);
4858 case Tabular::LONGTABULAR_ALIGN_RIGHT:
4859 status.setOnOff(tabular.longtabular_alignment
4860 == Tabular::LYX_LONGTABULAR_ALIGN_RIGHT);
4863 case Tabular::UNSET_ROTATE_TABULAR:
4864 status.setOnOff(tabular.rotate == 0);
4867 case Tabular::TOGGLE_ROTATE_CELL:
4868 case Tabular::SET_ROTATE_CELL:
4869 status.setOnOff(!oneCellHasRotationState(false,
4870 sel_row_start, sel_row_end, sel_col_start, sel_col_end));
4873 case Tabular::UNSET_ROTATE_CELL:
4874 status.setOnOff(!oneCellHasRotationState(true,
4875 sel_row_start, sel_row_end, sel_col_start, sel_col_end));
4878 case Tabular::SET_USEBOX:
4879 status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
4882 // every row can only be one thing:
4883 // either a footer or header
4884 case Tabular::SET_LTFIRSTHEAD:
4885 status.setEnabled(sel_row_start == sel_row_end);
4886 status.setOnOff(tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
4889 case Tabular::UNSET_LTFIRSTHEAD:
4890 status.setEnabled(sel_row_start == sel_row_end);
4891 status.setOnOff(!tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
4894 case Tabular::SET_LTHEAD:
4895 status.setEnabled(sel_row_start == sel_row_end);
4896 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
4899 case Tabular::UNSET_LTHEAD:
4900 status.setEnabled(sel_row_start == sel_row_end);
4901 status.setOnOff(!tabular.getRowOfLTHead(sel_row_start, dummyltt));
4904 case Tabular::SET_LTFOOT:
4905 status.setEnabled(sel_row_start == sel_row_end);
4906 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
4909 case Tabular::UNSET_LTFOOT:
4910 status.setEnabled(sel_row_start == sel_row_end);
4911 status.setOnOff(!tabular.getRowOfLTFoot(sel_row_start, dummyltt));
4914 case Tabular::SET_LTLASTFOOT:
4915 status.setEnabled(sel_row_start == sel_row_end);
4916 status.setOnOff(tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
4919 case Tabular::UNSET_LTLASTFOOT:
4920 status.setEnabled(sel_row_start == sel_row_end);
4921 status.setOnOff(!tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
4924 case Tabular::SET_LTNEWPAGE:
4925 status.setOnOff(tabular.getLTNewPage(sel_row_start));
4927 case Tabular::UNSET_LTNEWPAGE:
4928 status.setOnOff(!tabular.getLTNewPage(sel_row_start));
4931 // only one row in head/firsthead/foot/lasthead can be the caption
4932 // and a multirow cannot be set as caption
4933 case Tabular::SET_LTCAPTION:
4934 status.setEnabled(sel_row_start == sel_row_end
4935 && (!tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
4936 || !tabular.haveLTCaption(Tabular::CAPTION_FIRSTHEAD))
4937 && (!tabular.getRowOfLTHead(sel_row_start, dummyltt)
4938 || !tabular.haveLTCaption(Tabular::CAPTION_HEAD))
4939 && (!tabular.getRowOfLTFoot(sel_row_start, dummyltt)
4940 || !tabular.haveLTCaption(Tabular::CAPTION_FOOT))
4941 && (!tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
4942 || !tabular.haveLTCaption(Tabular::CAPTION_LASTFOOT))
4943 && !tabular.isMultiRow(sel_row_start));
4944 status.setOnOff(tabular.ltCaption(sel_row_start));
4947 case Tabular::UNSET_LTCAPTION:
4948 status.setEnabled(sel_row_start == sel_row_end && tabular.ltCaption(sel_row_start));
4951 case Tabular::TOGGLE_LTCAPTION:
4952 status.setEnabled(sel_row_start == sel_row_end && (tabular.ltCaption(sel_row_start)
4953 || ((!tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
4954 || !tabular.haveLTCaption(Tabular::CAPTION_FIRSTHEAD))
4955 && (!tabular.getRowOfLTHead(sel_row_start, dummyltt)
4956 || !tabular.haveLTCaption(Tabular::CAPTION_HEAD))
4957 && (!tabular.getRowOfLTFoot(sel_row_start, dummyltt)
4958 || !tabular.haveLTCaption(Tabular::CAPTION_FOOT))
4959 && (!tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
4960 || !tabular.haveLTCaption(Tabular::CAPTION_LASTFOOT)))));
4961 status.setOnOff(tabular.ltCaption(sel_row_start));
4964 case Tabular::TOGGLE_BOOKTABS:
4965 case Tabular::SET_BOOKTABS:
4966 status.setOnOff(tabular.use_booktabs);
4969 case Tabular::UNSET_BOOKTABS:
4970 status.setOnOff(!tabular.use_booktabs);
4975 status.setEnabled(false);
4982 // function sets an object as defined in FuncStatus.h:
4983 // states OK, Unknown, Disabled, On, Off.
4984 bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
4985 FuncStatus & status) const
4987 switch (cmd.action()) {
4988 case LFUN_INSET_MODIFY:
4989 if (cmd.getArg(0) != "tabular")
4991 if (cmd.getArg(1) == "for-dialog") {
4992 // The dialog is asking the status of a command
4993 if (&cur.inset() != this)
4995 string action = cmd.getArg(2);
4996 string arg = cmd.getLongArg(3);
4997 return getFeatureStatus(cur, action, arg, status);
4999 // We always enable the lfun if it is coming from the dialog
5000 // because the dialog makes sure all the settings are valid,
5001 // even though the first argument might not be valid now.
5002 status.setEnabled(true);
5006 case LFUN_TABULAR_FEATURE: {
5007 if (&cur.inset() != this)
5009 string action = cmd.getArg(0);
5010 string arg = cmd.getLongArg(1);
5011 return getFeatureStatus(cur, action, arg, status);
5014 case LFUN_CAPTION_INSERT: {
5015 // caption is only allowed in caption cell of longtable
5016 if (!tabular.ltCaption(tabular.cellRow(cur.idx()))) {
5017 status.setEnabled(false);
5020 // only standard caption is allowed
5021 string arg = cmd.getArg(0);
5022 if (!arg.empty() && arg != "Standard") {
5023 status.setEnabled(false);
5026 // check if there is already a caption
5027 bool have_caption = false;
5028 InsetTableCell itc = InsetTableCell(*tabular.cellInset(cur.idx()));
5029 ParagraphList::const_iterator pit = itc.paragraphs().begin();
5030 ParagraphList::const_iterator pend = itc.paragraphs().end();
5031 for (; pit != pend; ++pit) {
5032 InsetList::const_iterator it = pit->insetList().begin();
5033 InsetList::const_iterator end = pit->insetList().end();
5034 for (; it != end; ++it) {
5035 if (it->inset->lyxCode() == CAPTION_CODE) {
5036 have_caption = true;
5041 status.setEnabled(!have_caption);
5045 // These are only enabled inside tabular
5046 case LFUN_CELL_BACKWARD:
5047 case LFUN_CELL_FORWARD:
5048 status.setEnabled(true);
5051 // disable these with multiple cells selected
5052 case LFUN_INSET_INSERT:
5053 case LFUN_TABULAR_INSERT:
5054 case LFUN_FLEX_INSERT:
5055 case LFUN_FLOAT_INSERT:
5056 case LFUN_FLOAT_WIDE_INSERT:
5057 case LFUN_FOOTNOTE_INSERT:
5058 case LFUN_MARGINALNOTE_INSERT:
5059 case LFUN_MATH_INSERT:
5060 case LFUN_MATH_MODE:
5061 case LFUN_MATH_MUTATE:
5062 case LFUN_MATH_DISPLAY:
5063 case LFUN_NOTE_INSERT:
5064 case LFUN_ARGUMENT_INSERT:
5065 case LFUN_BOX_INSERT:
5066 case LFUN_BRANCH_INSERT:
5067 case LFUN_PHANTOM_INSERT:
5068 case LFUN_WRAP_INSERT:
5069 case LFUN_PREVIEW_INSERT:
5070 case LFUN_ERT_INSERT: {
5071 if (cur.selIsMultiCell()) {
5072 status.setEnabled(false);
5075 return cell(cur.idx())->getStatus(cur, cmd, status);
5078 // disable in non-fixed-width cells
5079 case LFUN_PARAGRAPH_BREAK:
5080 // multirow does not allow paragraph breaks
5081 if (tabular.isMultiRow(cur.idx())) {
5082 status.setEnabled(false);
5086 case LFUN_NEWLINE_INSERT: {
5087 if (tabular.getPWidth(cur.idx()).zero()) {
5088 status.setEnabled(false);
5091 return cell(cur.idx())->getStatus(cur, cmd, status);
5094 case LFUN_NEWPAGE_INSERT:
5095 status.setEnabled(false);
5099 if (tabularStackDirty() && theClipboard().isInternal()) {
5100 if (cur.selIsMultiCell()) {
5103 getSelection(cur, rs, re, cs, ce);
5104 if (paste_tabular && paste_tabular->ncols() == ce - cs + 1
5105 && paste_tabular->nrows() == re - rs + 1)
5106 status.setEnabled(true);
5108 status.setEnabled(false);
5109 status.message(_("Selection size should match clipboard content."));
5112 status.setEnabled(true);
5115 return cell(cur.idx())->getStatus(cur, cmd, status);
5117 case LFUN_INSET_SETTINGS:
5118 // relay this lfun to Inset, not to the cell.
5119 return Inset::getStatus(cur, cmd, status);
5122 // we try to handle this event in the insets dispatch function.
5123 return cell(cur.idx())->getStatus(cur, cmd, status);
5129 Inset::DisplayType InsetTabular::display() const
5131 if (tabular.is_long_tabular) {
5132 switch (tabular.longtabular_alignment) {
5133 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
5135 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
5137 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
5147 void InsetTabular::latex(otexstream & os, OutputParams const & runparams) const
5149 tabular.latex(os, runparams);
5153 int InsetTabular::plaintext(odocstringstream & os,
5154 OutputParams const & runparams, size_t max_length) const
5156 os << '\n'; // output table on a new line
5157 int const dp = runparams.linelen > 0 ? runparams.depth : 0;
5158 tabular.plaintext(os, runparams, dp, false, 0, max_length);
5159 return PLAINTEXT_NEWLINE;
5163 int InsetTabular::docbook(odocstream & os, OutputParams const & runparams) const
5168 // FIXME: Why not pass a proper DocIterator here?
5170 // if the table is inside a float it doesn't need the informaltable
5171 // wrapper. Search for it.
5172 for (master = owner(); master; master = master->owner())
5173 if (master->lyxCode() == FLOAT_CODE)
5178 os << "<informaltable>";
5181 ret += tabular.docbook(os, runparams);
5183 os << "</informaltable>";
5190 docstring InsetTabular::xhtml(XHTMLStream & xs, OutputParams const & rp) const
5192 return tabular.xhtml(xs, rp);
5196 void InsetTabular::validate(LaTeXFeatures & features) const
5198 tabular.validate(features);
5199 features.useInsetLayout(getLayout());
5203 shared_ptr<InsetTableCell const> InsetTabular::cell(idx_type idx) const
5205 return tabular.cellInset(idx);
5209 shared_ptr<InsetTableCell> InsetTabular::cell(idx_type idx)
5211 return tabular.cellInset(idx);
5215 void InsetTabular::cursorPos(BufferView const & bv,
5216 CursorSlice const & sl, bool boundary, int & x, int & y) const
5218 cell(sl.idx())->cursorPos(bv, sl, boundary, x, y);
5220 // y offset correction
5221 y += cellYPos(sl.idx());
5222 y += tabular.textVOffset(sl.idx());
5223 y += tabular.offsetVAlignment();
5225 // x offset correction
5226 x += cellXPos(sl.idx());
5227 x += tabular.textHOffset(sl.idx());
5228 x += ADD_TO_TABULAR_WIDTH;
5232 int InsetTabular::dist(BufferView & bv, idx_type const cell, int x, int y) const
5236 Inset const & inset = *tabular.cellInset(cell);
5237 Point o = bv.coordCache().getInsets().xy(&inset);
5238 int const xbeg = o.x_ - tabular.textHOffset(cell);
5239 int const xend = xbeg + tabular.cellWidth(cell);
5240 row_type const row = tabular.cellRow(cell);
5241 int const ybeg = o.y_ - tabular.rowAscent(row)
5242 - tabular.interRowSpace(row) - tabular.textVOffset(cell);
5243 int const yend = ybeg + tabular.cellHeight(cell);
5255 //lyxerr << " xbeg=" << xbeg << " xend=" << xend
5256 // << " ybeg=" << ybeg << " yend=" << yend
5257 // << " xx=" << xx << " yy=" << yy
5258 // << " dist=" << xx + yy << endl;
5263 Inset * InsetTabular::editXY(Cursor & cur, int x, int y)
5265 //lyxerr << "InsetTabular::editXY: " << this << endl;
5267 cur.idx() = getNearestCell(cur.bv(), x, y);
5268 return cur.bv().textMetrics(&cell(cur.idx())->text()).editXY(cur, x, y);
5272 void InsetTabular::setCursorFromCoordinates(Cursor & cur, int x, int y) const
5274 cur.idx() = getNearestCell(cur.bv(), x, y);
5275 cur.bv().textMetrics(&cell(cur.idx())->text()).setCursorFromCoordinates(cur, x, y);
5279 InsetTabular::idx_type InsetTabular::getNearestCell(BufferView & bv, int x, int y) const
5281 idx_type idx_min = 0;
5282 int dist_min = numeric_limits<int>::max();
5283 for (idx_type i = 0, n = nargs(); i != n; ++i) {
5284 if (bv.coordCache().getInsets().has(tabular.cellInset(i).get())) {
5285 int const d = dist(bv, i, x, y);
5296 int InsetTabular::cellYPos(idx_type const cell) const
5298 row_type row = tabular.cellRow(cell);
5300 for (row_type r = 0; r < row; ++r)
5301 ly += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
5302 + tabular.interRowSpace(r + 1);
5307 int InsetTabular::cellXPos(idx_type const cell) const
5309 col_type col = tabular.cellColumn(cell);
5311 for (col_type c = 0; c < col; ++c)
5312 lx += tabular.column_info[c].width;
5317 void InsetTabular::moveNextCell(Cursor & cur, EntryDirection entry_from)
5319 row_type const row = tabular.cellRow(cur.idx());
5320 col_type const col = tabular.cellColumn(cur.idx());
5322 if (isRightToLeft(cur)) {
5323 if (tabular.cellColumn(cur.idx()) == 0) {
5324 if (row == tabular.nrows() - 1)
5326 cur.idx() = tabular.cellBelow(tabular.getLastCellInRow(row));
5331 cur.idx() = tabular.getLastCellInRow(row - 1);
5333 cur.idx() = tabular.cellIndex(row, col - 1);
5336 if (tabular.isLastCell(cur.idx()))
5338 if (cur.idx() == tabular.getLastCellInRow(row))
5339 cur.idx() = tabular.cellIndex(row + 1, 0);
5341 col_type const colnextcell = col + tabular.columnSpan(cur.idx());
5342 cur.idx() = tabular.cellIndex(row, colnextcell);
5346 cur.boundary(false);
5348 if (cur.selIsMultiCell()) {
5349 cur.pit() = cur.lastpit();
5350 cur.pos() = cur.lastpos();
5357 // in visual mode, place cursor at extreme left or right
5359 switch(entry_from) {
5361 case ENTRY_DIRECTION_RIGHT:
5362 cur.posVisToRowExtremity(false /* !left */);
5364 case ENTRY_DIRECTION_LEFT:
5365 cur.posVisToRowExtremity(true /* left */);
5367 case ENTRY_DIRECTION_IGNORE:
5368 // nothing to do in this case
5372 cur.setCurrentFont();
5376 void InsetTabular::movePrevCell(Cursor & cur, EntryDirection entry_from)
5378 row_type const row = tabular.cellRow(cur.idx());
5379 col_type const col = tabular.cellColumn(cur.idx());
5381 if (isRightToLeft(cur)) {
5382 if (cur.idx() == tabular.getLastCellInRow(row)) {
5385 cur.idx() = tabular.getFirstCellInRow(row);
5386 cur.idx() = tabular.cellAbove(cur.idx());
5388 if (tabular.isLastCell(cur.idx()))
5390 if (cur.idx() == tabular.getLastCellInRow(row))
5391 cur.idx() = tabular.cellIndex(row + 1, 0);
5393 cur.idx() = tabular.cellIndex(row, col + 1);
5396 if (cur.idx() == 0) // first cell
5399 cur.idx() = tabular.getLastCellInRow(row - 1);
5401 cur.idx() = tabular.cellIndex(row, col - 1);
5404 if (cur.selIsMultiCell()) {
5405 cur.pit() = cur.lastpit();
5406 cur.pos() = cur.lastpos();
5410 cur.pit() = cur.lastpit();
5411 cur.pos() = cur.lastpos();
5413 // in visual mode, place cursor at extreme left or right
5415 switch(entry_from) {
5417 case ENTRY_DIRECTION_RIGHT:
5418 cur.posVisToRowExtremity(false /* !left */);
5420 case ENTRY_DIRECTION_LEFT:
5421 cur.posVisToRowExtremity(true /* left */);
5423 case ENTRY_DIRECTION_IGNORE:
5424 // nothing to do in this case
5428 cur.setCurrentFont();
5432 void InsetTabular::tabularFeatures(Cursor & cur, string const & argument)
5434 cur.recordUndoInset(this);
5436 istringstream is(argument);
5437 // limit the size of strings we read to avoid memory problems
5441 size_t safe_guard = 0;
5446 if (safe_guard > 1000) {
5447 LYXERR0("parameter max count reached!");
5451 Tabular::Feature action = Tabular::LAST_ACTION;
5454 for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
5455 if (s != tabularFeature[i].feature)
5457 action = tabularFeature[i].action;
5460 if (action == Tabular::LAST_ACTION) {
5461 LYXERR0("Feature not found " << s);
5465 if (tabularFeature[i].need_value)
5467 LYXERR(Debug::DEBUG, "Feature: " << s << "\t\tvalue: " << val);
5468 tabularFeatures(cur, action, val);
5473 static void checkLongtableSpecial(Tabular::ltType & ltt,
5474 string const & special, bool & flag)
5476 if (special == "dl_above") {
5479 } else if (special == "dl_below") {
5480 ltt.bottomDL = flag;
5482 } else if (special == "empty") {
5492 bool InsetTabular::oneCellHasRotationState(bool rotated,
5493 row_type row_start, row_type row_end,
5494 col_type col_start, col_type col_end) const
5496 for (row_type r = row_start; r <= row_end; ++r)
5497 for (col_type c = col_start; c <= col_end; ++c)
5499 if (tabular.getRotateCell(tabular.cellIndex(r, c)) != 0)
5502 if (tabular.getRotateCell(tabular.cellIndex(r, c)) == 0)
5509 void InsetTabular::tabularFeatures(Cursor & cur,
5510 Tabular::Feature feature, string const & value)
5512 col_type sel_col_start;
5513 col_type sel_col_end;
5514 row_type sel_row_start;
5515 row_type sel_row_end;
5516 bool setLines = false;
5517 LyXAlignment setAlign = LYX_ALIGN_LEFT;
5518 Tabular::VAlignment setVAlign = Tabular::LYX_VALIGN_TOP;
5522 case Tabular::M_ALIGN_LEFT:
5523 case Tabular::ALIGN_LEFT:
5524 setAlign = LYX_ALIGN_LEFT;
5527 case Tabular::M_ALIGN_RIGHT:
5528 case Tabular::ALIGN_RIGHT:
5529 setAlign = LYX_ALIGN_RIGHT;
5532 case Tabular::M_ALIGN_CENTER:
5533 case Tabular::ALIGN_CENTER:
5534 setAlign = LYX_ALIGN_CENTER;
5537 case Tabular::ALIGN_BLOCK:
5538 setAlign = LYX_ALIGN_BLOCK;
5541 case Tabular::ALIGN_DECIMAL:
5542 setAlign = LYX_ALIGN_DECIMAL;
5545 case Tabular::M_VALIGN_TOP:
5546 case Tabular::VALIGN_TOP:
5547 setVAlign = Tabular::LYX_VALIGN_TOP;
5550 case Tabular::M_VALIGN_BOTTOM:
5551 case Tabular::VALIGN_BOTTOM:
5552 setVAlign = Tabular::LYX_VALIGN_BOTTOM;
5555 case Tabular::M_VALIGN_MIDDLE:
5556 case Tabular::VALIGN_MIDDLE:
5557 setVAlign = Tabular::LYX_VALIGN_MIDDLE;
5564 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
5565 row_type const row = tabular.cellRow(cur.idx());
5566 col_type const column = tabular.cellColumn(cur.idx());
5568 Tabular::ltType ltt;
5572 case Tabular::SET_TABULAR_WIDTH:
5573 tabular.setTabularWidth(Length(value));
5576 case Tabular::SET_PWIDTH: {
5577 Length const len(value);
5578 tabular.setColumnPWidth(cur, cur.idx(), len);
5580 && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
5581 tabularFeatures(cur, Tabular::ALIGN_CENTER, string());
5585 case Tabular::SET_MPWIDTH:
5586 tabular.setMColumnPWidth(cur, cur.idx(), Length(value));
5589 case Tabular::SET_MROFFSET:
5590 tabular.setMROffset(cur, cur.idx(), Length(value));
5593 case Tabular::SET_SPECIAL_COLUMN:
5594 case Tabular::SET_SPECIAL_MULTICOLUMN:
5595 if (value == "none")
5596 tabular.setAlignSpecial(cur.idx(), docstring(), feature);
5598 tabular.setAlignSpecial(cur.idx(), from_utf8(value), feature);
5601 case Tabular::APPEND_ROW:
5602 // append the row into the tabular
5603 tabular.appendRow(row);
5606 case Tabular::APPEND_COLUMN:
5607 // append the column into the tabular
5608 tabular.appendColumn(column);
5609 cur.idx() = tabular.cellIndex(row, column);
5612 case Tabular::DELETE_ROW:
5613 if (sel_row_end == tabular.nrows() - 1 && sel_row_start != 0) {
5614 for (col_type c = 0; c < tabular.ncols(); c++)
5615 tabular.setBottomLine(tabular.cellIndex(sel_row_start - 1, c),
5616 tabular.bottomLine(tabular.cellIndex(sel_row_end, c)));
5619 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5620 tabular.deleteRow(sel_row_start);
5621 if (sel_row_start >= tabular.nrows())
5623 cur.idx() = tabular.cellIndex(sel_row_start, column);
5626 cur.selection(false);
5629 case Tabular::DELETE_COLUMN:
5630 if (sel_col_end == tabular.ncols() - 1 && sel_col_start != 0) {
5631 for (row_type r = 0; r < tabular.nrows(); r++)
5632 tabular.setRightLine(tabular.cellIndex(r, sel_col_start - 1),
5633 tabular.rightLine(tabular.cellIndex(r, sel_col_end)));
5636 if (sel_col_start == 0 && sel_col_end != tabular.ncols() - 1) {
5637 for (row_type r = 0; r < tabular.nrows(); r++)
5638 tabular.setLeftLine(tabular.cellIndex(r, sel_col_end + 1),
5639 tabular.leftLine(tabular.cellIndex(r, 0)));
5642 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5643 tabular.deleteColumn(sel_col_start);
5644 if (sel_col_start >= tabular.ncols())
5646 cur.idx() = tabular.cellIndex(row, sel_col_start);
5649 cur.selection(false);
5652 case Tabular::COPY_ROW:
5653 tabular.copyRow(row);
5656 case Tabular::COPY_COLUMN:
5657 tabular.copyColumn(column);
5658 cur.idx() = tabular.cellIndex(row, column);
5661 case Tabular::MOVE_COLUMN_RIGHT:
5662 tabular.moveColumn(column, Tabular::RIGHT);
5663 cur.idx() = tabular.cellIndex(row, column + 1);
5666 case Tabular::MOVE_COLUMN_LEFT:
5667 tabular.moveColumn(column, Tabular::LEFT);
5668 cur.idx() = tabular.cellIndex(row, column - 1);
5671 case Tabular::MOVE_ROW_DOWN:
5672 tabular.moveRow(row, Tabular::DOWN);
5673 cur.idx() = tabular.cellIndex(row + 1, column);
5676 case Tabular::MOVE_ROW_UP:
5677 tabular.moveRow(row, Tabular::UP);
5678 cur.idx() = tabular.cellIndex(row - 1, column);
5681 case Tabular::SET_LINE_TOP:
5682 case Tabular::TOGGLE_LINE_TOP: {
5683 bool lineSet = (feature == Tabular::SET_LINE_TOP)
5684 ? (value == "true") : !tabular.topLine(cur.idx());
5685 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5686 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5687 tabular.setTopLine(tabular.cellIndex(r, c), lineSet);
5691 case Tabular::SET_LINE_BOTTOM:
5692 case Tabular::TOGGLE_LINE_BOTTOM: {
5693 bool lineSet = (feature == Tabular::SET_LINE_BOTTOM)
5694 ? (value == "true") : !tabular.bottomLine(cur.idx());
5695 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5696 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5697 tabular.setBottomLine(tabular.cellIndex(r, c), lineSet);
5701 case Tabular::SET_LINE_LEFT:
5702 case Tabular::TOGGLE_LINE_LEFT: {
5703 bool lineSet = (feature == Tabular::SET_LINE_LEFT)
5704 ? (value == "true") : !tabular.leftLine(cur.idx());
5705 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5706 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5707 tabular.setLeftLine(tabular.cellIndex(r, c), lineSet);
5711 case Tabular::SET_LINE_RIGHT:
5712 case Tabular::TOGGLE_LINE_RIGHT: {
5713 bool lineSet = (feature == Tabular::SET_LINE_RIGHT)
5714 ? (value == "true") : !tabular.rightLine(cur.idx());
5715 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5716 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5717 tabular.setRightLine(tabular.cellIndex(r, c), lineSet);
5721 case Tabular::M_ALIGN_LEFT:
5722 case Tabular::M_ALIGN_RIGHT:
5723 case Tabular::M_ALIGN_CENTER:
5724 case Tabular::ALIGN_LEFT:
5725 case Tabular::ALIGN_RIGHT:
5726 case Tabular::ALIGN_CENTER:
5727 case Tabular::ALIGN_BLOCK:
5728 case Tabular::ALIGN_DECIMAL:
5729 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5730 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5731 tabular.setAlignment(tabular.cellIndex(r, c), setAlign,
5732 !tabular.getPWidth(c).zero());
5735 case Tabular::M_VALIGN_TOP:
5736 case Tabular::M_VALIGN_BOTTOM:
5737 case Tabular::M_VALIGN_MIDDLE:
5740 case Tabular::VALIGN_TOP:
5741 case Tabular::VALIGN_BOTTOM:
5742 case Tabular::VALIGN_MIDDLE:
5743 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5744 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5745 tabular.setVAlignment(tabular.cellIndex(r, c), setVAlign, flag);
5748 case Tabular::SET_MULTICOLUMN: {
5749 if (!cur.selection()) {
5750 // just multicol for one single cell
5751 // check whether we are completely in a multicol
5752 if (!tabular.isMultiColumn(cur.idx()))
5753 tabular.setMultiColumn(cur.idx(), 1,
5754 tabular.rightLine(cur.idx()));
5757 // we have a selection so this means we just add all these
5758 // cells to form a multicolumn cell
5759 idx_type const s_start = cur.selBegin().idx();
5760 row_type const col_start = tabular.cellColumn(s_start);
5761 row_type const col_end = tabular.cellColumn(cur.selEnd().idx());
5762 cur.idx() = tabular.setMultiColumn(s_start, col_end - col_start + 1,
5763 tabular.rightLine(cur.selEnd().idx()));
5766 cur.selection(false);
5770 case Tabular::UNSET_MULTICOLUMN: {
5771 if (!cur.selection()) {
5772 if (tabular.isMultiColumn(cur.idx()))
5773 tabular.unsetMultiColumn(cur.idx());
5778 case Tabular::MULTICOLUMN: {
5779 if (!cur.selection()) {
5780 if (tabular.isMultiColumn(cur.idx()))
5781 tabularFeatures(cur, Tabular::UNSET_MULTICOLUMN);
5783 tabularFeatures(cur, Tabular::SET_MULTICOLUMN);
5787 for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
5788 row_type const r = sel_row_start;
5789 if (!tabular.isMultiColumn(tabular.cellIndex(r, c))
5790 || (r > sel_row_start && !tabular.isPartOfMultiColumn(r, c)))
5793 // If the selection contains at least one singlecol cell
5794 // or multiple multicol cells,
5795 // we assume the user will merge is to a single multicol
5797 tabularFeatures(cur, Tabular::SET_MULTICOLUMN);
5799 tabularFeatures(cur, Tabular::UNSET_MULTICOLUMN);
5803 case Tabular::SET_MULTIROW: {
5804 if (!cur.selection()) {
5805 // just multirow for one single cell
5806 // check whether we are completely in a multirow
5807 if (!tabular.isMultiRow(cur.idx()))
5808 tabular.setMultiRow(cur.idx(), 1,
5809 tabular.bottomLine(cur.idx()),
5810 tabular.getAlignment(cur.idx()));
5813 // we have a selection so this means we just add all this
5814 // cells to form a multirow cell
5815 idx_type const s_start = cur.selBegin().idx();
5816 row_type const row_start = tabular.cellRow(s_start);
5817 row_type const row_end = tabular.cellRow(cur.selEnd().idx());
5818 cur.idx() = tabular.setMultiRow(s_start, row_end - row_start + 1,
5819 tabular.bottomLine(cur.selEnd().idx()),
5820 tabular.getAlignment(cur.selEnd().idx()));
5823 cur.selection(false);
5827 case Tabular::UNSET_MULTIROW: {
5828 if (!cur.selection()) {
5829 if (tabular.isMultiRow(cur.idx()))
5830 tabular.unsetMultiRow(cur.idx());
5835 case Tabular::MULTIROW: {
5836 if (!cur.selection()) {
5837 if (tabular.isMultiRow(cur.idx()))
5838 tabularFeatures(cur, Tabular::UNSET_MULTIROW);
5840 tabularFeatures(cur, Tabular::SET_MULTIROW);
5844 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
5845 col_type const c = sel_col_start;
5846 if (!tabular.isMultiRow(tabular.cellIndex(r, c))
5847 || (r > sel_row_start && !tabular.isPartOfMultiRow(r, c)))
5850 // If the selection contains at least one singlerow cell
5851 // or multiple multirow cells,
5852 // we assume the user will merge is to a single multirow
5854 tabularFeatures(cur, Tabular::SET_MULTIROW);
5856 tabularFeatures(cur, Tabular::UNSET_MULTIROW);
5860 case Tabular::SET_ALL_LINES:
5863 case Tabular::UNSET_ALL_LINES:
5864 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5865 for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
5866 idx_type const cell = tabular.cellIndex(r, c);
5867 tabular.setTopLine(cell, setLines);
5868 tabular.setBottomLine(cell, setLines);
5869 tabular.setRightLine(cell, setLines);
5870 tabular.setLeftLine(cell, setLines);
5874 case Tabular::SET_BORDER_LINES:
5875 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
5876 tabular.setLeftLine(tabular.cellIndex(r, sel_col_start), true);
5877 tabular.setRightLine(tabular.cellIndex(r, sel_col_end), true);
5879 for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
5880 tabular.setTopLine(tabular.cellIndex(sel_row_start, c), true);
5881 tabular.setBottomLine(tabular.cellIndex(sel_row_end, c), true);
5885 case Tabular::TOGGLE_LONGTABULAR:
5886 if (tabular.is_long_tabular)
5887 tabularFeatures(cur, Tabular::UNSET_LONGTABULAR);
5889 tabular.is_long_tabular = true;
5892 case Tabular::SET_LONGTABULAR:
5893 tabular.is_long_tabular = true;
5896 case Tabular::UNSET_LONGTABULAR:
5897 for (row_type r = 0; r < tabular.nrows(); ++r) {
5898 if (tabular.ltCaption(r)) {
5899 cur.idx() = tabular.cellIndex(r, 0);
5902 tabularFeatures(cur, Tabular::TOGGLE_LTCAPTION);
5905 tabular.is_long_tabular = false;
5908 case Tabular::SET_ROTATE_TABULAR:
5909 tabular.rotate = convert<int>(value);
5912 case Tabular::UNSET_ROTATE_TABULAR:
5916 case Tabular::TOGGLE_ROTATE_TABULAR:
5917 // when pressing the rotate button we default to 90° rotation
5918 tabular.rotate != 0 ? tabular.rotate = 0 : tabular.rotate = 90;
5921 case Tabular::TABULAR_VALIGN_TOP:
5922 tabular.tabular_valignment = Tabular::LYX_VALIGN_TOP;
5925 case Tabular::TABULAR_VALIGN_MIDDLE:
5926 tabular.tabular_valignment = Tabular::LYX_VALIGN_MIDDLE;
5929 case Tabular::TABULAR_VALIGN_BOTTOM:
5930 tabular.tabular_valignment = Tabular::LYX_VALIGN_BOTTOM;
5933 case Tabular::LONGTABULAR_ALIGN_LEFT:
5934 tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_LEFT;
5937 case Tabular::LONGTABULAR_ALIGN_CENTER:
5938 tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_CENTER;
5941 case Tabular::LONGTABULAR_ALIGN_RIGHT:
5942 tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_RIGHT;
5947 case Tabular::SET_ROTATE_CELL:
5948 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5949 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5950 tabular.setRotateCell(tabular.cellIndex(r, c), convert<int>(value));
5953 case Tabular::UNSET_ROTATE_CELL:
5954 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5955 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5956 tabular.setRotateCell(tabular.cellIndex(r, c), 0);
5959 case Tabular::TOGGLE_ROTATE_CELL:
5961 bool oneNotRotated = oneCellHasRotationState(false,
5962 sel_row_start, sel_row_end, sel_col_start, sel_col_end);
5964 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5965 for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
5966 // when pressing the rotate cell button we default to 90° rotation
5968 tabular.setRotateCell(tabular.cellIndex(r, c), 90);
5970 tabular.setRotateCell(tabular.cellIndex(r, c), 0);
5975 case Tabular::SET_USEBOX: {
5976 Tabular::BoxType val = Tabular::BoxType(convert<int>(value));
5977 if (val == tabular.getUsebox(cur.idx()))
5978 val = Tabular::BOX_NONE;
5979 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5980 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5981 tabular.setUsebox(tabular.cellIndex(r, c), val);
5985 case Tabular::UNSET_LTFIRSTHEAD:
5988 case Tabular::SET_LTFIRSTHEAD:
5989 tabular.getRowOfLTFirstHead(row, ltt);
5990 checkLongtableSpecial(ltt, value, flag);
5991 tabular.setLTHead(row, flag, ltt, true);
5994 case Tabular::UNSET_LTHEAD:
5997 case Tabular::SET_LTHEAD:
5998 tabular.getRowOfLTHead(row, ltt);
5999 checkLongtableSpecial(ltt, value, flag);
6000 tabular.setLTHead(row, flag, ltt, false);
6003 case Tabular::UNSET_LTFOOT:
6006 case Tabular::SET_LTFOOT:
6007 tabular.getRowOfLTFoot(row, ltt);
6008 checkLongtableSpecial(ltt, value, flag);
6009 tabular.setLTFoot(row, flag, ltt, false);
6012 case Tabular::UNSET_LTLASTFOOT:
6015 case Tabular::SET_LTLASTFOOT:
6016 tabular.getRowOfLTLastFoot(row, ltt);
6017 checkLongtableSpecial(ltt, value, flag);
6018 tabular.setLTFoot(row, flag, ltt, true);
6021 case Tabular::UNSET_LTNEWPAGE:
6024 case Tabular::SET_LTNEWPAGE:
6025 tabular.setLTNewPage(row, flag);
6028 case Tabular::SET_LTCAPTION: {
6029 if (tabular.ltCaption(row))
6031 cur.idx() = tabular.setLTCaption(row, true);
6034 cur.selection(false);
6035 // If a row is set as caption, then also insert
6036 // a caption. Otherwise the LaTeX output is broken.
6037 // Select cell if it is non-empty
6038 if (cur.lastpos() > 0 || cur.lastpit() > 0)
6039 lyx::dispatch(FuncRequest(LFUN_INSET_SELECT_ALL));
6040 lyx::dispatch(FuncRequest(LFUN_CAPTION_INSERT));
6044 case Tabular::UNSET_LTCAPTION: {
6045 if (!tabular.ltCaption(row))
6047 cur.idx() = tabular.setLTCaption(row, false);
6050 cur.selection(false);
6051 FuncRequest fr(LFUN_INSET_DISSOLVE, "caption");
6052 if (lyx::getStatus(fr).enabled())
6057 case Tabular::TOGGLE_LTCAPTION: {
6058 if (tabular.ltCaption(row))
6059 tabularFeatures(cur, Tabular::UNSET_LTCAPTION);
6061 tabularFeatures(cur, Tabular::SET_LTCAPTION);
6065 case Tabular::TOGGLE_BOOKTABS:
6066 tabular.use_booktabs = !tabular.use_booktabs;
6069 case Tabular::SET_BOOKTABS:
6070 tabular.use_booktabs = true;
6073 case Tabular::UNSET_BOOKTABS:
6074 tabular.use_booktabs = false;
6077 case Tabular::SET_TOP_SPACE: {
6079 if (value == "default")
6080 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
6081 tabular.row_info[r].top_space_default = true;
6082 else if (value == "none")
6083 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
6084 tabular.row_info[r].top_space_default = false;
6085 tabular.row_info[r].top_space = len;
6087 else if (isValidLength(value, &len))
6088 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
6089 tabular.row_info[r].top_space_default = false;
6090 tabular.row_info[r].top_space = len;
6095 case Tabular::SET_BOTTOM_SPACE: {
6097 if (value == "default")
6098 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
6099 tabular.row_info[r].bottom_space_default = true;
6100 else if (value == "none")
6101 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
6102 tabular.row_info[r].bottom_space_default = false;
6103 tabular.row_info[r].bottom_space = len;
6105 else if (isValidLength(value, &len))
6106 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
6107 tabular.row_info[r].bottom_space_default = false;
6108 tabular.row_info[r].bottom_space = len;
6113 case Tabular::SET_INTERLINE_SPACE: {
6115 if (value == "default")
6116 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
6117 tabular.row_info[r].interline_space_default = true;
6118 else if (value == "none")
6119 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
6120 tabular.row_info[r].interline_space_default = false;
6121 tabular.row_info[r].interline_space = len;
6123 else if (isValidLength(value, &len))
6124 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
6125 tabular.row_info[r].interline_space_default = false;
6126 tabular.row_info[r].interline_space = len;
6131 case Tabular::SET_DECIMAL_POINT:
6132 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
6133 tabular.column_info[c].decimal_point = from_utf8(value);
6136 // dummy stuff just to avoid warnings
6137 case Tabular::LAST_ACTION:
6143 bool InsetTabular::copySelection(Cursor & cur)
6145 if (!cur.selection())
6150 getSelection(cur, rs, re, cs, ce);
6152 paste_tabular.reset(new Tabular(tabular));
6154 for (row_type r = 0; r < rs; ++r)
6155 paste_tabular->deleteRow(0);
6157 row_type const rows = re - rs + 1;
6158 while (paste_tabular->nrows() > rows)
6159 paste_tabular->deleteRow(rows);
6161 for (col_type c = 0; c < cs; ++c)
6162 paste_tabular->deleteColumn(0);
6164 col_type const columns = ce - cs + 1;
6165 while (paste_tabular->ncols() > columns)
6166 paste_tabular->deleteColumn(columns);
6168 paste_tabular->setBuffer(tabular.buffer());
6170 odocstringstream os;
6171 OutputParams const runparams(0);
6172 paste_tabular->plaintext(os, runparams, 0, true, '\t', INT_MAX);
6173 // Needed for the "Edit->Paste recent" menu and the system clipboard.
6174 cap::copySelection(cur, os.str());
6176 // mark tabular stack dirty
6177 // FIXME: this is a workaround for bug 1919. Should be removed for 1.5,
6178 // when we (hopefully) have a one-for-all paste mechanism.
6179 // This must be called after cap::copySelection.
6180 dirtyTabularStack(true);
6186 bool InsetTabular::pasteClipboard(Cursor & cur)
6190 col_type actcol = tabular.cellColumn(cur.idx());
6191 row_type actrow = tabular.cellRow(cur.idx());
6193 if (cur.selIsMultiCell()) {
6196 getSelection(cur, actrow, re, actcol, ce);
6199 for (row_type r1 = 0, r2 = actrow;
6200 r1 < paste_tabular->nrows() && r2 < tabular.nrows();
6202 for (col_type c1 = 0, c2 = actcol;
6203 c1 < paste_tabular->ncols() && c2 < tabular.ncols();
6205 if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
6206 tabular.isPartOfMultiColumn(r2, c2))
6208 if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
6212 if (tabular.isPartOfMultiColumn(r2, c2)) {
6216 shared_ptr<InsetTableCell> inset(
6217 new InsetTableCell(*paste_tabular->cellInset(r1, c1)));
6218 tabular.setCellInset(r2, c2, inset);
6219 // FIXME?: why do we need to do this explicitly? (EL)
6220 tabular.cellInset(r2, c2)->setBuffer(tabular.buffer());
6222 // FIXME: change tracking (MG)
6223 inset->setChange(Change(buffer().params().track_changes ?
6224 Change::INSERTED : Change::UNCHANGED));
6233 void InsetTabular::cutSelection(Cursor & cur)
6235 if (!cur.selection())
6240 getSelection(cur, rs, re, cs, ce);
6241 for (row_type r = rs; r <= re; ++r) {
6242 for (col_type c = cs; c <= ce; ++c) {
6243 shared_ptr<InsetTableCell> t
6244 = cell(tabular.cellIndex(r, c));
6245 if (buffer().params().track_changes)
6246 // FIXME: Change tracking (MG)
6247 t->setChange(Change(Change::DELETED));
6253 // cursor position might be invalid now
6254 if (cur.pit() > cur.lastpit())
6255 cur.pit() = cur.lastpit();
6256 if (cur.pos() > cur.lastpos())
6257 cur.pos() = cur.lastpos();
6258 cur.clearSelection();
6262 bool InsetTabular::isRightToLeft(Cursor & cur) const
6264 // LASSERT: It might be better to abandon this Buffer.
6265 LASSERT(cur.depth() > 1, return false);
6266 Paragraph const & parentpar = cur[cur.depth() - 2].paragraph();
6267 pos_type const parentpos = cur[cur.depth() - 2].pos();
6268 return parentpar.getFontSettings(buffer().params(),
6269 parentpos).language()->rightToLeft();
6273 docstring InsetTabular::asString(idx_type stidx, idx_type enidx,
6276 LASSERT(stidx <= enidx, return docstring());
6278 col_type const col1 = tabular.cellColumn(stidx);
6279 col_type const col2 = tabular.cellColumn(enidx);
6280 row_type const row1 = tabular.cellRow(stidx);
6281 row_type const row2 = tabular.cellRow(enidx);
6283 for (col_type col = col1; col <= col2; col++)
6284 for (row_type row = row1; row <= row2; row++) {
6289 retval += tabular.cellInset(row, col)->asString(intoInsets);
6295 void InsetTabular::getSelection(Cursor & cur,
6296 row_type & rs, row_type & re, col_type & cs, col_type & ce) const
6298 CursorSlice const & beg = cur.selBegin();
6299 CursorSlice const & end = cur.selEnd();
6300 cs = tabular.cellColumn(beg.idx());
6301 ce = tabular.cellColumn(end.idx());
6305 rs = tabular.cellRow(beg.idx());
6306 re = tabular.cellRow(end.idx());
6312 Text * InsetTabular::getText(int idx) const
6314 return size_t(idx) < nargs() ? cell(idx)->getText(0) : 0;
6318 void InsetTabular::setChange(Change const & change)
6320 for (idx_type idx = 0; idx < nargs(); ++idx)
6321 cell(idx)->setChange(change);
6325 void InsetTabular::acceptChanges()
6327 for (idx_type idx = 0; idx < nargs(); ++idx)
6328 cell(idx)->acceptChanges();
6332 void InsetTabular::rejectChanges()
6334 for (idx_type idx = 0; idx < nargs(); ++idx)
6335 cell(idx)->rejectChanges();
6339 bool InsetTabular::allowParagraphCustomization(idx_type cell) const
6341 return tabular.getPWidth(cell).zero();
6345 bool InsetTabular::forcePlainLayout(idx_type cell) const
6347 return !tabular.getPWidth(cell).zero();
6351 bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
6354 if (buf.length() <= 0)
6359 col_type maxCols = 1;
6360 size_t const len = buf.length();
6364 (p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos) {
6372 maxCols = max(cols, maxCols);
6378 maxCols = max(cols, maxCols);
6384 paste_tabular.reset(new Tabular(buffer_, rows, maxCols));
6385 loctab = paste_tabular.get();
6386 dirtyTabularStack(true);
6389 cell = bv.cursor().idx();
6390 ocol = tabular.cellColumn(cell);
6391 row = tabular.cellRow(cell);
6395 idx_type const cells = loctab->numberofcells;
6398 rows = loctab->nrows();
6399 col_type const columns = loctab->ncols();
6401 while (cell < cells && p < len && row < rows &&
6402 (p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos)
6408 // we can only set this if we are not too far right
6409 if (cols < columns) {
6410 shared_ptr<InsetTableCell> inset = loctab->cellInset(cell);
6411 Font const font = bv.textMetrics(&inset->text()).
6413 inset->setText(buf.substr(op, p - op), font,
6414 buffer().params().track_changes);
6420 // we can only set this if we are not too far right
6421 if (cols < columns) {
6422 shared_ptr<InsetTableCell> inset = tabular.cellInset(cell);
6423 Font const font = bv.textMetrics(&inset->text()).
6425 inset->setText(buf.substr(op, p - op), font,
6426 buffer().params().track_changes);
6431 cell = loctab->cellIndex(row, cols);
6437 // check for the last cell if there is no trailing '\n'
6438 if (cell < cells && op < len) {
6439 shared_ptr<InsetTableCell> inset = loctab->cellInset(cell);
6440 Font const font = bv.textMetrics(&inset->text()).displayFont(0, 0);
6441 inset->setText(buf.substr(op, len - op), font,
6442 buffer().params().track_changes);
6448 void InsetTabular::addPreview(DocIterator const & inset_pos,
6449 PreviewLoader & loader) const
6451 DocIterator cell_pos = inset_pos;
6453 cell_pos.push_back(CursorSlice(*const_cast<InsetTabular *>(this)));
6454 for (row_type r = 0; r < tabular.nrows(); ++r) {
6455 for (col_type c = 0; c < tabular.ncols(); ++c) {
6456 cell_pos.top().idx() = tabular.cellIndex(r, c);
6457 tabular.cellInset(r, c)->addPreview(cell_pos, loader);
6463 bool InsetTabular::completionSupported(Cursor const & cur) const
6465 Cursor const & bvCur = cur.bv().cursor();
6466 if (&bvCur.inset() != this)
6468 return cur.text()->completionSupported(cur);
6472 bool InsetTabular::inlineCompletionSupported(Cursor const & cur) const
6474 return completionSupported(cur);
6478 bool InsetTabular::automaticInlineCompletion() const
6480 return lyxrc.completion_inline_text;
6484 bool InsetTabular::automaticPopupCompletion() const
6486 return lyxrc.completion_popup_text;
6490 bool InsetTabular::showCompletionCursor() const
6492 return lyxrc.completion_cursor_text;
6496 CompletionList const * InsetTabular::createCompletionList(Cursor const & cur) const
6498 return completionSupported(cur) ? cur.text()->createCompletionList(cur) : 0;
6502 docstring InsetTabular::completionPrefix(Cursor const & cur) const
6504 if (!completionSupported(cur))
6506 return cur.text()->completionPrefix(cur);
6510 bool InsetTabular::insertCompletion(Cursor & cur, docstring const & s, bool finished)
6512 if (!completionSupported(cur))
6515 return cur.text()->insertCompletion(cur, s, finished);
6519 void InsetTabular::completionPosAndDim(Cursor const & cur, int & x, int & y,
6520 Dimension & dim) const
6522 TextMetrics const & tm = cur.bv().textMetrics(cur.text());
6523 tm.completionPosAndDim(cur, x, y, dim);
6527 void InsetTabular::string2params(string const & in, InsetTabular & inset)
6529 istringstream data(in);
6531 lex.setStream(data);
6538 if (!lex || token != "tabular") {
6539 LYXERR0("Expected arg 1 to be \"tabular\" in " << in);
6543 // This is part of the inset proper that is usually swallowed
6544 // by Buffer::readInset
6546 if (!lex || token != "Tabular") {
6547 LYXERR0("Expected arg 2 to be \"Tabular\" in " << in);
6555 string InsetTabular::params2string(InsetTabular const & inset)
6558 data << "tabular" << ' ';
6560 data << "\\end_inset\n";
6565 void InsetTabular::setLayoutForHiddenCells(DocumentClass const & dc)
6567 for (Tabular::col_type c = 0; c < tabular.ncols(); ++c) {
6568 for (Tabular::row_type r = 0; r < tabular.nrows(); ++r) {
6569 if (!tabular.isPartOfMultiColumn(r,c) &&
6570 !tabular.isPartOfMultiRow(r,c))
6573 ParagraphList & parlist = tabular.cellInset(r,c)->paragraphs();
6574 ParagraphList::iterator it = parlist.begin();
6575 ParagraphList::iterator const en = parlist.end();
6576 for (; it != en; ++it)
6577 it->setLayout(dc.plainLayout());