3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "insettabular.h"
16 #include "bufferparams.h"
17 #include "BufferView.h"
20 #include "dispatchresult.h"
21 #include "funcrequest.h"
22 #include "FuncStatus.h"
28 #include "metricsinfo.h"
29 #include "outputparams.h"
30 #include "paragraph.h"
31 #include "paragraph_funcs.h"
32 #include "ParagraphParameters.h"
35 #include "frontends/Alert.h"
36 #include "frontends/font_metrics.h"
37 #include "frontends/LyXView.h"
38 #include "frontends/Painter.h"
43 using lyx::graphics::PreviewLoader;
45 using lyx::support::ltrim;
46 using lyx::support::strToInt;
47 using lyx::support::strToDbl;
53 using std::istringstream;
55 using std::ostringstream;
62 int const ADD_TO_HEIGHT = 2;
63 int const ADD_TO_TABULAR_WIDTH = 2;
66 boost::scoped_ptr<LyXTabular> paste_tabular;
69 struct TabularFeature {
70 LyXTabular::Feature action;
75 TabularFeature tabularFeature[] =
77 { LyXTabular::APPEND_ROW, "append-row" },
78 { LyXTabular::APPEND_COLUMN, "append-column" },
79 { LyXTabular::DELETE_ROW, "delete-row" },
80 { LyXTabular::DELETE_COLUMN, "delete-column" },
81 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
82 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
83 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
84 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
85 { LyXTabular::ALIGN_LEFT, "align-left" },
86 { LyXTabular::ALIGN_RIGHT, "align-right" },
87 { LyXTabular::ALIGN_CENTER, "align-center" },
88 { LyXTabular::ALIGN_BLOCK, "align-block" },
89 { LyXTabular::VALIGN_TOP, "valign-top" },
90 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
91 { LyXTabular::VALIGN_MIDDLE, "valign-middle" },
92 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
93 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
94 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
95 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
96 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
97 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
98 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
99 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
100 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
101 { LyXTabular::M_VALIGN_MIDDLE, "m-valign-middle" },
102 { LyXTabular::MULTICOLUMN, "multicolumn" },
103 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
104 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
105 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
106 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
107 { LyXTabular::SET_PWIDTH, "set-pwidth" },
108 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
109 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
110 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
111 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
112 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
113 { LyXTabular::SET_USEBOX, "set-usebox" },
114 { LyXTabular::SET_LTHEAD, "set-lthead" },
115 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
116 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
117 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
118 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
119 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
120 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
121 { LyXTabular::LAST_ACTION, "" }
125 class FeatureEqual : public std::unary_function<TabularFeature, bool> {
127 FeatureEqual(LyXTabular::Feature feature)
128 : feature_(feature) {}
129 bool operator()(TabularFeature const & tf) const {
130 return tf.action == feature_;
133 LyXTabular::Feature feature_;
139 string const featureAsString(LyXTabular::Feature feature)
141 TabularFeature * end = tabularFeature +
142 sizeof(tabularFeature) / sizeof(TabularFeature);
143 TabularFeature * it = std::find_if(tabularFeature, end,
144 FeatureEqual(feature));
145 return (it == end) ? string() : it->feature;
149 bool InsetTabular::hasPasteBuffer() const
151 return (paste_tabular.get() != 0);
155 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
156 : tabular(buf.params(), max(rows, 1), max(columns, 1)),
157 buffer_(&buf), cursorx_(0)
161 InsetTabular::InsetTabular(InsetTabular const & tab)
162 : UpdatableInset(tab), tabular(tab.tabular),
163 buffer_(tab.buffer_), cursorx_(0)
167 InsetTabular::~InsetTabular()
169 InsetTabularMailer(*this).hideDialog();
173 auto_ptr<InsetBase> InsetTabular::clone() const
175 return auto_ptr<InsetBase>(new InsetTabular(*this));
179 Buffer const & InsetTabular::buffer() const
185 void InsetTabular::buffer(Buffer const * b)
191 void InsetTabular::write(Buffer const & buf, ostream & os) const
193 os << "Tabular" << endl;
194 tabular.write(buf, os);
198 void InsetTabular::read(Buffer const & buf, LyXLex & lex)
200 bool const old_format = (lex.getString() == "\\LyXTable");
202 tabular.read(buf, lex);
208 string token = lex.getString();
209 while (lex.isOK() && (token != "\\end_inset")) {
211 token = lex.getString();
213 if (token != "\\end_inset") {
214 lex.printError("Missing \\end_inset at this point. "
220 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
222 //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
223 // mi.base.textwidth << "\n";
225 lyxerr << "InsetTabular::metrics: need bv" << endl;
229 for (int i = 0, cell = -1; i < tabular.rows(); ++i) {
232 for (int j = 0; j < tabular.columns(); ++j) {
233 if (tabular.isPartOfMultiColumn(i, j))
238 LyXLength p_width = tabular.column_info[j].p_width;
239 if (!p_width.zero()) {
240 m.base.textwidth = p_width.inPixels(mi.base.textwidth);
242 tabular.getCellInset(cell).metrics(m, dim);
243 maxAsc = max(maxAsc, dim.asc);
244 maxDesc = max(maxDesc, dim.des);
245 tabular.setWidthOfCell(cell, dim.wid);
247 tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
248 tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
251 dim.asc = tabular.getAscentOfRow(0);
252 dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
253 dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
258 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
260 //lyxerr << "InsetTabular::draw: " << x << " " << y << endl;
262 BufferView * bv = pi.base.bv;
263 setPosCache(pi, x, y);
266 x += ADD_TO_TABULAR_WIDTH;
269 first_visible_cell = -1;
270 for (int i = 0; i < tabular.rows(); ++i) {
272 idx = tabular.getCellNumber(i, 0);
273 if (y + tabular.getDescentOfRow(i) <= 0
274 && y - tabular.getAscentOfRow(i) < pi.pain.paperHeight()) {
275 y += tabular.getDescentOfRow(i)
276 + tabular.getAscentOfRow(i + 1)
277 + tabular.getAdditionalHeight(i + 1);
280 for (int j = 0; j < tabular.columns(); ++j) {
281 if (nx > bv->workWidth())
283 if (tabular.isPartOfMultiColumn(i, j))
285 if (first_visible_cell < 0)
286 first_visible_cell = idx;
287 if (bv->cursor().selection())
288 drawCellSelection(pi, nx, y, i, j, idx);
290 int const cx = nx + tabular.getBeginningOfTextInCell(idx);
291 cell(idx).draw(pi, cx, y);
292 drawCellLines(pi.pain, nx, y, i, idx);
293 nx += tabular.getWidthOfColumn(idx);
297 // Would be nice, but for some completely unfathomable reason,
298 // on a col resize to a new fixed width, even though the insettexts
299 // are resized, the cell isn't, but drawing all cells in a tall table
300 // has the desired effect somehow. Complete dark magic.
302 // avoiding drawing the rest of a long table is
303 // a pretty big speedup
304 if (y > bv->workHeight())
308 y += tabular.getDescentOfRow(i) +
309 tabular.getAscentOfRow(i + 1) +
310 tabular.getAdditionalHeight(i + 1);
315 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
316 int row, int cell) const
318 int x2 = x + tabular.getWidthOfColumn(cell);
321 if (!tabular.topAlreadyDrawn(cell)) {
322 on_off = !tabular.topLine(cell);
323 pain.line(x, y - tabular.getAscentOfRow(row),
324 x2, y - tabular.getAscentOfRow(row),
325 on_off ? LColor::tabularonoffline : LColor::tabularline,
326 on_off ? Painter::line_onoffdash : Painter::line_solid);
328 on_off = !tabular.bottomLine(cell);
329 pain.line(x, y + tabular.getDescentOfRow(row),
330 x2, y + tabular.getDescentOfRow(row),
331 on_off ? LColor::tabularonoffline : LColor::tabularline,
332 on_off ? Painter::line_onoffdash : Painter::line_solid);
333 if (!tabular.leftAlreadyDrawn(cell)) {
334 on_off = !tabular.leftLine(cell);
335 pain.line(x, y - tabular.getAscentOfRow(row),
336 x, y + tabular.getDescentOfRow(row),
337 on_off ? LColor::tabularonoffline : LColor::tabularline,
338 on_off ? Painter::line_onoffdash : Painter::line_solid);
340 on_off = !tabular.rightLine(cell);
341 pain.line(x2 - tabular.getAdditionalWidth(cell),
342 y - tabular.getAscentOfRow(row),
343 x2 - tabular.getAdditionalWidth(cell),
344 y + tabular.getDescentOfRow(row),
345 on_off ? LColor::tabularonoffline : LColor::tabularline,
346 on_off ? Painter::line_onoffdash : Painter::line_solid);
350 void InsetTabular::drawCellSelection(PainterInfo & pi, int x, int y,
351 int row, int column, int cell) const
353 LCursor & cur = pi.base.bv->cursor();
354 BOOST_ASSERT(cur.selection());
355 if (tablemode(cur)) {
357 getSelection(cur, rs, re, cs, ce);
358 if (column >= cs && column <= ce && row >= rs && row <= re) {
359 int w = tabular.getWidthOfColumn(cell);
360 int h = tabular.getAscentOfRow(row) + tabular.getDescentOfRow(row)-1;
361 pi.pain.fillRectangle(x, y - tabular.getAscentOfRow(row) + 1,
362 w, h, LColor::selection);
368 string const InsetTabular::editMessage() const
370 return _("Opened table");
374 void InsetTabular::edit(LCursor & cur, bool left)
376 lyxerr << "InsetTabular::edit: " << this << endl;
378 cur.selection() = false;
381 if (isRightToLeft(cur))
382 cur.idx() = tabular.getLastCellInRow(0);
388 if (isRightToLeft(cur))
389 cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1);
391 cur.idx() = tabular.getNumberOfCells() - 1;
393 cur.pos() = cur.lastpos(); // FIXME crude guess
395 // this accesses the position cache before it is initialized
397 //cur.bv().fitCursor();
401 InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) const
403 //lyxerr << "InsetTabular::editXY: " << this << endl;
404 cur.selection() = false;
405 cur.push(const_cast<InsetTabular&>(*this));
406 return setPos(cur, x, y);
407 //int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(cur.idx());
411 void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
413 lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
414 //lyxerr << " cur:\n" << cur << endl;
415 CursorSlice sl = cur.top();
416 LCursor & bvcur = cur.bv().cursor();
418 switch (cmd.action) {
420 case LFUN_MOUSE_PRESS:
421 lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
423 if (cmd.button() == mouse_button::button1) {
424 cur.selection() = false;
425 setPos(cur, cmd.x, cmd.y);
431 //if (cmd.button() == mouse_button::button2)
432 // dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
434 // we'll pop up the table dialog on release
435 if (cmd.button() == mouse_button::button3)
439 case LFUN_MOUSE_MOTION:
440 lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
441 if (cmd.button() == mouse_button::button1) {
442 // only accept motions to places not deeper nested than the real anchor
443 if (bvcur.anchor_.hasPart(cur)) {
444 setPos(cur, cmd.x, cmd.y);
445 bvcur.setCursor(cur);
446 bvcur.selection() = true;
451 case LFUN_MOUSE_RELEASE:
452 lyxerr << "# InsetTabular::MouseRelease\n" << bvcur << endl;
453 if (cmd.button() == mouse_button::button3)
454 InsetTabularMailer(*this).showDialog(&cur.bv());
457 case LFUN_CELL_BACKWARD:
459 cur.selection() = false;
462 case LFUN_CELL_FORWARD:
464 cur.selection() = false;
467 case LFUN_SCROLL_INSET:
468 if (cmd.argument.empty())
470 if (cmd.argument.find('.') != cmd.argument.npos)
471 scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
473 scroll(cur.bv(), strToInt(cmd.argument));
478 cell(cur.idx()).dispatch(cur, cmd);
479 cur.dispatched(); // override the cell's decision
481 isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
482 if (sl == cur.top()) {
483 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
490 cell(cur.idx()).dispatch(cur, cmd);
491 cur.dispatched(); // override the cell's decision
493 isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
494 if (sl == cur.top()) {
495 cmd = FuncRequest(LFUN_FINISHED_LEFT);
502 cell(cur.idx()).dispatch(cur, cmd);
503 cur.dispatched(); // override the cell's decision
505 if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) {
506 cur.idx() = tabular.getCellBelow(cur.idx());
511 if (sl == cur.top()) {
512 cmd = FuncRequest(LFUN_FINISHED_DOWN);
519 cell(cur.idx()).dispatch(cur, cmd);
520 cur.dispatched(); // override the cell's decision
522 if (tabular.row_of_cell(cur.idx()) != 0) {
523 cur.idx() = tabular.getCellAbove(cur.idx());
524 cur.par() = cur.lastpar();
525 cur.pos() = cur.lastpos();
528 if (sl == cur.top()) {
529 cmd = FuncRequest(LFUN_FINISHED_UP);
535 //if (hasSelection())
536 // cur.selection() = false;
537 int const col = tabular.column_of_cell(cur.idx());
538 int const t = cur.bv().top_y() + cur.bv().painter().paperHeight();
539 if (t < yo() + tabular.getHeightOfTabular()) {
540 cur.bv().scrollDocView(t);
541 cur.idx() = tabular.getCellBelow(first_visible_cell) + col;
543 cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + col;
552 //if (hasSelection())
553 // cur.selection() = false;
554 int const col = tabular.column_of_cell(cur.idx());
555 int const t = cur.bv().top_y() + cur.bv().painter().paperHeight();
557 cur.bv().scrollDocView(t);
561 cur.idx() = tabular.getCellBelow(first_visible_cell) + col;
565 cur.par() = cur.lastpar();
566 cur.pos() = cur.lastpos();
571 case LFUN_LAYOUT_TABULAR:
572 InsetTabularMailer(*this).showDialog(&cur.bv());
575 case LFUN_INSET_DIALOG_UPDATE:
576 InsetTabularMailer(*this).updateDialog(&cur.bv());
579 case LFUN_TABULAR_FEATURE:
580 if (!tabularFeatures(cur, cmd.argument))
584 // insert file functions
585 case LFUN_FILE_INSERT_ASCII_PARA:
586 case LFUN_FILE_INSERT_ASCII: {
587 string tmpstr = getContentsOfAsciiFile(&cur.bv(), cmd.argument, false);
588 if (!tmpstr.empty() && !insertAsciiString(cur.bv(), tmpstr, false))
594 if (copySelection(cur)) {
595 recordUndo(cur, Undo::DELETE);
602 recordUndo(cur, Undo::DELETE);
606 cell(cur.idx()).dispatch(cur, cmd);
610 if (!cur.selection())
616 case LFUN_PASTESELECTION: {
617 string const clip = cur.bv().getClipboard();
620 if (clip.find('\t') != string::npos) {
624 size_t len = clip.length();
625 for (size_t p = 0; p < len; ++p) {
626 p = clip.find_first_of("\t\n", p);
627 if (p == string::npos)
636 maxCols = max(cols, maxCols);
641 maxCols = max(cols, maxCols);
644 new LyXTabular(cur.buffer().params(), rows, maxCols));
646 string::size_type op = 0;
648 int cells = paste_tabular->getNumberOfCells();
651 for (size_t p = 0; cell < cells && p < len; ++p) {
652 p = clip.find_first_of("\t\n", p);
653 if (p == string::npos || p >= len)
657 paste_tabular->getCellInset(cell).
658 setText(clip.substr(op, p - op), font);
663 paste_tabular->getCellInset(cell).
664 setText(clip.substr(op, p - op), font);
665 while (cols++ < maxCols)
672 // check for the last cell if there is no trailing '\n'
673 if (cell < cells && op < len)
674 paste_tabular->getCellInset(cell).
675 setText(clip.substr(op, len - op), font);
676 } else if (!insertAsciiString(cur.bv(), clip, true)) {
677 // so that the clipboard is used and it goes on
679 // and executes LFUN_PASTESELECTION in insettext!
680 paste_tabular.reset();
686 if (hasPasteBuffer()) {
687 recordUndo(cur, Undo::INSERT);
691 cell(cur.idx()).dispatch(cur, cmd);
695 // we try to handle this event in the insets dispatch function.
696 cell(cur.idx()).dispatch(cur, cmd);
700 InsetTabularMailer(*this).updateDialog(&cur.bv());
704 // function sets an object as defined in func_status.h:
705 // states OK, Unknown, Disabled, On, Off.
706 bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd,
707 FuncStatus & status) const
709 switch (cmd.action) {
710 case LFUN_TABULAR_FEATURE: {
711 int action = LyXTabular::LAST_ACTION;
713 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
714 string const tmp = tabularFeature[i].feature;
715 if (tmp == cmd.argument.substr(0, tmp.length())) {
716 action = tabularFeature[i].action;
720 if (action == LyXTabular::LAST_ACTION) {
722 status.unknown(true);
726 string const argument
727 = ltrim(cmd.argument.substr(tabularFeature[i].feature.length()));
729 int sel_row_start = 0;
732 LyXTabular::ltType dummyltt;
735 getSelection(cur, sel_row_start, sel_row_end, dummy, dummy);
738 case LyXTabular::SET_PWIDTH:
739 case LyXTabular::SET_MPWIDTH:
740 case LyXTabular::SET_SPECIAL_COLUMN:
741 case LyXTabular::SET_SPECIAL_MULTI:
742 case LyXTabular::APPEND_ROW:
743 case LyXTabular::APPEND_COLUMN:
744 case LyXTabular::DELETE_ROW:
745 case LyXTabular::DELETE_COLUMN:
746 case LyXTabular::SET_ALL_LINES:
747 case LyXTabular::UNSET_ALL_LINES:
751 case LyXTabular::MULTICOLUMN:
752 status.setOnOff(tabular.isMultiColumn(cur.idx()));
755 case LyXTabular::M_TOGGLE_LINE_TOP:
757 case LyXTabular::TOGGLE_LINE_TOP:
758 status.setOnOff(tabular.topLine(cur.idx(), flag));
761 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
763 case LyXTabular::TOGGLE_LINE_BOTTOM:
764 status.setOnOff(tabular.bottomLine(cur.idx(), flag));
767 case LyXTabular::M_TOGGLE_LINE_LEFT:
769 case LyXTabular::TOGGLE_LINE_LEFT:
770 status.setOnOff(tabular.leftLine(cur.idx(), flag));
773 case LyXTabular::M_TOGGLE_LINE_RIGHT:
775 case LyXTabular::TOGGLE_LINE_RIGHT:
776 status.setOnOff(tabular.rightLine(cur.idx(), flag));
779 case LyXTabular::M_ALIGN_LEFT:
781 case LyXTabular::ALIGN_LEFT:
782 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_LEFT);
785 case LyXTabular::M_ALIGN_RIGHT:
787 case LyXTabular::ALIGN_RIGHT:
788 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_RIGHT);
791 case LyXTabular::M_ALIGN_CENTER:
793 case LyXTabular::ALIGN_CENTER:
794 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_CENTER);
797 case LyXTabular::ALIGN_BLOCK:
798 status.enabled(!tabular.getPWidth(cur.idx()).zero());
799 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_BLOCK);
802 case LyXTabular::M_VALIGN_TOP:
804 case LyXTabular::VALIGN_TOP:
806 tabular.getVAlignment(cur.idx(), flag) == LyXTabular::LYX_VALIGN_TOP);
809 case LyXTabular::M_VALIGN_BOTTOM:
811 case LyXTabular::VALIGN_BOTTOM:
813 tabular.getVAlignment(cur.idx(), flag) == LyXTabular::LYX_VALIGN_BOTTOM);
816 case LyXTabular::M_VALIGN_MIDDLE:
818 case LyXTabular::VALIGN_MIDDLE:
820 tabular.getVAlignment(cur.idx(), flag) == LyXTabular::LYX_VALIGN_MIDDLE);
823 case LyXTabular::SET_LONGTABULAR:
824 status.setOnOff(tabular.isLongTabular());
827 case LyXTabular::UNSET_LONGTABULAR:
828 status.setOnOff(!tabular.isLongTabular());
831 case LyXTabular::SET_ROTATE_TABULAR:
832 status.setOnOff(tabular.getRotateTabular());
835 case LyXTabular::UNSET_ROTATE_TABULAR:
836 status.setOnOff(!tabular.getRotateTabular());
839 case LyXTabular::SET_ROTATE_CELL:
840 status.setOnOff(tabular.getRotateCell(cur.idx()));
843 case LyXTabular::UNSET_ROTATE_CELL:
844 status.setOnOff(!tabular.getRotateCell(cur.idx()));
847 case LyXTabular::SET_USEBOX:
848 status.setOnOff(strToInt(argument) == tabular.getUsebox(cur.idx()));
851 case LyXTabular::SET_LTFIRSTHEAD:
852 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
855 case LyXTabular::SET_LTHEAD:
856 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
859 case LyXTabular::SET_LTFOOT:
860 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
863 case LyXTabular::SET_LTLASTFOOT:
864 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
867 case LyXTabular::SET_LTNEWPAGE:
868 status.setOnOff(tabular.getLTNewPage(sel_row_start));
873 status.enabled(false);
880 // we try to handle this event in the insets dispatch function.
881 return cell(cur.idx()).getStatus(cur, cmd, status);
886 int InsetTabular::latex(Buffer const & buf, ostream & os,
887 OutputParams const & runparams) const
889 return tabular.latex(buf, os, runparams);
893 int InsetTabular::plaintext(Buffer const & buf, ostream & os,
894 OutputParams const & runparams) const
896 int dp = runparams.linelen ? runparams.depth : 0;
897 return tabular.plaintext(buf, os, runparams, dp, false, 0);
901 int InsetTabular::linuxdoc(Buffer const & buf, ostream & os,
902 OutputParams const & runparams) const
904 return tabular.linuxdoc(buf,os, runparams);
908 int InsetTabular::docbook(Buffer const & buf, ostream & os,
909 OutputParams const & runparams) const
912 InsetOld * master = 0;
915 #warning Why not pass a proper DocIterator here?
918 // if the table is inside a float it doesn't need the informaltable
919 // wrapper. Search for it.
920 for (master = owner(); master; master = master->owner())
921 if (master->lyxCode() == InsetOld::FLOAT_CODE)
926 os << "<informaltable>";
929 ret += tabular.docbook(buf, os, runparams);
931 os << "</informaltable>";
938 void InsetTabular::validate(LaTeXFeatures & features) const
940 tabular.validate(features);
944 InsetText const & InsetTabular::cell(int idx) const
946 return tabular.getCellInset(idx);
950 InsetText & InsetTabular::cell(int idx)
952 return tabular.getCellInset(idx);
956 void InsetTabular::getCursorPos(LCursor const & cur, int & x, int & y) const
958 cell(cur.idx()).getCursorPos(cur, x, y);
962 InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const
964 lyxerr << "# InsetTabular::setPos() x=" << x << " y=" << y << endl;
966 int dist_min = 1000000;
967 for (idx_type i = 0; i < nargs(); ++i) {
968 int d = getText(i)->dist(x, y);
975 InsetBase * inset = cell(cur.idx()).text_.editXY(cur, x, y);
976 //lyxerr << "# InsetTabular::setPos()\n" << cur << endl;
981 int InsetTabular::getCellXPos(int cell) const
985 for (; !tabular.isFirstCellInRow(c); --c)
987 int lx = tabular.getWidthOfColumn(cell);
988 for (; c < cell; ++c)
989 lx += tabular.getWidthOfColumn(c);
991 return lx - tabular.getWidthOfColumn(cell) + xo();
995 void InsetTabular::resetPos(LCursor & cur) const
997 BufferView & bv = cur.bv();
998 int const actcol = tabular.column_of_cell(cur.idx());
999 int const offset = ADD_TO_TABULAR_WIDTH + 2;
1000 int const new_x = getCellXPos(cur.idx()) + offset;
1001 int const old_x = cursorx_;
1002 int const col_width = tabular.getWidthOfColumn(cur.idx());
1004 // cursor.x(getCellXPos(cur.idx()) + offset);
1005 if (actcol < tabular.columns() - 1 && scroll(false) &&
1006 tabular.getWidthOfTabular() < bv.workWidth()-20)
1009 } else if (cursorx_ - offset > 20 &&
1010 cursorx_ - offset + col_width > bv.workWidth() - 20) {
1011 scroll(bv, - col_width - 20);
1012 } else if (cursorx_ - offset < 20) {
1013 scroll(bv, 20 - cursorx_ + offset);
1014 } else if (scroll() && xo() > 20 &&
1015 xo() + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
1016 scroll(bv, old_x - cursorx_);
1019 InsetTabularMailer(*this).updateDialog(&bv);
1023 void InsetTabular::moveNextCell(LCursor & cur)
1025 lyxerr << "InsetTabular::moveNextCell 1 cur: " << cur.top() << endl;
1026 if (isRightToLeft(cur)) {
1027 lyxerr << "InsetTabular::moveNextCell A cur: " << endl;
1028 if (tabular.isFirstCellInRow(cur.idx())) {
1029 int row = tabular.row_of_cell(cur.idx());
1030 if (row == tabular.rows() - 1)
1032 cur.idx() = tabular.getCellBelow(tabular.getLastCellInRow(row));
1039 lyxerr << "InsetTabular::moveNextCell B cur: " << endl;
1040 if (tabular.isLastCell(cur.idx()))
1046 lyxerr << "InsetTabular::moveNextCell 2 cur: " << cur.top() << endl;
1051 void InsetTabular::movePrevCell(LCursor & cur)
1053 if (isRightToLeft(cur)) {
1054 if (tabular.isLastCellInRow(cur.idx())) {
1055 int row = tabular.row_of_cell(cur.idx());
1058 cur.idx() = tabular.getFirstCellInRow(row);
1059 cur.idx() = tabular.getCellAbove(cur.idx());
1061 if (tabular.isLastCell(cur.idx()))
1066 if (cur.idx() == 0) // first cell
1076 bool InsetTabular::tabularFeatures(LCursor & cur, string const & what)
1078 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1081 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1082 string const tmp = tabularFeature[i].feature;
1084 if (tmp == what.substr(0, tmp.length())) {
1085 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1086 //tabularFeatures[i].feature.length())) {
1087 action = tabularFeature[i].action;
1091 if (action == LyXTabular::LAST_ACTION)
1095 ltrim(what.substr(tabularFeature[i].feature.length()));
1096 tabularFeatures(cur, action, val);
1103 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1104 string const & special, bool & flag)
1106 if (special == "dl_above") {
1109 } else if (special == "dl_below") {
1110 ltt.bottomDL = flag;
1112 } else if (special == "empty") {
1124 void InsetTabular::tabularFeatures(LCursor & cur,
1125 LyXTabular::Feature feature, string const & value)
1127 BufferView & bv = cur.bv();
1132 bool setLines = false;
1133 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1134 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1138 case LyXTabular::M_ALIGN_LEFT:
1139 case LyXTabular::ALIGN_LEFT:
1140 setAlign = LYX_ALIGN_LEFT;
1143 case LyXTabular::M_ALIGN_RIGHT:
1144 case LyXTabular::ALIGN_RIGHT:
1145 setAlign = LYX_ALIGN_RIGHT;
1148 case LyXTabular::M_ALIGN_CENTER:
1149 case LyXTabular::ALIGN_CENTER:
1150 setAlign = LYX_ALIGN_CENTER;
1153 case LyXTabular::ALIGN_BLOCK:
1154 setAlign = LYX_ALIGN_BLOCK;
1157 case LyXTabular::M_VALIGN_TOP:
1158 case LyXTabular::VALIGN_TOP:
1159 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1162 case LyXTabular::M_VALIGN_BOTTOM:
1163 case LyXTabular::VALIGN_BOTTOM:
1164 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1167 case LyXTabular::M_VALIGN_MIDDLE:
1168 case LyXTabular::VALIGN_MIDDLE:
1169 setVAlign = LyXTabular::LYX_VALIGN_MIDDLE;
1176 recordUndo(cur, Undo::ATOMIC);
1178 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1179 int row = tabular.row_of_cell(cur.idx());
1180 int column = tabular.column_of_cell(cur.idx());
1182 LyXTabular::ltType ltt;
1186 case LyXTabular::SET_PWIDTH: {
1187 LyXLength const len(value);
1188 tabular.setColumnPWidth(cur.idx(), len);
1190 && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
1191 tabularFeatures(cur, LyXTabular::ALIGN_CENTER, string());
1192 else if (!len.zero()
1193 && tabular.getAlignment(cur.idx(), true) != LYX_ALIGN_BLOCK)
1194 tabularFeatures(cur, LyXTabular::ALIGN_BLOCK, string());
1198 case LyXTabular::SET_MPWIDTH:
1199 tabular.setMColumnPWidth(cur.idx(), LyXLength(value));
1202 case LyXTabular::SET_SPECIAL_COLUMN:
1203 case LyXTabular::SET_SPECIAL_MULTI:
1204 tabular.setAlignSpecial(cur.idx(),value,feature);
1207 case LyXTabular::APPEND_ROW:
1208 // append the row into the tabular
1209 tabular.appendRow(bv.buffer()->params(), cur.idx());
1212 case LyXTabular::APPEND_COLUMN:
1213 // append the column into the tabular
1214 tabular.appendColumn(bv.buffer()->params(), cur.idx());
1217 case LyXTabular::DELETE_ROW:
1218 for (int i = sel_row_start; i <= sel_row_end; ++i)
1219 tabular.deleteRow(sel_row_start);
1220 if (sel_row_start >= tabular.rows())
1222 cur.idx() = tabular.getCellNumber(sel_row_start, column);
1225 cur.selection() = false;
1228 case LyXTabular::DELETE_COLUMN:
1229 for (int i = sel_col_start; i <= sel_col_end; ++i)
1230 tabular.deleteColumn(sel_col_start);
1231 if (sel_col_start >= tabular.columns())
1233 cur.idx() = tabular.getCellNumber(row, sel_col_start);
1236 cur.selection() = false;
1239 case LyXTabular::M_TOGGLE_LINE_TOP:
1241 case LyXTabular::TOGGLE_LINE_TOP: {
1242 bool lineSet = !tabular.topLine(cur.idx(), flag);
1243 for (int i = sel_row_start; i <= sel_row_end; ++i)
1244 for (int j = sel_col_start; j <= sel_col_end; ++j)
1246 tabular.getCellNumber(i, j),
1251 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1253 case LyXTabular::TOGGLE_LINE_BOTTOM: {
1254 bool lineSet = !tabular.bottomLine(cur.idx(), flag);
1255 for (int i = sel_row_start; i <= sel_row_end; ++i)
1256 for (int j = sel_col_start; j <= sel_col_end; ++j)
1257 tabular.setBottomLine(
1258 tabular.getCellNumber(i, j),
1264 case LyXTabular::M_TOGGLE_LINE_LEFT:
1266 case LyXTabular::TOGGLE_LINE_LEFT: {
1267 bool lineSet = !tabular.leftLine(cur.idx(), flag);
1268 for (int i = sel_row_start; i <= sel_row_end; ++i)
1269 for (int j = sel_col_start; j <= sel_col_end; ++j)
1270 tabular.setLeftLine(
1271 tabular.getCellNumber(i,j),
1277 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1279 case LyXTabular::TOGGLE_LINE_RIGHT: {
1280 bool lineSet = !tabular.rightLine(cur.idx(), flag);
1281 for (int i = sel_row_start; i <= sel_row_end; ++i)
1282 for (int j = sel_col_start; j <= sel_col_end; ++j)
1283 tabular.setRightLine(
1284 tabular.getCellNumber(i,j),
1290 case LyXTabular::M_ALIGN_LEFT:
1291 case LyXTabular::M_ALIGN_RIGHT:
1292 case LyXTabular::M_ALIGN_CENTER:
1294 case LyXTabular::ALIGN_LEFT:
1295 case LyXTabular::ALIGN_RIGHT:
1296 case LyXTabular::ALIGN_CENTER:
1297 case LyXTabular::ALIGN_BLOCK:
1298 for (int i = sel_row_start; i <= sel_row_end; ++i)
1299 for (int j = sel_col_start; j <= sel_col_end; ++j)
1300 tabular.setAlignment(
1301 tabular.getCellNumber(i, j),
1306 case LyXTabular::M_VALIGN_TOP:
1307 case LyXTabular::M_VALIGN_BOTTOM:
1308 case LyXTabular::M_VALIGN_MIDDLE:
1310 case LyXTabular::VALIGN_TOP:
1311 case LyXTabular::VALIGN_BOTTOM:
1312 case LyXTabular::VALIGN_MIDDLE:
1313 for (int i = sel_row_start; i <= sel_row_end; ++i)
1314 for (int j = sel_col_start; j <= sel_col_end; ++j)
1315 tabular.setVAlignment(
1316 tabular.getCellNumber(i, j),
1320 case LyXTabular::MULTICOLUMN: {
1321 if (sel_row_start != sel_row_end) {
1322 #ifdef WITH_WARNINGS
1323 #warning Need I say it ? This is horrible.
1325 Alert::error(_("Error setting multicolumn"),
1326 _("You cannot set multicolumn vertically."));
1330 // just multicol for one Single Cell
1331 if (!hasSelection()) {
1332 // check whether we are completly in a multicol
1333 if (tabular.isMultiColumn(cur.idx()))
1334 tabular.unsetMultiColumn(cur.idx());
1336 tabular.setMultiColumn(bv.buffer(), cur.idx(), 1);
1339 // we have a selection so this means we just add all this
1340 // cells to form a multicolumn cell
1344 if (sel_cell_start > sel_cell_end) {
1345 s_start = sel_cell_end;
1346 s_end = sel_cell_start;
1348 s_start = sel_cell_start;
1349 s_end = sel_cell_end;
1351 tabular.setMultiColumn(bv.buffer(), s_start, s_end - s_start + 1);
1352 cur.idx() = s_start;
1356 cur.selection() = false;
1360 case LyXTabular::SET_ALL_LINES:
1362 case LyXTabular::UNSET_ALL_LINES:
1364 for (int i = sel_row_start; i <= sel_row_end; ++i)
1365 for (int j = sel_col_start; j <= sel_col_end; ++j)
1366 tabular.setAllLines(
1367 tabular.getCellNumber(i,j), setLines);
1371 case LyXTabular::SET_LONGTABULAR:
1372 tabular.setLongTabular(true);
1375 case LyXTabular::UNSET_LONGTABULAR:
1376 tabular.setLongTabular(false);
1379 case LyXTabular::SET_ROTATE_TABULAR:
1380 tabular.setRotateTabular(true);
1383 case LyXTabular::UNSET_ROTATE_TABULAR:
1384 tabular.setRotateTabular(false);
1387 case LyXTabular::SET_ROTATE_CELL:
1388 for (int i = sel_row_start; i <= sel_row_end; ++i)
1389 for (int j = sel_col_start; j <= sel_col_end; ++j)
1390 tabular.setRotateCell(
1391 tabular.getCellNumber(i, j), true);
1394 case LyXTabular::UNSET_ROTATE_CELL:
1395 for (int i = sel_row_start; i <= sel_row_end; ++i)
1396 for (int j = sel_col_start; j <= sel_col_end; ++j)
1397 tabular.setRotateCell(
1398 tabular.getCellNumber(i, j), false);
1401 case LyXTabular::SET_USEBOX: {
1402 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1403 if (val == tabular.getUsebox(cur.idx()))
1404 val = LyXTabular::BOX_NONE;
1405 for (int i = sel_row_start; i <= sel_row_end; ++i)
1406 for (int j = sel_col_start; j <= sel_col_end; ++j)
1407 tabular.setUsebox(tabular.getCellNumber(i, j), val);
1411 case LyXTabular::UNSET_LTFIRSTHEAD:
1413 case LyXTabular::SET_LTFIRSTHEAD:
1414 tabular.getRowOfLTFirstHead(row, ltt);
1415 checkLongtableSpecial(ltt, value, flag);
1416 tabular.setLTHead(row, flag, ltt, true);
1419 case LyXTabular::UNSET_LTHEAD:
1421 case LyXTabular::SET_LTHEAD:
1422 tabular.getRowOfLTHead(row, ltt);
1423 checkLongtableSpecial(ltt, value, flag);
1424 tabular.setLTHead(row, flag, ltt, false);
1427 case LyXTabular::UNSET_LTFOOT:
1429 case LyXTabular::SET_LTFOOT:
1430 tabular.getRowOfLTFoot(row, ltt);
1431 checkLongtableSpecial(ltt, value, flag);
1432 tabular.setLTFoot(row, flag, ltt, false);
1435 case LyXTabular::UNSET_LTLASTFOOT:
1437 case LyXTabular::SET_LTLASTFOOT:
1438 tabular.getRowOfLTLastFoot(row, ltt);
1439 checkLongtableSpecial(ltt, value, flag);
1440 tabular.setLTFoot(row, flag, ltt, true);
1443 case LyXTabular::SET_LTNEWPAGE:
1444 tabular.setLTNewPage(row, !tabular.getLTNewPage(row));
1447 // dummy stuff just to avoid warnings
1448 case LyXTabular::LAST_ACTION:
1452 InsetTabularMailer(*this).updateDialog(&bv);
1456 bool InsetTabular::showInsetDialog(BufferView * bv) const
1458 InsetTabularMailer(*this).showDialog(bv);
1463 void InsetTabular::openLayoutDialog(BufferView * bv) const
1465 InsetTabularMailer(*this).showDialog(bv);
1469 void InsetTabular::getLabelList(Buffer const & buffer,
1470 vector<string> & list) const
1472 tabular.getLabelList(buffer, list);
1476 bool InsetTabular::copySelection(LCursor & cur)
1478 if (!cur.selection())
1482 getSelection(cur, rs, re, cs, ce);
1484 paste_tabular.reset(new LyXTabular(tabular));
1486 for (int i = 0; i < rs; ++i)
1487 paste_tabular->deleteRow(0);
1489 int const rows = re - rs + 1;
1490 while (paste_tabular->rows() > rows)
1491 paste_tabular->deleteRow(rows);
1493 paste_tabular->setTopLine(0, true, true);
1494 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
1497 for (int i = 0; i < cs; ++i)
1498 paste_tabular->deleteColumn(0);
1500 int const columns = ce - cs + 1;
1501 while (paste_tabular->columns() > columns)
1502 paste_tabular->deleteColumn(columns);
1504 paste_tabular->setLeftLine(0, true, true);
1505 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
1509 OutputParams const runparams;
1510 paste_tabular->plaintext(cur.buffer(), os, runparams, 0, true, '\t');
1511 cur.bv().stuffClipboard(os.str());
1516 bool InsetTabular::pasteSelection(LCursor & cur)
1520 int actcol = tabular.column_of_cell(cur.idx());
1521 int actrow = tabular.row_of_cell(cur.idx());
1522 for (int r1 = 0, r2 = actrow;
1523 r1 < paste_tabular->rows() && r2 < tabular.rows();
1525 for (int c1 = 0, c2 = actcol;
1526 c1 < paste_tabular->columns() && c2 < tabular.columns();
1528 if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
1529 tabular.isPartOfMultiColumn(r2, c2))
1531 if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
1535 if (tabular.isPartOfMultiColumn(r2, c2)) {
1539 InsetText & inset = tabular.getCellInset(r2, c2);
1540 inset = paste_tabular->getCellInset(r1, c1);
1548 void InsetTabular::cutSelection(LCursor & cur)
1550 if (!cur.selection())
1553 bool const track = cur.buffer().params().tracking_changes;
1555 getSelection(cur, rs, re, cs, ce);
1556 for (int i = rs; i <= re; ++i)
1557 for (int j = cs; j <= ce; ++j)
1558 cell(tabular.getCellNumber(i, j)).clear(track);
1560 // cursor position might be invalid now
1561 cur.pos() = cur.lastpos();
1562 cur.clearSelection();
1566 bool InsetTabular::isRightToLeft(LCursor & cur) const
1568 BOOST_ASSERT(cur.size() > 1);
1569 Paragraph const & parentpar = cur[cur.size() - 2].paragraph();
1570 LCursor::pos_type const parentpos = cur[cur.size() - 2].pos();
1571 return parentpar.getFontSettings(cur.bv().buffer()->params(),
1572 parentpos).language()->RightToLeft();
1576 void InsetTabular::getSelection(LCursor & cur,
1577 int & rs, int & re, int & cs, int & ce) const
1579 CursorSlice const & beg = cur.selBegin();
1580 CursorSlice const & end = cur.selEnd();
1581 cs = tabular.column_of_cell(beg.idx());
1582 ce = tabular.column_of_cell(end.idx());
1585 cs = tabular.column_of_cell(end.idx());
1587 ce = tabular.right_column_of_cell(end.idx());
1590 rs = tabular.row_of_cell(beg.idx());
1591 re = tabular.row_of_cell(end.idx());
1597 size_t InsetTabular::nargs() const
1599 return tabular.getNumberOfCells();
1603 LyXText * InsetTabular::getText(int idx) const
1605 return size_t(idx) < nargs() ? cell(idx).getText(0) : 0;
1609 void InsetTabular::markErased()
1611 for (idx_type idx = 0; idx < nargs(); ++idx)
1612 cell(idx).markErased();
1616 bool InsetTabular::forceDefaultParagraphs(InsetBase const *) const
1619 const int cell = tabular.getCellFromInset(in);
1622 return tabular.getPWidth(cell).zero();
1624 // this is a workaround for a crash (New, Insert->Tabular,
1625 // Insert->FootNote)
1629 // well we didn't obviously find it so maybe our owner knows more
1630 BOOST_ASSERT(owner());
1631 return owner()->forceDefaultParagraphs(in);
1637 bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
1640 if (buf.length() <= 0)
1646 string::size_type len = buf.length();
1647 string::size_type p = 0;
1649 while (p < len && (p = buf.find_first_of("\t\n", p)) != string::npos) {
1657 maxCols = max(cols, maxCols);
1663 maxCols = max(cols, maxCols);
1664 LyXTabular * loctab;
1669 paste_tabular.reset(
1670 new LyXTabular(bv.buffer()->params(), rows, maxCols));
1671 loctab = paste_tabular.get();
1675 cell = bv.cursor().idx();
1676 ocol = tabular.column_of_cell(cell);
1677 row = tabular.row_of_cell(cell);
1680 string::size_type op = 0;
1681 int cells = loctab->getNumberOfCells();
1684 rows = loctab->rows();
1685 int const columns = loctab->columns();
1687 while (cell < cells && p < len && row < rows &&
1688 (p = buf.find_first_of("\t\n", p)) != string::npos)
1694 // we can only set this if we are not too far right
1695 if (cols < columns) {
1696 InsetText & inset = loctab->getCellInset(cell);
1697 Paragraph & par = inset.text_.getPar(0);
1698 LyXFont const font = inset.text_.getFont(par, 0);
1699 inset.setText(buf.substr(op, p - op), font);
1705 // we can only set this if we are not too far right
1706 if (cols < columns) {
1707 InsetText & inset = tabular.getCellInset(cell);
1708 Paragraph & par = inset.text_.getPar(0);
1709 LyXFont const font = inset.text_.getFont(par, 0);
1710 inset.setText(buf.substr(op, p - op), font);
1715 cell = loctab->getCellNumber(row, cols);
1721 // check for the last cell if there is no trailing '\n'
1722 if (cell < cells && op < len) {
1723 InsetText & inset = loctab->getCellInset(cell);
1724 Paragraph & par = inset.text_.getPar(0);
1725 LyXFont const font = inset.text_.getFont(par, 0);
1726 inset.setText(buf.substr(op, len - op), font);
1732 void InsetTabular::addPreview(PreviewLoader & loader) const
1734 int const rows = tabular.rows();
1735 int const columns = tabular.columns();
1736 for (int i = 0; i < rows; ++i) {
1737 for (int j = 0; j < columns; ++j)
1738 tabular.getCellInset(i, j).addPreview(loader);
1743 bool InsetTabular::tablemode(LCursor & cur) const
1745 return cur.selection() && cur.selBegin().idx() != cur.selEnd().idx();
1752 string const InsetTabularMailer::name_("tabular");
1754 InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)
1755 : inset_(const_cast<InsetTabular &>(inset))
1759 string const InsetTabularMailer::inset2string(Buffer const &) const
1761 return params2string(inset_);
1765 void InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
1767 istringstream data(in);
1769 lex.setStream(data);
1776 if (!lex || token != name_)
1777 return print_mailer_error("InsetTabularMailer", in, 1,
1780 // This is part of the inset proper that is usually swallowed
1781 // by Buffer::readInset
1783 if (!lex || token != "Tabular")
1784 return print_mailer_error("InsetTabularMailer", in, 2,
1787 Buffer const & buffer = inset.buffer();
1788 inset.read(buffer, lex);
1792 string const InsetTabularMailer::params2string(InsetTabular const & inset)
1795 data << name_ << ' ';
1796 inset.write(inset.buffer(), data);
1797 data << "\\end_inset\n";