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"
20 class GridInsetMailer : public MailInset {
22 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
24 virtual string const & name() const
26 static const string theName = "tabular";
30 virtual string const inset2string() const
33 //data << name() << " active_cell " << inset.getActCell() << '\n';
34 data << name() << " active_cell " << 0 << '\n';
41 InsetBase & inset() const { return inset_; }
42 MathGridInset & inset_;
46 void mathed_parse_normal(MathGridInset &, string const & argument);
50 string verboseHLine(int n)
53 for (int i = 0; i < n; ++i)
61 int extractInt(istream & is)
65 return (num == 0) ? 1 : num;
71 int MathGridInset::RowInfo::skipPixels() const
73 return crskip_.inBP();
78 //////////////////////////////////////////////////////////////
81 MathGridInset::MathGridInset(char v, string const & h)
82 : MathNestInset(1), rowinfo_(1), colinfo_(1), cellinfo_(1)
87 //lyxerr << "created grid with " << ncols() << " columns\n";
91 MathGridInset::MathGridInset()
92 : MathNestInset(1), rowinfo_(1), colinfo_(1), cellinfo_(1), v_align_('c')
98 MathGridInset::MathGridInset(col_type m, row_type n)
99 : MathNestInset(m * n),
100 rowinfo_(n), colinfo_(m), cellinfo_(m * n), v_align_('c')
106 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
107 : MathNestInset(m * n),
108 rowinfo_(n), colinfo_(m), cellinfo_(m * n), v_align_(v)
116 MathGridInset::~MathGridInset()
118 GridInsetMailer mailer(*this);
123 MathInset * MathGridInset::clone() const
125 return new MathGridInset(*this);
129 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
131 return col + ncols() * row;
135 void MathGridInset::setDefaults()
138 lyxerr << "positive number of columns expected\n";
140 // lyxerr << "positive number of rows expected\n";
141 for (col_type col = 0; col < ncols(); ++col) {
142 colinfo_[col].align = defaultColAlign(col);
143 colinfo_[col].skip_ = defaultColSpace(col);
148 void MathGridInset::halign(string const & hh)
151 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
156 colinfo_[col].lines_++;
157 } else if (c == 'c' || c == 'l' || c == 'r') {
158 colinfo_[col].align = c;
160 colinfo_[col].lines_ = 0;
162 lyxerr << "unknown column separator: '" << c << "'\n";
167 col_type n = hh.size();
170 for (col_type col = 0; col < n; ++col)
171 colinfo_[col].align_ = hh[col];
177 void MathGridInset::halign(char h, col_type col)
179 colinfo_[col].align = h;
183 char MathGridInset::halign(col_type col) const
185 return colinfo_[col].align;
189 string MathGridInset::halign() const
192 for (col_type col = 0; col < ncols(); ++col) {
193 res += string(colinfo_[col].lines_, '|');
194 res += colinfo_[col].align;
196 return res + string(colinfo_[ncols()].lines_, '|');
200 void MathGridInset::valign(char c)
206 char MathGridInset::valign() const
212 MathGridInset::col_type MathGridInset::ncols() const
214 return colinfo_.size() - 1;
218 MathGridInset::row_type MathGridInset::nrows() const
220 return rowinfo_.size() - 1;
224 MathGridInset::col_type MathGridInset::col(idx_type idx) const
226 return idx % ncols();
230 MathGridInset::row_type MathGridInset::row(idx_type idx) const
232 return idx / ncols();
236 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
238 rowinfo_[row].crskip_ = crskip;
242 LyXLength MathGridInset::vcrskip(row_type row) const
244 return rowinfo_[row].crskip_;
248 void MathGridInset::metrics(MetricsInfo & mi) const
250 // let the cells adjust themselves
251 MathNestInset::metrics(mi);
253 // compute absolute sizes of vertical structure
254 for (row_type row = 0; row < nrows(); ++row) {
257 for (col_type col = 0; col < ncols(); ++col) {
258 MathArray const & c = cell(index(row, col));
259 asc = max(asc, c.ascent());
260 desc = max(desc, c.descent());
262 rowinfo_[row].ascent_ = asc;
263 rowinfo_[row].descent_ = desc;
265 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
266 rowinfo_[nrows()].ascent_ = 0;
267 rowinfo_[nrows()].descent_ = 0;
269 // compute vertical offsets
270 rowinfo_[0].offset_ = 0;
271 for (row_type row = 1; row <= nrows(); ++row) {
272 rowinfo_[row].offset_ =
273 rowinfo_[row - 1].offset_ +
274 rowinfo_[row - 1].descent_ +
275 rowinfo_[row - 1].skipPixels() +
277 rowinfo_[row].lines_ * hlinesep() +
278 rowinfo_[row].ascent_;
281 // adjust vertical offset
288 h = rowinfo_[nrows() - 1].offset_;
291 h = rowinfo_[nrows() - 1].offset_ / 2;
293 for (row_type row = 0; row <= nrows(); ++row)
294 rowinfo_[row].offset_ -= h;
297 // compute absolute sizes of horizontal structure
298 for (col_type col = 0; col < ncols(); ++col) {
300 for (row_type row = 0; row < nrows(); ++row)
301 wid = max(wid, cell(index(row, col)).width());
302 colinfo_[col].width_ = wid;
304 colinfo_[ncols()].width_ = 0;
306 // compute horizontal offsets
307 colinfo_[0].offset_ = border();
308 for (col_type col = 1; col <= ncols(); ++col) {
309 colinfo_[col].offset_ =
310 colinfo_[col - 1].offset_ +
311 colinfo_[col - 1].width_ +
312 colinfo_[col - 1].skip_ +
314 colinfo_[col].lines_ * vlinesep();
318 dim_.w = colinfo_[ncols() - 1].offset_
319 + colinfo_[ncols() - 1].width_
320 + vlinesep() * colinfo_[ncols()].lines_
323 dim_.a = - rowinfo_[0].offset_
324 + rowinfo_[0].ascent_
325 + hlinesep() * rowinfo_[0].lines_
328 dim_.d = rowinfo_[nrows() - 1].offset_
329 + rowinfo_[nrows() - 1].descent_
330 + hlinesep() * rowinfo_[nrows()].lines_
335 // Increase ws_[i] for 'R' columns (except the first one)
336 for (int i = 1; i < nc_; ++i)
337 if (align_[i] == 'R')
338 ws_[i] += 10 * df_width;
339 // Increase ws_[i] for 'C' column
340 if (align_[0] == 'C')
341 if (ws_[0] < 7 * workwidth / 8)
342 ws_[0] = 7 * workwidth / 8;
346 for (cxrow = row_.begin(); cxrow; ++cxrow) {
349 for (int i = 0; i < nc_; ++i) {
351 if (cxrow->getTab(i) <= 0) {
352 cxrow->setTab(i, df_width);
360 lf = (ws_[i] - cxrow->getTab(i))/2;
364 lf = ws_[i] - cxrow->getTab(i);
367 if (cxrow == row_.begin())
369 else if (cxrow.is_last())
370 lf = ws_[i] - cxrow->getTab(i);
372 lf = (ws_[i] - cxrow->getTab(i))/2;
375 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
376 cxrow->setTab(i, lf + rg);
377 rg = ws_[i] - ww + colsep();
378 if (cxrow == row_.begin())
379 width += ws_[i] + colsep();
381 cxrow->setBaseline(cxrow->getBaseline() - ascent);
387 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
389 for (idx_type idx = 0; idx < nargs(); ++idx)
390 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
392 for (row_type row = 0; row <= nrows(); ++row)
393 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
394 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
395 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
396 pi.pain.line(x + 1, yy, x + width() - 1, yy);
399 for (col_type col = 0; col <= ncols(); ++col)
400 for (int i = 0; i < colinfo_[col].lines_; ++i) {
401 int xx = x + colinfo_[col].offset_
402 - i * vlinesep() - vlinesep()/2 - colsep()/2;
403 pi.pain.line(xx, y - ascent() + 1, xx, y + descent() - 1);
408 void MathGridInset::metricsT(TextMetricsInfo const & mi) const
410 // let the cells adjust themselves
411 //MathNestInset::metrics(mi);
412 for (idx_type i = 0; i < nargs(); ++i)
413 cell(i).metricsT(mi);
415 // compute absolute sizes of vertical structure
416 for (row_type row = 0; row < nrows(); ++row) {
419 for (col_type col = 0; col < ncols(); ++col) {
420 MathArray const & c = cell(index(row, col));
421 asc = max(asc, c.ascent());
422 desc = max(desc, c.descent());
424 rowinfo_[row].ascent_ = asc;
425 rowinfo_[row].descent_ = desc;
427 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
428 rowinfo_[nrows()].ascent_ = 0;
429 rowinfo_[nrows()].descent_ = 0;
431 // compute vertical offsets
432 rowinfo_[0].offset_ = 0;
433 for (row_type row = 1; row <= nrows(); ++row) {
434 rowinfo_[row].offset_ =
435 rowinfo_[row - 1].offset_ +
436 rowinfo_[row - 1].descent_ +
437 //rowinfo_[row - 1].skipPixels() +
439 //rowinfo_[row].lines_ * hlinesep() +
440 rowinfo_[row].ascent_;
443 // adjust vertical offset
450 h = rowinfo_[nrows() - 1].offset_;
453 h = rowinfo_[nrows() - 1].offset_ / 2;
455 for (row_type row = 0; row <= nrows(); ++row)
456 rowinfo_[row].offset_ -= h;
459 // compute absolute sizes of horizontal structure
460 for (col_type col = 0; col < ncols(); ++col) {
462 for (row_type row = 0; row < nrows(); ++row)
463 wid = max(wid, cell(index(row, col)).width());
464 colinfo_[col].width_ = wid;
466 colinfo_[ncols()].width_ = 0;
468 // compute horizontal offsets
469 colinfo_[0].offset_ = border();
470 for (col_type col = 1; col <= ncols(); ++col) {
471 colinfo_[col].offset_ =
472 colinfo_[col - 1].offset_ +
473 colinfo_[col - 1].width_ +
474 colinfo_[col - 1].skip_ +
476 //colinfo_[col].lines_ * vlinesep();
480 dim_.w = colinfo_[ncols() - 1].offset_
481 + colinfo_[ncols() - 1].width_
482 //+ vlinesep() * colinfo_[ncols()].lines_
485 dim_.a = -rowinfo_[0].offset_
486 + rowinfo_[0].ascent_
487 //+ hlinesep() * rowinfo_[0].lines_
490 dim_.d = rowinfo_[nrows() - 1].offset_
491 + rowinfo_[nrows() - 1].descent_
492 //+ hlinesep() * rowinfo_[nrows()].lines_
498 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
500 for (idx_type idx = 0; idx < nargs(); ++idx)
501 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
505 string MathGridInset::eolString(row_type row, bool fragile) const
509 if (!rowinfo_[row].crskip_.zero())
510 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
512 // make sure an upcoming '[' does not break anything
513 if (row + 1 < nrows()) {
514 MathArray const & c = cell(index(row + 1, 0));
515 if (c.size() && c.front()->getChar() == '[')
520 // only add \\ if necessary
521 if (eol.empty() && row + 1 == nrows())
524 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
528 string MathGridInset::eocString(col_type col, col_type lastcol) const
530 if (col + 1 == lastcol)
536 void MathGridInset::addRow(row_type row)
538 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
540 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
542 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
546 void MathGridInset::appendRow()
548 rowinfo_.push_back(RowInfo());
549 //cells_.insert(cells_.end(), ncols(), MathArray());
550 for (col_type col = 0; col < ncols(); ++col) {
551 cells_.push_back(cells_type::value_type());
552 cellinfo_.push_back(CellInfo());
557 void MathGridInset::delRow(row_type row)
562 cells_type::iterator it = cells_.begin() + row * ncols();
563 cells_.erase(it, it + ncols());
565 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
566 cellinfo_.erase(jt, jt + ncols());
568 rowinfo_.erase(rowinfo_.begin() + row);
572 void MathGridInset::copyRow(row_type row)
575 for (col_type col = 0; col < ncols(); ++col)
576 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
580 void MathGridInset::swapRow(row_type row)
584 if (row + 1 == nrows())
586 for (col_type col = 0; col < ncols(); ++col)
587 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
591 void MathGridInset::addCol(col_type newcol)
593 const col_type nc = ncols();
594 const row_type nr = nrows();
595 cells_type new_cells((nc + 1) * nr);
596 vector<CellInfo> new_cellinfo((nc + 1) * nr);
598 for (row_type row = 0; row < nr; ++row)
599 for (col_type col = 0; col < nc; ++col) {
600 new_cells[row * (nc + 1) + col + (col > newcol)]
601 = cells_[row * nc + col];
602 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
603 = cellinfo_[row * nc + col];
605 swap(cells_, new_cells);
606 swap(cellinfo_, new_cellinfo);
609 inf.skip_ = defaultColSpace(newcol);
610 inf.align = defaultColAlign(newcol);
611 colinfo_.insert(colinfo_.begin() + newcol, inf);
615 void MathGridInset::delCol(col_type col)
621 vector<CellInfo> tmpcellinfo;
622 for (col_type i = 0; i < nargs(); ++i)
623 if (i % ncols() != col) {
624 tmpcells.push_back(cells_[i]);
625 tmpcellinfo.push_back(cellinfo_[i]);
627 swap(cells_, tmpcells);
628 swap(cellinfo_, tmpcellinfo);
630 colinfo_.erase(colinfo_.begin() + col);
634 void MathGridInset::copyCol(col_type col)
637 for (row_type row = 0; row < nrows(); ++row)
638 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
642 void MathGridInset::swapCol(col_type col)
646 if (col + 1 == ncols())
648 for (row_type row = 0; row < nrows(); ++row)
649 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
653 int MathGridInset::cellXOffset(idx_type idx) const
655 col_type c = col(idx);
656 int x = colinfo_[c].offset_;
657 char align = colinfo_[c].align;
658 if (align == 'r' || align == 'R')
659 x += colinfo_[c].width_ - cell(idx).width();
660 if (align == 'c' || align == 'C')
661 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
666 int MathGridInset::cellYOffset(idx_type idx) const
668 return rowinfo_[row(idx)].offset_;
672 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
679 pos = cell(idx).x2pos(targetx - cell(idx).xo());
682 if (idx >= ncols() * (nrows() - 1))
685 pos = cell(idx).x2pos(targetx - cell(idx).xo());
691 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
693 // leave matrix if on the left hand edge
697 pos = cell(idx).size();
702 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
704 // leave matrix if on the right hand edge
705 if (col(idx) + 1 == ncols())
713 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
720 idx = (nrows() - 1) * ncols();
723 idx = ((nrows() - 1) / 2) * ncols();
730 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
740 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
742 pos = cell(idx).size();
747 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
754 idx -= idx % ncols();
767 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
769 if (pos < cell(idx).size()) {
770 pos = cell(idx).size();
773 if (col(idx) < ncols() - 1) {
774 idx = idx - idx % ncols() + ncols() - 1;
775 pos = cell(idx).size();
778 if (idx < nargs() - 1) {
780 pos = cell(idx).size();
787 bool MathGridInset::idxDelete(idx_type & idx)
789 // nothing to do if we have just one row
793 // nothing to do if we are in the middle of the last row of the inset
794 if (idx + ncols() > nargs())
797 // try to delete entire sequence of ncols() empty cells if possible
798 for (idx_type i = idx; i < idx + ncols(); ++i)
802 // move cells if necessary
803 for (idx_type i = index(row(idx), 0); i < idx; ++i)
804 std::swap(cell(i), cell(i + ncols()));
811 // undo effect of Ctrl-Tab (i.e. pull next cell)
812 //if (idx + 1 != nargs())
813 // cell(idx).swap(cell(idx + 1));
815 // we handled the event..
820 // reimplement old behaviour when pressing Delete in the last position
822 void MathGridInset::idxGlue(idx_type idx)
824 col_type c = col(idx);
825 if (c + 1 == ncols()) {
826 if (row(idx) + 1 != nrows()) {
827 for (col_type cc = 0; cc < ncols(); ++cc)
828 cell(idx).append(cell(idx + cc + 1));
829 delRow(row(idx) + 1);
832 cell(idx).append(cell(idx + 1));
833 for (col_type cc = c + 2; cc < ncols(); ++cc)
834 cell(idx - c + cc - 1) = cell(idx - c + cc);
835 cell(idx - c + ncols() - 1).clear();
840 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
842 return rowinfo_[row];
846 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
848 return rowinfo_[row];
852 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
854 row_type const ri = row(idx);
855 row_type const r1 = min(row(from), row(to));
856 row_type const r2 = max(row(from), row(to));
857 col_type const ci = col(idx);
858 col_type const c1 = min(col(from), col(to));
859 col_type const c2 = max(col(from), col(to));
860 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
865 void MathGridInset::normalize(NormalStream & os) const
868 for (row_type row = 0; row < nrows(); ++row) {
870 for (col_type col = 0; col < ncols(); ++col)
871 os << "[cell " << cell(index(row, col)) << ']';
878 void MathGridInset::mathmlize(MathMLStream & os) const
880 os << MTag("mtable");
881 for (row_type row = 0; row < nrows(); ++row) {
883 for (col_type col = 0; col < ncols(); ++col)
884 os << cell(index(row, col));
887 os << ETag("mtable");
891 void MathGridInset::write(WriteStream & os) const
893 for (row_type row = 0; row < nrows(); ++row) {
894 os << verboseHLine(rowinfo_[row].lines_);
895 // don't write & and empty cells at end of line
896 col_type lastcol = 0;
897 bool emptyline = true;
898 for (col_type col = 0; col < ncols(); ++col)
899 if (!cell(index(row, col)).empty()) {
903 for (col_type col = 0; col < lastcol; ++col)
904 os << cell(index(row, col)) << eocString(col, lastcol);
905 os << eolString(row, os.fragile());
906 // append newline only if line wasn't completely empty
907 // and this was not the last line in the grid
908 if (!emptyline && row + 1 < nrows())
911 string const s = verboseHLine(rowinfo_[nrows()].lines_);
912 if (!s.empty() && s != " ") {
920 int MathGridInset::colsep() const
926 int MathGridInset::rowsep() const
932 int MathGridInset::hlinesep() const
938 int MathGridInset::vlinesep() const
944 int MathGridInset::border() const
950 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
952 if (idx + 1 == nargs())
954 MathArray ar = cell(idx);
956 cell(idx).erase(pos, cell(idx).size());
959 cell(idx).insert(0, ar);
963 dispatch_result MathGridInset::dispatch
964 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
966 switch (cmd.action) {
968 case LFUN_MOUSE_RELEASE:
969 //if (cmd.button() == mouse_button::button3) {
970 // GridInsetMailer mailer(*this);
971 // mailer.showDialog();
972 // return DISPATCHED;
976 case LFUN_INSET_DIALOG_UPDATE: {
977 GridInsetMailer mailer(*this);
978 mailer.updateDialog(cmd.view());
982 // insert file functions
983 case LFUN_DELETE_LINE_FORWARD:
984 //autocorrect_ = false;
994 if (pos > cell(idx).size())
995 pos = cell(idx).size();
996 return DISPATCHED_POP;
998 case LFUN_CELL_SPLIT:
999 //bv->lockedInsetStoreUndo(Undo::EDIT);
1000 splitCell(idx, pos);
1001 return DISPATCHED_POP;
1003 case LFUN_BREAKLINE: {
1004 //bv->lockedInsetStoreUndo(Undo::INSERT);
1005 row_type const r = row(idx);
1009 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1010 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1013 splitCell(idx, pos);
1014 std::swap(cell(idx), cell(idx + ncols() - 1));
1017 pos = cell(idx).size();
1019 //mathcursor->normalize();
1020 return DISPATCHED_POP;
1023 case LFUN_TABULAR_FEATURE: {
1024 //lyxerr << "handling tabular-feature " << cmd.argument << "\n";
1025 istringstream is(cmd.argument);
1028 if (s == "valign-top")
1030 else if (s == "valign-center")
1032 else if (s == "valign-bottom")
1034 else if (s == "align-left")
1035 halign('l', col(idx));
1036 else if (s == "align-right")
1037 halign('r', col(idx));
1038 else if (s == "align-center")
1039 halign('c', col(idx));
1040 else if (s == "append-row")
1041 for (int i = 0, n = extractInt(is); i < n; ++i)
1043 else if (s == "delete-row")
1044 for (int i = 0, n = extractInt(is); i < n; ++i) {
1049 else if (s == "copy-row")
1050 for (int i = 0, n = extractInt(is); i < n; ++i)
1052 else if (s == "swap-row")
1054 else if (s == "append-column")
1055 for (int i = 0, n = extractInt(is); i < n; ++i) {
1056 row_type r = row(idx);
1057 col_type c = col(idx);
1061 else if (s == "delete-column")
1062 for (int i = 0, n = extractInt(is); i < n; ++i) {
1063 row_type r = row(idx);
1064 col_type c = col(idx);
1070 else if (s == "copy-column")
1072 else if (s == "swap-column")
1075 return UNDISPATCHED;
1076 lyxerr << "returning DISPATCHED_POP\n";
1077 return DISPATCHED_POP;
1081 //lyxerr << "pasting '" << cmd.argument << "'\n";
1082 MathGridInset grid(1, 1);
1083 mathed_parse_normal(grid, cmd.argument);
1084 if (grid.nargs() == 1) {
1085 // single cell/part of cell
1086 cell(idx).insert(pos, grid.cell(0));
1087 pos += grid.cell(0).size();
1090 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1091 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1092 for (row_type r = 0; r < numrows; ++r) {
1093 for (col_type c = 0; c < numcols; ++c) {
1094 idx_type i = index(r + row(idx), c + col(idx));
1095 cell(i).append(grid.cell(grid.index(r, c)));
1097 // append the left over horizontal cells to the last column
1098 idx_type i = index(r + row(idx), ncols() - 1);
1099 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1100 cell(i).append(grid.cell(grid.index(r, c)));
1102 // append the left over vertical cells to the last _cell_
1103 idx_type i = nargs() - 1;
1104 for (row_type r = numrows; r < grid.nrows(); ++r)
1105 for (col_type c = 0; c < grid.ncols(); ++c)
1106 cell(i).append(grid.cell(grid.index(r, c)));
1108 return DISPATCHED_POP;
1112 return MathNestInset::dispatch(cmd, idx, pos);
1114 return UNDISPATCHED;