1 #include "math_gridinset.h"
2 #include "math_mathmlstream.h"
3 #include "math_streamstr.h"
5 #include "funcrequest.h"
6 #include "frontends/Painter.h"
10 #include "insets/mailinset.h"
18 class GridInsetMailer : public MailInset {
20 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
22 virtual string const & name() const
24 static const string theName = "tabular";
28 virtual string const inset2string() const
30 lyxerr << "inset2string called" << std::endl;
31 return "whatever"; //(inset_);
35 InsetBase & inset() const { return inset_; }
36 MathGridInset & inset_;
40 void mathed_parse_normal(MathGridInset &, string const & argument);
44 string verboseHLine(int n)
47 for (int i = 0; i < n; ++i)
56 //////////////////////////////////////////////////////////////
59 MathGridInset::CellInfo::CellInfo()
66 //////////////////////////////////////////////////////////////
69 MathGridInset::RowInfo::RowInfo()
75 int MathGridInset::RowInfo::skipPixels() const
77 return crskip_.inBP();
82 //////////////////////////////////////////////////////////////
85 MathGridInset::ColInfo::ColInfo()
86 : align_('c'), leftline_(false), rightline_(false), lines_(0)
90 //////////////////////////////////////////////////////////////
93 MathGridInset::MathGridInset(char v, string const & h)
94 : MathNestInset(guessColumns(h)),
96 colinfo_(guessColumns(h) + 1),
97 cellinfo_(1 * guessColumns(h))
102 //lyxerr << "created grid with " << ncols() << " columns\n";
106 MathGridInset::MathGridInset()
117 MathGridInset::MathGridInset(col_type m, row_type n)
118 : MathNestInset(m * n),
128 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
129 : MathNestInset(m * n),
141 MathGridInset::~MathGridInset()
143 GridInsetMailer mailer(*this);
148 MathInset * MathGridInset::clone() const
150 return new MathGridInset(*this);
154 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
156 return col + ncols() * row;
160 void MathGridInset::setDefaults()
163 lyxerr << "positive number of columns expected\n";
165 // lyxerr << "positive number of rows expected\n";
166 for (col_type col = 0; col < ncols(); ++col) {
167 colinfo_[col].align_ = defaultColAlign(col);
168 colinfo_[col].skip_ = defaultColSpace(col);
173 void MathGridInset::halign(string const & hh)
176 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
181 colinfo_[col].lines_++;
182 } else if (c == 'c' || c == 'l' || c == 'r') {
183 colinfo_[col].align_ = c;
185 colinfo_[col].lines_ = 0;
187 lyxerr << "unknown column separator: '" << c << "'\n";
192 col_type n = hh.size();
195 for (col_type col = 0; col < n; ++col)
196 colinfo_[col].align_ = hh[col];
201 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
204 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
205 if (*it == 'c' || *it == 'l' || *it == 'r')
207 // let's have at least one column, even if we did not recognize its
215 void MathGridInset::halign(char h, col_type col)
217 colinfo_[col].align_ = h;
221 char MathGridInset::halign(col_type col) const
223 return colinfo_[col].align_;
227 string MathGridInset::halign() const
230 for (col_type col = 0; col < ncols(); ++col) {
231 res += string(colinfo_[col].lines_, '|');
232 res += colinfo_[col].align_;
234 return res + string(colinfo_[ncols()].lines_, '|');
238 void MathGridInset::valign(char c)
244 char MathGridInset::valign() const
250 MathGridInset::col_type MathGridInset::ncols() const
252 return colinfo_.size() - 1;
256 MathGridInset::row_type MathGridInset::nrows() const
258 return rowinfo_.size() - 1;
262 MathGridInset::col_type MathGridInset::col(idx_type idx) const
264 return idx % ncols();
268 MathGridInset::row_type MathGridInset::row(idx_type idx) const
270 return idx / ncols();
274 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
276 rowinfo_[row].crskip_ = crskip;
280 LyXLength MathGridInset::vcrskip(row_type row) const
282 return rowinfo_[row].crskip_;
286 void MathGridInset::metrics(MathMetricsInfo & mi) const
288 // let the cells adjust themselves
289 MathNestInset::metrics(mi);
291 // compute absolute sizes of vertical structure
292 for (row_type row = 0; row < nrows(); ++row) {
295 for (col_type col = 0; col < ncols(); ++col) {
296 MathArray const & c = cell(index(row, col));
297 asc = max(asc, c.ascent());
298 desc = max(desc, c.descent());
300 rowinfo_[row].ascent_ = asc;
301 rowinfo_[row].descent_ = desc;
303 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
304 rowinfo_[nrows()].ascent_ = 0;
305 rowinfo_[nrows()].descent_ = 0;
307 // compute vertical offsets
308 rowinfo_[0].offset_ = 0;
309 for (row_type row = 1; row <= nrows(); ++row) {
310 rowinfo_[row].offset_ =
311 rowinfo_[row - 1].offset_ +
312 rowinfo_[row - 1].descent_ +
313 rowinfo_[row - 1].skipPixels() +
315 rowinfo_[row].lines_ * hlinesep() +
316 rowinfo_[row].ascent_;
319 // adjust vertical offset
326 h = rowinfo_[nrows() - 1].offset_;
329 h = rowinfo_[nrows() - 1].offset_ / 2;
331 for (row_type row = 0; row <= nrows(); ++row)
332 rowinfo_[row].offset_ -= h;
335 // compute absolute sizes of horizontal structure
336 for (col_type col = 0; col < ncols(); ++col) {
338 for (row_type row = 0; row < nrows(); ++row)
339 wid = max(wid, cell(index(row, col)).width());
340 colinfo_[col].width_ = wid;
342 colinfo_[ncols()].width_ = 0;
344 // compute horizontal offsets
345 colinfo_[0].offset_ = border();
346 for (col_type col = 1; col <= ncols(); ++col) {
347 colinfo_[col].offset_ =
348 colinfo_[col - 1].offset_ +
349 colinfo_[col - 1].width_ +
350 colinfo_[col - 1].skip_ +
352 colinfo_[col].lines_ * vlinesep();
356 dim_.w = colinfo_[ncols() - 1].offset_
357 + colinfo_[ncols() - 1].width_
358 + vlinesep() * colinfo_[ncols()].lines_
361 dim_.a = - rowinfo_[0].offset_
362 + rowinfo_[0].ascent_
363 + hlinesep() * rowinfo_[0].lines_
366 dim_.d = rowinfo_[nrows() - 1].offset_
367 + rowinfo_[nrows() - 1].descent_
368 + hlinesep() * rowinfo_[nrows()].lines_
373 // Increase ws_[i] for 'R' columns (except the first one)
374 for (int i = 1; i < nc_; ++i)
375 if (align_[i] == 'R')
376 ws_[i] += 10 * df_width;
377 // Increase ws_[i] for 'C' column
378 if (align_[0] == 'C')
379 if (ws_[0] < 7 * workwidth / 8)
380 ws_[0] = 7 * workwidth / 8;
384 for (cxrow = row_.begin(); cxrow; ++cxrow) {
387 for (int i = 0; i < nc_; ++i) {
389 if (cxrow->getTab(i) <= 0) {
390 cxrow->setTab(i, df_width);
398 lf = (ws_[i] - cxrow->getTab(i))/2;
402 lf = ws_[i] - cxrow->getTab(i);
405 if (cxrow == row_.begin())
407 else if (cxrow.is_last())
408 lf = ws_[i] - cxrow->getTab(i);
410 lf = (ws_[i] - cxrow->getTab(i))/2;
413 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
414 cxrow->setTab(i, lf + rg);
415 rg = ws_[i] - ww + colsep();
416 if (cxrow == row_.begin())
417 width += ws_[i] + colsep();
419 cxrow->setBaseline(cxrow->getBaseline() - ascent);
425 void MathGridInset::draw(MathPainterInfo & pi, int x, int y) const
427 for (idx_type idx = 0; idx < nargs(); ++idx)
428 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
430 for (row_type row = 0; row <= nrows(); ++row)
431 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
432 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
433 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
434 pi.pain.line(x + 1, yy, x + width() - 1, yy);
437 for (col_type col = 0; col <= ncols(); ++col)
438 for (int i = 0; i < colinfo_[col].lines_; ++i) {
439 int xx = x + colinfo_[col].offset_
440 - i * vlinesep() - vlinesep()/2 - colsep()/2;
441 pi.pain.line(xx, y - ascent() + 1, xx, y + descent() - 1);
446 void MathGridInset::metricsT(TextMetricsInfo const & mi) const
448 // let the cells adjust themselves
449 //MathNestInset::metrics(mi);
450 for (idx_type i = 0; i < nargs(); ++i)
451 cell(i).metricsT(mi);
453 // compute absolute sizes of vertical structure
454 for (row_type row = 0; row < nrows(); ++row) {
457 for (col_type col = 0; col < ncols(); ++col) {
458 MathArray const & c = cell(index(row, col));
459 asc = max(asc, c.ascent());
460 desc = max(desc, c.descent());
462 rowinfo_[row].ascent_ = asc;
463 rowinfo_[row].descent_ = desc;
465 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
466 rowinfo_[nrows()].ascent_ = 0;
467 rowinfo_[nrows()].descent_ = 0;
469 // compute vertical offsets
470 rowinfo_[0].offset_ = 0;
471 for (row_type row = 1; row <= nrows(); ++row) {
472 rowinfo_[row].offset_ =
473 rowinfo_[row - 1].offset_ +
474 rowinfo_[row - 1].descent_ +
475 //rowinfo_[row - 1].skipPixels() +
477 //rowinfo_[row].lines_ * hlinesep() +
478 rowinfo_[row].ascent_;
481 // adjust vertical offset
488 h = rowinfo_[nrows() - 1].offset_;
491 h = rowinfo_[nrows() - 1].offset_ / 2;
493 for (row_type row = 0; row <= nrows(); ++row)
494 rowinfo_[row].offset_ -= h;
497 // compute absolute sizes of horizontal structure
498 for (col_type col = 0; col < ncols(); ++col) {
500 for (row_type row = 0; row < nrows(); ++row)
501 wid = max(wid, cell(index(row, col)).width());
502 colinfo_[col].width_ = wid;
504 colinfo_[ncols()].width_ = 0;
506 // compute horizontal offsets
507 colinfo_[0].offset_ = border();
508 for (col_type col = 1; col <= ncols(); ++col) {
509 colinfo_[col].offset_ =
510 colinfo_[col - 1].offset_ +
511 colinfo_[col - 1].width_ +
512 colinfo_[col - 1].skip_ +
514 //colinfo_[col].lines_ * vlinesep();
518 dim_.w = colinfo_[ncols() - 1].offset_
519 + colinfo_[ncols() - 1].width_
520 //+ vlinesep() * colinfo_[ncols()].lines_
523 dim_.a = -rowinfo_[0].offset_
524 + rowinfo_[0].ascent_
525 //+ hlinesep() * rowinfo_[0].lines_
528 dim_.d = rowinfo_[nrows() - 1].offset_
529 + rowinfo_[nrows() - 1].descent_
530 //+ hlinesep() * rowinfo_[nrows()].lines_
536 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
538 for (idx_type idx = 0; idx < nargs(); ++idx)
539 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
543 string MathGridInset::eolString(row_type row, bool fragile) const
547 if (!rowinfo_[row].crskip_.zero())
548 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
550 // make sure an upcoming '[' does not break anything
551 if (row + 1 < nrows()) {
552 MathArray const & c = cell(index(row + 1, 0));
553 if (c.size() && c.front()->getChar() == '[')
558 // only add \\ if necessary
559 if (eol.empty() && row + 1 == nrows())
562 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
566 string MathGridInset::eocString(col_type col, col_type lastcol) const
568 if (col + 1 == lastcol)
574 void MathGridInset::addRow(row_type row)
576 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
578 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
580 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
584 void MathGridInset::appendRow()
586 rowinfo_.push_back(RowInfo());
587 //cells_.insert(cells_.end(), ncols(), MathArray());
588 for (col_type col = 0; col < ncols(); ++col) {
589 cells_.push_back(cells_type::value_type());
590 cellinfo_.push_back(CellInfo());
595 void MathGridInset::delRow(row_type row)
600 cells_type::iterator it = cells_.begin() + row * ncols();
601 cells_.erase(it, it + ncols());
603 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
604 cellinfo_.erase(jt, jt + ncols());
606 rowinfo_.erase(rowinfo_.begin() + row);
610 void MathGridInset::copyRow(row_type row)
613 for (col_type col = 0; col < ncols(); ++col)
614 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
618 void MathGridInset::swapRow(row_type row)
622 if (row + 1 == nrows())
624 for (col_type col = 0; col < ncols(); ++col)
625 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
629 void MathGridInset::addCol(col_type newcol)
631 const col_type nc = ncols();
632 const row_type nr = nrows();
633 cells_type new_cells((nc + 1) * nr);
634 vector<CellInfo> new_cellinfo((nc + 1) * nr);
636 for (row_type row = 0; row < nr; ++row)
637 for (col_type col = 0; col < nc; ++col) {
638 new_cells[row * (nc + 1) + col + (col > newcol)]
639 = cells_[row * nc + col];
640 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
641 = cellinfo_[row * nc + col];
643 swap(cells_, new_cells);
644 swap(cellinfo_, new_cellinfo);
647 inf.skip_ = defaultColSpace(newcol);
648 inf.align_ = defaultColAlign(newcol);
649 colinfo_.insert(colinfo_.begin() + newcol, inf);
653 void MathGridInset::delCol(col_type col)
659 vector<CellInfo> tmpcellinfo;
660 for (col_type i = 0; i < nargs(); ++i)
661 if (i % ncols() != col) {
662 tmpcells.push_back(cells_[i]);
663 tmpcellinfo.push_back(cellinfo_[i]);
665 swap(cells_, tmpcells);
666 swap(cellinfo_, tmpcellinfo);
668 colinfo_.erase(colinfo_.begin() + col);
672 void MathGridInset::copyCol(col_type col)
675 for (row_type row = 0; row < nrows(); ++row)
676 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
680 void MathGridInset::swapCol(col_type col)
684 if (col + 1 == ncols())
686 for (row_type row = 0; row < nrows(); ++row)
687 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
691 int MathGridInset::cellXOffset(idx_type idx) const
693 col_type c = col(idx);
694 int x = colinfo_[c].offset_;
695 char align = colinfo_[c].align_;
696 if (align == 'r' || align == 'R')
697 x += colinfo_[c].width_ - cell(idx).width();
698 if (align == 'c' || align == 'C')
699 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
704 int MathGridInset::cellYOffset(idx_type idx) const
706 return rowinfo_[row(idx)].offset_;
710 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
717 pos = cell(idx).x2pos(targetx - cell(idx).xo());
720 if (idx >= ncols() * (nrows() - 1))
723 pos = cell(idx).x2pos(targetx - cell(idx).xo());
729 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
731 // leave matrix if on the left hand edge
735 pos = cell(idx).size();
740 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
742 // leave matrix if on the right hand edge
743 if (col(idx) + 1 == ncols())
751 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
758 idx = (nrows() - 1) * ncols();
761 idx = ((nrows() - 1) / 2) * ncols();
768 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
778 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
780 pos = cell(idx).size();
785 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
792 idx -= idx % ncols();
805 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
807 if (pos < cell(idx).size()) {
808 pos = cell(idx).size();
811 if (col(idx) < ncols() - 1) {
812 idx = idx - idx % ncols() + ncols() - 1;
813 pos = cell(idx).size();
816 if (idx < nargs() - 1) {
818 pos = cell(idx).size();
825 bool MathGridInset::idxDelete(idx_type & idx)
827 // nothing to do if we have just one row
831 // nothing to do if we are in the middle of the last row of the inset
832 if (idx + ncols() > nargs())
835 // try to delete entire sequence of ncols() empty cells if possible
836 for (idx_type i = idx; i < idx + ncols(); ++i)
840 // move cells if necessary
841 for (idx_type i = index(row(idx), 0); i < idx; ++i)
842 std::swap(cell(i), cell(i + ncols()));
849 // undo effect of Ctrl-Tab (i.e. pull next cell)
850 //if (idx + 1 != nargs())
851 // cell(idx).swap(cell(idx + 1));
853 // we handled the event..
858 // reimplement old behaviour when pressing Delete in the last position
860 void MathGridInset::idxGlue(idx_type idx)
862 col_type c = col(idx);
863 if (c + 1 == ncols()) {
864 if (row(idx) + 1 != nrows()) {
865 for (col_type cc = 0; cc < ncols(); ++cc)
866 cell(idx).append(cell(idx + cc + 1));
867 delRow(row(idx) + 1);
870 cell(idx).append(cell(idx + 1));
871 for (col_type cc = c + 2; cc < ncols(); ++cc)
872 cell(idx - c + cc - 1) = cell(idx - c + cc);
873 cell(idx - c + ncols() - 1).clear();
878 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
880 return rowinfo_[row];
884 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
886 return rowinfo_[row];
890 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
892 row_type const ri = row(idx);
893 row_type const r1 = min(row(from), row(to));
894 row_type const r2 = max(row(from), row(to));
895 col_type const ci = col(idx);
896 col_type const c1 = min(col(from), col(to));
897 col_type const c2 = max(col(from), col(to));
898 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
903 void MathGridInset::normalize(NormalStream & os) const
906 for (row_type row = 0; row < nrows(); ++row) {
908 for (col_type col = 0; col < ncols(); ++col)
909 os << "[cell " << cell(index(row, col)) << ']';
916 void MathGridInset::mathmlize(MathMLStream & os) const
918 os << MTag("mtable");
919 for (row_type row = 0; row < nrows(); ++row) {
921 for (col_type col = 0; col < ncols(); ++col)
922 os << cell(index(row, col));
925 os << ETag("mtable");
929 void MathGridInset::write(WriteStream & os) const
931 for (row_type row = 0; row < nrows(); ++row) {
932 os << verboseHLine(rowinfo_[row].lines_);
933 // don't write & and empty cells at end of line
934 col_type lastcol = 0;
935 bool emptyline = true;
936 for (col_type col = 0; col < ncols(); ++col)
937 if (!cell(index(row, col)).empty()) {
941 for (col_type col = 0; col < lastcol; ++col)
942 os << cell(index(row, col)) << eocString(col, lastcol);
943 os << eolString(row, os.fragile());
944 // append newline only if line wasn't completely empty
945 // and this was not the last line in the grid
946 if (!emptyline && row + 1 < nrows())
949 string const s = verboseHLine(rowinfo_[nrows()].lines_);
950 if (!s.empty() && s != " ") {
958 int MathGridInset::colsep() const
964 int MathGridInset::rowsep() const
970 int MathGridInset::hlinesep() const
976 int MathGridInset::vlinesep() const
982 int MathGridInset::border() const
988 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
990 if (idx + 1 == nargs())
992 MathArray ar = cell(idx);
994 cell(idx).erase(pos, cell(idx).size());
997 cell(idx).insert(0, ar);
1001 dispatch_result MathGridInset::dispatch
1002 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1004 switch (cmd.action) {
1006 case LFUN_MOUSE_RELEASE: {
1007 if (cmd.button() == mouse_button::button3) {
1008 WriteStream ws(lyxerr);
1010 GridInsetMailer mailer(*this);
1011 lyxerr << "mailer " << mailer.name() << " active\n";
1012 mailer.showDialog(cmd.view());
1018 case LFUN_INSET_DIALOG_UPDATE: {
1019 GridInsetMailer mailer(*this);
1020 mailer.updateDialog(cmd.view());
1024 // insert file functions
1025 case LFUN_DELETE_LINE_FORWARD:
1026 //autocorrect_ = false;
1036 if (pos > cell(idx).size())
1037 pos = cell(idx).size();
1038 return DISPATCHED_POP;
1040 case LFUN_TABINSERT:
1041 //bv->lockedInsetStoreUndo(Undo::EDIT);
1042 splitCell(idx, pos);
1043 //updateLocal(bv, true);
1044 return DISPATCHED_POP;
1046 case LFUN_BREAKLINE: {
1047 //bv->lockedInsetStoreUndo(Undo::INSERT);
1048 row_type const r = row(idx);
1052 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1053 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1056 splitCell(idx, pos);
1057 std::swap(cell(idx), cell(idx + ncols() - 1));
1060 pos = cell(idx).size();
1062 //mathcursor->normalize();
1063 //updateLocal(bv, true);
1064 return DISPATCHED_POP;
1067 case LFUN_TABULAR_FEATURE:
1068 //lyxerr << "handling tabular-feature " << cmd.argument << "\n";
1069 if (cmd.argument == "valign-top")
1071 else if (cmd.argument == "valign-center")
1073 else if (cmd.argument == "valign-bottom")
1075 else if (cmd.argument == "align-left")
1076 halign('l', col(idx));
1077 else if (cmd.argument == "align-right")
1078 halign('r', col(idx));
1079 else if (cmd.argument == "align-center")
1080 halign('c', col(idx));
1081 else if (cmd.argument == "append-row")
1083 else if (cmd.argument == "delete-row") {
1087 } else if (cmd.argument == "copy-row")
1089 else if (cmd.argument == "swap-row")
1091 else if (cmd.argument == "append-column") {
1092 row_type r = row(idx);
1093 col_type c = col(idx);
1096 } else if (cmd.argument == "delete-column") {
1097 row_type r = row(idx);
1098 col_type c = col(idx);
1103 } else if (cmd.argument == "copy-column")
1105 else if (cmd.argument == "swap-column")
1108 return UNDISPATCHED;
1109 return DISPATCHED_POP;
1112 //lyxerr << "pasting '" << cmd.argument << "'\n";
1113 MathGridInset grid(1, 1);
1114 mathed_parse_normal(grid, cmd.argument);
1115 if (grid.nargs() == 1) {
1116 // single cell/part of cell
1117 cell(idx).insert(pos, grid.cell(0));
1118 pos += grid.cell(0).size();
1121 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1122 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1123 for (row_type r = 0; r < numrows; ++r) {
1124 for (col_type c = 0; c < numcols; ++c) {
1125 idx_type i = index(r + row(idx), c + col(idx));
1126 cell(i).append(grid.cell(grid.index(r, c)));
1128 // append the left over horizontal cells to the last column
1129 idx_type i = index(r + row(idx), ncols() - 1);
1130 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1131 cell(i).append(grid.cell(grid.index(r, c)));
1133 // append the left over vertical cells to the last _cell_
1134 idx_type i = nargs() - 1;
1135 for (row_type r = numrows; r < grid.nrows(); ++r)
1136 for (col_type c = 0; c < grid.ncols(); ++c)
1137 cell(i).append(grid.cell(grid.index(r, c)));
1139 return DISPATCHED_POP;
1143 return MathNestInset::dispatch(cmd, idx, pos);
1145 return UNDISPATCHED;