1 #include "math_gridinset.h"
2 #include "math_mathmlstream.h"
3 #include "math_streamstr.h"
5 #include "funcrequest.h"
6 #include "frontends/Painter.h"
11 #include "insets/mailinset.h"
21 class GridInsetMailer : public MailInset {
23 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
25 virtual string const & name() const
27 static string const theName = "tabular";
31 virtual string const inset2string(Buffer const &) const
34 //data << name() << " active_cell " << inset.getActCell() << '\n';
35 data << name() << " active_cell " << 0 << '\n';
38 return STRCONV(data.str());
42 InsetBase & inset() const { return inset_; }
43 MathGridInset & inset_;
47 void mathed_parse_normal(MathGridInset &, string const & argument);
51 string verboseHLine(int n)
54 for (int i = 0; i < n; ++i)
62 int extractInt(istream & is)
66 return (num == 0) ? 1 : num;
72 //////////////////////////////////////////////////////////////
75 MathGridInset::CellInfo::CellInfo()
82 //////////////////////////////////////////////////////////////
85 MathGridInset::RowInfo::RowInfo()
91 int MathGridInset::RowInfo::skipPixels() const
93 return crskip_.inBP();
98 //////////////////////////////////////////////////////////////
101 MathGridInset::ColInfo::ColInfo()
102 : align_('c'), leftline_(false), rightline_(false), lines_(0)
106 //////////////////////////////////////////////////////////////
109 MathGridInset::MathGridInset(char v, string const & h)
110 : MathNestInset(guessColumns(h)),
112 colinfo_(guessColumns(h) + 1),
113 cellinfo_(1 * guessColumns(h))
118 //lyxerr << "created grid with " << ncols() << " columns\n";
122 MathGridInset::MathGridInset()
133 MathGridInset::MathGridInset(col_type m, row_type n)
134 : MathNestInset(m * n),
144 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
145 : MathNestInset(m * n),
157 MathGridInset::~MathGridInset()
159 GridInsetMailer mailer(*this);
164 auto_ptr<InsetBase> MathGridInset::clone() const
166 return auto_ptr<InsetBase>(new MathGridInset(*this));
170 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
172 return col + ncols() * row;
176 void MathGridInset::setDefaults()
179 lyxerr << "positive number of columns expected\n";
181 // lyxerr << "positive number of rows expected\n";
182 for (col_type col = 0; col < ncols(); ++col) {
183 colinfo_[col].align_ = defaultColAlign(col);
184 colinfo_[col].skip_ = defaultColSpace(col);
189 void MathGridInset::halign(string const & hh)
192 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
197 colinfo_[col].lines_++;
198 } else if (c == 'c' || c == 'l' || c == 'r') {
199 colinfo_[col].align_ = c;
201 colinfo_[col].lines_ = 0;
203 lyxerr << "unknown column separator: '" << c << "'\n";
208 col_type n = hh.size();
211 for (col_type col = 0; col < n; ++col)
212 colinfo_[col].align_ = hh[col];
217 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
220 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
221 if (*it == 'c' || *it == 'l' || *it == 'r')
223 // let's have at least one column, even if we did not recognize its
231 void MathGridInset::halign(char h, col_type col)
233 colinfo_[col].align_ = h;
237 char MathGridInset::halign(col_type col) const
239 return colinfo_[col].align_;
243 string MathGridInset::halign() const
246 for (col_type col = 0; col < ncols(); ++col) {
247 res += string(colinfo_[col].lines_, '|');
248 res += colinfo_[col].align_;
250 return res + string(colinfo_[ncols()].lines_, '|');
254 void MathGridInset::valign(char c)
260 char MathGridInset::valign() const
266 MathGridInset::col_type MathGridInset::ncols() const
268 return colinfo_.size() - 1;
272 MathGridInset::row_type MathGridInset::nrows() const
274 return rowinfo_.size() - 1;
278 MathGridInset::col_type MathGridInset::col(idx_type idx) const
280 return idx % ncols();
284 MathGridInset::row_type MathGridInset::row(idx_type idx) const
286 return idx / ncols();
290 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
292 rowinfo_[row].crskip_ = crskip;
296 LyXLength MathGridInset::vcrskip(row_type row) const
298 return rowinfo_[row].crskip_;
302 void MathGridInset::metrics(MetricsInfo & mi) const
304 // let the cells adjust themselves
305 MathNestInset::metrics(mi);
307 // compute absolute sizes of vertical structure
308 for (row_type row = 0; row < nrows(); ++row) {
311 for (col_type col = 0; col < ncols(); ++col) {
312 MathArray const & c = cell(index(row, col));
313 asc = max(asc, c.ascent());
314 desc = max(desc, c.descent());
316 rowinfo_[row].ascent_ = asc;
317 rowinfo_[row].descent_ = desc;
319 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
320 rowinfo_[nrows()].ascent_ = 0;
321 rowinfo_[nrows()].descent_ = 0;
323 // compute vertical offsets
324 rowinfo_[0].offset_ = 0;
325 for (row_type row = 1; row <= nrows(); ++row) {
326 rowinfo_[row].offset_ =
327 rowinfo_[row - 1].offset_ +
328 rowinfo_[row - 1].descent_ +
329 rowinfo_[row - 1].skipPixels() +
331 rowinfo_[row].lines_ * hlinesep() +
332 rowinfo_[row].ascent_;
335 // adjust vertical offset
342 h = rowinfo_[nrows() - 1].offset_;
345 h = rowinfo_[nrows() - 1].offset_ / 2;
347 for (row_type row = 0; row <= nrows(); ++row)
348 rowinfo_[row].offset_ -= h;
351 // compute absolute sizes of horizontal structure
352 for (col_type col = 0; col < ncols(); ++col) {
354 for (row_type row = 0; row < nrows(); ++row)
355 wid = max(wid, cell(index(row, col)).width());
356 colinfo_[col].width_ = wid;
358 colinfo_[ncols()].width_ = 0;
360 // compute horizontal offsets
361 colinfo_[0].offset_ = border();
362 for (col_type col = 1; col <= ncols(); ++col) {
363 colinfo_[col].offset_ =
364 colinfo_[col - 1].offset_ +
365 colinfo_[col - 1].width_ +
366 colinfo_[col - 1].skip_ +
368 colinfo_[col].lines_ * vlinesep();
372 dim_.wid = colinfo_[ncols() - 1].offset_
373 + colinfo_[ncols() - 1].width_
374 + vlinesep() * colinfo_[ncols()].lines_
377 dim_.asc = - rowinfo_[0].offset_
378 + rowinfo_[0].ascent_
379 + hlinesep() * rowinfo_[0].lines_
382 dim_.des = rowinfo_[nrows() - 1].offset_
383 + rowinfo_[nrows() - 1].descent_
384 + hlinesep() * rowinfo_[nrows()].lines_
389 // Increase ws_[i] for 'R' columns (except the first one)
390 for (int i = 1; i < nc_; ++i)
391 if (align_[i] == 'R')
392 ws_[i] += 10 * df_width;
393 // Increase ws_[i] for 'C' column
394 if (align_[0] == 'C')
395 if (ws_[0] < 7 * workwidth / 8)
396 ws_[0] = 7 * workwidth / 8;
400 for (cxrow = row_.begin(); cxrow; ++cxrow) {
403 for (int i = 0; i < nc_; ++i) {
405 if (cxrow->getTab(i) <= 0) {
406 cxrow->setTab(i, df_width);
414 lf = (ws_[i] - cxrow->getTab(i))/2;
418 lf = ws_[i] - cxrow->getTab(i);
421 if (cxrow == row_.begin())
423 else if (cxrow.is_last())
424 lf = ws_[i] - cxrow->getTab(i);
426 lf = (ws_[i] - cxrow->getTab(i))/2;
429 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
430 cxrow->setTab(i, lf + rg);
431 rg = ws_[i] - ww + colsep();
432 if (cxrow == row_.begin())
433 width += ws_[i] + colsep();
435 cxrow->setBaseline(cxrow->getBaseline() - ascent);
441 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
448 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
450 for (idx_type idx = 0; idx < nargs(); ++idx)
451 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
453 for (row_type row = 0; row <= nrows(); ++row)
454 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
455 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
456 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
457 pi.pain.line(x + 1, yy, x + dim_.width() - 1, yy);
460 for (col_type col = 0; col <= ncols(); ++col)
461 for (int i = 0; i < colinfo_[col].lines_; ++i) {
462 int xx = x + colinfo_[col].offset_
463 - i * vlinesep() - vlinesep()/2 - colsep()/2;
464 pi.pain.line(xx, y - dim_.ascent() + 1, xx, y + dim_.descent() - 1);
469 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
471 // let the cells adjust themselves
472 //MathNestInset::metrics(mi);
473 for (idx_type i = 0; i < nargs(); ++i)
474 cell(i).metricsT(mi, dim);
476 // compute absolute sizes of vertical structure
477 for (row_type row = 0; row < nrows(); ++row) {
480 for (col_type col = 0; col < ncols(); ++col) {
481 MathArray const & c = cell(index(row, col));
482 asc = max(asc, c.ascent());
483 desc = max(desc, c.descent());
485 rowinfo_[row].ascent_ = asc;
486 rowinfo_[row].descent_ = desc;
488 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
489 rowinfo_[nrows()].ascent_ = 0;
490 rowinfo_[nrows()].descent_ = 0;
492 // compute vertical offsets
493 rowinfo_[0].offset_ = 0;
494 for (row_type row = 1; row <= nrows(); ++row) {
495 rowinfo_[row].offset_ =
496 rowinfo_[row - 1].offset_ +
497 rowinfo_[row - 1].descent_ +
498 //rowinfo_[row - 1].skipPixels() +
500 //rowinfo_[row].lines_ * hlinesep() +
501 rowinfo_[row].ascent_;
504 // adjust vertical offset
511 h = rowinfo_[nrows() - 1].offset_;
514 h = rowinfo_[nrows() - 1].offset_ / 2;
516 for (row_type row = 0; row <= nrows(); ++row)
517 rowinfo_[row].offset_ -= h;
520 // compute absolute sizes of horizontal structure
521 for (col_type col = 0; col < ncols(); ++col) {
523 for (row_type row = 0; row < nrows(); ++row)
524 wid = max(wid, cell(index(row, col)).width());
525 colinfo_[col].width_ = wid;
527 colinfo_[ncols()].width_ = 0;
529 // compute horizontal offsets
530 colinfo_[0].offset_ = border();
531 for (col_type col = 1; col <= ncols(); ++col) {
532 colinfo_[col].offset_ =
533 colinfo_[col - 1].offset_ +
534 colinfo_[col - 1].width_ +
535 colinfo_[col - 1].skip_ +
537 //colinfo_[col].lines_ * vlinesep();
541 dim.wid = colinfo_[ncols() - 1].offset_
542 + colinfo_[ncols() - 1].width_
543 //+ vlinesep() * colinfo_[ncols()].lines_
546 dim.asc = -rowinfo_[0].offset_
547 + rowinfo_[0].ascent_
548 //+ hlinesep() * rowinfo_[0].lines_
551 dim.des = rowinfo_[nrows() - 1].offset_
552 + rowinfo_[nrows() - 1].descent_
553 //+ hlinesep() * rowinfo_[nrows()].lines_
558 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
560 for (idx_type idx = 0; idx < nargs(); ++idx)
561 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
565 string MathGridInset::eolString(row_type row, bool fragile) const
569 if (!rowinfo_[row].crskip_.zero())
570 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
572 // make sure an upcoming '[' does not break anything
573 if (row + 1 < nrows()) {
574 MathArray const & c = cell(index(row + 1, 0));
575 if (c.size() && c.front()->getChar() == '[')
580 // only add \\ if necessary
581 if (eol.empty() && row + 1 == nrows())
584 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
588 string MathGridInset::eocString(col_type col, col_type lastcol) const
590 if (col + 1 == lastcol)
596 void MathGridInset::addRow(row_type row)
598 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
600 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
602 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
606 void MathGridInset::appendRow()
608 rowinfo_.push_back(RowInfo());
609 //cells_.insert(cells_.end(), ncols(), MathArray());
610 for (col_type col = 0; col < ncols(); ++col) {
611 cells_.push_back(cells_type::value_type());
612 cellinfo_.push_back(CellInfo());
617 void MathGridInset::delRow(row_type row)
622 cells_type::iterator it = cells_.begin() + row * ncols();
623 cells_.erase(it, it + ncols());
625 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
626 cellinfo_.erase(jt, jt + ncols());
628 rowinfo_.erase(rowinfo_.begin() + row);
632 void MathGridInset::copyRow(row_type row)
635 for (col_type col = 0; col < ncols(); ++col)
636 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
640 void MathGridInset::swapRow(row_type row)
644 if (row + 1 == nrows())
646 for (col_type col = 0; col < ncols(); ++col)
647 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
651 void MathGridInset::addCol(col_type newcol)
653 const col_type nc = ncols();
654 const row_type nr = nrows();
655 cells_type new_cells((nc + 1) * nr);
656 vector<CellInfo> new_cellinfo((nc + 1) * nr);
658 for (row_type row = 0; row < nr; ++row)
659 for (col_type col = 0; col < nc; ++col) {
660 new_cells[row * (nc + 1) + col + (col > newcol)]
661 = cells_[row * nc + col];
662 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
663 = cellinfo_[row * nc + col];
665 swap(cells_, new_cells);
666 swap(cellinfo_, new_cellinfo);
669 inf.skip_ = defaultColSpace(newcol);
670 inf.align_ = defaultColAlign(newcol);
671 colinfo_.insert(colinfo_.begin() + newcol, inf);
675 void MathGridInset::delCol(col_type col)
681 vector<CellInfo> tmpcellinfo;
682 for (col_type i = 0; i < nargs(); ++i)
683 if (i % ncols() != col) {
684 tmpcells.push_back(cells_[i]);
685 tmpcellinfo.push_back(cellinfo_[i]);
687 swap(cells_, tmpcells);
688 swap(cellinfo_, tmpcellinfo);
690 colinfo_.erase(colinfo_.begin() + col);
694 void MathGridInset::copyCol(col_type col)
697 for (row_type row = 0; row < nrows(); ++row)
698 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
702 void MathGridInset::swapCol(col_type col)
706 if (col + 1 == ncols())
708 for (row_type row = 0; row < nrows(); ++row)
709 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
713 int MathGridInset::cellXOffset(idx_type idx) const
715 col_type c = col(idx);
716 int x = colinfo_[c].offset_;
717 char align = colinfo_[c].align_;
718 if (align == 'r' || align == 'R')
719 x += colinfo_[c].width_ - cell(idx).width();
720 if (align == 'c' || align == 'C')
721 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
726 int MathGridInset::cellYOffset(idx_type idx) const
728 return rowinfo_[row(idx)].offset_;
732 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
739 pos = cell(idx).x2pos(targetx - cell(idx).xo());
742 if (idx >= ncols() * (nrows() - 1))
745 pos = cell(idx).x2pos(targetx - cell(idx).xo());
751 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
753 // leave matrix if on the left hand edge
757 pos = cell(idx).size();
762 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
764 // leave matrix if on the right hand edge
765 if (col(idx) + 1 == ncols())
773 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
780 idx = (nrows() - 1) * ncols();
783 idx = ((nrows() - 1) / 2) * ncols();
790 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
800 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
802 pos = cell(idx).size();
807 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
814 idx -= idx % ncols();
827 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
829 if (pos < cell(idx).size()) {
830 pos = cell(idx).size();
833 if (col(idx) < ncols() - 1) {
834 idx = idx - idx % ncols() + ncols() - 1;
835 pos = cell(idx).size();
838 if (idx < nargs() - 1) {
840 pos = cell(idx).size();
847 bool MathGridInset::idxDelete(idx_type & idx)
849 // nothing to do if we have just one row
853 // nothing to do if we are in the middle of the last row of the inset
854 if (idx + ncols() > nargs())
857 // try to delete entire sequence of ncols() empty cells if possible
858 for (idx_type i = idx; i < idx + ncols(); ++i)
862 // move cells if necessary
863 for (idx_type i = index(row(idx), 0); i < idx; ++i)
864 std::swap(cell(i), cell(i + ncols()));
871 // undo effect of Ctrl-Tab (i.e. pull next cell)
872 //if (idx + 1 != nargs())
873 // cell(idx).swap(cell(idx + 1));
875 // we handled the event..
880 // reimplement old behaviour when pressing Delete in the last position
882 void MathGridInset::idxGlue(idx_type idx)
884 col_type c = col(idx);
885 if (c + 1 == ncols()) {
886 if (row(idx) + 1 != nrows()) {
887 for (col_type cc = 0; cc < ncols(); ++cc)
888 cell(idx).append(cell(idx + cc + 1));
889 delRow(row(idx) + 1);
892 cell(idx).append(cell(idx + 1));
893 for (col_type cc = c + 2; cc < ncols(); ++cc)
894 cell(idx - c + cc - 1) = cell(idx - c + cc);
895 cell(idx - c + ncols() - 1).clear();
900 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
902 return rowinfo_[row];
906 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
908 return rowinfo_[row];
912 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
914 row_type const ri = row(idx);
915 row_type const r1 = min(row(from), row(to));
916 row_type const r2 = max(row(from), row(to));
917 col_type const ci = col(idx);
918 col_type const c1 = min(col(from), col(to));
919 col_type const c2 = max(col(from), col(to));
920 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
925 void MathGridInset::normalize(NormalStream & os) const
928 for (row_type row = 0; row < nrows(); ++row) {
930 for (col_type col = 0; col < ncols(); ++col)
931 os << "[cell " << cell(index(row, col)) << ']';
938 void MathGridInset::mathmlize(MathMLStream & os) const
940 os << MTag("mtable");
941 for (row_type row = 0; row < nrows(); ++row) {
943 for (col_type col = 0; col < ncols(); ++col)
944 os << cell(index(row, col));
947 os << ETag("mtable");
951 void MathGridInset::write(WriteStream & os) const
953 for (row_type row = 0; row < nrows(); ++row) {
954 os << verboseHLine(rowinfo_[row].lines_);
955 // don't write & and empty cells at end of line
956 col_type lastcol = 0;
957 bool emptyline = true;
958 for (col_type col = 0; col < ncols(); ++col)
959 if (!cell(index(row, col)).empty()) {
963 for (col_type col = 0; col < lastcol; ++col)
964 os << cell(index(row, col)) << eocString(col, lastcol);
965 os << eolString(row, os.fragile());
966 // append newline only if line wasn't completely empty
967 // and this was not the last line in the grid
968 if (!emptyline && row + 1 < nrows())
971 string const s = verboseHLine(rowinfo_[nrows()].lines_);
972 if (!s.empty() && s != " ") {
980 int MathGridInset::colsep() const
986 int MathGridInset::rowsep() const
992 int MathGridInset::hlinesep() const
998 int MathGridInset::vlinesep() const
1004 int MathGridInset::border() const
1010 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1012 if (idx + 1 == nargs())
1014 MathArray ar = cell(idx);
1016 cell(idx).erase(pos, cell(idx).size());
1019 cell(idx).insert(0, ar);
1023 dispatch_result MathGridInset::dispatch
1024 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1026 switch (cmd.action) {
1028 case LFUN_MOUSE_RELEASE:
1029 //if (cmd.button() == mouse_button::button3) {
1030 // GridInsetMailer(*this).showDialog();
1031 // return DISPATCHED;
1033 return UNDISPATCHED;
1035 case LFUN_INSET_DIALOG_UPDATE:
1036 GridInsetMailer(*this).updateDialog(cmd.view());
1037 return UNDISPATCHED;
1039 // insert file functions
1040 case LFUN_DELETE_LINE_FORWARD:
1041 //autocorrect_ = false;
1051 if (pos > cell(idx).size())
1052 pos = cell(idx).size();
1053 return DISPATCHED_POP;
1055 case LFUN_CELL_SPLIT:
1056 //recordUndo(bv, Undo::ATOMIC);
1057 splitCell(idx, pos);
1058 return DISPATCHED_POP;
1060 case LFUN_BREAKLINE: {
1061 //recordUndo(bv, Undo::INSERT);
1062 row_type const r = row(idx);
1066 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1067 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1070 splitCell(idx, pos);
1071 std::swap(cell(idx), cell(idx + ncols() - 1));
1074 pos = cell(idx).size();
1076 //mathcursor->normalize();
1077 return DISPATCHED_POP;
1080 case LFUN_TABULAR_FEATURE: {
1081 //lyxerr << "handling tabular-feature " << cmd.argument << "\n";
1082 istringstream is(STRCONV(cmd.argument));
1085 if (s == "valign-top")
1087 else if (s == "valign-center")
1089 else if (s == "valign-bottom")
1091 else if (s == "align-left")
1092 halign('l', col(idx));
1093 else if (s == "align-right")
1094 halign('r', col(idx));
1095 else if (s == "align-center")
1096 halign('c', col(idx));
1097 else if (s == "append-row")
1098 for (int i = 0, n = extractInt(is); i < n; ++i)
1100 else if (s == "delete-row")
1101 for (int i = 0, n = extractInt(is); i < n; ++i) {
1106 else if (s == "copy-row")
1107 for (int i = 0, n = extractInt(is); i < n; ++i)
1109 else if (s == "swap-row")
1111 else if (s == "append-column")
1112 for (int i = 0, n = extractInt(is); i < n; ++i) {
1113 row_type r = row(idx);
1114 col_type c = col(idx);
1118 else if (s == "delete-column")
1119 for (int i = 0, n = extractInt(is); i < n; ++i) {
1120 row_type r = row(idx);
1121 col_type c = col(idx);
1127 else if (s == "copy-column")
1129 else if (s == "swap-column")
1132 return UNDISPATCHED;
1133 lyxerr << "returning DISPATCHED_POP\n";
1134 return DISPATCHED_POP;
1138 //lyxerr << "pasting '" << cmd.argument << "'\n";
1139 MathGridInset grid(1, 1);
1140 mathed_parse_normal(grid, cmd.argument);
1141 if (grid.nargs() == 1) {
1142 // single cell/part of cell
1143 cell(idx).insert(pos, grid.cell(0));
1144 pos += grid.cell(0).size();
1147 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1148 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1149 for (row_type r = 0; r < numrows; ++r) {
1150 for (col_type c = 0; c < numcols; ++c) {
1151 idx_type i = index(r + row(idx), c + col(idx));
1152 cell(i).append(grid.cell(grid.index(r, c)));
1154 // append the left over horizontal cells to the last column
1155 idx_type i = index(r + row(idx), ncols() - 1);
1156 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1157 cell(i).append(grid.cell(grid.index(r, c)));
1159 // append the left over vertical cells to the last _cell_
1160 idx_type i = nargs() - 1;
1161 for (row_type r = numrows; r < grid.nrows(); ++r)
1162 for (col_type c = 0; c < grid.ncols(); ++c)
1163 cell(i).append(grid.cell(grid.index(r, c)));
1165 return DISPATCHED_POP;
1169 return MathNestInset::dispatch(cmd, idx, pos);