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"
20 #include "frontends/Painter.h"
21 #include "support/std_sstream.h"
23 #include "insets/mailinset.h"
32 using std::istringstream;
33 using std::ostringstream;
37 class GridInsetMailer : public MailInset {
39 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
41 virtual string const & name() const
43 static string const theName = "tabular";
47 virtual string const inset2string(Buffer const &) const
50 //data << name() << " active_cell " << inset.getActCell() << '\n';
51 data << name() << " active_cell " << 0 << '\n';
58 InsetBase & inset() const { return inset_; }
59 MathGridInset & inset_;
63 void mathed_parse_normal(MathGridInset &, string const & argument);
67 string verboseHLine(int n)
70 for (int i = 0; i < n; ++i)
78 int extractInt(istream & is)
82 return (num == 0) ? 1 : num;
88 //////////////////////////////////////////////////////////////
91 MathGridInset::CellInfo::CellInfo()
98 //////////////////////////////////////////////////////////////
101 MathGridInset::RowInfo::RowInfo()
102 : lines_(0), skip_(0)
107 int MathGridInset::RowInfo::skipPixels() const
109 return crskip_.inBP();
114 //////////////////////////////////////////////////////////////
117 MathGridInset::ColInfo::ColInfo()
118 : align_('c'), leftline_(false), rightline_(false), lines_(0)
122 //////////////////////////////////////////////////////////////
125 MathGridInset::MathGridInset(char v, string const & h)
126 : MathNestInset(guessColumns(h)),
128 colinfo_(guessColumns(h) + 1),
129 cellinfo_(1 * guessColumns(h))
134 //lyxerr << "created grid with " << ncols() << " columns" << endl;
138 MathGridInset::MathGridInset()
149 MathGridInset::MathGridInset(col_type m, row_type n)
150 : MathNestInset(m * n),
160 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
161 : MathNestInset(m * n),
173 MathGridInset::~MathGridInset()
175 GridInsetMailer mailer(*this);
180 auto_ptr<InsetBase> MathGridInset::clone() const
182 return auto_ptr<InsetBase>(new MathGridInset(*this));
186 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
188 return col + ncols() * row;
192 void MathGridInset::setDefaults()
195 lyxerr << "positive number of columns expected" << endl;
197 // lyxerr << "positive number of rows expected" << endl;
198 for (col_type col = 0; col < ncols(); ++col) {
199 colinfo_[col].align_ = defaultColAlign(col);
200 colinfo_[col].skip_ = defaultColSpace(col);
205 void MathGridInset::halign(string const & hh)
208 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
213 colinfo_[col].lines_++;
214 } else if (c == 'c' || c == 'l' || c == 'r') {
215 colinfo_[col].align_ = c;
217 colinfo_[col].lines_ = 0;
219 lyxerr << "unknown column separator: '" << c << "'" << endl;
224 col_type n = hh.size();
227 for (col_type col = 0; col < n; ++col)
228 colinfo_[col].align_ = hh[col];
233 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
236 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
237 if (*it == 'c' || *it == 'l' || *it == 'r')
239 // let's have at least one column, even if we did not recognize its
247 void MathGridInset::halign(char h, col_type col)
249 colinfo_[col].align_ = h;
253 char MathGridInset::halign(col_type col) const
255 return colinfo_[col].align_;
259 string MathGridInset::halign() const
262 for (col_type col = 0; col < ncols(); ++col) {
263 res += string(colinfo_[col].lines_, '|');
264 res += colinfo_[col].align_;
266 return res + string(colinfo_[ncols()].lines_, '|');
270 void MathGridInset::valign(char c)
276 char MathGridInset::valign() const
282 MathGridInset::col_type MathGridInset::ncols() const
284 return colinfo_.size() - 1;
288 MathGridInset::row_type MathGridInset::nrows() const
290 return rowinfo_.size() - 1;
294 MathGridInset::col_type MathGridInset::col(idx_type idx) const
296 return idx % ncols();
300 MathGridInset::row_type MathGridInset::row(idx_type idx) const
302 return idx / ncols();
306 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
308 rowinfo_[row].crskip_ = crskip;
312 LyXLength MathGridInset::vcrskip(row_type row) const
314 return rowinfo_[row].crskip_;
318 void MathGridInset::metrics(MetricsInfo & mi) const
320 // let the cells adjust themselves
321 MathNestInset::metrics(mi);
323 // compute absolute sizes of vertical structure
324 for (row_type row = 0; row < nrows(); ++row) {
327 for (col_type col = 0; col < ncols(); ++col) {
328 MathArray const & c = cell(index(row, col));
329 asc = max(asc, c.ascent());
330 desc = max(desc, c.descent());
332 rowinfo_[row].ascent_ = asc;
333 rowinfo_[row].descent_ = desc;
335 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
336 rowinfo_[nrows()].ascent_ = 0;
337 rowinfo_[nrows()].descent_ = 0;
339 // compute vertical offsets
340 rowinfo_[0].offset_ = 0;
341 for (row_type row = 1; row <= nrows(); ++row) {
342 rowinfo_[row].offset_ =
343 rowinfo_[row - 1].offset_ +
344 rowinfo_[row - 1].descent_ +
345 rowinfo_[row - 1].skipPixels() +
347 rowinfo_[row].lines_ * hlinesep() +
348 rowinfo_[row].ascent_;
351 // adjust vertical offset
358 h = rowinfo_[nrows() - 1].offset_;
361 h = rowinfo_[nrows() - 1].offset_ / 2;
363 for (row_type row = 0; row <= nrows(); ++row)
364 rowinfo_[row].offset_ -= h;
367 // compute absolute sizes of horizontal structure
368 for (col_type col = 0; col < ncols(); ++col) {
370 for (row_type row = 0; row < nrows(); ++row)
371 wid = max(wid, cell(index(row, col)).width());
372 colinfo_[col].width_ = wid;
374 colinfo_[ncols()].width_ = 0;
376 // compute horizontal offsets
377 colinfo_[0].offset_ = border();
378 for (col_type col = 1; col <= ncols(); ++col) {
379 colinfo_[col].offset_ =
380 colinfo_[col - 1].offset_ +
381 colinfo_[col - 1].width_ +
382 colinfo_[col - 1].skip_ +
384 colinfo_[col].lines_ * vlinesep();
388 dim_.wid = colinfo_[ncols() - 1].offset_
389 + colinfo_[ncols() - 1].width_
390 + vlinesep() * colinfo_[ncols()].lines_
393 dim_.asc = - rowinfo_[0].offset_
394 + rowinfo_[0].ascent_
395 + hlinesep() * rowinfo_[0].lines_
398 dim_.des = rowinfo_[nrows() - 1].offset_
399 + rowinfo_[nrows() - 1].descent_
400 + hlinesep() * rowinfo_[nrows()].lines_
405 // Increase ws_[i] for 'R' columns (except the first one)
406 for (int i = 1; i < nc_; ++i)
407 if (align_[i] == 'R')
408 ws_[i] += 10 * df_width;
409 // Increase ws_[i] for 'C' column
410 if (align_[0] == 'C')
411 if (ws_[0] < 7 * workwidth / 8)
412 ws_[0] = 7 * workwidth / 8;
416 for (cxrow = row_.begin(); cxrow; ++cxrow) {
419 for (int i = 0; i < nc_; ++i) {
421 if (cxrow->getTab(i) <= 0) {
422 cxrow->setTab(i, df_width);
430 lf = (ws_[i] - cxrow->getTab(i))/2;
434 lf = ws_[i] - cxrow->getTab(i);
437 if (cxrow == row_.begin())
439 else if (cxrow.is_last())
440 lf = ws_[i] - cxrow->getTab(i);
442 lf = (ws_[i] - cxrow->getTab(i))/2;
445 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
446 cxrow->setTab(i, lf + rg);
447 rg = ws_[i] - ww + colsep();
448 if (cxrow == row_.begin())
449 width += ws_[i] + colsep();
451 cxrow->setBaseline(cxrow->getBaseline() - ascent);
457 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
464 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
466 for (idx_type idx = 0; idx < nargs(); ++idx)
467 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
469 for (row_type row = 0; row <= nrows(); ++row)
470 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
471 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
472 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
473 pi.pain.line(x + 1, yy,
474 x + dim_.width() - 1, yy,
478 for (col_type col = 0; col <= ncols(); ++col)
479 for (int i = 0; i < colinfo_[col].lines_; ++i) {
480 int xx = x + colinfo_[col].offset_
481 - i * vlinesep() - vlinesep()/2 - colsep()/2;
482 pi.pain.line(xx, y - dim_.ascent() + 1,
483 xx, y + dim_.descent() - 1,
489 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
491 // let the cells adjust themselves
492 //MathNestInset::metrics(mi);
493 for (idx_type i = 0; i < nargs(); ++i)
494 cell(i).metricsT(mi, dim);
496 // compute absolute sizes of vertical structure
497 for (row_type row = 0; row < nrows(); ++row) {
500 for (col_type col = 0; col < ncols(); ++col) {
501 MathArray const & c = cell(index(row, col));
502 asc = max(asc, c.ascent());
503 desc = max(desc, c.descent());
505 rowinfo_[row].ascent_ = asc;
506 rowinfo_[row].descent_ = desc;
508 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
509 rowinfo_[nrows()].ascent_ = 0;
510 rowinfo_[nrows()].descent_ = 0;
512 // compute vertical offsets
513 rowinfo_[0].offset_ = 0;
514 for (row_type row = 1; row <= nrows(); ++row) {
515 rowinfo_[row].offset_ =
516 rowinfo_[row - 1].offset_ +
517 rowinfo_[row - 1].descent_ +
518 //rowinfo_[row - 1].skipPixels() +
520 //rowinfo_[row].lines_ * hlinesep() +
521 rowinfo_[row].ascent_;
524 // adjust vertical offset
531 h = rowinfo_[nrows() - 1].offset_;
534 h = rowinfo_[nrows() - 1].offset_ / 2;
536 for (row_type row = 0; row <= nrows(); ++row)
537 rowinfo_[row].offset_ -= h;
540 // compute absolute sizes of horizontal structure
541 for (col_type col = 0; col < ncols(); ++col) {
543 for (row_type row = 0; row < nrows(); ++row)
544 wid = max(wid, cell(index(row, col)).width());
545 colinfo_[col].width_ = wid;
547 colinfo_[ncols()].width_ = 0;
549 // compute horizontal offsets
550 colinfo_[0].offset_ = border();
551 for (col_type col = 1; col <= ncols(); ++col) {
552 colinfo_[col].offset_ =
553 colinfo_[col - 1].offset_ +
554 colinfo_[col - 1].width_ +
555 colinfo_[col - 1].skip_ +
557 //colinfo_[col].lines_ * vlinesep();
561 dim.wid = colinfo_[ncols() - 1].offset_
562 + colinfo_[ncols() - 1].width_
563 //+ vlinesep() * colinfo_[ncols()].lines_
566 dim.asc = -rowinfo_[0].offset_
567 + rowinfo_[0].ascent_
568 //+ hlinesep() * rowinfo_[0].lines_
571 dim.des = rowinfo_[nrows() - 1].offset_
572 + rowinfo_[nrows() - 1].descent_
573 //+ hlinesep() * rowinfo_[nrows()].lines_
578 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
580 for (idx_type idx = 0; idx < nargs(); ++idx)
581 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
585 string MathGridInset::eolString(row_type row, bool fragile) const
589 if (!rowinfo_[row].crskip_.zero())
590 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
592 // make sure an upcoming '[' does not break anything
593 if (row + 1 < nrows()) {
594 MathArray const & c = cell(index(row + 1, 0));
595 if (c.size() && c.front()->getChar() == '[')
600 // only add \\ if necessary
601 if (eol.empty() && row + 1 == nrows())
604 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
608 string MathGridInset::eocString(col_type col, col_type lastcol) const
610 if (col + 1 == lastcol)
616 void MathGridInset::addRow(row_type row)
618 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
620 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
622 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
626 void MathGridInset::appendRow()
628 rowinfo_.push_back(RowInfo());
629 //cells_.insert(cells_.end(), ncols(), MathArray());
630 for (col_type col = 0; col < ncols(); ++col) {
631 cells_.push_back(cells_type::value_type());
632 cellinfo_.push_back(CellInfo());
637 void MathGridInset::delRow(row_type row)
642 cells_type::iterator it = cells_.begin() + row * ncols();
643 cells_.erase(it, it + ncols());
645 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
646 cellinfo_.erase(jt, jt + ncols());
648 rowinfo_.erase(rowinfo_.begin() + row);
652 void MathGridInset::copyRow(row_type row)
655 for (col_type col = 0; col < ncols(); ++col)
656 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
660 void MathGridInset::swapRow(row_type row)
664 if (row + 1 == nrows())
666 for (col_type col = 0; col < ncols(); ++col)
667 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
671 void MathGridInset::addCol(col_type newcol)
673 const col_type nc = ncols();
674 const row_type nr = nrows();
675 cells_type new_cells((nc + 1) * nr);
676 vector<CellInfo> new_cellinfo((nc + 1) * nr);
678 for (row_type row = 0; row < nr; ++row)
679 for (col_type col = 0; col < nc; ++col) {
680 new_cells[row * (nc + 1) + col + (col > newcol)]
681 = cells_[row * nc + col];
682 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
683 = cellinfo_[row * nc + col];
685 swap(cells_, new_cells);
686 swap(cellinfo_, new_cellinfo);
689 inf.skip_ = defaultColSpace(newcol);
690 inf.align_ = defaultColAlign(newcol);
691 colinfo_.insert(colinfo_.begin() + newcol, inf);
695 void MathGridInset::delCol(col_type col)
701 vector<CellInfo> tmpcellinfo;
702 for (col_type i = 0; i < nargs(); ++i)
703 if (i % ncols() != col) {
704 tmpcells.push_back(cells_[i]);
705 tmpcellinfo.push_back(cellinfo_[i]);
707 swap(cells_, tmpcells);
708 swap(cellinfo_, tmpcellinfo);
710 colinfo_.erase(colinfo_.begin() + col);
714 void MathGridInset::copyCol(col_type col)
717 for (row_type row = 0; row < nrows(); ++row)
718 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
722 void MathGridInset::swapCol(col_type col)
726 if (col + 1 == ncols())
728 for (row_type row = 0; row < nrows(); ++row)
729 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
733 int MathGridInset::cellXOffset(idx_type idx) const
735 col_type c = col(idx);
736 int x = colinfo_[c].offset_;
737 char align = colinfo_[c].align_;
738 if (align == 'r' || align == 'R')
739 x += colinfo_[c].width_ - cell(idx).width();
740 if (align == 'c' || align == 'C')
741 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
746 int MathGridInset::cellYOffset(idx_type idx) const
748 return rowinfo_[row(idx)].offset_;
752 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
759 pos = cell(idx).x2pos(targetx - cell(idx).xo());
762 if (idx >= ncols() * (nrows() - 1))
765 pos = cell(idx).x2pos(targetx - cell(idx).xo());
771 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
773 // leave matrix if on the left hand edge
777 pos = cell(idx).size();
782 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
784 // leave matrix if on the right hand edge
785 if (col(idx) + 1 == ncols())
793 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
800 idx = (nrows() - 1) * ncols();
803 idx = ((nrows() - 1) / 2) * ncols();
810 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
820 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
822 pos = cell(idx).size();
827 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
834 idx -= idx % ncols();
847 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
849 if (pos < cell(idx).size()) {
850 pos = cell(idx).size();
853 if (col(idx) < ncols() - 1) {
854 idx = idx - idx % ncols() + ncols() - 1;
855 pos = cell(idx).size();
858 if (idx < nargs() - 1) {
860 pos = cell(idx).size();
867 bool MathGridInset::idxDelete(idx_type & idx)
869 // nothing to do if we have just one row
873 // nothing to do if we are in the middle of the last row of the inset
874 if (idx + ncols() > nargs())
877 // try to delete entire sequence of ncols() empty cells if possible
878 for (idx_type i = idx; i < idx + ncols(); ++i)
882 // move cells if necessary
883 for (idx_type i = index(row(idx), 0); i < idx; ++i)
884 std::swap(cell(i), cell(i + ncols()));
891 // undo effect of Ctrl-Tab (i.e. pull next cell)
892 //if (idx + 1 != nargs())
893 // cell(idx).swap(cell(idx + 1));
895 // we handled the event..
900 // reimplement old behaviour when pressing Delete in the last position
902 void MathGridInset::idxGlue(idx_type idx)
904 col_type c = col(idx);
905 if (c + 1 == ncols()) {
906 if (row(idx) + 1 != nrows()) {
907 for (col_type cc = 0; cc < ncols(); ++cc)
908 cell(idx).append(cell(idx + cc + 1));
909 delRow(row(idx) + 1);
912 cell(idx).append(cell(idx + 1));
913 for (col_type cc = c + 2; cc < ncols(); ++cc)
914 cell(idx - c + cc - 1) = cell(idx - c + cc);
915 cell(idx - c + ncols() - 1).clear();
920 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
922 return rowinfo_[row];
926 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
928 return rowinfo_[row];
932 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
934 row_type const ri = row(idx);
935 row_type const r1 = min(row(from), row(to));
936 row_type const r2 = max(row(from), row(to));
937 col_type const ci = col(idx);
938 col_type const c1 = min(col(from), col(to));
939 col_type const c2 = max(col(from), col(to));
940 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
945 void MathGridInset::normalize(NormalStream & os) const
948 for (row_type row = 0; row < nrows(); ++row) {
950 for (col_type col = 0; col < ncols(); ++col)
951 os << "[cell " << cell(index(row, col)) << ']';
958 void MathGridInset::mathmlize(MathMLStream & os) const
960 os << MTag("mtable");
961 for (row_type row = 0; row < nrows(); ++row) {
963 for (col_type col = 0; col < ncols(); ++col)
964 os << cell(index(row, col));
967 os << ETag("mtable");
971 void MathGridInset::write(WriteStream & os) const
973 for (row_type row = 0; row < nrows(); ++row) {
974 os << verboseHLine(rowinfo_[row].lines_);
975 // don't write & and empty cells at end of line
976 col_type lastcol = 0;
977 bool emptyline = true;
978 for (col_type col = 0; col < ncols(); ++col)
979 if (!cell(index(row, col)).empty()) {
983 for (col_type col = 0; col < lastcol; ++col)
984 os << cell(index(row, col)) << eocString(col, lastcol);
985 os << eolString(row, os.fragile());
986 // append newline only if line wasn't completely empty
987 // and this was not the last line in the grid
988 if (!emptyline && row + 1 < nrows())
991 string const s = verboseHLine(rowinfo_[nrows()].lines_);
992 if (!s.empty() && s != " ") {
1000 int MathGridInset::colsep() const
1006 int MathGridInset::rowsep() const
1012 int MathGridInset::hlinesep() const
1018 int MathGridInset::vlinesep() const
1024 int MathGridInset::border() const
1030 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1032 if (idx + 1 == nargs())
1034 MathArray ar = cell(idx);
1036 cell(idx).erase(pos, cell(idx).size());
1039 cell(idx).insert(0, ar);
1043 dispatch_result MathGridInset::dispatch
1044 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1046 switch (cmd.action) {
1048 case LFUN_MOUSE_RELEASE:
1049 //if (cmd.button() == mouse_button::button3) {
1050 // GridInsetMailer(*this).showDialog();
1051 // return DISPATCHED;
1053 return UNDISPATCHED;
1055 case LFUN_INSET_DIALOG_UPDATE:
1056 GridInsetMailer(*this).updateDialog(cmd.view());
1057 return UNDISPATCHED;
1059 // insert file functions
1060 case LFUN_DELETE_LINE_FORWARD:
1061 //autocorrect_ = false;
1071 if (pos > cell(idx).size())
1072 pos = cell(idx).size();
1073 return DISPATCHED_POP;
1075 case LFUN_CELL_SPLIT:
1076 //recordUndo(bv, Undo::ATOMIC);
1077 splitCell(idx, pos);
1078 return DISPATCHED_POP;
1080 case LFUN_BREAKLINE: {
1081 //recordUndo(bv, Undo::INSERT);
1082 row_type const r = row(idx);
1086 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1087 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1090 splitCell(idx, pos);
1091 std::swap(cell(idx), cell(idx + ncols() - 1));
1094 pos = cell(idx).size();
1096 //mathcursor->normalize();
1097 return DISPATCHED_POP;
1100 case LFUN_TABULAR_FEATURE: {
1101 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1102 istringstream is(cmd.argument);
1105 if (s == "valign-top")
1107 else if (s == "valign-middle")
1109 else if (s == "valign-bottom")
1111 else if (s == "align-left")
1112 halign('l', col(idx));
1113 else if (s == "align-right")
1114 halign('r', col(idx));
1115 else if (s == "align-center")
1116 halign('c', col(idx));
1117 else if (s == "append-row")
1118 for (int i = 0, n = extractInt(is); i < n; ++i)
1120 else if (s == "delete-row")
1121 for (int i = 0, n = extractInt(is); i < n; ++i) {
1126 else if (s == "copy-row")
1127 for (int i = 0, n = extractInt(is); i < n; ++i)
1129 else if (s == "swap-row")
1131 else if (s == "append-column")
1132 for (int i = 0, n = extractInt(is); i < n; ++i) {
1133 row_type r = row(idx);
1134 col_type c = col(idx);
1138 else if (s == "delete-column")
1139 for (int i = 0, n = extractInt(is); i < n; ++i) {
1140 row_type r = row(idx);
1141 col_type c = col(idx);
1147 else if (s == "copy-column")
1149 else if (s == "swap-column")
1152 return UNDISPATCHED;
1153 lyxerr << "returning DISPATCHED_POP" << endl;
1154 return DISPATCHED_POP;
1158 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1159 MathGridInset grid(1, 1);
1160 mathed_parse_normal(grid, cmd.argument);
1161 if (grid.nargs() == 1) {
1162 // single cell/part of cell
1163 cell(idx).insert(pos, grid.cell(0));
1164 pos += grid.cell(0).size();
1167 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1168 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1169 for (row_type r = 0; r < numrows; ++r) {
1170 for (col_type c = 0; c < numcols; ++c) {
1171 idx_type i = index(r + row(idx), c + col(idx));
1172 cell(i).insert(0, grid.cell(grid.index(r, c)));
1174 // append the left over horizontal cells to the last column
1175 idx_type i = index(r + row(idx), ncols() - 1);
1176 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1177 cell(i).append(grid.cell(grid.index(r, c)));
1179 // append the left over vertical cells to the last _cell_
1180 idx_type i = nargs() - 1;
1181 for (row_type r = numrows; r < grid.nrows(); ++r)
1182 for (col_type c = 0; c < grid.ncols(); ++c)
1183 cell(i).append(grid.cell(grid.index(r, c)));
1185 return DISPATCHED_POP;
1189 return MathNestInset::dispatch(cmd, idx, pos);