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"
22 #include "insets/mailinset.h"
33 class GridInsetMailer : public MailInset {
35 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
37 virtual string const & name() const
39 static string const theName = "tabular";
43 virtual string const inset2string(Buffer const &) const
46 //data << name() << " active_cell " << inset.getActCell() << '\n';
47 data << name() << " active_cell " << 0 << '\n';
50 return STRCONV(data.str());
54 InsetBase & inset() const { return inset_; }
55 MathGridInset & inset_;
59 void mathed_parse_normal(MathGridInset &, string const & argument);
63 string verboseHLine(int n)
66 for (int i = 0; i < n; ++i)
74 int extractInt(istream & is)
78 return (num == 0) ? 1 : num;
84 //////////////////////////////////////////////////////////////
87 MathGridInset::CellInfo::CellInfo()
94 //////////////////////////////////////////////////////////////
97 MathGridInset::RowInfo::RowInfo()
103 int MathGridInset::RowInfo::skipPixels() const
105 return crskip_.inBP();
110 //////////////////////////////////////////////////////////////
113 MathGridInset::ColInfo::ColInfo()
114 : align_('c'), leftline_(false), rightline_(false), lines_(0)
118 //////////////////////////////////////////////////////////////
121 MathGridInset::MathGridInset(char v, string const & h)
122 : MathNestInset(guessColumns(h)),
124 colinfo_(guessColumns(h) + 1),
125 cellinfo_(1 * guessColumns(h))
130 //lyxerr << "created grid with " << ncols() << " columns" << endl;
134 MathGridInset::MathGridInset()
145 MathGridInset::MathGridInset(col_type m, row_type n)
146 : MathNestInset(m * n),
156 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
157 : MathNestInset(m * n),
169 MathGridInset::~MathGridInset()
171 GridInsetMailer mailer(*this);
176 auto_ptr<InsetBase> MathGridInset::clone() const
178 return auto_ptr<InsetBase>(new MathGridInset(*this));
182 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
184 return col + ncols() * row;
188 void MathGridInset::setDefaults()
191 lyxerr << "positive number of columns expected" << endl;
193 // lyxerr << "positive number of rows expected" << endl;
194 for (col_type col = 0; col < ncols(); ++col) {
195 colinfo_[col].align_ = defaultColAlign(col);
196 colinfo_[col].skip_ = defaultColSpace(col);
201 void MathGridInset::halign(string const & hh)
204 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
209 colinfo_[col].lines_++;
210 } else if (c == 'c' || c == 'l' || c == 'r') {
211 colinfo_[col].align_ = c;
213 colinfo_[col].lines_ = 0;
215 lyxerr << "unknown column separator: '" << c << "'" << endl;
220 col_type n = hh.size();
223 for (col_type col = 0; col < n; ++col)
224 colinfo_[col].align_ = hh[col];
229 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
232 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
233 if (*it == 'c' || *it == 'l' || *it == 'r')
235 // let's have at least one column, even if we did not recognize its
243 void MathGridInset::halign(char h, col_type col)
245 colinfo_[col].align_ = h;
249 char MathGridInset::halign(col_type col) const
251 return colinfo_[col].align_;
255 string MathGridInset::halign() const
258 for (col_type col = 0; col < ncols(); ++col) {
259 res += string(colinfo_[col].lines_, '|');
260 res += colinfo_[col].align_;
262 return res + string(colinfo_[ncols()].lines_, '|');
266 void MathGridInset::valign(char c)
272 char MathGridInset::valign() const
278 MathGridInset::col_type MathGridInset::ncols() const
280 return colinfo_.size() - 1;
284 MathGridInset::row_type MathGridInset::nrows() const
286 return rowinfo_.size() - 1;
290 MathGridInset::col_type MathGridInset::col(idx_type idx) const
292 return idx % ncols();
296 MathGridInset::row_type MathGridInset::row(idx_type idx) const
298 return idx / ncols();
302 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
304 rowinfo_[row].crskip_ = crskip;
308 LyXLength MathGridInset::vcrskip(row_type row) const
310 return rowinfo_[row].crskip_;
314 void MathGridInset::metrics(MetricsInfo & mi) const
316 // let the cells adjust themselves
317 MathNestInset::metrics(mi);
319 // compute absolute sizes of vertical structure
320 for (row_type row = 0; row < nrows(); ++row) {
323 for (col_type col = 0; col < ncols(); ++col) {
324 MathArray const & c = cell(index(row, col));
325 asc = max(asc, c.ascent());
326 desc = max(desc, c.descent());
328 rowinfo_[row].ascent_ = asc;
329 rowinfo_[row].descent_ = desc;
331 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
332 rowinfo_[nrows()].ascent_ = 0;
333 rowinfo_[nrows()].descent_ = 0;
335 // compute vertical offsets
336 rowinfo_[0].offset_ = 0;
337 for (row_type row = 1; row <= nrows(); ++row) {
338 rowinfo_[row].offset_ =
339 rowinfo_[row - 1].offset_ +
340 rowinfo_[row - 1].descent_ +
341 rowinfo_[row - 1].skipPixels() +
343 rowinfo_[row].lines_ * hlinesep() +
344 rowinfo_[row].ascent_;
347 // adjust vertical offset
354 h = rowinfo_[nrows() - 1].offset_;
357 h = rowinfo_[nrows() - 1].offset_ / 2;
359 for (row_type row = 0; row <= nrows(); ++row)
360 rowinfo_[row].offset_ -= h;
363 // compute absolute sizes of horizontal structure
364 for (col_type col = 0; col < ncols(); ++col) {
366 for (row_type row = 0; row < nrows(); ++row)
367 wid = max(wid, cell(index(row, col)).width());
368 colinfo_[col].width_ = wid;
370 colinfo_[ncols()].width_ = 0;
372 // compute horizontal offsets
373 colinfo_[0].offset_ = border();
374 for (col_type col = 1; col <= ncols(); ++col) {
375 colinfo_[col].offset_ =
376 colinfo_[col - 1].offset_ +
377 colinfo_[col - 1].width_ +
378 colinfo_[col - 1].skip_ +
380 colinfo_[col].lines_ * vlinesep();
384 dim_.wid = colinfo_[ncols() - 1].offset_
385 + colinfo_[ncols() - 1].width_
386 + vlinesep() * colinfo_[ncols()].lines_
389 dim_.asc = - rowinfo_[0].offset_
390 + rowinfo_[0].ascent_
391 + hlinesep() * rowinfo_[0].lines_
394 dim_.des = rowinfo_[nrows() - 1].offset_
395 + rowinfo_[nrows() - 1].descent_
396 + hlinesep() * rowinfo_[nrows()].lines_
401 // Increase ws_[i] for 'R' columns (except the first one)
402 for (int i = 1; i < nc_; ++i)
403 if (align_[i] == 'R')
404 ws_[i] += 10 * df_width;
405 // Increase ws_[i] for 'C' column
406 if (align_[0] == 'C')
407 if (ws_[0] < 7 * workwidth / 8)
408 ws_[0] = 7 * workwidth / 8;
412 for (cxrow = row_.begin(); cxrow; ++cxrow) {
415 for (int i = 0; i < nc_; ++i) {
417 if (cxrow->getTab(i) <= 0) {
418 cxrow->setTab(i, df_width);
426 lf = (ws_[i] - cxrow->getTab(i))/2;
430 lf = ws_[i] - cxrow->getTab(i);
433 if (cxrow == row_.begin())
435 else if (cxrow.is_last())
436 lf = ws_[i] - cxrow->getTab(i);
438 lf = (ws_[i] - cxrow->getTab(i))/2;
441 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
442 cxrow->setTab(i, lf + rg);
443 rg = ws_[i] - ww + colsep();
444 if (cxrow == row_.begin())
445 width += ws_[i] + colsep();
447 cxrow->setBaseline(cxrow->getBaseline() - ascent);
453 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
460 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
462 for (idx_type idx = 0; idx < nargs(); ++idx)
463 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
465 for (row_type row = 0; row <= nrows(); ++row)
466 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
467 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
468 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
469 pi.pain.line(x + 1, yy, x + dim_.width() - 1, yy);
472 for (col_type col = 0; col <= ncols(); ++col)
473 for (int i = 0; i < colinfo_[col].lines_; ++i) {
474 int xx = x + colinfo_[col].offset_
475 - i * vlinesep() - vlinesep()/2 - colsep()/2;
476 pi.pain.line(xx, y - dim_.ascent() + 1, xx, y + dim_.descent() - 1);
481 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
483 // let the cells adjust themselves
484 //MathNestInset::metrics(mi);
485 for (idx_type i = 0; i < nargs(); ++i)
486 cell(i).metricsT(mi, dim);
488 // compute absolute sizes of vertical structure
489 for (row_type row = 0; row < nrows(); ++row) {
492 for (col_type col = 0; col < ncols(); ++col) {
493 MathArray const & c = cell(index(row, col));
494 asc = max(asc, c.ascent());
495 desc = max(desc, c.descent());
497 rowinfo_[row].ascent_ = asc;
498 rowinfo_[row].descent_ = desc;
500 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
501 rowinfo_[nrows()].ascent_ = 0;
502 rowinfo_[nrows()].descent_ = 0;
504 // compute vertical offsets
505 rowinfo_[0].offset_ = 0;
506 for (row_type row = 1; row <= nrows(); ++row) {
507 rowinfo_[row].offset_ =
508 rowinfo_[row - 1].offset_ +
509 rowinfo_[row - 1].descent_ +
510 //rowinfo_[row - 1].skipPixels() +
512 //rowinfo_[row].lines_ * hlinesep() +
513 rowinfo_[row].ascent_;
516 // adjust vertical offset
523 h = rowinfo_[nrows() - 1].offset_;
526 h = rowinfo_[nrows() - 1].offset_ / 2;
528 for (row_type row = 0; row <= nrows(); ++row)
529 rowinfo_[row].offset_ -= h;
532 // compute absolute sizes of horizontal structure
533 for (col_type col = 0; col < ncols(); ++col) {
535 for (row_type row = 0; row < nrows(); ++row)
536 wid = max(wid, cell(index(row, col)).width());
537 colinfo_[col].width_ = wid;
539 colinfo_[ncols()].width_ = 0;
541 // compute horizontal offsets
542 colinfo_[0].offset_ = border();
543 for (col_type col = 1; col <= ncols(); ++col) {
544 colinfo_[col].offset_ =
545 colinfo_[col - 1].offset_ +
546 colinfo_[col - 1].width_ +
547 colinfo_[col - 1].skip_ +
549 //colinfo_[col].lines_ * vlinesep();
553 dim.wid = colinfo_[ncols() - 1].offset_
554 + colinfo_[ncols() - 1].width_
555 //+ vlinesep() * colinfo_[ncols()].lines_
558 dim.asc = -rowinfo_[0].offset_
559 + rowinfo_[0].ascent_
560 //+ hlinesep() * rowinfo_[0].lines_
563 dim.des = rowinfo_[nrows() - 1].offset_
564 + rowinfo_[nrows() - 1].descent_
565 //+ hlinesep() * rowinfo_[nrows()].lines_
570 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
572 for (idx_type idx = 0; idx < nargs(); ++idx)
573 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
577 string MathGridInset::eolString(row_type row, bool fragile) const
581 if (!rowinfo_[row].crskip_.zero())
582 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
584 // make sure an upcoming '[' does not break anything
585 if (row + 1 < nrows()) {
586 MathArray const & c = cell(index(row + 1, 0));
587 if (c.size() && c.front()->getChar() == '[')
592 // only add \\ if necessary
593 if (eol.empty() && row + 1 == nrows())
596 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
600 string MathGridInset::eocString(col_type col, col_type lastcol) const
602 if (col + 1 == lastcol)
608 void MathGridInset::addRow(row_type row)
610 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
612 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
614 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
618 void MathGridInset::appendRow()
620 rowinfo_.push_back(RowInfo());
621 //cells_.insert(cells_.end(), ncols(), MathArray());
622 for (col_type col = 0; col < ncols(); ++col) {
623 cells_.push_back(cells_type::value_type());
624 cellinfo_.push_back(CellInfo());
629 void MathGridInset::delRow(row_type row)
634 cells_type::iterator it = cells_.begin() + row * ncols();
635 cells_.erase(it, it + ncols());
637 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
638 cellinfo_.erase(jt, jt + ncols());
640 rowinfo_.erase(rowinfo_.begin() + row);
644 void MathGridInset::copyRow(row_type row)
647 for (col_type col = 0; col < ncols(); ++col)
648 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
652 void MathGridInset::swapRow(row_type row)
656 if (row + 1 == nrows())
658 for (col_type col = 0; col < ncols(); ++col)
659 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
663 void MathGridInset::addCol(col_type newcol)
665 const col_type nc = ncols();
666 const row_type nr = nrows();
667 cells_type new_cells((nc + 1) * nr);
668 vector<CellInfo> new_cellinfo((nc + 1) * nr);
670 for (row_type row = 0; row < nr; ++row)
671 for (col_type col = 0; col < nc; ++col) {
672 new_cells[row * (nc + 1) + col + (col > newcol)]
673 = cells_[row * nc + col];
674 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
675 = cellinfo_[row * nc + col];
677 swap(cells_, new_cells);
678 swap(cellinfo_, new_cellinfo);
681 inf.skip_ = defaultColSpace(newcol);
682 inf.align_ = defaultColAlign(newcol);
683 colinfo_.insert(colinfo_.begin() + newcol, inf);
687 void MathGridInset::delCol(col_type col)
693 vector<CellInfo> tmpcellinfo;
694 for (col_type i = 0; i < nargs(); ++i)
695 if (i % ncols() != col) {
696 tmpcells.push_back(cells_[i]);
697 tmpcellinfo.push_back(cellinfo_[i]);
699 swap(cells_, tmpcells);
700 swap(cellinfo_, tmpcellinfo);
702 colinfo_.erase(colinfo_.begin() + col);
706 void MathGridInset::copyCol(col_type col)
709 for (row_type row = 0; row < nrows(); ++row)
710 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
714 void MathGridInset::swapCol(col_type col)
718 if (col + 1 == ncols())
720 for (row_type row = 0; row < nrows(); ++row)
721 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
725 int MathGridInset::cellXOffset(idx_type idx) const
727 col_type c = col(idx);
728 int x = colinfo_[c].offset_;
729 char align = colinfo_[c].align_;
730 if (align == 'r' || align == 'R')
731 x += colinfo_[c].width_ - cell(idx).width();
732 if (align == 'c' || align == 'C')
733 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
738 int MathGridInset::cellYOffset(idx_type idx) const
740 return rowinfo_[row(idx)].offset_;
744 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
751 pos = cell(idx).x2pos(targetx - cell(idx).xo());
754 if (idx >= ncols() * (nrows() - 1))
757 pos = cell(idx).x2pos(targetx - cell(idx).xo());
763 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
765 // leave matrix if on the left hand edge
769 pos = cell(idx).size();
774 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
776 // leave matrix if on the right hand edge
777 if (col(idx) + 1 == ncols())
785 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
792 idx = (nrows() - 1) * ncols();
795 idx = ((nrows() - 1) / 2) * ncols();
802 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
812 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
814 pos = cell(idx).size();
819 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
826 idx -= idx % ncols();
839 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
841 if (pos < cell(idx).size()) {
842 pos = cell(idx).size();
845 if (col(idx) < ncols() - 1) {
846 idx = idx - idx % ncols() + ncols() - 1;
847 pos = cell(idx).size();
850 if (idx < nargs() - 1) {
852 pos = cell(idx).size();
859 bool MathGridInset::idxDelete(idx_type & idx)
861 // nothing to do if we have just one row
865 // nothing to do if we are in the middle of the last row of the inset
866 if (idx + ncols() > nargs())
869 // try to delete entire sequence of ncols() empty cells if possible
870 for (idx_type i = idx; i < idx + ncols(); ++i)
874 // move cells if necessary
875 for (idx_type i = index(row(idx), 0); i < idx; ++i)
876 std::swap(cell(i), cell(i + ncols()));
883 // undo effect of Ctrl-Tab (i.e. pull next cell)
884 //if (idx + 1 != nargs())
885 // cell(idx).swap(cell(idx + 1));
887 // we handled the event..
892 // reimplement old behaviour when pressing Delete in the last position
894 void MathGridInset::idxGlue(idx_type idx)
896 col_type c = col(idx);
897 if (c + 1 == ncols()) {
898 if (row(idx) + 1 != nrows()) {
899 for (col_type cc = 0; cc < ncols(); ++cc)
900 cell(idx).append(cell(idx + cc + 1));
901 delRow(row(idx) + 1);
904 cell(idx).append(cell(idx + 1));
905 for (col_type cc = c + 2; cc < ncols(); ++cc)
906 cell(idx - c + cc - 1) = cell(idx - c + cc);
907 cell(idx - c + ncols() - 1).clear();
912 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
914 return rowinfo_[row];
918 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
920 return rowinfo_[row];
924 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
926 row_type const ri = row(idx);
927 row_type const r1 = min(row(from), row(to));
928 row_type const r2 = max(row(from), row(to));
929 col_type const ci = col(idx);
930 col_type const c1 = min(col(from), col(to));
931 col_type const c2 = max(col(from), col(to));
932 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
937 void MathGridInset::normalize(NormalStream & os) const
940 for (row_type row = 0; row < nrows(); ++row) {
942 for (col_type col = 0; col < ncols(); ++col)
943 os << "[cell " << cell(index(row, col)) << ']';
950 void MathGridInset::mathmlize(MathMLStream & os) const
952 os << MTag("mtable");
953 for (row_type row = 0; row < nrows(); ++row) {
955 for (col_type col = 0; col < ncols(); ++col)
956 os << cell(index(row, col));
959 os << ETag("mtable");
963 void MathGridInset::write(WriteStream & os) const
965 for (row_type row = 0; row < nrows(); ++row) {
966 os << verboseHLine(rowinfo_[row].lines_);
967 // don't write & and empty cells at end of line
968 col_type lastcol = 0;
969 bool emptyline = true;
970 for (col_type col = 0; col < ncols(); ++col)
971 if (!cell(index(row, col)).empty()) {
975 for (col_type col = 0; col < lastcol; ++col)
976 os << cell(index(row, col)) << eocString(col, lastcol);
977 os << eolString(row, os.fragile());
978 // append newline only if line wasn't completely empty
979 // and this was not the last line in the grid
980 if (!emptyline && row + 1 < nrows())
983 string const s = verboseHLine(rowinfo_[nrows()].lines_);
984 if (!s.empty() && s != " ") {
992 int MathGridInset::colsep() const
998 int MathGridInset::rowsep() const
1004 int MathGridInset::hlinesep() const
1010 int MathGridInset::vlinesep() const
1016 int MathGridInset::border() const
1022 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1024 if (idx + 1 == nargs())
1026 MathArray ar = cell(idx);
1028 cell(idx).erase(pos, cell(idx).size());
1031 cell(idx).insert(0, ar);
1035 dispatch_result MathGridInset::dispatch
1036 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1038 switch (cmd.action) {
1040 case LFUN_MOUSE_RELEASE:
1041 //if (cmd.button() == mouse_button::button3) {
1042 // GridInsetMailer(*this).showDialog();
1043 // return DISPATCHED;
1045 return UNDISPATCHED;
1047 case LFUN_INSET_DIALOG_UPDATE:
1048 GridInsetMailer(*this).updateDialog(cmd.view());
1049 return UNDISPATCHED;
1051 // insert file functions
1052 case LFUN_DELETE_LINE_FORWARD:
1053 //autocorrect_ = false;
1063 if (pos > cell(idx).size())
1064 pos = cell(idx).size();
1065 return DISPATCHED_POP;
1067 case LFUN_CELL_SPLIT:
1068 //recordUndo(bv, Undo::ATOMIC);
1069 splitCell(idx, pos);
1070 return DISPATCHED_POP;
1072 case LFUN_BREAKLINE: {
1073 //recordUndo(bv, Undo::INSERT);
1074 row_type const r = row(idx);
1078 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1079 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1082 splitCell(idx, pos);
1083 std::swap(cell(idx), cell(idx + ncols() - 1));
1086 pos = cell(idx).size();
1088 //mathcursor->normalize();
1089 return DISPATCHED_POP;
1092 case LFUN_TABULAR_FEATURE: {
1093 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1094 istringstream is(STRCONV(cmd.argument));
1097 if (s == "valign-top")
1099 else if (s == "valign-middle")
1101 else if (s == "valign-bottom")
1103 else if (s == "align-left")
1104 halign('l', col(idx));
1105 else if (s == "align-right")
1106 halign('r', col(idx));
1107 else if (s == "align-center")
1108 halign('c', col(idx));
1109 else if (s == "append-row")
1110 for (int i = 0, n = extractInt(is); i < n; ++i)
1112 else if (s == "delete-row")
1113 for (int i = 0, n = extractInt(is); i < n; ++i) {
1118 else if (s == "copy-row")
1119 for (int i = 0, n = extractInt(is); i < n; ++i)
1121 else if (s == "swap-row")
1123 else if (s == "append-column")
1124 for (int i = 0, n = extractInt(is); i < n; ++i) {
1125 row_type r = row(idx);
1126 col_type c = col(idx);
1130 else if (s == "delete-column")
1131 for (int i = 0, n = extractInt(is); i < n; ++i) {
1132 row_type r = row(idx);
1133 col_type c = col(idx);
1139 else if (s == "copy-column")
1141 else if (s == "swap-column")
1144 return UNDISPATCHED;
1145 lyxerr << "returning DISPATCHED_POP" << endl;
1146 return DISPATCHED_POP;
1150 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1151 MathGridInset grid(1, 1);
1152 mathed_parse_normal(grid, cmd.argument);
1153 if (grid.nargs() == 1) {
1154 // single cell/part of cell
1155 cell(idx).insert(pos, grid.cell(0));
1156 pos += grid.cell(0).size();
1159 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1160 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1161 for (row_type r = 0; r < numrows; ++r) {
1162 for (col_type c = 0; c < numcols; ++c) {
1163 idx_type i = index(r + row(idx), c + col(idx));
1164 cell(i).append(grid.cell(grid.index(r, c)));
1166 // append the left over horizontal cells to the last column
1167 idx_type i = index(r + row(idx), ncols() - 1);
1168 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1169 cell(i).append(grid.cell(grid.index(r, c)));
1171 // append the left over vertical cells to the last _cell_
1172 idx_type i = nargs() - 1;
1173 for (row_type r = numrows; r < grid.nrows(); ++r)
1174 for (col_type c = 0; c < grid.ncols(); ++c)
1175 cell(i).append(grid.cell(grid.index(r, c)));
1177 return DISPATCHED_POP;
1181 return MathNestInset::dispatch(cmd, idx, pos);