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"
17 #include "funcrequest.h"
18 #include "frontends/Painter.h"
23 #include "insets/mailinset.h"
34 class GridInsetMailer : public MailInset {
36 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
38 virtual string const & name() const
40 static string const theName = "tabular";
44 virtual string const inset2string(Buffer const &) const
47 //data << name() << " active_cell " << inset.getActCell() << '\n';
48 data << name() << " active_cell " << 0 << '\n';
51 return STRCONV(data.str());
55 InsetBase & inset() const { return inset_; }
56 MathGridInset & inset_;
60 void mathed_parse_normal(MathGridInset &, string const & argument);
64 string verboseHLine(int n)
67 for (int i = 0; i < n; ++i)
75 int extractInt(istream & is)
79 return (num == 0) ? 1 : num;
85 //////////////////////////////////////////////////////////////
88 MathGridInset::CellInfo::CellInfo()
95 //////////////////////////////////////////////////////////////
98 MathGridInset::RowInfo::RowInfo()
104 int MathGridInset::RowInfo::skipPixels() const
106 return crskip_.inBP();
111 //////////////////////////////////////////////////////////////
114 MathGridInset::ColInfo::ColInfo()
115 : align_('c'), leftline_(false), rightline_(false), lines_(0)
119 //////////////////////////////////////////////////////////////
122 MathGridInset::MathGridInset(char v, string const & h)
123 : MathNestInset(guessColumns(h)),
125 colinfo_(guessColumns(h) + 1),
126 cellinfo_(1 * guessColumns(h))
131 //lyxerr << "created grid with " << ncols() << " columns" << endl;
135 MathGridInset::MathGridInset()
146 MathGridInset::MathGridInset(col_type m, row_type n)
147 : MathNestInset(m * n),
157 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
158 : MathNestInset(m * n),
170 MathGridInset::~MathGridInset()
172 GridInsetMailer mailer(*this);
177 auto_ptr<InsetBase> MathGridInset::clone() const
179 return auto_ptr<InsetBase>(new MathGridInset(*this));
183 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
185 return col + ncols() * row;
189 void MathGridInset::setDefaults()
192 lyxerr << "positive number of columns expected" << endl;
194 // lyxerr << "positive number of rows expected" << endl;
195 for (col_type col = 0; col < ncols(); ++col) {
196 colinfo_[col].align_ = defaultColAlign(col);
197 colinfo_[col].skip_ = defaultColSpace(col);
202 void MathGridInset::halign(string const & hh)
205 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
210 colinfo_[col].lines_++;
211 } else if (c == 'c' || c == 'l' || c == 'r') {
212 colinfo_[col].align_ = c;
214 colinfo_[col].lines_ = 0;
216 lyxerr << "unknown column separator: '" << c << "'" << endl;
221 col_type n = hh.size();
224 for (col_type col = 0; col < n; ++col)
225 colinfo_[col].align_ = hh[col];
230 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
233 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
234 if (*it == 'c' || *it == 'l' || *it == 'r')
236 // let's have at least one column, even if we did not recognize its
244 void MathGridInset::halign(char h, col_type col)
246 colinfo_[col].align_ = h;
250 char MathGridInset::halign(col_type col) const
252 return colinfo_[col].align_;
256 string MathGridInset::halign() const
259 for (col_type col = 0; col < ncols(); ++col) {
260 res += string(colinfo_[col].lines_, '|');
261 res += colinfo_[col].align_;
263 return res + string(colinfo_[ncols()].lines_, '|');
267 void MathGridInset::valign(char c)
273 char MathGridInset::valign() const
279 MathGridInset::col_type MathGridInset::ncols() const
281 return colinfo_.size() - 1;
285 MathGridInset::row_type MathGridInset::nrows() const
287 return rowinfo_.size() - 1;
291 MathGridInset::col_type MathGridInset::col(idx_type idx) const
293 return idx % ncols();
297 MathGridInset::row_type MathGridInset::row(idx_type idx) const
299 return idx / ncols();
303 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
305 rowinfo_[row].crskip_ = crskip;
309 LyXLength MathGridInset::vcrskip(row_type row) const
311 return rowinfo_[row].crskip_;
315 void MathGridInset::metrics(MetricsInfo & mi) const
317 // let the cells adjust themselves
318 MathNestInset::metrics(mi);
320 // compute absolute sizes of vertical structure
321 for (row_type row = 0; row < nrows(); ++row) {
324 for (col_type col = 0; col < ncols(); ++col) {
325 MathArray const & c = cell(index(row, col));
326 asc = max(asc, c.ascent());
327 desc = max(desc, c.descent());
329 rowinfo_[row].ascent_ = asc;
330 rowinfo_[row].descent_ = desc;
332 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
333 rowinfo_[nrows()].ascent_ = 0;
334 rowinfo_[nrows()].descent_ = 0;
336 // compute vertical offsets
337 rowinfo_[0].offset_ = 0;
338 for (row_type row = 1; row <= nrows(); ++row) {
339 rowinfo_[row].offset_ =
340 rowinfo_[row - 1].offset_ +
341 rowinfo_[row - 1].descent_ +
342 rowinfo_[row - 1].skipPixels() +
344 rowinfo_[row].lines_ * hlinesep() +
345 rowinfo_[row].ascent_;
348 // adjust vertical offset
355 h = rowinfo_[nrows() - 1].offset_;
358 h = rowinfo_[nrows() - 1].offset_ / 2;
360 for (row_type row = 0; row <= nrows(); ++row)
361 rowinfo_[row].offset_ -= h;
364 // compute absolute sizes of horizontal structure
365 for (col_type col = 0; col < ncols(); ++col) {
367 for (row_type row = 0; row < nrows(); ++row)
368 wid = max(wid, cell(index(row, col)).width());
369 colinfo_[col].width_ = wid;
371 colinfo_[ncols()].width_ = 0;
373 // compute horizontal offsets
374 colinfo_[0].offset_ = border();
375 for (col_type col = 1; col <= ncols(); ++col) {
376 colinfo_[col].offset_ =
377 colinfo_[col - 1].offset_ +
378 colinfo_[col - 1].width_ +
379 colinfo_[col - 1].skip_ +
381 colinfo_[col].lines_ * vlinesep();
385 dim_.wid = colinfo_[ncols() - 1].offset_
386 + colinfo_[ncols() - 1].width_
387 + vlinesep() * colinfo_[ncols()].lines_
390 dim_.asc = - rowinfo_[0].offset_
391 + rowinfo_[0].ascent_
392 + hlinesep() * rowinfo_[0].lines_
395 dim_.des = rowinfo_[nrows() - 1].offset_
396 + rowinfo_[nrows() - 1].descent_
397 + hlinesep() * rowinfo_[nrows()].lines_
402 // Increase ws_[i] for 'R' columns (except the first one)
403 for (int i = 1; i < nc_; ++i)
404 if (align_[i] == 'R')
405 ws_[i] += 10 * df_width;
406 // Increase ws_[i] for 'C' column
407 if (align_[0] == 'C')
408 if (ws_[0] < 7 * workwidth / 8)
409 ws_[0] = 7 * workwidth / 8;
413 for (cxrow = row_.begin(); cxrow; ++cxrow) {
416 for (int i = 0; i < nc_; ++i) {
418 if (cxrow->getTab(i) <= 0) {
419 cxrow->setTab(i, df_width);
427 lf = (ws_[i] - cxrow->getTab(i))/2;
431 lf = ws_[i] - cxrow->getTab(i);
434 if (cxrow == row_.begin())
436 else if (cxrow.is_last())
437 lf = ws_[i] - cxrow->getTab(i);
439 lf = (ws_[i] - cxrow->getTab(i))/2;
442 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
443 cxrow->setTab(i, lf + rg);
444 rg = ws_[i] - ww + colsep();
445 if (cxrow == row_.begin())
446 width += ws_[i] + colsep();
448 cxrow->setBaseline(cxrow->getBaseline() - ascent);
454 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
461 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
463 for (idx_type idx = 0; idx < nargs(); ++idx)
464 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
466 for (row_type row = 0; row <= nrows(); ++row)
467 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
468 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
469 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
470 pi.pain.line(x + 1, yy, x + dim_.width() - 1, yy);
473 for (col_type col = 0; col <= ncols(); ++col)
474 for (int i = 0; i < colinfo_[col].lines_; ++i) {
475 int xx = x + colinfo_[col].offset_
476 - i * vlinesep() - vlinesep()/2 - colsep()/2;
477 pi.pain.line(xx, y - dim_.ascent() + 1, xx, y + dim_.descent() - 1);
482 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
484 // let the cells adjust themselves
485 //MathNestInset::metrics(mi);
486 for (idx_type i = 0; i < nargs(); ++i)
487 cell(i).metricsT(mi, dim);
489 // compute absolute sizes of vertical structure
490 for (row_type row = 0; row < nrows(); ++row) {
493 for (col_type col = 0; col < ncols(); ++col) {
494 MathArray const & c = cell(index(row, col));
495 asc = max(asc, c.ascent());
496 desc = max(desc, c.descent());
498 rowinfo_[row].ascent_ = asc;
499 rowinfo_[row].descent_ = desc;
501 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
502 rowinfo_[nrows()].ascent_ = 0;
503 rowinfo_[nrows()].descent_ = 0;
505 // compute vertical offsets
506 rowinfo_[0].offset_ = 0;
507 for (row_type row = 1; row <= nrows(); ++row) {
508 rowinfo_[row].offset_ =
509 rowinfo_[row - 1].offset_ +
510 rowinfo_[row - 1].descent_ +
511 //rowinfo_[row - 1].skipPixels() +
513 //rowinfo_[row].lines_ * hlinesep() +
514 rowinfo_[row].ascent_;
517 // adjust vertical offset
524 h = rowinfo_[nrows() - 1].offset_;
527 h = rowinfo_[nrows() - 1].offset_ / 2;
529 for (row_type row = 0; row <= nrows(); ++row)
530 rowinfo_[row].offset_ -= h;
533 // compute absolute sizes of horizontal structure
534 for (col_type col = 0; col < ncols(); ++col) {
536 for (row_type row = 0; row < nrows(); ++row)
537 wid = max(wid, cell(index(row, col)).width());
538 colinfo_[col].width_ = wid;
540 colinfo_[ncols()].width_ = 0;
542 // compute horizontal offsets
543 colinfo_[0].offset_ = border();
544 for (col_type col = 1; col <= ncols(); ++col) {
545 colinfo_[col].offset_ =
546 colinfo_[col - 1].offset_ +
547 colinfo_[col - 1].width_ +
548 colinfo_[col - 1].skip_ +
550 //colinfo_[col].lines_ * vlinesep();
554 dim.wid = colinfo_[ncols() - 1].offset_
555 + colinfo_[ncols() - 1].width_
556 //+ vlinesep() * colinfo_[ncols()].lines_
559 dim.asc = -rowinfo_[0].offset_
560 + rowinfo_[0].ascent_
561 //+ hlinesep() * rowinfo_[0].lines_
564 dim.des = rowinfo_[nrows() - 1].offset_
565 + rowinfo_[nrows() - 1].descent_
566 //+ hlinesep() * rowinfo_[nrows()].lines_
571 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
573 for (idx_type idx = 0; idx < nargs(); ++idx)
574 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
578 string MathGridInset::eolString(row_type row, bool fragile) const
582 if (!rowinfo_[row].crskip_.zero())
583 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
585 // make sure an upcoming '[' does not break anything
586 if (row + 1 < nrows()) {
587 MathArray const & c = cell(index(row + 1, 0));
588 if (c.size() && c.front()->getChar() == '[')
593 // only add \\ if necessary
594 if (eol.empty() && row + 1 == nrows())
597 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
601 string MathGridInset::eocString(col_type col, col_type lastcol) const
603 if (col + 1 == lastcol)
609 void MathGridInset::addRow(row_type row)
611 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
613 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
615 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
619 void MathGridInset::appendRow()
621 rowinfo_.push_back(RowInfo());
622 //cells_.insert(cells_.end(), ncols(), MathArray());
623 for (col_type col = 0; col < ncols(); ++col) {
624 cells_.push_back(cells_type::value_type());
625 cellinfo_.push_back(CellInfo());
630 void MathGridInset::delRow(row_type row)
635 cells_type::iterator it = cells_.begin() + row * ncols();
636 cells_.erase(it, it + ncols());
638 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
639 cellinfo_.erase(jt, jt + ncols());
641 rowinfo_.erase(rowinfo_.begin() + row);
645 void MathGridInset::copyRow(row_type row)
648 for (col_type col = 0; col < ncols(); ++col)
649 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
653 void MathGridInset::swapRow(row_type row)
657 if (row + 1 == nrows())
659 for (col_type col = 0; col < ncols(); ++col)
660 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
664 void MathGridInset::addCol(col_type newcol)
666 const col_type nc = ncols();
667 const row_type nr = nrows();
668 cells_type new_cells((nc + 1) * nr);
669 vector<CellInfo> new_cellinfo((nc + 1) * nr);
671 for (row_type row = 0; row < nr; ++row)
672 for (col_type col = 0; col < nc; ++col) {
673 new_cells[row * (nc + 1) + col + (col > newcol)]
674 = cells_[row * nc + col];
675 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
676 = cellinfo_[row * nc + col];
678 swap(cells_, new_cells);
679 swap(cellinfo_, new_cellinfo);
682 inf.skip_ = defaultColSpace(newcol);
683 inf.align_ = defaultColAlign(newcol);
684 colinfo_.insert(colinfo_.begin() + newcol, inf);
688 void MathGridInset::delCol(col_type col)
694 vector<CellInfo> tmpcellinfo;
695 for (col_type i = 0; i < nargs(); ++i)
696 if (i % ncols() != col) {
697 tmpcells.push_back(cells_[i]);
698 tmpcellinfo.push_back(cellinfo_[i]);
700 swap(cells_, tmpcells);
701 swap(cellinfo_, tmpcellinfo);
703 colinfo_.erase(colinfo_.begin() + col);
707 void MathGridInset::copyCol(col_type col)
710 for (row_type row = 0; row < nrows(); ++row)
711 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
715 void MathGridInset::swapCol(col_type col)
719 if (col + 1 == ncols())
721 for (row_type row = 0; row < nrows(); ++row)
722 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
726 int MathGridInset::cellXOffset(idx_type idx) const
728 col_type c = col(idx);
729 int x = colinfo_[c].offset_;
730 char align = colinfo_[c].align_;
731 if (align == 'r' || align == 'R')
732 x += colinfo_[c].width_ - cell(idx).width();
733 if (align == 'c' || align == 'C')
734 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
739 int MathGridInset::cellYOffset(idx_type idx) const
741 return rowinfo_[row(idx)].offset_;
745 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
752 pos = cell(idx).x2pos(targetx - cell(idx).xo());
755 if (idx >= ncols() * (nrows() - 1))
758 pos = cell(idx).x2pos(targetx - cell(idx).xo());
764 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
766 // leave matrix if on the left hand edge
770 pos = cell(idx).size();
775 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
777 // leave matrix if on the right hand edge
778 if (col(idx) + 1 == ncols())
786 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
793 idx = (nrows() - 1) * ncols();
796 idx = ((nrows() - 1) / 2) * ncols();
803 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
813 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
815 pos = cell(idx).size();
820 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
827 idx -= idx % ncols();
840 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
842 if (pos < cell(idx).size()) {
843 pos = cell(idx).size();
846 if (col(idx) < ncols() - 1) {
847 idx = idx - idx % ncols() + ncols() - 1;
848 pos = cell(idx).size();
851 if (idx < nargs() - 1) {
853 pos = cell(idx).size();
860 bool MathGridInset::idxDelete(idx_type & idx)
862 // nothing to do if we have just one row
866 // nothing to do if we are in the middle of the last row of the inset
867 if (idx + ncols() > nargs())
870 // try to delete entire sequence of ncols() empty cells if possible
871 for (idx_type i = idx; i < idx + ncols(); ++i)
875 // move cells if necessary
876 for (idx_type i = index(row(idx), 0); i < idx; ++i)
877 std::swap(cell(i), cell(i + ncols()));
884 // undo effect of Ctrl-Tab (i.e. pull next cell)
885 //if (idx + 1 != nargs())
886 // cell(idx).swap(cell(idx + 1));
888 // we handled the event..
893 // reimplement old behaviour when pressing Delete in the last position
895 void MathGridInset::idxGlue(idx_type idx)
897 col_type c = col(idx);
898 if (c + 1 == ncols()) {
899 if (row(idx) + 1 != nrows()) {
900 for (col_type cc = 0; cc < ncols(); ++cc)
901 cell(idx).append(cell(idx + cc + 1));
902 delRow(row(idx) + 1);
905 cell(idx).append(cell(idx + 1));
906 for (col_type cc = c + 2; cc < ncols(); ++cc)
907 cell(idx - c + cc - 1) = cell(idx - c + cc);
908 cell(idx - c + ncols() - 1).clear();
913 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
915 return rowinfo_[row];
919 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
921 return rowinfo_[row];
925 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
927 row_type const ri = row(idx);
928 row_type const r1 = min(row(from), row(to));
929 row_type const r2 = max(row(from), row(to));
930 col_type const ci = col(idx);
931 col_type const c1 = min(col(from), col(to));
932 col_type const c2 = max(col(from), col(to));
933 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
938 void MathGridInset::normalize(NormalStream & os) const
941 for (row_type row = 0; row < nrows(); ++row) {
943 for (col_type col = 0; col < ncols(); ++col)
944 os << "[cell " << cell(index(row, col)) << ']';
951 void MathGridInset::mathmlize(MathMLStream & os) const
953 os << MTag("mtable");
954 for (row_type row = 0; row < nrows(); ++row) {
956 for (col_type col = 0; col < ncols(); ++col)
957 os << cell(index(row, col));
960 os << ETag("mtable");
964 void MathGridInset::write(WriteStream & os) const
966 for (row_type row = 0; row < nrows(); ++row) {
967 os << verboseHLine(rowinfo_[row].lines_);
968 // don't write & and empty cells at end of line
969 col_type lastcol = 0;
970 bool emptyline = true;
971 for (col_type col = 0; col < ncols(); ++col)
972 if (!cell(index(row, col)).empty()) {
976 for (col_type col = 0; col < lastcol; ++col)
977 os << cell(index(row, col)) << eocString(col, lastcol);
978 os << eolString(row, os.fragile());
979 // append newline only if line wasn't completely empty
980 // and this was not the last line in the grid
981 if (!emptyline && row + 1 < nrows())
984 string const s = verboseHLine(rowinfo_[nrows()].lines_);
985 if (!s.empty() && s != " ") {
993 int MathGridInset::colsep() const
999 int MathGridInset::rowsep() const
1005 int MathGridInset::hlinesep() const
1011 int MathGridInset::vlinesep() const
1017 int MathGridInset::border() const
1023 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1025 if (idx + 1 == nargs())
1027 MathArray ar = cell(idx);
1029 cell(idx).erase(pos, cell(idx).size());
1032 cell(idx).insert(0, ar);
1036 dispatch_result MathGridInset::dispatch
1037 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1039 switch (cmd.action) {
1041 case LFUN_MOUSE_RELEASE:
1042 //if (cmd.button() == mouse_button::button3) {
1043 // GridInsetMailer(*this).showDialog();
1044 // return DISPATCHED;
1046 return UNDISPATCHED;
1048 case LFUN_INSET_DIALOG_UPDATE:
1049 GridInsetMailer(*this).updateDialog(cmd.view());
1050 return UNDISPATCHED;
1052 // insert file functions
1053 case LFUN_DELETE_LINE_FORWARD:
1054 //autocorrect_ = false;
1064 if (pos > cell(idx).size())
1065 pos = cell(idx).size();
1066 return DISPATCHED_POP;
1068 case LFUN_CELL_SPLIT:
1069 //recordUndo(bv, Undo::ATOMIC);
1070 splitCell(idx, pos);
1071 return DISPATCHED_POP;
1073 case LFUN_BREAKLINE: {
1074 //recordUndo(bv, Undo::INSERT);
1075 row_type const r = row(idx);
1079 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1080 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1083 splitCell(idx, pos);
1084 std::swap(cell(idx), cell(idx + ncols() - 1));
1087 pos = cell(idx).size();
1089 //mathcursor->normalize();
1090 return DISPATCHED_POP;
1093 case LFUN_TABULAR_FEATURE: {
1094 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1095 istringstream is(STRCONV(cmd.argument));
1098 if (s == "valign-top")
1100 else if (s == "valign-middle")
1102 else if (s == "valign-bottom")
1104 else if (s == "align-left")
1105 halign('l', col(idx));
1106 else if (s == "align-right")
1107 halign('r', col(idx));
1108 else if (s == "align-center")
1109 halign('c', col(idx));
1110 else if (s == "append-row")
1111 for (int i = 0, n = extractInt(is); i < n; ++i)
1113 else if (s == "delete-row")
1114 for (int i = 0, n = extractInt(is); i < n; ++i) {
1119 else if (s == "copy-row")
1120 for (int i = 0, n = extractInt(is); i < n; ++i)
1122 else if (s == "swap-row")
1124 else if (s == "append-column")
1125 for (int i = 0, n = extractInt(is); i < n; ++i) {
1126 row_type r = row(idx);
1127 col_type c = col(idx);
1131 else if (s == "delete-column")
1132 for (int i = 0, n = extractInt(is); i < n; ++i) {
1133 row_type r = row(idx);
1134 col_type c = col(idx);
1140 else if (s == "copy-column")
1142 else if (s == "swap-column")
1145 return UNDISPATCHED;
1146 lyxerr << "returning DISPATCHED_POP" << endl;
1147 return DISPATCHED_POP;
1151 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1152 MathGridInset grid(1, 1);
1153 mathed_parse_normal(grid, cmd.argument);
1154 if (grid.nargs() == 1) {
1155 // single cell/part of cell
1156 cell(idx).insert(pos, grid.cell(0));
1157 pos += grid.cell(0).size();
1160 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1161 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1162 for (row_type r = 0; r < numrows; ++r) {
1163 for (col_type c = 0; c < numcols; ++c) {
1164 idx_type i = index(r + row(idx), c + col(idx));
1165 cell(i).append(grid.cell(grid.index(r, c)));
1167 // append the left over horizontal cells to the last column
1168 idx_type i = index(r + row(idx), ncols() - 1);
1169 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1170 cell(i).append(grid.cell(grid.index(r, c)));
1172 // append the left over vertical cells to the last _cell_
1173 idx_type i = nargs() - 1;
1174 for (row_type r = numrows; r < grid.nrows(); ++r)
1175 for (col_type c = 0; c < grid.ncols(); ++c)
1176 cell(i).append(grid.cell(grid.index(r, c)));
1178 return DISPATCHED_POP;
1182 return MathNestInset::dispatch(cmd, idx, pos);