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"
33 using std::istringstream;
34 using std::ostringstream;
38 class GridInsetMailer : public MailInset {
40 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
42 virtual string const & name() const
44 static string const theName = "tabular";
48 virtual string const inset2string(Buffer const &) const
51 //data << name() << " active_cell " << inset.getActCell() << '\n';
52 data << name() << " active_cell " << 0 << '\n';
59 InsetBase & inset() const { return inset_; }
60 MathGridInset & inset_;
64 void mathed_parse_normal(MathGridInset &, string const & argument);
68 string verboseHLine(int n)
71 for (int i = 0; i < n; ++i)
79 int extractInt(istream & is)
83 return (num == 0) ? 1 : num;
89 //////////////////////////////////////////////////////////////
92 MathGridInset::CellInfo::CellInfo()
99 //////////////////////////////////////////////////////////////
102 MathGridInset::RowInfo::RowInfo()
103 : lines_(0), skip_(0)
108 int MathGridInset::RowInfo::skipPixels() const
110 return crskip_.inBP();
115 //////////////////////////////////////////////////////////////
118 MathGridInset::ColInfo::ColInfo()
119 : align_('c'), leftline_(false), rightline_(false), lines_(0)
123 //////////////////////////////////////////////////////////////
126 MathGridInset::MathGridInset(char v, string const & h)
127 : MathNestInset(guessColumns(h)),
129 colinfo_(guessColumns(h) + 1),
130 cellinfo_(1 * guessColumns(h))
135 //lyxerr << "created grid with " << ncols() << " columns" << endl;
139 MathGridInset::MathGridInset()
150 MathGridInset::MathGridInset(col_type m, row_type n)
151 : MathNestInset(m * n),
161 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
162 : MathNestInset(m * n),
174 MathGridInset::~MathGridInset()
176 GridInsetMailer mailer(*this);
181 auto_ptr<InsetBase> MathGridInset::clone() const
183 return auto_ptr<InsetBase>(new MathGridInset(*this));
187 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
189 return col + ncols() * row;
193 void MathGridInset::setDefaults()
196 lyxerr << "positive number of columns expected" << endl;
198 // lyxerr << "positive number of rows expected" << endl;
199 for (col_type col = 0; col < ncols(); ++col) {
200 colinfo_[col].align_ = defaultColAlign(col);
201 colinfo_[col].skip_ = defaultColSpace(col);
206 void MathGridInset::halign(string const & hh)
209 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
214 colinfo_[col].lines_++;
215 } else if (c == 'c' || c == 'l' || c == 'r') {
216 colinfo_[col].align_ = c;
218 colinfo_[col].lines_ = 0;
220 lyxerr << "unknown column separator: '" << c << "'" << endl;
225 col_type n = hh.size();
228 for (col_type col = 0; col < n; ++col)
229 colinfo_[col].align_ = hh[col];
234 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
237 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
238 if (*it == 'c' || *it == 'l' || *it == 'r')
240 // let's have at least one column, even if we did not recognize its
248 void MathGridInset::halign(char h, col_type col)
250 colinfo_[col].align_ = h;
254 char MathGridInset::halign(col_type col) const
256 return colinfo_[col].align_;
260 string MathGridInset::halign() const
263 for (col_type col = 0; col < ncols(); ++col) {
264 res += string(colinfo_[col].lines_, '|');
265 res += colinfo_[col].align_;
267 return res + string(colinfo_[ncols()].lines_, '|');
271 void MathGridInset::valign(char c)
277 char MathGridInset::valign() const
283 MathGridInset::col_type MathGridInset::ncols() const
285 return colinfo_.size() - 1;
289 MathGridInset::row_type MathGridInset::nrows() const
291 return rowinfo_.size() - 1;
295 MathGridInset::col_type MathGridInset::col(idx_type idx) const
297 return idx % ncols();
301 MathGridInset::row_type MathGridInset::row(idx_type idx) const
303 return idx / ncols();
307 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
309 rowinfo_[row].crskip_ = crskip;
313 LyXLength MathGridInset::vcrskip(row_type row) const
315 return rowinfo_[row].crskip_;
319 void MathGridInset::metrics(MetricsInfo & mi) const
321 // let the cells adjust themselves
322 MathNestInset::metrics(mi);
324 // compute absolute sizes of vertical structure
325 for (row_type row = 0; row < nrows(); ++row) {
328 for (col_type col = 0; col < ncols(); ++col) {
329 MathArray const & c = cell(index(row, col));
330 asc = max(asc, c.ascent());
331 desc = max(desc, c.descent());
333 rowinfo_[row].ascent_ = asc;
334 rowinfo_[row].descent_ = desc;
336 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
337 rowinfo_[nrows()].ascent_ = 0;
338 rowinfo_[nrows()].descent_ = 0;
340 // compute vertical offsets
341 rowinfo_[0].offset_ = 0;
342 for (row_type row = 1; row <= nrows(); ++row) {
343 rowinfo_[row].offset_ =
344 rowinfo_[row - 1].offset_ +
345 rowinfo_[row - 1].descent_ +
346 rowinfo_[row - 1].skipPixels() +
348 rowinfo_[row].lines_ * hlinesep() +
349 rowinfo_[row].ascent_;
352 // adjust vertical offset
359 h = rowinfo_[nrows() - 1].offset_;
362 h = rowinfo_[nrows() - 1].offset_ / 2;
364 for (row_type row = 0; row <= nrows(); ++row)
365 rowinfo_[row].offset_ -= h;
368 // compute absolute sizes of horizontal structure
369 for (col_type col = 0; col < ncols(); ++col) {
371 for (row_type row = 0; row < nrows(); ++row)
372 wid = max(wid, cell(index(row, col)).width());
373 colinfo_[col].width_ = wid;
375 colinfo_[ncols()].width_ = 0;
377 // compute horizontal offsets
378 colinfo_[0].offset_ = border();
379 for (col_type col = 1; col <= ncols(); ++col) {
380 colinfo_[col].offset_ =
381 colinfo_[col - 1].offset_ +
382 colinfo_[col - 1].width_ +
383 colinfo_[col - 1].skip_ +
385 colinfo_[col].lines_ * vlinesep();
389 dim_.wid = colinfo_[ncols() - 1].offset_
390 + colinfo_[ncols() - 1].width_
391 + vlinesep() * colinfo_[ncols()].lines_
394 dim_.asc = - rowinfo_[0].offset_
395 + rowinfo_[0].ascent_
396 + hlinesep() * rowinfo_[0].lines_
399 dim_.des = rowinfo_[nrows() - 1].offset_
400 + rowinfo_[nrows() - 1].descent_
401 + hlinesep() * rowinfo_[nrows()].lines_
406 // Increase ws_[i] for 'R' columns (except the first one)
407 for (int i = 1; i < nc_; ++i)
408 if (align_[i] == 'R')
409 ws_[i] += 10 * df_width;
410 // Increase ws_[i] for 'C' column
411 if (align_[0] == 'C')
412 if (ws_[0] < 7 * workwidth / 8)
413 ws_[0] = 7 * workwidth / 8;
417 for (cxrow = row_.begin(); cxrow; ++cxrow) {
420 for (int i = 0; i < nc_; ++i) {
422 if (cxrow->getTab(i) <= 0) {
423 cxrow->setTab(i, df_width);
431 lf = (ws_[i] - cxrow->getTab(i))/2;
435 lf = ws_[i] - cxrow->getTab(i);
438 if (cxrow == row_.begin())
440 else if (cxrow.is_last())
441 lf = ws_[i] - cxrow->getTab(i);
443 lf = (ws_[i] - cxrow->getTab(i))/2;
446 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
447 cxrow->setTab(i, lf + rg);
448 rg = ws_[i] - ww + colsep();
449 if (cxrow == row_.begin())
450 width += ws_[i] + colsep();
452 cxrow->setBaseline(cxrow->getBaseline() - ascent);
458 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
465 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
467 for (idx_type idx = 0; idx < nargs(); ++idx)
468 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
470 for (row_type row = 0; row <= nrows(); ++row)
471 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
472 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
473 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
474 pi.pain.line(x + 1, yy,
475 x + dim_.width() - 1, yy,
479 for (col_type col = 0; col <= ncols(); ++col)
480 for (int i = 0; i < colinfo_[col].lines_; ++i) {
481 int xx = x + colinfo_[col].offset_
482 - i * vlinesep() - vlinesep()/2 - colsep()/2;
483 pi.pain.line(xx, y - dim_.ascent() + 1,
484 xx, y + dim_.descent() - 1,
490 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
492 // let the cells adjust themselves
493 //MathNestInset::metrics(mi);
494 for (idx_type i = 0; i < nargs(); ++i)
495 cell(i).metricsT(mi, dim);
497 // compute absolute sizes of vertical structure
498 for (row_type row = 0; row < nrows(); ++row) {
501 for (col_type col = 0; col < ncols(); ++col) {
502 MathArray const & c = cell(index(row, col));
503 asc = max(asc, c.ascent());
504 desc = max(desc, c.descent());
506 rowinfo_[row].ascent_ = asc;
507 rowinfo_[row].descent_ = desc;
509 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
510 rowinfo_[nrows()].ascent_ = 0;
511 rowinfo_[nrows()].descent_ = 0;
513 // compute vertical offsets
514 rowinfo_[0].offset_ = 0;
515 for (row_type row = 1; row <= nrows(); ++row) {
516 rowinfo_[row].offset_ =
517 rowinfo_[row - 1].offset_ +
518 rowinfo_[row - 1].descent_ +
519 //rowinfo_[row - 1].skipPixels() +
521 //rowinfo_[row].lines_ * hlinesep() +
522 rowinfo_[row].ascent_;
525 // adjust vertical offset
532 h = rowinfo_[nrows() - 1].offset_;
535 h = rowinfo_[nrows() - 1].offset_ / 2;
537 for (row_type row = 0; row <= nrows(); ++row)
538 rowinfo_[row].offset_ -= h;
541 // compute absolute sizes of horizontal structure
542 for (col_type col = 0; col < ncols(); ++col) {
544 for (row_type row = 0; row < nrows(); ++row)
545 wid = max(wid, cell(index(row, col)).width());
546 colinfo_[col].width_ = wid;
548 colinfo_[ncols()].width_ = 0;
550 // compute horizontal offsets
551 colinfo_[0].offset_ = border();
552 for (col_type col = 1; col <= ncols(); ++col) {
553 colinfo_[col].offset_ =
554 colinfo_[col - 1].offset_ +
555 colinfo_[col - 1].width_ +
556 colinfo_[col - 1].skip_ +
558 //colinfo_[col].lines_ * vlinesep();
562 dim.wid = colinfo_[ncols() - 1].offset_
563 + colinfo_[ncols() - 1].width_
564 //+ vlinesep() * colinfo_[ncols()].lines_
567 dim.asc = -rowinfo_[0].offset_
568 + rowinfo_[0].ascent_
569 //+ hlinesep() * rowinfo_[0].lines_
572 dim.des = rowinfo_[nrows() - 1].offset_
573 + rowinfo_[nrows() - 1].descent_
574 //+ hlinesep() * rowinfo_[nrows()].lines_
579 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
581 for (idx_type idx = 0; idx < nargs(); ++idx)
582 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
586 string MathGridInset::eolString(row_type row, bool fragile) const
590 if (!rowinfo_[row].crskip_.zero())
591 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
593 // make sure an upcoming '[' does not break anything
594 if (row + 1 < nrows()) {
595 MathArray const & c = cell(index(row + 1, 0));
596 if (c.size() && c.front()->getChar() == '[')
601 // only add \\ if necessary
602 if (eol.empty() && row + 1 == nrows())
605 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
609 string MathGridInset::eocString(col_type col, col_type lastcol) const
611 if (col + 1 == lastcol)
617 void MathGridInset::addRow(row_type row)
619 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
621 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
623 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
627 void MathGridInset::appendRow()
629 rowinfo_.push_back(RowInfo());
630 //cells_.insert(cells_.end(), ncols(), MathArray());
631 for (col_type col = 0; col < ncols(); ++col) {
632 cells_.push_back(cells_type::value_type());
633 cellinfo_.push_back(CellInfo());
638 void MathGridInset::delRow(row_type row)
643 cells_type::iterator it = cells_.begin() + row * ncols();
644 cells_.erase(it, it + ncols());
646 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
647 cellinfo_.erase(jt, jt + ncols());
649 rowinfo_.erase(rowinfo_.begin() + row);
653 void MathGridInset::copyRow(row_type row)
656 for (col_type col = 0; col < ncols(); ++col)
657 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
661 void MathGridInset::swapRow(row_type row)
665 if (row + 1 == nrows())
667 for (col_type col = 0; col < ncols(); ++col)
668 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
672 void MathGridInset::addCol(col_type newcol)
674 const col_type nc = ncols();
675 const row_type nr = nrows();
676 cells_type new_cells((nc + 1) * nr);
677 vector<CellInfo> new_cellinfo((nc + 1) * nr);
679 for (row_type row = 0; row < nr; ++row)
680 for (col_type col = 0; col < nc; ++col) {
681 new_cells[row * (nc + 1) + col + (col > newcol)]
682 = cells_[row * nc + col];
683 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
684 = cellinfo_[row * nc + col];
686 swap(cells_, new_cells);
687 swap(cellinfo_, new_cellinfo);
690 inf.skip_ = defaultColSpace(newcol);
691 inf.align_ = defaultColAlign(newcol);
692 colinfo_.insert(colinfo_.begin() + newcol, inf);
696 void MathGridInset::delCol(col_type col)
702 vector<CellInfo> tmpcellinfo;
703 for (col_type i = 0; i < nargs(); ++i)
704 if (i % ncols() != col) {
705 tmpcells.push_back(cells_[i]);
706 tmpcellinfo.push_back(cellinfo_[i]);
708 swap(cells_, tmpcells);
709 swap(cellinfo_, tmpcellinfo);
711 colinfo_.erase(colinfo_.begin() + col);
715 void MathGridInset::copyCol(col_type col)
718 for (row_type row = 0; row < nrows(); ++row)
719 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
723 void MathGridInset::swapCol(col_type col)
727 if (col + 1 == ncols())
729 for (row_type row = 0; row < nrows(); ++row)
730 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
734 int MathGridInset::cellXOffset(idx_type idx) const
736 col_type c = col(idx);
737 int x = colinfo_[c].offset_;
738 char align = colinfo_[c].align_;
739 if (align == 'r' || align == 'R')
740 x += colinfo_[c].width_ - cell(idx).width();
741 if (align == 'c' || align == 'C')
742 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
747 int MathGridInset::cellYOffset(idx_type idx) const
749 return rowinfo_[row(idx)].offset_;
753 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
760 pos = cell(idx).x2pos(targetx - cell(idx).xo());
763 if (idx >= ncols() * (nrows() - 1))
766 pos = cell(idx).x2pos(targetx - cell(idx).xo());
772 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
774 // leave matrix if on the left hand edge
778 pos = cell(idx).size();
783 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
785 // leave matrix if on the right hand edge
786 if (col(idx) + 1 == ncols())
794 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
801 idx = (nrows() - 1) * ncols();
804 idx = ((nrows() - 1) / 2) * ncols();
811 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
821 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
823 pos = cell(idx).size();
828 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
835 idx -= idx % ncols();
848 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
850 if (pos < cell(idx).size()) {
851 pos = cell(idx).size();
854 if (col(idx) < ncols() - 1) {
855 idx = idx - idx % ncols() + ncols() - 1;
856 pos = cell(idx).size();
859 if (idx < nargs() - 1) {
861 pos = cell(idx).size();
868 bool MathGridInset::idxDelete(idx_type & idx)
870 // nothing to do if we have just one row
874 // nothing to do if we are in the middle of the last row of the inset
875 if (idx + ncols() > nargs())
878 // try to delete entire sequence of ncols() empty cells if possible
879 for (idx_type i = idx; i < idx + ncols(); ++i)
883 // move cells if necessary
884 for (idx_type i = index(row(idx), 0); i < idx; ++i)
885 std::swap(cell(i), cell(i + ncols()));
892 // undo effect of Ctrl-Tab (i.e. pull next cell)
893 //if (idx + 1 != nargs())
894 // cell(idx).swap(cell(idx + 1));
896 // we handled the event..
901 // reimplement old behaviour when pressing Delete in the last position
903 void MathGridInset::idxGlue(idx_type idx)
905 col_type c = col(idx);
906 if (c + 1 == ncols()) {
907 if (row(idx) + 1 != nrows()) {
908 for (col_type cc = 0; cc < ncols(); ++cc)
909 cell(idx).append(cell(idx + cc + 1));
910 delRow(row(idx) + 1);
913 cell(idx).append(cell(idx + 1));
914 for (col_type cc = c + 2; cc < ncols(); ++cc)
915 cell(idx - c + cc - 1) = cell(idx - c + cc);
916 cell(idx - c + ncols() - 1).clear();
921 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
923 return rowinfo_[row];
927 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
929 return rowinfo_[row];
933 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
935 row_type const ri = row(idx);
936 row_type const r1 = min(row(from), row(to));
937 row_type const r2 = max(row(from), row(to));
938 col_type const ci = col(idx);
939 col_type const c1 = min(col(from), col(to));
940 col_type const c2 = max(col(from), col(to));
941 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
946 void MathGridInset::normalize(NormalStream & os) const
949 for (row_type row = 0; row < nrows(); ++row) {
951 for (col_type col = 0; col < ncols(); ++col)
952 os << "[cell " << cell(index(row, col)) << ']';
959 void MathGridInset::mathmlize(MathMLStream & os) const
961 os << MTag("mtable");
962 for (row_type row = 0; row < nrows(); ++row) {
964 for (col_type col = 0; col < ncols(); ++col)
965 os << cell(index(row, col));
968 os << ETag("mtable");
972 void MathGridInset::write(WriteStream & os) const
974 for (row_type row = 0; row < nrows(); ++row) {
975 os << verboseHLine(rowinfo_[row].lines_);
976 // don't write & and empty cells at end of line
977 col_type lastcol = 0;
978 bool emptyline = true;
979 for (col_type col = 0; col < ncols(); ++col)
980 if (!cell(index(row, col)).empty()) {
984 for (col_type col = 0; col < lastcol; ++col)
985 os << cell(index(row, col)) << eocString(col, lastcol);
986 os << eolString(row, os.fragile());
987 // append newline only if line wasn't completely empty
988 // and this was not the last line in the grid
989 if (!emptyline && row + 1 < nrows())
992 string const s = verboseHLine(rowinfo_[nrows()].lines_);
993 if (!s.empty() && s != " ") {
1001 int MathGridInset::colsep() const
1007 int MathGridInset::rowsep() const
1013 int MathGridInset::hlinesep() const
1019 int MathGridInset::vlinesep() const
1025 int MathGridInset::border() const
1031 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1033 if (idx + 1 == nargs())
1035 MathArray ar = cell(idx);
1037 cell(idx).erase(pos, cell(idx).size());
1040 cell(idx).insert(0, ar);
1044 dispatch_result MathGridInset::dispatch
1045 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1047 switch (cmd.action) {
1049 case LFUN_MOUSE_RELEASE:
1050 //if (cmd.button() == mouse_button::button3) {
1051 // GridInsetMailer(*this).showDialog();
1052 // return DISPATCHED;
1054 return UNDISPATCHED;
1056 case LFUN_INSET_DIALOG_UPDATE:
1057 GridInsetMailer(*this).updateDialog(cmd.view());
1058 return UNDISPATCHED;
1060 // insert file functions
1061 case LFUN_DELETE_LINE_FORWARD:
1062 //autocorrect_ = false;
1072 if (pos > cell(idx).size())
1073 pos = cell(idx).size();
1074 return DISPATCHED_POP;
1076 case LFUN_CELL_SPLIT:
1077 //recordUndo(bv, Undo::ATOMIC);
1078 splitCell(idx, pos);
1079 return DISPATCHED_POP;
1081 case LFUN_BREAKLINE: {
1082 //recordUndo(bv, Undo::INSERT);
1083 row_type const r = row(idx);
1087 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1088 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1091 splitCell(idx, pos);
1092 std::swap(cell(idx), cell(idx + ncols() - 1));
1095 pos = cell(idx).size();
1097 //mathcursor->normalize();
1098 return DISPATCHED_POP;
1101 case LFUN_TABULAR_FEATURE: {
1102 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1103 istringstream is(cmd.argument);
1106 if (s == "valign-top")
1108 else if (s == "valign-middle")
1110 else if (s == "valign-bottom")
1112 else if (s == "align-left")
1113 halign('l', col(idx));
1114 else if (s == "align-right")
1115 halign('r', col(idx));
1116 else if (s == "align-center")
1117 halign('c', col(idx));
1118 else if (s == "append-row")
1119 for (int i = 0, n = extractInt(is); i < n; ++i)
1121 else if (s == "delete-row")
1122 for (int i = 0, n = extractInt(is); i < n; ++i) {
1127 else if (s == "copy-row")
1128 for (int i = 0, n = extractInt(is); i < n; ++i)
1130 else if (s == "swap-row")
1132 else if (s == "append-column")
1133 for (int i = 0, n = extractInt(is); i < n; ++i) {
1134 row_type r = row(idx);
1135 col_type c = col(idx);
1139 else if (s == "delete-column")
1140 for (int i = 0, n = extractInt(is); i < n; ++i) {
1141 row_type r = row(idx);
1142 col_type c = col(idx);
1148 else if (s == "copy-column")
1150 else if (s == "swap-column")
1153 return UNDISPATCHED;
1154 lyxerr << "returning DISPATCHED_POP" << endl;
1155 return DISPATCHED_POP;
1159 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1160 MathGridInset grid(1, 1);
1161 mathed_parse_normal(grid, cmd.argument);
1162 if (grid.nargs() == 1) {
1163 // single cell/part of cell
1164 cell(idx).insert(pos, grid.cell(0));
1165 pos += grid.cell(0).size();
1168 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1169 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1170 for (row_type r = 0; r < numrows; ++r) {
1171 for (col_type c = 0; c < numcols; ++c) {
1172 idx_type i = index(r + row(idx), c + col(idx));
1173 cell(i).insert(0, grid.cell(grid.index(r, c)));
1175 // append the left over horizontal cells to the last column
1176 idx_type i = index(r + row(idx), ncols() - 1);
1177 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1178 cell(i).append(grid.cell(grid.index(r, c)));
1180 // append the left over vertical cells to the last _cell_
1181 idx_type i = nargs() - 1;
1182 for (row_type r = numrows; r < grid.nrows(); ++r)
1183 for (col_type c = 0; c < grid.ncols(); ++c)
1184 cell(i).append(grid.cell(grid.index(r, c)));
1186 return DISPATCHED_POP;
1190 return MathNestInset::dispatch(cmd, idx, pos);