2 * \file math_gridinset.C
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 "math_gridinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16 #include "math_streamstr.h"
18 #include "funcrequest.h"
19 #include "frontends/Painter.h"
20 #include "support/std_sstream.h"
23 #include "insets/mailinset.h"
30 using std::istringstream;
31 using std::ostringstream;
36 class GridInsetMailer : public MailInset {
38 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
40 virtual string const & name() const
42 static string const theName = "tabular";
46 virtual string const inset2string(Buffer const &) const
49 //data << name() << " active_cell " << inset.getActCell() << '\n';
50 data << name() << " active_cell " << 0 << '\n';
53 return STRCONV(data.str());
57 InsetBase & inset() const { return inset_; }
58 MathGridInset & inset_;
62 void mathed_parse_normal(MathGridInset &, string const & argument);
66 string verboseHLine(int n)
69 for (int i = 0; i < n; ++i)
77 int extractInt(istream & is)
81 return (num == 0) ? 1 : num;
87 //////////////////////////////////////////////////////////////
90 MathGridInset::CellInfo::CellInfo()
97 //////////////////////////////////////////////////////////////
100 MathGridInset::RowInfo::RowInfo()
101 : lines_(0), skip_(0)
106 int MathGridInset::RowInfo::skipPixels() const
108 return crskip_.inBP();
113 //////////////////////////////////////////////////////////////
116 MathGridInset::ColInfo::ColInfo()
117 : align_('c'), leftline_(false), rightline_(false), lines_(0)
121 //////////////////////////////////////////////////////////////
124 MathGridInset::MathGridInset(char v, string const & h)
125 : MathNestInset(guessColumns(h)),
127 colinfo_(guessColumns(h) + 1),
128 cellinfo_(1 * guessColumns(h))
133 //lyxerr << "created grid with " << ncols() << " columns" << endl;
137 MathGridInset::MathGridInset()
148 MathGridInset::MathGridInset(col_type m, row_type n)
149 : MathNestInset(m * n),
159 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
160 : MathNestInset(m * n),
172 MathGridInset::~MathGridInset()
174 GridInsetMailer mailer(*this);
179 auto_ptr<InsetBase> MathGridInset::clone() const
181 return auto_ptr<InsetBase>(new MathGridInset(*this));
185 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
187 return col + ncols() * row;
191 void MathGridInset::setDefaults()
194 lyxerr << "positive number of columns expected" << endl;
196 // lyxerr << "positive number of rows expected" << endl;
197 for (col_type col = 0; col < ncols(); ++col) {
198 colinfo_[col].align_ = defaultColAlign(col);
199 colinfo_[col].skip_ = defaultColSpace(col);
204 void MathGridInset::halign(string const & hh)
207 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
212 colinfo_[col].lines_++;
213 } else if (c == 'c' || c == 'l' || c == 'r') {
214 colinfo_[col].align_ = c;
216 colinfo_[col].lines_ = 0;
218 lyxerr << "unknown column separator: '" << c << "'" << endl;
223 col_type n = hh.size();
226 for (col_type col = 0; col < n; ++col)
227 colinfo_[col].align_ = hh[col];
232 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
235 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
236 if (*it == 'c' || *it == 'l' || *it == 'r')
238 // let's have at least one column, even if we did not recognize its
246 void MathGridInset::halign(char h, col_type col)
248 colinfo_[col].align_ = h;
252 char MathGridInset::halign(col_type col) const
254 return colinfo_[col].align_;
258 string MathGridInset::halign() const
261 for (col_type col = 0; col < ncols(); ++col) {
262 res += string(colinfo_[col].lines_, '|');
263 res += colinfo_[col].align_;
265 return res + string(colinfo_[ncols()].lines_, '|');
269 void MathGridInset::valign(char c)
275 char MathGridInset::valign() const
281 MathGridInset::col_type MathGridInset::ncols() const
283 return colinfo_.size() - 1;
287 MathGridInset::row_type MathGridInset::nrows() const
289 return rowinfo_.size() - 1;
293 MathGridInset::col_type MathGridInset::col(idx_type idx) const
295 return idx % ncols();
299 MathGridInset::row_type MathGridInset::row(idx_type idx) const
301 return idx / ncols();
305 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
307 rowinfo_[row].crskip_ = crskip;
311 LyXLength MathGridInset::vcrskip(row_type row) const
313 return rowinfo_[row].crskip_;
317 void MathGridInset::metrics(MetricsInfo & mi) const
319 // let the cells adjust themselves
320 MathNestInset::metrics(mi);
322 // compute absolute sizes of vertical structure
323 for (row_type row = 0; row < nrows(); ++row) {
326 for (col_type col = 0; col < ncols(); ++col) {
327 MathArray const & c = cell(index(row, col));
328 asc = max(asc, c.ascent());
329 desc = max(desc, c.descent());
331 rowinfo_[row].ascent_ = asc;
332 rowinfo_[row].descent_ = desc;
334 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
335 rowinfo_[nrows()].ascent_ = 0;
336 rowinfo_[nrows()].descent_ = 0;
338 // compute vertical offsets
339 rowinfo_[0].offset_ = 0;
340 for (row_type row = 1; row <= nrows(); ++row) {
341 rowinfo_[row].offset_ =
342 rowinfo_[row - 1].offset_ +
343 rowinfo_[row - 1].descent_ +
344 rowinfo_[row - 1].skipPixels() +
346 rowinfo_[row].lines_ * hlinesep() +
347 rowinfo_[row].ascent_;
350 // adjust vertical offset
357 h = rowinfo_[nrows() - 1].offset_;
360 h = rowinfo_[nrows() - 1].offset_ / 2;
362 for (row_type row = 0; row <= nrows(); ++row)
363 rowinfo_[row].offset_ -= h;
366 // compute absolute sizes of horizontal structure
367 for (col_type col = 0; col < ncols(); ++col) {
369 for (row_type row = 0; row < nrows(); ++row)
370 wid = max(wid, cell(index(row, col)).width());
371 colinfo_[col].width_ = wid;
373 colinfo_[ncols()].width_ = 0;
375 // compute horizontal offsets
376 colinfo_[0].offset_ = border();
377 for (col_type col = 1; col <= ncols(); ++col) {
378 colinfo_[col].offset_ =
379 colinfo_[col - 1].offset_ +
380 colinfo_[col - 1].width_ +
381 colinfo_[col - 1].skip_ +
383 colinfo_[col].lines_ * vlinesep();
387 dim_.wid = colinfo_[ncols() - 1].offset_
388 + colinfo_[ncols() - 1].width_
389 + vlinesep() * colinfo_[ncols()].lines_
392 dim_.asc = - rowinfo_[0].offset_
393 + rowinfo_[0].ascent_
394 + hlinesep() * rowinfo_[0].lines_
397 dim_.des = rowinfo_[nrows() - 1].offset_
398 + rowinfo_[nrows() - 1].descent_
399 + hlinesep() * rowinfo_[nrows()].lines_
404 // Increase ws_[i] for 'R' columns (except the first one)
405 for (int i = 1; i < nc_; ++i)
406 if (align_[i] == 'R')
407 ws_[i] += 10 * df_width;
408 // Increase ws_[i] for 'C' column
409 if (align_[0] == 'C')
410 if (ws_[0] < 7 * workwidth / 8)
411 ws_[0] = 7 * workwidth / 8;
415 for (cxrow = row_.begin(); cxrow; ++cxrow) {
418 for (int i = 0; i < nc_; ++i) {
420 if (cxrow->getTab(i) <= 0) {
421 cxrow->setTab(i, df_width);
429 lf = (ws_[i] - cxrow->getTab(i))/2;
433 lf = ws_[i] - cxrow->getTab(i);
436 if (cxrow == row_.begin())
438 else if (cxrow.is_last())
439 lf = ws_[i] - cxrow->getTab(i);
441 lf = (ws_[i] - cxrow->getTab(i))/2;
444 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
445 cxrow->setTab(i, lf + rg);
446 rg = ws_[i] - ww + colsep();
447 if (cxrow == row_.begin())
448 width += ws_[i] + colsep();
450 cxrow->setBaseline(cxrow->getBaseline() - ascent);
456 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
463 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
465 for (idx_type idx = 0; idx < nargs(); ++idx)
466 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
468 for (row_type row = 0; row <= nrows(); ++row)
469 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
470 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
471 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
472 pi.pain.line(x + 1, yy, x + dim_.width() - 1, yy);
475 for (col_type col = 0; col <= ncols(); ++col)
476 for (int i = 0; i < colinfo_[col].lines_; ++i) {
477 int xx = x + colinfo_[col].offset_
478 - i * vlinesep() - vlinesep()/2 - colsep()/2;
479 pi.pain.line(xx, y - dim_.ascent() + 1, xx, y + dim_.descent() - 1);
484 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
486 // let the cells adjust themselves
487 //MathNestInset::metrics(mi);
488 for (idx_type i = 0; i < nargs(); ++i)
489 cell(i).metricsT(mi, dim);
491 // compute absolute sizes of vertical structure
492 for (row_type row = 0; row < nrows(); ++row) {
495 for (col_type col = 0; col < ncols(); ++col) {
496 MathArray const & c = cell(index(row, col));
497 asc = max(asc, c.ascent());
498 desc = max(desc, c.descent());
500 rowinfo_[row].ascent_ = asc;
501 rowinfo_[row].descent_ = desc;
503 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
504 rowinfo_[nrows()].ascent_ = 0;
505 rowinfo_[nrows()].descent_ = 0;
507 // compute vertical offsets
508 rowinfo_[0].offset_ = 0;
509 for (row_type row = 1; row <= nrows(); ++row) {
510 rowinfo_[row].offset_ =
511 rowinfo_[row - 1].offset_ +
512 rowinfo_[row - 1].descent_ +
513 //rowinfo_[row - 1].skipPixels() +
515 //rowinfo_[row].lines_ * hlinesep() +
516 rowinfo_[row].ascent_;
519 // adjust vertical offset
526 h = rowinfo_[nrows() - 1].offset_;
529 h = rowinfo_[nrows() - 1].offset_ / 2;
531 for (row_type row = 0; row <= nrows(); ++row)
532 rowinfo_[row].offset_ -= h;
535 // compute absolute sizes of horizontal structure
536 for (col_type col = 0; col < ncols(); ++col) {
538 for (row_type row = 0; row < nrows(); ++row)
539 wid = max(wid, cell(index(row, col)).width());
540 colinfo_[col].width_ = wid;
542 colinfo_[ncols()].width_ = 0;
544 // compute horizontal offsets
545 colinfo_[0].offset_ = border();
546 for (col_type col = 1; col <= ncols(); ++col) {
547 colinfo_[col].offset_ =
548 colinfo_[col - 1].offset_ +
549 colinfo_[col - 1].width_ +
550 colinfo_[col - 1].skip_ +
552 //colinfo_[col].lines_ * vlinesep();
556 dim.wid = colinfo_[ncols() - 1].offset_
557 + colinfo_[ncols() - 1].width_
558 //+ vlinesep() * colinfo_[ncols()].lines_
561 dim.asc = -rowinfo_[0].offset_
562 + rowinfo_[0].ascent_
563 //+ hlinesep() * rowinfo_[0].lines_
566 dim.des = rowinfo_[nrows() - 1].offset_
567 + rowinfo_[nrows() - 1].descent_
568 //+ hlinesep() * rowinfo_[nrows()].lines_
573 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
575 for (idx_type idx = 0; idx < nargs(); ++idx)
576 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
580 string MathGridInset::eolString(row_type row, bool fragile) const
584 if (!rowinfo_[row].crskip_.zero())
585 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
587 // make sure an upcoming '[' does not break anything
588 if (row + 1 < nrows()) {
589 MathArray const & c = cell(index(row + 1, 0));
590 if (c.size() && c.front()->getChar() == '[')
595 // only add \\ if necessary
596 if (eol.empty() && row + 1 == nrows())
599 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
603 string MathGridInset::eocString(col_type col, col_type lastcol) const
605 if (col + 1 == lastcol)
611 void MathGridInset::addRow(row_type row)
613 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
615 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
617 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
621 void MathGridInset::appendRow()
623 rowinfo_.push_back(RowInfo());
624 //cells_.insert(cells_.end(), ncols(), MathArray());
625 for (col_type col = 0; col < ncols(); ++col) {
626 cells_.push_back(cells_type::value_type());
627 cellinfo_.push_back(CellInfo());
632 void MathGridInset::delRow(row_type row)
637 cells_type::iterator it = cells_.begin() + row * ncols();
638 cells_.erase(it, it + ncols());
640 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
641 cellinfo_.erase(jt, jt + ncols());
643 rowinfo_.erase(rowinfo_.begin() + row);
647 void MathGridInset::copyRow(row_type row)
650 for (col_type col = 0; col < ncols(); ++col)
651 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
655 void MathGridInset::swapRow(row_type row)
659 if (row + 1 == nrows())
661 for (col_type col = 0; col < ncols(); ++col)
662 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
666 void MathGridInset::addCol(col_type newcol)
668 const col_type nc = ncols();
669 const row_type nr = nrows();
670 cells_type new_cells((nc + 1) * nr);
671 vector<CellInfo> new_cellinfo((nc + 1) * nr);
673 for (row_type row = 0; row < nr; ++row)
674 for (col_type col = 0; col < nc; ++col) {
675 new_cells[row * (nc + 1) + col + (col > newcol)]
676 = cells_[row * nc + col];
677 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
678 = cellinfo_[row * nc + col];
680 swap(cells_, new_cells);
681 swap(cellinfo_, new_cellinfo);
684 inf.skip_ = defaultColSpace(newcol);
685 inf.align_ = defaultColAlign(newcol);
686 colinfo_.insert(colinfo_.begin() + newcol, inf);
690 void MathGridInset::delCol(col_type col)
696 vector<CellInfo> tmpcellinfo;
697 for (col_type i = 0; i < nargs(); ++i)
698 if (i % ncols() != col) {
699 tmpcells.push_back(cells_[i]);
700 tmpcellinfo.push_back(cellinfo_[i]);
702 swap(cells_, tmpcells);
703 swap(cellinfo_, tmpcellinfo);
705 colinfo_.erase(colinfo_.begin() + col);
709 void MathGridInset::copyCol(col_type col)
712 for (row_type row = 0; row < nrows(); ++row)
713 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
717 void MathGridInset::swapCol(col_type col)
721 if (col + 1 == ncols())
723 for (row_type row = 0; row < nrows(); ++row)
724 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
728 int MathGridInset::cellXOffset(idx_type idx) const
730 col_type c = col(idx);
731 int x = colinfo_[c].offset_;
732 char align = colinfo_[c].align_;
733 if (align == 'r' || align == 'R')
734 x += colinfo_[c].width_ - cell(idx).width();
735 if (align == 'c' || align == 'C')
736 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
741 int MathGridInset::cellYOffset(idx_type idx) const
743 return rowinfo_[row(idx)].offset_;
747 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
754 pos = cell(idx).x2pos(targetx - cell(idx).xo());
757 if (idx >= ncols() * (nrows() - 1))
760 pos = cell(idx).x2pos(targetx - cell(idx).xo());
766 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
768 // leave matrix if on the left hand edge
772 pos = cell(idx).size();
777 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
779 // leave matrix if on the right hand edge
780 if (col(idx) + 1 == ncols())
788 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
795 idx = (nrows() - 1) * ncols();
798 idx = ((nrows() - 1) / 2) * ncols();
805 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
815 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
817 pos = cell(idx).size();
822 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
829 idx -= idx % ncols();
842 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
844 if (pos < cell(idx).size()) {
845 pos = cell(idx).size();
848 if (col(idx) < ncols() - 1) {
849 idx = idx - idx % ncols() + ncols() - 1;
850 pos = cell(idx).size();
853 if (idx < nargs() - 1) {
855 pos = cell(idx).size();
862 bool MathGridInset::idxDelete(idx_type & idx)
864 // nothing to do if we have just one row
868 // nothing to do if we are in the middle of the last row of the inset
869 if (idx + ncols() > nargs())
872 // try to delete entire sequence of ncols() empty cells if possible
873 for (idx_type i = idx; i < idx + ncols(); ++i)
877 // move cells if necessary
878 for (idx_type i = index(row(idx), 0); i < idx; ++i)
879 std::swap(cell(i), cell(i + ncols()));
886 // undo effect of Ctrl-Tab (i.e. pull next cell)
887 //if (idx + 1 != nargs())
888 // cell(idx).swap(cell(idx + 1));
890 // we handled the event..
895 // reimplement old behaviour when pressing Delete in the last position
897 void MathGridInset::idxGlue(idx_type idx)
899 col_type c = col(idx);
900 if (c + 1 == ncols()) {
901 if (row(idx) + 1 != nrows()) {
902 for (col_type cc = 0; cc < ncols(); ++cc)
903 cell(idx).append(cell(idx + cc + 1));
904 delRow(row(idx) + 1);
907 cell(idx).append(cell(idx + 1));
908 for (col_type cc = c + 2; cc < ncols(); ++cc)
909 cell(idx - c + cc - 1) = cell(idx - c + cc);
910 cell(idx - c + ncols() - 1).clear();
915 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
917 return rowinfo_[row];
921 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
923 return rowinfo_[row];
927 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
929 row_type const ri = row(idx);
930 row_type const r1 = min(row(from), row(to));
931 row_type const r2 = max(row(from), row(to));
932 col_type const ci = col(idx);
933 col_type const c1 = min(col(from), col(to));
934 col_type const c2 = max(col(from), col(to));
935 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
940 void MathGridInset::normalize(NormalStream & os) const
943 for (row_type row = 0; row < nrows(); ++row) {
945 for (col_type col = 0; col < ncols(); ++col)
946 os << "[cell " << cell(index(row, col)) << ']';
953 void MathGridInset::mathmlize(MathMLStream & os) const
955 os << MTag("mtable");
956 for (row_type row = 0; row < nrows(); ++row) {
958 for (col_type col = 0; col < ncols(); ++col)
959 os << cell(index(row, col));
962 os << ETag("mtable");
966 void MathGridInset::write(WriteStream & os) const
968 for (row_type row = 0; row < nrows(); ++row) {
969 os << verboseHLine(rowinfo_[row].lines_);
970 // don't write & and empty cells at end of line
971 col_type lastcol = 0;
972 bool emptyline = true;
973 for (col_type col = 0; col < ncols(); ++col)
974 if (!cell(index(row, col)).empty()) {
978 for (col_type col = 0; col < lastcol; ++col)
979 os << cell(index(row, col)) << eocString(col, lastcol);
980 os << eolString(row, os.fragile());
981 // append newline only if line wasn't completely empty
982 // and this was not the last line in the grid
983 if (!emptyline && row + 1 < nrows())
986 string const s = verboseHLine(rowinfo_[nrows()].lines_);
987 if (!s.empty() && s != " ") {
995 int MathGridInset::colsep() const
1001 int MathGridInset::rowsep() const
1007 int MathGridInset::hlinesep() const
1013 int MathGridInset::vlinesep() const
1019 int MathGridInset::border() const
1025 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1027 if (idx + 1 == nargs())
1029 MathArray ar = cell(idx);
1031 cell(idx).erase(pos, cell(idx).size());
1034 cell(idx).insert(0, ar);
1038 dispatch_result MathGridInset::dispatch
1039 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1041 switch (cmd.action) {
1043 case LFUN_MOUSE_RELEASE:
1044 //if (cmd.button() == mouse_button::button3) {
1045 // GridInsetMailer(*this).showDialog();
1046 // return DISPATCHED;
1048 return UNDISPATCHED;
1050 case LFUN_INSET_DIALOG_UPDATE:
1051 GridInsetMailer(*this).updateDialog(cmd.view());
1052 return UNDISPATCHED;
1054 // insert file functions
1055 case LFUN_DELETE_LINE_FORWARD:
1056 //autocorrect_ = false;
1066 if (pos > cell(idx).size())
1067 pos = cell(idx).size();
1068 return DISPATCHED_POP;
1070 case LFUN_CELL_SPLIT:
1071 //recordUndo(bv, Undo::ATOMIC);
1072 splitCell(idx, pos);
1073 return DISPATCHED_POP;
1075 case LFUN_BREAKLINE: {
1076 //recordUndo(bv, Undo::INSERT);
1077 row_type const r = row(idx);
1081 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1082 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1085 splitCell(idx, pos);
1086 std::swap(cell(idx), cell(idx + ncols() - 1));
1089 pos = cell(idx).size();
1091 //mathcursor->normalize();
1092 return DISPATCHED_POP;
1095 case LFUN_TABULAR_FEATURE: {
1096 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1097 istringstream is(STRCONV(cmd.argument));
1100 if (s == "valign-top")
1102 else if (s == "valign-middle")
1104 else if (s == "valign-bottom")
1106 else if (s == "align-left")
1107 halign('l', col(idx));
1108 else if (s == "align-right")
1109 halign('r', col(idx));
1110 else if (s == "align-center")
1111 halign('c', col(idx));
1112 else if (s == "append-row")
1113 for (int i = 0, n = extractInt(is); i < n; ++i)
1115 else if (s == "delete-row")
1116 for (int i = 0, n = extractInt(is); i < n; ++i) {
1121 else if (s == "copy-row")
1122 for (int i = 0, n = extractInt(is); i < n; ++i)
1124 else if (s == "swap-row")
1126 else if (s == "append-column")
1127 for (int i = 0, n = extractInt(is); i < n; ++i) {
1128 row_type r = row(idx);
1129 col_type c = col(idx);
1133 else if (s == "delete-column")
1134 for (int i = 0, n = extractInt(is); i < n; ++i) {
1135 row_type r = row(idx);
1136 col_type c = col(idx);
1142 else if (s == "copy-column")
1144 else if (s == "swap-column")
1147 return UNDISPATCHED;
1148 lyxerr << "returning DISPATCHED_POP" << endl;
1149 return DISPATCHED_POP;
1153 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1154 MathGridInset grid(1, 1);
1155 mathed_parse_normal(grid, cmd.argument);
1156 if (grid.nargs() == 1) {
1157 // single cell/part of cell
1158 cell(idx).insert(pos, grid.cell(0));
1159 pos += grid.cell(0).size();
1162 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1163 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1164 for (row_type r = 0; r < numrows; ++r) {
1165 for (col_type c = 0; c < numcols; ++c) {
1166 idx_type i = index(r + row(idx), c + col(idx));
1167 cell(i).append(grid.cell(grid.index(r, c)));
1169 // append the left over horizontal cells to the last column
1170 idx_type i = index(r + row(idx), ncols() - 1);
1171 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1172 cell(i).append(grid.cell(grid.index(r, c)));
1174 // append the left over vertical cells to the last _cell_
1175 idx_type i = nargs() - 1;
1176 for (row_type r = numrows; r < grid.nrows(); ++r)
1177 for (col_type c = 0; c < grid.ncols(); ++c)
1178 cell(i).append(grid.cell(grid.index(r, c)));
1180 return DISPATCHED_POP;
1184 return MathNestInset::dispatch(cmd, idx, pos);