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;
49 using boost::shared_ptr;
55 using std::istringstream;
57 using std::ostringstream;
64 int const ADD_TO_HEIGHT = 2;
65 int const ADD_TO_TABULAR_WIDTH = 2;
68 boost::scoped_ptr<LyXTabular> paste_tabular;
71 struct TabularFeature {
72 LyXTabular::Feature action;
77 TabularFeature tabularFeature[] =
79 { LyXTabular::APPEND_ROW, "append-row" },
80 { LyXTabular::APPEND_COLUMN, "append-column" },
81 { LyXTabular::DELETE_ROW, "delete-row" },
82 { LyXTabular::DELETE_COLUMN, "delete-column" },
83 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
84 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
85 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
86 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
87 { LyXTabular::ALIGN_LEFT, "align-left" },
88 { LyXTabular::ALIGN_RIGHT, "align-right" },
89 { LyXTabular::ALIGN_CENTER, "align-center" },
90 { LyXTabular::ALIGN_BLOCK, "align-block" },
91 { LyXTabular::VALIGN_TOP, "valign-top" },
92 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
93 { LyXTabular::VALIGN_MIDDLE, "valign-middle" },
94 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
95 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
96 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
97 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
98 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
99 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
100 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
101 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
102 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
103 { LyXTabular::M_VALIGN_MIDDLE, "m-valign-middle" },
104 { LyXTabular::MULTICOLUMN, "multicolumn" },
105 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
106 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
107 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
108 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
109 { LyXTabular::SET_PWIDTH, "set-pwidth" },
110 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
111 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
112 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
113 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
114 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
115 { LyXTabular::SET_USEBOX, "set-usebox" },
116 { LyXTabular::SET_LTHEAD, "set-lthead" },
117 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
118 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
119 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
120 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
121 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
122 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
123 { LyXTabular::LAST_ACTION, "" }
127 class FeatureEqual : public std::unary_function<TabularFeature, bool> {
129 FeatureEqual(LyXTabular::Feature feature)
130 : feature_(feature) {}
131 bool operator()(TabularFeature const & tf) const {
132 return tf.action == feature_;
135 LyXTabular::Feature feature_;
141 string const featureAsString(LyXTabular::Feature feature)
143 TabularFeature * end = tabularFeature +
144 sizeof(tabularFeature) / sizeof(TabularFeature);
145 TabularFeature * it = std::find_if(tabularFeature, end,
146 FeatureEqual(feature));
147 return (it == end) ? string() : it->feature;
151 bool InsetTabular::hasPasteBuffer() const
153 return (paste_tabular.get() != 0);
157 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
158 : tabular(buf.params(), max(rows, 1), max(columns, 1)),
159 buffer_(&buf), cursorx_(0)
163 InsetTabular::InsetTabular(InsetTabular const & tab)
164 : UpdatableInset(tab), tabular(tab.tabular),
165 buffer_(tab.buffer_), cursorx_(0)
169 InsetTabular::~InsetTabular()
171 InsetTabularMailer(*this).hideDialog();
175 auto_ptr<InsetBase> InsetTabular::doClone() const
177 return auto_ptr<InsetBase>(new InsetTabular(*this));
181 Buffer const & InsetTabular::buffer() const
187 void InsetTabular::buffer(Buffer const * b)
193 void InsetTabular::write(Buffer const & buf, ostream & os) const
195 os << "Tabular" << endl;
196 tabular.write(buf, os);
200 void InsetTabular::read(Buffer const & buf, LyXLex & lex)
202 bool const old_format = (lex.getString() == "\\LyXTable");
204 tabular.read(buf, lex);
210 string token = lex.getString();
211 while (lex.isOK() && (token != "\\end_inset")) {
213 token = lex.getString();
215 if (token != "\\end_inset") {
216 lex.printError("Missing \\end_inset at this point. "
222 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
224 //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
225 // mi.base.textwidth << "\n";
227 lyxerr << "InsetTabular::metrics: need bv" << endl;
231 for (int i = 0, cell = -1; i < tabular.rows(); ++i) {
234 for (int j = 0; j < tabular.columns(); ++j) {
235 if (tabular.isPartOfMultiColumn(i, j))
240 LyXLength p_width = tabular.column_info[j].p_width;
241 if (!p_width.zero()) {
242 m.base.textwidth = p_width.inPixels(mi.base.textwidth);
244 tabular.getCellInset(cell)->metrics(m, dim);
245 maxAsc = max(maxAsc, dim.asc);
246 maxDesc = max(maxDesc, dim.des);
247 tabular.setWidthOfCell(cell, dim.wid);
249 tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
250 tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
253 dim.asc = tabular.getAscentOfRow(0);
254 dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
255 dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
260 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
262 //lyxerr << "InsetTabular::draw: " << x << " " << y << endl;
264 BufferView * bv = pi.base.bv;
265 setPosCache(pi, x, y);
268 x += ADD_TO_TABULAR_WIDTH;
271 first_visible_cell = -1;
272 for (int i = 0; i < tabular.rows(); ++i) {
274 idx = tabular.getCellNumber(i, 0);
275 if (y + tabular.getDescentOfRow(i) <= 0
276 && y - tabular.getAscentOfRow(i) < pi.pain.paperHeight()) {
277 y += tabular.getDescentOfRow(i)
278 + tabular.getAscentOfRow(i + 1)
279 + tabular.getAdditionalHeight(i + 1);
282 for (int j = 0; j < tabular.columns(); ++j) {
283 if (nx > bv->workWidth())
285 if (tabular.isPartOfMultiColumn(i, j))
287 if (first_visible_cell < 0)
288 first_visible_cell = idx;
289 if (bv->cursor().selection())
290 drawCellSelection(pi, nx, y, i, j, idx);
292 int const cx = nx + tabular.getBeginningOfTextInCell(idx);
293 cell(idx)->draw(pi, cx, y);
294 drawCellLines(pi.pain, nx, y, i, idx);
295 nx += tabular.getWidthOfColumn(idx);
299 // Would be nice, but for some completely unfathomable reason,
300 // on a col resize to a new fixed width, even though the insettexts
301 // are resized, the cell isn't, but drawing all cells in a tall table
302 // has the desired effect somehow. Complete dark magic.
304 // avoiding drawing the rest of a long table is
305 // a pretty big speedup
306 if (y > bv->workHeight())
310 y += tabular.getDescentOfRow(i) +
311 tabular.getAscentOfRow(i + 1) +
312 tabular.getAdditionalHeight(i + 1);
317 void InsetTabular::drawCellLines(Painter & pain, int x, int y,
318 int row, int cell) const
320 int x2 = x + tabular.getWidthOfColumn(cell);
323 if (!tabular.topAlreadyDrawn(cell)) {
324 on_off = !tabular.topLine(cell);
325 pain.line(x, y - tabular.getAscentOfRow(row),
326 x2, y - tabular.getAscentOfRow(row),
327 on_off ? LColor::tabularonoffline : LColor::tabularline,
328 on_off ? Painter::line_onoffdash : Painter::line_solid);
330 on_off = !tabular.bottomLine(cell);
331 pain.line(x, y + tabular.getDescentOfRow(row),
332 x2, y + tabular.getDescentOfRow(row),
333 on_off ? LColor::tabularonoffline : LColor::tabularline,
334 on_off ? Painter::line_onoffdash : Painter::line_solid);
335 if (!tabular.leftAlreadyDrawn(cell)) {
336 on_off = !tabular.leftLine(cell);
337 pain.line(x, y - tabular.getAscentOfRow(row),
338 x, y + tabular.getDescentOfRow(row),
339 on_off ? LColor::tabularonoffline : LColor::tabularline,
340 on_off ? Painter::line_onoffdash : Painter::line_solid);
342 on_off = !tabular.rightLine(cell);
343 pain.line(x2 - tabular.getAdditionalWidth(cell),
344 y - tabular.getAscentOfRow(row),
345 x2 - tabular.getAdditionalWidth(cell),
346 y + tabular.getDescentOfRow(row),
347 on_off ? LColor::tabularonoffline : LColor::tabularline,
348 on_off ? Painter::line_onoffdash : Painter::line_solid);
352 void InsetTabular::drawCellSelection(PainterInfo & pi, int x, int y,
353 int row, int column, int cell) const
355 LCursor & cur = pi.base.bv->cursor();
356 BOOST_ASSERT(cur.selection());
357 if (tablemode(cur)) {
359 getSelection(cur, rs, re, cs, ce);
360 if (column >= cs && column <= ce && row >= rs && row <= re) {
361 int w = tabular.getWidthOfColumn(cell);
362 int h = tabular.getAscentOfRow(row) + tabular.getDescentOfRow(row)-1;
363 pi.pain.fillRectangle(x, y - tabular.getAscentOfRow(row) + 1,
364 w, h, LColor::selection);
370 string const InsetTabular::editMessage() const
372 return _("Opened table");
376 void InsetTabular::edit(LCursor & cur, bool left)
378 lyxerr << "InsetTabular::edit: " << this << endl;
380 cur.selection() = false;
383 if (isRightToLeft(cur))
384 cur.idx() = tabular.getLastCellInRow(0);
390 if (isRightToLeft(cur))
391 cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1);
393 cur.idx() = tabular.getNumberOfCells() - 1;
395 cur.pos() = cur.lastpos(); // FIXME crude guess
397 // this accesses the position cache before it is initialized
399 //cur.bv().fitCursor();
403 InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y) const
405 //lyxerr << "InsetTabular::editXY: " << this << endl;
406 cur.selection() = false;
407 cur.push(const_cast<InsetTabular&>(*this));
408 return setPos(cur, x, y);
409 //int xx = cursorx_ - xo() + tabular.getBeginningOfTextInCell(cur.idx());
413 void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
415 lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
416 //lyxerr << " cur:\n" << cur << endl;
417 CursorSlice sl = cur.top();
418 LCursor & bvcur = cur.bv().cursor();
420 switch (cmd.action) {
422 case LFUN_MOUSE_PRESS:
423 lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
425 if (cmd.button() == mouse_button::button1) {
426 cur.selection() = false;
427 setPos(cur, cmd.x, cmd.y);
433 //if (cmd.button() == mouse_button::button2)
434 // dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
436 // we'll pop up the table dialog on release
437 if (cmd.button() == mouse_button::button3)
441 case LFUN_MOUSE_MOTION:
442 lyxerr << "# InsetTabular::MouseMotion\n" << bvcur << endl;
443 if (cmd.button() == mouse_button::button1) {
444 // only accept motions to places not deeper nested than the real anchor
445 if (bvcur.anchor_.hasPart(cur)) {
446 setPos(cur, cmd.x, cmd.y);
447 bvcur.setCursor(cur);
448 bvcur.selection() = true;
453 case LFUN_MOUSE_RELEASE:
454 lyxerr << "# InsetTabular::MouseRelease\n" << bvcur << endl;
455 if (cmd.button() == mouse_button::button3)
456 InsetTabularMailer(*this).showDialog(&cur.bv());
459 case LFUN_CELL_BACKWARD:
461 cur.selection() = false;
464 case LFUN_CELL_FORWARD:
466 cur.selection() = false;
469 case LFUN_SCROLL_INSET:
470 if (cmd.argument.empty())
472 if (cmd.argument.find('.') != cmd.argument.npos)
473 scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
475 scroll(cur.bv(), strToInt(cmd.argument));
480 cell(cur.idx())->dispatch(cur, cmd);
481 cur.dispatched(); // override the cell's decision
483 isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
484 if (sl == cur.top()) {
485 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
492 cell(cur.idx())->dispatch(cur, cmd);
493 cur.dispatched(); // override the cell's decision
495 isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
496 if (sl == cur.top()) {
497 cmd = FuncRequest(LFUN_FINISHED_LEFT);
504 cell(cur.idx())->dispatch(cur, cmd);
505 cur.dispatched(); // override the cell's decision
507 if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) {
508 cur.idx() = tabular.getCellBelow(cur.idx());
513 if (sl == cur.top()) {
514 cmd = FuncRequest(LFUN_FINISHED_DOWN);
521 cell(cur.idx())->dispatch(cur, cmd);
522 cur.dispatched(); // override the cell's decision
524 if (tabular.row_of_cell(cur.idx()) != 0) {
525 cur.idx() = tabular.getCellAbove(cur.idx());
526 cur.pit() = cur.lastpit();
527 cur.pos() = cur.lastpos();
530 if (sl == cur.top()) {
531 cmd = FuncRequest(LFUN_FINISHED_UP);
537 //if (hasSelection())
538 // cur.selection() = false;
539 int const col = tabular.column_of_cell(cur.idx());
540 int const t = cur.bv().top_y() + cur.bv().painter().paperHeight();
541 if (t < yo() + tabular.getHeightOfTabular()) {
542 cur.bv().scrollDocView(t);
543 cur.idx() = tabular.getCellBelow(first_visible_cell) + col;
545 cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + col;
554 //if (hasSelection())
555 // cur.selection() = false;
556 int const col = tabular.column_of_cell(cur.idx());
557 int const t = cur.bv().top_y() + cur.bv().painter().paperHeight();
559 cur.bv().scrollDocView(t);
563 cur.idx() = tabular.getCellBelow(first_visible_cell) + col;
567 cur.pit() = cur.lastpit();
568 cur.pos() = cur.lastpos();
573 case LFUN_LAYOUT_TABULAR:
574 InsetTabularMailer(*this).showDialog(&cur.bv());
577 case LFUN_INSET_DIALOG_UPDATE:
578 InsetTabularMailer(*this).updateDialog(&cur.bv());
581 case LFUN_TABULAR_FEATURE:
582 if (!tabularFeatures(cur, cmd.argument))
586 // insert file functions
587 case LFUN_FILE_INSERT_ASCII_PARA:
588 case LFUN_FILE_INSERT_ASCII: {
589 string const tmpstr = getContentsOfAsciiFile(&cur.bv(), cmd.argument, false);
590 if (!tmpstr.empty() && !insertAsciiString(cur.bv(), tmpstr, false))
596 if (copySelection(cur)) {
597 recordUndo(cur, Undo::DELETE);
604 recordUndo(cur, Undo::DELETE);
608 cell(cur.idx())->dispatch(cur, cmd);
612 if (!cur.selection())
618 case LFUN_PASTESELECTION: {
619 string const clip = cur.bv().getClipboard();
622 if (clip.find('\t') != string::npos) {
626 size_t len = clip.length();
627 for (size_t p = 0; p < len; ++p) {
628 p = clip.find_first_of("\t\n", p);
629 if (p == string::npos)
638 maxCols = max(cols, maxCols);
643 maxCols = max(cols, maxCols);
646 new LyXTabular(cur.buffer().params(), rows, maxCols));
648 string::size_type op = 0;
650 int const cells = paste_tabular->getNumberOfCells();
653 for (size_t p = 0; cell < cells && p < len; ++p) {
654 p = clip.find_first_of("\t\n", p);
655 if (p == string::npos || p >= len)
659 paste_tabular->getCellInset(cell)->
660 setText(clip.substr(op, p - op), font);
665 paste_tabular->getCellInset(cell)->
666 setText(clip.substr(op, p - op), font);
667 while (cols++ < maxCols)
674 // check for the last cell if there is no trailing '\n'
675 if (cell < cells && op < len)
676 paste_tabular->getCellInset(cell)->
677 setText(clip.substr(op, len - op), font);
678 } else if (!insertAsciiString(cur.bv(), clip, true)) {
679 // so that the clipboard is used and it goes on
681 // and executes LFUN_PASTESELECTION in insettext!
682 paste_tabular.reset();
688 if (hasPasteBuffer()) {
689 recordUndo(cur, Undo::INSERT);
693 cell(cur.idx())->dispatch(cur, cmd);
697 // we try to handle this event in the insets dispatch function.
698 cell(cur.idx())->dispatch(cur, cmd);
702 InsetTabularMailer(*this).updateDialog(&cur.bv());
706 // function sets an object as defined in func_status.h:
707 // states OK, Unknown, Disabled, On, Off.
708 bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd,
709 FuncStatus & status) const
711 switch (cmd.action) {
712 case LFUN_TABULAR_FEATURE: {
713 int action = LyXTabular::LAST_ACTION;
715 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
716 string const tmp = tabularFeature[i].feature;
717 if (tmp == cmd.argument.substr(0, tmp.length())) {
718 action = tabularFeature[i].action;
722 if (action == LyXTabular::LAST_ACTION) {
724 status.unknown(true);
728 string const argument
729 = ltrim(cmd.argument.substr(tabularFeature[i].feature.length()));
731 int sel_row_start = 0;
734 LyXTabular::ltType dummyltt;
737 getSelection(cur, sel_row_start, sel_row_end, dummy, dummy);
740 case LyXTabular::SET_PWIDTH:
741 case LyXTabular::SET_MPWIDTH:
742 case LyXTabular::SET_SPECIAL_COLUMN:
743 case LyXTabular::SET_SPECIAL_MULTI:
744 case LyXTabular::APPEND_ROW:
745 case LyXTabular::APPEND_COLUMN:
746 case LyXTabular::DELETE_ROW:
747 case LyXTabular::DELETE_COLUMN:
748 case LyXTabular::SET_ALL_LINES:
749 case LyXTabular::UNSET_ALL_LINES:
753 case LyXTabular::MULTICOLUMN:
754 status.setOnOff(tabular.isMultiColumn(cur.idx()));
757 case LyXTabular::M_TOGGLE_LINE_TOP:
759 case LyXTabular::TOGGLE_LINE_TOP:
760 status.setOnOff(tabular.topLine(cur.idx(), flag));
763 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
765 case LyXTabular::TOGGLE_LINE_BOTTOM:
766 status.setOnOff(tabular.bottomLine(cur.idx(), flag));
769 case LyXTabular::M_TOGGLE_LINE_LEFT:
771 case LyXTabular::TOGGLE_LINE_LEFT:
772 status.setOnOff(tabular.leftLine(cur.idx(), flag));
775 case LyXTabular::M_TOGGLE_LINE_RIGHT:
777 case LyXTabular::TOGGLE_LINE_RIGHT:
778 status.setOnOff(tabular.rightLine(cur.idx(), flag));
781 case LyXTabular::M_ALIGN_LEFT:
783 case LyXTabular::ALIGN_LEFT:
784 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_LEFT);
787 case LyXTabular::M_ALIGN_RIGHT:
789 case LyXTabular::ALIGN_RIGHT:
790 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_RIGHT);
793 case LyXTabular::M_ALIGN_CENTER:
795 case LyXTabular::ALIGN_CENTER:
796 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_CENTER);
799 case LyXTabular::ALIGN_BLOCK:
800 status.enabled(!tabular.getPWidth(cur.idx()).zero());
801 status.setOnOff(tabular.getAlignment(cur.idx(), flag) == LYX_ALIGN_BLOCK);
804 case LyXTabular::M_VALIGN_TOP:
806 case LyXTabular::VALIGN_TOP:
808 tabular.getVAlignment(cur.idx(), flag) == LyXTabular::LYX_VALIGN_TOP);
811 case LyXTabular::M_VALIGN_BOTTOM:
813 case LyXTabular::VALIGN_BOTTOM:
815 tabular.getVAlignment(cur.idx(), flag) == LyXTabular::LYX_VALIGN_BOTTOM);
818 case LyXTabular::M_VALIGN_MIDDLE:
820 case LyXTabular::VALIGN_MIDDLE:
822 tabular.getVAlignment(cur.idx(), flag) == LyXTabular::LYX_VALIGN_MIDDLE);
825 case LyXTabular::SET_LONGTABULAR:
826 status.setOnOff(tabular.isLongTabular());
829 case LyXTabular::UNSET_LONGTABULAR:
830 status.setOnOff(!tabular.isLongTabular());
833 case LyXTabular::SET_ROTATE_TABULAR:
834 status.setOnOff(tabular.getRotateTabular());
837 case LyXTabular::UNSET_ROTATE_TABULAR:
838 status.setOnOff(!tabular.getRotateTabular());
841 case LyXTabular::SET_ROTATE_CELL:
842 status.setOnOff(tabular.getRotateCell(cur.idx()));
845 case LyXTabular::UNSET_ROTATE_CELL:
846 status.setOnOff(!tabular.getRotateCell(cur.idx()));
849 case LyXTabular::SET_USEBOX:
850 status.setOnOff(strToInt(argument) == tabular.getUsebox(cur.idx()));
853 case LyXTabular::SET_LTFIRSTHEAD:
854 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
857 case LyXTabular::SET_LTHEAD:
858 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
861 case LyXTabular::SET_LTFOOT:
862 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
865 case LyXTabular::SET_LTLASTFOOT:
866 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
869 case LyXTabular::SET_LTNEWPAGE:
870 status.setOnOff(tabular.getLTNewPage(sel_row_start));
875 status.enabled(false);
882 // we try to handle this event in the insets dispatch function.
883 return cell(cur.idx())->getStatus(cur, cmd, status);
888 int InsetTabular::latex(Buffer const & buf, ostream & os,
889 OutputParams const & runparams) const
891 return tabular.latex(buf, os, runparams);
895 int InsetTabular::plaintext(Buffer const & buf, ostream & os,
896 OutputParams const & runparams) const
898 int const dp = runparams.linelen ? runparams.depth : 0;
899 return tabular.plaintext(buf, os, runparams, dp, false, 0);
903 int InsetTabular::linuxdoc(Buffer const & buf, ostream & os,
904 OutputParams const & runparams) const
906 return tabular.linuxdoc(buf,os, runparams);
910 int InsetTabular::docbook(Buffer const & buf, ostream & os,
911 OutputParams const & runparams) const
914 InsetBase * master = 0;
917 #warning Why not pass a proper DocIterator here?
920 // if the table is inside a float it doesn't need the informaltable
921 // wrapper. Search for it.
922 for (master = owner(); master; master = master->owner())
923 if (master->lyxCode() == InsetBase::FLOAT_CODE)
928 os << "<informaltable>";
931 ret += tabular.docbook(buf, os, runparams);
933 os << "</informaltable>";
940 void InsetTabular::validate(LaTeXFeatures & features) const
942 tabular.validate(features);
946 shared_ptr<InsetText const> InsetTabular::cell(int idx) const
948 return tabular.getCellInset(idx);
952 shared_ptr<InsetText> InsetTabular::cell(int idx)
954 return tabular.getCellInset(idx);
958 void InsetTabular::getCursorPos(LCursor const & cur, int & x, int & y) const
960 cell(cur.idx())->getCursorPos(cur, x, y);
964 InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const
966 lyxerr << "# InsetTabular::setPos() x=" << x << " y=" << y << endl;
968 int dist_min = 1000000;
969 for (idx_type i = 0; i < nargs(); ++i) {
970 int d = getText(i)->dist(x, y);
977 InsetBase * inset = cell(cur.idx())->text_.editXY(cur, x, y);
978 //lyxerr << "# InsetTabular::setPos()\n" << cur << endl;
983 int InsetTabular::getCellXPos(int const cell) const
987 for (; !tabular.isFirstCellInRow(c); --c)
989 int lx = tabular.getWidthOfColumn(cell);
990 for (; c < cell; ++c)
991 lx += tabular.getWidthOfColumn(c);
993 return lx - tabular.getWidthOfColumn(cell) + xo();
997 void InsetTabular::resetPos(LCursor & cur) const
999 BufferView & bv = cur.bv();
1000 int const actcol = tabular.column_of_cell(cur.idx());
1001 int const offset = ADD_TO_TABULAR_WIDTH + 2;
1002 int const new_x = getCellXPos(cur.idx()) + offset;
1003 int const old_x = cursorx_;
1004 int const col_width = tabular.getWidthOfColumn(cur.idx());
1006 // cursor.x(getCellXPos(cur.idx()) + offset);
1007 if (actcol < tabular.columns() - 1 && scroll(false) &&
1008 tabular.getWidthOfTabular() < bv.workWidth()-20)
1011 } else if (cursorx_ - offset > 20 &&
1012 cursorx_ - offset + col_width > bv.workWidth() - 20) {
1013 scroll(bv, - col_width - 20);
1014 } else if (cursorx_ - offset < 20) {
1015 scroll(bv, 20 - cursorx_ + offset);
1016 } else if (scroll() && xo() > 20 &&
1017 xo() + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
1018 scroll(bv, old_x - cursorx_);
1021 InsetTabularMailer(*this).updateDialog(&bv);
1025 void InsetTabular::moveNextCell(LCursor & cur)
1027 lyxerr << "InsetTabular::moveNextCell 1 cur: " << cur.top() << endl;
1028 if (isRightToLeft(cur)) {
1029 lyxerr << "InsetTabular::moveNextCell A cur: " << endl;
1030 if (tabular.isFirstCellInRow(cur.idx())) {
1031 int const row = tabular.row_of_cell(cur.idx());
1032 if (row == tabular.rows() - 1)
1034 cur.idx() = tabular.getCellBelow(tabular.getLastCellInRow(row));
1041 lyxerr << "InsetTabular::moveNextCell B cur: " << endl;
1042 if (tabular.isLastCell(cur.idx()))
1048 lyxerr << "InsetTabular::moveNextCell 2 cur: " << cur.top() << endl;
1053 void InsetTabular::movePrevCell(LCursor & cur)
1055 if (isRightToLeft(cur)) {
1056 if (tabular.isLastCellInRow(cur.idx())) {
1057 int const row = tabular.row_of_cell(cur.idx());
1060 cur.idx() = tabular.getFirstCellInRow(row);
1061 cur.idx() = tabular.getCellAbove(cur.idx());
1063 if (tabular.isLastCell(cur.idx()))
1068 if (cur.idx() == 0) // first cell
1078 bool InsetTabular::tabularFeatures(LCursor & cur, string const & what)
1080 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1083 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1084 string const tmp = tabularFeature[i].feature;
1086 if (tmp == what.substr(0, tmp.length())) {
1087 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1088 //tabularFeatures[i].feature.length())) {
1089 action = tabularFeature[i].action;
1093 if (action == LyXTabular::LAST_ACTION)
1097 ltrim(what.substr(tabularFeature[i].feature.length()));
1098 tabularFeatures(cur, action, val);
1105 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1106 string const & special, bool & flag)
1108 if (special == "dl_above") {
1111 } else if (special == "dl_below") {
1112 ltt.bottomDL = flag;
1114 } else if (special == "empty") {
1126 void InsetTabular::tabularFeatures(LCursor & cur,
1127 LyXTabular::Feature feature, string const & value)
1129 BufferView & bv = cur.bv();
1134 bool setLines = false;
1135 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1136 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1140 case LyXTabular::M_ALIGN_LEFT:
1141 case LyXTabular::ALIGN_LEFT:
1142 setAlign = LYX_ALIGN_LEFT;
1145 case LyXTabular::M_ALIGN_RIGHT:
1146 case LyXTabular::ALIGN_RIGHT:
1147 setAlign = LYX_ALIGN_RIGHT;
1150 case LyXTabular::M_ALIGN_CENTER:
1151 case LyXTabular::ALIGN_CENTER:
1152 setAlign = LYX_ALIGN_CENTER;
1155 case LyXTabular::ALIGN_BLOCK:
1156 setAlign = LYX_ALIGN_BLOCK;
1159 case LyXTabular::M_VALIGN_TOP:
1160 case LyXTabular::VALIGN_TOP:
1161 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1164 case LyXTabular::M_VALIGN_BOTTOM:
1165 case LyXTabular::VALIGN_BOTTOM:
1166 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1169 case LyXTabular::M_VALIGN_MIDDLE:
1170 case LyXTabular::VALIGN_MIDDLE:
1171 setVAlign = LyXTabular::LYX_VALIGN_MIDDLE;
1178 recordUndo(cur, Undo::ATOMIC);
1180 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1181 int const row = tabular.row_of_cell(cur.idx());
1182 int const column = tabular.column_of_cell(cur.idx());
1184 LyXTabular::ltType ltt;
1188 case LyXTabular::SET_PWIDTH: {
1189 LyXLength const len(value);
1190 tabular.setColumnPWidth(cur.idx(), len);
1192 && tabular.getAlignment(cur.idx(), true) == LYX_ALIGN_BLOCK)
1193 tabularFeatures(cur, LyXTabular::ALIGN_CENTER, string());
1194 else if (!len.zero()
1195 && tabular.getAlignment(cur.idx(), true) != LYX_ALIGN_BLOCK)
1196 tabularFeatures(cur, LyXTabular::ALIGN_BLOCK, string());
1200 case LyXTabular::SET_MPWIDTH:
1201 tabular.setMColumnPWidth(cur.idx(), LyXLength(value));
1204 case LyXTabular::SET_SPECIAL_COLUMN:
1205 case LyXTabular::SET_SPECIAL_MULTI:
1206 tabular.setAlignSpecial(cur.idx(),value,feature);
1209 case LyXTabular::APPEND_ROW:
1210 // append the row into the tabular
1211 tabular.appendRow(bv.buffer()->params(), cur.idx());
1214 case LyXTabular::APPEND_COLUMN:
1215 // append the column into the tabular
1216 tabular.appendColumn(bv.buffer()->params(), cur.idx());
1219 case LyXTabular::DELETE_ROW:
1220 for (int i = sel_row_start; i <= sel_row_end; ++i)
1221 tabular.deleteRow(sel_row_start);
1222 if (sel_row_start >= tabular.rows())
1224 cur.idx() = tabular.getCellNumber(sel_row_start, column);
1227 cur.selection() = false;
1230 case LyXTabular::DELETE_COLUMN:
1231 for (int i = sel_col_start; i <= sel_col_end; ++i)
1232 tabular.deleteColumn(sel_col_start);
1233 if (sel_col_start >= tabular.columns())
1235 cur.idx() = tabular.getCellNumber(row, sel_col_start);
1238 cur.selection() = false;
1241 case LyXTabular::M_TOGGLE_LINE_TOP:
1243 case LyXTabular::TOGGLE_LINE_TOP: {
1244 bool lineSet = !tabular.topLine(cur.idx(), flag);
1245 for (int i = sel_row_start; i <= sel_row_end; ++i)
1246 for (int j = sel_col_start; j <= sel_col_end; ++j)
1248 tabular.getCellNumber(i, j),
1253 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1255 case LyXTabular::TOGGLE_LINE_BOTTOM: {
1256 bool lineSet = !tabular.bottomLine(cur.idx(), flag);
1257 for (int i = sel_row_start; i <= sel_row_end; ++i)
1258 for (int j = sel_col_start; j <= sel_col_end; ++j)
1259 tabular.setBottomLine(
1260 tabular.getCellNumber(i, j),
1266 case LyXTabular::M_TOGGLE_LINE_LEFT:
1268 case LyXTabular::TOGGLE_LINE_LEFT: {
1269 bool lineSet = !tabular.leftLine(cur.idx(), flag);
1270 for (int i = sel_row_start; i <= sel_row_end; ++i)
1271 for (int j = sel_col_start; j <= sel_col_end; ++j)
1272 tabular.setLeftLine(
1273 tabular.getCellNumber(i,j),
1279 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1281 case LyXTabular::TOGGLE_LINE_RIGHT: {
1282 bool lineSet = !tabular.rightLine(cur.idx(), flag);
1283 for (int i = sel_row_start; i <= sel_row_end; ++i)
1284 for (int j = sel_col_start; j <= sel_col_end; ++j)
1285 tabular.setRightLine(
1286 tabular.getCellNumber(i,j),
1292 case LyXTabular::M_ALIGN_LEFT:
1293 case LyXTabular::M_ALIGN_RIGHT:
1294 case LyXTabular::M_ALIGN_CENTER:
1296 case LyXTabular::ALIGN_LEFT:
1297 case LyXTabular::ALIGN_RIGHT:
1298 case LyXTabular::ALIGN_CENTER:
1299 case LyXTabular::ALIGN_BLOCK:
1300 for (int i = sel_row_start; i <= sel_row_end; ++i)
1301 for (int j = sel_col_start; j <= sel_col_end; ++j)
1302 tabular.setAlignment(
1303 tabular.getCellNumber(i, j),
1308 case LyXTabular::M_VALIGN_TOP:
1309 case LyXTabular::M_VALIGN_BOTTOM:
1310 case LyXTabular::M_VALIGN_MIDDLE:
1312 case LyXTabular::VALIGN_TOP:
1313 case LyXTabular::VALIGN_BOTTOM:
1314 case LyXTabular::VALIGN_MIDDLE:
1315 for (int i = sel_row_start; i <= sel_row_end; ++i)
1316 for (int j = sel_col_start; j <= sel_col_end; ++j)
1317 tabular.setVAlignment(
1318 tabular.getCellNumber(i, j),
1322 case LyXTabular::MULTICOLUMN: {
1323 if (sel_row_start != sel_row_end) {
1324 #ifdef WITH_WARNINGS
1325 #warning Need I say it ? This is horrible.
1327 Alert::error(_("Error setting multicolumn"),
1328 _("You cannot set multicolumn vertically."));
1331 if (!cur.selection()) {
1332 // just multicol for one single cell
1333 // check whether we are completely in a multicol
1334 if (tabular.isMultiColumn(cur.idx()))
1335 tabular.unsetMultiColumn(cur.idx());
1337 tabular.setMultiColumn(bv.buffer(), cur.idx(), 1);
1340 // we have a selection so this means we just add all this
1341 // cells to form a multicolumn cell
1342 CursorSlice::idx_type const s_start = cur.selBegin().idx();
1343 CursorSlice::idx_type const s_end = cur.selEnd().idx();
1344 tabular.setMultiColumn(bv.buffer(), s_start, s_end - s_start + 1);
1345 cur.idx() = s_start;
1348 cur.selection() = false;
1352 case LyXTabular::SET_ALL_LINES:
1354 case LyXTabular::UNSET_ALL_LINES:
1356 for (int i = sel_row_start; i <= sel_row_end; ++i)
1357 for (int j = sel_col_start; j <= sel_col_end; ++j)
1358 tabular.setAllLines(
1359 tabular.getCellNumber(i,j), setLines);
1363 case LyXTabular::SET_LONGTABULAR:
1364 tabular.setLongTabular(true);
1367 case LyXTabular::UNSET_LONGTABULAR:
1368 tabular.setLongTabular(false);
1371 case LyXTabular::SET_ROTATE_TABULAR:
1372 tabular.setRotateTabular(true);
1375 case LyXTabular::UNSET_ROTATE_TABULAR:
1376 tabular.setRotateTabular(false);
1379 case LyXTabular::SET_ROTATE_CELL:
1380 for (int i = sel_row_start; i <= sel_row_end; ++i)
1381 for (int j = sel_col_start; j <= sel_col_end; ++j)
1382 tabular.setRotateCell(
1383 tabular.getCellNumber(i, j), true);
1386 case LyXTabular::UNSET_ROTATE_CELL:
1387 for (int i = sel_row_start; i <= sel_row_end; ++i)
1388 for (int j = sel_col_start; j <= sel_col_end; ++j)
1389 tabular.setRotateCell(
1390 tabular.getCellNumber(i, j), false);
1393 case LyXTabular::SET_USEBOX: {
1394 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1395 if (val == tabular.getUsebox(cur.idx()))
1396 val = LyXTabular::BOX_NONE;
1397 for (int i = sel_row_start; i <= sel_row_end; ++i)
1398 for (int j = sel_col_start; j <= sel_col_end; ++j)
1399 tabular.setUsebox(tabular.getCellNumber(i, j), val);
1403 case LyXTabular::UNSET_LTFIRSTHEAD:
1405 case LyXTabular::SET_LTFIRSTHEAD:
1406 tabular.getRowOfLTFirstHead(row, ltt);
1407 checkLongtableSpecial(ltt, value, flag);
1408 tabular.setLTHead(row, flag, ltt, true);
1411 case LyXTabular::UNSET_LTHEAD:
1413 case LyXTabular::SET_LTHEAD:
1414 tabular.getRowOfLTHead(row, ltt);
1415 checkLongtableSpecial(ltt, value, flag);
1416 tabular.setLTHead(row, flag, ltt, false);
1419 case LyXTabular::UNSET_LTFOOT:
1421 case LyXTabular::SET_LTFOOT:
1422 tabular.getRowOfLTFoot(row, ltt);
1423 checkLongtableSpecial(ltt, value, flag);
1424 tabular.setLTFoot(row, flag, ltt, false);
1427 case LyXTabular::UNSET_LTLASTFOOT:
1429 case LyXTabular::SET_LTLASTFOOT:
1430 tabular.getRowOfLTLastFoot(row, ltt);
1431 checkLongtableSpecial(ltt, value, flag);
1432 tabular.setLTFoot(row, flag, ltt, true);
1435 case LyXTabular::SET_LTNEWPAGE:
1436 tabular.setLTNewPage(row, !tabular.getLTNewPage(row));
1439 // dummy stuff just to avoid warnings
1440 case LyXTabular::LAST_ACTION:
1444 InsetTabularMailer(*this).updateDialog(&bv);
1448 bool InsetTabular::showInsetDialog(BufferView * bv) const
1450 InsetTabularMailer(*this).showDialog(bv);
1455 void InsetTabular::openLayoutDialog(BufferView * bv) const
1457 InsetTabularMailer(*this).showDialog(bv);
1461 void InsetTabular::getLabelList(Buffer const & buffer,
1462 vector<string> & list) const
1464 tabular.getLabelList(buffer, list);
1468 bool InsetTabular::copySelection(LCursor & cur)
1470 if (!cur.selection())
1474 getSelection(cur, rs, re, cs, ce);
1476 paste_tabular.reset(new LyXTabular(tabular));
1478 for (int i = 0; i < rs; ++i)
1479 paste_tabular->deleteRow(0);
1481 int const rows = re - rs + 1;
1482 while (paste_tabular->rows() > rows)
1483 paste_tabular->deleteRow(rows);
1485 paste_tabular->setTopLine(0, true, true);
1486 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
1489 for (int i = 0; i < cs; ++i)
1490 paste_tabular->deleteColumn(0);
1492 int const columns = ce - cs + 1;
1493 while (paste_tabular->columns() > columns)
1494 paste_tabular->deleteColumn(columns);
1496 paste_tabular->setLeftLine(0, true, true);
1497 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
1501 OutputParams const runparams;
1502 paste_tabular->plaintext(cur.buffer(), os, runparams, 0, true, '\t');
1503 cur.bv().stuffClipboard(os.str());
1508 bool InsetTabular::pasteSelection(LCursor & cur)
1512 int const actcol = tabular.column_of_cell(cur.idx());
1513 int const actrow = tabular.row_of_cell(cur.idx());
1514 for (int r1 = 0, r2 = actrow;
1515 r1 < paste_tabular->rows() && r2 < tabular.rows();
1517 for (int c1 = 0, c2 = actcol;
1518 c1 < paste_tabular->columns() && c2 < tabular.columns();
1520 if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
1521 tabular.isPartOfMultiColumn(r2, c2))
1523 if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
1527 if (tabular.isPartOfMultiColumn(r2, c2)) {
1531 shared_ptr<InsetText> inset = tabular.getCellInset(r2, c2);
1532 inset = paste_tabular->getCellInset(r1, c1);
1540 void InsetTabular::cutSelection(LCursor & cur)
1542 if (!cur.selection())
1545 bool const track = cur.buffer().params().tracking_changes;
1547 getSelection(cur, rs, re, cs, ce);
1548 for (int i = rs; i <= re; ++i)
1549 for (int j = cs; j <= ce; ++j)
1550 cell(tabular.getCellNumber(i, j))->clear(track);
1552 // cursor position might be invalid now
1553 cur.pos() = cur.lastpos();
1554 cur.clearSelection();
1558 bool InsetTabular::isRightToLeft(LCursor & cur) const
1560 BOOST_ASSERT(cur.size() > 1);
1561 Paragraph const & parentpar = cur[cur.size() - 2].paragraph();
1562 LCursor::pos_type const parentpos = cur[cur.size() - 2].pos();
1563 return parentpar.getFontSettings(cur.bv().buffer()->params(),
1564 parentpos).language()->RightToLeft();
1568 void InsetTabular::getSelection(LCursor & cur,
1569 int & rs, int & re, int & cs, int & ce) const
1571 CursorSlice const & beg = cur.selBegin();
1572 CursorSlice const & end = cur.selEnd();
1573 cs = tabular.column_of_cell(beg.idx());
1574 ce = tabular.column_of_cell(end.idx());
1577 cs = tabular.column_of_cell(end.idx());
1579 ce = tabular.right_column_of_cell(end.idx());
1582 rs = tabular.row_of_cell(beg.idx());
1583 re = tabular.row_of_cell(end.idx());
1589 size_t InsetTabular::nargs() const
1591 return tabular.getNumberOfCells();
1595 LyXText * InsetTabular::getText(int idx) const
1597 return size_t(idx) < nargs() ? cell(idx)->getText(0) : 0;
1601 void InsetTabular::markErased()
1603 for (idx_type idx = 0; idx < nargs(); ++idx)
1604 cell(idx)->markErased();
1608 bool InsetTabular::forceDefaultParagraphs(InsetBase const *) const
1611 int const cell = tabular.getCellFromInset(in);
1614 return tabular.getPWidth(cell).zero();
1616 // this is a workaround for a crash (New, Insert->Tabular,
1617 // Insert->FootNote)
1621 // well we didn't obviously find it so maybe our owner knows more
1622 BOOST_ASSERT(owner());
1623 return owner()->forceDefaultParagraphs(in);
1629 bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
1632 if (buf.length() <= 0)
1638 string::size_type const len = buf.length();
1639 string::size_type p = 0;
1641 while (p < len && (p = buf.find_first_of("\t\n", p)) != string::npos) {
1649 maxCols = max(cols, maxCols);
1655 maxCols = max(cols, maxCols);
1656 LyXTabular * loctab;
1661 paste_tabular.reset(
1662 new LyXTabular(bv.buffer()->params(), rows, maxCols));
1663 loctab = paste_tabular.get();
1667 cell = bv.cursor().idx();
1668 ocol = tabular.column_of_cell(cell);
1669 row = tabular.row_of_cell(cell);
1672 string::size_type op = 0;
1673 int const cells = loctab->getNumberOfCells();
1676 rows = loctab->rows();
1677 int const columns = loctab->columns();
1679 while (cell < cells && p < len && row < rows &&
1680 (p = buf.find_first_of("\t\n", p)) != string::npos)
1686 // we can only set this if we are not too far right
1687 if (cols < columns) {
1688 shared_ptr<InsetText> inset = loctab->getCellInset(cell);
1689 Paragraph & par = inset->text_.getPar(0);
1690 LyXFont const font = inset->text_.getFont(par, 0);
1691 inset->setText(buf.substr(op, p - op), font);
1697 // we can only set this if we are not too far right
1698 if (cols < columns) {
1699 shared_ptr<InsetText> inset = tabular.getCellInset(cell);
1700 Paragraph & par = inset->text_.getPar(0);
1701 LyXFont const font = inset->text_.getFont(par, 0);
1702 inset->setText(buf.substr(op, p - op), font);
1707 cell = loctab->getCellNumber(row, cols);
1713 // check for the last cell if there is no trailing '\n'
1714 if (cell < cells && op < len) {
1715 shared_ptr<InsetText> inset = loctab->getCellInset(cell);
1716 Paragraph & par = inset->text_.getPar(0);
1717 LyXFont const font = inset->text_.getFont(par, 0);
1718 inset->setText(buf.substr(op, len - op), font);
1724 void InsetTabular::addPreview(PreviewLoader & loader) const
1726 int const rows = tabular.rows();
1727 int const columns = tabular.columns();
1728 for (int i = 0; i < rows; ++i) {
1729 for (int j = 0; j < columns; ++j)
1730 tabular.getCellInset(i, j)->addPreview(loader);
1735 bool InsetTabular::tablemode(LCursor & cur) const
1737 return cur.selection() && cur.selBegin().idx() != cur.selEnd().idx();
1744 string const InsetTabularMailer::name_("tabular");
1746 InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)
1747 : inset_(const_cast<InsetTabular &>(inset))
1751 string const InsetTabularMailer::inset2string(Buffer const &) const
1753 return params2string(inset_);
1757 void InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
1759 istringstream data(in);
1761 lex.setStream(data);
1768 if (!lex || token != name_)
1769 return print_mailer_error("InsetTabularMailer", in, 1,
1772 // This is part of the inset proper that is usually swallowed
1773 // by Buffer::readInset
1775 if (!lex || token != "Tabular")
1776 return print_mailer_error("InsetTabularMailer", in, 2,
1779 Buffer const & buffer = inset.buffer();
1780 inset.read(buffer, lex);
1784 string const InsetTabularMailer::params2string(InsetTabular const & inset)
1787 data << name_ << ' ';
1788 inset.write(inset.buffer(), data);
1789 data << "\\end_inset\n";