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" << 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 MathInset * MathGridInset::clone() const
143 return new MathGridInset(*this);
147 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
149 return col + ncols() * row;
153 void MathGridInset::setDefaults()
156 lyxerr << "positive number of columns expected\n";
158 // lyxerr << "positive number of rows expected\n";
159 for (col_type col = 0; col < ncols(); ++col) {
160 colinfo_[col].align_ = defaultColAlign(col);
161 colinfo_[col].skip_ = defaultColSpace(col);
166 void MathGridInset::halign(string const & hh)
169 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
174 colinfo_[col].lines_++;
175 } else if (c == 'c' || c == 'l' || c == 'r') {
176 colinfo_[col].align_ = c;
178 colinfo_[col].lines_ = 0;
180 lyxerr << "unknown column separator: '" << c << "'\n";
185 col_type n = hh.size();
188 for (col_type col = 0; col < n; ++col)
189 colinfo_[col].align_ = hh[col];
194 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
197 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
198 if (*it == 'c' || *it == 'l' || *it == 'r')
200 // let's have at least one column, even if we did not recognize its
208 void MathGridInset::halign(char h, col_type col)
210 colinfo_[col].align_ = h;
214 char MathGridInset::halign(col_type col) const
216 return colinfo_[col].align_;
220 string MathGridInset::halign() const
223 for (col_type col = 0; col < ncols(); ++col) {
224 res += string(colinfo_[col].lines_, '|');
225 res += colinfo_[col].align_;
227 return res + string(colinfo_[ncols()].lines_, '|');
231 void MathGridInset::valign(char c)
237 char MathGridInset::valign() const
243 MathGridInset::col_type MathGridInset::ncols() const
245 return colinfo_.size() - 1;
249 MathGridInset::row_type MathGridInset::nrows() const
251 return rowinfo_.size() - 1;
255 MathGridInset::col_type MathGridInset::col(idx_type idx) const
257 return idx % ncols();
261 MathGridInset::row_type MathGridInset::row(idx_type idx) const
263 return idx / ncols();
267 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
269 rowinfo_[row].crskip_ = crskip;
273 LyXLength MathGridInset::vcrskip(row_type row) const
275 return rowinfo_[row].crskip_;
279 void MathGridInset::metrics(MathMetricsInfo & mi) const
281 // let the cells adjust themselves
282 MathNestInset::metrics(mi);
284 // compute absolute sizes of vertical structure
285 for (row_type row = 0; row < nrows(); ++row) {
288 for (col_type col = 0; col < ncols(); ++col) {
289 MathArray const & c = cell(index(row, col));
290 asc = max(asc, c.ascent());
291 desc = max(desc, c.descent());
293 rowinfo_[row].ascent_ = asc;
294 rowinfo_[row].descent_ = desc;
296 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
297 rowinfo_[nrows()].ascent_ = 0;
298 rowinfo_[nrows()].descent_ = 0;
300 // compute vertical offsets
301 rowinfo_[0].offset_ = 0;
302 for (row_type row = 1; row <= nrows(); ++row) {
303 rowinfo_[row].offset_ =
304 rowinfo_[row - 1].offset_ +
305 rowinfo_[row - 1].descent_ +
306 rowinfo_[row - 1].skipPixels() +
308 rowinfo_[row].lines_ * hlinesep() +
309 rowinfo_[row].ascent_;
312 // adjust vertical offset
319 h = rowinfo_[nrows() - 1].offset_;
322 h = rowinfo_[nrows() - 1].offset_ / 2;
324 for (row_type row = 0; row <= nrows(); ++row)
325 rowinfo_[row].offset_ -= h;
328 // compute absolute sizes of horizontal structure
329 for (col_type col = 0; col < ncols(); ++col) {
331 for (row_type row = 0; row < nrows(); ++row)
332 wid = max(wid, cell(index(row, col)).width());
333 colinfo_[col].width_ = wid;
335 colinfo_[ncols()].width_ = 0;
337 // compute horizontal offsets
338 colinfo_[0].offset_ = border();
339 for (col_type col = 1; col <= ncols(); ++col) {
340 colinfo_[col].offset_ =
341 colinfo_[col - 1].offset_ +
342 colinfo_[col - 1].width_ +
343 colinfo_[col - 1].skip_ +
345 colinfo_[col].lines_ * vlinesep();
349 dim_.w = colinfo_[ncols() - 1].offset_
350 + colinfo_[ncols() - 1].width_
351 + vlinesep() * colinfo_[ncols()].lines_
354 dim_.a = - rowinfo_[0].offset_
355 + rowinfo_[0].ascent_
356 + hlinesep() * rowinfo_[0].lines_
359 dim_.d = rowinfo_[nrows() - 1].offset_
360 + rowinfo_[nrows() - 1].descent_
361 + hlinesep() * rowinfo_[nrows()].lines_
366 // Increase ws_[i] for 'R' columns (except the first one)
367 for (int i = 1; i < nc_; ++i)
368 if (align_[i] == 'R')
369 ws_[i] += 10 * df_width;
370 // Increase ws_[i] for 'C' column
371 if (align_[0] == 'C')
372 if (ws_[0] < 7 * workwidth / 8)
373 ws_[0] = 7 * workwidth / 8;
377 for (cxrow = row_.begin(); cxrow; ++cxrow) {
380 for (int i = 0; i < nc_; ++i) {
382 if (cxrow->getTab(i) <= 0) {
383 cxrow->setTab(i, df_width);
391 lf = (ws_[i] - cxrow->getTab(i))/2;
395 lf = ws_[i] - cxrow->getTab(i);
398 if (cxrow == row_.begin())
400 else if (cxrow.is_last())
401 lf = ws_[i] - cxrow->getTab(i);
403 lf = (ws_[i] - cxrow->getTab(i))/2;
406 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
407 cxrow->setTab(i, lf + rg);
408 rg = ws_[i] - ww + colsep();
409 if (cxrow == row_.begin())
410 width += ws_[i] + colsep();
412 cxrow->setBaseline(cxrow->getBaseline() - ascent);
418 void MathGridInset::draw(MathPainterInfo & pi, int x, int y) const
420 for (idx_type idx = 0; idx < nargs(); ++idx)
421 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
423 for (row_type row = 0; row <= nrows(); ++row)
424 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
425 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
426 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
427 pi.pain.line(x + 1, yy, x + width() - 1, yy);
430 for (col_type col = 0; col <= ncols(); ++col)
431 for (int i = 0; i < colinfo_[col].lines_; ++i) {
432 int xx = x + colinfo_[col].offset_
433 - i * vlinesep() - vlinesep()/2 - colsep()/2;
434 pi.pain.line(xx, y - ascent() + 1, xx, y + descent() - 1);
439 void MathGridInset::metricsT(TextMetricsInfo const & mi) const
441 // let the cells adjust themselves
442 //MathNestInset::metrics(mi);
443 for (idx_type i = 0; i < nargs(); ++i)
444 cell(i).metricsT(mi);
446 // compute absolute sizes of vertical structure
447 for (row_type row = 0; row < nrows(); ++row) {
450 for (col_type col = 0; col < ncols(); ++col) {
451 MathArray const & c = cell(index(row, col));
452 asc = max(asc, c.ascent());
453 desc = max(desc, c.descent());
455 rowinfo_[row].ascent_ = asc;
456 rowinfo_[row].descent_ = desc;
458 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
459 rowinfo_[nrows()].ascent_ = 0;
460 rowinfo_[nrows()].descent_ = 0;
462 // compute vertical offsets
463 rowinfo_[0].offset_ = 0;
464 for (row_type row = 1; row <= nrows(); ++row) {
465 rowinfo_[row].offset_ =
466 rowinfo_[row - 1].offset_ +
467 rowinfo_[row - 1].descent_ +
468 //rowinfo_[row - 1].skipPixels() +
470 //rowinfo_[row].lines_ * hlinesep() +
471 rowinfo_[row].ascent_;
474 // adjust vertical offset
481 h = rowinfo_[nrows() - 1].offset_;
484 h = rowinfo_[nrows() - 1].offset_ / 2;
486 for (row_type row = 0; row <= nrows(); ++row)
487 rowinfo_[row].offset_ -= h;
490 // compute absolute sizes of horizontal structure
491 for (col_type col = 0; col < ncols(); ++col) {
493 for (row_type row = 0; row < nrows(); ++row)
494 wid = max(wid, cell(index(row, col)).width());
495 colinfo_[col].width_ = wid;
497 colinfo_[ncols()].width_ = 0;
499 // compute horizontal offsets
500 colinfo_[0].offset_ = border();
501 for (col_type col = 1; col <= ncols(); ++col) {
502 colinfo_[col].offset_ =
503 colinfo_[col - 1].offset_ +
504 colinfo_[col - 1].width_ +
505 colinfo_[col - 1].skip_ +
507 //colinfo_[col].lines_ * vlinesep();
511 dim_.w = colinfo_[ncols() - 1].offset_
512 + colinfo_[ncols() - 1].width_
513 //+ vlinesep() * colinfo_[ncols()].lines_
516 dim_.a = -rowinfo_[0].offset_
517 + rowinfo_[0].ascent_
518 //+ hlinesep() * rowinfo_[0].lines_
521 dim_.d = rowinfo_[nrows() - 1].offset_
522 + rowinfo_[nrows() - 1].descent_
523 //+ hlinesep() * rowinfo_[nrows()].lines_
529 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
531 for (idx_type idx = 0; idx < nargs(); ++idx)
532 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
536 string MathGridInset::eolString(row_type row, bool fragile) const
540 if (!rowinfo_[row].crskip_.zero())
541 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
543 // make sure an upcoming '[' does not break anything
544 if (row + 1 < nrows()) {
545 MathArray const & c = cell(index(row + 1, 0));
546 if (c.size() && c.front()->getChar() == '[')
551 // only add \\ if necessary
552 if (eol.empty() && row + 1 == nrows())
555 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
559 string MathGridInset::eocString(col_type col, col_type lastcol) const
561 if (col + 1 == lastcol)
567 void MathGridInset::addRow(row_type row)
569 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
571 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
573 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
577 void MathGridInset::appendRow()
579 rowinfo_.push_back(RowInfo());
580 //cells_.insert(cells_.end(), ncols(), MathArray());
581 for (col_type col = 0; col < ncols(); ++col) {
582 cells_.push_back(cells_type::value_type());
583 cellinfo_.push_back(CellInfo());
588 void MathGridInset::delRow(row_type row)
593 cells_type::iterator it = cells_.begin() + row * ncols();
594 cells_.erase(it, it + ncols());
596 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
597 cellinfo_.erase(jt, jt + ncols());
599 rowinfo_.erase(rowinfo_.begin() + row);
603 void MathGridInset::copyRow(row_type row)
606 for (col_type col = 0; col < ncols(); ++col)
607 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
611 void MathGridInset::swapRow(row_type row)
615 if (row + 1 == nrows())
617 for (col_type col = 0; col < ncols(); ++col)
618 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
622 void MathGridInset::addCol(col_type newcol)
624 const col_type nc = ncols();
625 const row_type nr = nrows();
626 cells_type new_cells((nc + 1) * nr);
627 vector<CellInfo> new_cellinfo((nc + 1) * nr);
629 for (row_type row = 0; row < nr; ++row)
630 for (col_type col = 0; col < nc; ++col) {
631 new_cells[row * (nc + 1) + col + (col > newcol)]
632 = cells_[row * nc + col];
633 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
634 = cellinfo_[row * nc + col];
636 swap(cells_, new_cells);
637 swap(cellinfo_, new_cellinfo);
640 inf.skip_ = defaultColSpace(newcol);
641 inf.align_ = defaultColAlign(newcol);
642 colinfo_.insert(colinfo_.begin() + newcol, inf);
646 void MathGridInset::delCol(col_type col)
652 vector<CellInfo> tmpcellinfo;
653 for (col_type i = 0; i < nargs(); ++i)
654 if (i % ncols() != col) {
655 tmpcells.push_back(cells_[i]);
656 tmpcellinfo.push_back(cellinfo_[i]);
658 swap(cells_, tmpcells);
659 swap(cellinfo_, tmpcellinfo);
661 colinfo_.erase(colinfo_.begin() + col);
665 void MathGridInset::copyCol(col_type col)
668 for (row_type row = 0; row < nrows(); ++row)
669 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
673 void MathGridInset::swapCol(col_type col)
677 if (col + 1 == ncols())
679 for (row_type row = 0; row < nrows(); ++row)
680 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
684 int MathGridInset::cellXOffset(idx_type idx) const
686 col_type c = col(idx);
687 int x = colinfo_[c].offset_;
688 char align = colinfo_[c].align_;
689 if (align == 'r' || align == 'R')
690 x += colinfo_[c].width_ - cell(idx).width();
691 if (align == 'c' || align == 'C')
692 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
697 int MathGridInset::cellYOffset(idx_type idx) const
699 return rowinfo_[row(idx)].offset_;
703 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
710 pos = cell(idx).x2pos(targetx - cell(idx).xo());
713 if (idx >= ncols() * (nrows() - 1))
716 pos = cell(idx).x2pos(targetx - cell(idx).xo());
722 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
724 // leave matrix if on the left hand edge
728 pos = cell(idx).size();
733 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
735 // leave matrix if on the right hand edge
736 if (col(idx) + 1 == ncols())
744 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
751 idx = (nrows() - 1) * ncols();
754 idx = ((nrows() - 1) / 2) * ncols();
761 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
771 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
773 pos = cell(idx).size();
778 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
785 idx -= idx % ncols();
798 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
800 if (pos < cell(idx).size()) {
801 pos = cell(idx).size();
804 if (col(idx) < ncols() - 1) {
805 idx = idx - idx % ncols() + ncols() - 1;
806 pos = cell(idx).size();
809 if (idx < nargs() - 1) {
811 pos = cell(idx).size();
818 bool MathGridInset::idxDelete(idx_type & idx)
820 // nothing to do if we have just one row
824 // nothing to do if we are in the middle of the last row of the inset
825 if (idx + ncols() > nargs())
828 // try to delete entire sequence of ncols() empty cells if possible
829 for (idx_type i = idx; i < idx + ncols(); ++i)
833 // move cells if necessary
834 for (idx_type i = index(row(idx), 0); i < idx; ++i)
835 std::swap(cell(i), cell(i + ncols()));
842 // undo effect of Ctrl-Tab (i.e. pull next cell)
843 //if (idx + 1 != nargs())
844 // cell(idx).swap(cell(idx + 1));
846 // we handled the event..
851 // reimplement old behaviour when pressing Delete in the last position
853 void MathGridInset::idxGlue(idx_type idx)
855 col_type c = col(idx);
856 if (c + 1 == ncols()) {
857 if (row(idx) + 1 != nrows()) {
858 for (col_type cc = 0; cc < ncols(); ++cc)
859 cell(idx).append(cell(idx + cc + 1));
860 delRow(row(idx) + 1);
863 cell(idx).append(cell(idx + 1));
864 for (col_type cc = c + 2; cc < ncols(); ++cc)
865 cell(idx - c + cc - 1) = cell(idx - c + cc);
866 cell(idx - c + ncols() - 1).clear();
871 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
873 return rowinfo_[row];
877 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
879 return rowinfo_[row];
883 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
885 row_type const ri = row(idx);
886 row_type const r1 = min(row(from), row(to));
887 row_type const r2 = max(row(from), row(to));
888 col_type const ci = col(idx);
889 col_type const c1 = min(col(from), col(to));
890 col_type const c2 = max(col(from), col(to));
891 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
896 void MathGridInset::normalize(NormalStream & os) const
899 for (row_type row = 0; row < nrows(); ++row) {
901 for (col_type col = 0; col < ncols(); ++col)
902 os << "[cell " << cell(index(row, col)) << ']';
909 void MathGridInset::mathmlize(MathMLStream & os) const
911 os << MTag("mtable");
912 for (row_type row = 0; row < nrows(); ++row) {
914 for (col_type col = 0; col < ncols(); ++col)
915 os << cell(index(row, col));
918 os << ETag("mtable");
922 void MathGridInset::write(WriteStream & os) const
924 for (row_type row = 0; row < nrows(); ++row) {
925 os << verboseHLine(rowinfo_[row].lines_);
926 // don't write & and empty cells at end of line
927 col_type lastcol = 0;
928 bool emptyline = true;
929 for (col_type col = 0; col < ncols(); ++col)
930 if (!cell(index(row, col)).empty()) {
934 for (col_type col = 0; col < lastcol; ++col)
935 os << cell(index(row, col)) << eocString(col, lastcol);
936 os << eolString(row, os.fragile());
937 // append newline only if line wasn't completely empty
938 // and this was not the last line in the grid
939 if (!emptyline && row + 1 < nrows())
942 string const s = verboseHLine(rowinfo_[nrows()].lines_);
943 if (!s.empty() && s != " ") {
951 int MathGridInset::colsep() const
957 int MathGridInset::rowsep() const
963 int MathGridInset::hlinesep() const
969 int MathGridInset::vlinesep() const
975 int MathGridInset::border() const
981 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
983 if (idx + 1 == nargs())
985 MathArray ar = cell(idx);
987 cell(idx).erase(pos, cell(idx).size());
990 cell(idx).insert(0, ar);
994 dispatch_result MathGridInset::dispatch
995 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
997 switch (cmd.action) {
999 case LFUN_MOUSE_RELEASE: {
1000 if (cmd.button() == mouse_button::button3) {
1001 WriteStream ws(lyxerr);
1003 GridInsetMailer mailer(*this);
1004 lyxerr << "mailer " << mailer.name() << " active\n";
1005 mailer.showDialog();
1011 case LFUN_INSET_DIALOG_UPDATE: {
1012 GridInsetMailer mailer(*this);
1013 mailer.updateDialog();
1017 // insert file functions
1018 case LFUN_DELETE_LINE_FORWARD:
1019 //autocorrect_ = false;
1029 if (pos > cell(idx).size())
1030 pos = cell(idx).size();
1031 return DISPATCHED_POP;
1033 case LFUN_TABINSERT:
1034 //bv->lockedInsetStoreUndo(Undo::EDIT);
1035 splitCell(idx, pos);
1036 //updateLocal(bv, true);
1037 return DISPATCHED_POP;
1039 case LFUN_BREAKLINE: {
1040 //bv->lockedInsetStoreUndo(Undo::INSERT);
1041 row_type const r = row(idx);
1045 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1046 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1049 splitCell(idx, pos);
1050 std::swap(cell(idx), cell(idx + ncols() - 1));
1053 pos = cell(idx).size();
1055 //mathcursor->normalize();
1056 //updateLocal(bv, true);
1057 return DISPATCHED_POP;
1060 case LFUN_TABULAR_FEATURE:
1061 //lyxerr << "handling tabular-feature " << cmd.argument << "\n";
1062 if (cmd.argument == "valign-top")
1064 else if (cmd.argument == "valign-center")
1066 else if (cmd.argument == "valign-bottom")
1068 else if (cmd.argument == "align-left")
1069 halign('l', col(idx));
1070 else if (cmd.argument == "align-right")
1071 halign('r', col(idx));
1072 else if (cmd.argument == "align-center")
1073 halign('c', col(idx));
1074 else if (cmd.argument == "append-row")
1076 else if (cmd.argument == "delete-row") {
1080 } else if (cmd.argument == "copy-row")
1082 else if (cmd.argument == "swap-row")
1084 else if (cmd.argument == "append-column") {
1085 row_type r = row(idx);
1086 col_type c = col(idx);
1089 } else if (cmd.argument == "delete-column") {
1090 row_type r = row(idx);
1091 col_type c = col(idx);
1096 } else if (cmd.argument == "copy-column")
1098 else if (cmd.argument == "swap-column")
1101 return UNDISPATCHED;
1102 return DISPATCHED_POP;
1105 //lyxerr << "pasting '" << cmd.argument << "'\n";
1106 MathGridInset grid(1, 1);
1107 mathed_parse_normal(grid, cmd.argument);
1108 if (grid.nargs() == 1) {
1109 // single cell/part of cell
1110 cell(idx).insert(pos, grid.cell(0));
1111 pos += grid.cell(0).size();
1114 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1115 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1116 for (row_type r = 0; r < numrows; ++r) {
1117 for (col_type c = 0; c < numcols; ++c) {
1118 idx_type i = index(r + row(idx), c + col(idx));
1119 cell(i).append(grid.cell(grid.index(r, c)));
1121 // append the left over horizontal cells to the last column
1122 idx_type i = index(r + row(idx), ncols() - 1);
1123 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1124 cell(i).append(grid.cell(grid.index(r, c)));
1126 // append the left over vertical cells to the last _cell_
1127 idx_type i = nargs() - 1;
1128 for (row_type r = numrows; r < grid.nrows(); ++r)
1129 for (col_type c = 0; c < grid.ncols(); ++c)
1130 cell(i).append(grid.cell(grid.index(r, c)));
1132 return DISPATCHED_POP;
1136 return MathNestInset::dispatch(cmd, idx, pos);
1138 return UNDISPATCHED;