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 if we are not in a multicolumn cell
1031 // exclude possible multicolumn cells in the row
1032 if (!isMultiColumn(cell)) {
1033 for (row_type r = 0; r < nrows(); ++r) {
1034 if (!isMultiRow(cellIndex(r, col))
1035 && !isMultiColumn(cellIndex(r, col))) {
1036 cell_info[r][col].alignment = align;
1037 cell_info[r][col].inset->setContentAlignment(align);
1040 column_info[col].alignment = align;
1041 docstring & dpoint = column_info[col].decimal_point;
1042 if (align == LYX_ALIGN_DECIMAL && dpoint.empty())
1043 dpoint = from_utf8(lyxrc.default_decimal_point);
1045 cellInfo(cell).alignment = align;
1046 cellInset(cell).get()->setContentAlignment(align);
1051 void Tabular::setVAlignment(idx_type cell, VAlignment align,
1054 if (!isMultiColumn(cell) || onlycolumn)
1055 column_info[cellColumn(cell)].valignment = align;
1057 cellInfo(cell).valignment = align;
1064 * Allow line and paragraph breaks for fixed width cells or disallow them,
1065 * merge cell paragraphs and reset layout to standard for variable width
1068 void toggleFixedWidth(Cursor & cur, InsetTableCell * inset, bool fixedWidth)
1070 inset->setAutoBreakRows(fixedWidth);
1071 inset->toggleFixedWidth(fixedWidth);
1075 // merge all paragraphs to one
1076 BufferParams const & bp = cur.bv().buffer().params();
1077 while (inset->paragraphs().size() > 1)
1078 mergeParagraph(bp, inset->paragraphs(), 0);
1082 // undo information has already been recorded
1083 inset->getText(0)->setLayout(0, cur.lastpit() + 1,
1084 bp.documentClass().plainLayoutName());
1091 void Tabular::setColumnPWidth(Cursor & cur, idx_type cell,
1092 Length const & width)
1094 col_type const c = cellColumn(cell);
1096 column_info[c].p_width = width;
1097 // reset the vertical alignment to top if the fixed with
1098 // is removed or zero because only fixed width columns can
1099 // have a vertical alignment
1100 if (column_info[c].p_width.zero())
1101 column_info[c].valignment = LYX_VALIGN_TOP;
1102 for (row_type r = 0; r < nrows(); ++r) {
1103 idx_type const cell = cellIndex(r, c);
1104 // because of multicolumns
1105 toggleFixedWidth(cur, cellInset(cell).get(),
1106 !getPWidth(cell).zero());
1108 // cur paragraph can become invalid after paragraphs were merged
1109 if (cur.pit() > cur.lastpit())
1110 cur.pit() = cur.lastpit();
1111 // cur position can become invalid after newlines were removed
1112 if (cur.pos() > cur.lastpos())
1113 cur.pos() = cur.lastpos();
1117 bool Tabular::setFixedWidth(row_type r, col_type c)
1119 bool const multicol = cell_info[r][c].multicolumn != CELL_NORMAL;
1120 bool const fixed_width = (!column_info[c].p_width.zero() && !multicol)
1121 || (multicol && !cell_info[r][c].p_width.zero());
1122 cell_info[r][c].inset->toggleFixedWidth(fixed_width);
1127 bool Tabular::setMColumnPWidth(Cursor & cur, idx_type cell,
1128 Length const & width)
1130 if (!isMultiColumn(cell))
1133 cellInfo(cell).p_width = width;
1134 toggleFixedWidth(cur, cellInset(cell).get(), !width.zero());
1135 // cur paragraph can become invalid after paragraphs were merged
1136 if (cur.pit() > cur.lastpit())
1137 cur.pit() = cur.lastpit();
1138 // cur position can become invalid after newlines were removed
1139 if (cur.pos() > cur.lastpos())
1140 cur.pos() = cur.lastpos();
1145 bool Tabular::setMROffset(Cursor &, idx_type cell, Length const & mroffset)
1147 cellInfo(cell).mroffset = mroffset;
1152 void Tabular::setAlignSpecial(idx_type cell, docstring const & special,
1153 Tabular::Feature what)
1155 if (what == SET_SPECIAL_MULTICOLUMN)
1156 cellInfo(cell).align_special = special;
1158 column_info[cellColumn(cell)].align_special = special;
1162 void Tabular::setTopLine(idx_type i, bool line)
1164 cellInfo(i).top_line = line;
1168 void Tabular::setBottomLine(idx_type i, bool line)
1170 cellInfo(i).bottom_line = line;
1174 void Tabular::setLeftLine(idx_type cell, bool line)
1176 cellInfo(cell).left_line = line;
1180 void Tabular::setRightLine(idx_type cell, bool line)
1182 cellInfo(cell).right_line = line;
1185 bool Tabular::rowTopLine(row_type r) const
1187 bool all_rows_set = true;
1188 for (col_type c = 0; all_rows_set && c < ncols(); ++c)
1189 all_rows_set = cellInfo(cellIndex(r, c)).top_line;
1190 return all_rows_set;
1194 bool Tabular::rowBottomLine(row_type r) const
1196 bool all_rows_set = true;
1197 for (col_type c = 0; all_rows_set && c < ncols(); ++c)
1198 all_rows_set = cellInfo(cellIndex(r, c)).bottom_line;
1199 return all_rows_set;
1203 bool Tabular::columnLeftLine(col_type c) const
1210 for (row_type r = 0; r < nrows(); ++r) {
1211 idx_type const i = cellIndex(r, c);
1212 if (c == cellColumn(i)) {
1214 bool right = c > 0 && cellInfo(cellIndex(r, c - 1)).right_line;
1215 if (cellInfo(i).left_line || right)
1219 return 2 * nrows_left >= total;
1223 bool Tabular::columnRightLine(col_type c) const
1228 int nrows_right = 0;
1230 for (row_type r = 0; r < nrows(); ++r) {
1231 idx_type i = cellIndex(r, c);
1232 if (c == cellColumn(i) + columnSpan(i) - 1) {
1234 bool left = (c + 1 < ncols()
1235 && cellInfo(cellIndex(r, c + 1)).left_line)
1236 || c + 1 == ncols();
1237 if (cellInfo(i).right_line && left)
1241 return 2 * nrows_right >= total;
1245 LyXAlignment Tabular::getAlignment(idx_type cell, bool onlycolumn) const
1247 if (!onlycolumn && (isMultiColumn(cell) || isMultiRow(cell)))
1248 return cellInfo(cell).alignment;
1250 return column_info[cellColumn(cell)].alignment;
1255 Tabular::getVAlignment(idx_type cell, bool onlycolumn) const
1257 if (!onlycolumn && (isMultiColumn(cell) || isMultiRow(cell)))
1258 return cellInfo(cell).valignment;
1259 return column_info[cellColumn(cell)].valignment;
1263 Length const Tabular::getPWidth(idx_type cell) const
1265 if (isMultiColumn(cell))
1266 return cellInfo(cell).p_width;
1267 return column_info[cellColumn(cell)].p_width;
1271 Length const Tabular::getMROffset(idx_type cell) const
1273 return cellInfo(cell).mroffset;
1277 int Tabular::textHOffset(idx_type cell) const
1279 // the LaTeX Way :-(
1280 int x = WIDTH_OF_LINE;
1282 int const w = cellWidth(cell) - cellInfo(cell).width;
1284 switch (getAlignment(cell)) {
1285 case LYX_ALIGN_CENTER:
1288 case LYX_ALIGN_RIGHT:
1291 case LYX_ALIGN_DECIMAL: {
1292 // we center when no decimal point
1293 if (cellInfo(cell).decimal_width == 0) {
1297 col_type const c = cellColumn(cell);
1298 int max_dhoffset = 0;
1299 for(row_type r = 0; r < row_info.size() ; ++r) {
1300 idx_type const i = cellIndex(r, c);
1301 if (getAlignment(i) == LYX_ALIGN_DECIMAL
1302 && cellInfo(i).decimal_width != 0)
1303 max_dhoffset = max(max_dhoffset, cellInfo(i).decimal_hoffset);
1305 x += max_dhoffset - cellInfo(cell).decimal_hoffset;
1308 // LYX_ALIGN_LEFT: nothing :-)
1316 int Tabular::textVOffset(idx_type cell) const
1318 int voffset = cellInfo(cell).voffset;
1319 if (isMultiRow(cell)) {
1320 row_type const row = cellRow(cell);
1321 voffset += (cellHeight(cell) - rowAscent(row) - rowDescent(row))/2;
1327 Tabular::idx_type Tabular::getFirstCellInRow(row_type row) const
1330 while (cell_info[row][c].multirow == CELL_PART_OF_MULTIROW)
1332 return cell_info[row][c].cellno;
1336 Tabular::idx_type Tabular::getLastCellInRow(row_type row) const
1338 col_type c = ncols() - 1;
1339 while (cell_info[row][c].multirow == CELL_PART_OF_MULTIROW
1340 || cell_info[row][c].multicolumn == CELL_PART_OF_MULTICOLUMN)
1342 return cell_info[row][c].cellno;
1346 Tabular::row_type Tabular::cellRow(idx_type cell) const
1348 if (cell >= numberofcells)
1352 return rowofcell[cell];
1356 Tabular::col_type Tabular::cellColumn(idx_type cell) const
1358 if (cell >= numberofcells)
1362 return columnofcell[cell];
1366 void Tabular::write(ostream & os) const
1370 << write_attribute("version", 3)
1371 << write_attribute("rows", nrows())
1372 << write_attribute("columns", ncols())
1374 // global longtable options
1376 << write_attribute("rotate", rotate)
1377 << write_attribute("booktabs", use_booktabs)
1378 << write_attribute("islongtable", is_long_tabular)
1379 << write_attribute("firstHeadTopDL", endfirsthead.topDL)
1380 << write_attribute("firstHeadBottomDL", endfirsthead.bottomDL)
1381 << write_attribute("firstHeadEmpty", endfirsthead.empty)
1382 << write_attribute("headTopDL", endhead.topDL)
1383 << write_attribute("headBottomDL", endhead.bottomDL)
1384 << write_attribute("footTopDL", endfoot.topDL)
1385 << write_attribute("footBottomDL", endfoot.bottomDL)
1386 << write_attribute("lastFootTopDL", endlastfoot.topDL)
1387 << write_attribute("lastFootBottomDL", endlastfoot.bottomDL)
1388 << write_attribute("lastFootEmpty", endlastfoot.empty);
1389 // longtables cannot be aligned vertically
1390 if (!is_long_tabular)
1391 os << write_attribute("tabularvalignment", tabular_valignment);
1392 if (is_long_tabular)
1393 os << write_attribute("longtabularalignment",
1394 longtabular_alignment);
1396 for (col_type c = 0; c < ncols(); ++c) {
1398 << write_attribute("alignment", column_info[c].alignment);
1399 if (column_info[c].alignment == LYX_ALIGN_DECIMAL)
1400 os << write_attribute("decimal_point", column_info[c].decimal_point);
1401 os << write_attribute("valignment", column_info[c].valignment)
1402 << write_attribute("width", column_info[c].p_width.asString())
1403 << write_attribute("special", column_info[c].align_special)
1406 for (row_type r = 0; r < nrows(); ++r) {
1407 static const string def("default");
1409 if (row_info[r].top_space_default)
1410 os << write_attribute("topspace", def);
1412 os << write_attribute("topspace", row_info[r].top_space);
1413 if (row_info[r].bottom_space_default)
1414 os << write_attribute("bottomspace", def);
1416 os << write_attribute("bottomspace", row_info[r].bottom_space);
1417 if (row_info[r].interline_space_default)
1418 os << write_attribute("interlinespace", def);
1420 os << write_attribute("interlinespace", row_info[r].interline_space);
1421 os << write_attribute("endhead", row_info[r].endhead)
1422 << write_attribute("endfirsthead", row_info[r].endfirsthead)
1423 << write_attribute("endfoot", row_info[r].endfoot)
1424 << write_attribute("endlastfoot", row_info[r].endlastfoot)
1425 << write_attribute("newpage", row_info[r].newpage)
1426 << write_attribute("caption", row_info[r].caption)
1428 for (col_type c = 0; c < ncols(); ++c) {
1430 << write_attribute("multicolumn", cell_info[r][c].multicolumn)
1431 << write_attribute("multirow", cell_info[r][c].multirow)
1432 << write_attribute("mroffset", cell_info[r][c].mroffset)
1433 << write_attribute("alignment", cell_info[r][c].alignment)
1434 << write_attribute("valignment", cell_info[r][c].valignment)
1435 << write_attribute("topline", cell_info[r][c].top_line)
1436 << write_attribute("bottomline", cell_info[r][c].bottom_line)
1437 << write_attribute("leftline", cell_info[r][c].left_line)
1438 << write_attribute("rightline", cell_info[r][c].right_line)
1439 << write_attribute("rotate", cell_info[r][c].rotate)
1440 << write_attribute("usebox", cell_info[r][c].usebox)
1441 << write_attribute("width", cell_info[r][c].p_width)
1442 << write_attribute("special", cell_info[r][c].align_special)
1444 os << "\\begin_inset ";
1445 cell_info[r][c].inset->write(os);
1446 os << "\n\\end_inset\n"
1451 os << "</lyxtabular>\n";
1455 void Tabular::read(Lexer & lex)
1458 istream & is = lex.getStream();
1460 l_getline(is, line);
1461 if (!prefixIs(line, "<lyxtabular ") && !prefixIs(line, "<Tabular ")) {
1462 LASSERT(false, /**/);
1467 if (!getTokenValue(line, "version", version))
1469 LASSERT(version >= 2, /**/);
1472 if (!getTokenValue(line, "rows", rows_arg))
1475 if (!getTokenValue(line, "columns", columns_arg))
1477 init(buffer_, rows_arg, columns_arg);
1478 l_getline(is, line);
1479 if (!prefixIs(line, "<features")) {
1480 lyxerr << "Wrong tabular format (expected <features ...> got"
1481 << line << ')' << endl;
1484 getTokenValue(line, "rotate", rotate);
1485 getTokenValue(line, "booktabs", use_booktabs);
1486 getTokenValue(line, "islongtable", is_long_tabular);
1487 getTokenValue(line, "tabularvalignment", tabular_valignment);
1488 getTokenValue(line, "longtabularalignment", longtabular_alignment);
1489 getTokenValue(line, "firstHeadTopDL", endfirsthead.topDL);
1490 getTokenValue(line, "firstHeadBottomDL", endfirsthead.bottomDL);
1491 getTokenValue(line, "firstHeadEmpty", endfirsthead.empty);
1492 getTokenValue(line, "headTopDL", endhead.topDL);
1493 getTokenValue(line, "headBottomDL", endhead.bottomDL);
1494 getTokenValue(line, "footTopDL", endfoot.topDL);
1495 getTokenValue(line, "footBottomDL", endfoot.bottomDL);
1496 getTokenValue(line, "lastFootTopDL", endlastfoot.topDL);
1497 getTokenValue(line, "lastFootBottomDL", endlastfoot.bottomDL);
1498 getTokenValue(line, "lastFootEmpty", endlastfoot.empty);
1500 for (col_type c = 0; c < ncols(); ++c) {
1502 if (!prefixIs(line,"<column")) {
1503 lyxerr << "Wrong tabular format (expected <column ...> got"
1504 << line << ')' << endl;
1507 getTokenValue(line, "alignment", column_info[c].alignment);
1508 getTokenValue(line, "decimal_point", column_info[c].decimal_point);
1509 getTokenValue(line, "valignment", column_info[c].valignment);
1510 getTokenValue(line, "width", column_info[c].p_width);
1511 getTokenValue(line, "special", column_info[c].align_special);
1514 for (row_type i = 0; i < nrows(); ++i) {
1515 l_getline(is, line);
1516 if (!prefixIs(line, "<row")) {
1517 lyxerr << "Wrong tabular format (expected <row ...> got"
1518 << line << ')' << endl;
1521 getTokenValue(line, "topspace", row_info[i].top_space,
1522 row_info[i].top_space_default);
1523 getTokenValue(line, "bottomspace", row_info[i].bottom_space,
1524 row_info[i].bottom_space_default);
1525 getTokenValue(line, "interlinespace", row_info[i].interline_space,
1526 row_info[i].interline_space_default);
1527 getTokenValue(line, "endfirsthead", row_info[i].endfirsthead);
1528 getTokenValue(line, "endhead", row_info[i].endhead);
1529 getTokenValue(line, "endfoot", row_info[i].endfoot);
1530 getTokenValue(line, "endlastfoot", row_info[i].endlastfoot);
1531 getTokenValue(line, "newpage", row_info[i].newpage);
1532 getTokenValue(line, "caption", row_info[i].caption);
1533 for (col_type j = 0; j < ncols(); ++j) {
1534 l_getline(is, line);
1535 if (!prefixIs(line, "<cell")) {
1536 lyxerr << "Wrong tabular format (expected <cell ...> got"
1537 << line << ')' << endl;
1540 getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
1541 getTokenValue(line, "multirow", cell_info[i][j].multirow);
1542 getTokenValue(line, "mroffset", cell_info[i][j].mroffset);
1543 getTokenValue(line, "alignment", cell_info[i][j].alignment);
1544 getTokenValue(line, "valignment", cell_info[i][j].valignment);
1545 getTokenValue(line, "topline", cell_info[i][j].top_line);
1546 getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
1547 getTokenValue(line, "leftline", cell_info[i][j].left_line);
1548 getTokenValue(line, "rightline", cell_info[i][j].right_line);
1549 getTokenValue(line, "rotate", cell_info[i][j].rotate);
1550 getTokenValue(line, "usebox", cell_info[i][j].usebox);
1551 getTokenValue(line, "width", cell_info[i][j].p_width);
1553 getTokenValue(line, "special", cell_info[i][j].align_special);
1554 l_getline(is, line);
1555 if (prefixIs(line, "\\begin_inset")) {
1556 cell_info[i][j].inset->setBuffer(*buffer_);
1557 cell_info[i][j].inset->read(lex);
1558 l_getline(is, line);
1560 if (!prefixIs(line, "</cell>")) {
1561 lyxerr << "Wrong tabular format (expected </cell> got"
1562 << line << ')' << endl;
1566 l_getline(is, line);
1567 if (!prefixIs(line, "</row>")) {
1568 lyxerr << "Wrong tabular format (expected </row> got"
1569 << line << ')' << endl;
1573 while (!prefixIs(line, "</lyxtabular>")) {
1574 l_getline(is, line);
1580 bool Tabular::isMultiColumn(idx_type cell) const
1582 return (cellInfo(cell).multicolumn == CELL_BEGIN_OF_MULTICOLUMN
1583 || cellInfo(cell).multicolumn == CELL_PART_OF_MULTICOLUMN);
1587 Tabular::CellData & Tabular::cellInfo(idx_type cell) const
1589 return cell_info[cellRow(cell)][cellColumn(cell)];
1593 Tabular::idx_type Tabular::setMultiColumn(idx_type cell, idx_type number)
1595 idx_type const col = cellColumn(cell);
1596 idx_type const row = cellRow(cell);
1597 for (idx_type i = 0; i < number; ++i)
1598 unsetMultiRow(cellIndex(row, col + i));
1600 // unsetting of multirow may have invalidated cell index
1601 cell = cellIndex(row, col);
1602 CellData & cs = cellInfo(cell);
1603 cs.multicolumn = CELL_BEGIN_OF_MULTICOLUMN;
1604 if (column_info[col].alignment != LYX_ALIGN_DECIMAL)
1605 cs.alignment = column_info[col].alignment;
1607 setRightLine(cell, rightLine(cellIndex(row, col - 1)));
1609 for (idx_type i = 1; i < number; ++i) {
1610 CellData & cs1 = cellInfo(cell + i);
1611 cs1.multicolumn = CELL_PART_OF_MULTICOLUMN;
1612 cs.inset->appendParagraphs(cs1.inset->paragraphs());
1620 bool Tabular::isMultiRow(idx_type cell) const
1622 return (cellInfo(cell).multirow == CELL_BEGIN_OF_MULTIROW
1623 || cellInfo(cell).multirow == CELL_PART_OF_MULTIROW);
1627 Tabular::idx_type Tabular::setMultiRow(idx_type cell, idx_type number)
1629 idx_type const col = cellColumn(cell);
1630 idx_type const row = cellRow(cell);
1631 for (idx_type i = 0; i < number; ++i)
1632 unsetMultiColumn(cellIndex(row + i, col));
1634 // unsetting of multirow may have invalidated cell index
1635 cell = cellIndex(row, col);
1636 CellData & cs = cellInfo(cell);
1637 cs.multirow = CELL_BEGIN_OF_MULTIROW;
1638 cs.valignment = LYX_VALIGN_MIDDLE;
1639 // the horizontal alignment of multirow cells can only
1640 // be changed for the whole table row,
1641 // support changing this only for the multirow cell can be done via
1643 // this feature would be a fileformat change
1644 // until LyX supports this, use the deault alignment of multirow
1646 cs.alignment = LYX_ALIGN_LEFT;
1648 // set the bottom row of the last selected cell
1649 setBottomLine(cell, bottomLine(cell + (number - 1)*ncols()));
1651 for (idx_type i = 1; i < number; ++i) {
1652 CellData & cs1 = cell_info[row + i][col];
1653 cs1.multirow = CELL_PART_OF_MULTIROW;
1654 cs.inset->appendParagraphs(cs1.inset->paragraphs());
1662 Tabular::idx_type Tabular::columnSpan(idx_type cell) const
1664 row_type const row = cellRow(cell);
1665 col_type const col = cellColumn(cell);
1667 while (col + span < ncols() && isPartOfMultiColumn(row, col + span))
1674 Tabular::idx_type Tabular::rowSpan(idx_type cell) const
1676 col_type const column = cellColumn(cell);
1677 col_type row = cellRow(cell) + 1;
1678 while (row < nrows() && isPartOfMultiRow(row, column))
1681 return row - cellRow(cell);
1685 void Tabular::unsetMultiColumn(idx_type cell)
1687 if (!isMultiColumn(cell))
1690 row_type const row = cellRow(cell);
1691 col_type const col = cellColumn(cell);
1692 row_type const span = columnSpan(cell);
1693 for (col_type c = 0; c < span; ++c) {
1694 // in the table dialog the lines are set in every case
1695 // when unsetting a multicolumn this leads to an additional right
1696 // line for every cell that was part of the former multicolumn cell,
1697 // except if the cell is in the last column
1698 // therefore remove this line
1699 if (cell_info[row][col + c].multicolumn == CELL_BEGIN_OF_MULTICOLUMN
1700 && (col + c) < (col + span - 1))
1701 cell_info[row][col + c].right_line = false;
1702 cell_info[row][col + c].multicolumn = CELL_NORMAL;
1708 void Tabular::unsetMultiRow(idx_type cell)
1710 if (!isMultiRow(cell))
1713 cellInfo(cell).valignment = LYX_VALIGN_TOP;
1714 cellInfo(cell).alignment = LYX_ALIGN_CENTER;
1715 row_type const row = cellRow(cell);
1716 col_type const col = cellColumn(cell);
1717 row_type const span = rowSpan(cell);
1718 for (row_type r = 0; r < span; ++r)
1719 cell_info[row + r][col].multirow = CELL_NORMAL;
1724 void Tabular::setRotateCell(idx_type cell, bool flag)
1726 cellInfo(cell).rotate = flag;
1730 bool Tabular::getRotateCell(idx_type cell) const
1732 return cellInfo(cell).rotate;
1736 bool Tabular::needRotating() const
1740 for (row_type r = 0; r < nrows(); ++r)
1741 for (col_type c = 0; c < ncols(); ++c)
1742 if (cell_info[r][c].rotate)
1748 bool Tabular::isLastCell(idx_type cell) const
1750 if (cell + 1 < numberofcells)
1756 Tabular::idx_type Tabular::cellAbove(idx_type cell) const
1758 if (cellRow(cell) == 0)
1761 col_type const col = cellColumn(cell);
1762 row_type r = cellRow(cell) - 1;
1763 while (r > 0 && cell_info[r][col].multirow == CELL_PART_OF_MULTIROW)
1766 return cell_info[r][col].cellno;
1770 Tabular::idx_type Tabular::cellBelow(idx_type cell) const
1772 row_type const nextrow = cellRow(cell) + rowSpan(cell);
1773 if (nextrow < nrows())
1774 return cell_info[nextrow][cellColumn(cell)].cellno;
1779 Tabular::idx_type Tabular::cellIndex(row_type row, col_type column) const
1781 LASSERT(column != npos && column < ncols()
1782 && row != npos && row < nrows(), /**/);
1783 return cell_info[row][column].cellno;
1787 void Tabular::setUsebox(idx_type cell, BoxType type)
1789 cellInfo(cell).usebox = type;
1793 // FIXME: Remove this routine because we cannot insert \parboxes when the user
1794 // adds line breaks, see bug 4886.
1795 Tabular::BoxType Tabular::getUsebox(idx_type cell) const
1797 if ((!column_info[cellColumn(cell)].p_width.zero() && !isMultiColumn(cell)) ||
1798 (isMultiColumn(cell) && !cellInfo(cell).p_width.zero()))
1800 if (cellInfo(cell).usebox > 1)
1801 return cellInfo(cell).usebox;
1802 return useParbox(cell);
1807 // This are functions used for the longtable support
1809 void Tabular::setLTHead(row_type row, bool flag, ltType const & hd,
1815 row_info[row].endfirsthead = flag;
1819 row_info[row].endhead = flag;
1824 bool Tabular::getRowOfLTHead(row_type row, ltType & hd) const
1827 hd.set = haveLTHead();
1828 return row_info[row].endhead;
1832 bool Tabular::getRowOfLTFirstHead(row_type row, ltType & hd) const
1835 hd.set = haveLTFirstHead();
1836 return row_info[row].endfirsthead;
1840 void Tabular::setLTFoot(row_type row, bool flag, ltType const & fd,
1846 row_info[row].endlastfoot = flag;
1850 row_info[row].endfoot = flag;
1855 bool Tabular::getRowOfLTFoot(row_type row, ltType & fd) const
1858 fd.set = haveLTFoot();
1859 return row_info[row].endfoot;
1863 bool Tabular::getRowOfLTLastFoot(row_type row, ltType & fd) const
1866 fd.set = haveLTLastFoot();
1867 return row_info[row].endlastfoot;
1871 void Tabular::setLTNewPage(row_type row, bool what)
1873 row_info[row].newpage = what;
1877 bool Tabular::getLTNewPage(row_type row) const
1879 return row_info[row].newpage;
1883 bool Tabular::haveLTHead() const
1885 for (row_type i = 0; i < nrows(); ++i)
1886 if (row_info[i].endhead)
1892 bool Tabular::haveLTFirstHead() const
1894 if (endfirsthead.empty)
1896 for (row_type r = 0; r < nrows(); ++r)
1897 if (row_info[r].endfirsthead)
1903 bool Tabular::haveLTFoot() const
1905 for (row_type r = 0; r < nrows(); ++r)
1906 if (row_info[r].endfoot)
1912 bool Tabular::haveLTLastFoot() const
1914 if (endlastfoot.empty)
1916 for (row_type r = 0; r < nrows(); ++r)
1917 if (row_info[r].endlastfoot)
1923 Tabular::idx_type Tabular::setLTCaption(row_type row, bool what)
1925 idx_type i = getFirstCellInRow(row);
1927 setMultiColumn(i, numberOfCellsInRow(row));
1928 setTopLine(i, false);
1929 setBottomLine(i, false);
1930 setLeftLine(i, false);
1931 setRightLine(i, false);
1933 unsetMultiColumn(i);
1934 // When unsetting a caption row, also all existing
1935 // captions in this row must be dissolved.
1937 row_info[row].caption = what;
1942 bool Tabular::ltCaption(row_type row) const
1944 return row_info[row].caption;
1948 bool Tabular::haveLTCaption() const
1950 for (row_type r = 0; r < nrows(); ++r)
1951 if (row_info[r].caption)
1957 // end longtable support functions
1959 void Tabular::setRowAscent(row_type row, int height)
1961 if (row >= nrows() || row_info[row].ascent == height)
1963 row_info[row].ascent = height;
1967 void Tabular::setRowDescent(row_type row, int height)
1969 if (row >= nrows() || row_info[row].descent == height)
1971 row_info[row].descent = height;
1975 int Tabular::rowAscent(row_type row) const
1977 LASSERT(row < nrows(), /**/);
1978 return row_info[row].ascent;
1982 int Tabular::rowDescent(row_type row) const
1984 LASSERT(row < nrows(), /**/);
1985 return row_info[row].descent;
1989 int Tabular::height() const
1992 for (row_type row = 0; row < nrows(); ++row)
1993 height += rowAscent(row) + rowDescent(row) +
1999 bool Tabular::isPartOfMultiColumn(row_type row, col_type column) const
2001 LASSERT(row < nrows(), /**/);
2002 LASSERT(column < ncols(), /**/);
2003 return cell_info[row][column].multicolumn == CELL_PART_OF_MULTICOLUMN;
2007 bool Tabular::isPartOfMultiRow(row_type row, col_type column) const
2009 LASSERT(row < nrows(), /**/);
2010 LASSERT(column < ncols(), /**/);
2011 return cell_info[row][column].multirow == CELL_PART_OF_MULTIROW;
2015 int Tabular::TeXTopHLine(odocstream & os, row_type row, string const lang) const
2017 // we only output complete row lines and the 1st row here, the rest
2018 // is done in Tabular::TeXBottomHLine(...)
2020 // get for each column the topline (if any)
2021 vector<bool> topline;
2023 for (col_type c = 0; c < ncols(); ++c) {
2024 topline.push_back(topLine(cellIndex(row, c)));
2025 // If cell is part of a multirow and not the first cell of the
2026 // multirow, no line must be drawn.
2028 if (isMultiRow(cellIndex(row, c))
2029 && isMultiRow(cellIndex(row - 1, c)))
2035 // do nothing if empty first row, or incomplete row line after
2036 if ((row == 0 && nset == 0) || (row > 0 && nset != ncols()))
2039 // only output complete row lines and the 1st row's clines
2040 if (nset == ncols()) {
2042 os << (row == 0 ? "\\toprule " : "\\midrule ");
2046 } else if (row == 0) {
2047 for (col_type c = 0; c < ncols(); ++c) {
2049 col_type offset = 0;
2050 for (col_type j = 0 ; j < c; ++j)
2051 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2054 //babel makes the "-" character an active one, so we have to suppress this here
2055 //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
2056 if (lang == "slovak" || lang == "czech")
2057 os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline")
2058 << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
2060 os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
2062 col_type cstart = c;
2063 for ( ; c < ncols() && topline[c]; ++c) {}
2065 for (col_type j = cstart ; j < c ; ++j)
2066 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2069 os << c + offset << "} ";
2078 int Tabular::TeXBottomHLine(odocstream & os, row_type row, string const lang) const
2080 // we output bottomlines of row r and the toplines of row r+1
2081 // if the latter do not span the whole tabular
2083 // get the bottomlines of row r, and toplines in next row
2084 bool lastrow = row == nrows() - 1;
2085 vector<bool> bottomline, topline;
2086 bool nextrowset = true;
2087 for (col_type c = 0; c < ncols(); ++c) {
2088 bottomline.push_back(bottomLine(cellIndex(row, c)));
2089 topline.push_back(!lastrow && topLine(cellIndex(row + 1, c)));
2090 // If cell is part of a multirow and not the last or first cell of the
2091 // multirow, no line must be drawn.
2093 if (isMultiRow(cellIndex(row, c))
2094 && isMultiRow(cellIndex(row + 1, c))) {
2095 bottomline[c] = false;
2098 nextrowset &= topline[c];
2101 // combine this row's bottom lines and next row's toplines if necessary
2103 for (col_type c = 0; c < ncols(); ++c) {
2105 bottomline[c] = bottomline[c] || topline[c];
2110 // do nothing if empty, OR incomplete row line with a topline in next row
2111 if (nset == 0 || (nextrowset && nset != ncols()))
2114 if (nset == ncols()) {
2116 os << (lastrow ? "\\bottomrule" : "\\midrule");
2120 for (col_type c = 0; c < ncols(); ++c) {
2121 if (bottomline[c]) {
2122 col_type offset = 0;
2123 for (col_type j = 0 ; j < c; ++j)
2124 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2127 //babel makes the "-" character an active one, so we have to suppress this here
2128 //see http://groups.google.com/group/comp.text.tex/browse_thread/thread/af769424a4a0f289#
2129 if (lang == "slovak" || lang == "czech")
2130 os << "\\expandafter" << (use_booktabs ? "\\cmidrule" : "\\cline")
2131 << "\\expandafter{\\expandafter" << c + 1 + offset << "\\string-";
2133 os << (use_booktabs ? "\\cmidrule{" : "\\cline{") << c + 1 + offset << '-';
2135 col_type cstart = c;
2136 for ( ; c < ncols() && bottomline[c]; ++c) {}
2138 for (col_type j = cstart ; j < c ; ++j)
2139 if (column_info[j].alignment == LYX_ALIGN_DECIMAL)
2142 os << c + offset << "} ";
2151 int Tabular::TeXCellPreamble(odocstream & os, idx_type cell,
2152 bool & ismulticol, bool & ismultirow) const
2155 row_type const r = cellRow(cell);
2156 if (is_long_tabular && row_info[r].caption)
2159 Tabular::VAlignment valign = getVAlignment(cell, !isMultiColumn(cell));
2160 LyXAlignment align = getAlignment(cell, !isMultiColumn(cell));
2161 // figure out how to set the lines
2162 // we always set double lines to the right of the cell
2163 col_type const c = cellColumn(cell);
2164 col_type const nextcol = c + columnSpan(cell);
2165 bool colright = columnRightLine(c);
2166 bool colleft = columnLeftLine(c);
2167 bool nextcolleft = nextcol < ncols() && columnLeftLine(nextcol);
2168 bool nextcellleft = nextcol < ncols()
2169 && leftLine(cellIndex(r, nextcol));
2170 bool coldouble = colright && nextcolleft;
2171 bool celldouble = rightLine(cell) && nextcellleft;
2173 ismulticol = isMultiColumn(cell)
2174 || (c == 0 && colleft != leftLine(cell))
2175 || ((colright || nextcolleft) && !rightLine(cell) && !nextcellleft)
2176 || (!colright && !nextcolleft && (rightLine(cell) || nextcellleft))
2177 || (coldouble != celldouble);
2179 // we center in multicol when no decimal point
2180 ismulticol |= ((column_info[c].alignment == LYX_ALIGN_DECIMAL)
2181 && (cellInfo(cell).decimal_width == 0));
2183 // up counter by 1 for each decimally aligned col since they use 2 latex cols
2184 int latexcolspan = columnSpan(cell);
2185 for(col_type col = c; col < c + columnSpan(cell); ++col)
2186 if (column_info[col].alignment == LYX_ALIGN_DECIMAL)
2190 os << "\\multicolumn{" << latexcolspan << "}{";
2191 if (c ==0 && leftLine(cell))
2193 if (!cellInfo(cell).align_special.empty()) {
2194 os << cellInfo(cell).align_special;
2196 if (!getPWidth(cell).zero()) {
2198 case LYX_ALIGN_LEFT:
2199 os << ">{\\raggedright}";
2201 case LYX_ALIGN_RIGHT:
2202 os << ">{\\raggedleft}";
2204 case LYX_ALIGN_CENTER:
2205 os << ">{\\centering}";
2211 case LYX_VALIGN_TOP:
2214 case LYX_VALIGN_MIDDLE:
2217 case LYX_VALIGN_BOTTOM:
2222 << from_ascii(getPWidth(cell).asLatexString())
2226 case LYX_ALIGN_LEFT:
2229 case LYX_ALIGN_RIGHT:
2236 } // end if else !getPWidth
2237 } // end if else !cellinfo_of_cell
2238 if (rightLine(cell) || nextcellleft)
2241 // add extra vertical line if we want a double one
2244 } // end if ismulticol
2246 // we only need code for the first multirow cell
2247 ismultirow = isMultiRow(cell);
2249 os << "\\multirow{" << rowSpan(cell) << "}{";
2250 if (!getPWidth(cell).zero())
2251 os << from_ascii(getPWidth(cell).asLatexString());
2253 // we need to set a default value
2256 if (!getMROffset(cell).zero())
2257 os << "[" << from_ascii(getMROffset(cell).asLatexString()) << "]";
2259 } // end if ismultirow
2261 if (getRotateCell(cell)) {
2262 os << "\\begin{sideways}\n";
2265 if (getUsebox(cell) == BOX_PARBOX) {
2268 case LYX_VALIGN_TOP:
2271 case LYX_VALIGN_MIDDLE:
2274 case LYX_VALIGN_BOTTOM:
2278 os << "]{" << from_ascii(getPWidth(cell).asLatexString())
2280 } else if (getUsebox(cell) == BOX_MINIPAGE) {
2281 os << "\\begin{minipage}[";
2283 case LYX_VALIGN_TOP:
2286 case LYX_VALIGN_MIDDLE:
2289 case LYX_VALIGN_BOTTOM:
2293 os << "]{" << from_ascii(getPWidth(cell).asLatexString())
2301 int Tabular::TeXCellPostamble(odocstream & os, idx_type cell,
2302 bool ismulticol, bool ismultirow) const
2305 row_type const r = cellRow(cell);
2306 if (is_long_tabular && row_info[r].caption)
2310 if (getUsebox(cell) == BOX_PARBOX)
2312 else if (getUsebox(cell) == BOX_MINIPAGE) {
2313 os << "%\n\\end{minipage}";
2316 if (getRotateCell(cell)) {
2317 os << "%\n\\end{sideways}";
2329 int Tabular::TeXLongtableHeaderFooter(odocstream & os,
2330 OutputParams const & runparams) const
2332 if (!is_long_tabular)
2337 // the caption must be output before the headers
2338 if (haveLTCaption()) {
2339 for (row_type r = 0; r < nrows(); ++r) {
2340 if (row_info[r].caption) {
2341 ret += TeXRow(os, r, runparams);
2345 // output first header info
2346 // first header must be output before the header, otherwise the
2347 // correct caption placement becomes really weird
2348 if (haveLTFirstHead()) {
2349 if (endfirsthead.topDL) {
2353 for (row_type r = 0; r < nrows(); ++r) {
2354 if (row_info[r].endfirsthead) {
2355 ret += TeXRow(os, r, runparams);
2358 if (endfirsthead.bottomDL) {
2362 os << "\\endfirsthead\n";
2365 // output header info
2367 if (endfirsthead.empty && !haveLTFirstHead()) {
2368 os << "\\endfirsthead\n";
2371 if (endhead.topDL) {
2375 for (row_type r = 0; r < nrows(); ++r) {
2376 if (row_info[r].endhead) {
2377 ret += TeXRow(os, r, runparams);
2380 if (endhead.bottomDL) {
2384 os << "\\endhead\n";
2387 // output footer info
2389 if (endfoot.topDL) {
2393 for (row_type r = 0; r < nrows(); ++r) {
2394 if (row_info[r].endfoot) {
2395 ret += TeXRow(os, r, runparams);
2398 if (endfoot.bottomDL) {
2402 os << "\\endfoot\n";
2404 if (endlastfoot.empty && !haveLTLastFoot()) {
2405 os << "\\endlastfoot\n";
2409 // output lastfooter info
2410 if (haveLTLastFoot()) {
2411 if (endlastfoot.topDL) {
2415 for (row_type r = 0; r < nrows(); ++r) {
2416 if (row_info[r].endlastfoot) {
2417 ret += TeXRow(os, r, runparams);
2420 if (endlastfoot.bottomDL) {
2424 os << "\\endlastfoot\n";
2431 bool Tabular::isValidRow(row_type row) const
2433 if (!is_long_tabular)
2435 return !row_info[row].endhead && !row_info[row].endfirsthead
2436 && !row_info[row].endfoot && !row_info[row].endlastfoot
2437 && !row_info[row].caption;
2441 int Tabular::TeXRow(odocstream & os, row_type row,
2442 OutputParams const & runparams) const
2444 idx_type cell = cellIndex(row, 0);
2445 shared_ptr<InsetTableCell> inset = cellInset(cell);
2446 Paragraph const & par = inset->paragraphs().front();
2447 string const lang = par.getParLanguage(buffer().params())->lang();
2449 //output the top line
2450 int ret = TeXTopHLine(os, row, lang);
2452 if (row_info[row].top_space_default) {
2454 os << "\\addlinespace\n";
2456 os << "\\noalign{\\vskip\\doublerulesep}\n";
2458 } else if(!row_info[row].top_space.zero()) {
2460 os << "\\addlinespace["
2461 << from_ascii(row_info[row].top_space.asLatexString())
2464 os << "\\noalign{\\vskip"
2465 << from_ascii(row_info[row].top_space.asLatexString())
2470 bool ismulticol = false;
2471 bool ismultirow = false;
2472 for (col_type c = 0; c < ncols(); ++c) {
2473 if (isPartOfMultiColumn(row, c))
2476 if (isPartOfMultiRow(row, c) &&
2477 column_info[c].alignment != LYX_ALIGN_DECIMAL) {
2482 cell = cellIndex(row, c);
2483 ret += TeXCellPreamble(os, cell, ismulticol, ismultirow);
2484 shared_ptr<InsetTableCell> inset = cellInset(cell);
2486 Paragraph const & par = inset->paragraphs().front();
2487 bool rtl = par.isRTL(buffer().params())
2489 && getPWidth(cell).zero();
2493 par.getParLanguage(buffer().params())->lang();
2494 if (lang == "farsi")
2496 else if (lang == "arabic_arabi")
2498 // currently, remaning RTL languages are
2499 // arabic_arabtex and hebrew
2503 // pass to the OutputParams that we are in a cell and
2504 // which alignment we have set.
2505 // InsetNewline needs this context information.
2506 OutputParams newrp(runparams);
2507 newrp.inTableCell = (getAlignment(cell) == LYX_ALIGN_BLOCK)
2508 ? OutputParams::PLAIN
2509 : OutputParams::ALIGNED;
2511 if (getAlignment(cell) == LYX_ALIGN_DECIMAL
2512 && cellInfo(cell).decimal_width != 0) {
2513 // copy cell and split in 2
2514 InsetTableCell head = InsetTableCell(*cellInset(cell).get());
2515 head.getText(0)->setMacrocontextPosition(
2516 cellInset(cell)->getText(0)->macrocontextPosition());
2517 head.setBuffer(buffer());
2518 bool hassep = false;
2519 InsetTableCell tail = splitCell(head, column_info[c].decimal_point, hassep);
2520 head.latex(os, newrp);
2522 ret += tail.latex(os, newrp);
2523 } else if (!isPartOfMultiRow(row, c))
2524 ret += inset->latex(os, newrp);
2526 runparams.encoding = newrp.encoding;
2530 ret += TeXCellPostamble(os, cell, ismulticol, ismultirow);
2531 if (cell != getLastCellInRow(row)) { // not last cell in row
2535 if (row_info[row].caption && !endfirsthead.empty && !haveLTFirstHead())
2536 // if no first header and no empty first header is used,
2537 // the caption needs to be terminated by \endfirsthead
2539 os << "\\endfirsthead";
2541 os << "\\tabularnewline";
2542 if (row_info[row].bottom_space_default) {
2544 os << "\\addlinespace";
2546 os << "[\\doublerulesep]";
2547 } else if (!row_info[row].bottom_space.zero()) {
2549 os << "\\addlinespace";
2551 << from_ascii(row_info[row].bottom_space.asLatexString())
2557 //output the bottom line
2558 ret += TeXBottomHLine(os, row, lang);
2560 if (row_info[row].interline_space_default) {
2562 os << "\\addlinespace\n";
2564 os << "\\noalign{\\vskip\\doublerulesep}\n";
2566 } else if (!row_info[row].interline_space.zero()) {
2568 os << "\\addlinespace["
2569 << from_ascii(row_info[row].interline_space.asLatexString())
2572 os << "\\noalign{\\vskip"
2573 << from_ascii(row_info[row].interline_space.asLatexString())
2581 int Tabular::latex(odocstream & os, OutputParams const & runparams) const
2585 //+---------------------------------------------------------------------
2586 //+ first the opening preamble +
2587 //+---------------------------------------------------------------------
2590 os << "\\begin{sideways}\n";
2593 if (is_long_tabular) {
2594 os << "\\begin{longtable}";
2595 switch (longtabular_alignment) {
2596 case LYX_LONGTABULAR_ALIGN_LEFT:
2599 case LYX_LONGTABULAR_ALIGN_CENTER:
2601 case LYX_LONGTABULAR_ALIGN_RIGHT:
2606 os << "\\begin{tabular}";
2607 switch (tabular_valignment) {
2608 case LYX_VALIGN_TOP:
2611 case LYX_VALIGN_MIDDLE:
2613 case LYX_VALIGN_BOTTOM:
2621 for (col_type c = 0; c < ncols(); ++c) {
2622 if (columnLeftLine(c))
2624 if (!column_info[c].align_special.empty()) {
2625 os << column_info[c].align_special;
2627 if (!column_info[c].p_width.zero()) {
2628 switch (column_info[c].alignment) {
2629 case LYX_ALIGN_LEFT:
2630 os << ">{\\raggedright}";
2632 case LYX_ALIGN_RIGHT:
2633 os << ">{\\raggedleft}";
2635 case LYX_ALIGN_CENTER:
2636 os << ">{\\centering}";
2638 case LYX_ALIGN_NONE:
2639 case LYX_ALIGN_BLOCK:
2640 case LYX_ALIGN_LAYOUT:
2641 case LYX_ALIGN_SPECIAL:
2642 case LYX_ALIGN_DECIMAL:
2646 switch (column_info[c].valignment) {
2647 case LYX_VALIGN_TOP:
2650 case LYX_VALIGN_MIDDLE:
2653 case LYX_VALIGN_BOTTOM:
2658 << from_ascii(column_info[c].p_width.asLatexString())
2661 switch (column_info[c].alignment) {
2662 case LYX_ALIGN_LEFT:
2665 case LYX_ALIGN_RIGHT:
2668 case LYX_ALIGN_DECIMAL:
2669 os << "r@{\\extracolsep{0pt}" << column_info[c].decimal_point << "}l";
2675 } // end if else !column_info[i].p_width
2676 } // end if else !column_info[i].align_special
2677 if (columnRightLine(c))
2683 ret += TeXLongtableHeaderFooter(os, runparams);
2685 //+---------------------------------------------------------------------
2686 //+ the single row and columns (cells) +
2687 //+---------------------------------------------------------------------
2689 for (row_type r = 0; r < nrows(); ++r) {
2690 if (isValidRow(r)) {
2691 ret += TeXRow(os, r, runparams);
2692 if (is_long_tabular && row_info[r].newpage) {
2693 os << "\\newpage\n";
2699 //+---------------------------------------------------------------------
2700 //+ the closing of the tabular +
2701 //+---------------------------------------------------------------------
2703 if (is_long_tabular)
2704 os << "\\end{longtable}";
2706 os << "\\end{tabular}";
2708 os << "\n\\end{sideways}";
2716 int Tabular::docbookRow(odocstream & os, row_type row,
2717 OutputParams const & runparams) const
2720 idx_type cell = getFirstCellInRow(row);
2723 for (col_type c = 0; c < ncols(); ++c) {
2724 if (isPartOfMultiColumn(row, c))
2727 os << "<entry align=\"";
2728 switch (getAlignment(cell)) {
2729 case LYX_ALIGN_LEFT:
2732 case LYX_ALIGN_RIGHT:
2740 os << "\" valign=\"";
2741 switch (getVAlignment(cell)) {
2742 case LYX_VALIGN_TOP:
2745 case LYX_VALIGN_BOTTOM:
2748 case LYX_VALIGN_MIDDLE:
2753 if (isMultiColumn(cell)) {
2754 os << " namest=\"col" << c << "\" ";
2755 os << "nameend=\"col" << c + columnSpan(cell) - 1 << '"';
2759 ret += cellInset(cell)->docbook(os, runparams);
2768 int Tabular::docbook(odocstream & os, OutputParams const & runparams) const
2772 //+---------------------------------------------------------------------
2773 //+ first the opening preamble +
2774 //+---------------------------------------------------------------------
2776 os << "<tgroup cols=\"" << ncols()
2777 << "\" colsep=\"1\" rowsep=\"1\">\n";
2779 for (col_type c = 0; c < ncols(); ++c) {
2780 os << "<colspec colname=\"col" << c << "\" align=\"";
2781 switch (column_info[c].alignment) {
2782 case LYX_ALIGN_LEFT:
2785 case LYX_ALIGN_RIGHT:
2793 if (runparams.flavor == OutputParams::XML)
2799 //+---------------------------------------------------------------------
2800 //+ Long Tabular case +
2801 //+---------------------------------------------------------------------
2803 // output caption info
2804 if (haveLTCaption()) {
2805 os << "<caption>\n";
2807 for (row_type r = 0; r < nrows(); ++r) {
2808 if (row_info[r].caption) {
2809 ret += docbookRow(os, r, runparams);
2812 os << "</caption>\n";
2815 // output header info
2816 if (haveLTHead() || haveLTFirstHead()) {
2819 for (row_type r = 0; r < nrows(); ++r) {
2820 if (row_info[r].endhead || row_info[r].endfirsthead) {
2821 ret += docbookRow(os, r, runparams);
2827 // output footer info
2828 if (haveLTFoot() || haveLTLastFoot()) {
2831 for (row_type r = 0; r < nrows(); ++r) {
2832 if (row_info[r].endfoot || row_info[r].endlastfoot) {
2833 ret += docbookRow(os, r, runparams);
2840 //+---------------------------------------------------------------------
2841 //+ the single row and columns (cells) +
2842 //+---------------------------------------------------------------------
2846 for (row_type r = 0; r < nrows(); ++r) {
2847 if (isValidRow(r)) {
2848 ret += docbookRow(os, r, runparams);
2853 //+---------------------------------------------------------------------
2854 //+ the closing of the tabular +
2855 //+---------------------------------------------------------------------
2864 docstring Tabular::xhtmlRow(XHTMLStream & xs, row_type row,
2865 OutputParams const & runparams) const
2868 idx_type cell = getFirstCellInRow(row);
2870 xs << html::StartTag("tr");
2871 for (col_type c = 0; c < ncols(); ++c) {
2872 if (isPartOfMultiColumn(row, c))
2877 switch (getAlignment(cell)) {
2878 case LYX_ALIGN_LEFT:
2881 case LYX_ALIGN_RIGHT:
2889 attr << " valign='";
2890 switch (getVAlignment(cell)) {
2891 case LYX_VALIGN_TOP:
2894 case LYX_VALIGN_BOTTOM:
2897 case LYX_VALIGN_MIDDLE:
2902 if (isMultiColumn(cell))
2903 attr << " colspan='" << columnSpan(cell) << "'";
2905 xs << html::StartTag("td", attr.str());
2906 ret += cellInset(cell)->xhtml(xs, runparams);
2907 xs << html::EndTag("td");
2910 xs << html::EndTag("tr");
2915 docstring Tabular::xhtml(XHTMLStream & xs, OutputParams const & runparams) const
2918 // It's unclear to me if we need to mess with the long table stuff.
2919 // We can borrow that too from docbook, if so.
2921 xs << html::StartTag("tbody");
2922 for (row_type r = 0; r < nrows(); ++r) {
2923 if (isValidRow(r)) {
2924 ret += xhtmlRow(xs, r, runparams);
2927 xs << html::EndTag("tbody");
2932 bool Tabular::plaintextTopHLine(odocstream & os, row_type row,
2933 vector<unsigned int> const & clen) const
2935 idx_type const fcell = getFirstCellInRow(row);
2936 idx_type const n = numberOfCellsInRow(row) + fcell;
2939 for (idx_type i = fcell; i < n; ++i) {
2949 for (idx_type i = fcell; i < n; ++i) {
2960 col_type column = cellColumn(i);
2961 int len = clen[column];
2962 while (column < ncols() - 1
2963 && isPartOfMultiColumn(row, ++column))
2964 len += clen[column] + 4;
2965 os << docstring(len, ch);
2980 bool Tabular::plaintextBottomHLine(odocstream & os, row_type row,
2981 vector<unsigned int> const & clen) const
2983 idx_type const fcell = getFirstCellInRow(row);
2984 idx_type const n = numberOfCellsInRow(row) + fcell;
2987 for (idx_type i = fcell; i < n; ++i) {
2988 if (bottomLine(i)) {
2997 for (idx_type i = fcell; i < n; ++i) {
2998 if (bottomLine(i)) {
3008 col_type column = cellColumn(i);
3009 int len = clen[column];
3010 while (column < ncols() - 1 && isPartOfMultiColumn(row, ++column))
3011 len += clen[column] + 4;
3012 os << docstring(len, ch);
3013 if (bottomLine(i)) {
3027 void Tabular::plaintextPrintCell(odocstream & os,
3028 OutputParams const & runparams,
3029 idx_type cell, row_type row, col_type column,
3030 vector<unsigned int> const & clen,
3031 bool onlydata) const
3033 odocstringstream sstr;
3034 cellInset(cell)->plaintext(sstr, runparams);
3046 unsigned int len1 = sstr.str().length();
3047 unsigned int len2 = clen[column];
3048 while (column < ncols() - 1 && isPartOfMultiColumn(row, ++column))
3049 len2 += clen[column] + 4;
3052 switch (getAlignment(cell)) {
3054 case LYX_ALIGN_LEFT:
3057 case LYX_ALIGN_RIGHT:
3061 case LYX_ALIGN_CENTER:
3067 os << docstring(len1, ' ') << sstr.str()
3068 << docstring(len2, ' ');
3070 if (rightLine(cell))
3077 void Tabular::plaintext(odocstream & os,
3078 OutputParams const & runparams, int const depth,
3079 bool onlydata, char_type delim) const
3081 // first calculate the width of the single columns
3082 vector<unsigned int> clen(ncols());
3085 // first all non multicolumn cells!
3086 for (col_type c = 0; c < ncols(); ++c) {
3088 for (row_type r = 0; r < nrows(); ++r) {
3089 idx_type cell = cellIndex(r, c);
3090 if (isMultiColumn(cell))
3092 odocstringstream sstr;
3093 cellInset(cell)->plaintext(sstr, runparams);
3094 if (clen[c] < sstr.str().length())
3095 clen[c] = sstr.str().length();
3098 // then all multicolumn cells!
3099 for (col_type c = 0; c < ncols(); ++c) {
3100 for (row_type r = 0; r < nrows(); ++r) {
3101 idx_type cell = cellIndex(r, c);
3102 if (cell_info[r][c].multicolumn != CELL_BEGIN_OF_MULTICOLUMN)
3104 odocstringstream sstr;
3105 cellInset(cell)->plaintext(sstr, runparams);
3106 int len = int(sstr.str().length());
3107 idx_type const n = columnSpan(cell);
3108 for (col_type k = c; len > 0 && k < c + n - 1; ++k)
3110 if (len > int(clen[c + n - 1]))
3111 clen[c + n - 1] = len;
3116 for (row_type r = 0; r < nrows(); ++r) {
3117 if (!onlydata && plaintextTopHLine(os, r, clen))
3118 os << docstring(depth * 2, ' ');
3119 for (col_type c = 0; c < ncols(); ++c) {
3120 if (isPartOfMultiColumn(r, c))
3122 if (onlydata && c > 0)
3123 // we don't use operator<< for single UCS4 character.
3124 // see explanation in docstream.h
3126 plaintextPrintCell(os, runparams, cell, r, c, clen, onlydata);
3131 os << docstring(depth * 2, ' ');
3132 if (plaintextBottomHLine(os, r, clen))
3133 os << docstring(depth * 2, ' ');
3139 shared_ptr<InsetTableCell> Tabular::cellInset(idx_type cell) const
3141 return cell_info[cellRow(cell)][cellColumn(cell)].inset;
3145 shared_ptr<InsetTableCell> Tabular::cellInset(row_type row,
3146 col_type column) const
3148 return cell_info[row][column].inset;
3152 void Tabular::setCellInset(row_type row, col_type column,
3153 shared_ptr<InsetTableCell> ins) const
3155 CellData & cd = cell_info[row][column];
3160 void Tabular::validate(LaTeXFeatures & features) const
3162 features.require("NeedTabularnewline");
3164 features.require("booktabs");
3165 if (is_long_tabular)
3166 features.require("longtable");
3168 features.require("rotating");
3169 for (idx_type cell = 0; cell < numberofcells; ++cell) {
3170 if (isMultiRow(cell))
3171 features.require("multirow");
3172 if (getVAlignment(cell) != LYX_VALIGN_TOP
3173 || !getPWidth(cell).zero())
3174 features.require("array");
3175 cellInset(cell)->validate(features);
3180 Tabular::BoxType Tabular::useParbox(idx_type cell) const
3182 ParagraphList const & parlist = cellInset(cell)->paragraphs();
3183 ParagraphList::const_iterator cit = parlist.begin();
3184 ParagraphList::const_iterator end = parlist.end();
3186 for (; cit != end; ++cit)
3187 for (int i = 0; i < cit->size(); ++i)
3188 if (cit->isNewline(i))
3195 /////////////////////////////////////////////////////////////////////
3199 /////////////////////////////////////////////////////////////////////
3201 InsetTableCell::InsetTableCell(Buffer * buf)
3202 : InsetText(buf, InsetText::PlainLayout), isFixedWidth(false),
3203 contentAlign(LYX_ALIGN_CENTER)
3207 bool InsetTableCell::forcePlainLayout(idx_type) const
3209 return !isFixedWidth;
3213 bool InsetTableCell::allowParagraphCustomization(idx_type) const
3215 return isFixedWidth;
3219 bool InsetTableCell::getStatus(Cursor & cur, FuncRequest const & cmd,
3220 FuncStatus & status) const
3223 switch (cmd.action()) {
3225 enabled = !forcePlainLayout();
3227 case LFUN_LAYOUT_PARAGRAPH:
3228 enabled = allowParagraphCustomization();
3231 return InsetText::getStatus(cur, cmd, status);
3233 status.setEnabled(enabled);
3237 docstring InsetTableCell::asString(bool intoInsets)
3240 if (paragraphs().empty())
3242 ParagraphList::const_iterator it = paragraphs().begin();
3243 ParagraphList::const_iterator en = paragraphs().end();
3245 for (; it != en; ++it) {
3250 retval += it->asString(intoInsets ? AS_STR_INSETS : AS_STR_NONE);
3256 docstring InsetTableCell::xhtml(XHTMLStream & xs, OutputParams const & rp) const
3259 return InsetText::insetAsXHTML(xs, rp, InsetText::JustText);
3260 return InsetText::xhtml(xs, rp);
3265 /////////////////////////////////////////////////////////////////////
3269 /////////////////////////////////////////////////////////////////////
3271 InsetTabular::InsetTabular(Buffer * buf, row_type rows,
3273 : Inset(buf), tabular(buf, max(rows, row_type(1)), max(columns, col_type(1))), scx_(0),
3274 rowselect_(false), colselect_(false)
3279 InsetTabular::InsetTabular(InsetTabular const & tab)
3280 : Inset(tab), tabular(tab.tabular), scx_(0)
3285 InsetTabular::~InsetTabular()
3287 hideDialogs("tabular", this);
3291 void InsetTabular::setBuffer(Buffer & buf)
3293 tabular.setBuffer(buf);
3294 Inset::setBuffer(buf);
3298 bool InsetTabular::insetAllowed(InsetCode code) const
3303 case MATHMACRO_CODE:
3308 return tabular.is_long_tabular;
3316 void InsetTabular::write(ostream & os) const
3318 os << "Tabular" << endl;
3323 docstring InsetTabular::contextMenu(BufferView const &, int, int) const
3325 // FIXME: depending on the selection state, we could offer a different menu.
3326 return from_ascii("context-tabular");
3330 void InsetTabular::read(Lexer & lex)
3332 //bool const old_format = (lex.getString() == "\\LyXTable");
3340 string token = lex.getString();
3341 while (lex && token != "\\end_inset") {
3343 token = lex.getString();
3346 lex.printError("Missing \\end_inset at this point. ");
3350 int InsetTabular::rowFromY(Cursor & cur, int y) const
3352 // top y coordinate of tabular
3353 int h = yo(cur.bv()) - tabular.rowAscent(0);
3355 for (; r < tabular.nrows() && y > h; ++r)
3356 h += tabular.rowAscent(r) + tabular.rowDescent(r)
3357 + tabular.interRowSpace(r);
3363 int InsetTabular::columnFromX(Cursor & cur, int x) const
3365 // left x coordinate of tabular
3366 int w = xo(cur.bv()) + ADD_TO_TABULAR_WIDTH;
3368 for (; c < tabular.ncols() && x > w; ++c)
3369 w += tabular.cellWidth(c);
3374 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
3376 //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
3377 // mi.base.textwidth << "\n";
3380 LASSERT(false, /**/);
3383 for (row_type r = 0; r < tabular.nrows(); ++r) {
3386 for (col_type c = 0; c < tabular.ncols(); ++c) {
3387 if (tabular.isPartOfMultiColumn(r, c)
3388 || tabular.isPartOfMultiRow(r, c))
3389 // multicolumn or multirow cell, but not first one
3391 idx_type const cell = tabular.cellIndex(r, c);
3394 Length const p_width = tabular.getPWidth(cell);
3395 if (!p_width.zero())
3396 m.base.textwidth = p_width.inPixels(mi.base.textwidth);
3397 tabular.cellInset(cell)->metrics(m, dim);
3398 if (!p_width.zero())
3399 dim.wid = m.base.textwidth;
3400 tabular.cellInfo(cell).width = dim.wid + 2 * WIDTH_OF_LINE
3401 + tabular.interColumnSpace(cell);
3403 // FIXME(?): do we need a second metrics call?
3404 TextMetrics const & tm =
3405 mi.base.bv->textMetrics(tabular.cellInset(cell)->getText(0));
3407 // determine horiz offset because of decimal align (if necessary)
3408 int decimal_hoffset = 0;
3409 int decimal_width = 0;
3410 if (tabular.getAlignment(cell) == LYX_ALIGN_DECIMAL) {
3411 // make a copy which we will split in 2
3412 InsetTableCell head = InsetTableCell(*tabular.cellInset(cell).get());
3413 head.getText(0)->setMacrocontextPosition(
3414 tabular.cellInset(cell)->getText(0)->macrocontextPosition());
3415 head.setBuffer(tabular.buffer());
3416 // split in 2 and calculate width of each part
3417 bool hassep = false;
3418 InsetTableCell tail =
3419 splitCell(head, tabular.column_info[c].decimal_point, hassep);
3421 head.metrics(m, dim1);
3422 decimal_hoffset = dim1.width();
3424 tail.metrics(m, dim1);
3425 decimal_width = dim1.width();
3428 tabular.cell_info[r][c].decimal_hoffset = decimal_hoffset;
3429 tabular.cell_info[r][c].decimal_width = decimal_width;
3431 // with LYX_VALIGN_BOTTOM the descent is relative to the last par
3432 // = descent of text in last par + TEXT_TO_INSET_OFFSET:
3433 int const lastpardes = tm.last().second->descent()
3434 + TEXT_TO_INSET_OFFSET;
3436 switch (tabular.getVAlignment(cell)) {
3437 case Tabular::LYX_VALIGN_TOP:
3439 case Tabular::LYX_VALIGN_MIDDLE:
3440 offset = -(dim.des - lastpardes)/2;
3442 case Tabular::LYX_VALIGN_BOTTOM:
3443 offset = -(dim.des - lastpardes);
3446 tabular.cell_info[r][c].voffset = offset;
3447 maxasc = max(maxasc, dim.asc - offset);
3448 maxdes = max(maxdes, dim.des + offset);
3450 int const top_space = tabular.row_info[r].top_space_default ?
3451 default_line_space :
3452 tabular.row_info[r].top_space.inPixels(mi.base.textwidth);
3453 tabular.setRowAscent(r, maxasc + ADD_TO_HEIGHT + top_space);
3454 int const bottom_space = tabular.row_info[r].bottom_space_default ?
3455 default_line_space :
3456 tabular.row_info[r].bottom_space.inPixels(mi.base.textwidth);
3457 tabular.setRowDescent(r, maxdes + ADD_TO_HEIGHT + bottom_space);
3459 tabular.updateColumnWidths();
3460 dim.asc = tabular.rowAscent(0);
3461 dim.des = tabular.height() - dim.asc;
3462 dim.wid = tabular.width() + 2 * ADD_TO_TABULAR_WIDTH;
3466 bool InsetTabular::isCellSelected(Cursor & cur, row_type row, col_type col)
3469 if (&cur.inset() == this && cur.selection()) {
3470 if (cur.selIsMultiCell()) {
3473 getSelection(cur, rs, re, cs, ce);
3475 idx_type const cell = tabular.cellIndex(row, col);
3476 col_type const cspan = tabular.columnSpan(cell);
3477 row_type const rspan = tabular.rowSpan(cell);
3478 if (col + cspan - 1 >= cs && col <= ce
3479 && row + rspan - 1 >= rs && row <= re)
3482 if (col == tabular.cellColumn(cur.idx())
3483 && row == tabular.cellRow(cur.idx())) {
3484 CursorSlice const & beg = cur.selBegin();
3485 CursorSlice const & end = cur.selEnd();
3487 if ((end.lastpos() > 0 || end.lastpit() > 0)
3488 && end.pos() == end.lastpos() && beg.pos() == 0
3489 && end.pit() == end.lastpit() && beg.pit() == 0)
3497 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
3499 x += scx_ + ADD_TO_TABULAR_WIDTH;
3501 BufferView * bv = pi.base.bv;
3502 Cursor & cur = pi.base.bv->cursor();
3505 // FIXME: As the full background is painted in drawSelection(),
3506 // we have no choice but to do a full repaint for the Text cells.
3507 pi.full_repaint = true;
3509 bool const original_selection_state = pi.selected;
3512 first_visible_cell = Tabular::npos;
3513 for (row_type r = 0; r < tabular.nrows(); ++r) {
3515 for (col_type c = 0; c < tabular.ncols(); ++c) {
3516 if (tabular.isPartOfMultiColumn(r, c))
3519 idx = tabular.cellIndex(r, c);
3521 if (tabular.isPartOfMultiRow(r, c)) {
3522 nx += tabular.cellWidth(idx);
3526 if (first_visible_cell == Tabular::npos)
3527 first_visible_cell = idx;
3529 pi.selected |= isCellSelected(cur, r, c);
3530 int const cx = nx + tabular.textHOffset(idx);
3531 int const cy = y + tabular.textVOffset(idx);
3532 // Cache the Inset position.
3533 bv->coordCache().insets().add(cell(idx).get(), cx, cy);
3534 cell(idx)->draw(pi, cx, cy);
3535 drawCellLines(pi, nx, y, r, idx);
3536 nx += tabular.cellWidth(idx);
3537 pi.selected = original_selection_state;
3540 if (r + 1 < tabular.nrows())
3541 y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
3542 + tabular.interRowSpace(r + 1);
3547 void InsetTabular::drawSelection(PainterInfo & pi, int x, int y) const
3549 Cursor & cur = pi.base.bv->cursor();
3552 x += scx_ + ADD_TO_TABULAR_WIDTH;
3554 // FIXME: it is wrong to completely paint the background
3555 // if we want to do single row painting.
3557 // Paint background of current tabular
3558 int const w = tabular.width();
3559 int const h = tabular.height();
3560 int yy = y - tabular.rowAscent(0);
3561 pi.pain.fillRectangle(x, yy, w, h, pi.backgroundColor(this));
3563 if (!cur.selection())
3565 if (&cur.inset() != this)
3570 bool const full_cell_selected = isCellSelected(cur,
3571 tabular.cellRow(cur.idx()), tabular.cellColumn(cur.idx()));
3573 if (cur.selIsMultiCell() || full_cell_selected) {
3574 for (row_type r = 0; r < tabular.nrows(); ++r) {
3576 for (col_type c = 0; c < tabular.ncols(); ++c) {
3577 if (tabular.isPartOfMultiColumn(r, c))
3580 idx_type const cell = tabular.cellIndex(r, c);
3582 if (tabular.isPartOfMultiRow(r, c)) {
3583 xx += tabular.cellWidth(cell);
3586 int const w = tabular.cellWidth(cell);
3587 int const h = tabular.cellHeight(cell);
3588 int const yy = y - tabular.rowAscent(r);
3589 if (isCellSelected(cur, r, c))
3590 pi.pain.fillRectangle(xx, yy, w, h, Color_selection);
3593 if (r + 1 < tabular.nrows())
3594 y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
3595 + tabular.interRowSpace(r + 1);
3599 x += cellXPos(cur.idx());
3600 x += tabular.textHOffset(cur.idx());
3601 cell(cur.idx())->drawSelection(pi, x, 0 /* ignored */);
3606 void InsetTabular::drawCellLines(PainterInfo & pi, int x, int y,
3607 row_type row, idx_type cell) const
3609 y -= tabular.rowAscent(row);
3610 int const w = tabular.cellWidth(cell);
3611 int const h = tabular.cellHeight(cell);
3612 Color const linecolor = pi.textColor(Color_tabularline);
3613 Color const gridcolor = pi.textColor(Color_tabularonoffline);
3616 bool drawline = tabular.topLine(cell)
3617 || (row > 0 && tabular.bottomLine(tabular.cellAbove(cell)));
3618 pi.pain.line(x, y, x + w, y,
3619 drawline ? linecolor : gridcolor,
3620 drawline ? Painter::line_solid : Painter::line_onoffdash);
3623 drawline = tabular.bottomLine(cell);
3624 pi.pain.line(x, y + h, x + w, y + h,
3625 drawline ? linecolor : gridcolor,
3626 drawline ? Painter::line_solid : Painter::line_onoffdash);
3629 col_type const col = tabular.cellColumn(cell);
3630 drawline = tabular.leftLine(cell)
3631 || (col > 0 && tabular.rightLine(tabular.cellIndex(row, col - 1)));
3632 pi.pain.line(x, y, x, y + h,
3633 drawline ? linecolor : gridcolor,
3634 drawline ? Painter::line_solid : Painter::line_onoffdash);
3637 x -= tabular.interColumnSpace(cell);
3638 drawline = tabular.rightLine(cell)
3639 || (col + 1 < tabular.ncols()
3640 && tabular.leftLine(tabular.cellIndex(row, col + 1)));
3641 pi.pain.line(x + w, y, x + w, y + h,
3642 drawline ? linecolor : gridcolor,
3643 drawline ? Painter::line_solid : Painter::line_onoffdash);
3647 void InsetTabular::edit(Cursor & cur, bool front, EntryDirection)
3649 //lyxerr << "InsetTabular::edit: " << this << endl;
3651 cur.setSelection(false);
3654 if (isRightToLeft(cur))
3655 cur.idx() = tabular.getLastCellInRow(0);
3661 if (isRightToLeft(cur))
3662 cur.idx() = tabular.getFirstCellInRow(tabular.nrows() - 1);
3664 cur.idx() = tabular.numberofcells - 1;
3666 cur.pos() = cur.lastpos(); // FIXME crude guess
3668 cur.setCurrentFont();
3669 // FIXME: this accesses the position cache before it is initialized
3671 //cur.bv().fitCursor();
3675 void InsetTabular::updateBuffer(ParIterator const & it, UpdateType utype)
3677 // In a longtable, tell captions what the current float is
3678 Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
3679 string const saveflt = cnts.current_float();
3680 if (tabular.is_long_tabular)
3681 cnts.current_float("table");
3683 ParIterator it2 = it;
3685 size_t const end = it2.nargs();
3686 for ( ; it2.idx() < end; it2.top().forwardIdx())
3687 buffer().updateBuffer(it2, utype);
3690 if (tabular.is_long_tabular)
3691 cnts.current_float(saveflt);
3695 void InsetTabular::addToToc(DocIterator const & cpit)
3697 DocIterator dit = cpit;
3699 size_t const end = dit.nargs();
3700 for ( ; dit.idx() < end; dit.top().forwardIdx())
3701 cell(dit.idx())->addToToc(dit);
3705 void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
3707 LYXERR(Debug::DEBUG, "# InsetTabular::doDispatch: cmd: " << cmd
3708 << "\n cur:" << cur);
3709 CursorSlice sl = cur.top();
3710 Cursor & bvcur = cur.bv().cursor();
3712 FuncCode const act = cmd.action();
3716 case LFUN_MOUSE_PRESS: {
3717 //lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
3719 if (cmd.x() < xo(cur.bv()) + ADD_TO_TABULAR_WIDTH
3720 || cmd.x() > xo(cur.bv()) + tabular.width()) {
3721 row_type r = rowFromY(cur, cmd.y());
3722 cur.idx() = tabular.getFirstCellInRow(r);
3725 cur.idx() = tabular.getLastCellInRow(r);
3726 cur.pos() = cur.lastpos();
3727 cur.setSelection(true);
3733 int const y0 = yo(cur.bv()) - tabular.rowAscent(0);
3734 if (cmd.y() < y0 + ADD_TO_TABULAR_WIDTH
3735 || cmd.y() > y0 + tabular.height()) {
3736 col_type c = columnFromX(cur, cmd.x());
3737 cur.idx() = tabular.cellIndex(0, c);
3740 cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c);
3741 cur.pos() = cur.lastpos();
3742 cur.setSelection(true);
3747 // do not reset cursor/selection if we have selected
3748 // some cells (bug 2715).
3749 if (cmd.button() == mouse_button::button3
3750 && &bvcur.selBegin().inset() == this
3751 && bvcur.selIsMultiCell())
3754 // Let InsetTableCell do it
3755 cell(cur.idx())->dispatch(cur, cmd);
3758 case LFUN_MOUSE_MOTION:
3759 //lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
3760 if (cmd.button() == mouse_button::button1) {
3761 // only accept motions to places not deeper nested than the real anchor
3762 if (!bvcur.realAnchor().hasPart(cur)) {
3766 // select (additional) row
3768 row_type r = rowFromY(cur, cmd.y());
3769 cur.idx() = tabular.getLastCellInRow(r);
3770 // we need to reset the cursor's pit and pos now, as the old ones
3771 // may no longer be valid.
3774 bvcur.setCursor(cur);
3775 bvcur.setSelection(true);
3778 // select (additional) column
3780 col_type c = columnFromX(cur, cmd.x());
3781 cur.idx() = tabular.cellIndex(tabular.nrows() - 1, c);
3782 // we need to reset the cursor's pit and pos now, as the old ones
3783 // may no longer be valid.
3786 bvcur.setCursor(cur);
3787 bvcur.setSelection(true);
3790 // only update if selection changes
3791 if (bvcur.idx() == cur.idx() &&
3792 !(bvcur.realAnchor().idx() == cur.idx() && bvcur.pos() != cur.pos()))
3793 cur.noScreenUpdate();
3794 setCursorFromCoordinates(cur, cmd.x(), cmd.y());
3795 bvcur.setCursor(cur);
3796 bvcur.setSelection(true);
3797 // if this is a multicell selection, we just set the cursor to
3798 // the beginning of the cell's text.
3799 if (bvcur.selIsMultiCell()) {
3800 bvcur.pit() = bvcur.lastpit();
3801 bvcur.pos() = bvcur.lastpos();
3806 case LFUN_MOUSE_RELEASE:
3811 case LFUN_CELL_BACKWARD:
3813 cur.setSelection(false);
3816 case LFUN_CELL_FORWARD:
3818 cur.setSelection(false);
3821 case LFUN_CHAR_FORWARD_SELECT:
3822 case LFUN_CHAR_FORWARD:
3823 case LFUN_CHAR_BACKWARD_SELECT:
3824 case LFUN_CHAR_BACKWARD:
3825 case LFUN_CHAR_RIGHT_SELECT:
3826 case LFUN_CHAR_RIGHT:
3827 case LFUN_CHAR_LEFT_SELECT:
3828 case LFUN_CHAR_LEFT:
3829 case LFUN_WORD_FORWARD:
3830 case LFUN_WORD_FORWARD_SELECT:
3831 case LFUN_WORD_BACKWARD:
3832 case LFUN_WORD_BACKWARD_SELECT:
3833 case LFUN_WORD_RIGHT:
3834 case LFUN_WORD_RIGHT_SELECT:
3835 case LFUN_WORD_LEFT:
3836 case LFUN_WORD_LEFT_SELECT: {
3837 // determine whether we move to next or previous cell, where to enter
3838 // the new cell from, and which command to "finish" (i.e., exit the
3841 EntryDirection entry_from = ENTRY_DIRECTION_IGNORE;
3842 FuncCode finish_lfun;
3844 if (act == LFUN_CHAR_FORWARD
3845 || act == LFUN_CHAR_FORWARD_SELECT
3846 || act == LFUN_WORD_FORWARD
3847 || act == LFUN_WORD_FORWARD_SELECT) {
3849 finish_lfun = LFUN_FINISHED_FORWARD;
3851 else if (act == LFUN_CHAR_BACKWARD
3852 || act == LFUN_CHAR_BACKWARD_SELECT
3853 || act == LFUN_WORD_BACKWARD
3854 || act == LFUN_WORD_BACKWARD_SELECT) {
3856 finish_lfun = LFUN_FINISHED_BACKWARD;
3858 // LEFT or RIGHT commands --- the interpretation will depend on the
3859 // table's direction.
3861 bool const right = act == LFUN_CHAR_RIGHT
3862 || act == LFUN_CHAR_RIGHT_SELECT
3863 || act == LFUN_WORD_RIGHT
3864 || act == LFUN_WORD_RIGHT_SELECT;
3865 next_cell = isRightToLeft(cur) != right;
3867 if (lyxrc.visual_cursor)
3868 entry_from = right ? ENTRY_DIRECTION_LEFT:ENTRY_DIRECTION_RIGHT;
3870 finish_lfun = right ? LFUN_FINISHED_RIGHT : LFUN_FINISHED_LEFT;
3873 bool const select = act == LFUN_CHAR_FORWARD_SELECT
3874 || act == LFUN_CHAR_BACKWARD_SELECT
3875 || act == LFUN_CHAR_RIGHT_SELECT
3876 || act == LFUN_CHAR_LEFT_SELECT
3877 || act == LFUN_WORD_FORWARD_SELECT
3878 || act == LFUN_WORD_RIGHT_SELECT
3879 || act == LFUN_WORD_BACKWARD_SELECT
3880 || act == LFUN_WORD_LEFT_SELECT;
3882 // If we have a multicell selection or we're
3883 // not doing some LFUN_*_SELECT thing anyway...
3884 if (!cur.selIsMultiCell() || !select) {
3885 col_type const c = tabular.cellColumn(cur.idx());
3886 row_type const r = tabular.cellRow(cur.idx());
3887 // Are we trying to select the whole cell and is the whole cell
3888 // not yet selected?
3889 bool const select_whole = select && !isCellSelected(cur, r, c) &&
3890 ((next_cell && cur.pit() == cur.lastpit()
3891 && cur.pos() == cur.lastpos())
3892 || (!next_cell && cur.pit() == 0 && cur.pos() == 0));
3894 bool const empty_cell = cur.lastpos() == 0 && cur.lastpit() == 0;
3896 // ...try to dispatch to the cell's inset.
3897 cell(cur.idx())->dispatch(cur, cmd);
3899 // When we already have a selection we want to select the whole cell
3900 // before going to the next cell.
3901 if (select_whole && !empty_cell){
3902 getText(cur.idx())->selectAll(cur);
3907 // FIXME: When we support the selection of an empty cell, remove
3908 // the !empty_cell from this condition. For now we jump to the next
3909 // cell if the current cell is empty.
3910 if (cur.result().dispatched() && !empty_cell)
3914 // move to next/prev cell, as appropriate
3915 // note that we will always do this if we're selecting and we have
3916 // a multicell selection
3917 LYXERR(Debug::RTL, "entering " << (next_cell ? "next" : "previous")
3918 << " cell from: " << int(entry_from));
3920 moveNextCell(cur, entry_from);
3922 movePrevCell(cur, entry_from);
3923 // if we're exiting the table, call the appropriate FINISHED lfun
3924 if (sl == cur.top())
3925 cmd = FuncRequest(finish_lfun);
3932 case LFUN_DOWN_SELECT:
3934 if (!(cur.selection() && cur.selIsMultiCell()))
3935 cell(cur.idx())->dispatch(cur, cmd);
3937 cur.dispatched(); // override the cell's decision
3938 if (sl == cur.top()) {
3939 // if our Text didn't do anything to the cursor
3940 // then we try to put the cursor into the cell below
3941 // setting also the right targetX.
3942 cur.selHandle(act == LFUN_DOWN_SELECT);
3943 if (tabular.cellRow(cur.idx()) != tabular.nrows() - 1) {
3944 cur.idx() = tabular.cellBelow(cur.idx());
3946 TextMetrics const & tm =
3947 cur.bv().textMetrics(cell(cur.idx())->getText(0));
3948 cur.pos() = tm.x2pos(cur.pit(), 0, cur.targetX());
3949 cur.setCurrentFont();
3952 if (sl == cur.top()) {
3953 // we trick it to go to forward after leaving the
3955 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
3958 if (cur.selIsMultiCell()) {
3959 cur.pit() = cur.lastpit();
3960 cur.pos() = cur.lastpos();
3961 cur.setCurrentFont();
3966 case LFUN_UP_SELECT:
3968 if (!(cur.selection() && cur.selIsMultiCell()))
3969 cell(cur.idx())->dispatch(cur, cmd);
3970 cur.dispatched(); // override the cell's decision
3971 if (sl == cur.top()) {
3972 // if our Text didn't do anything to the cursor
3973 // then we try to put the cursor into the cell above
3974 // setting also the right targetX.
3975 cur.selHandle(act == LFUN_UP_SELECT);
3976 if (tabular.cellRow(cur.idx()) != 0) {
3977 cur.idx() = tabular.cellAbove(cur.idx());
3978 cur.pit() = cur.lastpit();
3979 Text const * text = cell(cur.idx())->getText(0);
3980 TextMetrics const & tm = cur.bv().textMetrics(text);
3981 ParagraphMetrics const & pm =
3982 tm.parMetrics(cur.lastpit());
3983 cur.pos() = tm.x2pos(cur.pit(), pm.rows().size()-1, cur.targetX());
3984 cur.setCurrentFont();
3987 if (sl == cur.top()) {
3988 cmd = FuncRequest(LFUN_UP);
3991 if (cur.selIsMultiCell()) {
3993 cur.pos() = cur.lastpos();
3994 cur.setCurrentFont();
3999 // case LFUN_SCREEN_DOWN: {
4000 // //if (hasSelection())
4001 // // cur.selection() = false;
4002 // col_type const col = tabular.cellColumn(cur.idx());
4003 // int const t = cur.bv().top_y() + cur.bv().height();
4004 // if (t < yo() + tabular.getHeightOfTabular()) {
4005 // cur.bv().scrollDocView(t, true);
4006 // cur.idx() = tabular.cellBelow(first_visible_cell) + col;
4008 // cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + col;
4015 // case LFUN_SCREEN_UP: {
4016 // //if (hasSelection())
4017 // // cur.selection() = false;
4018 // col_type const col = tabular.cellColumn(cur.idx());
4019 // int const t = cur.bv().top_y() + cur.bv().height();
4021 // cur.bv().scrollDocView(t, true);
4025 // cur.idx() = tabular.cellBelow(first_visible_cell) + col;
4029 // cur.par() = cur.lastpar();
4030 // cur.pos() = cur.lastpos();
4034 case LFUN_LAYOUT_TABULAR:
4035 cur.bv().showDialog("tabular");
4038 case LFUN_INSET_MODIFY:
4039 if (!tabularFeatures(cur, to_utf8(cmd.argument())))
4043 // insert file functions
4044 case LFUN_FILE_INSERT_PLAINTEXT_PARA:
4045 case LFUN_FILE_INSERT_PLAINTEXT:
4047 if (FileName::isAbsolute(to_utf8(cmd.argument()))) {
4048 docstring const tmpstr = cur.bv().contentsOfPlaintextFile(
4049 FileName(to_utf8(cmd.argument())));
4052 cur.recordUndoInset(INSERT_UNDO);
4053 if (insertPlaintextString(cur.bv(), tmpstr, false)) {
4054 // content has been replaced,
4055 // so cursor might be invalid
4056 cur.pos() = cur.lastpos();
4057 cur.pit() = cur.lastpit();
4058 bvcur.setCursor(cur);
4065 if (cur.selIsMultiCell()) {
4066 if (copySelection(cur)) {
4067 cur.recordUndoInset(DELETE_UNDO);
4071 cell(cur.idx())->dispatch(cur, cmd);
4074 case LFUN_SELF_INSERT:
4075 if (cur.selIsMultiCell()) {
4076 cur.recordUndoInset(DELETE_UNDO);
4079 cell(cur.idx())->dispatch(cur, cmd);
4082 case LFUN_CHAR_DELETE_BACKWARD:
4083 case LFUN_CHAR_DELETE_FORWARD:
4084 if (cur.selIsMultiCell()) {
4085 cur.recordUndoInset(DELETE_UNDO);
4088 cell(cur.idx())->dispatch(cur, cmd);
4092 if (!cur.selection())
4094 if (cur.selIsMultiCell()) {
4098 cell(cur.idx())->dispatch(cur, cmd);
4101 case LFUN_CLIPBOARD_PASTE:
4102 case LFUN_PRIMARY_SELECTION_PASTE: {
4103 docstring const clip = (act == LFUN_CLIPBOARD_PASTE) ?
4104 theClipboard().getAsText() :
4105 theSelection().get();
4108 // pass to InsertPlaintextString, but
4109 // only if we have multi-cell content
4110 if (clip.find_first_of(from_ascii("\t\n")) != docstring::npos) {
4111 cur.recordUndoInset(INSERT_UNDO);
4112 if (insertPlaintextString(cur.bv(), clip, false)) {
4113 // content has been replaced,
4114 // so cursor might be invalid
4115 cur.pos() = cur.lastpos();
4116 cur.pit() = cur.lastpit();
4117 bvcur.setCursor(cur);
4121 // Let the cell handle normal text
4122 cell(cur.idx())->dispatch(cur, cmd);
4127 if (!tabularStackDirty()) {
4128 if (!cur.selIsMultiCell())
4129 cell(cur.idx())->dispatch(cur, cmd);
4132 if (theClipboard().isInternal() ||
4133 (!theClipboard().hasInternal() && theClipboard().hasLyXContents())) {
4134 cur.recordUndoInset(INSERT_UNDO);
4135 pasteClipboard(cur);
4139 case LFUN_FONT_EMPH:
4140 case LFUN_FONT_BOLD:
4141 case LFUN_FONT_BOLDSYMBOL:
4142 case LFUN_FONT_ROMAN:
4143 case LFUN_FONT_NOUN:
4144 case LFUN_FONT_ITAL:
4145 case LFUN_FONT_FRAK:
4146 case LFUN_FONT_TYPEWRITER:
4147 case LFUN_FONT_SANS:
4148 case LFUN_TEXTSTYLE_APPLY:
4149 case LFUN_TEXTSTYLE_UPDATE:
4150 case LFUN_FONT_SIZE:
4151 case LFUN_FONT_UNDERLINE:
4152 case LFUN_FONT_STRIKEOUT:
4153 case LFUN_FONT_UULINE:
4154 case LFUN_FONT_UWAVE:
4156 case LFUN_WORD_CAPITALIZE:
4157 case LFUN_WORD_UPCASE:
4158 case LFUN_WORD_LOWCASE:
4159 case LFUN_CHARS_TRANSPOSE:
4160 if (cur.selIsMultiCell()) {
4163 getSelection(cur, rs, re, cs, ce);
4164 Cursor tmpcur = cur;
4165 for (row_type r = rs; r <= re; ++r) {
4166 for (col_type c = cs; c <= ce; ++c) {
4167 // cursor follows cell:
4168 tmpcur.idx() = tabular.cellIndex(r, c);
4169 // select this cell only:
4172 tmpcur.resetAnchor();
4173 tmpcur.pit() = tmpcur.lastpit();
4174 tmpcur.pos() = tmpcur.top().lastpos();
4175 tmpcur.setCursor(tmpcur);
4176 tmpcur.setSelection();
4177 cell(tmpcur.idx())->dispatch(tmpcur, cmd);
4182 cell(cur.idx())->dispatch(cur, cmd);
4186 case LFUN_INSET_SETTINGS:
4187 // relay this lfun to Inset, not to the cell.
4188 Inset::doDispatch(cur, cmd);
4192 // we try to handle this event in the insets dispatch function.
4193 cell(cur.idx())->dispatch(cur, cmd);
4199 // function sets an object as defined in func_status.h:
4200 // states OK, Unknown, Disabled, On, Off.
4201 bool InsetTabular::getStatus(Cursor & cur, FuncRequest const & cmd,
4202 FuncStatus & status) const
4204 switch (cmd.action()) {
4205 case LFUN_INSET_MODIFY: {
4206 if (&cur.inset() != this || cmd.getArg(0) != "tabular")
4209 string const s = cmd.getArg(1);
4210 // FIXME: We only check for the very first argument...
4211 int action = Tabular::LAST_ACTION;
4213 for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
4214 if (tabularFeature[i].feature == s) {
4215 action = tabularFeature[i].action;
4219 if (action == Tabular::LAST_ACTION) {
4221 status.setUnknown(true);
4225 string const argument = cmd.getLongArg(2);
4227 row_type sel_row_start = 0;
4228 row_type sel_row_end = 0;
4229 col_type sel_col_start = 0;
4230 col_type sel_col_end = 0;
4231 Tabular::ltType dummyltt;
4234 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
4237 case Tabular::SET_PWIDTH:
4238 case Tabular::SET_MPWIDTH:
4239 case Tabular::SET_SPECIAL_COLUMN:
4240 case Tabular::SET_SPECIAL_MULTICOLUMN:
4241 case Tabular::APPEND_ROW:
4242 case Tabular::APPEND_COLUMN:
4243 case Tabular::DELETE_ROW:
4244 case Tabular::DELETE_COLUMN:
4245 case Tabular::COPY_ROW:
4246 case Tabular::COPY_COLUMN:
4247 case Tabular::SET_TOP_SPACE:
4248 case Tabular::SET_BOTTOM_SPACE:
4249 case Tabular::SET_INTERLINE_SPACE:
4253 case Tabular::SET_DECIMAL_POINT:
4255 tabular.getAlignment(cur.idx()) == LYX_ALIGN_DECIMAL);
4258 case Tabular::SET_MULTICOLUMN:
4259 case Tabular::UNSET_MULTICOLUMN:
4260 case Tabular::MULTICOLUMN:
4261 // If a row is set as longtable caption, it must not be allowed
4262 // to unset that this row is a multicolumn.
4263 status.setEnabled(sel_row_start == sel_row_end
4264 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
4265 status.setOnOff(tabular.isMultiColumn(cur.idx()));
4268 case Tabular::SET_MULTIROW:
4269 case Tabular::UNSET_MULTIROW:
4270 case Tabular::MULTIROW:
4271 // If a row is set as longtable caption, it must not be allowed
4272 // to unset that this row is a multirow.
4273 status.setEnabled(sel_col_start == sel_col_end
4274 && !tabular.ltCaption(tabular.cellRow(cur.idx())));
4275 status.setOnOff(tabular.isMultiRow(cur.idx()));
4278 case Tabular::SET_ALL_LINES:
4279 case Tabular::UNSET_ALL_LINES:
4280 case Tabular::SET_BORDER_LINES:
4281 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4284 case Tabular::SET_LINE_TOP:
4285 case Tabular::SET_LINE_BOTTOM:
4286 case Tabular::SET_LINE_LEFT:
4287 case Tabular::SET_LINE_RIGHT:
4288 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4291 case Tabular::TOGGLE_LINE_TOP:
4292 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4293 status.setOnOff(tabular.topLine(cur.idx()));
4296 case Tabular::TOGGLE_LINE_BOTTOM:
4297 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4298 status.setOnOff(tabular.bottomLine(cur.idx()));
4301 case Tabular::TOGGLE_LINE_LEFT:
4302 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4303 status.setOnOff(tabular.leftLine(cur.idx()));
4306 case Tabular::TOGGLE_LINE_RIGHT:
4307 status.setEnabled(!tabular.ltCaption(tabular.cellRow(cur.idx())));
4308 status.setOnOff(tabular.rightLine(cur.idx()));
4311 // multirow cells are alwas left aligned
4312 case Tabular::M_ALIGN_LEFT:
4314 case Tabular::ALIGN_LEFT:
4315 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_LEFT);
4318 case Tabular::M_ALIGN_RIGHT:
4320 case Tabular::ALIGN_RIGHT:
4321 status.setEnabled(!tabular.isMultiRow(cur.idx()));
4322 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_RIGHT);
4325 case Tabular::M_ALIGN_CENTER:
4327 case Tabular::ALIGN_CENTER:
4328 status.setEnabled(!tabular.isMultiRow(cur.idx()));
4329 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_CENTER);
4332 case Tabular::ALIGN_BLOCK:
4333 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4334 && !tabular.isMultiRow(cur.idx()));
4335 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_BLOCK);
4338 case Tabular::ALIGN_DECIMAL:
4339 status.setEnabled(!tabular.isMultiRow(cur.idx())
4340 && !tabular.isMultiColumn(cur.idx()));
4341 status.setOnOff(tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_DECIMAL);
4344 case Tabular::M_VALIGN_TOP:
4346 case Tabular::VALIGN_TOP:
4347 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4348 && !tabular.isMultiRow(cur.idx()));
4350 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_TOP);
4353 case Tabular::M_VALIGN_BOTTOM:
4355 case Tabular::VALIGN_BOTTOM:
4356 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4357 && !tabular.isMultiRow(cur.idx()));
4359 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_BOTTOM);
4362 case Tabular::M_VALIGN_MIDDLE:
4364 case Tabular::VALIGN_MIDDLE:
4365 status.setEnabled(!tabular.getPWidth(cur.idx()).zero()
4366 && !tabular.isMultiRow(cur.idx()));
4368 tabular.getVAlignment(cur.idx(), flag) == Tabular::LYX_VALIGN_MIDDLE);
4371 case Tabular::SET_LONGTABULAR:
4372 // setting as longtable is not allowed when table is inside a float
4373 if (cur.innerInsetOfType(FLOAT_CODE) != 0
4374 || cur.innerInsetOfType(WRAP_CODE) != 0)
4375 status.setEnabled(false);
4377 status.setEnabled(true);
4378 status.setOnOff(tabular.is_long_tabular);
4381 case Tabular::UNSET_LONGTABULAR:
4382 status.setOnOff(!tabular.is_long_tabular);
4385 case Tabular::TOGGLE_ROTATE_TABULAR:
4386 case Tabular::SET_ROTATE_TABULAR:
4387 status.setOnOff(tabular.rotate);
4390 case Tabular::TABULAR_VALIGN_TOP:
4391 status.setOnOff(tabular.tabular_valignment
4392 == Tabular::LYX_VALIGN_TOP);
4394 case Tabular::TABULAR_VALIGN_MIDDLE:
4395 status.setOnOff(tabular.tabular_valignment
4396 == Tabular::LYX_VALIGN_MIDDLE);
4398 case Tabular::TABULAR_VALIGN_BOTTOM:
4399 status.setOnOff(tabular.tabular_valignment
4400 == Tabular::LYX_VALIGN_BOTTOM);
4403 case Tabular::LONGTABULAR_ALIGN_LEFT:
4404 status.setOnOff(tabular.longtabular_alignment
4405 == Tabular::LYX_LONGTABULAR_ALIGN_LEFT);
4407 case Tabular::LONGTABULAR_ALIGN_CENTER:
4408 status.setOnOff(tabular.longtabular_alignment
4409 == Tabular::LYX_LONGTABULAR_ALIGN_CENTER);
4411 case Tabular::LONGTABULAR_ALIGN_RIGHT:
4412 status.setOnOff(tabular.longtabular_alignment
4413 == Tabular::LYX_LONGTABULAR_ALIGN_RIGHT);
4416 case Tabular::UNSET_ROTATE_TABULAR:
4417 status.setOnOff(!tabular.rotate);
4420 case Tabular::TOGGLE_ROTATE_CELL:
4421 case Tabular::SET_ROTATE_CELL:
4422 status.setOnOff(!oneCellHasRotationState(false,
4423 sel_row_start, sel_row_end, sel_col_start, sel_col_end));
4426 case Tabular::UNSET_ROTATE_CELL:
4427 status.setOnOff(!oneCellHasRotationState(true,
4428 sel_row_start, sel_row_end, sel_col_start, sel_col_end));
4431 case Tabular::SET_USEBOX:
4432 status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
4435 // every row can only be one thing:
4436 // either a footer or header or caption
4437 case Tabular::SET_LTFIRSTHEAD:
4438 status.setEnabled(sel_row_start == sel_row_end
4439 && !tabular.ltCaption(sel_row_start));
4440 status.setOnOff(tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
4443 case Tabular::UNSET_LTFIRSTHEAD:
4444 status.setOnOff(!tabular.getRowOfLTFirstHead(sel_row_start, dummyltt));
4447 case Tabular::SET_LTHEAD:
4448 status.setEnabled(sel_row_start == sel_row_end
4449 && !tabular.ltCaption(sel_row_start));
4450 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
4453 case Tabular::UNSET_LTHEAD:
4454 status.setOnOff(!tabular.getRowOfLTHead(sel_row_start, dummyltt));
4457 case Tabular::SET_LTFOOT:
4458 status.setEnabled(sel_row_start == sel_row_end
4459 && !tabular.ltCaption(sel_row_start));
4460 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
4463 case Tabular::UNSET_LTFOOT:
4464 status.setOnOff(!tabular.getRowOfLTFoot(sel_row_start, dummyltt));
4467 case Tabular::SET_LTLASTFOOT:
4468 status.setEnabled(sel_row_start == sel_row_end
4469 && !tabular.ltCaption(sel_row_start));
4470 status.setOnOff(tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
4473 case Tabular::UNSET_LTLASTFOOT:
4474 status.setOnOff(!tabular.getRowOfLTLastFoot(sel_row_start, dummyltt));
4477 case Tabular::SET_LTNEWPAGE:
4478 status.setOnOff(tabular.getLTNewPage(sel_row_start));
4481 // only one row can be the caption
4482 // and a multirow cannot be set as caption
4483 case Tabular::SET_LTCAPTION:
4484 case Tabular::UNSET_LTCAPTION:
4485 case Tabular::TOGGLE_LTCAPTION:
4486 status.setEnabled(sel_row_start == sel_row_end
4487 && !tabular.getRowOfLTFirstHead(sel_row_start, dummyltt)
4488 && !tabular.getRowOfLTHead(sel_row_start, dummyltt)
4489 && !tabular.getRowOfLTFoot(sel_row_start, dummyltt)
4490 && !tabular.getRowOfLTLastFoot(sel_row_start, dummyltt)
4491 && (!tabular.haveLTCaption()
4492 || tabular.ltCaption(sel_row_start))
4493 && !tabular.isMultiRow(sel_row_start));
4494 status.setOnOff(tabular.ltCaption(sel_row_start));
4497 case Tabular::SET_BOOKTABS:
4498 status.setOnOff(tabular.use_booktabs);
4501 case Tabular::UNSET_BOOKTABS:
4502 status.setOnOff(!tabular.use_booktabs);
4507 status.setEnabled(false);
4513 // These are only enabled inside tabular
4514 case LFUN_CELL_BACKWARD:
4515 case LFUN_CELL_FORWARD:
4516 status.setEnabled(true);
4519 // disable these with multiple cells selected
4520 case LFUN_INSET_INSERT:
4521 case LFUN_TABULAR_INSERT:
4522 case LFUN_FLEX_INSERT:
4523 case LFUN_FLOAT_INSERT:
4524 case LFUN_FLOAT_WIDE_INSERT:
4525 case LFUN_FOOTNOTE_INSERT:
4526 case LFUN_MARGINALNOTE_INSERT:
4527 case LFUN_MATH_INSERT:
4528 case LFUN_MATH_MODE:
4529 case LFUN_MATH_MUTATE:
4530 case LFUN_MATH_DISPLAY:
4531 case LFUN_NOTE_INSERT:
4532 case LFUN_ARGUMENT_INSERT:
4533 case LFUN_BOX_INSERT:
4534 case LFUN_BRANCH_INSERT:
4535 case LFUN_PHANTOM_INSERT:
4536 case LFUN_WRAP_INSERT:
4537 case LFUN_PREVIEW_INSERT:
4538 case LFUN_ERT_INSERT: {
4539 if (cur.selIsMultiCell()) {
4540 status.setEnabled(false);
4543 return cell(cur.idx())->getStatus(cur, cmd, status);
4546 // disable in non-fixed-width cells
4547 case LFUN_NEWLINE_INSERT:
4548 case LFUN_BREAK_PARAGRAPH: {
4549 if (tabular.getPWidth(cur.idx()).zero()) {
4550 status.setEnabled(false);
4553 return cell(cur.idx())->getStatus(cur, cmd, status);
4556 case LFUN_NEWPAGE_INSERT:
4557 status.setEnabled(false);
4561 if (tabularStackDirty() && theClipboard().isInternal()) {
4562 if (cur.selIsMultiCell()) {
4565 getSelection(cur, rs, re, cs, ce);
4566 if (paste_tabular && paste_tabular->ncols() == ce - cs + 1
4567 && paste_tabular->nrows() == re - rs + 1)
4568 status.setEnabled(true);
4570 status.setEnabled(false);
4571 status.message(_("Selection size should match clipboard content."));
4574 status.setEnabled(true);
4577 return cell(cur.idx())->getStatus(cur, cmd, status);
4579 case LFUN_INSET_SETTINGS:
4580 // relay this lfun to Inset, not to the cell.
4581 return Inset::getStatus(cur, cmd, status);
4584 // we try to handle this event in the insets dispatch function.
4585 return cell(cur.idx())->getStatus(cur, cmd, status);
4591 Inset::DisplayType InsetTabular::display() const
4593 if (tabular.is_long_tabular) {
4594 switch (tabular.longtabular_alignment) {
4595 case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
4597 case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
4599 case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
4609 int InsetTabular::latex(odocstream & os, OutputParams const & runparams) const
4611 return tabular.latex(os, runparams);
4615 int InsetTabular::plaintext(odocstream & os, OutputParams const & runparams) const
4617 os << '\n'; // output table on a new line
4618 int const dp = runparams.linelen > 0 ? runparams.depth : 0;
4619 tabular.plaintext(os, runparams, dp, false, 0);
4620 return PLAINTEXT_NEWLINE;
4624 int InsetTabular::docbook(odocstream & os, OutputParams const & runparams) const
4629 // FIXME: Why not pass a proper DocIterator here?
4631 // if the table is inside a float it doesn't need the informaltable
4632 // wrapper. Search for it.
4633 for (master = owner(); master; master = master->owner())
4634 if (master->lyxCode() == FLOAT_CODE)
4639 os << "<informaltable>";
4642 ret += tabular.docbook(os, runparams);
4644 os << "</informaltable>";
4651 docstring InsetTabular::xhtml(XHTMLStream & xs, OutputParams const & rp) const
4654 // It'd be better to be able to get this from an InsetLayout, but at present
4655 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
4656 xs << html::StartTag("table");
4657 docstring ret = tabular.xhtml(xs, rp);
4658 xs << html::EndTag("table");
4663 void InsetTabular::validate(LaTeXFeatures & features) const
4665 tabular.validate(features);
4667 // It'd be better to be able to get this from an InsetLayout, but at present
4668 // InsetLayouts do not seem really to work for things that aren't InsetTexts.
4669 if (features.runparams().flavor == OutputParams::HTML)
4670 features.addPreambleSnippet("<style type=\"text/css\">\n"
4671 "table { border: 1px solid black; display: inline-block; }\n"
4672 "td { border: 1px solid black; padding: 0.5ex; }\n"
4677 shared_ptr<InsetTableCell const> InsetTabular::cell(idx_type idx) const
4679 return tabular.cellInset(idx);
4683 shared_ptr<InsetTableCell> InsetTabular::cell(idx_type idx)
4685 return tabular.cellInset(idx);
4689 void InsetTabular::cursorPos(BufferView const & bv,
4690 CursorSlice const & sl, bool boundary, int & x, int & y) const
4692 cell(sl.idx())->cursorPos(bv, sl, boundary, x, y);
4694 int const row = tabular.cellRow(sl.idx());
4695 int const col = tabular.cellColumn(sl.idx());
4697 // y offset correction
4698 for (int r = 0; r < row; ++r)
4699 y += tabular.rowDescent(r) + tabular.rowAscent(r + 1)
4700 + tabular.interRowSpace(r + 1);
4702 y += tabular.textVOffset(sl.idx());
4704 // x offset correction
4705 for (int c = 0; c < col; ++c)
4706 x += tabular.column_info[c].width;
4708 x += tabular.textHOffset(sl.idx());
4709 x += ADD_TO_TABULAR_WIDTH;
4714 int InsetTabular::dist(BufferView & bv, idx_type const cell, int x, int y) const
4718 Inset const & inset = *tabular.cellInset(cell);
4719 Point o = bv.coordCache().getInsets().xy(&inset);
4720 int const xbeg = o.x_ - tabular.textHOffset(cell);
4721 int const xend = xbeg + tabular.cellWidth(cell);
4722 row_type const row = tabular.cellRow(cell);
4723 int const ybeg = o.y_ - tabular.rowAscent(row)
4724 - tabular.interRowSpace(row);
4725 int const yend = ybeg + tabular.cellHeight(cell);
4737 //lyxerr << " xbeg=" << xbeg << " xend=" << xend
4738 // << " ybeg=" << ybeg << " yend=" << yend
4739 // << " xx=" << xx << " yy=" << yy
4740 // << " dist=" << xx + yy << endl;
4745 Inset * InsetTabular::editXY(Cursor & cur, int x, int y)
4747 //lyxerr << "InsetTabular::editXY: " << this << endl;
4748 cur.setSelection(false);
4750 cur.idx() = getNearestCell(cur.bv(), x, y);
4752 return cur.bv().textMetrics(&cell(cur.idx())->text()).editXY(cur, x, y);
4756 void InsetTabular::setCursorFromCoordinates(Cursor & cur, int x, int y) const
4758 cur.idx() = getNearestCell(cur.bv(), x, y);
4759 cur.bv().textMetrics(&cell(cur.idx())->text()).setCursorFromCoordinates(cur, x, y);
4763 InsetTabular::idx_type InsetTabular::getNearestCell(BufferView & bv, int x, int y) const
4765 idx_type idx_min = 0;
4766 int dist_min = numeric_limits<int>::max();
4767 for (idx_type i = 0, n = nargs(); i != n; ++i) {
4768 if (bv.coordCache().getInsets().has(tabular.cellInset(i).get())) {
4769 int const d = dist(bv, i, x, y);
4780 int InsetTabular::cellXPos(idx_type const cell) const
4782 col_type col = tabular.cellColumn(cell);
4784 for (col_type c = 0; c < col; ++c)
4785 lx += tabular.column_info[c].width;
4791 void InsetTabular::resetPos(Cursor & cur) const
4793 BufferView & bv = cur.bv();
4794 int const maxwidth = bv.workWidth();
4796 int const scx_old = scx_;
4797 int const i = cur.find(this);
4802 int const X2 = maxwidth;
4803 int const offset = ADD_TO_TABULAR_WIDTH + 2;
4804 int const x1 = xo(cur.bv()) + cellXPos(cur[i].idx()) + offset;
4805 int const x2 = x1 + tabular.cellWidth(cur[i].idx());
4808 scx_ = X1 + 20 - x1;
4810 scx_ = X2 - 20 - x2;
4815 // only update if offset changed
4816 if (scx_ != scx_old)
4817 cur.screenUpdateFlags(Update::Force | Update::FitCursor);
4821 void InsetTabular::moveNextCell(Cursor & cur, EntryDirection entry_from)
4823 row_type const row = tabular.cellRow(cur.idx());
4824 col_type const col = tabular.cellColumn(cur.idx());
4826 if (isRightToLeft(cur)) {
4827 if (tabular.cellColumn(cur.idx()) == 0) {
4828 if (row == tabular.nrows() - 1)
4830 cur.idx() = tabular.cellBelow(tabular.getLastCellInRow(row));
4835 cur.idx() = tabular.getLastCellInRow(row - 1);
4837 cur.idx() = tabular.cellIndex(row, col - 1);
4840 if (tabular.isLastCell(cur.idx()))
4842 if (cur.idx() == tabular.getLastCellInRow(row))
4843 cur.idx() = tabular.cellIndex(row + 1, 0);
4845 col_type const colnextcell = col + tabular.columnSpan(cur.idx());
4846 cur.idx() = tabular.cellIndex(row, colnextcell);
4850 cur.boundary(false);
4852 if (cur.selIsMultiCell()) {
4853 cur.pit() = cur.lastpit();
4854 cur.pos() = cur.lastpos();
4862 // in visual mode, place cursor at extreme left or right
4864 switch(entry_from) {
4866 case ENTRY_DIRECTION_RIGHT:
4867 cur.posVisToRowExtremity(false /* !left */);
4869 case ENTRY_DIRECTION_LEFT:
4870 cur.posVisToRowExtremity(true /* left */);
4872 case ENTRY_DIRECTION_IGNORE:
4873 // nothing to do in this case
4877 cur.setCurrentFont();
4882 void InsetTabular::movePrevCell(Cursor & cur, EntryDirection entry_from)
4884 row_type const row = tabular.cellRow(cur.idx());
4885 col_type const col = tabular.cellColumn(cur.idx());
4887 if (isRightToLeft(cur)) {
4888 if (cur.idx() == tabular.getLastCellInRow(row)) {
4891 cur.idx() = tabular.getFirstCellInRow(row);
4892 cur.idx() = tabular.cellAbove(cur.idx());
4894 if (tabular.isLastCell(cur.idx()))
4896 if (cur.idx() == tabular.getLastCellInRow(row))
4897 cur.idx() = tabular.cellIndex(row + 1, 0);
4899 cur.idx() = tabular.cellIndex(row, col + 1);
4902 if (cur.idx() == 0) // first cell
4905 cur.idx() = tabular.getLastCellInRow(row - 1);
4907 cur.idx() = tabular.cellIndex(row, col - 1);
4910 if (cur.selIsMultiCell()) {
4911 cur.pit() = cur.lastpit();
4912 cur.pos() = cur.lastpos();
4917 cur.pit() = cur.lastpit();
4918 cur.pos() = cur.lastpos();
4920 // in visual mode, place cursor at extreme left or right
4922 switch(entry_from) {
4924 case ENTRY_DIRECTION_RIGHT:
4925 cur.posVisToRowExtremity(false /* !left */);
4927 case ENTRY_DIRECTION_LEFT:
4928 cur.posVisToRowExtremity(true /* left */);
4930 case ENTRY_DIRECTION_IGNORE:
4931 // nothing to do in this case
4935 cur.setCurrentFont();
4940 bool InsetTabular::tabularFeatures(Cursor & cur, string const & argument)
4942 istringstream is(argument);
4945 if (insetCode(s) != TABULAR_CODE)
4949 size_t safe_guard = 0;
4954 if (safe_guard > 1000) {
4955 LYXERR0("parameter max count reached!");
4959 Tabular::Feature action = Tabular::LAST_ACTION;
4962 for (; tabularFeature[i].action != Tabular::LAST_ACTION; ++i) {
4963 if (s != tabularFeature[i].feature)
4966 action = tabularFeature[i].action;
4969 if (action == Tabular::LAST_ACTION) {
4970 LYXERR0("Feature not found " << s);
4974 if (tabularFeature[i].need_value)
4976 LYXERR(Debug::DEBUG, "Feature: " << s << "\t\tvalue: " << val);
4977 tabularFeatures(cur, action, val);
4983 static void checkLongtableSpecial(Tabular::ltType & ltt,
4984 string const & special, bool & flag)
4986 if (special == "dl_above") {
4989 } else if (special == "dl_below") {
4990 ltt.bottomDL = flag;
4992 } else if (special == "empty") {
5002 bool InsetTabular::oneCellHasRotationState(bool rotated,
5003 row_type row_start, row_type row_end,
5004 col_type col_start, col_type col_end) const
5006 for (row_type r = row_start; r <= row_end; ++r)
5007 for (col_type c = col_start; c <= col_end; ++c)
5008 if (tabular.getRotateCell(tabular.cellIndex(r, c)) == rotated)
5014 void InsetTabular::tabularFeatures(Cursor & cur,
5015 Tabular::Feature feature, string const & value)
5017 col_type sel_col_start;
5018 col_type sel_col_end;
5019 row_type sel_row_start;
5020 row_type sel_row_end;
5021 bool setLines = false;
5022 LyXAlignment setAlign = LYX_ALIGN_LEFT;
5023 Tabular::VAlignment setVAlign = Tabular::LYX_VALIGN_TOP;
5027 case Tabular::M_ALIGN_LEFT:
5028 case Tabular::ALIGN_LEFT:
5029 setAlign = LYX_ALIGN_LEFT;
5032 case Tabular::M_ALIGN_RIGHT:
5033 case Tabular::ALIGN_RIGHT:
5034 setAlign = LYX_ALIGN_RIGHT;
5037 case Tabular::M_ALIGN_CENTER:
5038 case Tabular::ALIGN_CENTER:
5039 setAlign = LYX_ALIGN_CENTER;
5042 case Tabular::ALIGN_BLOCK:
5043 setAlign = LYX_ALIGN_BLOCK;
5046 case Tabular::ALIGN_DECIMAL:
5047 setAlign = LYX_ALIGN_DECIMAL;
5050 case Tabular::M_VALIGN_TOP:
5051 case Tabular::VALIGN_TOP:
5052 setVAlign = Tabular::LYX_VALIGN_TOP;
5055 case Tabular::M_VALIGN_BOTTOM:
5056 case Tabular::VALIGN_BOTTOM:
5057 setVAlign = Tabular::LYX_VALIGN_BOTTOM;
5060 case Tabular::M_VALIGN_MIDDLE:
5061 case Tabular::VALIGN_MIDDLE:
5062 setVAlign = Tabular::LYX_VALIGN_MIDDLE;
5069 cur.recordUndoInset(ATOMIC_UNDO);
5071 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
5072 row_type const row = tabular.cellRow(cur.idx());
5073 col_type const column = tabular.cellColumn(cur.idx());
5075 Tabular::ltType ltt;
5079 case Tabular::SET_PWIDTH: {
5080 Length const len(value);
5081 tabular.setColumnPWidth(cur, cur.idx(), len);
5083 && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
5084 tabularFeatures(cur, Tabular::ALIGN_CENTER, string());
5088 case Tabular::SET_MPWIDTH:
5089 tabular.setMColumnPWidth(cur, cur.idx(), Length(value));
5092 case Tabular::SET_MROFFSET:
5093 tabular.setMROffset(cur, cur.idx(), Length(value));
5096 case Tabular::SET_SPECIAL_COLUMN:
5097 case Tabular::SET_SPECIAL_MULTICOLUMN:
5098 if (value == "none")
5099 tabular.setAlignSpecial(cur.idx(), docstring(), feature);
5101 tabular.setAlignSpecial(cur.idx(), from_utf8(value), feature);
5104 case Tabular::APPEND_ROW:
5105 // append the row into the tabular
5106 tabular.appendRow(cur.idx());
5109 case Tabular::APPEND_COLUMN:
5110 // append the column into the tabular
5111 tabular.appendColumn(cur.idx());
5112 cur.idx() = tabular.cellIndex(row, column);
5115 case Tabular::DELETE_ROW:
5116 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5117 tabular.deleteRow(sel_row_start);
5118 if (sel_row_start >= tabular.nrows())
5120 cur.idx() = tabular.cellIndex(sel_row_start, column);
5123 cur.setSelection(false);
5126 case Tabular::DELETE_COLUMN:
5127 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5128 tabular.deleteColumn(sel_col_start);
5129 if (sel_col_start >= tabular.ncols())
5131 cur.idx() = tabular.cellIndex(row, sel_col_start);
5134 cur.setSelection(false);
5137 case Tabular::COPY_ROW:
5138 tabular.copyRow(row);
5141 case Tabular::COPY_COLUMN:
5142 tabular.copyColumn(column);
5143 cur.idx() = tabular.cellIndex(row, column);
5146 case Tabular::SET_LINE_TOP:
5147 case Tabular::TOGGLE_LINE_TOP: {
5148 bool lineSet = (feature == Tabular::SET_LINE_TOP)
5149 ? (value == "true") : !tabular.topLine(cur.idx());
5150 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5151 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5152 tabular.setTopLine(tabular.cellIndex(r, c), lineSet);
5156 case Tabular::SET_LINE_BOTTOM:
5157 case Tabular::TOGGLE_LINE_BOTTOM: {
5158 bool lineSet = (feature == Tabular::SET_LINE_BOTTOM)
5159 ? (value == "true") : !tabular.bottomLine(cur.idx());
5160 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5161 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5162 tabular.setBottomLine(tabular.cellIndex(r, c), lineSet);
5166 case Tabular::SET_LINE_LEFT:
5167 case Tabular::TOGGLE_LINE_LEFT: {
5168 bool lineSet = (feature == Tabular::SET_LINE_LEFT)
5169 ? (value == "true") : !tabular.leftLine(cur.idx());
5170 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5171 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5172 tabular.setLeftLine(tabular.cellIndex(r, c), lineSet);
5176 case Tabular::SET_LINE_RIGHT:
5177 case Tabular::TOGGLE_LINE_RIGHT: {
5178 bool lineSet = (feature == Tabular::SET_LINE_RIGHT)
5179 ? (value == "true") : !tabular.rightLine(cur.idx());
5180 for (row_type r = sel_row_start; r <= sel_row_end; ++r)
5181 for (col_type c = sel_col_start; c <= sel_col_end; ++c)
5182 tabular.setRightLine(tabular.cellIndex(r, c), lineSet);
5186 case Tabular::M_ALIGN_LEFT:
5187 case Tabular::M_ALIGN_RIGHT:
5188 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);
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";