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"
19 class GridInsetMailer : public MailInset {
21 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
23 virtual string const & name() const
25 static const string theName = "tabular";
29 virtual string const inset2string() const
32 //data << name() << " active_cell " << inset.getActCell() << '\n';
33 data << name() << " active_cell " << 0 << '\n';
40 InsetBase & inset() const { return inset_; }
41 MathGridInset & inset_;
45 void mathed_parse_normal(MathGridInset &, string const & argument);
49 string verboseHLine(int n)
52 for (int i = 0; i < n; ++i)
61 //////////////////////////////////////////////////////////////
64 MathGridInset::CellInfo::CellInfo()
71 //////////////////////////////////////////////////////////////
74 MathGridInset::RowInfo::RowInfo()
80 int MathGridInset::RowInfo::skipPixels() const
82 return crskip_.inBP();
87 //////////////////////////////////////////////////////////////
90 MathGridInset::ColInfo::ColInfo()
91 : align_('c'), leftline_(false), rightline_(false), lines_(0)
95 //////////////////////////////////////////////////////////////
98 MathGridInset::MathGridInset(char v, string const & h)
99 : MathNestInset(guessColumns(h)),
101 colinfo_(guessColumns(h) + 1),
102 cellinfo_(1 * guessColumns(h))
107 //lyxerr << "created grid with " << ncols() << " columns\n";
111 MathGridInset::MathGridInset()
122 MathGridInset::MathGridInset(col_type m, row_type n)
123 : MathNestInset(m * n),
133 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
134 : MathNestInset(m * n),
146 MathGridInset::~MathGridInset()
148 GridInsetMailer mailer(*this);
153 MathInset * MathGridInset::clone() const
155 return new MathGridInset(*this);
159 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
161 return col + ncols() * row;
165 void MathGridInset::setDefaults()
168 lyxerr << "positive number of columns expected\n";
170 // lyxerr << "positive number of rows expected\n";
171 for (col_type col = 0; col < ncols(); ++col) {
172 colinfo_[col].align_ = defaultColAlign(col);
173 colinfo_[col].skip_ = defaultColSpace(col);
178 void MathGridInset::halign(string const & hh)
181 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
186 colinfo_[col].lines_++;
187 } else if (c == 'c' || c == 'l' || c == 'r') {
188 colinfo_[col].align_ = c;
190 colinfo_[col].lines_ = 0;
192 lyxerr << "unknown column separator: '" << c << "'\n";
197 col_type n = hh.size();
200 for (col_type col = 0; col < n; ++col)
201 colinfo_[col].align_ = hh[col];
206 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
209 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
210 if (*it == 'c' || *it == 'l' || *it == 'r')
212 // let's have at least one column, even if we did not recognize its
220 void MathGridInset::halign(char h, col_type col)
222 colinfo_[col].align_ = h;
226 char MathGridInset::halign(col_type col) const
228 return colinfo_[col].align_;
232 string MathGridInset::halign() const
235 for (col_type col = 0; col < ncols(); ++col) {
236 res += string(colinfo_[col].lines_, '|');
237 res += colinfo_[col].align_;
239 return res + string(colinfo_[ncols()].lines_, '|');
243 void MathGridInset::valign(char c)
249 char MathGridInset::valign() const
255 MathGridInset::col_type MathGridInset::ncols() const
257 return colinfo_.size() - 1;
261 MathGridInset::row_type MathGridInset::nrows() const
263 return rowinfo_.size() - 1;
267 MathGridInset::col_type MathGridInset::col(idx_type idx) const
269 return idx % ncols();
273 MathGridInset::row_type MathGridInset::row(idx_type idx) const
275 return idx / ncols();
279 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
281 rowinfo_[row].crskip_ = crskip;
285 LyXLength MathGridInset::vcrskip(row_type row) const
287 return rowinfo_[row].crskip_;
291 void MathGridInset::metrics(MathMetricsInfo & mi) const
293 // let the cells adjust themselves
294 MathNestInset::metrics(mi);
296 // compute absolute sizes of vertical structure
297 for (row_type row = 0; row < nrows(); ++row) {
300 for (col_type col = 0; col < ncols(); ++col) {
301 MathArray const & c = cell(index(row, col));
302 asc = max(asc, c.ascent());
303 desc = max(desc, c.descent());
305 rowinfo_[row].ascent_ = asc;
306 rowinfo_[row].descent_ = desc;
308 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
309 rowinfo_[nrows()].ascent_ = 0;
310 rowinfo_[nrows()].descent_ = 0;
312 // compute vertical offsets
313 rowinfo_[0].offset_ = 0;
314 for (row_type row = 1; row <= nrows(); ++row) {
315 rowinfo_[row].offset_ =
316 rowinfo_[row - 1].offset_ +
317 rowinfo_[row - 1].descent_ +
318 rowinfo_[row - 1].skipPixels() +
320 rowinfo_[row].lines_ * hlinesep() +
321 rowinfo_[row].ascent_;
324 // adjust vertical offset
331 h = rowinfo_[nrows() - 1].offset_;
334 h = rowinfo_[nrows() - 1].offset_ / 2;
336 for (row_type row = 0; row <= nrows(); ++row)
337 rowinfo_[row].offset_ -= h;
340 // compute absolute sizes of horizontal structure
341 for (col_type col = 0; col < ncols(); ++col) {
343 for (row_type row = 0; row < nrows(); ++row)
344 wid = max(wid, cell(index(row, col)).width());
345 colinfo_[col].width_ = wid;
347 colinfo_[ncols()].width_ = 0;
349 // compute horizontal offsets
350 colinfo_[0].offset_ = border();
351 for (col_type col = 1; col <= ncols(); ++col) {
352 colinfo_[col].offset_ =
353 colinfo_[col - 1].offset_ +
354 colinfo_[col - 1].width_ +
355 colinfo_[col - 1].skip_ +
357 colinfo_[col].lines_ * vlinesep();
361 dim_.w = colinfo_[ncols() - 1].offset_
362 + colinfo_[ncols() - 1].width_
363 + vlinesep() * colinfo_[ncols()].lines_
366 dim_.a = - rowinfo_[0].offset_
367 + rowinfo_[0].ascent_
368 + hlinesep() * rowinfo_[0].lines_
371 dim_.d = rowinfo_[nrows() - 1].offset_
372 + rowinfo_[nrows() - 1].descent_
373 + hlinesep() * rowinfo_[nrows()].lines_
378 // Increase ws_[i] for 'R' columns (except the first one)
379 for (int i = 1; i < nc_; ++i)
380 if (align_[i] == 'R')
381 ws_[i] += 10 * df_width;
382 // Increase ws_[i] for 'C' column
383 if (align_[0] == 'C')
384 if (ws_[0] < 7 * workwidth / 8)
385 ws_[0] = 7 * workwidth / 8;
389 for (cxrow = row_.begin(); cxrow; ++cxrow) {
392 for (int i = 0; i < nc_; ++i) {
394 if (cxrow->getTab(i) <= 0) {
395 cxrow->setTab(i, df_width);
403 lf = (ws_[i] - cxrow->getTab(i))/2;
407 lf = ws_[i] - cxrow->getTab(i);
410 if (cxrow == row_.begin())
412 else if (cxrow.is_last())
413 lf = ws_[i] - cxrow->getTab(i);
415 lf = (ws_[i] - cxrow->getTab(i))/2;
418 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
419 cxrow->setTab(i, lf + rg);
420 rg = ws_[i] - ww + colsep();
421 if (cxrow == row_.begin())
422 width += ws_[i] + colsep();
424 cxrow->setBaseline(cxrow->getBaseline() - ascent);
430 void MathGridInset::draw(MathPainterInfo & pi, int x, int y) const
432 for (idx_type idx = 0; idx < nargs(); ++idx)
433 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
435 for (row_type row = 0; row <= nrows(); ++row)
436 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
437 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
438 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
439 pi.pain.line(x + 1, yy, x + width() - 1, yy);
442 for (col_type col = 0; col <= ncols(); ++col)
443 for (int i = 0; i < colinfo_[col].lines_; ++i) {
444 int xx = x + colinfo_[col].offset_
445 - i * vlinesep() - vlinesep()/2 - colsep()/2;
446 pi.pain.line(xx, y - ascent() + 1, xx, y + descent() - 1);
451 void MathGridInset::metricsT(TextMetricsInfo const & mi) const
453 // let the cells adjust themselves
454 //MathNestInset::metrics(mi);
455 for (idx_type i = 0; i < nargs(); ++i)
456 cell(i).metricsT(mi);
458 // compute absolute sizes of vertical structure
459 for (row_type row = 0; row < nrows(); ++row) {
462 for (col_type col = 0; col < ncols(); ++col) {
463 MathArray const & c = cell(index(row, col));
464 asc = max(asc, c.ascent());
465 desc = max(desc, c.descent());
467 rowinfo_[row].ascent_ = asc;
468 rowinfo_[row].descent_ = desc;
470 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
471 rowinfo_[nrows()].ascent_ = 0;
472 rowinfo_[nrows()].descent_ = 0;
474 // compute vertical offsets
475 rowinfo_[0].offset_ = 0;
476 for (row_type row = 1; row <= nrows(); ++row) {
477 rowinfo_[row].offset_ =
478 rowinfo_[row - 1].offset_ +
479 rowinfo_[row - 1].descent_ +
480 //rowinfo_[row - 1].skipPixels() +
482 //rowinfo_[row].lines_ * hlinesep() +
483 rowinfo_[row].ascent_;
486 // adjust vertical offset
493 h = rowinfo_[nrows() - 1].offset_;
496 h = rowinfo_[nrows() - 1].offset_ / 2;
498 for (row_type row = 0; row <= nrows(); ++row)
499 rowinfo_[row].offset_ -= h;
502 // compute absolute sizes of horizontal structure
503 for (col_type col = 0; col < ncols(); ++col) {
505 for (row_type row = 0; row < nrows(); ++row)
506 wid = max(wid, cell(index(row, col)).width());
507 colinfo_[col].width_ = wid;
509 colinfo_[ncols()].width_ = 0;
511 // compute horizontal offsets
512 colinfo_[0].offset_ = border();
513 for (col_type col = 1; col <= ncols(); ++col) {
514 colinfo_[col].offset_ =
515 colinfo_[col - 1].offset_ +
516 colinfo_[col - 1].width_ +
517 colinfo_[col - 1].skip_ +
519 //colinfo_[col].lines_ * vlinesep();
523 dim_.w = colinfo_[ncols() - 1].offset_
524 + colinfo_[ncols() - 1].width_
525 //+ vlinesep() * colinfo_[ncols()].lines_
528 dim_.a = -rowinfo_[0].offset_
529 + rowinfo_[0].ascent_
530 //+ hlinesep() * rowinfo_[0].lines_
533 dim_.d = rowinfo_[nrows() - 1].offset_
534 + rowinfo_[nrows() - 1].descent_
535 //+ hlinesep() * rowinfo_[nrows()].lines_
541 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
543 for (idx_type idx = 0; idx < nargs(); ++idx)
544 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
548 string MathGridInset::eolString(row_type row, bool fragile) const
552 if (!rowinfo_[row].crskip_.zero())
553 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
555 // make sure an upcoming '[' does not break anything
556 if (row + 1 < nrows()) {
557 MathArray const & c = cell(index(row + 1, 0));
558 if (c.size() && c.front()->getChar() == '[')
563 // only add \\ if necessary
564 if (eol.empty() && row + 1 == nrows())
567 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
571 string MathGridInset::eocString(col_type col, col_type lastcol) const
573 if (col + 1 == lastcol)
579 void MathGridInset::addRow(row_type row)
581 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
583 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
585 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
589 void MathGridInset::appendRow()
591 rowinfo_.push_back(RowInfo());
592 //cells_.insert(cells_.end(), ncols(), MathArray());
593 for (col_type col = 0; col < ncols(); ++col) {
594 cells_.push_back(cells_type::value_type());
595 cellinfo_.push_back(CellInfo());
600 void MathGridInset::delRow(row_type row)
605 cells_type::iterator it = cells_.begin() + row * ncols();
606 cells_.erase(it, it + ncols());
608 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
609 cellinfo_.erase(jt, jt + ncols());
611 rowinfo_.erase(rowinfo_.begin() + row);
615 void MathGridInset::copyRow(row_type row)
618 for (col_type col = 0; col < ncols(); ++col)
619 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
623 void MathGridInset::swapRow(row_type row)
627 if (row + 1 == nrows())
629 for (col_type col = 0; col < ncols(); ++col)
630 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
634 void MathGridInset::addCol(col_type newcol)
636 const col_type nc = ncols();
637 const row_type nr = nrows();
638 cells_type new_cells((nc + 1) * nr);
639 vector<CellInfo> new_cellinfo((nc + 1) * nr);
641 for (row_type row = 0; row < nr; ++row)
642 for (col_type col = 0; col < nc; ++col) {
643 new_cells[row * (nc + 1) + col + (col > newcol)]
644 = cells_[row * nc + col];
645 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
646 = cellinfo_[row * nc + col];
648 swap(cells_, new_cells);
649 swap(cellinfo_, new_cellinfo);
652 inf.skip_ = defaultColSpace(newcol);
653 inf.align_ = defaultColAlign(newcol);
654 colinfo_.insert(colinfo_.begin() + newcol, inf);
658 void MathGridInset::delCol(col_type col)
664 vector<CellInfo> tmpcellinfo;
665 for (col_type i = 0; i < nargs(); ++i)
666 if (i % ncols() != col) {
667 tmpcells.push_back(cells_[i]);
668 tmpcellinfo.push_back(cellinfo_[i]);
670 swap(cells_, tmpcells);
671 swap(cellinfo_, tmpcellinfo);
673 colinfo_.erase(colinfo_.begin() + col);
677 void MathGridInset::copyCol(col_type col)
680 for (row_type row = 0; row < nrows(); ++row)
681 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
685 void MathGridInset::swapCol(col_type col)
689 if (col + 1 == ncols())
691 for (row_type row = 0; row < nrows(); ++row)
692 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
696 int MathGridInset::cellXOffset(idx_type idx) const
698 col_type c = col(idx);
699 int x = colinfo_[c].offset_;
700 char align = colinfo_[c].align_;
701 if (align == 'r' || align == 'R')
702 x += colinfo_[c].width_ - cell(idx).width();
703 if (align == 'c' || align == 'C')
704 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
709 int MathGridInset::cellYOffset(idx_type idx) const
711 return rowinfo_[row(idx)].offset_;
715 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
722 pos = cell(idx).x2pos(targetx - cell(idx).xo());
725 if (idx >= ncols() * (nrows() - 1))
728 pos = cell(idx).x2pos(targetx - cell(idx).xo());
734 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
736 // leave matrix if on the left hand edge
740 pos = cell(idx).size();
745 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
747 // leave matrix if on the right hand edge
748 if (col(idx) + 1 == ncols())
756 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
763 idx = (nrows() - 1) * ncols();
766 idx = ((nrows() - 1) / 2) * ncols();
773 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
783 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
785 pos = cell(idx).size();
790 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
797 idx -= idx % ncols();
810 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
812 if (pos < cell(idx).size()) {
813 pos = cell(idx).size();
816 if (col(idx) < ncols() - 1) {
817 idx = idx - idx % ncols() + ncols() - 1;
818 pos = cell(idx).size();
821 if (idx < nargs() - 1) {
823 pos = cell(idx).size();
830 bool MathGridInset::idxDelete(idx_type & idx)
832 // nothing to do if we have just one row
836 // nothing to do if we are in the middle of the last row of the inset
837 if (idx + ncols() > nargs())
840 // try to delete entire sequence of ncols() empty cells if possible
841 for (idx_type i = idx; i < idx + ncols(); ++i)
845 // move cells if necessary
846 for (idx_type i = index(row(idx), 0); i < idx; ++i)
847 std::swap(cell(i), cell(i + ncols()));
854 // undo effect of Ctrl-Tab (i.e. pull next cell)
855 //if (idx + 1 != nargs())
856 // cell(idx).swap(cell(idx + 1));
858 // we handled the event..
863 // reimplement old behaviour when pressing Delete in the last position
865 void MathGridInset::idxGlue(idx_type idx)
867 col_type c = col(idx);
868 if (c + 1 == ncols()) {
869 if (row(idx) + 1 != nrows()) {
870 for (col_type cc = 0; cc < ncols(); ++cc)
871 cell(idx).append(cell(idx + cc + 1));
872 delRow(row(idx) + 1);
875 cell(idx).append(cell(idx + 1));
876 for (col_type cc = c + 2; cc < ncols(); ++cc)
877 cell(idx - c + cc - 1) = cell(idx - c + cc);
878 cell(idx - c + ncols() - 1).clear();
883 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
885 return rowinfo_[row];
889 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
891 return rowinfo_[row];
895 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
897 row_type const ri = row(idx);
898 row_type const r1 = min(row(from), row(to));
899 row_type const r2 = max(row(from), row(to));
900 col_type const ci = col(idx);
901 col_type const c1 = min(col(from), col(to));
902 col_type const c2 = max(col(from), col(to));
903 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
908 void MathGridInset::normalize(NormalStream & os) const
911 for (row_type row = 0; row < nrows(); ++row) {
913 for (col_type col = 0; col < ncols(); ++col)
914 os << "[cell " << cell(index(row, col)) << ']';
921 void MathGridInset::mathmlize(MathMLStream & os) const
923 os << MTag("mtable");
924 for (row_type row = 0; row < nrows(); ++row) {
926 for (col_type col = 0; col < ncols(); ++col)
927 os << cell(index(row, col));
930 os << ETag("mtable");
934 void MathGridInset::write(WriteStream & os) const
936 for (row_type row = 0; row < nrows(); ++row) {
937 os << verboseHLine(rowinfo_[row].lines_);
938 // don't write & and empty cells at end of line
939 col_type lastcol = 0;
940 bool emptyline = true;
941 for (col_type col = 0; col < ncols(); ++col)
942 if (!cell(index(row, col)).empty()) {
946 for (col_type col = 0; col < lastcol; ++col)
947 os << cell(index(row, col)) << eocString(col, lastcol);
948 os << eolString(row, os.fragile());
949 // append newline only if line wasn't completely empty
950 // and this was not the last line in the grid
951 if (!emptyline && row + 1 < nrows())
954 string const s = verboseHLine(rowinfo_[nrows()].lines_);
955 if (!s.empty() && s != " ") {
963 int MathGridInset::colsep() const
969 int MathGridInset::rowsep() const
975 int MathGridInset::hlinesep() const
981 int MathGridInset::vlinesep() const
987 int MathGridInset::border() const
993 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
995 if (idx + 1 == nargs())
997 MathArray ar = cell(idx);
999 cell(idx).erase(pos, cell(idx).size());
1002 cell(idx).insert(0, ar);
1006 dispatch_result MathGridInset::dispatch
1007 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1009 switch (cmd.action) {
1011 case LFUN_MOUSE_RELEASE:
1012 //if (cmd.button() == mouse_button::button3) {
1013 // GridInsetMailer mailer(*this);
1014 // mailer.showDialog();
1015 // return DISPATCHED;
1019 case LFUN_INSET_DIALOG_UPDATE: {
1020 GridInsetMailer mailer(*this);
1021 mailer.updateDialog(cmd.view());
1025 // insert file functions
1026 case LFUN_DELETE_LINE_FORWARD:
1027 //autocorrect_ = false;
1037 if (pos > cell(idx).size())
1038 pos = cell(idx).size();
1039 return DISPATCHED_POP;
1041 case LFUN_TABINSERT:
1042 //bv->lockedInsetStoreUndo(Undo::EDIT);
1043 splitCell(idx, pos);
1044 //updateLocal(bv, true);
1045 return DISPATCHED_POP;
1047 case LFUN_BREAKLINE: {
1048 //bv->lockedInsetStoreUndo(Undo::INSERT);
1049 row_type const r = row(idx);
1053 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1054 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1057 splitCell(idx, pos);
1058 std::swap(cell(idx), cell(idx + ncols() - 1));
1061 pos = cell(idx).size();
1063 //mathcursor->normalize();
1064 //updateLocal(bv, true);
1065 return DISPATCHED_POP;
1068 case LFUN_TABULAR_FEATURE:
1069 //lyxerr << "handling tabular-feature " << cmd.argument << "\n";
1070 if (cmd.argument == "valign-top")
1072 else if (cmd.argument == "valign-center")
1074 else if (cmd.argument == "valign-bottom")
1076 else if (cmd.argument == "align-left")
1077 halign('l', col(idx));
1078 else if (cmd.argument == "align-right")
1079 halign('r', col(idx));
1080 else if (cmd.argument == "align-center")
1081 halign('c', col(idx));
1082 else if (cmd.argument == "append-row")
1084 else if (cmd.argument == "delete-row") {
1088 } else if (cmd.argument == "copy-row")
1090 else if (cmd.argument == "swap-row")
1092 else if (cmd.argument == "append-column") {
1093 row_type r = row(idx);
1094 col_type c = col(idx);
1097 } else if (cmd.argument == "delete-column") {
1098 row_type r = row(idx);
1099 col_type c = col(idx);
1104 } else if (cmd.argument == "copy-column")
1106 else if (cmd.argument == "swap-column")
1109 return UNDISPATCHED;
1110 return DISPATCHED_POP;
1113 //lyxerr << "pasting '" << cmd.argument << "'\n";
1114 MathGridInset grid(1, 1);
1115 mathed_parse_normal(grid, cmd.argument);
1116 if (grid.nargs() == 1) {
1117 // single cell/part of cell
1118 cell(idx).insert(pos, grid.cell(0));
1119 pos += grid.cell(0).size();
1122 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1123 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1124 for (row_type r = 0; r < numrows; ++r) {
1125 for (col_type c = 0; c < numcols; ++c) {
1126 idx_type i = index(r + row(idx), c + col(idx));
1127 cell(i).append(grid.cell(grid.index(r, c)));
1129 // append the left over horizontal cells to the last column
1130 idx_type i = index(r + row(idx), ncols() - 1);
1131 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1132 cell(i).append(grid.cell(grid.index(r, c)));
1134 // append the left over vertical cells to the last _cell_
1135 idx_type i = nargs() - 1;
1136 for (row_type r = numrows; r < grid.nrows(); ++r)
1137 for (col_type c = 0; c < grid.ncols(); ++c)
1138 cell(i).append(grid.cell(grid.index(r, c)));
1140 return DISPATCHED_POP;
1144 return MathNestInset::dispatch(cmd, idx, pos);
1146 return UNDISPATCHED;