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_mathmlstream.h"
15 #include "math_streamstr.h"
16 #include "funcrequest.h"
17 #include "frontends/Painter.h"
19 #include "support/std_sstream.h"
22 #include "insets/mailinset.h"
29 using std::istringstream;
30 using std::ostringstream;
35 class GridInsetMailer : public MailInset {
37 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
39 virtual string const & name() const
41 static string const theName = "tabular";
45 virtual string const inset2string(Buffer const &) const
48 //data << name() << " active_cell " << inset.getActCell() << '\n';
49 data << name() << " active_cell " << 0 << '\n';
52 return STRCONV(data.str());
56 InsetBase & inset() const { return inset_; }
57 MathGridInset & inset_;
61 void mathed_parse_normal(MathGridInset &, string const & argument);
65 string verboseHLine(int n)
68 for (int i = 0; i < n; ++i)
76 int extractInt(istream & is)
80 return (num == 0) ? 1 : num;
86 //////////////////////////////////////////////////////////////
89 MathGridInset::CellInfo::CellInfo()
96 //////////////////////////////////////////////////////////////
99 MathGridInset::RowInfo::RowInfo()
100 : lines_(0), skip_(0)
105 int MathGridInset::RowInfo::skipPixels() const
107 return crskip_.inBP();
112 //////////////////////////////////////////////////////////////
115 MathGridInset::ColInfo::ColInfo()
116 : align_('c'), leftline_(false), rightline_(false), lines_(0)
120 //////////////////////////////////////////////////////////////
123 MathGridInset::MathGridInset(char v, string const & h)
124 : MathNestInset(guessColumns(h)),
126 colinfo_(guessColumns(h) + 1),
127 cellinfo_(1 * guessColumns(h))
132 //lyxerr << "created grid with " << ncols() << " columns" << endl;
136 MathGridInset::MathGridInset()
147 MathGridInset::MathGridInset(col_type m, row_type n)
148 : MathNestInset(m * n),
158 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
159 : MathNestInset(m * n),
171 MathGridInset::~MathGridInset()
173 GridInsetMailer mailer(*this);
178 auto_ptr<InsetBase> MathGridInset::clone() const
180 return auto_ptr<InsetBase>(new MathGridInset(*this));
184 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
186 return col + ncols() * row;
190 void MathGridInset::setDefaults()
193 lyxerr << "positive number of columns expected" << endl;
195 // lyxerr << "positive number of rows expected" << endl;
196 for (col_type col = 0; col < ncols(); ++col) {
197 colinfo_[col].align_ = defaultColAlign(col);
198 colinfo_[col].skip_ = defaultColSpace(col);
203 void MathGridInset::halign(string const & hh)
206 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
211 colinfo_[col].lines_++;
212 } else if (c == 'c' || c == 'l' || c == 'r') {
213 colinfo_[col].align_ = c;
215 colinfo_[col].lines_ = 0;
217 lyxerr << "unknown column separator: '" << c << "'" << endl;
222 col_type n = hh.size();
225 for (col_type col = 0; col < n; ++col)
226 colinfo_[col].align_ = hh[col];
231 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
234 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
235 if (*it == 'c' || *it == 'l' || *it == 'r')
237 // let's have at least one column, even if we did not recognize its
245 void MathGridInset::halign(char h, col_type col)
247 colinfo_[col].align_ = h;
251 char MathGridInset::halign(col_type col) const
253 return colinfo_[col].align_;
257 string MathGridInset::halign() const
260 for (col_type col = 0; col < ncols(); ++col) {
261 res += string(colinfo_[col].lines_, '|');
262 res += colinfo_[col].align_;
264 return res + string(colinfo_[ncols()].lines_, '|');
268 void MathGridInset::valign(char c)
274 char MathGridInset::valign() const
280 MathGridInset::col_type MathGridInset::ncols() const
282 return colinfo_.size() - 1;
286 MathGridInset::row_type MathGridInset::nrows() const
288 return rowinfo_.size() - 1;
292 MathGridInset::col_type MathGridInset::col(idx_type idx) const
294 return idx % ncols();
298 MathGridInset::row_type MathGridInset::row(idx_type idx) const
300 return idx / ncols();
304 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
306 rowinfo_[row].crskip_ = crskip;
310 LyXLength MathGridInset::vcrskip(row_type row) const
312 return rowinfo_[row].crskip_;
316 void MathGridInset::metrics(MetricsInfo & mi) const
318 // let the cells adjust themselves
319 MathNestInset::metrics(mi);
321 // compute absolute sizes of vertical structure
322 for (row_type row = 0; row < nrows(); ++row) {
325 for (col_type col = 0; col < ncols(); ++col) {
326 MathArray const & c = cell(index(row, col));
327 asc = max(asc, c.ascent());
328 desc = max(desc, c.descent());
330 rowinfo_[row].ascent_ = asc;
331 rowinfo_[row].descent_ = desc;
333 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
334 rowinfo_[nrows()].ascent_ = 0;
335 rowinfo_[nrows()].descent_ = 0;
337 // compute vertical offsets
338 rowinfo_[0].offset_ = 0;
339 for (row_type row = 1; row <= nrows(); ++row) {
340 rowinfo_[row].offset_ =
341 rowinfo_[row - 1].offset_ +
342 rowinfo_[row - 1].descent_ +
343 rowinfo_[row - 1].skipPixels() +
345 rowinfo_[row].lines_ * hlinesep() +
346 rowinfo_[row].ascent_;
349 // adjust vertical offset
356 h = rowinfo_[nrows() - 1].offset_;
359 h = rowinfo_[nrows() - 1].offset_ / 2;
361 for (row_type row = 0; row <= nrows(); ++row)
362 rowinfo_[row].offset_ -= h;
365 // compute absolute sizes of horizontal structure
366 for (col_type col = 0; col < ncols(); ++col) {
368 for (row_type row = 0; row < nrows(); ++row)
369 wid = max(wid, cell(index(row, col)).width());
370 colinfo_[col].width_ = wid;
372 colinfo_[ncols()].width_ = 0;
374 // compute horizontal offsets
375 colinfo_[0].offset_ = border();
376 for (col_type col = 1; col <= ncols(); ++col) {
377 colinfo_[col].offset_ =
378 colinfo_[col - 1].offset_ +
379 colinfo_[col - 1].width_ +
380 colinfo_[col - 1].skip_ +
382 colinfo_[col].lines_ * vlinesep();
386 dim_.wid = colinfo_[ncols() - 1].offset_
387 + colinfo_[ncols() - 1].width_
388 + vlinesep() * colinfo_[ncols()].lines_
391 dim_.asc = - rowinfo_[0].offset_
392 + rowinfo_[0].ascent_
393 + hlinesep() * rowinfo_[0].lines_
396 dim_.des = rowinfo_[nrows() - 1].offset_
397 + rowinfo_[nrows() - 1].descent_
398 + hlinesep() * rowinfo_[nrows()].lines_
403 // Increase ws_[i] for 'R' columns (except the first one)
404 for (int i = 1; i < nc_; ++i)
405 if (align_[i] == 'R')
406 ws_[i] += 10 * df_width;
407 // Increase ws_[i] for 'C' column
408 if (align_[0] == 'C')
409 if (ws_[0] < 7 * workwidth / 8)
410 ws_[0] = 7 * workwidth / 8;
414 for (cxrow = row_.begin(); cxrow; ++cxrow) {
417 for (int i = 0; i < nc_; ++i) {
419 if (cxrow->getTab(i) <= 0) {
420 cxrow->setTab(i, df_width);
428 lf = (ws_[i] - cxrow->getTab(i))/2;
432 lf = ws_[i] - cxrow->getTab(i);
435 if (cxrow == row_.begin())
437 else if (cxrow.is_last())
438 lf = ws_[i] - cxrow->getTab(i);
440 lf = (ws_[i] - cxrow->getTab(i))/2;
443 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
444 cxrow->setTab(i, lf + rg);
445 rg = ws_[i] - ww + colsep();
446 if (cxrow == row_.begin())
447 width += ws_[i] + colsep();
449 cxrow->setBaseline(cxrow->getBaseline() - ascent);
455 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
462 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
464 for (idx_type idx = 0; idx < nargs(); ++idx)
465 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
467 for (row_type row = 0; row <= nrows(); ++row)
468 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
469 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
470 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
471 pi.pain.line(x + 1, yy, x + dim_.width() - 1, yy);
474 for (col_type col = 0; col <= ncols(); ++col)
475 for (int i = 0; i < colinfo_[col].lines_; ++i) {
476 int xx = x + colinfo_[col].offset_
477 - i * vlinesep() - vlinesep()/2 - colsep()/2;
478 pi.pain.line(xx, y - dim_.ascent() + 1, xx, y + dim_.descent() - 1);
483 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
485 // let the cells adjust themselves
486 //MathNestInset::metrics(mi);
487 for (idx_type i = 0; i < nargs(); ++i)
488 cell(i).metricsT(mi, dim);
490 // compute absolute sizes of vertical structure
491 for (row_type row = 0; row < nrows(); ++row) {
494 for (col_type col = 0; col < ncols(); ++col) {
495 MathArray const & c = cell(index(row, col));
496 asc = max(asc, c.ascent());
497 desc = max(desc, c.descent());
499 rowinfo_[row].ascent_ = asc;
500 rowinfo_[row].descent_ = desc;
502 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
503 rowinfo_[nrows()].ascent_ = 0;
504 rowinfo_[nrows()].descent_ = 0;
506 // compute vertical offsets
507 rowinfo_[0].offset_ = 0;
508 for (row_type row = 1; row <= nrows(); ++row) {
509 rowinfo_[row].offset_ =
510 rowinfo_[row - 1].offset_ +
511 rowinfo_[row - 1].descent_ +
512 //rowinfo_[row - 1].skipPixels() +
514 //rowinfo_[row].lines_ * hlinesep() +
515 rowinfo_[row].ascent_;
518 // adjust vertical offset
525 h = rowinfo_[nrows() - 1].offset_;
528 h = rowinfo_[nrows() - 1].offset_ / 2;
530 for (row_type row = 0; row <= nrows(); ++row)
531 rowinfo_[row].offset_ -= h;
534 // compute absolute sizes of horizontal structure
535 for (col_type col = 0; col < ncols(); ++col) {
537 for (row_type row = 0; row < nrows(); ++row)
538 wid = max(wid, cell(index(row, col)).width());
539 colinfo_[col].width_ = wid;
541 colinfo_[ncols()].width_ = 0;
543 // compute horizontal offsets
544 colinfo_[0].offset_ = border();
545 for (col_type col = 1; col <= ncols(); ++col) {
546 colinfo_[col].offset_ =
547 colinfo_[col - 1].offset_ +
548 colinfo_[col - 1].width_ +
549 colinfo_[col - 1].skip_ +
551 //colinfo_[col].lines_ * vlinesep();
555 dim.wid = colinfo_[ncols() - 1].offset_
556 + colinfo_[ncols() - 1].width_
557 //+ vlinesep() * colinfo_[ncols()].lines_
560 dim.asc = -rowinfo_[0].offset_
561 + rowinfo_[0].ascent_
562 //+ hlinesep() * rowinfo_[0].lines_
565 dim.des = rowinfo_[nrows() - 1].offset_
566 + rowinfo_[nrows() - 1].descent_
567 //+ hlinesep() * rowinfo_[nrows()].lines_
572 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
574 for (idx_type idx = 0; idx < nargs(); ++idx)
575 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
579 string MathGridInset::eolString(row_type row, bool fragile) const
583 if (!rowinfo_[row].crskip_.zero())
584 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
586 // make sure an upcoming '[' does not break anything
587 if (row + 1 < nrows()) {
588 MathArray const & c = cell(index(row + 1, 0));
589 if (c.size() && c.front()->getChar() == '[')
594 // only add \\ if necessary
595 if (eol.empty() && row + 1 == nrows())
598 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
602 string MathGridInset::eocString(col_type col, col_type lastcol) const
604 if (col + 1 == lastcol)
610 void MathGridInset::addRow(row_type row)
612 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
614 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
616 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
620 void MathGridInset::appendRow()
622 rowinfo_.push_back(RowInfo());
623 //cells_.insert(cells_.end(), ncols(), MathArray());
624 for (col_type col = 0; col < ncols(); ++col) {
625 cells_.push_back(cells_type::value_type());
626 cellinfo_.push_back(CellInfo());
631 void MathGridInset::delRow(row_type row)
636 cells_type::iterator it = cells_.begin() + row * ncols();
637 cells_.erase(it, it + ncols());
639 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
640 cellinfo_.erase(jt, jt + ncols());
642 rowinfo_.erase(rowinfo_.begin() + row);
646 void MathGridInset::copyRow(row_type row)
649 for (col_type col = 0; col < ncols(); ++col)
650 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
654 void MathGridInset::swapRow(row_type row)
658 if (row + 1 == nrows())
660 for (col_type col = 0; col < ncols(); ++col)
661 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
665 void MathGridInset::addCol(col_type newcol)
667 const col_type nc = ncols();
668 const row_type nr = nrows();
669 cells_type new_cells((nc + 1) * nr);
670 vector<CellInfo> new_cellinfo((nc + 1) * nr);
672 for (row_type row = 0; row < nr; ++row)
673 for (col_type col = 0; col < nc; ++col) {
674 new_cells[row * (nc + 1) + col + (col > newcol)]
675 = cells_[row * nc + col];
676 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
677 = cellinfo_[row * nc + col];
679 swap(cells_, new_cells);
680 swap(cellinfo_, new_cellinfo);
683 inf.skip_ = defaultColSpace(newcol);
684 inf.align_ = defaultColAlign(newcol);
685 colinfo_.insert(colinfo_.begin() + newcol, inf);
689 void MathGridInset::delCol(col_type col)
695 vector<CellInfo> tmpcellinfo;
696 for (col_type i = 0; i < nargs(); ++i)
697 if (i % ncols() != col) {
698 tmpcells.push_back(cells_[i]);
699 tmpcellinfo.push_back(cellinfo_[i]);
701 swap(cells_, tmpcells);
702 swap(cellinfo_, tmpcellinfo);
704 colinfo_.erase(colinfo_.begin() + col);
708 void MathGridInset::copyCol(col_type col)
711 for (row_type row = 0; row < nrows(); ++row)
712 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
716 void MathGridInset::swapCol(col_type col)
720 if (col + 1 == ncols())
722 for (row_type row = 0; row < nrows(); ++row)
723 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
727 int MathGridInset::cellXOffset(idx_type idx) const
729 col_type c = col(idx);
730 int x = colinfo_[c].offset_;
731 char align = colinfo_[c].align_;
732 if (align == 'r' || align == 'R')
733 x += colinfo_[c].width_ - cell(idx).width();
734 if (align == 'c' || align == 'C')
735 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
740 int MathGridInset::cellYOffset(idx_type idx) const
742 return rowinfo_[row(idx)].offset_;
746 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
753 pos = cell(idx).x2pos(targetx - cell(idx).xo());
756 if (idx >= ncols() * (nrows() - 1))
759 pos = cell(idx).x2pos(targetx - cell(idx).xo());
765 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
767 // leave matrix if on the left hand edge
771 pos = cell(idx).size();
776 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
778 // leave matrix if on the right hand edge
779 if (col(idx) + 1 == ncols())
787 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
794 idx = (nrows() - 1) * ncols();
797 idx = ((nrows() - 1) / 2) * ncols();
804 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
814 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
816 pos = cell(idx).size();
821 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
828 idx -= idx % ncols();
841 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
843 if (pos < cell(idx).size()) {
844 pos = cell(idx).size();
847 if (col(idx) < ncols() - 1) {
848 idx = idx - idx % ncols() + ncols() - 1;
849 pos = cell(idx).size();
852 if (idx < nargs() - 1) {
854 pos = cell(idx).size();
861 bool MathGridInset::idxDelete(idx_type & idx)
863 // nothing to do if we have just one row
867 // nothing to do if we are in the middle of the last row of the inset
868 if (idx + ncols() > nargs())
871 // try to delete entire sequence of ncols() empty cells if possible
872 for (idx_type i = idx; i < idx + ncols(); ++i)
876 // move cells if necessary
877 for (idx_type i = index(row(idx), 0); i < idx; ++i)
878 std::swap(cell(i), cell(i + ncols()));
885 // undo effect of Ctrl-Tab (i.e. pull next cell)
886 //if (idx + 1 != nargs())
887 // cell(idx).swap(cell(idx + 1));
889 // we handled the event..
894 // reimplement old behaviour when pressing Delete in the last position
896 void MathGridInset::idxGlue(idx_type idx)
898 col_type c = col(idx);
899 if (c + 1 == ncols()) {
900 if (row(idx) + 1 != nrows()) {
901 for (col_type cc = 0; cc < ncols(); ++cc)
902 cell(idx).append(cell(idx + cc + 1));
903 delRow(row(idx) + 1);
906 cell(idx).append(cell(idx + 1));
907 for (col_type cc = c + 2; cc < ncols(); ++cc)
908 cell(idx - c + cc - 1) = cell(idx - c + cc);
909 cell(idx - c + ncols() - 1).clear();
914 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
916 return rowinfo_[row];
920 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
922 return rowinfo_[row];
926 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
928 row_type const ri = row(idx);
929 row_type const r1 = min(row(from), row(to));
930 row_type const r2 = max(row(from), row(to));
931 col_type const ci = col(idx);
932 col_type const c1 = min(col(from), col(to));
933 col_type const c2 = max(col(from), col(to));
934 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
939 void MathGridInset::normalize(NormalStream & os) const
942 for (row_type row = 0; row < nrows(); ++row) {
944 for (col_type col = 0; col < ncols(); ++col)
945 os << "[cell " << cell(index(row, col)) << ']';
952 void MathGridInset::mathmlize(MathMLStream & os) const
954 os << MTag("mtable");
955 for (row_type row = 0; row < nrows(); ++row) {
957 for (col_type col = 0; col < ncols(); ++col)
958 os << cell(index(row, col));
961 os << ETag("mtable");
965 void MathGridInset::write(WriteStream & os) const
967 for (row_type row = 0; row < nrows(); ++row) {
968 os << verboseHLine(rowinfo_[row].lines_);
969 // don't write & and empty cells at end of line
970 col_type lastcol = 0;
971 bool emptyline = true;
972 for (col_type col = 0; col < ncols(); ++col)
973 if (!cell(index(row, col)).empty()) {
977 for (col_type col = 0; col < lastcol; ++col)
978 os << cell(index(row, col)) << eocString(col, lastcol);
979 os << eolString(row, os.fragile());
980 // append newline only if line wasn't completely empty
981 // and this was not the last line in the grid
982 if (!emptyline && row + 1 < nrows())
985 string const s = verboseHLine(rowinfo_[nrows()].lines_);
986 if (!s.empty() && s != " ") {
994 int MathGridInset::colsep() const
1000 int MathGridInset::rowsep() const
1006 int MathGridInset::hlinesep() const
1012 int MathGridInset::vlinesep() const
1018 int MathGridInset::border() const
1024 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1026 if (idx + 1 == nargs())
1028 MathArray ar = cell(idx);
1030 cell(idx).erase(pos, cell(idx).size());
1033 cell(idx).insert(0, ar);
1037 dispatch_result MathGridInset::dispatch
1038 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1040 switch (cmd.action) {
1042 case LFUN_MOUSE_RELEASE:
1043 //if (cmd.button() == mouse_button::button3) {
1044 // GridInsetMailer(*this).showDialog();
1045 // return DISPATCHED;
1047 return UNDISPATCHED;
1049 case LFUN_INSET_DIALOG_UPDATE:
1050 GridInsetMailer(*this).updateDialog(cmd.view());
1051 return UNDISPATCHED;
1053 // insert file functions
1054 case LFUN_DELETE_LINE_FORWARD:
1055 //autocorrect_ = false;
1065 if (pos > cell(idx).size())
1066 pos = cell(idx).size();
1067 return DISPATCHED_POP;
1069 case LFUN_CELL_SPLIT:
1070 //recordUndo(bv, Undo::ATOMIC);
1071 splitCell(idx, pos);
1072 return DISPATCHED_POP;
1074 case LFUN_BREAKLINE: {
1075 //recordUndo(bv, Undo::INSERT);
1076 row_type const r = row(idx);
1080 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1081 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1084 splitCell(idx, pos);
1085 std::swap(cell(idx), cell(idx + ncols() - 1));
1088 pos = cell(idx).size();
1090 //mathcursor->normalize();
1091 return DISPATCHED_POP;
1094 case LFUN_TABULAR_FEATURE: {
1095 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1096 istringstream is(STRCONV(cmd.argument));
1099 if (s == "valign-top")
1101 else if (s == "valign-middle")
1103 else if (s == "valign-bottom")
1105 else if (s == "align-left")
1106 halign('l', col(idx));
1107 else if (s == "align-right")
1108 halign('r', col(idx));
1109 else if (s == "align-center")
1110 halign('c', col(idx));
1111 else if (s == "append-row")
1112 for (int i = 0, n = extractInt(is); i < n; ++i)
1114 else if (s == "delete-row")
1115 for (int i = 0, n = extractInt(is); i < n; ++i) {
1120 else if (s == "copy-row")
1121 for (int i = 0, n = extractInt(is); i < n; ++i)
1123 else if (s == "swap-row")
1125 else if (s == "append-column")
1126 for (int i = 0, n = extractInt(is); i < n; ++i) {
1127 row_type r = row(idx);
1128 col_type c = col(idx);
1132 else if (s == "delete-column")
1133 for (int i = 0, n = extractInt(is); i < n; ++i) {
1134 row_type r = row(idx);
1135 col_type c = col(idx);
1141 else if (s == "copy-column")
1143 else if (s == "swap-column")
1146 return UNDISPATCHED;
1147 lyxerr << "returning DISPATCHED_POP" << endl;
1148 return DISPATCHED_POP;
1152 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1153 MathGridInset grid(1, 1);
1154 mathed_parse_normal(grid, cmd.argument);
1155 if (grid.nargs() == 1) {
1156 // single cell/part of cell
1157 cell(idx).insert(pos, grid.cell(0));
1158 pos += grid.cell(0).size();
1161 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1162 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1163 for (row_type r = 0; r < numrows; ++r) {
1164 for (col_type c = 0; c < numcols; ++c) {
1165 idx_type i = index(r + row(idx), c + col(idx));
1166 cell(i).append(grid.cell(grid.index(r, c)));
1168 // append the left over horizontal cells to the last column
1169 idx_type i = index(r + row(idx), ncols() - 1);
1170 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1171 cell(i).append(grid.cell(grid.index(r, c)));
1173 // append the left over vertical cells to the last _cell_
1174 idx_type i = nargs() - 1;
1175 for (row_type r = numrows; r < grid.nrows(); ++r)
1176 for (col_type c = 0; c < grid.ncols(); ++c)
1177 cell(i).append(grid.cell(grid.index(r, c)));
1179 return DISPATCHED_POP;
1183 return MathNestInset::dispatch(cmd, idx, pos);