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"
22 #include "insets/mailinset.h"
31 using std::istringstream;
32 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';
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,
473 x + dim_.width() - 1, yy,
477 for (col_type col = 0; col <= ncols(); ++col)
478 for (int i = 0; i < colinfo_[col].lines_; ++i) {
479 int xx = x + colinfo_[col].offset_
480 - i * vlinesep() - vlinesep()/2 - colsep()/2;
481 pi.pain.line(xx, y - dim_.ascent() + 1,
482 xx, y + dim_.descent() - 1,
488 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
490 // let the cells adjust themselves
491 //MathNestInset::metrics(mi);
492 for (idx_type i = 0; i < nargs(); ++i)
493 cell(i).metricsT(mi, dim);
495 // compute absolute sizes of vertical structure
496 for (row_type row = 0; row < nrows(); ++row) {
499 for (col_type col = 0; col < ncols(); ++col) {
500 MathArray const & c = cell(index(row, col));
501 asc = max(asc, c.ascent());
502 desc = max(desc, c.descent());
504 rowinfo_[row].ascent_ = asc;
505 rowinfo_[row].descent_ = desc;
507 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
508 rowinfo_[nrows()].ascent_ = 0;
509 rowinfo_[nrows()].descent_ = 0;
511 // compute vertical offsets
512 rowinfo_[0].offset_ = 0;
513 for (row_type row = 1; row <= nrows(); ++row) {
514 rowinfo_[row].offset_ =
515 rowinfo_[row - 1].offset_ +
516 rowinfo_[row - 1].descent_ +
517 //rowinfo_[row - 1].skipPixels() +
519 //rowinfo_[row].lines_ * hlinesep() +
520 rowinfo_[row].ascent_;
523 // adjust vertical offset
530 h = rowinfo_[nrows() - 1].offset_;
533 h = rowinfo_[nrows() - 1].offset_ / 2;
535 for (row_type row = 0; row <= nrows(); ++row)
536 rowinfo_[row].offset_ -= h;
539 // compute absolute sizes of horizontal structure
540 for (col_type col = 0; col < ncols(); ++col) {
542 for (row_type row = 0; row < nrows(); ++row)
543 wid = max(wid, cell(index(row, col)).width());
544 colinfo_[col].width_ = wid;
546 colinfo_[ncols()].width_ = 0;
548 // compute horizontal offsets
549 colinfo_[0].offset_ = border();
550 for (col_type col = 1; col <= ncols(); ++col) {
551 colinfo_[col].offset_ =
552 colinfo_[col - 1].offset_ +
553 colinfo_[col - 1].width_ +
554 colinfo_[col - 1].skip_ +
556 //colinfo_[col].lines_ * vlinesep();
560 dim.wid = colinfo_[ncols() - 1].offset_
561 + colinfo_[ncols() - 1].width_
562 //+ vlinesep() * colinfo_[ncols()].lines_
565 dim.asc = -rowinfo_[0].offset_
566 + rowinfo_[0].ascent_
567 //+ hlinesep() * rowinfo_[0].lines_
570 dim.des = rowinfo_[nrows() - 1].offset_
571 + rowinfo_[nrows() - 1].descent_
572 //+ hlinesep() * rowinfo_[nrows()].lines_
577 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
579 for (idx_type idx = 0; idx < nargs(); ++idx)
580 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
584 string MathGridInset::eolString(row_type row, bool fragile) const
588 if (!rowinfo_[row].crskip_.zero())
589 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
591 // make sure an upcoming '[' does not break anything
592 if (row + 1 < nrows()) {
593 MathArray const & c = cell(index(row + 1, 0));
594 if (c.size() && c.front()->getChar() == '[')
599 // only add \\ if necessary
600 if (eol.empty() && row + 1 == nrows())
603 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
607 string MathGridInset::eocString(col_type col, col_type lastcol) const
609 if (col + 1 == lastcol)
615 void MathGridInset::addRow(row_type row)
617 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
619 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
621 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
625 void MathGridInset::appendRow()
627 rowinfo_.push_back(RowInfo());
628 //cells_.insert(cells_.end(), ncols(), MathArray());
629 for (col_type col = 0; col < ncols(); ++col) {
630 cells_.push_back(cells_type::value_type());
631 cellinfo_.push_back(CellInfo());
636 void MathGridInset::delRow(row_type row)
641 cells_type::iterator it = cells_.begin() + row * ncols();
642 cells_.erase(it, it + ncols());
644 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
645 cellinfo_.erase(jt, jt + ncols());
647 rowinfo_.erase(rowinfo_.begin() + row);
651 void MathGridInset::copyRow(row_type row)
654 for (col_type col = 0; col < ncols(); ++col)
655 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
659 void MathGridInset::swapRow(row_type row)
663 if (row + 1 == nrows())
665 for (col_type col = 0; col < ncols(); ++col)
666 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
670 void MathGridInset::addCol(col_type newcol)
672 const col_type nc = ncols();
673 const row_type nr = nrows();
674 cells_type new_cells((nc + 1) * nr);
675 vector<CellInfo> new_cellinfo((nc + 1) * nr);
677 for (row_type row = 0; row < nr; ++row)
678 for (col_type col = 0; col < nc; ++col) {
679 new_cells[row * (nc + 1) + col + (col > newcol)]
680 = cells_[row * nc + col];
681 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
682 = cellinfo_[row * nc + col];
684 swap(cells_, new_cells);
685 swap(cellinfo_, new_cellinfo);
688 inf.skip_ = defaultColSpace(newcol);
689 inf.align_ = defaultColAlign(newcol);
690 colinfo_.insert(colinfo_.begin() + newcol, inf);
694 void MathGridInset::delCol(col_type col)
700 vector<CellInfo> tmpcellinfo;
701 for (col_type i = 0; i < nargs(); ++i)
702 if (i % ncols() != col) {
703 tmpcells.push_back(cells_[i]);
704 tmpcellinfo.push_back(cellinfo_[i]);
706 swap(cells_, tmpcells);
707 swap(cellinfo_, tmpcellinfo);
709 colinfo_.erase(colinfo_.begin() + col);
713 void MathGridInset::copyCol(col_type col)
716 for (row_type row = 0; row < nrows(); ++row)
717 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
721 void MathGridInset::swapCol(col_type col)
725 if (col + 1 == ncols())
727 for (row_type row = 0; row < nrows(); ++row)
728 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
732 int MathGridInset::cellXOffset(idx_type idx) const
734 col_type c = col(idx);
735 int x = colinfo_[c].offset_;
736 char align = colinfo_[c].align_;
737 if (align == 'r' || align == 'R')
738 x += colinfo_[c].width_ - cell(idx).width();
739 if (align == 'c' || align == 'C')
740 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
745 int MathGridInset::cellYOffset(idx_type idx) const
747 return rowinfo_[row(idx)].offset_;
751 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
758 pos = cell(idx).x2pos(targetx - cell(idx).xo());
761 if (idx >= ncols() * (nrows() - 1))
764 pos = cell(idx).x2pos(targetx - cell(idx).xo());
770 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
772 // leave matrix if on the left hand edge
776 pos = cell(idx).size();
781 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
783 // leave matrix if on the right hand edge
784 if (col(idx) + 1 == ncols())
792 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
799 idx = (nrows() - 1) * ncols();
802 idx = ((nrows() - 1) / 2) * ncols();
809 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
819 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
821 pos = cell(idx).size();
826 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
833 idx -= idx % ncols();
846 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
848 if (pos < cell(idx).size()) {
849 pos = cell(idx).size();
852 if (col(idx) < ncols() - 1) {
853 idx = idx - idx % ncols() + ncols() - 1;
854 pos = cell(idx).size();
857 if (idx < nargs() - 1) {
859 pos = cell(idx).size();
866 bool MathGridInset::idxDelete(idx_type & idx)
868 // nothing to do if we have just one row
872 // nothing to do if we are in the middle of the last row of the inset
873 if (idx + ncols() > nargs())
876 // try to delete entire sequence of ncols() empty cells if possible
877 for (idx_type i = idx; i < idx + ncols(); ++i)
881 // move cells if necessary
882 for (idx_type i = index(row(idx), 0); i < idx; ++i)
883 std::swap(cell(i), cell(i + ncols()));
890 // undo effect of Ctrl-Tab (i.e. pull next cell)
891 //if (idx + 1 != nargs())
892 // cell(idx).swap(cell(idx + 1));
894 // we handled the event..
899 // reimplement old behaviour when pressing Delete in the last position
901 void MathGridInset::idxGlue(idx_type idx)
903 col_type c = col(idx);
904 if (c + 1 == ncols()) {
905 if (row(idx) + 1 != nrows()) {
906 for (col_type cc = 0; cc < ncols(); ++cc)
907 cell(idx).append(cell(idx + cc + 1));
908 delRow(row(idx) + 1);
911 cell(idx).append(cell(idx + 1));
912 for (col_type cc = c + 2; cc < ncols(); ++cc)
913 cell(idx - c + cc - 1) = cell(idx - c + cc);
914 cell(idx - c + ncols() - 1).clear();
919 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
921 return rowinfo_[row];
925 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
927 return rowinfo_[row];
931 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
933 row_type const ri = row(idx);
934 row_type const r1 = min(row(from), row(to));
935 row_type const r2 = max(row(from), row(to));
936 col_type const ci = col(idx);
937 col_type const c1 = min(col(from), col(to));
938 col_type const c2 = max(col(from), col(to));
939 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
944 void MathGridInset::normalize(NormalStream & os) const
947 for (row_type row = 0; row < nrows(); ++row) {
949 for (col_type col = 0; col < ncols(); ++col)
950 os << "[cell " << cell(index(row, col)) << ']';
957 void MathGridInset::mathmlize(MathMLStream & os) const
959 os << MTag("mtable");
960 for (row_type row = 0; row < nrows(); ++row) {
962 for (col_type col = 0; col < ncols(); ++col)
963 os << cell(index(row, col));
966 os << ETag("mtable");
970 void MathGridInset::write(WriteStream & os) const
972 for (row_type row = 0; row < nrows(); ++row) {
973 os << verboseHLine(rowinfo_[row].lines_);
974 // don't write & and empty cells at end of line
975 col_type lastcol = 0;
976 bool emptyline = true;
977 for (col_type col = 0; col < ncols(); ++col)
978 if (!cell(index(row, col)).empty()) {
982 for (col_type col = 0; col < lastcol; ++col)
983 os << cell(index(row, col)) << eocString(col, lastcol);
984 os << eolString(row, os.fragile());
985 // append newline only if line wasn't completely empty
986 // and this was not the last line in the grid
987 if (!emptyline && row + 1 < nrows())
990 string const s = verboseHLine(rowinfo_[nrows()].lines_);
991 if (!s.empty() && s != " ") {
999 int MathGridInset::colsep() const
1005 int MathGridInset::rowsep() const
1011 int MathGridInset::hlinesep() const
1017 int MathGridInset::vlinesep() const
1023 int MathGridInset::border() const
1029 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1031 if (idx + 1 == nargs())
1033 MathArray ar = cell(idx);
1035 cell(idx).erase(pos, cell(idx).size());
1038 cell(idx).insert(0, ar);
1042 dispatch_result MathGridInset::dispatch
1043 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1045 switch (cmd.action) {
1047 case LFUN_MOUSE_RELEASE:
1048 //if (cmd.button() == mouse_button::button3) {
1049 // GridInsetMailer(*this).showDialog();
1050 // return DISPATCHED;
1052 return UNDISPATCHED;
1054 case LFUN_INSET_DIALOG_UPDATE:
1055 GridInsetMailer(*this).updateDialog(cmd.view());
1056 return UNDISPATCHED;
1058 // insert file functions
1059 case LFUN_DELETE_LINE_FORWARD:
1060 //autocorrect_ = false;
1070 if (pos > cell(idx).size())
1071 pos = cell(idx).size();
1072 return DISPATCHED_POP;
1074 case LFUN_CELL_SPLIT:
1075 //recordUndo(bv, Undo::ATOMIC);
1076 splitCell(idx, pos);
1077 return DISPATCHED_POP;
1079 case LFUN_BREAKLINE: {
1080 //recordUndo(bv, Undo::INSERT);
1081 row_type const r = row(idx);
1085 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1086 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1089 splitCell(idx, pos);
1090 std::swap(cell(idx), cell(idx + ncols() - 1));
1093 pos = cell(idx).size();
1095 //mathcursor->normalize();
1096 return DISPATCHED_POP;
1099 case LFUN_TABULAR_FEATURE: {
1100 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1101 istringstream is(cmd.argument);
1104 if (s == "valign-top")
1106 else if (s == "valign-middle")
1108 else if (s == "valign-bottom")
1110 else if (s == "align-left")
1111 halign('l', col(idx));
1112 else if (s == "align-right")
1113 halign('r', col(idx));
1114 else if (s == "align-center")
1115 halign('c', col(idx));
1116 else if (s == "append-row")
1117 for (int i = 0, n = extractInt(is); i < n; ++i)
1119 else if (s == "delete-row")
1120 for (int i = 0, n = extractInt(is); i < n; ++i) {
1125 else if (s == "copy-row")
1126 for (int i = 0, n = extractInt(is); i < n; ++i)
1128 else if (s == "swap-row")
1130 else if (s == "append-column")
1131 for (int i = 0, n = extractInt(is); i < n; ++i) {
1132 row_type r = row(idx);
1133 col_type c = col(idx);
1137 else if (s == "delete-column")
1138 for (int i = 0, n = extractInt(is); i < n; ++i) {
1139 row_type r = row(idx);
1140 col_type c = col(idx);
1146 else if (s == "copy-column")
1148 else if (s == "swap-column")
1151 return UNDISPATCHED;
1152 lyxerr << "returning DISPATCHED_POP" << endl;
1153 return DISPATCHED_POP;
1157 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1158 MathGridInset grid(1, 1);
1159 mathed_parse_normal(grid, cmd.argument);
1160 if (grid.nargs() == 1) {
1161 // single cell/part of cell
1162 cell(idx).insert(pos, grid.cell(0));
1163 pos += grid.cell(0).size();
1166 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1167 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1168 for (row_type r = 0; r < numrows; ++r) {
1169 for (col_type c = 0; c < numcols; ++c) {
1170 idx_type i = index(r + row(idx), c + col(idx));
1171 cell(i).append(grid.cell(grid.index(r, c)));
1173 // append the left over horizontal cells to the last column
1174 idx_type i = index(r + row(idx), ncols() - 1);
1175 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1176 cell(i).append(grid.cell(grid.index(r, c)));
1178 // append the left over vertical cells to the last _cell_
1179 idx_type i = nargs() - 1;
1180 for (row_type r = numrows; r < grid.nrows(); ++r)
1181 for (col_type c = 0; c < grid.ncols(); ++c)
1182 cell(i).append(grid.cell(grid.index(r, c)));
1184 return DISPATCHED_POP;
1188 return MathNestInset::dispatch(cmd, idx, pos);