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"
40 #include "support/std_sstream.h"
44 using lyx::graphics::PreviewLoader;
46 using lyx::support::ltrim;
47 using lyx::support::strToInt;
48 using lyx::support::strToDbl;
54 using std::istringstream;
56 using std::ostringstream;
63 int const ADD_TO_HEIGHT = 2;
64 int const ADD_TO_TABULAR_WIDTH = 2;
67 boost::scoped_ptr<LyXTabular> paste_tabular;
70 struct TabularFeature {
71 LyXTabular::Feature action;
76 TabularFeature tabularFeature[] =
78 { LyXTabular::APPEND_ROW, "append-row" },
79 { LyXTabular::APPEND_COLUMN, "append-column" },
80 { LyXTabular::DELETE_ROW, "delete-row" },
81 { LyXTabular::DELETE_COLUMN, "delete-column" },
82 { LyXTabular::TOGGLE_LINE_TOP, "toggle-line-top" },
83 { LyXTabular::TOGGLE_LINE_BOTTOM, "toggle-line-bottom" },
84 { LyXTabular::TOGGLE_LINE_LEFT, "toggle-line-left" },
85 { LyXTabular::TOGGLE_LINE_RIGHT, "toggle-line-right" },
86 { LyXTabular::ALIGN_LEFT, "align-left" },
87 { LyXTabular::ALIGN_RIGHT, "align-right" },
88 { LyXTabular::ALIGN_CENTER, "align-center" },
89 { LyXTabular::ALIGN_BLOCK, "align-block" },
90 { LyXTabular::VALIGN_TOP, "valign-top" },
91 { LyXTabular::VALIGN_BOTTOM, "valign-bottom" },
92 { LyXTabular::VALIGN_MIDDLE, "valign-middle" },
93 { LyXTabular::M_TOGGLE_LINE_TOP, "m-toggle-line-top" },
94 { LyXTabular::M_TOGGLE_LINE_BOTTOM, "m-toggle-line-bottom" },
95 { LyXTabular::M_TOGGLE_LINE_LEFT, "m-toggle-line-left" },
96 { LyXTabular::M_TOGGLE_LINE_RIGHT, "m-toggle-line-right" },
97 { LyXTabular::M_ALIGN_LEFT, "m-align-left" },
98 { LyXTabular::M_ALIGN_RIGHT, "m-align-right" },
99 { LyXTabular::M_ALIGN_CENTER, "m-align-center" },
100 { LyXTabular::M_VALIGN_TOP, "m-valign-top" },
101 { LyXTabular::M_VALIGN_BOTTOM, "m-valign-bottom" },
102 { LyXTabular::M_VALIGN_MIDDLE, "m-valign-middle" },
103 { LyXTabular::MULTICOLUMN, "multicolumn" },
104 { LyXTabular::SET_ALL_LINES, "set-all-lines" },
105 { LyXTabular::UNSET_ALL_LINES, "unset-all-lines" },
106 { LyXTabular::SET_LONGTABULAR, "set-longtabular" },
107 { LyXTabular::UNSET_LONGTABULAR, "unset-longtabular" },
108 { LyXTabular::SET_PWIDTH, "set-pwidth" },
109 { LyXTabular::SET_MPWIDTH, "set-mpwidth" },
110 { LyXTabular::SET_ROTATE_TABULAR, "set-rotate-tabular" },
111 { LyXTabular::UNSET_ROTATE_TABULAR, "unset-rotate-tabular" },
112 { LyXTabular::SET_ROTATE_CELL, "set-rotate-cell" },
113 { LyXTabular::UNSET_ROTATE_CELL, "unset-rotate-cell" },
114 { LyXTabular::SET_USEBOX, "set-usebox" },
115 { LyXTabular::SET_LTHEAD, "set-lthead" },
116 { LyXTabular::SET_LTFIRSTHEAD, "set-ltfirsthead" },
117 { LyXTabular::SET_LTFOOT, "set-ltfoot" },
118 { LyXTabular::SET_LTLASTFOOT, "set-ltlastfoot" },
119 { LyXTabular::SET_LTNEWPAGE, "set-ltnewpage" },
120 { LyXTabular::SET_SPECIAL_COLUMN, "set-special-column" },
121 { LyXTabular::SET_SPECIAL_MULTI, "set-special-multi" },
122 { LyXTabular::LAST_ACTION, "" }
126 class FeatureEqual : public std::unary_function<TabularFeature, bool> {
128 FeatureEqual(LyXTabular::Feature feature)
129 : feature_(feature) {}
130 bool operator()(TabularFeature const & tf) const {
131 return tf.action == feature_;
134 LyXTabular::Feature feature_;
140 string const featureAsString(LyXTabular::Feature feature)
142 TabularFeature * end = tabularFeature +
143 sizeof(tabularFeature) / sizeof(TabularFeature);
144 TabularFeature * it = std::find_if(tabularFeature, end,
145 FeatureEqual(feature));
146 return (it == end) ? string() : it->feature;
150 bool InsetTabular::hasPasteBuffer() const
152 return (paste_tabular.get() != 0);
156 InsetTabular::InsetTabular(Buffer const & buf, int rows, int columns)
157 : tabular(buf.params(), max(rows, 1), max(columns, 1)),
158 buffer_(&buf), cursorx_(0)
162 InsetTabular::InsetTabular(InsetTabular const & tab)
163 : UpdatableInset(tab), tabular(tab.tabular),
164 buffer_(tab.buffer_), cursorx_(0)
168 InsetTabular::~InsetTabular()
170 InsetTabularMailer(*this).hideDialog();
174 auto_ptr<InsetBase> InsetTabular::clone() const
176 return auto_ptr<InsetBase>(new InsetTabular(*this));
180 Buffer const & InsetTabular::buffer() const
186 void InsetTabular::buffer(Buffer * b)
192 void InsetTabular::write(Buffer const & buf, ostream & os) const
194 os << "Tabular" << endl;
195 tabular.write(buf, os);
199 void InsetTabular::read(Buffer const & buf, LyXLex & lex)
201 bool const old_format = (lex.getString() == "\\LyXTable");
203 tabular.read(buf, lex);
209 string token = lex.getString();
210 while (lex.isOK() && (token != "\\end_inset")) {
212 token = lex.getString();
214 if (token != "\\end_inset") {
215 lex.printError("Missing \\end_inset at this point. "
221 void InsetTabular::metrics(MetricsInfo & mi, Dimension & dim) const
223 //lyxerr << "InsetTabular::metrics: " << mi.base.bv << " width: " <<
224 // mi.base.textwidth << "\n";
226 lyxerr << "InsetTabular::metrics: need bv" << endl;
230 for (int i = 0, cell = -1; i < tabular.rows(); ++i) {
233 for (int j = 0; j < tabular.columns(); ++j) {
234 if (tabular.isPartOfMultiColumn(i, j))
240 tabular.column_info[j].p_width.inPixels(mi.base.textwidth);
241 tabular.getCellInset(cell).metrics(m, dim);
242 maxAsc = max(maxAsc, dim.asc);
243 maxDesc = max(maxDesc, dim.des);
244 tabular.setWidthOfCell(cell, dim.wid);
246 tabular.setAscentOfRow(i, maxAsc + ADD_TO_HEIGHT);
247 tabular.setDescentOfRow(i, maxDesc + ADD_TO_HEIGHT);
250 dim.asc = tabular.getAscentOfRow(0);
251 dim.des = tabular.getHeightOfTabular() - tabular.getAscentOfRow(0) + 1;
252 dim.wid = tabular.getWidthOfTabular() + 2 * ADD_TO_TABULAR_WIDTH;
257 void InsetTabular::draw(PainterInfo & pi, int x, int y) const
259 //lyxerr << "InsetTabular::draw: " << x << " " << y << endl;
261 BufferView * bv = pi.base.bv;
262 setPosCache(pi, x, y);
265 x += ADD_TO_TABULAR_WIDTH;
268 first_visible_cell = -1;
269 for (int i = 0; i < tabular.rows(); ++i) {
271 idx = tabular.getCellNumber(i, 0);
272 if (y + tabular.getDescentOfRow(i) <= 0 &&
273 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;
380 if (isRightToLeft(cur))
381 cell = tabular.getLastCellInRow(0);
385 if (isRightToLeft(cur))
386 cell = tabular.getFirstCellInRow(tabular.rows()-1);
388 cell = tabular.getNumberOfCells() - 1;
390 cur.selection() = false;
392 cur.bv().fitCursor();
398 InsetBase * InsetTabular::editXY(LCursor & cur, int x, int y)
400 //lyxerr << "InsetTabular::editXY: " << this << endl;
401 cur.selection() = false;
403 return setPos(cur, x, y);
404 //int xx = cursorx_ - xo_ + tabular.getBeginningOfTextInCell(actcell);
408 void InsetTabular::priv_dispatch(LCursor & cur, FuncRequest & cmd)
410 lyxerr << "# InsetTabular::dispatch: cmd: " << cmd << endl;
411 //lyxerr << " cur:\n" << cur << endl;
412 CursorSlice sl = cur.top();
414 switch (cmd.action) {
416 case LFUN_MOUSE_PRESS:
417 // we'll pop up the table dialog on release
418 if (cmd.button() == mouse_button::button3)
420 cur.selection() = false;
421 setPos(cur, cmd.x, cmd.y);
423 cur.bv().cursor().setCursor(cur, false);
424 //if (cmd.button() == mouse_button::button2)
425 // dispatch(cur, FuncRequest(LFUN_PASTESELECTION, "paragraph"));
426 //lyxerr << "# InsetTabular::MousePress\n" << cur.bv().cursor() << endl;
429 case LFUN_MOUSE_MOTION:
430 if (cmd.button() != mouse_button::button1)
432 setPos(cur, cmd.x, cmd.y);
433 cur.bv().cursor().setCursor(cur, true);
434 //lyxerr << "# InsetTabular::MouseMotion\n" << cur.bv().cursor() << endl;
437 case LFUN_MOUSE_RELEASE:
438 //lyxerr << "# InsetTabular::MouseRelease\n" << cur.bv().cursor() << endl;
439 if (cmd.button() == mouse_button::button3)
440 InsetTabularMailer(*this).showDialog(&cur.bv());
443 case LFUN_CELL_BACKWARD:
445 cur.selection() = false;
448 case LFUN_CELL_FORWARD:
450 cur.selection() = false;
453 case LFUN_SCROLL_INSET:
454 if (cmd.argument.empty())
456 if (cmd.argument.find('.') != cmd.argument.npos)
457 scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
459 scroll(cur.bv(), strToInt(cmd.argument));
464 cell(cur.idx()).dispatch(cur, cmd);
465 cur.dispatched(); // override the cell's decision
467 isRightToLeft(cur) ? movePrevCell(cur) : moveNextCell(cur);
468 if (sl == cur.top()) {
469 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
476 cell(cur.idx()).dispatch(cur, cmd);
477 cur.dispatched(); // override the cell's decision
479 isRightToLeft(cur) ? moveNextCell(cur) : movePrevCell(cur);
480 if (sl == cur.top()) {
481 cmd = FuncRequest(LFUN_FINISHED_LEFT);
488 cell(cur.idx()).dispatch(cur, cmd);
489 cur.dispatched(); // override the cell's decision
491 if (tabular.row_of_cell(cur.idx()) != tabular.rows() - 1) {
492 cur.idx() = tabular.getCellBelow(cur.idx());
497 if (sl == cur.top()) {
498 cmd = FuncRequest(LFUN_FINISHED_DOWN);
505 cell(cur.idx()).dispatch(cur, cmd);
506 cur.dispatched(); // override the cell's decision
508 if (tabular.row_of_cell(cur.idx()) != 0) {
509 cur.idx() = tabular.getCellAbove(cur.idx());
510 cur.par() = cur.lastpar();
511 cur.pos() = cur.lastpos();
514 if (sl == cur.top()) {
515 cmd = FuncRequest(LFUN_FINISHED_UP);
521 //if (hasSelection())
522 // cur.selection() = false;
523 int actcell = cur.idx();
524 int actcol = tabular.column_of_cell(actcell);
526 if (cur.bv().top_y() + cur.bv().painter().paperHeight()
527 < yo_ + tabular.getHeightOfTabular())
529 cur.bv().scrollDocView(
530 cur.bv().top_y() + cur.bv().painter().paperHeight());
531 cur.idx() = tabular.getCellBelow(first_visible_cell) + column;
533 cur.idx() = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
540 //if (hasSelection())
541 // cur.selection() = false;
542 int column = tabular.column_of_cell(cur.idx());
544 cur.bv().scrollDocView(
545 cur.bv().top_y() - cur.bv().painter().paperHeight());
549 cur.idx() = tabular.getCellBelow(first_visible_cell) + column;
557 case LFUN_LAYOUT_TABULAR:
558 InsetTabularMailer(*this).showDialog(&cur.bv());
561 case LFUN_INSET_DIALOG_UPDATE:
562 InsetTabularMailer(*this).updateDialog(&cur.bv());
565 case LFUN_TABULAR_FEATURE:
566 if (!tabularFeatures(cur, cmd.argument))
570 // insert file functions
571 case LFUN_FILE_INSERT_ASCII_PARA:
572 case LFUN_FILE_INSERT_ASCII: {
573 string tmpstr = getContentsOfAsciiFile(&cur.bv(), cmd.argument, false);
574 if (!tmpstr.empty() && !insertAsciiString(cur.bv(), tmpstr, false))
580 if (copySelection(cur)) {
581 recordUndo(cur, Undo::DELETE);
588 recordUndo(cur, Undo::DELETE);
592 cell(cur.idx()).dispatch(cur, cmd);
596 if (!cur.selection())
602 case LFUN_PASTESELECTION: {
603 string const clip = cur.bv().getClipboard();
606 if (clip.find('\t') != string::npos) {
610 size_t len = clip.length();
611 for (size_t p = 0; p < len; ++p) {
612 p = clip.find_first_of("\t\n", p);
613 if (p == string::npos)
622 maxCols = max(cols, maxCols);
627 maxCols = max(cols, maxCols);
630 new LyXTabular(cur.bv().buffer()->params(), rows, maxCols));
632 string::size_type op = 0;
634 int cells = paste_tabular->getNumberOfCells();
637 for (size_t p = 0; cell < cells && p < len; ++p) {
638 p = clip.find_first_of("\t\n", p);
639 if (p == string::npos || p >= len)
643 paste_tabular->getCellInset(cell).
644 setText(clip.substr(op, p - op), font);
649 paste_tabular->getCellInset(cell).
650 setText(clip.substr(op, p - op), font);
651 while (cols++ < maxCols)
658 // check for the last cell if there is no trailing '\n'
659 if (cell < cells && op < len)
660 paste_tabular->getCellInset(cell).
661 setText(clip.substr(op, len - op), font);
662 } else if (!insertAsciiString(cur.bv(), clip, true)) {
663 // so that the clipboard is used and it goes on
665 // and executes LFUN_PASTESELECTION in insettext!
666 paste_tabular.reset();
672 if (hasPasteBuffer()) {
673 recordUndo(cur, Undo::INSERT);
677 cell(cur.idx()).dispatch(cur, cmd);
681 // we try to handle this event in the insets dispatch function.
682 cell(cur.idx()).dispatch(cur, cmd);
686 InsetTabularMailer(*this).updateDialog(&cur.bv());
690 // function sets an object as defined in func_status.h:
691 // states OK, Unknown, Disabled, On, Off.
692 bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd,
693 FuncStatus & status) const
695 switch (cmd.action) {
696 case LFUN_TABULAR_FEATURE: {
697 int actcell = cur.idx();
698 int action = LyXTabular::LAST_ACTION;
700 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
701 string const tmp = tabularFeature[i].feature;
702 if (tmp == cmd.argument.substr(0, tmp.length())) {
703 action = tabularFeature[i].action;
707 if (action == LyXTabular::LAST_ACTION) {
709 status.unknown(true);
713 string const argument
714 = ltrim(cmd.argument.substr(tabularFeature[i].feature.length()));
716 int sel_row_start = 0;
719 LyXTabular::ltType dummyltt;
722 getSelection(cur, sel_row_start, sel_row_end, dummy, dummy);
725 case LyXTabular::SET_PWIDTH:
726 case LyXTabular::SET_MPWIDTH:
727 case LyXTabular::SET_SPECIAL_COLUMN:
728 case LyXTabular::SET_SPECIAL_MULTI:
729 case LyXTabular::APPEND_ROW:
730 case LyXTabular::APPEND_COLUMN:
731 case LyXTabular::DELETE_ROW:
732 case LyXTabular::DELETE_COLUMN:
733 case LyXTabular::SET_ALL_LINES:
734 case LyXTabular::UNSET_ALL_LINES:
738 case LyXTabular::MULTICOLUMN:
739 status.setOnOff(tabular.isMultiColumn(actcell));
742 case LyXTabular::M_TOGGLE_LINE_TOP:
744 case LyXTabular::TOGGLE_LINE_TOP:
745 status.setOnOff(tabular.topLine(actcell, flag));
748 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
750 case LyXTabular::TOGGLE_LINE_BOTTOM:
751 status.setOnOff(tabular.bottomLine(actcell, flag));
754 case LyXTabular::M_TOGGLE_LINE_LEFT:
756 case LyXTabular::TOGGLE_LINE_LEFT:
757 status.setOnOff(tabular.leftLine(actcell, flag));
760 case LyXTabular::M_TOGGLE_LINE_RIGHT:
762 case LyXTabular::TOGGLE_LINE_RIGHT:
763 status.setOnOff(tabular.rightLine(actcell, flag));
766 case LyXTabular::M_ALIGN_LEFT:
768 case LyXTabular::ALIGN_LEFT:
769 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_LEFT);
772 case LyXTabular::M_ALIGN_RIGHT:
774 case LyXTabular::ALIGN_RIGHT:
775 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_RIGHT);
778 case LyXTabular::M_ALIGN_CENTER:
780 case LyXTabular::ALIGN_CENTER:
781 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_CENTER);
784 case LyXTabular::ALIGN_BLOCK:
785 status.enabled(!tabular.getPWidth(actcell).zero());
786 status.setOnOff(tabular.getAlignment(actcell, flag) == LYX_ALIGN_BLOCK);
789 case LyXTabular::M_VALIGN_TOP:
791 case LyXTabular::VALIGN_TOP:
793 tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_TOP);
796 case LyXTabular::M_VALIGN_BOTTOM:
798 case LyXTabular::VALIGN_BOTTOM:
800 tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_BOTTOM);
803 case LyXTabular::M_VALIGN_MIDDLE:
805 case LyXTabular::VALIGN_MIDDLE:
807 tabular.getVAlignment(actcell, flag) == LyXTabular::LYX_VALIGN_MIDDLE);
810 case LyXTabular::SET_LONGTABULAR:
811 status.setOnOff(tabular.isLongTabular());
814 case LyXTabular::UNSET_LONGTABULAR:
815 status.setOnOff(!tabular.isLongTabular());
818 case LyXTabular::SET_ROTATE_TABULAR:
819 status.setOnOff(tabular.getRotateTabular());
822 case LyXTabular::UNSET_ROTATE_TABULAR:
823 status.setOnOff(!tabular.getRotateTabular());
826 case LyXTabular::SET_ROTATE_CELL:
827 status.setOnOff(tabular.getRotateCell(actcell));
830 case LyXTabular::UNSET_ROTATE_CELL:
831 status.setOnOff(!tabular.getRotateCell(actcell));
834 case LyXTabular::SET_USEBOX:
835 status.setOnOff(strToInt(argument) == tabular.getUsebox(actcell));
838 case LyXTabular::SET_LTFIRSTHEAD:
839 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
842 case LyXTabular::SET_LTHEAD:
843 status.setOnOff(tabular.getRowOfLTHead(sel_row_start, dummyltt));
846 case LyXTabular::SET_LTFOOT:
847 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
850 case LyXTabular::SET_LTLASTFOOT:
851 status.setOnOff(tabular.getRowOfLTFoot(sel_row_start, dummyltt));
854 case LyXTabular::SET_LTNEWPAGE:
855 status.setOnOff(tabular.getLTNewPage(sel_row_start));
860 status.enabled(false);
867 // we try to handle this event in the insets dispatch function.
868 return cell(cur.idx()).getStatus(cur, cmd, status);
873 int InsetTabular::latex(Buffer const & buf, ostream & os,
874 OutputParams const & runparams) const
876 return tabular.latex(buf, os, runparams);
880 int InsetTabular::plaintext(Buffer const & buf, ostream & os,
881 OutputParams const & runparams) const
883 int dp = runparams.linelen ? ownerPar(buf, this).params().depth() : 0;
884 return tabular.plaintext(buf, os, runparams, dp, false, 0);
888 int InsetTabular::linuxdoc(Buffer const & buf, ostream & os,
889 OutputParams const & runparams) const
891 return tabular.linuxdoc(buf,os, runparams);
895 int InsetTabular::docbook(Buffer const & buf, ostream & os,
896 OutputParams const & runparams) const
899 InsetOld * master = 0;
901 #warning Why not pass a proper DocIterator here?
903 // if the table is inside a float it doesn't need the informaltable
904 // wrapper. Search for it.
905 for (master = owner(); master; master = master->owner())
906 if (master->lyxCode() == InsetOld::FLOAT_CODE)
911 os << "<informaltable>";
912 if (runparams.mixed_content)
916 ret += tabular.docbook(buf, os, runparams);
918 os << "</informaltable>";
919 if (runparams.mixed_content)
927 void InsetTabular::validate(LaTeXFeatures & features) const
929 tabular.validate(features);
933 InsetText const & InsetTabular::cell(int idx) const
935 return tabular.getCellInset(idx);
939 InsetText & InsetTabular::cell(int idx)
941 return tabular.getCellInset(idx);
945 void InsetTabular::getCursorPos(CursorSlice const & cur, int & x, int & y) const
947 cell(cur.idx()).getCursorPos(cur, x, y);
951 InsetBase * InsetTabular::setPos(LCursor & cur, int x, int y) const
954 int dist_min = 1000000;
955 for (idx_type i = 0; i < nargs(); ++i) {
956 int d = getText(i)->dist(x, y);
963 InsetBase * inset = cell(cur.idx()).text_.editXY(cur, x, y);
964 //lyxerr << "# InsetTabular::setPos()\n" << cur << endl;
969 int InsetTabular::getCellXPos(int cell) const
973 for (; !tabular.isFirstCellInRow(c); --c)
975 int lx = tabular.getWidthOfColumn(cell);
976 for (; c < cell; ++c)
977 lx += tabular.getWidthOfColumn(c);
979 return lx - tabular.getWidthOfColumn(cell) + xo_;
983 void InsetTabular::resetPos(LCursor & cur) const
985 BufferView & bv = cur.bv();
986 int actcell = cur.idx();
987 int actcol = tabular.column_of_cell(actcell);
989 int const offset = ADD_TO_TABULAR_WIDTH + 2;
990 int new_x = getCellXPos(actcell) + offset;
991 int old_x = cursorx_;
993 // cursor.x(getCellXPos(actcell) + offset);
994 if (actcol < tabular.columns() - 1 && scroll(false) &&
995 tabular.getWidthOfTabular() < bv.workWidth()-20)
998 } else if (cursorx_ - offset > 20 &&
999 cursorx_ - offset + tabular.getWidthOfColumn(actcell)
1000 > bv.workWidth() - 20) {
1001 scroll(bv, - tabular.getWidthOfColumn(actcell) - 20);
1002 } else if (cursorx_ - offset < 20) {
1003 scroll(bv, 20 - cursorx_ + offset);
1004 } else if (scroll() && xo_ > 20 &&
1005 xo_ + tabular.getWidthOfTabular() > bv.workWidth() - 20) {
1006 scroll(bv, old_x - cursorx_);
1009 InsetTabularMailer(*this).updateDialog(&bv);
1013 void InsetTabular::moveNextCell(LCursor & cur)
1015 lyxerr << "InsetTabular::moveNextCell 1 cur: " << cur.top() << endl;
1016 if (isRightToLeft(cur)) {
1017 lyxerr << "InsetTabular::moveNextCell A cur: " << endl;
1018 if (tabular.isFirstCellInRow(cur.idx())) {
1019 int row = tabular.row_of_cell(cur.idx());
1020 if (row == tabular.rows() - 1)
1022 cur.idx() = tabular.getLastCellInRow(row);
1023 cur.idx() = tabular.getCellBelow(cur.idx());
1030 lyxerr << "InsetTabular::moveNextCell B cur: " << endl;
1031 if (tabular.isLastCell(cur.idx()))
1037 lyxerr << "InsetTabular::moveNextCell 2 cur: " << cur.top() << endl;
1042 void InsetTabular::movePrevCell(LCursor & cur)
1044 if (isRightToLeft(cur)) {
1045 if (tabular.isLastCellInRow(cur.idx())) {
1046 int row = tabular.row_of_cell(cur.idx());
1049 cur.idx() = tabular.getFirstCellInRow(row);
1050 cur.idx() = tabular.getCellAbove(cur.idx());
1052 if (tabular.isLastCell(cur.idx()))
1057 if (cur.idx() == 0) // first cell
1067 bool InsetTabular::tabularFeatures(LCursor & cur, string const & what)
1069 LyXTabular::Feature action = LyXTabular::LAST_ACTION;
1072 for (; tabularFeature[i].action != LyXTabular::LAST_ACTION; ++i) {
1073 string const tmp = tabularFeature[i].feature;
1075 if (tmp == what.substr(0, tmp.length())) {
1076 //if (!compare(tabularFeatures[i].feature.c_str(), what.c_str(),
1077 //tabularFeatures[i].feature.length())) {
1078 action = tabularFeature[i].action;
1082 if (action == LyXTabular::LAST_ACTION)
1086 ltrim(what.substr(tabularFeature[i].feature.length()));
1087 tabularFeatures(cur, action, val);
1094 void checkLongtableSpecial(LyXTabular::ltType & ltt,
1095 string const & special, bool & flag)
1097 if (special == "dl_above") {
1100 } else if (special == "dl_below") {
1101 ltt.bottomDL = flag;
1103 } else if (special == "empty") {
1115 void InsetTabular::tabularFeatures(LCursor & cur,
1116 LyXTabular::Feature feature, string const & value)
1118 BufferView & bv = cur.bv();
1119 int actcell = cur.idx();
1124 bool setLines = false;
1125 LyXAlignment setAlign = LYX_ALIGN_LEFT;
1126 LyXTabular::VAlignment setVAlign = LyXTabular::LYX_VALIGN_TOP;
1130 case LyXTabular::M_ALIGN_LEFT:
1131 case LyXTabular::ALIGN_LEFT:
1132 setAlign = LYX_ALIGN_LEFT;
1135 case LyXTabular::M_ALIGN_RIGHT:
1136 case LyXTabular::ALIGN_RIGHT:
1137 setAlign = LYX_ALIGN_RIGHT;
1140 case LyXTabular::M_ALIGN_CENTER:
1141 case LyXTabular::ALIGN_CENTER:
1142 setAlign = LYX_ALIGN_CENTER;
1145 case LyXTabular::ALIGN_BLOCK:
1146 setAlign = LYX_ALIGN_BLOCK;
1149 case LyXTabular::M_VALIGN_TOP:
1150 case LyXTabular::VALIGN_TOP:
1151 setVAlign = LyXTabular::LYX_VALIGN_TOP;
1154 case LyXTabular::M_VALIGN_BOTTOM:
1155 case LyXTabular::VALIGN_BOTTOM:
1156 setVAlign = LyXTabular::LYX_VALIGN_BOTTOM;
1159 case LyXTabular::M_VALIGN_MIDDLE:
1160 case LyXTabular::VALIGN_MIDDLE:
1161 setVAlign = LyXTabular::LYX_VALIGN_MIDDLE;
1168 recordUndo(cur, Undo::ATOMIC);
1170 getSelection(cur, sel_row_start, sel_row_end, sel_col_start, sel_col_end);
1171 int row = tabular.row_of_cell(actcell);
1172 int column = tabular.column_of_cell(actcell);
1174 LyXTabular::ltType ltt;
1178 case LyXTabular::SET_PWIDTH: {
1179 LyXLength const len(value);
1180 tabular.setColumnPWidth(actcell, len);
1182 && tabular.getAlignment(actcell, true) == LYX_ALIGN_BLOCK)
1183 tabularFeatures(cur, LyXTabular::ALIGN_CENTER, string());
1184 else if (!len.zero()
1185 && tabular.getAlignment(actcell, true) != LYX_ALIGN_BLOCK)
1186 tabularFeatures(cur, LyXTabular::ALIGN_BLOCK, string());
1190 case LyXTabular::SET_MPWIDTH:
1191 tabular.setMColumnPWidth(actcell, LyXLength(value));
1194 case LyXTabular::SET_SPECIAL_COLUMN:
1195 case LyXTabular::SET_SPECIAL_MULTI:
1196 tabular.setAlignSpecial(actcell,value,feature);
1199 case LyXTabular::APPEND_ROW:
1200 // append the row into the tabular
1201 tabular.appendRow(bv.buffer()->params(), actcell);
1204 case LyXTabular::APPEND_COLUMN:
1205 // append the column into the tabular
1206 tabular.appendColumn(bv.buffer()->params(), actcell);
1207 actcell = tabular.getCellNumber(row, column);
1210 case LyXTabular::DELETE_ROW:
1211 for (int i = sel_row_start; i <= sel_row_end; ++i)
1212 tabular.deleteRow(sel_row_start);
1213 if (sel_row_start >= tabular.rows())
1215 actcell = tabular.getCellNumber(sel_row_start, column);
1216 cur.selection() = false;
1219 case LyXTabular::DELETE_COLUMN:
1220 for (int i = sel_col_start; i <= sel_col_end; ++i)
1221 tabular.deleteColumn(sel_col_start);
1222 if (sel_col_start >= tabular.columns())
1224 actcell = tabular.getCellNumber(row, sel_col_start);
1225 cur.selection() = false;
1228 case LyXTabular::M_TOGGLE_LINE_TOP:
1230 case LyXTabular::TOGGLE_LINE_TOP: {
1231 bool lineSet = !tabular.topLine(actcell, flag);
1232 for (int i = sel_row_start; i <= sel_row_end; ++i)
1233 for (int j = sel_col_start; j <= sel_col_end; ++j)
1235 tabular.getCellNumber(i, j),
1240 case LyXTabular::M_TOGGLE_LINE_BOTTOM:
1242 case LyXTabular::TOGGLE_LINE_BOTTOM: {
1243 bool lineSet = !tabular.bottomLine(actcell, flag);
1244 for (int i = sel_row_start; i <= sel_row_end; ++i)
1245 for (int j = sel_col_start; j <= sel_col_end; ++j)
1246 tabular.setBottomLine(
1247 tabular.getCellNumber(i, j),
1253 case LyXTabular::M_TOGGLE_LINE_LEFT:
1255 case LyXTabular::TOGGLE_LINE_LEFT: {
1256 bool lineSet = !tabular.leftLine(actcell, 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.setLeftLine(
1260 tabular.getCellNumber(i,j),
1266 case LyXTabular::M_TOGGLE_LINE_RIGHT:
1268 case LyXTabular::TOGGLE_LINE_RIGHT: {
1269 bool lineSet = !tabular.rightLine(actcell, 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.setRightLine(
1273 tabular.getCellNumber(i,j),
1279 case LyXTabular::M_ALIGN_LEFT:
1280 case LyXTabular::M_ALIGN_RIGHT:
1281 case LyXTabular::M_ALIGN_CENTER:
1283 case LyXTabular::ALIGN_LEFT:
1284 case LyXTabular::ALIGN_RIGHT:
1285 case LyXTabular::ALIGN_CENTER:
1286 case LyXTabular::ALIGN_BLOCK:
1287 for (int i = sel_row_start; i <= sel_row_end; ++i)
1288 for (int j = sel_col_start; j <= sel_col_end; ++j)
1289 tabular.setAlignment(
1290 tabular.getCellNumber(i, j),
1295 case LyXTabular::M_VALIGN_TOP:
1296 case LyXTabular::M_VALIGN_BOTTOM:
1297 case LyXTabular::M_VALIGN_MIDDLE:
1299 case LyXTabular::VALIGN_TOP:
1300 case LyXTabular::VALIGN_BOTTOM:
1301 case LyXTabular::VALIGN_MIDDLE:
1302 for (int i = sel_row_start; i <= sel_row_end; ++i)
1303 for (int j = sel_col_start; j <= sel_col_end; ++j)
1304 tabular.setVAlignment(
1305 tabular.getCellNumber(i, j),
1309 case LyXTabular::MULTICOLUMN: {
1310 if (sel_row_start != sel_row_end) {
1311 #ifdef WITH_WARNINGS
1312 #warning Need I say it ? This is horrible.
1314 Alert::error(_("Error setting multicolumn"),
1315 _("You cannot set multicolumn vertically."));
1319 // just multicol for one Single Cell
1320 if (!hasSelection()) {
1321 // check wether we are completly in a multicol
1322 if (tabular.isMultiColumn(actcell))
1323 tabular.unsetMultiColumn(actcell);
1325 tabular.setMultiColumn(bv.buffer(), actcell, 1);
1328 // we have a selection so this means we just add all this
1329 // cells to form a multicolumn cell
1333 if (sel_cell_start > sel_cell_end) {
1334 s_start = sel_cell_end;
1335 s_end = sel_cell_start;
1337 s_start = sel_cell_start;
1338 s_end = sel_cell_end;
1340 tabular.setMultiColumn(bv.buffer(), s_start, s_end - s_start + 1);
1343 cur.selection() = false;
1347 case LyXTabular::SET_ALL_LINES:
1349 case LyXTabular::UNSET_ALL_LINES:
1351 for (int i = sel_row_start; i <= sel_row_end; ++i)
1352 for (int j = sel_col_start; j <= sel_col_end; ++j)
1353 tabular.setAllLines(
1354 tabular.getCellNumber(i,j), setLines);
1358 case LyXTabular::SET_LONGTABULAR:
1359 tabular.setLongTabular(true);
1362 case LyXTabular::UNSET_LONGTABULAR:
1363 tabular.setLongTabular(false);
1366 case LyXTabular::SET_ROTATE_TABULAR:
1367 tabular.setRotateTabular(true);
1370 case LyXTabular::UNSET_ROTATE_TABULAR:
1371 tabular.setRotateTabular(false);
1374 case LyXTabular::SET_ROTATE_CELL:
1375 for (int i = sel_row_start; i <= sel_row_end; ++i)
1376 for (int j = sel_col_start; j <= sel_col_end; ++j)
1377 tabular.setRotateCell(
1378 tabular.getCellNumber(i, j), true);
1381 case LyXTabular::UNSET_ROTATE_CELL:
1382 for (int i = sel_row_start; i <= sel_row_end; ++i)
1383 for (int j = sel_col_start; j <= sel_col_end; ++j)
1384 tabular.setRotateCell(
1385 tabular.getCellNumber(i, j), false);
1388 case LyXTabular::SET_USEBOX: {
1389 LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
1390 if (val == tabular.getUsebox(actcell))
1391 val = LyXTabular::BOX_NONE;
1392 for (int i = sel_row_start; i <= sel_row_end; ++i)
1393 for (int j = sel_col_start; j <= sel_col_end; ++j)
1394 tabular.setUsebox(tabular.getCellNumber(i, j), val);
1398 case LyXTabular::UNSET_LTFIRSTHEAD:
1400 case LyXTabular::SET_LTFIRSTHEAD:
1401 tabular.getRowOfLTFirstHead(row, ltt);
1402 checkLongtableSpecial(ltt, value, flag);
1403 tabular.setLTHead(row, flag, ltt, true);
1406 case LyXTabular::UNSET_LTHEAD:
1408 case LyXTabular::SET_LTHEAD:
1409 tabular.getRowOfLTHead(row, ltt);
1410 checkLongtableSpecial(ltt, value, flag);
1411 tabular.setLTHead(row, flag, ltt, false);
1414 case LyXTabular::UNSET_LTFOOT:
1416 case LyXTabular::SET_LTFOOT:
1417 tabular.getRowOfLTFoot(row, ltt);
1418 checkLongtableSpecial(ltt, value, flag);
1419 tabular.setLTFoot(row, flag, ltt, false);
1422 case LyXTabular::UNSET_LTLASTFOOT:
1424 case LyXTabular::SET_LTLASTFOOT:
1425 tabular.getRowOfLTLastFoot(row, ltt);
1426 checkLongtableSpecial(ltt, value, flag);
1427 tabular.setLTFoot(row, flag, ltt, true);
1430 case LyXTabular::SET_LTNEWPAGE:
1431 tabular.setLTNewPage(row, !tabular.getLTNewPage(row));
1434 // dummy stuff just to avoid warnings
1435 case LyXTabular::LAST_ACTION:
1439 InsetTabularMailer(*this).updateDialog(&bv);
1443 bool InsetTabular::showInsetDialog(BufferView * bv) const
1445 InsetTabularMailer(*this).showDialog(bv);
1450 void InsetTabular::openLayoutDialog(BufferView * bv) const
1452 InsetTabularMailer(*this).showDialog(bv);
1456 void InsetTabular::getLabelList(Buffer const & buffer,
1457 vector<string> & list) const
1459 tabular.getLabelList(buffer, list);
1463 bool InsetTabular::copySelection(LCursor & cur)
1465 if (!cur.selection())
1469 getSelection(cur, rs, re, cs, ce);
1471 paste_tabular.reset(new LyXTabular(tabular));
1473 for (int i = 0; i < rs; ++i)
1474 paste_tabular->deleteRow(0);
1476 int const rows = re - rs + 1;
1477 while (paste_tabular->rows() > rows)
1478 paste_tabular->deleteRow(rows);
1480 paste_tabular->setTopLine(0, true, true);
1481 paste_tabular->setBottomLine(paste_tabular->getFirstCellInRow(rows - 1),
1484 for (int i = 0; i < cs; ++i)
1485 paste_tabular->deleteColumn(0);
1487 int const columns = ce - cs + 1;
1488 while (paste_tabular->columns() > columns)
1489 paste_tabular->deleteColumn(columns);
1491 paste_tabular->setLeftLine(0, true, true);
1492 paste_tabular->setRightLine(paste_tabular->getLastCellInRow(0),
1496 OutputParams const runparams;
1497 paste_tabular->plaintext(*cur.bv().buffer(), os, runparams, 0, true, '\t');
1498 cur.bv().stuffClipboard(os.str());
1503 bool InsetTabular::pasteSelection(LCursor & cur)
1507 int actcell = cur.idx();
1508 int actcol = tabular.column_of_cell(actcell);
1509 int actrow = tabular.row_of_cell(actcell);
1510 for (int r1 = 0, r2 = actrow;
1511 r1 < paste_tabular->rows() && r2 < tabular.rows();
1513 for (int c1 = 0, c2 = actcol;
1514 c1 < paste_tabular->columns() && c2 < tabular.columns();
1516 if (paste_tabular->isPartOfMultiColumn(r1, c1) &&
1517 tabular.isPartOfMultiColumn(r2, c2))
1519 if (paste_tabular->isPartOfMultiColumn(r1, c1)) {
1523 if (tabular.isPartOfMultiColumn(r2, c2)) {
1527 InsetText & inset = tabular.getCellInset(r2, c2);
1528 inset = paste_tabular->getCellInset(r1, c1);
1536 void InsetTabular::cutSelection(LCursor & cur)
1538 if (!cur.selection())
1541 bool const track = cur.bv().buffer()->params().tracking_changes;
1543 getSelection(cur, rs, re, cs, ce);
1544 for (int i = rs; i <= re; ++i)
1545 for (int j = cs; j <= ce; ++j)
1546 cell(tabular.getCellNumber(i, j)).clear(track);
1550 bool InsetTabular::isRightToLeft(LCursor & cur)
1552 return cur.bv().getParentLanguage(this)->RightToLeft();
1556 void InsetTabular::getSelection(LCursor & cur,
1557 int & rs, int & re, int & cs, int & ce) const
1559 CursorSlice const & beg = cur.selBegin();
1560 CursorSlice const & end = cur.selEnd();
1561 cs = tabular.column_of_cell(beg.idx());
1562 ce = tabular.column_of_cell(end.idx());
1565 cs = tabular.column_of_cell(end.idx());
1567 ce = tabular.right_column_of_cell(end.idx());
1570 rs = tabular.row_of_cell(beg.idx());
1571 re = tabular.row_of_cell(end.idx());
1577 size_t InsetTabular::nargs() const
1579 return tabular.getNumberOfCells();
1583 LyXText * InsetTabular::getText(int idx) const
1585 return size_t(idx) < nargs() ? cell(idx).getText(0) : 0;
1589 void InsetTabular::markErased()
1591 for (idx_type idx = 0; idx < nargs(); ++idx)
1592 cell(idx).markErased();
1596 bool InsetTabular::forceDefaultParagraphs(InsetBase const *) const
1599 const int cell = tabular.getCellFromInset(in);
1602 return tabular.getPWidth(cell).zero();
1604 // this is a workaround for a crash (New, Insert->Tabular,
1605 // Insert->FootNote)
1609 // well we didn't obviously find it so maybe our owner knows more
1610 BOOST_ASSERT(owner());
1611 return owner()->forceDefaultParagraphs(in);
1617 bool InsetTabular::insertAsciiString(BufferView & bv, string const & buf,
1620 if (buf.length() <= 0)
1626 string::size_type len = buf.length();
1627 string::size_type p = 0;
1629 int actcell = bv.cursor().idx();
1630 int actcol = tabular.column_of_cell(actcell);
1631 int actrow = tabular.row_of_cell(actcell);
1633 while (p < len && (p = buf.find_first_of("\t\n", p)) != string::npos) {
1641 maxCols = max(cols, maxCols);
1647 maxCols = max(cols, maxCols);
1648 LyXTabular * loctab;
1653 paste_tabular.reset(
1654 new LyXTabular(bv.buffer()->params(), rows, maxCols));
1655 loctab = paste_tabular.get();
1664 string::size_type op = 0;
1665 int cells = loctab->getNumberOfCells();
1668 rows = loctab->rows();
1669 int const columns = loctab->columns();
1671 while (cell < cells && p < len && row < rows &&
1672 (p = buf.find_first_of("\t\n", p)) != string::npos)
1678 // we can only set this if we are not too far right
1679 if (cols < columns) {
1680 InsetText & inset = loctab->getCellInset(cell);
1681 LyXFont const font = inset.text_.getFont(0, 0);
1682 inset.setText(buf.substr(op, p - op), font);
1688 // we can only set this if we are not too far right
1689 if (cols < columns) {
1690 InsetText & inset = tabular.getCellInset(cell);
1691 LyXFont const font = inset.text_.getFont(0, 0);
1692 inset.setText(buf.substr(op, p - op), font);
1697 cell = loctab->getCellNumber(row, cols);
1703 // check for the last cell if there is no trailing '\n'
1704 if (cell < cells && op < len) {
1705 InsetText & inset = loctab->getCellInset(cell);
1706 LyXFont const font = inset.text_.getFont(0, 0);
1707 inset.setText(buf.substr(op, len - op), font);
1713 void InsetTabular::addPreview(PreviewLoader & loader) const
1715 int const rows = tabular.rows();
1716 int const columns = tabular.columns();
1717 for (int i = 0; i < rows; ++i) {
1718 for (int j = 0; j < columns; ++j)
1719 tabular.getCellInset(i, j).addPreview(loader);
1724 bool InsetTabular::tablemode(LCursor & cur) const
1726 return cur.selBegin().idx() != cur.selEnd().idx();
1733 string const InsetTabularMailer::name_("tabular");
1735 InsetTabularMailer::InsetTabularMailer(InsetTabular const & inset)
1736 : inset_(const_cast<InsetTabular &>(inset))
1740 string const InsetTabularMailer::inset2string(Buffer const &) const
1742 return params2string(inset_);
1746 int InsetTabularMailer::string2params(string const & in, InsetTabular & inset)
1748 istringstream data(in);
1750 lex.setStream(data);
1752 #warning CHECK verify that this is a sane value to return.
1758 string const token = lex.getString();
1766 string const token = lex.getString();
1767 if (token != "\\active_cell")
1770 cell = lex.getInteger();
1773 // This is part of the inset proper that is usually swallowed
1774 // by Buffer::readInset
1777 string const token = lex.getString();
1778 if (token != "Tabular")
1785 Buffer const & buffer = inset.buffer();
1786 inset.read(buffer, lex);
1788 // We can't set the active cell, but we can tell the frontend
1794 string const InsetTabularMailer::params2string(InsetTabular const & inset)
1798 //data << name_ << " \\active_cell " << inset.getActCell() << '\n';
1799 data << name_ << " \\active_cell " << 0 << '\n';
1800 inset.write(inset.buffer(), data);
1801 data << "\\end_inset\n";