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
17 * Full author contact details are available in file CREDITS.
22 #include "InsetTabular.h"
24 #include "buffer_funcs.h"
26 #include "BufferParams.h"
27 #include "BufferView.h"
28 #include "CoordCache.h"
31 #include "CutAndPaste.h"
32 #include "DispatchResult.h"
33 #include "FuncRequest.h"
34 #include "FuncStatus.h"
36 #include "LaTeXFeatures.h"
40 #include "MetricsInfo.h"
41 #include "OutputParams.h"
42 #include "output_xhtml.h"
43 #include "Paragraph.h"
44 #include "ParagraphParameters.h"
45 #include "ParIterator.h"
46 #include "TextClass.h"
47 #include "TextMetrics.h"
49 #include "frontends/Application.h"
50 #include "frontends/alert.h"
51 #include "frontends/Clipboard.h"
52 #include "frontends/Painter.h"
53 #include "frontends/Selection.h"
55 #include "support/convert.h"
56 #include "support/debug.h"
57 #include "support/docstream.h"
58 #include "support/FileName.h"
59 #include "support/gettext.h"
60 #include "support/lassert.h"
61 #include "support/lstrings.h"
63 #include <boost/scoped_ptr.hpp>
71 using namespace lyx::support;
77 using cap::dirtyTabularStack;
78 using cap::tabularStackDirty;
80 using graphics::PreviewLoader;
82 using frontend::Painter;
83 using frontend::Clipboard;
85 namespace Alert = frontend::Alert;
90 int const ADD_TO_HEIGHT = 2; // in cell
91 int const ADD_TO_TABULAR_WIDTH = 6; // horiz space before and after the table
92 int const default_line_space = 10; // ?
93 int const WIDTH_OF_LINE = 5; // space between double lines
97 boost::scoped_ptr<Tabular> paste_tabular;
100 struct TabularFeature {
101 Tabular::Feature action;
107 TabularFeature tabularFeature[] =
109 // the SET/UNSET actions are used by the table dialog,
110 // the TOGGLE actions by the table toolbar buttons
111 { Tabular::APPEND_ROW, "append-row", false },
112 { Tabular::APPEND_COLUMN, "append-column", false },
113 { Tabular::DELETE_ROW, "delete-row", false },
114 { Tabular::DELETE_COLUMN, "delete-column", false },
115 { Tabular::COPY_ROW, "copy-row", false },
116 { Tabular::COPY_COLUMN, "copy-column", false },
117 { Tabular::SET_LINE_TOP, "set-line-top", true },
118 { Tabular::SET_LINE_BOTTOM, "set-line-bottom", true },
119 { Tabular::SET_LINE_LEFT, "set-line-left", true },
120 { Tabular::SET_LINE_RIGHT, "set-line-right", true },
121 { Tabular::TOGGLE_LINE_TOP, "toggle-line-top", false },
122 { Tabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom", false },
123 { Tabular::TOGGLE_LINE_LEFT, "toggle-line-left", false },
124 { Tabular::TOGGLE_LINE_RIGHT, "toggle-line-right", false },
125 { Tabular::ALIGN_LEFT, "align-left", false },
126 { Tabular::ALIGN_RIGHT, "align-right", false },
127 { Tabular::ALIGN_CENTER, "align-center", false },
128 { Tabular::ALIGN_BLOCK, "align-block", false },
129 { Tabular::ALIGN_DECIMAL, "align-decimal", false },
130 { Tabular::VALIGN_TOP, "valign-top", false },
131 { Tabular::VALIGN_BOTTOM, "valign-bottom", false },
132 { Tabular::VALIGN_MIDDLE, "valign-middle", false },
133 { Tabular::M_ALIGN_LEFT, "m-align-left", false },
134 { Tabular::M_ALIGN_RIGHT, "m-align-right", false },
135 { Tabular::M_ALIGN_CENTER, "m-align-center", false },
136 { Tabular::M_VALIGN_TOP, "m-valign-top", false },
137 { Tabular::M_VALIGN_BOTTOM, "m-valign-bottom", false },
138 { Tabular::M_VALIGN_MIDDLE, "m-valign-middle", false },
139 { Tabular::MULTICOLUMN, "multicolumn", false },
140 { Tabular::SET_MULTICOLUMN, "set-multicolumn", false },
141 { Tabular::UNSET_MULTICOLUMN, "unset-multicolumn", false },
142 { Tabular::MULTIROW, "multirow", false },
143 { Tabular::SET_MULTIROW, "set-multirow", false },
144 { Tabular::UNSET_MULTIROW, "unset-multirow", false },
145 { Tabular::SET_MROFFSET, "set-mroffset", true },
146 { Tabular::SET_ALL_LINES, "set-all-lines", false },
147 { Tabular::UNSET_ALL_LINES, "unset-all-lines", false },
148 { Tabular::SET_LONGTABULAR, "set-longtabular", false },
149 { Tabular::UNSET_LONGTABULAR, "unset-longtabular", false },
150 { Tabular::SET_PWIDTH, "set-pwidth", true },
151 { Tabular::SET_MPWIDTH, "set-mpwidth", true },
152 { Tabular::SET_ROTATE_TABULAR, "set-rotate-tabular", false },
153 { Tabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular", false },
154 { Tabular::TOGGLE_ROTATE_TABULAR, "toggle-rotate-tabular", false },
155 { Tabular::SET_ROTATE_CELL, "set-rotate-cell", false },
156 { Tabular::UNSET_ROTATE_CELL, "unset-rotate-cell", false },
157 { Tabular::TOGGLE_ROTATE_CELL, "toggle-rotate-cell", false },
158 { Tabular::SET_USEBOX, "set-usebox", true },
159 { Tabular::SET_LTHEAD, "set-lthead", true },
160 { Tabular::UNSET_LTHEAD, "unset-lthead", true },
161 { Tabular::SET_LTFIRSTHEAD, "set-ltfirsthead", true },
162 { Tabular::UNSET_LTFIRSTHEAD, "unset-ltfirsthead", true },
163 { Tabular::SET_LTFOOT, "set-ltfoot", true },
164 { Tabular::UNSET_LTFOOT, "unset-ltfoot", true },
165 { Tabular::SET_LTLASTFOOT, "set-ltlastfoot", true },
166 { Tabular::UNSET_LTLASTFOOT, "unset-ltlastfoot", true },
167 { Tabular::SET_LTNEWPAGE, "set-ltnewpage", false },
168 { Tabular::TOGGLE_LTCAPTION, "toggle-ltcaption", false },
169 { Tabular::SET_LTCAPTION, "set-ltcaption", false },
170 { Tabular::UNSET_LTCAPTION, "unset-ltcaption", false },
171 { Tabular::SET_SPECIAL_COLUMN, "set-special-column", true },
172 { Tabular::SET_SPECIAL_MULTICOLUMN, "set-special-multicolumn", true },
173 { Tabular::SET_BOOKTABS, "set-booktabs", false },
174 { Tabular::UNSET_BOOKTABS, "unset-booktabs", false },
175 { Tabular::SET_TOP_SPACE, "set-top-space", true },
176 { Tabular::SET_BOTTOM_SPACE, "set-bottom-space", true },
177 { Tabular::SET_INTERLINE_SPACE, "set-interline-space", true },
178 { Tabular::SET_BORDER_LINES, "set-border-lines", false },
179 { Tabular::TABULAR_VALIGN_TOP, "tabular-valign-top", false},
180 { Tabular::TABULAR_VALIGN_MIDDLE, "tabular-valign-middle", false},
181 { Tabular::TABULAR_VALIGN_BOTTOM, "tabular-valign-bottom", false},
182 { Tabular::LONGTABULAR_ALIGN_LEFT, "longtabular-align-left", false },
183 { Tabular::LONGTABULAR_ALIGN_CENTER, "longtabular-align-center", false },
184 { Tabular::LONGTABULAR_ALIGN_RIGHT, "longtabular-align-right", false },
185 { Tabular::SET_DECIMAL_POINT, "set-decimal-point", true },
186 { Tabular::LAST_ACTION, "", false }
191 string const write_attribute(string const & name, T const & t)
193 string const s = tostr(t);
194 return s.empty() ? s : " " + name + "=\"" + s + "\"";
198 string const write_attribute(string const & name, string const & t)
200 return t.empty() ? t : " " + name + "=\"" + t + "\"";
205 string const write_attribute(string const & name, docstring const & t)
207 return t.empty() ? string() : " " + name + "=\"" + to_utf8(t) + "\"";
212 string const write_attribute(string const & name, bool const & b)
214 // we write only true attribute values so we remove a bit of the
215 // file format bloat for tabulars.
216 return b ? write_attribute(name, convert<string>(b)) : string();
221 string const write_attribute(string const & name, int const & i)
223 // we write only true attribute values so we remove a bit of the
224 // file format bloat for tabulars.
225 return i ? write_attribute(name, convert<string>(i)) : string();
230 string const write_attribute(string const & name, Tabular::idx_type const & i)
232 // we write only true attribute values so we remove a bit of the
233 // file format bloat for tabulars.
234 return i ? write_attribute(name, convert<string>(i)) : string();
239 string const write_attribute(string const & name, Length const & value)
241 // we write only the value if we really have one same reson as above.
242 return value.zero() ? string() : write_attribute(name, value.asString());
246 string const tostr(LyXAlignment const & num)
251 case LYX_ALIGN_BLOCK:
255 case LYX_ALIGN_CENTER:
257 case LYX_ALIGN_RIGHT:
259 case LYX_ALIGN_LAYOUT:
261 case LYX_ALIGN_SPECIAL:
263 case LYX_ALIGN_DECIMAL:
270 string const tostr(Tabular::HAlignment const & num)
273 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
275 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
277 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
284 string const tostr(Tabular::VAlignment const & num)
287 case Tabular::LYX_VALIGN_TOP:
289 case Tabular::LYX_VALIGN_MIDDLE:
291 case Tabular::LYX_VALIGN_BOTTOM:
298 string const tostr(Tabular::BoxType const & num)
301 case Tabular::BOX_NONE:
303 case Tabular::BOX_PARBOX:
305 case Tabular::BOX_MINIPAGE:
312 // I would have liked a fromstr template a lot better. (Lgb)
313 bool string2type(string const str, LyXAlignment & num)
316 num = LYX_ALIGN_NONE;
317 else if (str == "block")
318 num = LYX_ALIGN_BLOCK;
319 else if (str == "left")
320 num = LYX_ALIGN_LEFT;
321 else if (str == "center")
322 num = LYX_ALIGN_CENTER;
323 else if (str == "right")
324 num = LYX_ALIGN_RIGHT;
325 else if (str == "decimal")
326 num = LYX_ALIGN_DECIMAL;
333 bool string2type(string const str, Tabular::HAlignment & num)
336 num = Tabular::LYX_LONGTABULAR_ALIGN_LEFT;
337 else if (str == "center" )
338 num = Tabular::LYX_LONGTABULAR_ALIGN_CENTER;
339 else if (str == "right")
340 num = Tabular::LYX_LONGTABULAR_ALIGN_RIGHT;
347 bool string2type(string const str, Tabular::VAlignment & num)
350 num = Tabular::LYX_VALIGN_TOP;
351 else if (str == "middle" )
352 num = Tabular::LYX_VALIGN_MIDDLE;
353 else if (str == "bottom")
354 num = Tabular::LYX_VALIGN_BOTTOM;
361 bool string2type(string const str, Tabular::BoxType & num)
364 num = Tabular::BOX_NONE;
365 else if (str == "parbox")
366 num = Tabular::BOX_PARBOX;
367 else if (str == "minipage")
368 num = Tabular::BOX_MINIPAGE;
375 bool string2type(string const str, bool & num)
379 else if (str == "false")
387 bool getTokenValue(string const & str, char const * token, string & ret)
390 size_t token_length = strlen(token);
391 size_t pos = str.find(token);
393 if (pos == string::npos || pos + token_length + 1 >= str.length()
394 || str[pos + token_length] != '=')
396 pos += token_length + 1;
398 if (ch != '"' && ch != '\'') { // only read till next space
402 while (pos < str.length() - 1 && str[++pos] != ch)
409 bool getTokenValue(string const & str, char const * token, docstring & ret)
412 bool const success = getTokenValue(str, token, tmp);
413 ret = from_utf8(tmp);
418 bool getTokenValue(string const & str, char const * token, int & num)
422 if (!getTokenValue(str, token, tmp))
424 num = convert<int>(tmp);
429 bool getTokenValue(string const & str, char const * token, LyXAlignment & num)
432 return getTokenValue(str, token, tmp) && string2type(tmp, num);
436 bool getTokenValue(string const & str, char const * token,
437 Tabular::HAlignment & num)
440 return getTokenValue(str, token, tmp) && string2type(tmp, num);
444 bool getTokenValue(string const & str, char const * token,
445 Tabular::VAlignment & num)
448 return getTokenValue(str, token, tmp) && string2type(tmp, num);
452 bool getTokenValue(string const & str, char const * token,
453 Tabular::BoxType & num)
456 return getTokenValue(str, token, tmp) && string2type(tmp, num);
460 bool getTokenValue(string const & str, char const * token, bool & flag)
462 // set the flag always to false as this should be the default for bools
463 // not in the file-format.
466 return getTokenValue(str, token, tmp) && string2type(tmp, flag);
470 bool getTokenValue(string const & str, char const * token, Length & len)
472 // set the length to be zero() as default as this it should be if not
473 // in the file format.
476 return getTokenValue(str, token, tmp) && isValidLength(tmp, &len);
480 bool getTokenValue(string const & str, char const * token, Length & len, bool & flag)
485 if (!getTokenValue(str, token, tmp))
487 if (tmp == "default") {
491 return isValidLength(tmp, &len);
495 void l_getline(istream & is, string & str)
498 while (str.empty()) {
500 if (!str.empty() && str[str.length() - 1] == '\r')
501 str.erase(str.length() - 1);
508 string const featureAsString(Tabular::Feature action)
510 for (size_t i = 0; i != Tabular::LAST_ACTION; ++i) {
511 if (tabularFeature[i].action == action)
512 return tabularFeature[i].feature;
518 InsetTableCell splitCell(InsetTableCell & head, docstring const align_d, bool & hassep)
520 InsetTableCell tail = InsetTableCell(head);
521 tail.getText(0)->setMacrocontextPosition(
522 head.getText(0)->macrocontextPosition());
523 tail.setBuffer(head.buffer());
525 DocIterator dit = doc_iterator_begin(&head.buffer(), &head);
526 for (; dit; dit.forwardChar())
527 if (dit.inTexted() && dit.depth()==1
528 && dit.paragraph().find(align_d, false, false, dit.pos()))
531 pit_type const psize = head.paragraphs().front().size();
534 head.paragraphs().front().eraseChars(dit.pos(), psize, false);
535 tail.paragraphs().front().eraseChars(0,
536 dit.pos() < psize ? dit.pos() + 1 : psize, false);
543 /////////////////////////////////////////////////////////////////////
547 /////////////////////////////////////////////////////////////////////
550 Tabular::CellData::CellData(Buffer * buf)
553 multicolumn(Tabular::CELL_NORMAL),
554 multirow(Tabular::CELL_NORMAL),
555 alignment(LYX_ALIGN_CENTER),
556 valignment(LYX_VALIGN_TOP),
566 inset(new InsetTableCell(buf))
568 inset->setBuffer(*buf);
572 Tabular::CellData::CellData(CellData const & cs)
575 multicolumn(cs.multicolumn),
576 multirow(cs.multirow),
577 mroffset(cs.mroffset),
578 alignment(cs.alignment),
579 valignment(cs.valignment),
580 decimal_hoffset(cs.decimal_hoffset),
581 decimal_width(cs.decimal_width),
583 top_line(cs.top_line),
584 bottom_line(cs.bottom_line),
585 left_line(cs.left_line),
586 right_line(cs.right_line),
589 align_special(cs.align_special),
591 inset(static_cast<InsetTableCell *>(cs.inset->clone()))
595 Tabular::CellData & Tabular::CellData::operator=(CellData cs)
601 void Tabular::CellData::swap(CellData & rhs)
603 std::swap(cellno, rhs.cellno);
604 std::swap(width, rhs.width);
605 std::swap(multicolumn, rhs.multicolumn);
606 std::swap(multirow, rhs.multirow);
607 std::swap(mroffset, rhs.mroffset);
608 std::swap(alignment, rhs.alignment);
609 std::swap(valignment, rhs.valignment);
610 std::swap(decimal_hoffset, rhs.decimal_hoffset);
611 std::swap(decimal_width, rhs.decimal_width);
612 std::swap(voffset, rhs.voffset);
613 std::swap(top_line, rhs.top_line);
614 std::swap(bottom_line, rhs.bottom_line);
615 std::swap(left_line, rhs.left_line);
616 std::swap(right_line, rhs.right_line);
617 std::swap(usebox, rhs.usebox);
618 std::swap(rotate, rhs.rotate);
619 std::swap(align_special, rhs.align_special);
620 p_width.swap(rhs.p_width);
621 inset.swap(rhs.inset);
625 Tabular::RowData::RowData()
628 top_space_default(false),
629 bottom_space_default(false),
630 interline_space_default(false),
640 Tabular::ColumnData::ColumnData()
641 : alignment(LYX_ALIGN_CENTER),
642 valignment(LYX_VALIGN_TOP),
648 Tabular::ltType::ltType()
655 Tabular::Tabular(Buffer * buffer, row_type rows_arg, col_type columns_arg)
657 init(buffer, rows_arg, columns_arg);
661 void Tabular::setBuffer(Buffer & buffer)
664 for (row_type i = 0; i < nrows(); ++i)
665 for (col_type j = 0; j < ncols(); ++j)
666 cell_info[i][j].inset->setBuffer(*buffer_);
670 // activates all lines and sets all widths to 0
671 void Tabular::init(Buffer * buf, row_type rows_arg,
672 col_type columns_arg)
675 row_info = row_vector(rows_arg);
676 column_info = column_vector(columns_arg);
677 cell_info = cell_vvector(rows_arg, cell_vector(columns_arg, CellData(buf)));
678 row_info.reserve(10);
679 column_info.reserve(10);
680 cell_info.reserve(100);
682 is_long_tabular = false;
683 tabular_valignment = LYX_VALIGN_MIDDLE;
684 longtabular_alignment = LYX_LONGTABULAR_ALIGN_CENTER;
686 use_booktabs = false;
687 // set silly default lines
688 for (row_type r = 0; r < nrows(); ++r)
689 for (col_type c = 0; c < ncols(); ++c) {
690 cell_info[r][c].inset->setBuffer(*buffer_);
691 cell_info[r][c].top_line = true;
692 cell_info[r][c].left_line = true;
693 cell_info[r][c].bottom_line = r == 0 || r == nrows() - 1;
694 cell_info[r][c].right_line = c == ncols() - 1;
699 void Tabular::appendRow(idx_type const cell)
701 row_type const row = cellRow(cell);
703 row_info.insert(row_info.begin() + row + 1, RowData());
704 row_info[row + 1] = row_info[row];
706 cell_info.insert(cell_info.begin() + row + 1,
707 cell_vector(ncols(), CellData(buffer_)));
708 for (col_type c = 0; c < ncols(); ++c) {
709 if (cell_info[row][c].multirow == CELL_BEGIN_OF_MULTIROW)
710 cell_info[row + 1][c].multirow = CELL_PART_OF_MULTIROW;
712 cell_info[row + 1][c].multirow = cell_info[row][c].multirow;
716 for (col_type c = 0; c < ncols(); ++c) {
717 if (isPartOfMultiRow(row, c))
719 // inherit line settings
720 idx_type const i = cellIndex(row + 1, c);
721 idx_type const j = cellIndex(row, c);
722 setLeftLine(i, leftLine(j));
723 setRightLine(i, rightLine(j));
724 setTopLine(i, topLine(j));
725 if (topLine(j) && bottomLine(j)) {
726 setBottomLine(i, true);
727 setBottomLine(j, false);
729 // mark track changes
730 if (buffer().params().trackChanges)
731 cellInfo(i).inset->setChange(Change(Change::INSERTED));
736 void Tabular::deleteRow(row_type const row)
738 // Not allowed to delete last row
742 for (col_type c = 0; c < ncols(); ++c) {
743 // Care about multirow cells
744 if (row + 1 < nrows() &&
745 cell_info[row][c].multirow == CELL_BEGIN_OF_MULTIROW &&
746 cell_info[row + 1][c].multirow == CELL_PART_OF_MULTIROW) {
747 cell_info[row + 1][c].multirow = CELL_BEGIN_OF_MULTIROW;
750 row_info.erase(row_info.begin() + row);
751 cell_info.erase(cell_info.begin() + row);
756 void Tabular::copyRow(row_type const row)
758 row_info.insert(row_info.begin() + row, row_info[row]);
759 cell_info.insert(cell_info.begin() + row, cell_info[row]);
761 if (buffer().params().trackChanges)
762 for (col_type c = 0; c < ncols(); ++c)
763 cell_info[row + 1][c].inset->setChange(Change(Change::INSERTED));
769 void Tabular::appendColumn(idx_type const cell)
771 col_type const c = cellColumn(cell);
773 column_info.insert(column_info.begin() + c + 1, ColumnData());
774 column_info[c + 1] = column_info[c];
776 for (row_type r = 0; r < nrows(); ++r) {
777 cell_info[r].insert(cell_info[r].begin() + c + 1,
779 if (cell_info[r][c].multicolumn == CELL_BEGIN_OF_MULTICOLUMN)
780 cell_info[r][c + 1].multicolumn = CELL_PART_OF_MULTICOLUMN;
782 cell_info[r][c + 1].multicolumn = cell_info[r][c].multicolumn;
785 for (row_type r = 0; r < nrows(); ++r) {
786 // inherit line settings
787 idx_type const i = cellIndex(r, c + 1);
788 idx_type const j = cellIndex(r, c);
789 setBottomLine(i, bottomLine(j));
790 setTopLine(i, topLine(j));
791 setLeftLine(i, leftLine(j));
792 if (rightLine(j) && rightLine(j)) {
793 setRightLine(i, true);
794 setRightLine(j, false);
796 if (buffer().params().trackChanges)
797 cellInfo(i).inset->setChange(Change(Change::INSERTED));
802 void Tabular::deleteColumn(col_type const col)
804 // Not allowed to delete last column
808 for (row_type r = 0; r < nrows(); ++r) {
809 // Care about multicolumn cells
810 if (col + 1 < ncols() &&
811 cell_info[r][col].multicolumn == CELL_BEGIN_OF_MULTICOLUMN &&
812 cell_info[r][col + 1].multicolumn == CELL_PART_OF_MULTICOLUMN) {
813 cell_info[r][col + 1].multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
815 cell_info[r].erase(cell_info[r].begin() + col);
817 column_info.erase(column_info.begin() + col);
822 void Tabular::copyColumn(col_type const col)
824 BufferParams const & bp = buffer().params();
825 column_info.insert(column_info.begin() + col, column_info[col]);
827 for (row_type r = 0; r < nrows(); ++r) {
828 cell_info[r].insert(cell_info[r].begin() + col, cell_info[r][col]);
830 cell_info[r][col + 1].inset->setChange(Change(Change::INSERTED));
836 void Tabular::updateIndexes()
841 for (row_type row = 0; row < nrows(); ++row)
842 for (col_type column = 0; column < ncols(); ++column) {
843 if (!isPartOfMultiColumn(row, column)
844 && !isPartOfMultiRow(row, column))
846 if (isPartOfMultiRow(row, column))
847 cell_info[row][column].cellno = cell_info[row - 1][column].cellno;
849 cell_info[row][column].cellno = numberofcells - 1;
852 rowofcell.resize(numberofcells);
853 columnofcell.resize(numberofcells);
855 // reset column and row of cells and update their width and alignment
856 for (row_type row = 0; row < nrows(); ++row)
857 for (col_type column = 0; column < ncols(); ++column) {
858 if (isPartOfMultiColumn(row, column))
860 // columnofcell needs to be called before setting width and aligment
861 // multirow cells inherit the width from the column width
862 if (!isPartOfMultiRow(row, column)) {
863 columnofcell[i] = column;
866 setFixedWidth(row, column);
867 if (isPartOfMultiRow(row, column))
869 cell_info[row][column].inset->setContentAlignment(
870 getAlignment(cellIndex(row, column)));
876 Tabular::idx_type Tabular::numberOfCellsInRow(row_type const row) const
879 for (col_type c = 0; c < ncols(); ++c)
880 if (cell_info[row][c].multicolumn != Tabular::CELL_PART_OF_MULTICOLUMN)
886 bool Tabular::topLine(idx_type const cell) const
888 return cellInfo(cell).top_line;
892 bool Tabular::bottomLine(idx_type const cell) const
894 return cellInfo(cell).bottom_line;
898 bool Tabular::leftLine(idx_type cell) const
902 return cellInfo(cell).left_line;
906 bool Tabular::rightLine(idx_type cell) const
910 return cellInfo(cell).right_line;
914 int Tabular::interRowSpace(row_type row) const
916 if (!row || row >= nrows())
919 int const interline_space = row_info[row - 1].interline_space_default ?
921 row_info[row - 1].interline_space.inPixels(width());
922 if (rowTopLine(row) && rowBottomLine(row - 1))
923 return interline_space + WIDTH_OF_LINE;
924 return interline_space;
928 int Tabular::interColumnSpace(idx_type cell) const
930 col_type const nextcol = cellColumn(cell) + columnSpan(cell);
931 if (rightLine(cell) && nextcol < ncols()
932 && leftLine(cellIndex(cellRow(cell), nextcol)))
933 return WIDTH_OF_LINE;
938 int Tabular::cellWidth(idx_type cell) const
941 col_type const span = columnSpan(cell);
942 col_type const col = cellColumn(cell);
943 for(col_type c = col; c < col + span ; ++c)
944 w += column_info[c].width;
949 int Tabular::cellHeight(idx_type cell) const
951 row_type const span = rowSpan(cell);
952 row_type const row = cellRow(cell);
954 for(row_type r = row; r < row + span ; ++r) {
955 h += rowAscent(r) + rowDescent(r);
956 if (r != row + span - 1)
957 h += interRowSpace(r + 1);
964 bool Tabular::updateColumnWidths()
966 vector<int> max_dwidth(ncols(), 0);
967 for(col_type c = 0; c < ncols(); ++c)
968 for(row_type r = 0; r < nrows(); ++r) {
969 idx_type const i = cellIndex(r, c);
970 if (getAlignment(i) == LYX_ALIGN_DECIMAL)
971 max_dwidth[c] = max(max_dwidth[c], cell_info[r][c].decimal_width);
975 // for each col get max of single col cells
976 for(col_type c = 0; c < ncols(); ++c) {
978 for(row_type r = 0; r < nrows(); ++r) {
979 idx_type const i = cellIndex(r, c);
980 if (columnSpan(i) == 1) {
981 if (getAlignment(i) == LYX_ALIGN_DECIMAL
982 && cell_info[r][c].decimal_width!=0)
983 new_width = max(new_width, cellInfo(i).width
984 + max_dwidth[c] - cellInfo(i).decimal_width);
986 new_width = max(new_width, cellInfo(i).width);
990 if (column_info[c].width != new_width) {
991 column_info[c].width = new_width;
995 // update col widths to fit merged cells
996 for(col_type c = 0; c < ncols(); ++c)
997 for(row_type r = 0; r < nrows(); ++r) {
998 idx_type const i = cellIndex(r, c);
999 int const span = columnSpan(i);
1000 if (span == 1 || c > cellColumn(i))
1004 for(col_type j = c; j < c + span ; ++j)
1005 old_width += column_info[j].width;
1007 if (cellInfo(i).width > old_width) {
1008 column_info[c + span - 1].width += cellInfo(i).width - old_width;
1017 int Tabular::width() const
1020 for (col_type c = 0; c < ncols(); ++c)
1021 width += column_info[c].width;
1026 void Tabular::setAlignment(idx_type cell, LyXAlignment align,
1029 col_type const col = cellColumn(cell);
1030 // set alignment for the whole row of the selection is only
1031 // withing one column and it is no multicolumn cell
1032 if (onlycolumn || !isMultiColumn(cell)) {
1033 for (row_type r = 0; r < nrows(); ++r) {
1034 if (!isMultiRow(cellIndex(r, col))) {
1035 cell_info[r][col].alignment = align;
1036 cell_info[r][col].inset->setContentAlignment(align);
1039 column_info[col].alignment = align;
1040 docstring & dpoint = column_info[col].decimal_point;
1041 if (align == LYX_ALIGN_DECIMAL && dpoint.empty())
1042 dpoint = from_utf8(lyxrc.default_decimal_point);
1044 cellInfo(cell).alignment = align;
1045 cellInset(cell).get()->setContentAlignment(align);
1050 void Tabular::setVAlignment(idx_type cell, VAlignment align,
1053 if (!isMultiColumn(cell) || onlycolumn)
1054 column_info[cellColumn(cell)].valignment = align;
1056 cellInfo(cell).valignment = align;
1063 * Allow line and paragraph breaks for fixed width cells or disallow them,
1064 * merge cell paragraphs and reset layout to standard for variable width
1067 void toggleFixedWidth(Cursor & cur, InsetTableCell * inset, bool fixedWidth)
1069 inset->setAutoBreakRows(fixedWidth);
1070 inset->toggleFixedWidth(fixedWidth);
1074 // merge all paragraphs to one
1075 BufferParams const & bp = cur.bv().buffer().params();
1076 while (inset->paragraphs().size() > 1)
1077 mergeParagraph(bp, inset->paragraphs(), 0);
1081 // undo information has already been recorded
1082 inset->getText(0)->setLayout(0, cur.lastpit() + 1,
1083 bp.documentClass().plainLayoutName());
1090 void Tabular::setColumnPWidth(Cursor & cur, idx_type cell,
1091 Length const & width)
1093 col_type const c = cellColumn(cell);
1095 column_info[c].p_width = width;
1096 // reset the vertical alignment to top if the fixed with
1097 // is removed or zero because only fixed width columns can
1098 // have a vertical alignment
1099 if (column_info[c].p_width.zero())
1100 column_info[c].valignment = LYX_VALIGN_TOP;
1101 for (row_type r = 0; r < nrows(); ++r) {
1102 idx_type const cell = cellIndex(r, c);
1103 // because of multicolumns
1104 toggleFixedWidth(cur, cellInset(cell).get(),
1105 !getPWidth(cell).zero());
1107 // cur paragraph can become invalid after paragraphs were merged
1108 if (cur.pit() > cur.lastpit())
1109 cur.pit() = cur.lastpit();
1110 // cur position can become invalid after newlines were removed
1111 if (cur.pos() > cur.lastpos())
1112 cur.pos() = cur.lastpos();
1116 bool Tabular::setFixedWidth(row_type r, col_type c)
1118 bool const multicol = cell_info[r][c].multicolumn != CELL_NORMAL;
1119 bool const fixed_width = (!column_info[c].p_width.zero() && !multicol)
1120 || (multicol && !cell_info[r][c].p_width.zero());
1121 cell_info[r][c].inset->toggleFixedWidth(fixed_width);
1126 bool Tabular::setMColumnPWidth(Cursor & cur, idx_type cell,
1127 Length const & width)
1129 if (!isMultiColumn(cell))
1132 cellInfo(cell).p_width = width;
1133 toggleFixedWidth(cur, cellInset(cell).get(), !width.zero());
1134 // cur paragraph can become invalid after paragraphs were merged
1135 if (cur.pit() > cur.lastpit())
1136 cur.pit() = cur.lastpit();
1137 // cur position can become invalid after newlines were removed
1138 if (cur.pos() > cur.lastpos())
1139 cur.pos() = cur.lastpos();
1144 bool Tabular::setMROffset(Cursor &, idx_type cell, Length const & mroffset)
1146 cellInfo(cell).mroffset = mroffset;
1151 void Tabular::setAlignSpecial(idx_type cell, docstring const & special,
1152 Tabular::Feature what)
1154 if (what == SET_SPECIAL_MULTICOLUMN)
1155 cellInfo(cell).align_special = special;
1157 column_info[cellColumn(cell)].align_special = special;
1161 void Tabular::setTopLine(idx_type i, bool line)
1163 cellInfo(i).top_line = line;
1167 void Tabular::setBottomLine(idx_type i, bool line)
1169 cellInfo(i).bottom_line = line;
1173 void Tabular::setLeftLine(idx_type cell, bool line)
1175 cellInfo(cell).left_line = line;
1179 void Tabular::setRightLine(idx_type cell, bool line)
1181 cellInfo(cell).right_line = line;
1184 bool Tabular::rowTopLine(row_type r) const
1186 bool all_rows_set = true;
1187 for (col_type c = 0; all_rows_set && c < ncols(); ++c)
1188 all_rows_set = cellInfo(cellIndex(r, c)).top_line;
1189 return all_rows_set;
1193 bool Tabular::rowBottomLine(row_type r) const
1195 bool all_rows_set = true;
1196 for (col_type c = 0; all_rows_set && c < ncols(); ++c)
1197 all_rows_set = cellInfo(cellIndex(r, c)).bottom_line;
1198 return all_rows_set;
1202 bool Tabular::columnLeftLine(col_type c) const
1209 for (row_type r = 0; r < nrows(); ++r) {
1210 idx_type const i = cellIndex(r, c);
1211 if (c == cellColumn(i)) {
1213 bool right = c > 0 && cellInfo(cellIndex(r, c - 1)).right_line;
1214 if (cellInfo(i).left_line || right)
1218 return 2 * nrows_left >= total;
1222 bool Tabular::columnRightLine(col_type c) const
1227 int nrows_right = 0;
1229 for (row_type r = 0; r < nrows(); ++r) {
1230 idx_type i = cellIndex(r, c);
1231 if (c == cellColumn(i) + columnSpan(i) - 1) {
1233 bool left = (c + 1 < ncols()
1234 && cellInfo(cellIndex(r, c + 1)).left_line)
1235 || c + 1 == ncols();
1236 if (cellInfo(i).right_line && left)
1240 return 2 * nrows_right >= total;
1244 LyXAlignment Tabular::getAlignment(idx_type cell, bool onlycolumn) const
1246 if (!onlycolumn && (isMultiColumn(cell) || isMultiRow(cell)))
1247 return cellInfo(cell).alignment;
1249 return column_info[cellColumn(cell)].alignment;
1254 Tabular::getVAlignment(idx_type cell, bool onlycolumn) const
1256 if (!onlycolumn && (isMultiColumn(cell) || isMultiRow(cell)))
1257 return cellInfo(cell).valignment;
1258 return column_info[cellColumn(cell)].valignment;
1262 Length const Tabular::getPWidth(idx_type cell) const
1264 if (isMultiColumn(cell))
1265 return cellInfo(cell).p_width;
1266 return column_info[cellColumn(cell)].p_width;
1270 Length const Tabular::getMROffset(idx_type cell) const
1272 return cellInfo(cell).mroffset;
1276 int Tabular::textHOffset(idx_type cell) const
1278 // the LaTeX Way :-(
1279 int x = WIDTH_OF_LINE;
1281 int const w = cellWidth(cell) - cellInfo(cell).width;
1283 switch (getAlignment(cell)) {
1284 case LYX_ALIGN_CENTER:
1287 case LYX_ALIGN_RIGHT:
1290 case LYX_ALIGN_DECIMAL: {
1291 // we center when no decimal point
1292 if (cellInfo(cell).decimal_width == 0) {
1296 col_type const c = cellColumn(cell);
1297 int max_dhoffset = 0;
1298 for(row_type r = 0; r < row_info.size() ; ++r) {
1299 idx_type const i = cellIndex(r, c);
1300 if (getAlignment(i) == LYX_ALIGN_DECIMAL
1301 && cellInfo(i).decimal_width != 0)
1302 max_dhoffset = max(max_dhoffset, cellInfo(i).decimal_hoffset);
1304 x += max_dhoffset - cellInfo(cell).decimal_hoffset;
1307 // LYX_ALIGN_LEFT: nothing :-)
1315 int Tabular::textVOffset(idx_type cell) const
1317 int voffset = cellInfo(cell).voffset;
1318 if (isMultiRow(cell)) {
1319 row_type const row = cellRow(cell);
1320 voffset += (cellHeight(cell) - rowAscent(row) - rowDescent(row))/2;
1326 Tabular::idx_type Tabular::getFirstCellInRow(row_type row) const
1329 while (cell_info[row][c].multirow == CELL_PART_OF_MULTIROW)
1331 return cell_info[row][c].cellno;
1335 Tabular::idx_type Tabular::getLastCellInRow(row_type row) const
1337 col_type c = ncols() - 1;
1338 while (cell_info[row][c].multirow == CELL_PART_OF_MULTIROW
1339 || cell_info[row][c].multicolumn == CELL_PART_OF_MULTICOLUMN)
1341 return cell_info[row][c].cellno;
1345 Tabular::row_type Tabular::cellRow(idx_type cell) const
1347 if (cell >= numberofcells)
1351 return rowofcell[cell];
1355 Tabular::col_type Tabular::cellColumn(idx_type cell) const
1357 if (cell >= numberofcells)
1361 return columnofcell[cell];
1365 void Tabular::write(ostream & os) const
1369 << write_attribute("version", 3)
1370 << write_attribute("rows", nrows())
1371 << write_attribute("columns", ncols())
1373 // global longtable options
1375 << write_attribute("rotate", rotate)
1376 << write_attribute("booktabs", use_booktabs)
1377 << write_attribute("islongtable", is_long_tabular)
1378 << write_attribute("firstHeadTopDL", endfirsthead.topDL)
1379 << write_attribute("firstHeadBottomDL", endfirsthead.bottomDL)
1380 << write_attribute("firstHeadEmpty", endfirsthead.empty)
1381 << write_attribute("headTopDL", endhead.topDL)
1382 << write_attribute("headBottomDL", endhead.bottomDL)
1383 << write_attribute("footTopDL", endfoot.topDL)
1384 << write_attribute("footBottomDL", endfoot.bottomDL)
1385 << write_attribute("lastFootTopDL", endlastfoot.topDL)
1386 << write_attribute("lastFootBottomDL", endlastfoot.bottomDL)
1387 << write_attribute("lastFootEmpty", endlastfoot.empty);
1388 // longtables cannot be aligned vertically
1389 if (!is_long_tabular)
1390 os << write_attribute("tabularvalignment", tabular_valignment);
1391 if (is_long_tabular)
1392 os << write_attribute("longtabularalignment",
1393 longtabular_alignment);
1395 for (col_type c = 0; c < ncols(); ++c) {
1397 << write_attribute("alignment", column_info[c].alignment);
1398 if (column_info[c].alignment == LYX_ALIGN_DECIMAL)
1399 os << write_attribute("decimal_point", column_info[c].decimal_point);
1400 os << write_attribute("valignment", column_info[c].valignment)
1401 << write_attribute("width", column_info[c].p_width.asString())
1402 << write_attribute("special", column_info[c].align_special)
1405 for (row_type r = 0; r < nrows(); ++r) {
1406 static const string def("default");
1408 if (row_info[r].top_space_default)
1409 os << write_attribute("topspace", def);
1411 os << write_attribute("topspace", row_info[r].top_space);
1412 if (row_info[r].bottom_space_default)
1413 os << write_attribute("bottomspace", def);
1415 os << write_attribute("bottomspace", row_info[r].bottom_space);
1416 if (row_info[r].interline_space_default)
1417 os << write_attribute("interlinespace", def);
1419 os << write_attribute("interlinespace", row_info[r].interline_space);
1420 os << write_attribute("endhead", row_info[r].endhead)
1421 << write_attribute("endfirsthead", row_info[r].endfirsthead)
1422 << write_attribute("endfoot", row_info[r].endfoot)
1423 << write_attribute("endlastfoot", row_info[r].endlastfoot)
1424 << write_attribute("newpage", row_info[r].newpage)
1425 << write_attribute("caption", row_info[r].caption)
1427 for (col_type c = 0; c < ncols(); ++c) {
1429 << write_attribute("multicolumn", cell_info[r][c].multicolumn)
1430 << write_attribute("multirow", cell_info[r][c].multirow)
1431 << write_attribute("mroffset", cell_info[r][c].mroffset)
1432 << write_attribute("alignment", cell_info[r][c].alignment)
1433 << write_attribute("valignment", cell_info[r][c].valignment)
1434 << write_attribute("topline", cell_info[r][c].top_line)
1435 << write_attribute("bottomline", cell_info[r][c].bottom_line)
1436 << write_attribute("leftline", cell_info[r][c].left_line)
1437 << write_attribute("rightline", cell_info[r][c].right_line)
1438 << write_attribute("rotate", cell_info[r][c].rotate)
1439 << write_attribute("usebox", cell_info[r][c].usebox)
1440 << write_attribute("width", cell_info[r][c].p_width)
1441 << write_attribute("special", cell_info[r][c].align_special)
1443 os << "\\begin_inset ";
1444 cell_info[r][c].inset->write(os);
1445 os << "\n\\end_inset\n"
1450 os << "</lyxtabular>\n";
1454 void Tabular::read(Lexer & lex)
1457 istream & is = lex.getStream();
1459 l_getline(is, line);
1460 if (!prefixIs(line, "<lyxtabular ") && !prefixIs(line, "<Tabular ")) {
1461 LASSERT(false, /**/);
1466 if (!getTokenValue(line, "version", version))
1468 LASSERT(version >= 2, /**/);
1471 if (!getTokenValue(line, "rows", rows_arg))
1474 if (!getTokenValue(line, "columns", columns_arg))
1476 init(buffer_, rows_arg, columns_arg);
1477 l_getline(is, line);
1478 if (!prefixIs(line, "<features")) {
1479 lyxerr << "Wrong tabular format (expected <features ...> got"
1480 << line << ')' << endl;
1483 getTokenValue(line, "rotate", rotate);
1484 getTokenValue(line, "booktabs", use_booktabs);
1485 getTokenValue(line, "islongtable", is_long_tabular);
1486 getTokenValue(line, "tabularvalignment", tabular_valignment);
1487 getTokenValue(line, "longtabularalignment", longtabular_alignment);
1488 getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
1489 getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
1490 getTokenValue(line, "firstHeadEmpty", endfirsthead.empty);
1491 getTokenValue(line, "headTopDL", endhead.topDL);
1492 getTokenValue(line, "headBottomDL", endhead.bottomDL);
1493 getTokenValue(line, "footTopDL", endfoot.topDL);
1494 getTokenValue(line, "footBottomDL", endfoot.bottomDL);
1495 getTokenValue(line, "lastFootTopDL", endlastfoot.topDL);
1496 getTokenValue(line, "lastFootBottomDL", endlastfoot.bottomDL);
1497 getTokenValue(line, "lastFootEmpty", endlastfoot.empty);
1499 for (col_type c = 0; c < ncols(); ++c) {
1501 if (!prefixIs(line,"<column")) {
1502 lyxerr << "Wrong tabular format (expected <column ...> got"
1503 << line << ')' << endl;
1506 getTokenValue(line, "alignment", column_info[c].alignment);
1507 getTokenValue(line, "decimal_point", column_info[c].decimal_point);
1508 getTokenValue(line, "valignment", column_info[c].valignment);
1509 getTokenValue(line, "width", column_info[c].p_width);
1510 getTokenValue(line, "special", column_info[c].align_special);
1513 for (row_type i = 0; i < nrows(); ++i) {
1514 l_getline(is, line);
1515 if (!prefixIs(line, "<row")) {
1516 lyxerr << "Wrong tabular format (expected <row ...> got"
1517 << line << ')' << endl;
1520 getTokenValue(line, "topspace", row_info[i].top_space,
1521 row_info[i].top_space_default);
1522 getTokenValue(line, "bottomspace", row_info[i].bottom_space,
1523 row_info[i].bottom_space_default);
1524 getTokenValue(line, "interlinespace", row_info[i].interline_space,
1525 row_info[i].interline_space_default);
1526 getTokenValue(line, "endfirsthead", row_info[i].endfirsthead);
1527 getTokenValue(line, "endhead", row_info[i].endhead);
1528 getTokenValue(line, "endfoot", row_info[i].endfoot);
1529 getTokenValue(line, "endlastfoot", row_info[i].endlastfoot);
1530 getTokenValue(line, "newpage", row_info[i].newpage);
1531 getTokenValue(line, "caption", row_info[i].caption);
1532 for (col_type j = 0; j < ncols(); ++j) {
1533 l_getline(is, line);
1534 if (!prefixIs(line, "<cell")) {
1535 lyxerr << "Wrong tabular format (expected <cell ...> got"
1536 << line << ')' << endl;
1539 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1540 getTokenValue(line, "multirow", cell_info[i][j].multirow);
1541 getTokenValue(line, "mroffset", cell_info[i][j].mroffset);
1542 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1543 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1544 getTokenValue(line, "topline", cell_info[i][j].top_line);
1545 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1546 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1547 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1548 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1549 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1550 getTokenValue(line, "width", cell_info[i][j].p_width);
1552 getTokenValue(line, "special", cell_info[i][j].align_special);
1553 l_getline(is, line);
1554 if (prefixIs(line, "\\begin_inset")) {
1555 cell_info[i][j].inset->setBuffer(*buffer_);
1556 cell_info[i][j].inset->read(lex);
1557 l_getline(is, line);
1559 if (!prefixIs(line, "</cell>")) {
1560 lyxerr << "Wrong tabular format (expected </cell> got"
1561 << line << ')' << endl;
1565 l_getline(is, line);
1566 if (!prefixIs(line, "</row>")) {
1567 lyxerr << "Wrong tabular format (expected </row> got"
1568 << line << ')' << endl;
1572 while (!prefixIs(line, "</lyxtabular>")) {
1573 l_getline(is, line);
1579 bool Tabular::isMultiColumn(idx_type cell) const
1581 return (cellInfo(cell).multicolumn == CELL_BEGIN_OF_MULTICOLUMN
1582 || cellInfo(cell).multicolumn == CELL_PART_OF_MULTICOLUMN);
1586 Tabular::CellData & Tabular::cellInfo(idx_type cell) const
1588 return cell_info[cellRow(cell)][cellColumn(cell)];
1592 Tabular::idx_type Tabular::setMultiColumn(idx_type cell, idx_type number)
1594 idx_type const col = cellColumn(cell);
1595 idx_type const row = cellRow(cell);
1596 for (idx_type i = 0; i < number; ++i)
1597 unsetMultiRow(cellIndex(row, col + i));
1599 // unsetting of multirow may have invalidated cell index
1600 cell = cellIndex(row, col);
1601 CellData & cs = cellInfo(cell);
1602 cs.multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1603 if (column_info[col].alignment != LYX_ALIGN_DECIMAL)
1604 cs.alignment = column_info[col].alignment;
1606 setRightLine(cell, rightLine(cellIndex(row, col - 1)));
1608 for (idx_type i = 1; i < number; ++i) {
1609 CellData & cs1 = cellInfo(cell + i);
1610 cs1.multicolumn = CELL_PART_OF_MULTICOLUMN;
1611 cs.inset->appendParagraphs(cs1.inset->paragraphs());
1619 bool Tabular::isMultiRow(idx_type cell) const
1621 return (cellInfo(cell).multirow == CELL_BEGIN_OF_MULTIROW
1622 || cellInfo(cell).multirow == CELL_PART_OF_MULTIROW);
1626 Tabular::idx_type Tabular::setMultiRow(idx_type cell, idx_type number)
1628 idx_type const col = cellColumn(cell);
1629 idx_type const row = cellRow(cell);
1630 for (idx_type i = 0; i < number; ++i)
1631 unsetMultiColumn(cellIndex(row + i, col));
1633 // unsetting of multirow may have invalidated cell index
1634 cell = cellIndex(row, col);
1635 CellData & cs = cellInfo(cell);
1636 cs.multirow = CELL_BEGIN_OF_MULTIROW;
1637 cs.valignment = LYX_VALIGN_MIDDLE;
1638 // the horizontal alignment of multirow cells can only
1639 // be changed for the whole table row,
1640 // support changing this only for the multirow cell can be done via
1642 // this feature would be a fileformat change
1643 // until LyX supports this, use the deault alignment of multirow
1645 cs.alignment = LYX_ALIGN_LEFT;
1647 // set the bottom row of the last selected cell
1648 setBottomLine(cell, bottomLine(cell + (number - 1)*ncols()));
1650 for (idx_type i = 1; i < number; ++i) {
1651 CellData & cs1 = cell_info[row + i][col];
1652 cs1.multirow = CELL_PART_OF_MULTIROW;
1653 cs.inset->appendParagraphs(cs1.inset->paragraphs());
1661 Tabular::idx_type Tabular::columnSpan(idx_type cell) const
1663 row_type const row = cellRow(cell);
1664 col_type const col = cellColumn(cell);
1666 while (col + span < ncols() && isPartOfMultiColumn(row, col + span))
1673 Tabular::idx_type Tabular::rowSpan(idx_type cell) const
1675 col_type const column = cellColumn(cell);
1676 col_type row = cellRow(cell) + 1;
1677 while (row < nrows() && isPartOfMultiRow(row, column))
1680 return row - cellRow(cell);
1684 void Tabular::unsetMultiColumn(idx_type cell)
1686 if (!isMultiColumn(cell))
1689 row_type const row = cellRow(cell);
1690 col_type const col = cellColumn(cell);
1691 row_type const span = columnSpan(cell);
1692 for (col_type c = 0; c < span; ++c) {
1693 // in the table dialog the lines are set in every case
1694 // when unsetting a multicolumn this leads to an additional right
1695 // line for every cell that was part of the former multicolumn cell,
1696 // except if the cell is in the last column
1697 // therefore remove this line
1698 if (cell_info[row][col + c].multicolumn == CELL_BEGIN_OF_MULTICOLUMN
1699 && (col + c) < (col + span - 1))
1700 cell_info[row][col + c].right_line = false;
1701 cell_info[row][col + c].multicolumn = CELL_NORMAL;
1707 void Tabular::unsetMultiRow(idx_type cell)
1709 if (!isMultiRow(cell))
1712 cellInfo(cell).valignment = LYX_VALIGN_TOP;
1713 cellInfo(cell).alignment = LYX_ALIGN_CENTER;
1714 row_type const row = cellRow(cell);
1715 col_type const col = cellColumn(cell);
1716 row_type const span = rowSpan(cell);
1717 for (row_type r = 0; r < span; ++r)
1718 cell_info[row + r][col].multirow = CELL_NORMAL;
1723 void Tabular::setRotateCell(idx_type cell, bool flag)
1725 cellInfo(cell).rotate = flag;
1729 bool Tabular::getRotateCell(idx_type cell) const
1731 return cellInfo(cell).rotate;
1735 bool Tabular::needRotating() const
1739 for (row_type r = 0; r < nrows(); ++r)
1740 for (col_type c = 0; c < ncols(); ++c)
1741 if (cell_info[r][c].rotate)
1747 bool Tabular::isLastCell(idx_type cell) const
1749 if (cell + 1 < numberofcells)
1755 Tabular::idx_type Tabular::cellAbove(idx_type cell) const
1757 if (cellRow(cell) == 0)
1760 col_type const col = cellColumn(cell);
1761 row_type r = cellRow(cell) - 1;
1762 while (r > 0 && cell_info[r][col].multirow == CELL_PART_OF_MULTIROW)
1765 return cell_info[r][col].cellno;
1769 Tabular::idx_type Tabular::cellBelow(idx_type cell) const
1771 row_type const nextrow = cellRow(cell) + rowSpan(cell);
1772 if (nextrow < nrows())
1773 return cell_info[nextrow][cellColumn(cell)].cellno;
1778 Tabular::idx_type Tabular::cellIndex(row_type row, col_type column) const
1780 LASSERT(column != npos && column < ncols()
1781 && row != npos && row < nrows(), /**/);
1782 return cell_info[row][column].cellno;
1786 void Tabular::setUsebox(idx_type cell, BoxType type)
1788 cellInfo(cell).usebox = type;
1792 // FIXME: Remove this routine because we cannot insert \parboxes when the user
1793 // adds line breaks, see bug 4886.
1794 Tabular::BoxType Tabular::getUsebox(idx_type cell) const
1796 if ((!column_info[cellColumn(cell)].p_width.zero() && !isMultiColumn(cell)) ||
1797 (isMultiColumn(cell) && !cellInfo(cell).p_width.zero()))
1799 if (cellInfo(cell).usebox > 1)
1800 return cellInfo(cell).usebox;
1801 return useParbox(cell);
1806 // This are functions used for the longtable support
1808 void Tabular::setLTHead(row_type row, bool flag, ltType const & hd,
1814 row_info[row].endfirsthead = flag;
1818 row_info[row].endhead = flag;
1823 bool Tabular::getRowOfLTHead(row_type row, ltType & hd) const
1826 hd.set = haveLTHead();
1827 return row_info[row].endhead;
1831 bool Tabular::getRowOfLTFirstHead(row_type row, ltType & hd) const
1834 hd.set = haveLTFirstHead();
1835 return row_info[row].endfirsthead;
1839 void Tabular::setLTFoot(row_type row, bool flag, ltType const & fd,
1845 row_info[row].endlastfoot = flag;
1849 row_info[row].endfoot = flag;
1854 bool Tabular::getRowOfLTFoot(row_type row, ltType & fd) const
1857 fd.set = haveLTFoot();
1858 return row_info[row].endfoot;
1862 bool Tabular::getRowOfLTLastFoot(row_type row, ltType & fd) const
1865 fd.set = haveLTLastFoot();
1866 return row_info[row].endlastfoot;
1870 void Tabular::setLTNewPage(row_type row, bool what)
1872 row_info[row].newpage = what;
1876 bool Tabular::getLTNewPage(row_type row) const
1878 return row_info[row].newpage;
1882 bool Tabular::haveLTHead() const
1884 for (row_type i = 0; i < nrows(); ++i)
1885 if (row_info[i].endhead)
1891 bool Tabular::haveLTFirstHead() const
1893 if (endfirsthead.empty)
1895 for (row_type r = 0; r < nrows(); ++r)
1896 if (row_info[r].endfirsthead)
1902 bool Tabular::haveLTFoot() const
1904 for (row_type r = 0; r < nrows(); ++r)
1905 if (row_info[r].endfoot)
1911 bool Tabular::haveLTLastFoot() const
1913 if (endlastfoot.empty)
1915 for (row_type r = 0; r < nrows(); ++r)
1916 if (row_info[r].endlastfoot)
1922 Tabular::idx_type Tabular::setLTCaption(row_type row, bool what)
1924 idx_type i = getFirstCellInRow(row);
1926 setMultiColumn(i, numberOfCellsInRow(row));
1927 setTopLine(i, false);
1928 setBottomLine(i, false);
1929 setLeftLine(i, false);
1930 setRightLine(i, false);
1932 unsetMultiColumn(i);
1933 // When unsetting a caption row, also all existing
1934 // captions in this row must be dissolved.
1936 row_info[row].caption = what;
1941 bool Tabular::ltCaption(row_type row) const
1943 return row_info[row].caption;
1947 bool Tabular::haveLTCaption() const
1949 for (row_type r = 0; r < nrows(); ++r)
1950 if (row_info[r].caption)
1956 // end longtable support functions
1958 void Tabular::setRowAscent(row_type row, int height)
1960 if (row >= nrows() || row_info[row].ascent == height)
1962 row_info[row].ascent = height;
1966 void Tabular::setRowDescent(row_type row, int height)
1968 if (row >= nrows() || row_info[row].descent == height)
1970 row_info[row].descent = height;
1974 int Tabular::rowAscent(row_type row) const
1976 LASSERT(row < nrows(), /**/);
1977 return row_info[row].ascent;
1981 int Tabular::rowDescent(row_type row) const
1983 LASSERT(row < nrows(), /**/);
1984 return row_info[row].descent;
1988 int Tabular::height() const
1991 for (row_type row = 0; row < nrows(); ++row)
1992 height += rowAscent(row) + rowDescent(row) +
1998 bool Tabular::isPartOfMultiColumn(row_type row, col_type column) const
2000 LASSERT(row < nrows(), /**/);
2001 LASSERT(column < ncols(), /**/);
2002 return cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN;
2006 bool Tabular::isPartOfMultiRow(row_type row, col_type column) const
2008 LASSERT(row < nrows(), /**/);
2009 LASSERT(column < ncols(), /**/);
2010 return cell_info[row][column].multirow == CELL_PART_OF_MULTIROW;
2014 int Tabular::TeXTopHLine(odocstream & os, row_type row, string const lang) const
2016 // we only output complete row lines and the 1st row here, the rest
2017 // is done in Tabular::TeXBottomHLine(...)
2019 // get for each column the topline (if any)
2020 vector<bool> topline;
2022 for (col_type c = 0; c < ncols(); ++c) {
2023 topline.push_back(topLine(cellIndex(row, c)));
2024 // If cell is part of a multirow and not the first cell of the
2025 // multirow, no line must be drawn.
2027 if (isMultiRow(cellIndex(row, c))
2028 && isMultiRow(cellIndex(row - 1, c)))
2034 // do nothing if empty first row, or incomplete row line after
2035 if ((row == 0 && nset == 0) || (row > 0 && nset != ncols()))
2038 // only output complete row lines and the 1st row's clines
2039 if (nset == ncols()) {
2041 os << (row == 0 ? "\\toprule " : "\\midrule ");
2045 } else if (row == 0) {
2046 for (col_type c = 0; c < ncols(); ++c) {
2048 col_type offset = 0;
2049 for (col_type j = 0 ; j < c; ++j)
2050 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2053 //babel makes the "-" character an active one, so we have to suppress this here
2054 //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
2055 if (lang == "slovak" || lang == "czech")
2056 os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline")
2057 << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
2059 os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
2061 col_type cstart = c;
2062 for ( ; c < ncols() && topline[c]; ++c) {}
2064 for (col_type j = cstart ; j < c ; ++j)
2065 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2068 os << c + offset << "} ";
2077 int Tabular::TeXBottomHLine(odocstream & os, row_type row, string const lang) const
2079 // we output bottomlines of row r and the toplines of row r+1
2080 // if the latter do not span the whole tabular
2082 // get the bottomlines of row r, and toplines in next row
2083 bool lastrow = row == nrows() - 1;
2084 vector<bool> bottomline, topline;
2085 bool nextrowset = true;
2086 for (col_type c = 0; c < ncols(); ++c) {
2087 bottomline.push_back(bottomLine(cellIndex(row, c)));
2088 topline.push_back(!lastrow && topLine(cellIndex(row + 1, c)));
2089 // If cell is part of a multirow and not the last or first cell of the
2090 // multirow, no line must be drawn.
2092 if (isMultiRow(cellIndex(row, c))
2093 && isMultiRow(cellIndex(row + 1, c))) {
2094 bottomline[c] = false;
2097 nextrowset &= topline[c];
2100 // combine this row's bottom lines and next row's toplines if necessary
2102 for (col_type c = 0; c < ncols(); ++c) {
2104 bottomline[c] = bottomline[c] || topline[c];
2109 // do nothing if empty, OR incomplete row line with a topline in next row
2110 if (nset == 0 || (nextrowset && nset != ncols()))
2113 if (nset == ncols()) {
2115 os << (lastrow ? "\\bottomrule" : "\\midrule");
2119 for (col_type c = 0; c < ncols(); ++c) {
2120 if (bottomline[c]) {
2121 col_type offset = 0;
2122 for (col_type j = 0 ; j < c; ++j)
2123 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2126 //babel makes the "-" character an active one, so we have to suppress this here
2127 //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
2128 if (lang == "slovak" || lang == "czech")
2129 os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline")
2130 << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
2132 os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
2134 col_type cstart = c;
2135 for ( ; c < ncols() && bottomline[c]; ++c) {}
2137 for (col_type j = cstart ; j < c ; ++j)
2138 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2141 os << c + offset << "} ";
2150 int Tabular::TeXCellPreamble(odocstream & os, idx_type cell,
2151 bool & ismulticol, bool & ismultirow) const
2154 row_type const r = cellRow(cell);
2155 if (is_long_tabular && row_info[r].caption)
2158 Tabular::VAlignment valign = getVAlignment(cell, !isMultiColumn(cell));
2159 LyXAlignment align = getAlignment(cell, !isMultiColumn(cell));
2160 // figure out how to set the lines
2161 // we always set double lines to the right of the cell
2162 col_type const c = cellColumn(cell);
2163 col_type const nextcol = c + columnSpan(cell);
2164 bool colright = columnRightLine(c);
2165 bool colleft = columnLeftLine(c);
2166 bool nextcolleft = nextcol < ncols() && columnLeftLine(nextcol);
2167 bool nextcellleft = nextcol < ncols()
2168 && leftLine(cellIndex(r, nextcol));
2169 bool coldouble = colright && nextcolleft;
2170 bool celldouble = rightLine(cell) && nextcellleft;
2172 ismulticol = isMultiColumn(cell)
2173 || (c == 0 && colleft != leftLine(cell))
2174 || ((colright || nextcolleft) && !rightLine(cell) && !nextcellleft)
2175 || (!colright && !nextcolleft && (rightLine(cell) || nextcellleft))
2176 || (coldouble != celldouble);
2178 // we center in multicol when no decimal point
2179 ismulticol |= ((column_info[c].alignment == LYX_ALIGN_DECIMAL)
2180 && (cellInfo(cell).decimal_width == 0));
2182 // up counter by 1 for each decimally aligned col since they use 2 latex cols
2183 int latexcolspan = columnSpan(cell);
2184 for(col_type col = c; col < c + columnSpan(cell); ++col)
2185 if (column_info[col].alignment == LYX_ALIGN_DECIMAL)
2189 os << "\\multicolumn{" << latexcolspan << "}{";
2190 if (c ==0 && leftLine(cell))
2192 if (!cellInfo(cell).align_special.empty()) {
2193 os << cellInfo(cell).align_special;
2195 if (!getPWidth(cell).zero()) {
2197 case LYX_ALIGN_LEFT:
2198 os << ">{\\raggedright}";
2200 case LYX_ALIGN_RIGHT:
2201 os << ">{\\raggedleft}";
2203 case LYX_ALIGN_CENTER:
2204 os << ">{\\centering}";
2210 case LYX_VALIGN_TOP:
2213 case LYX_VALIGN_MIDDLE:
2216 case LYX_VALIGN_BOTTOM:
2221 << from_ascii(getPWidth(cell).asLatexString())
2225 case LYX_ALIGN_LEFT:
2228 case LYX_ALIGN_RIGHT:
2235 } // end if else !getPWidth
2236 } // end if else !cellinfo_of_cell
2237 if (rightLine(cell) || nextcellleft)
2240 // add extra vertical line if we want a double one
2243 } // end if ismulticol
2245 // we only need code for the first multirow cell
2246 ismultirow = isMultiRow(cell);
2248 os << "\\multirow{" << rowSpan(cell) << "}{";
2249 if (!getPWidth(cell).zero())
2250 os << from_ascii(getPWidth(cell).asLatexString());
2252 // we need to set a default value
2255 if (!getMROffset(cell).zero())
2256 os << "[" << from_ascii(getMROffset(cell).asLatexString()) << "]";
2258 } // end if ismultirow
2260 if (getRotateCell(cell)) {
2261 os << "\\begin{sideways}\n";
2264 if (getUsebox(cell) == BOX_PARBOX) {
2267 case LYX_VALIGN_TOP:
2270 case LYX_VALIGN_MIDDLE:
2273 case LYX_VALIGN_BOTTOM:
2277 os << "]{" << from_ascii(getPWidth(cell).asLatexString())
2279 } else if (getUsebox(cell) == BOX_MINIPAGE) {
2280 os << "\\begin{minipage}[";
2282 case LYX_VALIGN_TOP:
2285 case LYX_VALIGN_MIDDLE:
2288 case LYX_VALIGN_BOTTOM:
2292 os << "]{" << from_ascii(getPWidth(cell).asLatexString())
2300 int Tabular::TeXCellPostamble(odocstream & os, idx_type cell,
2301 bool ismulticol, bool ismultirow) const
2304 row_type const r = cellRow(cell);
2305 if (is_long_tabular && row_info[r].caption)
2309 if (getUsebox(cell) == BOX_PARBOX)
2311 else if (getUsebox(cell) == BOX_MINIPAGE) {
2312 os << "%\n\\end{minipage}";
2315 if (getRotateCell(cell)) {
2316 os << "%\n\\end{sideways}";
2328 int Tabular::TeXLongtableHeaderFooter(odocstream & os,
2329 OutputParams const & runparams) const
2331 if (!is_long_tabular)
2336 // the caption must be output before the headers
2337 if (haveLTCaption()) {
2338 for (row_type r = 0; r < nrows(); ++r) {
2339 if (row_info[r].caption) {
2340 ret += TeXRow(os, r, runparams);
2344 // output first header info
2345 // first header must be output before the header, otherwise the
2346 // correct caption placement becomes really weird
2347 if (haveLTFirstHead()) {
2348 if (endfirsthead.topDL) {
2352 for (row_type r = 0; r < nrows(); ++r) {
2353 if (row_info[r].endfirsthead) {
2354 ret += TeXRow(os, r, runparams);
2357 if (endfirsthead.bottomDL) {
2361 os << "\\endfirsthead\n";
2364 // output header info
2366 if (endfirsthead.empty && !haveLTFirstHead()) {
2367 os << "\\endfirsthead\n";
2370 if (endhead.topDL) {
2374 for (row_type r = 0; r < nrows(); ++r) {
2375 if (row_info[r].endhead) {
2376 ret += TeXRow(os, r, runparams);
2379 if (endhead.bottomDL) {
2383 os << "\\endhead\n";
2386 // output footer info
2388 if (endfoot.topDL) {
2392 for (row_type r = 0; r < nrows(); ++r) {
2393 if (row_info[r].endfoot) {
2394 ret += TeXRow(os, r, runparams);
2397 if (endfoot.bottomDL) {
2401 os << "\\endfoot\n";
2403 if (endlastfoot.empty && !haveLTLastFoot()) {
2404 os << "\\endlastfoot\n";
2408 // output lastfooter info
2409 if (haveLTLastFoot()) {
2410 if (endlastfoot.topDL) {
2414 for (row_type r = 0; r < nrows(); ++r) {
2415 if (row_info[r].endlastfoot) {
2416 ret += TeXRow(os, r, runparams);
2419 if (endlastfoot.bottomDL) {
2423 os << "\\endlastfoot\n";
2430 bool Tabular::isValidRow(row_type row) const
2432 if (!is_long_tabular)
2434 return !row_info[row].endhead && !row_info[row].endfirsthead
2435 && !row_info[row].endfoot && !row_info[row].endlastfoot
2436 && !row_info[row].caption;
2440 int Tabular::TeXRow(odocstream & os, row_type row,
2441 OutputParams const & runparams) const
2443 idx_type cell = cellIndex(row, 0);
2444 shared_ptr<InsetTableCell> inset = cellInset(cell);
2445 Paragraph const & par = inset->paragraphs().front();
2446 string const lang = par.getParLanguage(buffer().params())->lang();
2448 //output the top line
2449 int ret = TeXTopHLine(os, row, lang);
2451 if (row_info[row].top_space_default) {
2453 os << "\\addlinespace\n";
2455 os << "\\noalign{\\vskip\\doublerulesep}\n";
2457 } else if(!row_info[row].top_space.zero()) {
2459 os << "\\addlinespace["
2460 << from_ascii(row_info[row].top_space.asLatexString())
2463 os << "\\noalign{\\vskip"
2464 << from_ascii(row_info[row].top_space.asLatexString())
2469 bool ismulticol = false;
2470 bool ismultirow = false;
2471 for (col_type c = 0; c < ncols(); ++c) {
2472 if (isPartOfMultiColumn(row, c))
2475 if (isPartOfMultiRow(row, c) &&
2476 column_info[c].alignment != LYX_ALIGN_DECIMAL) {
2481 cell = cellIndex(row, c);
2482 ret += TeXCellPreamble(os, cell, ismulticol, ismultirow);
2483 shared_ptr<InsetTableCell> inset = cellInset(cell);
2485 Paragraph const & par = inset->paragraphs().front();
2486 bool rtl = par.isRTL(buffer().params())
2488 && getPWidth(cell).zero();
2492 par.getParLanguage(buffer().params())->lang();
2493 if (lang == "farsi")
2495 else if (lang == "arabic_arabi")
2497 // currently, remaning RTL languages are
2498 // arabic_arabtex and hebrew
2502 // pass to the OutputParams that we are in a cell and
2503 // which alignment we have set.
2504 // InsetNewline needs this context information.
2505 OutputParams newrp(runparams);
2506 newrp.inTableCell = (getAlignment(cell) == LYX_ALIGN_BLOCK)
2507 ? OutputParams::PLAIN
2508 : OutputParams::ALIGNED;
2510 if (getAlignment(cell) == LYX_ALIGN_DECIMAL
2511 && cellInfo(cell).decimal_width != 0) {
2512 // copy cell and split in 2
2513 InsetTableCell head = InsetTableCell(*cellInset(cell).get());
2514 head.getText(0)->setMacrocontextPosition(
2515 cellInset(cell)->getText(0)->macrocontextPosition());
2516 head.setBuffer(buffer());
2517 bool hassep = false;
2518 InsetTableCell tail = splitCell(head, column_info[c].decimal_point, hassep);
2519 head.latex(os, newrp);
2521 ret += tail.latex(os, newrp);
2522 } else if (!isPartOfMultiRow(row, c))
2523 ret += inset->latex(os, newrp);
2525 runparams.encoding = newrp.encoding;
2529 ret += TeXCellPostamble(os, cell, ismulticol, ismultirow);
2530 if (cell != getLastCellInRow(row)) { // not last cell in row
2534 if (row_info[row].caption && !endfirsthead.empty && !haveLTFirstHead())
2535 // if no first header and no empty first header is used,
2536 // the caption needs to be terminated by \endfirsthead
2538 os << "\\endfirsthead";
2540 os << "\\tabularnewline";
2541 if (row_info[row].bottom_space_default) {
2543 os << "\\addlinespace";
2545 os << "[\\doublerulesep]";
2546 } else if (!row_info[row].bottom_space.zero()) {
2548 os << "\\addlinespace";
2550 << from_ascii(row_info[row].bottom_space.asLatexString())
2556 //output the bottom line
2557 ret += TeXBottomHLine(os, row, lang);
2559 if (row_info[row].interline_space_default) {
2561 os << "\\addlinespace\n";
2563 os << "\\noalign{\\vskip\\doublerulesep}\n";
2565 } else if (!row_info[row].interline_space.zero()) {
2567 os << "\\addlinespace["
2568 << from_ascii(row_info[row].interline_space.asLatexString())
2571 os << "\\noalign{\\vskip"
2572 << from_ascii(row_info[row].interline_space.asLatexString())
2580 int Tabular::latex(odocstream & os, OutputParams const & runparams) const
2584 //+---------------------------------------------------------------------
2585 //+ first the opening preamble +
2586 //+---------------------------------------------------------------------
2589 os << "\\begin{sideways}\n";
2592 if (is_long_tabular) {
2593 os << "\\begin{longtable}";
2594 switch (longtabular_alignment) {
2595 case LYX_LONGTABULAR_ALIGN_LEFT:
2598 case LYX_LONGTABULAR_ALIGN_CENTER:
2600 case LYX_LONGTABULAR_ALIGN_RIGHT:
2605 os << "\\begin{tabular}";
2606 switch (tabular_valignment) {
2607 case LYX_VALIGN_TOP:
2610 case LYX_VALIGN_MIDDLE:
2612 case LYX_VALIGN_BOTTOM:
2620 for (col_type c = 0; c < ncols(); ++c) {
2621 if (columnLeftLine(c))
2623 if (!column_info[c].align_special.empty()) {
2624 os << column_info[c].align_special;
2626 if (!column_info[c].p_width.zero()) {
2627 switch (column_info[c].alignment) {
2628 case LYX_ALIGN_LEFT:
2629 os << ">{\\raggedright}";
2631 case LYX_ALIGN_RIGHT:
2632 os << ">{\\raggedleft}";
2634 case LYX_ALIGN_CENTER:
2635 os << ">{\\centering}";
2637 case LYX_ALIGN_NONE:
2638 case LYX_ALIGN_BLOCK:
2639 case LYX_ALIGN_LAYOUT:
2640 case LYX_ALIGN_SPECIAL:
2641 case LYX_ALIGN_DECIMAL:
2645 switch (column_info[c].valignment) {
2646 case LYX_VALIGN_TOP:
2649 case LYX_VALIGN_MIDDLE:
2652 case LYX_VALIGN_BOTTOM:
2657 << from_ascii(column_info[c].p_width.asLatexString())
2660 switch (column_info[c].alignment) {
2661 case LYX_ALIGN_LEFT:
2664 case LYX_ALIGN_RIGHT:
2667 case LYX_ALIGN_DECIMAL:
2668 os << "r@{\\extracolsep{0pt}" << column_info[c].decimal_point << "}l";
2674 } // end if else !column_info[i].p_width
2675 } // end if else !column_info[i].align_special
2676 if (columnRightLine(c))
2682 ret += TeXLongtableHeaderFooter(os, runparams);
2684 //+---------------------------------------------------------------------
2685 //+ the single row and columns (cells) +
2686 //+---------------------------------------------------------------------
2688 for (row_type r = 0; r < nrows(); ++r) {
2689 if (isValidRow(r)) {
2690 ret += TeXRow(os, r, runparams);
2691 if (is_long_tabular && row_info[r].newpage) {
2692 os << "\\newpage\n";
2698 //+---------------------------------------------------------------------
2699 //+ the closing of the tabular +
2700 //+---------------------------------------------------------------------
2702 if (is_long_tabular)
2703 os << "\\end{longtable}";
2705 os << "\\end{tabular}";
2707 os << "\n\\end{sideways}";
2715 int Tabular::docbookRow(odocstream & os, row_type row,
2716 OutputParams const & runparams) const
2719 idx_type cell = getFirstCellInRow(row);
2722 for (col_type c = 0; c < ncols(); ++c) {
2723 if (isPartOfMultiColumn(row, c))
2726 os << "<entry align=\"";
2727 switch (getAlignment(cell)) {
2728 case LYX_ALIGN_LEFT:
2731 case LYX_ALIGN_RIGHT:
2739 os << "\" valign=\"";
2740 switch (getVAlignment(cell)) {
2741 case LYX_VALIGN_TOP:
2744 case LYX_VALIGN_BOTTOM:
2747 case LYX_VALIGN_MIDDLE:
2752 if (isMultiColumn(cell)) {
2753 os << " namest=\"col" << c << "\" ";
2754 os << "nameend=\"col" << c + columnSpan(cell) - 1 << '"';
2758 ret += cellInset(cell)->docbook(os, runparams);
2767 int Tabular::docbook(odocstream & os, OutputParams const & runparams) const
2771 //+---------------------------------------------------------------------
2772 //+ first the opening preamble +
2773 //+---------------------------------------------------------------------
2775 os << "<tgroup cols=\"" << ncols()
2776 << "\" colsep=\"1\" rowsep=\"1\">\n";
2778 for (col_type c = 0; c < ncols(); ++c) {
2779 os << "<colspec colname=\"col" << c << "\" align=\"";
2780 switch (column_info[c].alignment) {
2781 case LYX_ALIGN_LEFT:
2784 case LYX_ALIGN_RIGHT:
2792 if (runparams.flavor == OutputParams::XML)
2798 //+---------------------------------------------------------------------
2799 //+ Long Tabular case +
2800 //+---------------------------------------------------------------------
2802 // output caption info
2803 if (haveLTCaption()) {
2804 os << "<caption>\n";
2806 for (row_type r = 0; r < nrows(); ++r) {
2807 if (row_info[r].caption) {
2808 ret += docbookRow(os, r, runparams);
2811 os << "</caption>\n";
2814 // output header info
2815 if (haveLTHead() || haveLTFirstHead()) {
2818 for (row_type r = 0; r < nrows(); ++r) {
2819 if (row_info[r].endhead || row_info[r].endfirsthead) {
2820 ret += docbookRow(os, r, runparams);
2826 // output footer info
2827 if (haveLTFoot() || haveLTLastFoot()) {
2830 for (row_type r = 0; r < nrows(); ++r) {
2831 if (row_info[r].endfoot || row_info[r].endlastfoot) {
2832 ret += docbookRow(os, r, runparams);
2839 //+---------------------------------------------------------------------
2840 //+ the single row and columns (cells) +
2841 //+---------------------------------------------------------------------
2845 for (row_type r = 0; r < nrows(); ++r) {
2846 if (isValidRow(r)) {
2847 ret += docbookRow(os, r, runparams);
2852 //+---------------------------------------------------------------------
2853 //+ the closing of the tabular +
2854 //+---------------------------------------------------------------------
2863 docstring Tabular::xhtmlRow(XHTMLStream & xs, row_type row,
2864 OutputParams const & runparams) const
2867 idx_type cell = getFirstCellInRow(row);
2869 xs << html::StartTag("tr");
2870 for (col_type c = 0; c < ncols(); ++c) {
2871 if (isPartOfMultiColumn(row, c))
2876 switch (getAlignment(cell)) {
2877 case LYX_ALIGN_LEFT:
2880 case LYX_ALIGN_RIGHT:
2888 attr << " valign='";
2889 switch (getVAlignment(cell)) {
2890 case LYX_VALIGN_TOP:
2893 case LYX_VALIGN_BOTTOM:
2896 case LYX_VALIGN_MIDDLE:
2901 if (isMultiColumn(cell))
2902 attr << " colspan='" << columnSpan(cell) << "'";
2904 xs << html::StartTag("td", attr.str());
2905 ret += cellInset(cell)->xhtml(xs, runparams);
2906 xs << html::EndTag("td");
2909 xs << html::EndTag("tr");
2914 docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
2917 // It's unclear to me if we need to mess with the long table stuff.
2918 // We can borrow that too from docbook, if so.
2920 xs << html::StartTag("tbody");
2921 for (row_type r = 0; r < nrows(); ++r) {
2922 if (isValidRow(r)) {
2923 ret += xhtmlRow(xs, r, runparams);
2926 xs << html::EndTag("tbody");
2931 bool Tabular::plaintextTopHLine(odocstream & os, row_type row,
2932 vector<unsigned int> const & clen) const
2934 idx_type const fcell = getFirstCellInRow(row);
2935 idx_type const n = numberOfCellsInRow(row) + fcell;
2938 for (idx_type i = fcell; i < n; ++i) {
2948 for (idx_type i = fcell; i < n; ++i) {
2959 col_type column = cellColumn(i);
2960 int len = clen[column];
2961 while (column < ncols() - 1
2962 && isPartOfMultiColumn(row, ++column))
2963 len += clen[column] + 4;
2964 os << docstring(len, ch);
2979 bool Tabular::plaintextBottomHLine(odocstream & os, row_type row,
2980 vector<unsigned int> const & clen) const
2982 idx_type const fcell = getFirstCellInRow(row);
2983 idx_type const n = numberOfCellsInRow(row) + fcell;
2986 for (idx_type i = fcell; i < n; ++i) {
2987 if (bottomLine(i)) {
2996 for (idx_type i = fcell; i < n; ++i) {
2997 if (bottomLine(i)) {
3007 col_type column = cellColumn(i);
3008 int len = clen[column];
3009 while (column < ncols() - 1 && isPartOfMultiColumn(row, ++column))
3010 len += clen[column] + 4;
3011 os << docstring(len, ch);
3012 if (bottomLine(i)) {
3026 void Tabular::plaintextPrintCell(odocstream & os,
3027 OutputParams const & runparams,
3028 idx_type cell, row_type row, col_type column,
3029 vector<unsigned int> const & clen,
3030 bool onlydata) const
3032 odocstringstream sstr;
3033 cellInset(cell)->plaintext(sstr, runparams);
3045 unsigned int len1 = sstr.str().length();
3046 unsigned int len2 = clen[column];
3047 while (column < ncols() - 1 && isPartOfMultiColumn(row, ++column))
3048 len2 += clen[column] + 4;
3051 switch (getAlignment(cell)) {
3053 case LYX_ALIGN_LEFT:
3056 case LYX_ALIGN_RIGHT:
3060 case LYX_ALIGN_CENTER:
3066 os << docstring(len1, ' ') << sstr.str()
3067 << docstring(len2, ' ');
3069 if (rightLine(cell))
3076 void Tabular::plaintext(odocstream & os,
3077 OutputParams const & runparams, int const depth,
3078 bool onlydata, char_type delim) const
3080 // first calculate the width of the single columns
3081 vector<unsigned int> clen(ncols());
3084 // first all non multicolumn cells!
3085 for (col_type c = 0; c < ncols(); ++c) {
3087 for (row_type r = 0; r < nrows(); ++r) {
3088 idx_type cell = cellIndex(r, c);
3089 if (isMultiColumn(cell))
3091 odocstringstream sstr;
3092 cellInset(cell)->plaintext(sstr, runparams);
3093 if (clen[c] < sstr.str().length())
3094 clen[c] = sstr.str().length();
3097 // then all multicolumn cells!
3098 for (col_type c = 0; c < ncols(); ++c) {
3099 for (row_type r = 0; r < nrows(); ++r) {
3100 idx_type cell = cellIndex(r, c);
3101 if (cell_info[r][c].multicolumn != CELL_BEGIN_OF_MULTICOLUMN)
3103 odocstringstream sstr;
3104 cellInset(cell)->plaintext(sstr, runparams);
3105 int len = int(sstr.str().length());
3106 idx_type const n = columnSpan(cell);
3107 for (col_type k = c; len > 0 && k < c + n - 1; ++k)
3109 if (len > int(clen[c + n - 1]))
3110 clen[c + n - 1] = len;
3115 for (row_type r = 0; r < nrows(); ++r) {
3116 if (!onlydata && plaintextTopHLine(os, r, clen))
3117 os << docstring(depth * 2, ' ');
3118 for (col_type c = 0; c < ncols(); ++c) {
3119 if (isPartOfMultiColumn(r, c))
3121 if (onlydata && c > 0)
3122 // we don't use operator<< for single UCS4 character.
3123 // see explanation in docstream.h
3125 plaintextPrintCell(os, runparams, cell, r, c, clen, onlydata);
3130 os << docstring(depth * 2, ' ');
3131 if (plaintextBottomHLine(os, r, clen))
3132 os << docstring(depth * 2, ' ');
3138 shared_ptr<InsetTableCell> Tabular::cellInset(idx_type cell) const
3140 return cell_info[cellRow(cell)][cellColumn(cell)].inset;
3144 shared_ptr<InsetTableCell> Tabular::cellInset(row_type row,
3145 col_type column) const
3147 return cell_info[row][column].inset;
3151 void Tabular::setCellInset(row_type row, col_type column,
3152 shared_ptr<InsetTableCell> ins) const
3154 CellData & cd = cell_info[row][column];
3159 void Tabular::validate(LaTeXFeatures & features) const
3161 features.require("NeedTabularnewline");
3163 features.require("booktabs");
3164 if (is_long_tabular)
3165 features.require("longtable");
3167 features.require("rotating");
3168 for (idx_type cell = 0; cell < numberofcells; ++cell) {
3169 if (isMultiRow(cell))
3170 features.require("multirow");
3171 if (getVAlignment(cell) != LYX_VALIGN_TOP
3172 || !getPWidth(cell).zero())
3173 features.require("array");
3174 cellInset(cell)->validate(features);
3179 Tabular::BoxType Tabular::useParbox(idx_type cell) const
3181 ParagraphList const & parlist = cellInset(cell)->paragraphs();
3182 ParagraphList::const_iterator cit = parlist.begin();
3183 ParagraphList::const_iterator end = parlist.end();
3185 for (; cit != end; ++cit)
3186 for (int i = 0; i < cit->size(); ++i)
3187 if (cit->isNewline(i))
3194 /////////////////////////////////////////////////////////////////////
3198 /////////////////////////////////////////////////////////////////////
3200 InsetTableCell::InsetTableCell(Buffer * buf)
3201 : InsetText(buf, InsetText::PlainLayout), isFixedWidth(false),
3202 contentAlign(LYX_ALIGN_CENTER)
3206 bool InsetTableCell::forcePlainLayout(idx_type) const
3208 return !isFixedWidth;
3212 bool InsetTableCell::allowParagraphCustomization(idx_type) const
3214 return isFixedWidth;
3218 bool InsetTableCell::getStatus(Cursor & cur, FuncRequest const & cmd,
3219 FuncStatus & status) const
3222 switch (cmd.action()) {
3224 enabled = !forcePlainLayout();
3226 case LFUN_LAYOUT_PARAGRAPH:
3227 enabled = allowParagraphCustomization();
3230 return InsetText::getStatus(cur, cmd, status);
3232 status.setEnabled(enabled);
3236 docstring InsetTableCell::asString(bool intoInsets)
3239 if (paragraphs().empty())
3241 ParagraphList::const_iterator it = paragraphs().begin();
3242 ParagraphList::const_iterator en = paragraphs().end();
3244 for (; it != en; ++it) {
3249 retval += it->asString(intoInsets ? AS_STR_INSETS : AS_STR_NONE);
3255 docstring InsetTableCell::xhtml(XHTMLStream & xs, OutputParams const & rp) const
3258 return InsetText::insetAsXHTML(xs, rp, InsetText::JustText);
3259 return InsetText::xhtml(xs, rp);
3264 /////////////////////////////////////////////////////////////////////
3268 /////////////////////////////////////////////////////////////////////
3270 InsetTabular::InsetTabular(Buffer * buf, row_type rows,
3272 : Inset(buf), tabular(buf, max(rows, row_type(1)), max(columns, col_type(1))), scx_(0),
3273 rowselect_(false), colselect_(false)
3278 InsetTabular::InsetTabular(InsetTabular const & tab)
3279 : Inset(tab), tabular(tab.tabular), scx_(0)
3284 InsetTabular::~InsetTabular()
3286 hideDialogs("tabular", this);
3290 void InsetTabular::setBuffer(Buffer & buf)
3292 tabular.setBuffer(buf);
3293 Inset::setBuffer(buf);
3297 bool InsetTabular::insetAllowed(InsetCode code) const
3302 case MATHMACRO_CODE:
3307 return tabular.is_long_tabular;
3315 void InsetTabular::write(ostream & os) const
3317 os << "Tabular" << endl;
3322 docstring InsetTabular::contextMenu(BufferView const &, int, int) const
3324 // FIXME: depending on the selection state, we could offer a different menu.
3325 return from_ascii("context-tabular");
3329 void InsetTabular::read(Lexer & lex)
3331 //bool const old_format = (lex.getString() == "\\LyXTable");
3339 string token = lex.getString();
3340 while (lex && token != "\\end_inset") {
3342 token = lex.getString();
3345 lex.printError("Missing \\end_inset at this point. ");
3349 int InsetTabular::rowFromY(Cursor & cur, int y) const
3351 // top y coordinate of tabular
3352 int h = yo(cur.bv()) - tabular.rowAscent(0);
3354 for (; r < tabular.nrows() && y > h; ++r)
3355 h += tabular.rowAscent(r) + tabular.rowDescent(r)
3356 + tabular.interRowSpace(r);
3362 int InsetTabular::columnFromX(Cursor & cur, int x) const
3364 // left x coordinate of tabular
3365 int w = xo(cur.bv()) + ADD_TO_TABULAR_WIDTH;
3367 for (; c < tabular.ncols() && x > w; ++c)
3368 w += tabular.cellWidth(c);
3373 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
3375 //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
3376 // mi.base.textwidth << "\n";
3379 LASSERT(false, /**/);
3382 for (row_type r = 0; r < tabular.nrows(); ++r) {
3385 for (col_type c = 0; c < tabular.ncols(); ++c) {
3386 if (tabular.isPartOfMultiColumn(r, c)
3387 || tabular.isPartOfMultiRow(r, c))
3388 // multicolumn or multirow cell, but not first one
3390 idx_type const cell = tabular.cellIndex(r, c);
3393 Length const p_width = tabular.getPWidth(cell);
3394 if (!p_width.zero())
3395 m.base.textwidth = p_width.inPixels(mi.base.textwidth);
3396 tabular.cellInset(cell)->metrics(m, dim);
3397 if (!p_width.zero())
3398 dim.wid = m.base.textwidth;
3399 tabular.cellInfo(cell).width = dim.wid + 2 * WIDTH_OF_LINE
3400 + tabular.interColumnSpace(cell);
3402 // FIXME(?): do we need a second metrics call?
3403 TextMetrics const & tm =
3404 mi.base.bv->textMetrics(tabular.cellInset(cell)->getText(0));
3406 // determine horiz offset because of decimal align (if necessary)
3407 int decimal_hoffset = 0;
3408 int decimal_width = 0;
3409 if (tabular.getAlignment(cell) == LYX_ALIGN_DECIMAL) {
3410 // make a copy which we will split in 2
3411 InsetTableCell head = InsetTableCell(*tabular.cellInset(cell).get());
3412 head.getText(0)->setMacrocontextPosition(
3413 tabular.cellInset(cell)->getText(0)->macrocontextPosition());
3414 head.setBuffer(tabular.buffer());
3415 // split in 2 and calculate width of each part
3416 bool hassep = false;
3417 InsetTableCell tail =
3418 splitCell(head, tabular.column_info[c].decimal_point, hassep);
3420 head.metrics(m, dim1);
3421 decimal_hoffset = dim1.width();
3423 tail.metrics(m, dim1);
3424 decimal_width = dim1.width();
3427 tabular.cell_info[r][c].decimal_hoffset = decimal_hoffset;
3428 tabular.cell_info[r][c].decimal_width = decimal_width;
3430 // with LYX_VALIGN_BOTTOM the descent is relative to the last par
3431 // = descent of text in last par + TEXT_TO_INSET_OFFSET:
3432 int const lastpardes = tm.last().second->descent()
3433 + TEXT_TO_INSET_OFFSET;
3435 switch (tabular.getVAlignment(cell)) {
3436 case Tabular::LYX_VALIGN_TOP:
3438 case Tabular::LYX_VALIGN_MIDDLE:
3439 offset = -(dim.des - lastpardes)/2;
3441 case Tabular::LYX_VALIGN_BOTTOM:
3442 offset = -(dim.des - lastpardes);
3445 tabular.cell_info[r][c].voffset = offset;
3446 maxasc = max(maxasc, dim.asc - offset);
3447 maxdes = max(maxdes, dim.des + offset);
3449 int const top_space = tabular.row_info[r].top_space_default ?
3450 default_line_space :
3451 tabular.row_info[r].top_space.inPixels(mi.base.textwidth);
3452 tabular.setRowAscent(r, maxasc + ADD_TO_HEIGHT + top_space);
3453 int const bottom_space = tabular.row_info[r].bottom_space_default ?
3454 default_line_space :
3455 tabular.row_info[r].bottom_space.inPixels(mi.base.textwidth);
3456 tabular.setRowDescent(r, maxdes + ADD_TO_HEIGHT + bottom_space);
3458 tabular.updateColumnWidths();
3459 dim.asc = tabular.rowAscent(0);
3460 dim.des = tabular.height() - dim.asc;
3461 dim.wid = tabular.width() + 2 * ADD_TO_TABULAR_WIDTH;
3465 bool InsetTabular::isCellSelected(Cursor & cur, row_type row, col_type col)
3468 if (&cur.inset() == this && cur.selection()) {
3469 if (cur.selIsMultiCell()) {
3472 getSelection(cur, rs, re, cs, ce);
3474 idx_type const cell = tabular.cellIndex(row, col);
3475 col_type const cspan = tabular.columnSpan(cell);
3476 row_type const rspan = tabular.rowSpan(cell);
3477 if (col + cspan - 1 >= cs && col <= ce
3478 && row + rspan - 1 >= rs && row <= re)
3481 if (col == tabular.cellColumn(cur.idx())
3482 && row == tabular.cellRow(cur.idx())) {
3483 CursorSlice const & beg = cur.selBegin();
3484 CursorSlice const & end = cur.selEnd();
3486 if ((end.lastpos() > 0 || end.lastpit() > 0)
3487 && end.pos() == end.lastpos() && beg.pos() == 0
3488 && end.pit() == end.lastpit() && beg.pit() == 0)
3496 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
3498 x += scx_ + ADD_TO_TABULAR_WIDTH;
3500 BufferView * bv = pi.base.bv;
3501 Cursor & cur = pi.base.bv->cursor();
3504 // FIXME: As the full background is painted in drawSelection(),
3505 // we have no choice but to do a full repaint for the Text cells.
3506 pi.full_repaint = true;
3508 bool const original_selection_state = pi.selected;
3511 first_visible_cell = Tabular::npos;
3512 for (row_type r = 0; r < tabular.nrows(); ++r) {
3514 for (col_type c = 0; c < tabular.ncols(); ++c) {
3515 if (tabular.isPartOfMultiColumn(r, c))
3518 idx = tabular.cellIndex(r, c);
3520 if (tabular.isPartOfMultiRow(r, c)) {
3521 nx += tabular.cellWidth(idx);
3525 if (first_visible_cell == Tabular::npos)
3526 first_visible_cell = idx;
3528 pi.selected |= isCellSelected(cur, r, c);
3529 int const cx = nx + tabular.textHOffset(idx);
3530 int const cy = y + tabular.textVOffset(idx);
3531 // Cache the Inset position.
3532 bv->coordCache().insets().add(cell(idx).get(), cx, cy);
3533 cell(idx)->draw(pi, cx, cy);
3534 drawCellLines(pi, nx, y, r, idx);
3535 nx += tabular.cellWidth(idx);
3536 pi.selected = original_selection_state;
3539 if (r + 1 < tabular.nrows())
3540 y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
3541 + tabular.interRowSpace(r + 1);
3546 void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
3548 Cursor & cur = pi.base.bv->cursor();
3551 x += scx_ + ADD_TO_TABULAR_WIDTH;
3553 // FIXME: it is wrong to completely paint the background
3554 // if we want to do single row painting.
3556 // Paint background of current tabular
3557 int const w = tabular.width();
3558 int const h = tabular.height();
3559 int yy = y - tabular.rowAscent(0);
3560 pi.pain.fillRectangle(x, yy, w, h, pi.backgroundColor(this));
3562 if (!cur.selection())
3564 if (&cur.inset() != this)
3569 bool const full_cell_selected = isCellSelected(cur,
3570 tabular.cellRow(cur.idx()), tabular.cellColumn(cur.idx()));
3572 if (cur.selIsMultiCell() || full_cell_selected) {
3573 for (row_type r = 0; r < tabular.nrows(); ++r) {
3575 for (col_type c = 0; c < tabular.ncols(); ++c) {
3576 if (tabular.isPartOfMultiColumn(r, c))
3579 idx_type const cell = tabular.cellIndex(r, c);
3581 if (tabular.isPartOfMultiRow(r, c)) {
3582 xx += tabular.cellWidth(cell);
3585 int const w = tabular.cellWidth(cell);
3586 int const h = tabular.cellHeight(cell);
3587 int const yy = y - tabular.rowAscent(r);
3588 if (isCellSelected(cur, r, c))
3589 pi.pain.fillRectangle(xx, yy, w, h, Color_selection);
3592 if (r + 1 < tabular.nrows())
3593 y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
3594 + tabular.interRowSpace(r + 1);
3598 x += cellXPos(cur.idx());
3599 x += tabular.textHOffset(cur.idx());
3600 cell(cur.idx())->drawSelection(pi, x, 0 /* ignored */);
3605 void InsetTabular::drawCellLines(PainterInfo & pi, int x, int y,
3606 row_type row, idx_type cell) const
3608 y -= tabular.rowAscent(row);
3609 int const w = tabular.cellWidth(cell);
3610 int const h = tabular.cellHeight(cell);
3611 Color const linecolor = pi.textColor(Color_tabularline);
3612 Color const gridcolor = pi.textColor(Color_tabularonoffline);
3615 bool drawline = tabular.topLine(cell)
3616 || (row > 0 && tabular.bottomLine(tabular.cellAbove(cell)));
3617 pi.pain.line(x, y, x + w, y,
3618 drawline ? linecolor : gridcolor,
3619 drawline ? Painter::line_solid : Painter::line_onoffdash);
3622 drawline = tabular.bottomLine(cell);
3623 pi.pain.line(x, y + h, x + w, y + h,
3624 drawline ? linecolor : gridcolor,
3625 drawline ? Painter::line_solid : Painter::line_onoffdash);
3628 col_type const col = tabular.cellColumn(cell);
3629 drawline = tabular.leftLine(cell)
3630 || (col > 0 && tabular.rightLine(tabular.cellIndex(row, col - 1)));
3631 pi.pain.line(x, y, x, y + h,
3632 drawline ? linecolor : gridcolor,
3633 drawline ? Painter::line_solid : Painter::line_onoffdash);
3636 x -= tabular.interColumnSpace(cell);
3637 drawline = tabular.rightLine(cell)
3638 || (col + 1 < tabular.ncols()
3639 && tabular.leftLine(tabular.cellIndex(row, col + 1)));
3640 pi.pain.line(x + w, y, x + w, y + h,
3641 drawline ? linecolor : gridcolor,
3642 drawline ? Painter::line_solid : Painter::line_onoffdash);
3646 void InsetTabular::edit(Cursor & cur, bool front, EntryDirection)
3648 //lyxerr << "InsetTabular::edit: " << this << endl;
3650 cur.setSelection(false);
3653 if (isRightToLeft(cur))
3654 cur.idx() = tabular.getLastCellInRow(0);
3660 if (isRightToLeft(cur))
3661 cur.idx() = tabular.getFirstCellInRow(tabular.nrows() - 1);
3663 cur.idx() = tabular.numberofcells - 1;
3665 cur.pos() = cur.lastpos(); // FIXME crude guess
3667 cur.setCurrentFont();
3668 // FIXME: this accesses the position cache before it is initialized
3670 //cur.bv().fitCursor();
3674 void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype)
3676 // In a longtable, tell captions what the current float is
3677 Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
3678 string const saveflt = cnts.current_float();
3679 if (tabular.is_long_tabular)
3680 cnts.current_float("table");
3682 ParIterator it2 = it;
3684 size_t const end = it2.nargs();
3685 for ( ; it2.idx() < end; it2.top().forwardIdx())
3686 buffer().updateBuffer(it2, utype);
3689 if (tabular.is_long_tabular)
3690 cnts.current_float(saveflt);
3694 void InsetTabular::addToToc(DocIterator const & cpit)
3696 DocIterator dit = cpit;
3698 size_t const end = dit.nargs();
3699 for ( ; dit.idx() < end; dit.top().forwardIdx())
3700 cell(dit.idx())->addToToc(dit);
3704 void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
3706 LYXERR(Debug::DEBUG, "# InsetTabular::doDispatch: cmd: " << cmd
3707 << "\n cur:" << cur);
3708 CursorSlice sl = cur.top();
3709 Cursor & bvcur = cur.bv().cursor();
3711 FuncCode const act = cmd.action();
3715 case LFUN_MOUSE_PRESS: {
3716 //lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
3718 if (cmd.x() < xo(cur.bv()) + ADD_TO_TABULAR_WIDTH
3719 || cmd.x() > xo(cur.bv()) + tabular.width()) {
3720 row_type r = rowFromY(cur, cmd.y());
3721 cur.idx() = tabular.getFirstCellInRow(r);
3724 cur.idx() = tabular.getLastCellInRow(r);
3725 cur.pos() = cur.lastpos();
3726 cur.setSelection(true);
3732 int const y0 = yo(cur.bv()) - tabular.rowAscent(0);
3733 if (cmd.y() < y0 + ADD_TO_TABULAR_WIDTH
3734 || cmd.y() > y0 + tabular.height()) {
3735 col_type c = columnFromX(cur, cmd.x());
3736 cur.idx() = tabular.cellIndex(0, c);
3739 cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c);
3740 cur.pos() = cur.lastpos();
3741 cur.setSelection(true);
3746 // do not reset cursor/selection if we have selected
3747 // some cells (bug 2715).
3748 if (cmd.button() == mouse_button::button3
3749 && &bvcur.selBegin().inset() == this
3750 && bvcur.selIsMultiCell())
3753 // Let InsetTableCell do it
3754 cell(cur.idx())->dispatch(cur, cmd);
3757 case LFUN_MOUSE_MOTION:
3758 //lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
3759 if (cmd.button() == mouse_button::button1) {
3760 // only accept motions to places not deeper nested than the real anchor
3761 if (!bvcur.realAnchor().hasPart(cur)) {
3765 // select (additional) row
3767 row_type r = rowFromY(cur, cmd.y());
3768 cur.idx() = tabular.getLastCellInRow(r);
3769 // we need to reset the cursor's pit and pos now, as the old ones
3770 // may no longer be valid.
3773 bvcur.setCursor(cur);
3774 bvcur.setSelection(true);
3777 // select (additional) column
3779 col_type c = columnFromX(cur, cmd.x());
3780 cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c);
3781 // we need to reset the cursor's pit and pos now, as the old ones
3782 // may no longer be valid.
3785 bvcur.setCursor(cur);
3786 bvcur.setSelection(true);
3789 // only update if selection changes
3790 if (bvcur.idx() == cur.idx() &&
3791 !(bvcur.realAnchor().idx() == cur.idx() && bvcur.pos() != cur.pos()))
3792 cur.noScreenUpdate();
3793 setCursorFromCoordinates(cur, cmd.x(), cmd.y());
3794 bvcur.setCursor(cur);
3795 bvcur.setSelection(true);
3796 // if this is a multicell selection, we just set the cursor to
3797 // the beginning of the cell's text.
3798 if (bvcur.selIsMultiCell()) {
3799 bvcur.pit() = bvcur.lastpit();
3800 bvcur.pos() = bvcur.lastpos();
3805 case LFUN_MOUSE_RELEASE:
3810 case LFUN_CELL_BACKWARD:
3812 cur.setSelection(false);
3815 case LFUN_CELL_FORWARD:
3817 cur.setSelection(false);
3820 case LFUN_CHAR_FORWARD_SELECT:
3821 case LFUN_CHAR_FORWARD:
3822 case LFUN_CHAR_BACKWARD_SELECT:
3823 case LFUN_CHAR_BACKWARD:
3824 case LFUN_CHAR_RIGHT_SELECT:
3825 case LFUN_CHAR_RIGHT:
3826 case LFUN_CHAR_LEFT_SELECT:
3827 case LFUN_CHAR_LEFT:
3828 case LFUN_WORD_FORWARD:
3829 case LFUN_WORD_FORWARD_SELECT:
3830 case LFUN_WORD_BACKWARD:
3831 case LFUN_WORD_BACKWARD_SELECT:
3832 case LFUN_WORD_RIGHT:
3833 case LFUN_WORD_RIGHT_SELECT:
3834 case LFUN_WORD_LEFT:
3835 case LFUN_WORD_LEFT_SELECT: {
3836 // determine whether we move to next or previous cell, where to enter
3837 // the new cell from, and which command to "finish" (i.e., exit the
3840 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE;
3841 FuncCode finish_lfun;
3843 if (act == LFUN_CHAR_FORWARD
3844 || act == LFUN_CHAR_FORWARD_SELECT
3845 || act == LFUN_WORD_FORWARD
3846 || act == LFUN_WORD_FORWARD_SELECT) {
3848 finish_lfun = LFUN_FINISHED_FORWARD;
3850 else if (act == LFUN_CHAR_BACKWARD
3851 || act == LFUN_CHAR_BACKWARD_SELECT
3852 || act == LFUN_WORD_BACKWARD
3853 || act == LFUN_WORD_BACKWARD_SELECT) {
3855 finish_lfun = LFUN_FINISHED_BACKWARD;
3857 // LEFT or RIGHT commands --- the interpretation will depend on the
3858 // table's direction.
3860 bool const right = act == LFUN_CHAR_RIGHT
3861 || act == LFUN_CHAR_RIGHT_SELECT
3862 || act == LFUN_WORD_RIGHT
3863 || act == LFUN_WORD_RIGHT_SELECT;
3864 next_cell = isRightToLeft(cur) != right;
3866 if (lyxrc.visual_cursor)
3867 entry_from = right ? ENTRY_DIRECTION_LEFT:ENTRY_DIRECTION_RIGHT;
3869 finish_lfun = right ? LFUN_FINISHED_RIGHT : LFUN_FINISHED_LEFT;
3872 bool const select = act == LFUN_CHAR_FORWARD_SELECT
3873 || act == LFUN_CHAR_BACKWARD_SELECT
3874 || act == LFUN_CHAR_RIGHT_SELECT
3875 || act == LFUN_CHAR_LEFT_SELECT
3876 || act == LFUN_WORD_FORWARD_SELECT
3877 || act == LFUN_WORD_RIGHT_SELECT
3878 || act == LFUN_WORD_BACKWARD_SELECT
3879 || act == LFUN_WORD_LEFT_SELECT;
3881 // If we have a multicell selection or we're
3882 // not doing some LFUN_*_SELECT thing anyway...
3883 if (!cur.selIsMultiCell() || !select) {
3884 col_type const c = tabular.cellColumn(cur.idx());
3885 row_type const r = tabular.cellRow(cur.idx());
3886 // Are we trying to select the whole cell and is the whole cell
3887 // not yet selected?
3888 bool const select_whole = select && !isCellSelected(cur, r, c) &&
3889 ((next_cell && cur.pit() == cur.lastpit()
3890 && cur.pos() == cur.lastpos())
3891 || (!next_cell && cur.pit() == 0 && cur.pos() == 0));
3893 bool const empty_cell = cur.lastpos() == 0 && cur.lastpit() == 0;
3895 // ...try to dispatch to the cell's inset.
3896 cell(cur.idx())->dispatch(cur, cmd);
3898 // When we already have a selection we want to select the whole cell
3899 // before going to the next cell.
3900 if (select_whole && !empty_cell){
3901 getText(cur.idx())->selectAll(cur);
3906 // FIXME: When we support the selection of an empty cell, remove
3907 // the !empty_cell from this condition. For now we jump to the next
3908 // cell if the current cell is empty.
3909 if (cur.result().dispatched() && !empty_cell)
3913 // move to next/prev cell, as appropriate
3914 // note that we will always do this if we're selecting and we have
3915 // a multicell selection
3916 LYXERR(Debug::RTL, "entering " << (next_cell ? "next" : "previous")
3917 << " cell from: " << int(entry_from));
3919 moveNextCell(cur, entry_from);
3921 movePrevCell(cur, entry_from);
3922 // if we're exiting the table, call the appropriate FINISHED lfun
3923 if (sl == cur.top())
3924 cmd = FuncRequest(finish_lfun);
3931 case LFUN_DOWN_SELECT:
3933 if (!(cur.selection() && cur.selIsMultiCell()))
3934 cell(cur.idx())->dispatch(cur, cmd);
3936 cur.dispatched(); // override the cell's decision
3937 if (sl == cur.top()) {
3938 // if our Text didn't do anything to the cursor
3939 // then we try to put the cursor into the cell below
3940 // setting also the right targetX.
3941 cur.selHandle(act == LFUN_DOWN_SELECT);
3942 if (tabular.cellRow(cur.idx()) != tabular.nrows() - 1) {
3943 cur.idx() = tabular.cellBelow(cur.idx());
3945 TextMetrics const & tm =
3946 cur.bv().textMetrics(cell(cur.idx())->getText(0));
3947 cur.pos() = tm.x2pos(cur.pit(), 0, cur.targetX());
3948 cur.setCurrentFont();
3951 if (sl == cur.top()) {
3952 // we trick it to go to forward after leaving the
3954 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
3957 if (cur.selIsMultiCell()) {
3958 cur.pit() = cur.lastpit();
3959 cur.pos() = cur.lastpos();
3960 cur.setCurrentFont();
3965 case LFUN_UP_SELECT:
3967 if (!(cur.selection() && cur.selIsMultiCell()))
3968 cell(cur.idx())->dispatch(cur, cmd);
3969 cur.dispatched(); // override the cell's decision
3970 if (sl == cur.top()) {
3971 // if our Text didn't do anything to the cursor
3972 // then we try to put the cursor into the cell above
3973 // setting also the right targetX.
3974 cur.selHandle(act == LFUN_UP_SELECT);
3975 if (tabular.cellRow(cur.idx()) != 0) {
3976 cur.idx() = tabular.cellAbove(cur.idx());
3977 cur.pit() = cur.lastpit();
3978 Text const * text = cell(cur.idx())->getText(0);
3979 TextMetrics const & tm = cur.bv().textMetrics(text);
3980 ParagraphMetrics const & pm =
3981 tm.parMetrics(cur.lastpit());
3982 cur.pos() = tm.x2pos(cur.pit(), pm.rows().size()-1, cur.targetX());
3983 cur.setCurrentFont();
3986 if (sl == cur.top()) {
3987 cmd = FuncRequest(LFUN_UP);
3990 if (cur.selIsMultiCell()) {
3992 cur.pos() = cur.lastpos();
3993 cur.setCurrentFont();
3998 // case LFUN_SCREEN_DOWN: {
3999 // //if (hasSelection())
4000 // // cur.selection() = false;
4001 // col_type const col = tabular.cellColumn(cur.idx());
4002 // int const t = cur.bv().top_y() + cur.bv().height();
4003 // if (t < yo() + tabular.getHeightOfTabular()) {
4004 // cur.bv().scrollDocView(t, true);
4005 // cur.idx() = tabular.cellBelow(first_visible_cell) + col;
4007 // cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + col;
4014 // case LFUN_SCREEN_UP: {
4015 // //if (hasSelection())
4016 // // cur.selection() = false;
4017 // col_type const col = tabular.cellColumn(cur.idx());
4018 // int const t = cur.bv().top_y() + cur.bv().height();
4020 // cur.bv().scrollDocView(t, true);
4024 // cur.idx() = tabular.cellBelow(first_visible_cell) + col;
4028 // cur.par() = cur.lastpar();
4029 // cur.pos() = cur.lastpos();
4033 case LFUN_LAYOUT_TABULAR:
4034 cur.bv().showDialog("tabular");
4037 case LFUN_INSET_MODIFY:
4038 if (!tabularFeatures(cur, to_utf8(cmd.argument())))
4042 // insert file functions
4043 case LFUN_FILE_INSERT_PLAINTEXT_PARA:
4044 case LFUN_FILE_INSERT_PLAINTEXT:
4046 if (FileName::isAbsolute(to_utf8(cmd.argument()))) {
4047 docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
4048 FileName(to_utf8(cmd.argument())));
4051 cur.recordUndoInset(INSERT_UNDO);
4052 if (insertPlaintextString(cur.bv(), tmpstr, false)) {
4053 // content has been replaced,
4054 // so cursor might be invalid
4055 cur.pos() = cur.lastpos();
4056 cur.pit() = cur.lastpit();
4057 bvcur.setCursor(cur);
4064 if (cur.selIsMultiCell()) {
4065 if (copySelection(cur)) {
4066 cur.recordUndoInset(DELETE_UNDO);
4070 cell(cur.idx())->dispatch(cur, cmd);
4073 case LFUN_SELF_INSERT:
4074 if (cur.selIsMultiCell()) {
4075 cur.recordUndoInset(DELETE_UNDO);
4078 cell(cur.idx())->dispatch(cur, cmd);
4081 case LFUN_CHAR_DELETE_BACKWARD:
4082 case LFUN_CHAR_DELETE_FORWARD:
4083 if (cur.selIsMultiCell()) {
4084 cur.recordUndoInset(DELETE_UNDO);
4087 cell(cur.idx())->dispatch(cur, cmd);
4091 if (!cur.selection())
4093 if (cur.selIsMultiCell()) {
4097 cell(cur.idx())->dispatch(cur, cmd);
4100 case LFUN_CLIPBOARD_PASTE:
4101 case LFUN_PRIMARY_SELECTION_PASTE: {
4102 docstring const clip = (act == LFUN_CLIPBOARD_PASTE) ?
4103 theClipboard().getAsText() :
4104 theSelection().get();
4107 // pass to InsertPlaintextString, but
4108 // only if we have multi-cell content
4109 if (clip.find_first_of(from_ascii("\t\n")) != docstring::npos) {
4110 cur.recordUndoInset(INSERT_UNDO);
4111 if (insertPlaintextString(cur.bv(), clip, false)) {
4112 // content has been replaced,
4113 // so cursor might be invalid
4114 cur.pos() = cur.lastpos();
4115 cur.pit() = cur.lastpit();
4116 bvcur.setCursor(cur);
4120 // Let the cell handle normal text
4121 cell(cur.idx())->dispatch(cur, cmd);
4126 if (!tabularStackDirty()) {
4127 if (!cur.selIsMultiCell())
4128 cell(cur.idx())->dispatch(cur, cmd);
4131 if (theClipboard().isInternal() ||
4132 (!theClipboard().hasInternal() && theClipboard().hasLyXContents())) {
4133 cur.recordUndoInset(INSERT_UNDO);
4134 pasteClipboard(cur);
4138 case LFUN_FONT_EMPH:
4139 case LFUN_FONT_BOLD:
4140 case LFUN_FONT_BOLDSYMBOL:
4141 case LFUN_FONT_ROMAN:
4142 case LFUN_FONT_NOUN:
4143 case LFUN_FONT_ITAL:
4144 case LFUN_FONT_FRAK:
4145 case LFUN_FONT_TYPEWRITER:
4146 case LFUN_FONT_SANS:
4147 case LFUN_TEXTSTYLE_APPLY:
4148 case LFUN_TEXTSTYLE_UPDATE:
4149 case LFUN_FONT_SIZE:
4150 case LFUN_FONT_UNDERLINE:
4151 case LFUN_FONT_STRIKEOUT:
4152 case LFUN_FONT_UULINE:
4153 case LFUN_FONT_UWAVE:
4155 case LFUN_WORD_CAPITALIZE:
4156 case LFUN_WORD_UPCASE:
4157 case LFUN_WORD_LOWCASE:
4158 case LFUN_CHARS_TRANSPOSE:
4159 if (cur.selIsMultiCell()) {
4162 getSelection(cur, rs, re, cs, ce);
4163 Cursor tmpcur = cur;
4164 for (row_type r = rs; r <= re; ++r) {
4165 for (col_type c = cs; c <= ce; ++c) {
4166 // cursor follows cell:
4167 tmpcur.idx() = tabular.cellIndex(r, c);
4168 // select this cell only:
4171 tmpcur.resetAnchor();
4172 tmpcur.pit() = tmpcur.lastpit();
4173 tmpcur.pos() = tmpcur.top().lastpos();
4174 tmpcur.setCursor(tmpcur);
4175 tmpcur.setSelection();
4176 cell(tmpcur.idx())->dispatch(tmpcur, cmd);
4181 cell(cur.idx())->dispatch(cur, cmd);
4185 case LFUN_INSET_SETTINGS:
4186 // relay this lfun to Inset, not to the cell.
4187 Inset::doDispatch(cur, cmd);
4191 // we try to handle this event in the insets dispatch function.
4192 cell(cur.idx())->dispatch(cur, cmd);
4198 // function sets an object as defined in func_status.h:
4199 // states OK, Unknown, Disabled, On, Off.
4200 bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
4201 FuncStatus & status) const
4203 switch (cmd.action()) {
4204 case LFUN_INSET_MODIFY: {
4205 if (&cur.inset() != this || cmd.getArg(0) != "tabular")
4208 string const s = cmd.getArg(1);
4209 // FIXME: We only check for the very first argument...
4210 int action = Tabular::LAST_ACTION;
4212 for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
4213 if (tabularFeature[i].feature == s) {
4214 action = tabularFeature[i].action;
4218 if (action == Tabular::LAST_ACTION) {
4220 status.setUnknown(true);
4224 string const argument = cmd.getLongArg(2);
4226 row_type sel_row_start = 0;
4227 row_type sel_row_end = 0;
4228 col_type sel_col_start = 0;
4229 col_type sel_col_end = 0;
4230 Tabular::ltType dummyltt;
4233 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
4236 case Tabular::SET_PWIDTH:
4237 case Tabular::SET_MPWIDTH:
4238 case Tabular::SET_SPECIAL_COLUMN:
4239 case Tabular::SET_SPECIAL_MULTICOLUMN:
4240 case Tabular::APPEND_ROW:
4241 case Tabular::APPEND_COLUMN:
4242 case Tabular::DELETE_ROW:
4243 case Tabular::DELETE_COLUMN:
4244 case Tabular::COPY_ROW:
4245 case Tabular::COPY_COLUMN:
4246 case Tabular::SET_TOP_SPACE:
4247 case Tabular::SET_BOTTOM_SPACE:
4248 case Tabular::SET_INTERLINE_SPACE:
4252 case Tabular::SET_DECIMAL_POINT:
4254 tabular.getAlignment(cur.idx()) == LYX_ALIGN_DECIMAL);
4257 case Tabular::SET_MULTICOLUMN:
4258 case Tabular::UNSET_MULTICOLUMN:
4259 case Tabular::MULTICOLUMN:
4260 // If a row is set as longtable caption, it must not be allowed
4261 // to unset that this row is a multicolumn.
4262 status.setEnabled(sel_row_start == sel_row_end
4263 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
4264 status.setOnOff(tabular.isMultiColumn(cur.idx()));
4267 case Tabular::SET_MULTIROW:
4268 case Tabular::UNSET_MULTIROW:
4269 case Tabular::MULTIROW:
4270 // If a row is set as longtable caption, it must not be allowed
4271 // to unset that this row is a multirow.
4272 status.setEnabled(sel_col_start == sel_col_end
4273 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
4274 status.setOnOff(tabular.isMultiRow(cur.idx()));
4277 case Tabular::SET_ALL_LINES:
4278 case Tabular::UNSET_ALL_LINES:
4279 case Tabular::SET_BORDER_LINES:
4280 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4283 case Tabular::SET_LINE_TOP:
4284 case Tabular::SET_LINE_BOTTOM:
4285 case Tabular::SET_LINE_LEFT:
4286 case Tabular::SET_LINE_RIGHT:
4287 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4290 case Tabular::TOGGLE_LINE_TOP:
4291 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4292 status.setOnOff(tabular.topLine(cur.idx()));
4295 case Tabular::TOGGLE_LINE_BOTTOM:
4296 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4297 status.setOnOff(tabular.bottomLine(cur.idx()));
4300 case Tabular::TOGGLE_LINE_LEFT:
4301 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4302 status.setOnOff(tabular.leftLine(cur.idx()));
4305 case Tabular::TOGGLE_LINE_RIGHT:
4306 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4307 status.setOnOff(tabular.rightLine(cur.idx()));
4310 // multirow cells are alwas left aligned
4311 case Tabular::M_ALIGN_LEFT:
4313 case Tabular::ALIGN_LEFT:
4314 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_LEFT);
4317 case Tabular::M_ALIGN_RIGHT:
4319 case Tabular::ALIGN_RIGHT:
4320 status.setEnabled(!tabular.isMultiRow(cur.idx()));
4321 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_RIGHT);
4324 case Tabular::M_ALIGN_CENTER:
4326 case Tabular::ALIGN_CENTER:
4327 status.setEnabled(!tabular.isMultiRow(cur.idx()));
4328 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_CENTER);
4331 case Tabular::ALIGN_BLOCK:
4332 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4333 && !tabular.isMultiRow(cur.idx()));
4334 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_BLOCK);
4337 case Tabular::ALIGN_DECIMAL:
4338 status.setEnabled(!tabular.isMultiRow(cur.idx())
4339 && !tabular.isMultiColumn(cur.idx()));
4340 status.setOnOff(tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_DECIMAL);
4343 case Tabular::M_VALIGN_TOP:
4345 case Tabular::VALIGN_TOP:
4346 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4347 && !tabular.isMultiRow(cur.idx()));
4349 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_TOP);
4352 case Tabular::M_VALIGN_BOTTOM:
4354 case Tabular::VALIGN_BOTTOM:
4355 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4356 && !tabular.isMultiRow(cur.idx()));
4358 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_BOTTOM);
4361 case Tabular::M_VALIGN_MIDDLE:
4363 case Tabular::VALIGN_MIDDLE:
4364 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4365 && !tabular.isMultiRow(cur.idx()));
4367 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_MIDDLE);
4370 case Tabular::SET_LONGTABULAR:
4371 // setting as longtable is not allowed when table is inside a float
4372 if (cur.innerInsetOfType(FLOAT_CODE) != 0
4373 || cur.innerInsetOfType(WRAP_CODE) != 0)
4374 status.setEnabled(false);
4376 status.setEnabled(true);
4377 status.setOnOff(tabular.is_long_tabular);
4380 case Tabular::UNSET_LONGTABULAR:
4381 status.setOnOff(!tabular.is_long_tabular);
4384 case Tabular::TOGGLE_ROTATE_TABULAR:
4385 case Tabular::SET_ROTATE_TABULAR:
4386 status.setOnOff(tabular.rotate);
4389 case Tabular::TABULAR_VALIGN_TOP:
4390 status.setOnOff(tabular.tabular_valignment
4391 == Tabular::LYX_VALIGN_TOP);
4393 case Tabular::TABULAR_VALIGN_MIDDLE:
4394 status.setOnOff(tabular.tabular_valignment
4395 == Tabular::LYX_VALIGN_MIDDLE);
4397 case Tabular::TABULAR_VALIGN_BOTTOM:
4398 status.setOnOff(tabular.tabular_valignment
4399 == Tabular::LYX_VALIGN_BOTTOM);
4402 case Tabular::LONGTABULAR_ALIGN_LEFT:
4403 status.setOnOff(tabular.longtabular_alignment
4404 == Tabular::LYX_LONGTABULAR_ALIGN_LEFT);
4406 case Tabular::LONGTABULAR_ALIGN_CENTER:
4407 status.setOnOff(tabular.longtabular_alignment
4408 == Tabular::LYX_LONGTABULAR_ALIGN_CENTER);
4410 case Tabular::LONGTABULAR_ALIGN_RIGHT:
4411 status.setOnOff(tabular.longtabular_alignment
4412 == Tabular::LYX_LONGTABULAR_ALIGN_RIGHT);
4415 case Tabular::UNSET_ROTATE_TABULAR:
4416 status.setOnOff(!tabular.rotate);
4419 case Tabular::TOGGLE_ROTATE_CELL:
4420 case Tabular::SET_ROTATE_CELL:
4421 status.setOnOff(!oneCellHasRotationState(false,
4422 sel_row_start, sel_row_end, sel_col_start, sel_col_end));
4425 case Tabular::UNSET_ROTATE_CELL:
4426 status.setOnOff(!oneCellHasRotationState(true,
4427 sel_row_start, sel_row_end, sel_col_start, sel_col_end));
4430 case Tabular::SET_USEBOX:
4431 status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
4434 // every row can only be one thing:
4435 // either a footer or header or caption
4436 case Tabular::SET_LTFIRSTHEAD:
4437 status.setEnabled(sel_row_start == sel_row_end
4438 && !tabular.ltCaption(sel_row_start));
4439 status.setOnOff(tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
4442 case Tabular::UNSET_LTFIRSTHEAD:
4443 status.setOnOff(!tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
4446 case Tabular::SET_LTHEAD:
4447 status.setEnabled(sel_row_start == sel_row_end
4448 && !tabular.ltCaption(sel_row_start));
4449 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
4452 case Tabular::UNSET_LTHEAD:
4453 status.setOnOff(!tabular.getRowOfLTHead(sel_row_start, dummyltt));
4456 case Tabular::SET_LTFOOT:
4457 status.setEnabled(sel_row_start == sel_row_end
4458 && !tabular.ltCaption(sel_row_start));
4459 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
4462 case Tabular::UNSET_LTFOOT:
4463 status.setOnOff(!tabular.getRowOfLTFoot(sel_row_start, dummyltt));
4466 case Tabular::SET_LTLASTFOOT:
4467 status.setEnabled(sel_row_start == sel_row_end
4468 && !tabular.ltCaption(sel_row_start));
4469 status.setOnOff(tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
4472 case Tabular::UNSET_LTLASTFOOT:
4473 status.setOnOff(!tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
4476 case Tabular::SET_LTNEWPAGE:
4477 status.setOnOff(tabular.getLTNewPage(sel_row_start));
4480 // only one row can be the caption
4481 // and a multirow cannot be set as caption
4482 case Tabular::SET_LTCAPTION:
4483 case Tabular::UNSET_LTCAPTION:
4484 case Tabular::TOGGLE_LTCAPTION:
4485 status.setEnabled(sel_row_start == sel_row_end
4486 && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
4487 && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
4488 && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
4489 && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
4490 && (!tabular.haveLTCaption()
4491 || tabular.ltCaption(sel_row_start))
4492 && !tabular.isMultiRow(sel_row_start));
4493 status.setOnOff(tabular.ltCaption(sel_row_start));
4496 case Tabular::SET_BOOKTABS:
4497 status.setOnOff(tabular.use_booktabs);
4500 case Tabular::UNSET_BOOKTABS:
4501 status.setOnOff(!tabular.use_booktabs);
4506 status.setEnabled(false);
4512 // These are only enabled inside tabular
4513 case LFUN_CELL_BACKWARD:
4514 case LFUN_CELL_FORWARD:
4515 status.setEnabled(true);
4518 // disable these with multiple cells selected
4519 case LFUN_INSET_INSERT:
4520 case LFUN_TABULAR_INSERT:
4521 case LFUN_FLEX_INSERT:
4522 case LFUN_FLOAT_INSERT:
4523 case LFUN_FLOAT_WIDE_INSERT:
4524 case LFUN_FOOTNOTE_INSERT:
4525 case LFUN_MARGINALNOTE_INSERT:
4526 case LFUN_MATH_INSERT:
4527 case LFUN_MATH_MODE:
4528 case LFUN_MATH_MUTATE:
4529 case LFUN_MATH_DISPLAY:
4530 case LFUN_NOTE_INSERT:
4531 case LFUN_ARGUMENT_INSERT:
4532 case LFUN_BOX_INSERT:
4533 case LFUN_BRANCH_INSERT:
4534 case LFUN_PHANTOM_INSERT:
4535 case LFUN_WRAP_INSERT:
4536 case LFUN_PREVIEW_INSERT:
4537 case LFUN_ERT_INSERT: {
4538 if (cur.selIsMultiCell()) {
4539 status.setEnabled(false);
4542 return cell(cur.idx())->getStatus(cur, cmd, status);
4545 // disable in non-fixed-width cells
4546 case LFUN_NEWLINE_INSERT:
4547 case LFUN_BREAK_PARAGRAPH: {
4548 if (tabular.getPWidth(cur.idx()).zero()) {
4549 status.setEnabled(false);
4552 return cell(cur.idx())->getStatus(cur, cmd, status);
4555 case LFUN_NEWPAGE_INSERT:
4556 status.setEnabled(false);
4560 if (tabularStackDirty() && theClipboard().isInternal()) {
4561 if (cur.selIsMultiCell()) {
4564 getSelection(cur, rs, re, cs, ce);
4565 if (paste_tabular && paste_tabular->ncols() == ce - cs + 1
4566 && paste_tabular->nrows() == re - rs + 1)
4567 status.setEnabled(true);
4569 status.setEnabled(false);
4570 status.message(_("Selection size should match clipboard content."));
4573 status.setEnabled(true);
4576 return cell(cur.idx())->getStatus(cur, cmd, status);
4578 case LFUN_INSET_SETTINGS:
4579 // relay this lfun to Inset, not to the cell.
4580 return Inset::getStatus(cur, cmd, status);
4583 // we try to handle this event in the insets dispatch function.
4584 return cell(cur.idx())->getStatus(cur, cmd, status);
4590 Inset::DisplayType InsetTabular::display() const
4592 if (tabular.is_long_tabular) {
4593 switch (tabular.longtabular_alignment) {
4594 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
4596 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
4598 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
4608 int InsetTabular::latex(odocstream & os, OutputParams const & runparams) const
4610 return tabular.latex(os, runparams);
4614 int InsetTabular::plaintext(odocstream & os, OutputParams const & runparams) const
4616 os << '\n'; // output table on a new line
4617 int const dp = runparams.linelen > 0 ? runparams.depth : 0;
4618 tabular.plaintext(os, runparams, dp, false, 0);
4619 return PLAINTEXT_NEWLINE;
4623 int InsetTabular::docbook(odocstream & os, OutputParams const & runparams) const
4628 // FIXME: Why not pass a proper DocIterator here?
4630 // if the table is inside a float it doesn't need the informaltable
4631 // wrapper. Search for it.
4632 for (master = owner(); master; master = master->owner())
4633 if (master->lyxCode() == FLOAT_CODE)
4638 os << "<informaltable>";
4641 ret += tabular.docbook(os, runparams);
4643 os << "</informaltable>";
4650 docstring InsetTabular::xhtml(XHTMLStream & xs, OutputParams const & rp) const
4653 // It'd be better to be able to get this from an InsetLayout, but at present
4654 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
4655 xs << html::StartTag("table");
4656 docstring ret = tabular.xhtml(xs, rp);
4657 xs << html::EndTag("table");
4662 void InsetTabular::validate(LaTeXFeatures & features) const
4664 tabular.validate(features);
4666 // It'd be better to be able to get this from an InsetLayout, but at present
4667 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
4668 if (features.runparams().flavor == OutputParams::HTML)
4669 features.addPreambleSnippet("<style type=\"text/css\">\n"
4670 "table { border: 1px solid black; display: inline-block; }\n"
4671 "td { border: 1px solid black; padding: 0.5ex; }\n"
4676 shared_ptr<InsetTableCell const> InsetTabular::cell(idx_type idx) const
4678 return tabular.cellInset(idx);
4682 shared_ptr<InsetTableCell> InsetTabular::cell(idx_type idx)
4684 return tabular.cellInset(idx);
4688 void InsetTabular::cursorPos(BufferView const & bv,
4689 CursorSlice const & sl, bool boundary, int & x, int & y) const
4691 cell(sl.idx())->cursorPos(bv, sl, boundary, x, y);
4693 int const row = tabular.cellRow(sl.idx());
4694 int const col = tabular.cellColumn(sl.idx());
4696 // y offset correction
4697 for (int r = 0; r < row; ++r)
4698 y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
4699 + tabular.interRowSpace(r + 1);
4701 y += tabular.textVOffset(sl.idx());
4703 // x offset correction
4704 for (int c = 0; c < col; ++c)
4705 x += tabular.column_info[c].width;
4707 x += tabular.textHOffset(sl.idx());
4708 x += ADD_TO_TABULAR_WIDTH;
4713 int InsetTabular::dist(BufferView & bv, idx_type const cell, int x, int y) const
4717 Inset const & inset = *tabular.cellInset(cell);
4718 Point o = bv.coordCache().getInsets().xy(&inset);
4719 int const xbeg = o.x_ - tabular.textHOffset(cell);
4720 int const xend = xbeg + tabular.cellWidth(cell);
4721 row_type const row = tabular.cellRow(cell);
4722 int const ybeg = o.y_ - tabular.rowAscent(row)
4723 - tabular.interRowSpace(row);
4724 int const yend = ybeg + tabular.cellHeight(cell);
4736 //lyxerr << " xbeg=" << xbeg << " xend=" << xend
4737 // << " ybeg=" << ybeg << " yend=" << yend
4738 // << " xx=" << xx << " yy=" << yy
4739 // << " dist=" << xx + yy << endl;
4744 Inset * InsetTabular::editXY(Cursor & cur, int x, int y)
4746 //lyxerr << "InsetTabular::editXY: " << this << endl;
4747 cur.setSelection(false);
4749 cur.idx() = getNearestCell(cur.bv(), x, y);
4751 return cur.bv().textMetrics(&cell(cur.idx())->text()).editXY(cur, x, y);
4755 void InsetTabular::setCursorFromCoordinates(Cursor & cur, int x, int y) const
4757 cur.idx() = getNearestCell(cur.bv(), x, y);
4758 cur.bv().textMetrics(&cell(cur.idx())->text()).setCursorFromCoordinates(cur, x, y);
4762 InsetTabular::idx_type InsetTabular::getNearestCell(BufferView & bv, int x, int y) const
4764 idx_type idx_min = 0;
4765 int dist_min = numeric_limits<int>::max();
4766 for (idx_type i = 0, n = nargs(); i != n; ++i) {
4767 if (bv.coordCache().getInsets().has(tabular.cellInset(i).get())) {
4768 int const d = dist(bv, i, x, y);
4779 int InsetTabular::cellXPos(idx_type const cell) const
4781 col_type col = tabular.cellColumn(cell);
4783 for (col_type c = 0; c < col; ++c)
4784 lx += tabular.column_info[c].width;
4790 void InsetTabular::resetPos(Cursor & cur) const
4792 BufferView & bv = cur.bv();
4793 int const maxwidth = bv.workWidth();
4795 int const scx_old = scx_;
4796 int const i = cur.find(this);
4801 int const X2 = maxwidth;
4802 int const offset = ADD_TO_TABULAR_WIDTH + 2;
4803 int const x1 = xo(cur.bv()) + cellXPos(cur[i].idx()) + offset;
4804 int const x2 = x1 + tabular.cellWidth(cur[i].idx());
4807 scx_ = X1 + 20 - x1;
4809 scx_ = X2 - 20 - x2;
4814 // only update if offset changed
4815 if (scx_ != scx_old)
4816 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
4820 void InsetTabular::moveNextCell(Cursor & cur, EntryDirection entry_from)
4822 row_type const row = tabular.cellRow(cur.idx());
4823 col_type const col = tabular.cellColumn(cur.idx());
4825 if (isRightToLeft(cur)) {
4826 if (tabular.cellColumn(cur.idx()) == 0) {
4827 if (row == tabular.nrows() - 1)
4829 cur.idx() = tabular.cellBelow(tabular.getLastCellInRow(row));
4834 cur.idx() = tabular.getLastCellInRow(row - 1);
4836 cur.idx() = tabular.cellIndex(row, col - 1);
4839 if (tabular.isLastCell(cur.idx()))
4841 if (cur.idx() == tabular.getLastCellInRow(row))
4842 cur.idx() = tabular.cellIndex(row + 1, 0);
4844 col_type const colnextcell = col + tabular.columnSpan(cur.idx());
4845 cur.idx() = tabular.cellIndex(row, colnextcell);
4849 cur.boundary(false);
4851 if (cur.selIsMultiCell()) {
4852 cur.pit() = cur.lastpit();
4853 cur.pos() = cur.lastpos();
4861 // in visual mode, place cursor at extreme left or right
4863 switch(entry_from) {
4865 case ENTRY_DIRECTION_RIGHT:
4866 cur.posVisToRowExtremity(false /* !left */);
4868 case ENTRY_DIRECTION_LEFT:
4869 cur.posVisToRowExtremity(true /* left */);
4871 case ENTRY_DIRECTION_IGNORE:
4872 // nothing to do in this case
4876 cur.setCurrentFont();
4881 void InsetTabular::movePrevCell(Cursor & cur, EntryDirection entry_from)
4883 row_type const row = tabular.cellRow(cur.idx());
4884 col_type const col = tabular.cellColumn(cur.idx());
4886 if (isRightToLeft(cur)) {
4887 if (cur.idx() == tabular.getLastCellInRow(row)) {
4890 cur.idx() = tabular.getFirstCellInRow(row);
4891 cur.idx() = tabular.cellAbove(cur.idx());
4893 if (tabular.isLastCell(cur.idx()))
4895 if (cur.idx() == tabular.getLastCellInRow(row))
4896 cur.idx() = tabular.cellIndex(row + 1, 0);
4898 cur.idx() = tabular.cellIndex(row, col + 1);
4901 if (cur.idx() == 0) // first cell
4904 cur.idx() = tabular.getLastCellInRow(row - 1);
4906 cur.idx() = tabular.cellIndex(row, col - 1);
4909 if (cur.selIsMultiCell()) {
4910 cur.pit() = cur.lastpit();
4911 cur.pos() = cur.lastpos();
4916 cur.pit() = cur.lastpit();
4917 cur.pos() = cur.lastpos();
4919 // in visual mode, place cursor at extreme left or right
4921 switch(entry_from) {
4923 case ENTRY_DIRECTION_RIGHT:
4924 cur.posVisToRowExtremity(false /* !left */);
4926 case ENTRY_DIRECTION_LEFT:
4927 cur.posVisToRowExtremity(true /* left */);
4929 case ENTRY_DIRECTION_IGNORE:
4930 // nothing to do in this case
4934 cur.setCurrentFont();
4939 bool InsetTabular::tabularFeatures(Cursor & cur, string const & argument)
4941 istringstream is(argument);
4944 if (insetCode(s) != TABULAR_CODE)
4948 size_t safe_guard = 0;
4953 if (safe_guard > 1000) {
4954 LYXERR0("parameter max count reached!");
4958 Tabular::Feature action = Tabular::LAST_ACTION;
4961 for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
4962 if (s != tabularFeature[i].feature)
4965 action = tabularFeature[i].action;
4968 if (action == Tabular::LAST_ACTION) {
4969 LYXERR0("Feature not found " << s);
4973 if (tabularFeature[i].need_value)
4975 LYXERR(Debug::DEBUG, "Feature: " << s << "\t\tvalue: " << val);
4976 tabularFeatures(cur, action, val);
4982 static void checkLongtableSpecial(Tabular::ltType & ltt,
4983 string const & special, bool & flag)
4985 if (special == "dl_above") {
4988 } else if (special == "dl_below") {
4989 ltt.bottomDL = flag;
4991 } else if (special == "empty") {
5001 bool InsetTabular::oneCellHasRotationState(bool rotated,
5002 row_type row_start, row_type row_end,
5003 col_type col_start, col_type col_end) const
5005 for (row_type r = row_start; r <= row_end; ++r)
5006 for (col_type c = col_start; c <= col_end; ++c)
5007 if (tabular.getRotateCell(tabular.cellIndex(r, c)) == rotated)
5013 void InsetTabular::tabularFeatures(Cursor & cur,
5014 Tabular::Feature feature, string const & value)
5016 col_type sel_col_start;
5017 col_type sel_col_end;
5018 row_type sel_row_start;
5019 row_type sel_row_end;
5020 bool setLines = false;
5021 LyXAlignment setAlign = LYX_ALIGN_LEFT;
5022 Tabular::VAlignment setVAlign = Tabular::LYX_VALIGN_TOP;
5026 case Tabular::M_ALIGN_LEFT:
5027 case Tabular::ALIGN_LEFT:
5028 setAlign = LYX_ALIGN_LEFT;
5031 case Tabular::M_ALIGN_RIGHT:
5032 case Tabular::ALIGN_RIGHT:
5033 setAlign = LYX_ALIGN_RIGHT;
5036 case Tabular::M_ALIGN_CENTER:
5037 case Tabular::ALIGN_CENTER:
5038 setAlign = LYX_ALIGN_CENTER;
5041 case Tabular::ALIGN_BLOCK:
5042 setAlign = LYX_ALIGN_BLOCK;
5045 case Tabular::ALIGN_DECIMAL:
5046 setAlign = LYX_ALIGN_DECIMAL;
5049 case Tabular::M_VALIGN_TOP:
5050 case Tabular::VALIGN_TOP:
5051 setVAlign = Tabular::LYX_VALIGN_TOP;
5054 case Tabular::M_VALIGN_BOTTOM:
5055 case Tabular::VALIGN_BOTTOM:
5056 setVAlign = Tabular::LYX_VALIGN_BOTTOM;
5059 case Tabular::M_VALIGN_MIDDLE:
5060 case Tabular::VALIGN_MIDDLE:
5061 setVAlign = Tabular::LYX_VALIGN_MIDDLE;
5068 cur.recordUndoInset(ATOMIC_UNDO);
5070 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
5071 row_type const row = tabular.cellRow(cur.idx());
5072 col_type const column = tabular.cellColumn(cur.idx());
5074 Tabular::ltType ltt;
5078 case Tabular::SET_PWIDTH: {
5079 Length const len(value);
5080 tabular.setColumnPWidth(cur, cur.idx(), len);
5082 && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
5083 tabularFeatures(cur, Tabular::ALIGN_CENTER, string());
5087 case Tabular::SET_MPWIDTH:
5088 tabular.setMColumnPWidth(cur, cur.idx(), Length(value));
5091 case Tabular::SET_MROFFSET:
5092 tabular.setMROffset(cur, cur.idx(), Length(value));
5095 case Tabular::SET_SPECIAL_COLUMN:
5096 case Tabular::SET_SPECIAL_MULTICOLUMN:
5097 if (value == "none")
5098 tabular.setAlignSpecial(cur.idx(), docstring(), feature);
5100 tabular.setAlignSpecial(cur.idx(), from_utf8(value), feature);
5103 case Tabular::APPEND_ROW:
5104 // append the row into the tabular
5105 tabular.appendRow(cur.idx());
5108 case Tabular::APPEND_COLUMN:
5109 // append the column into the tabular
5110 tabular.appendColumn(cur.idx());
5111 cur.idx() = tabular.cellIndex(row, column);
5114 case Tabular::DELETE_ROW:
5115 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5116 tabular.deleteRow(sel_row_start);
5117 if (sel_row_start >= tabular.nrows())
5119 cur.idx() = tabular.cellIndex(sel_row_start, column);
5122 cur.setSelection(false);
5125 case Tabular::DELETE_COLUMN:
5126 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5127 tabular.deleteColumn(sel_col_start);
5128 if (sel_col_start >= tabular.ncols())
5130 cur.idx() = tabular.cellIndex(row, sel_col_start);
5133 cur.setSelection(false);
5136 case Tabular::COPY_ROW:
5137 tabular.copyRow(row);
5140 case Tabular::COPY_COLUMN:
5141 tabular.copyColumn(column);
5142 cur.idx() = tabular.cellIndex(row, column);
5145 case Tabular::SET_LINE_TOP:
5146 case Tabular::TOGGLE_LINE_TOP: {
5147 bool lineSet = (feature == Tabular::SET_LINE_TOP)
5148 ? (value == "true") : !tabular.topLine(cur.idx());
5149 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5150 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5151 tabular.setTopLine(tabular.cellIndex(r, c), lineSet);
5155 case Tabular::SET_LINE_BOTTOM:
5156 case Tabular::TOGGLE_LINE_BOTTOM: {
5157 bool lineSet = (feature == Tabular::SET_LINE_BOTTOM)
5158 ? (value == "true") : !tabular.bottomLine(cur.idx());
5159 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5160 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5161 tabular.setBottomLine(tabular.cellIndex(r, c), lineSet);
5165 case Tabular::SET_LINE_LEFT:
5166 case Tabular::TOGGLE_LINE_LEFT: {
5167 bool lineSet = (feature == Tabular::SET_LINE_LEFT)
5168 ? (value == "true") : !tabular.leftLine(cur.idx());
5169 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5170 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5171 tabular.setLeftLine(tabular.cellIndex(r, c), lineSet);
5175 case Tabular::SET_LINE_RIGHT:
5176 case Tabular::TOGGLE_LINE_RIGHT: {
5177 bool lineSet = (feature == Tabular::SET_LINE_RIGHT)
5178 ? (value == "true") : !tabular.rightLine(cur.idx());
5179 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5180 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5181 tabular.setRightLine(tabular.cellIndex(r, c), lineSet);
5185 case Tabular::M_ALIGN_LEFT:
5186 case Tabular::M_ALIGN_RIGHT:
5187 case Tabular::M_ALIGN_CENTER:
5189 case Tabular::ALIGN_LEFT:
5190 case Tabular::ALIGN_RIGHT:
5191 case Tabular::ALIGN_CENTER:
5192 case Tabular::ALIGN_BLOCK:
5193 case Tabular::ALIGN_DECIMAL:
5194 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5195 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5196 tabular.setAlignment(tabular.cellIndex(r, c), setAlign, flag);
5199 case Tabular::M_VALIGN_TOP:
5200 case Tabular::M_VALIGN_BOTTOM:
5201 case Tabular::M_VALIGN_MIDDLE:
5203 case Tabular::VALIGN_TOP:
5204 case Tabular::VALIGN_BOTTOM:
5205 case Tabular::VALIGN_MIDDLE:
5206 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5207 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5208 tabular.setVAlignment(tabular.cellIndex(r, c), setVAlign, flag);
5211 case Tabular::SET_MULTICOLUMN: {
5212 if (!cur.selection()) {
5213 // just multicol for one single cell
5214 // check whether we are completely in a multicol
5215 if (!tabular.isMultiColumn(cur.idx()))
5216 tabular.setMultiColumn(cur.idx(), 1);
5219 // we have a selection so this means we just add all this
5220 // cells to form a multicolumn cell
5221 idx_type const s_start = cur.selBegin().idx();
5222 row_type const col_start = tabular.cellColumn(s_start);
5223 row_type const col_end = tabular.cellColumn(cur.selEnd().idx());
5224 cur.idx() = tabular.setMultiColumn(s_start, col_end - col_start + 1);
5227 cur.setSelection(false);
5231 case Tabular::UNSET_MULTICOLUMN: {
5232 if (!cur.selection()) {
5233 if (tabular.isMultiColumn(cur.idx()))
5234 tabular.unsetMultiColumn(cur.idx());
5239 case Tabular::MULTICOLUMN: {
5240 if (tabular.isMultiColumn(cur.idx()))
5241 tabularFeatures(cur, Tabular::UNSET_MULTICOLUMN);
5243 tabularFeatures(cur, Tabular::SET_MULTICOLUMN);
5247 case Tabular::SET_MULTIROW: {
5248 if (!cur.selection()) {
5249 // just multirow for one single cell
5250 // check whether we are completely in a multirow
5251 if (!tabular.isMultiRow(cur.idx()))
5252 tabular.setMultiRow(cur.idx(), 1);
5255 // we have a selection so this means we just add all this
5256 // cells to form a multirow cell
5257 idx_type const s_start = cur.selBegin().idx();
5258 row_type const row_start = tabular.cellRow(s_start);
5259 row_type const row_end = tabular.cellRow(cur.selEnd().idx());
5260 cur.idx() = tabular.setMultiRow(s_start, row_end - row_start + 1);
5263 cur.setSelection(false);
5267 case Tabular::UNSET_MULTIROW: {
5268 if (!cur.selection()) {
5269 if (tabular.isMultiRow(cur.idx()))
5270 tabular.unsetMultiRow(cur.idx());
5275 case Tabular::MULTIROW: {
5276 if (tabular.isMultiRow(cur.idx()))
5277 tabularFeatures(cur, Tabular::UNSET_MULTIROW);
5279 tabularFeatures(cur, Tabular::SET_MULTIROW);
5283 case Tabular::SET_ALL_LINES:
5285 case Tabular::UNSET_ALL_LINES:
5286 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5287 for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
5288 idx_type const cell = tabular.cellIndex(r, c);
5289 tabular.setTopLine(cell, setLines);
5290 tabular.setBottomLine(cell, setLines);
5291 tabular.setRightLine(cell, setLines);
5292 tabular.setLeftLine(cell, setLines);
5296 case Tabular::SET_BORDER_LINES:
5297 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
5298 tabular.setLeftLine(tabular.cellIndex(r, sel_col_start), true);
5299 tabular.setRightLine(tabular.cellIndex(r, sel_col_end), true);
5301 for (col_type c = sel_col_start; c <= sel_col_end; ++c) {
5302 tabular.setTopLine(tabular.cellIndex(sel_row_start, c), true);
5303 tabular.setBottomLine(tabular.cellIndex(sel_row_end, c), true);
5307 case Tabular::SET_LONGTABULAR:
5308 tabular.is_long_tabular = true;
5311 case Tabular::UNSET_LONGTABULAR:
5312 for (row_type r = 0; r < tabular.nrows(); ++r) {
5313 if (tabular.ltCaption(r)) {
5314 cur.idx() = tabular.cellIndex(r, 0);
5317 tabularFeatures(cur, Tabular::TOGGLE_LTCAPTION);
5320 tabular.is_long_tabular = false;
5323 case Tabular::SET_ROTATE_TABULAR:
5324 tabular.rotate = true;
5327 case Tabular::UNSET_ROTATE_TABULAR:
5328 tabular.rotate = false;
5331 case Tabular::TOGGLE_ROTATE_TABULAR:
5332 tabular.rotate = !tabular.rotate;
5335 case Tabular::TABULAR_VALIGN_TOP:
5336 tabular.tabular_valignment = Tabular::LYX_VALIGN_TOP;
5339 case Tabular::TABULAR_VALIGN_MIDDLE:
5340 tabular.tabular_valignment = Tabular::LYX_VALIGN_MIDDLE;
5343 case Tabular::TABULAR_VALIGN_BOTTOM:
5344 tabular.tabular_valignment = Tabular::LYX_VALIGN_BOTTOM;
5347 case Tabular::LONGTABULAR_ALIGN_LEFT:
5348 tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_LEFT;
5351 case Tabular::LONGTABULAR_ALIGN_CENTER:
5352 tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_CENTER;
5355 case Tabular::LONGTABULAR_ALIGN_RIGHT:
5356 tabular.longtabular_alignment = Tabular::LYX_LONGTABULAR_ALIGN_RIGHT;
5361 case Tabular::SET_ROTATE_CELL:
5362 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5363 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5364 tabular.setRotateCell(tabular.cellIndex(r, c), true);
5367 case Tabular::UNSET_ROTATE_CELL:
5368 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5369 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5370 tabular.setRotateCell(tabular.cellIndex(r, c), false);
5373 case Tabular::TOGGLE_ROTATE_CELL:
5375 bool oneNotRotated = oneCellHasRotationState(false,
5376 sel_row_start, sel_row_end, sel_col_start, sel_col_end);
5378 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5379 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5380 tabular.setRotateCell(tabular.cellIndex(r, c),
5385 case Tabular::SET_USEBOX: {
5386 Tabular::BoxType val = Tabular::BoxType(convert<int>(value));
5387 if (val == tabular.getUsebox(cur.idx()))
5388 val = Tabular::BOX_NONE;
5389 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5390 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5391 tabular.setUsebox(tabular.cellIndex(r, c), val);
5395 case Tabular::UNSET_LTFIRSTHEAD:
5397 case Tabular::SET_LTFIRSTHEAD:
5398 tabular.getRowOfLTFirstHead(row, ltt);
5399 checkLongtableSpecial(ltt, value, flag);
5400 tabular.setLTHead(row, flag, ltt, true);
5403 case Tabular::UNSET_LTHEAD:
5405 case Tabular::SET_LTHEAD:
5406 tabular.getRowOfLTHead(row, ltt);
5407 checkLongtableSpecial(ltt, value, flag);
5408 tabular.setLTHead(row, flag, ltt, false);
5411 case Tabular::UNSET_LTFOOT:
5413 case Tabular::SET_LTFOOT:
5414 tabular.getRowOfLTFoot(row, ltt);
5415 checkLongtableSpecial(ltt, value, flag);
5416 tabular.setLTFoot(row, flag, ltt, false);
5419 case Tabular::UNSET_LTLASTFOOT:
5421 case Tabular::SET_LTLASTFOOT:
5422 tabular.getRowOfLTLastFoot(row, ltt);
5423 checkLongtableSpecial(ltt, value, flag);
5424 tabular.setLTFoot(row, flag, ltt, true);
5427 case Tabular::SET_LTNEWPAGE:
5428 tabular.setLTNewPage(row, !tabular.getLTNewPage(row));
5431 case Tabular::SET_LTCAPTION: {
5432 if (tabular.ltCaption(row))
5434 cur.idx() = tabular.setLTCaption(row, true);
5437 cur.setSelection(false);
5438 // If a row is set as caption, then also insert
5439 // a caption. Otherwise the LaTeX output is broken.
5440 lyx::dispatch(FuncRequest(LFUN_INSET_SELECT_ALL));
5441 lyx::dispatch(FuncRequest(LFUN_CAPTION_INSERT));
5445 case Tabular::UNSET_LTCAPTION: {
5446 if (!tabular.ltCaption(row))
5448 cur.idx() = tabular.setLTCaption(row, false);
5451 cur.setSelection(false);
5452 FuncRequest fr(LFUN_INSET_DISSOLVE, "caption");
5453 if (lyx::getStatus(fr).enabled())
5458 case Tabular::TOGGLE_LTCAPTION: {
5459 if (tabular.ltCaption(row))
5460 tabularFeatures(cur, Tabular::UNSET_LTCAPTION);
5462 tabularFeatures(cur, Tabular::SET_LTCAPTION);
5466 case Tabular::SET_BOOKTABS:
5467 tabular.use_booktabs = true;
5470 case Tabular::UNSET_BOOKTABS:
5471 tabular.use_booktabs = false;
5474 case Tabular::SET_TOP_SPACE: {
5476 if (value == "default")
5477 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5478 tabular.row_info[r].top_space_default = true;
5479 else if (value == "none")
5480 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
5481 tabular.row_info[r].top_space_default = false;
5482 tabular.row_info[r].top_space = len;
5484 else if (isValidLength(value, &len))
5485 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
5486 tabular.row_info[r].top_space_default = false;
5487 tabular.row_info[r].top_space = len;
5492 case Tabular::SET_BOTTOM_SPACE: {
5494 if (value == "default")
5495 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5496 tabular.row_info[r].bottom_space_default = true;
5497 else if (value == "none")
5498 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
5499 tabular.row_info[r].bottom_space_default = false;
5500 tabular.row_info[r].bottom_space = len;
5502 else if (isValidLength(value, &len))
5503 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
5504 tabular.row_info[r].bottom_space_default = false;
5505 tabular.row_info[r].bottom_space = len;
5510 case Tabular::SET_INTERLINE_SPACE: {
5512 if (value == "default")
5513 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5514 tabular.row_info[r].interline_space_default = true;
5515 else if (value == "none")
5516 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
5517 tabular.row_info[r].interline_space_default = false;
5518 tabular.row_info[r].interline_space = len;
5520 else if (isValidLength(value, &len))
5521 for (row_type r = sel_row_start; r <= sel_row_end; ++r) {
5522 tabular.row_info[r].interline_space_default = false;
5523 tabular.row_info[r].interline_space = len;
5528 case Tabular::SET_DECIMAL_POINT:
5529 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5530 tabular.column_info[c].decimal_point = from_utf8(value);
5533 // dummy stuff just to avoid warnings
5534 case Tabular::LAST_ACTION:
5540 bool InsetTabular::copySelection(Cursor & cur)
5542 if (!cur.selection())
5547 getSelection(cur, rs, re, cs, ce);
5549 paste_tabular.reset(new Tabular(tabular));
5551 for (row_type r = 0; r < rs; ++r)
5552 paste_tabular->deleteRow(0);
5554 row_type const rows = re - rs + 1;
5555 while (paste_tabular->nrows() > rows)
5556 paste_tabular->deleteRow(rows);
5558 for (col_type c = 0; c < cs; ++c)
5559 paste_tabular->deleteColumn(0);
5561 col_type const columns = ce - cs + 1;
5562 while (paste_tabular->ncols() > columns)
5563 paste_tabular->deleteColumn(columns);
5565 paste_tabular->setBuffer(tabular.buffer());
5567 odocstringstream os;
5568 OutputParams const runparams(0);
5569 paste_tabular->plaintext(os, runparams, 0, true, '\t');
5570 // Needed for the "Edit->Paste recent" menu and the system clipboard.
5571 cap::copySelection(cur, os.str());
5573 // mark tabular stack dirty
5574 // FIXME: this is a workaround for bug 1919. Should be removed for 1.5,
5575 // when we (hopefully) have a one-for-all paste mechanism.
5576 // This must be called after cap::copySelection.
5577 dirtyTabularStack(true);
5583 bool InsetTabular::pasteClipboard(Cursor & cur)
5587 col_type actcol = tabular.cellColumn(cur.idx());
5588 row_type actrow = tabular.cellRow(cur.idx());
5590 if (cur.selIsMultiCell()) {
5593 getSelection(cur, actrow, re, actcol, ce);
5596 for (row_type r1 = 0, r2 = actrow;
5597 r1 < paste_tabular->nrows() && r2 < tabular.nrows();
5599 for (col_type c1 = 0, c2 = actcol;
5600 c1 < paste_tabular->ncols() && c2 < tabular.ncols();
5602 if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
5603 tabular.isPartOfMultiColumn(r2, c2))
5605 if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
5609 if (tabular.isPartOfMultiColumn(r2, c2)) {
5613 shared_ptr<InsetTableCell> inset(
5614 new InsetTableCell(*paste_tabular->cellInset(r1, c1)));
5615 tabular.setCellInset(r2, c2, inset);
5616 // FIXME?: why do we need to do this explicitly? (EL)
5617 tabular.cellInset(r2, c2)->setBuffer(tabular.buffer());
5619 // FIXME: change tracking (MG)
5620 inset->setChange(Change(buffer().params().trackChanges ?
5621 Change::INSERTED : Change::UNCHANGED));
5629 void InsetTabular::cutSelection(Cursor & cur)
5631 if (!cur.selection())
5636 getSelection(cur, rs, re, cs, ce);
5637 for (row_type r = rs; r <= re; ++r) {
5638 for (col_type c = cs; c <= ce; ++c) {
5639 shared_ptr<InsetTableCell> t
5640 = cell(tabular.cellIndex(r, c));
5641 if (buffer().params().trackChanges)
5642 // FIXME: Change tracking (MG)
5643 t->setChange(Change(Change::DELETED));
5649 // cursor position might be invalid now
5650 if (cur.pit() > cur.lastpit())
5651 cur.pit() = cur.lastpit();
5652 if (cur.pos() > cur.lastpos())
5653 cur.pos() = cur.lastpos();
5654 cur.clearSelection();
5658 bool InsetTabular::isRightToLeft(Cursor & cur) const
5660 LASSERT(cur.depth() > 1, /**/);
5661 Paragraph const & parentpar = cur[cur.depth() - 2].paragraph();
5662 pos_type const parentpos = cur[cur.depth() - 2].pos();
5663 return parentpar.getFontSettings(buffer().params(),
5664 parentpos).language()->rightToLeft();
5668 docstring InsetTabular::asString(idx_type stidx, idx_type enidx,
5671 LASSERT(stidx <= enidx, return docstring());
5673 col_type const col1 = tabular.cellColumn(stidx);
5674 col_type const col2 = tabular.cellColumn(enidx);
5675 row_type const row1 = tabular.cellRow(stidx);
5676 row_type const row2 = tabular.cellRow(enidx);
5678 for (col_type col = col1; col <= col2; col++)
5679 for (row_type row = row1; row <= row2; row++) {
5684 retval += tabular.cellInset(row, col)->asString(intoInsets);
5690 void InsetTabular::getSelection(Cursor & cur,
5691 row_type & rs, row_type & re, col_type & cs, col_type & ce) const
5693 CursorSlice const & beg = cur.selBegin();
5694 CursorSlice const & end = cur.selEnd();
5695 cs = tabular.cellColumn(beg.idx());
5696 ce = tabular.cellColumn(end.idx());
5700 rs = tabular.cellRow(beg.idx());
5701 re = tabular.cellRow(end.idx());
5707 Text * InsetTabular::getText(int idx) const
5709 return size_t(idx) < nargs() ? cell(idx)->getText(0) : 0;
5713 void InsetTabular::setChange(Change const & change)
5715 for (idx_type idx = 0; idx < nargs(); ++idx)
5716 cell(idx)->setChange(change);
5720 void InsetTabular::acceptChanges()
5722 for (idx_type idx = 0; idx < nargs(); ++idx)
5723 cell(idx)->acceptChanges();
5727 void InsetTabular::rejectChanges()
5729 for (idx_type idx = 0; idx < nargs(); ++idx)
5730 cell(idx)->rejectChanges();
5734 bool InsetTabular::allowParagraphCustomization(idx_type cell) const
5736 return tabular.getPWidth(cell).zero();
5740 bool InsetTabular::forcePlainLayout(idx_type cell) const
5742 return !tabular.getPWidth(cell).zero();
5746 bool InsetTabular::insertPlaintextString(BufferView & bv, docstring const & buf,
5749 if (buf.length() <= 0)
5754 col_type maxCols = 1;
5755 size_t const len = buf.length();
5759 (p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos) {
5767 maxCols = max(cols, maxCols);
5773 maxCols = max(cols, maxCols);
5779 paste_tabular.reset(new Tabular(buffer_, rows, maxCols));
5780 loctab = paste_tabular.get();
5782 dirtyTabularStack(true);
5785 cell = bv.cursor().idx();
5786 ocol = tabular.cellColumn(cell);
5787 row = tabular.cellRow(cell);
5791 idx_type const cells = loctab->numberofcells;
5794 rows = loctab->nrows();
5795 col_type const columns = loctab->ncols();
5797 while (cell < cells && p < len && row < rows &&
5798 (p = buf.find_first_of(from_ascii("\t\n"), p)) != docstring::npos)
5804 // we can only set this if we are not too far right
5805 if (cols < columns) {
5806 shared_ptr<InsetTableCell> inset = loctab->cellInset(cell);
5807 Font const font = bv.textMetrics(&inset->text()).
5809 inset->setText(buf.substr(op, p - op), font,
5810 buffer().params().trackChanges);
5816 // we can only set this if we are not too far right
5817 if (cols < columns) {
5818 shared_ptr<InsetTableCell> inset = tabular.cellInset(cell);
5819 Font const font = bv.textMetrics(&inset->text()).
5821 inset->setText(buf.substr(op, p - op), font,
5822 buffer().params().trackChanges);
5827 cell = loctab->cellIndex(row, cols);
5833 // check for the last cell if there is no trailing '\n'
5834 if (cell < cells && op < len) {
5835 shared_ptr<InsetTableCell> inset = loctab->cellInset(cell);
5836 Font const font = bv.textMetrics(&inset->text()).displayFont(0, 0);
5837 inset->setText(buf.substr(op, len - op), font,
5838 buffer().params().trackChanges);
5844 void InsetTabular::addPreview(DocIterator const & inset_pos,
5845 PreviewLoader & loader) const
5847 DocIterator cell_pos = inset_pos;
5849 cell_pos.push_back(CursorSlice(*const_cast<InsetTabular *>(this)));
5850 for (row_type r = 0; r < tabular.nrows(); ++r) {
5851 for (col_type c = 0; c < tabular.ncols(); ++c) {
5852 cell_pos.top().idx() = tabular.cellIndex(r, c);
5853 tabular.cellInset(r, c)->addPreview(cell_pos, loader);
5859 bool InsetTabular::completionSupported(Cursor const & cur) const
5861 Cursor const & bvCur = cur.bv().cursor();
5862 if (&bvCur.inset() != this)
5864 return cur.text()->completionSupported(cur);
5868 bool InsetTabular::inlineCompletionSupported(Cursor const & cur) const
5870 return completionSupported(cur);
5874 bool InsetTabular::automaticInlineCompletion() const
5876 return lyxrc.completion_inline_text;
5880 bool InsetTabular::automaticPopupCompletion() const
5882 return lyxrc.completion_popup_text;
5886 bool InsetTabular::showCompletionCursor() const
5888 return lyxrc.completion_cursor_text;
5892 CompletionList const * InsetTabular::createCompletionList(Cursor const & cur) const
5894 return completionSupported(cur) ? cur.text()->createCompletionList(cur) : 0;
5898 docstring InsetTabular::completionPrefix(Cursor const & cur) const
5900 if (!completionSupported(cur))
5902 return cur.text()->completionPrefix(cur);
5906 bool InsetTabular::insertCompletion(Cursor & cur, docstring const & s, bool finished)
5908 if (!completionSupported(cur))
5911 return cur.text()->insertCompletion(cur, s, finished);
5915 void InsetTabular::completionPosAndDim(Cursor const & cur, int & x, int & y,
5916 Dimension & dim) const
5918 TextMetrics const & tm = cur.bv().textMetrics(cur.text());
5919 tm.completionPosAndDim(cur, x, y, dim);
5923 void InsetTabular::string2params(string const & in, InsetTabular & inset)
5925 istringstream data(in);
5927 lex.setStream(data);
5934 if (!lex || token != "tabular") {
5935 LYXERR0("Expected arg 1 to be \"tabular\" in " << in);
5939 // This is part of the inset proper that is usually swallowed
5940 // by Buffer::readInset
5942 if (!lex || token != "Tabular") {
5943 LYXERR0("Expected arg 2 to be \"Tabular\" in " << in);
5951 string InsetTabular::params2string(InsetTabular const & inset)
5954 data << "tabular" << ' ';
5956 data << "\\end_inset\n";