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 //////////////////////////////////////////////////////////////
74 MathGridInset::CellInfo::CellInfo()
81 //////////////////////////////////////////////////////////////
84 MathGridInset::RowInfo::RowInfo()
90 int MathGridInset::RowInfo::skipPixels() const
92 return crskip_.inBP();
97 //////////////////////////////////////////////////////////////
100 MathGridInset::ColInfo::ColInfo()
101 : align_('c'), leftline_(false), rightline_(false), lines_(0)
105 //////////////////////////////////////////////////////////////
108 MathGridInset::MathGridInset(char v, string const & h)
109 : MathNestInset(guessColumns(h)),
111 colinfo_(guessColumns(h) + 1),
112 cellinfo_(1 * guessColumns(h))
117 //lyxerr << "created grid with " << ncols() << " columns\n";
121 MathGridInset::MathGridInset()
132 MathGridInset::MathGridInset(col_type m, row_type n)
133 : MathNestInset(m * n),
143 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
144 : MathNestInset(m * n),
156 MathGridInset::~MathGridInset()
158 GridInsetMailer mailer(*this);
163 MathInset * MathGridInset::clone() const
165 return new MathGridInset(*this);
169 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
171 return col + ncols() * row;
175 void MathGridInset::setDefaults()
178 lyxerr << "positive number of columns expected\n";
180 // lyxerr << "positive number of rows expected\n";
181 for (col_type col = 0; col < ncols(); ++col) {
182 colinfo_[col].align_ = defaultColAlign(col);
183 colinfo_[col].skip_ = defaultColSpace(col);
188 void MathGridInset::halign(string const & hh)
191 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
196 colinfo_[col].lines_++;
197 } else if (c == 'c' || c == 'l' || c == 'r') {
198 colinfo_[col].align_ = c;
200 colinfo_[col].lines_ = 0;
202 lyxerr << "unknown column separator: '" << c << "'\n";
207 col_type n = hh.size();
210 for (col_type col = 0; col < n; ++col)
211 colinfo_[col].align_ = hh[col];
216 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
219 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
220 if (*it == 'c' || *it == 'l' || *it == 'r')
222 // let's have at least one column, even if we did not recognize its
230 void MathGridInset::halign(char h, col_type col)
232 colinfo_[col].align_ = h;
236 char MathGridInset::halign(col_type col) const
238 return colinfo_[col].align_;
242 string MathGridInset::halign() const
245 for (col_type col = 0; col < ncols(); ++col) {
246 res += string(colinfo_[col].lines_, '|');
247 res += colinfo_[col].align_;
249 return res + string(colinfo_[ncols()].lines_, '|');
253 void MathGridInset::valign(char c)
259 char MathGridInset::valign() const
265 MathGridInset::col_type MathGridInset::ncols() const
267 return colinfo_.size() - 1;
271 MathGridInset::row_type MathGridInset::nrows() const
273 return rowinfo_.size() - 1;
277 MathGridInset::col_type MathGridInset::col(idx_type idx) const
279 return idx % ncols();
283 MathGridInset::row_type MathGridInset::row(idx_type idx) const
285 return idx / ncols();
289 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
291 rowinfo_[row].crskip_ = crskip;
295 LyXLength MathGridInset::vcrskip(row_type row) const
297 return rowinfo_[row].crskip_;
301 void MathGridInset::metrics(MetricsInfo & mi) const
303 // let the cells adjust themselves
304 MathNestInset::metrics(mi);
306 // compute absolute sizes of vertical structure
307 for (row_type row = 0; row < nrows(); ++row) {
310 for (col_type col = 0; col < ncols(); ++col) {
311 MathArray const & c = cell(index(row, col));
312 asc = max(asc, c.ascent());
313 desc = max(desc, c.descent());
315 rowinfo_[row].ascent_ = asc;
316 rowinfo_[row].descent_ = desc;
318 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
319 rowinfo_[nrows()].ascent_ = 0;
320 rowinfo_[nrows()].descent_ = 0;
322 // compute vertical offsets
323 rowinfo_[0].offset_ = 0;
324 for (row_type row = 1; row <= nrows(); ++row) {
325 rowinfo_[row].offset_ =
326 rowinfo_[row - 1].offset_ +
327 rowinfo_[row - 1].descent_ +
328 rowinfo_[row - 1].skipPixels() +
330 rowinfo_[row].lines_ * hlinesep() +
331 rowinfo_[row].ascent_;
334 // adjust vertical offset
341 h = rowinfo_[nrows() - 1].offset_;
344 h = rowinfo_[nrows() - 1].offset_ / 2;
346 for (row_type row = 0; row <= nrows(); ++row)
347 rowinfo_[row].offset_ -= h;
350 // compute absolute sizes of horizontal structure
351 for (col_type col = 0; col < ncols(); ++col) {
353 for (row_type row = 0; row < nrows(); ++row)
354 wid = max(wid, cell(index(row, col)).width());
355 colinfo_[col].width_ = wid;
357 colinfo_[ncols()].width_ = 0;
359 // compute horizontal offsets
360 colinfo_[0].offset_ = border();
361 for (col_type col = 1; col <= ncols(); ++col) {
362 colinfo_[col].offset_ =
363 colinfo_[col - 1].offset_ +
364 colinfo_[col - 1].width_ +
365 colinfo_[col - 1].skip_ +
367 colinfo_[col].lines_ * vlinesep();
371 dim_.w = colinfo_[ncols() - 1].offset_
372 + colinfo_[ncols() - 1].width_
373 + vlinesep() * colinfo_[ncols()].lines_
376 dim_.a = - rowinfo_[0].offset_
377 + rowinfo_[0].ascent_
378 + hlinesep() * rowinfo_[0].lines_
381 dim_.d = rowinfo_[nrows() - 1].offset_
382 + rowinfo_[nrows() - 1].descent_
383 + hlinesep() * rowinfo_[nrows()].lines_
388 // Increase ws_[i] for 'R' columns (except the first one)
389 for (int i = 1; i < nc_; ++i)
390 if (align_[i] == 'R')
391 ws_[i] += 10 * df_width;
392 // Increase ws_[i] for 'C' column
393 if (align_[0] == 'C')
394 if (ws_[0] < 7 * workwidth / 8)
395 ws_[0] = 7 * workwidth / 8;
399 for (cxrow = row_.begin(); cxrow; ++cxrow) {
402 for (int i = 0; i < nc_; ++i) {
404 if (cxrow->getTab(i) <= 0) {
405 cxrow->setTab(i, df_width);
413 lf = (ws_[i] - cxrow->getTab(i))/2;
417 lf = ws_[i] - cxrow->getTab(i);
420 if (cxrow == row_.begin())
422 else if (cxrow.is_last())
423 lf = ws_[i] - cxrow->getTab(i);
425 lf = (ws_[i] - cxrow->getTab(i))/2;
428 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
429 cxrow->setTab(i, lf + rg);
430 rg = ws_[i] - ww + colsep();
431 if (cxrow == row_.begin())
432 width += ws_[i] + colsep();
434 cxrow->setBaseline(cxrow->getBaseline() - ascent);
440 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
442 for (idx_type idx = 0; idx < nargs(); ++idx)
443 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
445 for (row_type row = 0; row <= nrows(); ++row)
446 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
447 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
448 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
449 pi.pain.line(x + 1, yy, x + width() - 1, yy);
452 for (col_type col = 0; col <= ncols(); ++col)
453 for (int i = 0; i < colinfo_[col].lines_; ++i) {
454 int xx = x + colinfo_[col].offset_
455 - i * vlinesep() - vlinesep()/2 - colsep()/2;
456 pi.pain.line(xx, y - ascent() + 1, xx, y + descent() - 1);
461 void MathGridInset::metricsT(TextMetricsInfo const & mi) const
463 // let the cells adjust themselves
464 //MathNestInset::metrics(mi);
465 for (idx_type i = 0; i < nargs(); ++i)
466 cell(i).metricsT(mi);
468 // compute absolute sizes of vertical structure
469 for (row_type row = 0; row < nrows(); ++row) {
472 for (col_type col = 0; col < ncols(); ++col) {
473 MathArray const & c = cell(index(row, col));
474 asc = max(asc, c.ascent());
475 desc = max(desc, c.descent());
477 rowinfo_[row].ascent_ = asc;
478 rowinfo_[row].descent_ = desc;
480 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
481 rowinfo_[nrows()].ascent_ = 0;
482 rowinfo_[nrows()].descent_ = 0;
484 // compute vertical offsets
485 rowinfo_[0].offset_ = 0;
486 for (row_type row = 1; row <= nrows(); ++row) {
487 rowinfo_[row].offset_ =
488 rowinfo_[row - 1].offset_ +
489 rowinfo_[row - 1].descent_ +
490 //rowinfo_[row - 1].skipPixels() +
492 //rowinfo_[row].lines_ * hlinesep() +
493 rowinfo_[row].ascent_;
496 // adjust vertical offset
503 h = rowinfo_[nrows() - 1].offset_;
506 h = rowinfo_[nrows() - 1].offset_ / 2;
508 for (row_type row = 0; row <= nrows(); ++row)
509 rowinfo_[row].offset_ -= h;
512 // compute absolute sizes of horizontal structure
513 for (col_type col = 0; col < ncols(); ++col) {
515 for (row_type row = 0; row < nrows(); ++row)
516 wid = max(wid, cell(index(row, col)).width());
517 colinfo_[col].width_ = wid;
519 colinfo_[ncols()].width_ = 0;
521 // compute horizontal offsets
522 colinfo_[0].offset_ = border();
523 for (col_type col = 1; col <= ncols(); ++col) {
524 colinfo_[col].offset_ =
525 colinfo_[col - 1].offset_ +
526 colinfo_[col - 1].width_ +
527 colinfo_[col - 1].skip_ +
529 //colinfo_[col].lines_ * vlinesep();
533 dim_.w = colinfo_[ncols() - 1].offset_
534 + colinfo_[ncols() - 1].width_
535 //+ vlinesep() * colinfo_[ncols()].lines_
538 dim_.a = -rowinfo_[0].offset_
539 + rowinfo_[0].ascent_
540 //+ hlinesep() * rowinfo_[0].lines_
543 dim_.d = rowinfo_[nrows() - 1].offset_
544 + rowinfo_[nrows() - 1].descent_
545 //+ hlinesep() * rowinfo_[nrows()].lines_
551 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
553 for (idx_type idx = 0; idx < nargs(); ++idx)
554 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
558 string MathGridInset::eolString(row_type row, bool fragile) const
562 if (!rowinfo_[row].crskip_.zero())
563 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
565 // make sure an upcoming '[' does not break anything
566 if (row + 1 < nrows()) {
567 MathArray const & c = cell(index(row + 1, 0));
568 if (c.size() && c.front()->getChar() == '[')
573 // only add \\ if necessary
574 if (eol.empty() && row + 1 == nrows())
577 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
581 string MathGridInset::eocString(col_type col, col_type lastcol) const
583 if (col + 1 == lastcol)
589 void MathGridInset::addRow(row_type row)
591 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
593 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
595 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
599 void MathGridInset::appendRow()
601 rowinfo_.push_back(RowInfo());
602 //cells_.insert(cells_.end(), ncols(), MathArray());
603 for (col_type col = 0; col < ncols(); ++col) {
604 cells_.push_back(cells_type::value_type());
605 cellinfo_.push_back(CellInfo());
610 void MathGridInset::delRow(row_type row)
615 cells_type::iterator it = cells_.begin() + row * ncols();
616 cells_.erase(it, it + ncols());
618 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
619 cellinfo_.erase(jt, jt + ncols());
621 rowinfo_.erase(rowinfo_.begin() + row);
625 void MathGridInset::copyRow(row_type row)
628 for (col_type col = 0; col < ncols(); ++col)
629 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
633 void MathGridInset::swapRow(row_type row)
637 if (row + 1 == nrows())
639 for (col_type col = 0; col < ncols(); ++col)
640 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
644 void MathGridInset::addCol(col_type newcol)
646 const col_type nc = ncols();
647 const row_type nr = nrows();
648 cells_type new_cells((nc + 1) * nr);
649 vector<CellInfo> new_cellinfo((nc + 1) * nr);
651 for (row_type row = 0; row < nr; ++row)
652 for (col_type col = 0; col < nc; ++col) {
653 new_cells[row * (nc + 1) + col + (col > newcol)]
654 = cells_[row * nc + col];
655 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
656 = cellinfo_[row * nc + col];
658 swap(cells_, new_cells);
659 swap(cellinfo_, new_cellinfo);
662 inf.skip_ = defaultColSpace(newcol);
663 inf.align_ = defaultColAlign(newcol);
664 colinfo_.insert(colinfo_.begin() + newcol, inf);
668 void MathGridInset::delCol(col_type col)
674 vector<CellInfo> tmpcellinfo;
675 for (col_type i = 0; i < nargs(); ++i)
676 if (i % ncols() != col) {
677 tmpcells.push_back(cells_[i]);
678 tmpcellinfo.push_back(cellinfo_[i]);
680 swap(cells_, tmpcells);
681 swap(cellinfo_, tmpcellinfo);
683 colinfo_.erase(colinfo_.begin() + col);
687 void MathGridInset::copyCol(col_type col)
690 for (row_type row = 0; row < nrows(); ++row)
691 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
695 void MathGridInset::swapCol(col_type col)
699 if (col + 1 == ncols())
701 for (row_type row = 0; row < nrows(); ++row)
702 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
706 int MathGridInset::cellXOffset(idx_type idx) const
708 col_type c = col(idx);
709 int x = colinfo_[c].offset_;
710 char align = colinfo_[c].align_;
711 if (align == 'r' || align == 'R')
712 x += colinfo_[c].width_ - cell(idx).width();
713 if (align == 'c' || align == 'C')
714 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
719 int MathGridInset::cellYOffset(idx_type idx) const
721 return rowinfo_[row(idx)].offset_;
725 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
732 pos = cell(idx).x2pos(targetx - cell(idx).xo());
735 if (idx >= ncols() * (nrows() - 1))
738 pos = cell(idx).x2pos(targetx - cell(idx).xo());
744 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
746 // leave matrix if on the left hand edge
750 pos = cell(idx).size();
755 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
757 // leave matrix if on the right hand edge
758 if (col(idx) + 1 == ncols())
766 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
773 idx = (nrows() - 1) * ncols();
776 idx = ((nrows() - 1) / 2) * ncols();
783 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
793 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
795 pos = cell(idx).size();
800 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
807 idx -= idx % ncols();
820 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
822 if (pos < cell(idx).size()) {
823 pos = cell(idx).size();
826 if (col(idx) < ncols() - 1) {
827 idx = idx - idx % ncols() + ncols() - 1;
828 pos = cell(idx).size();
831 if (idx < nargs() - 1) {
833 pos = cell(idx).size();
840 bool MathGridInset::idxDelete(idx_type & idx)
842 // nothing to do if we have just one row
846 // nothing to do if we are in the middle of the last row of the inset
847 if (idx + ncols() > nargs())
850 // try to delete entire sequence of ncols() empty cells if possible
851 for (idx_type i = idx; i < idx + ncols(); ++i)
855 // move cells if necessary
856 for (idx_type i = index(row(idx), 0); i < idx; ++i)
857 std::swap(cell(i), cell(i + ncols()));
864 // undo effect of Ctrl-Tab (i.e. pull next cell)
865 //if (idx + 1 != nargs())
866 // cell(idx).swap(cell(idx + 1));
868 // we handled the event..
873 // reimplement old behaviour when pressing Delete in the last position
875 void MathGridInset::idxGlue(idx_type idx)
877 col_type c = col(idx);
878 if (c + 1 == ncols()) {
879 if (row(idx) + 1 != nrows()) {
880 for (col_type cc = 0; cc < ncols(); ++cc)
881 cell(idx).append(cell(idx + cc + 1));
882 delRow(row(idx) + 1);
885 cell(idx).append(cell(idx + 1));
886 for (col_type cc = c + 2; cc < ncols(); ++cc)
887 cell(idx - c + cc - 1) = cell(idx - c + cc);
888 cell(idx - c + ncols() - 1).clear();
893 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
895 return rowinfo_[row];
899 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
901 return rowinfo_[row];
905 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
907 row_type const ri = row(idx);
908 row_type const r1 = min(row(from), row(to));
909 row_type const r2 = max(row(from), row(to));
910 col_type const ci = col(idx);
911 col_type const c1 = min(col(from), col(to));
912 col_type const c2 = max(col(from), col(to));
913 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
918 void MathGridInset::normalize(NormalStream & os) const
921 for (row_type row = 0; row < nrows(); ++row) {
923 for (col_type col = 0; col < ncols(); ++col)
924 os << "[cell " << cell(index(row, col)) << ']';
931 void MathGridInset::mathmlize(MathMLStream & os) const
933 os << MTag("mtable");
934 for (row_type row = 0; row < nrows(); ++row) {
936 for (col_type col = 0; col < ncols(); ++col)
937 os << cell(index(row, col));
940 os << ETag("mtable");
944 void MathGridInset::write(WriteStream & os) const
946 for (row_type row = 0; row < nrows(); ++row) {
947 os << verboseHLine(rowinfo_[row].lines_);
948 // don't write & and empty cells at end of line
949 col_type lastcol = 0;
950 bool emptyline = true;
951 for (col_type col = 0; col < ncols(); ++col)
952 if (!cell(index(row, col)).empty()) {
956 for (col_type col = 0; col < lastcol; ++col)
957 os << cell(index(row, col)) << eocString(col, lastcol);
958 os << eolString(row, os.fragile());
959 // append newline only if line wasn't completely empty
960 // and this was not the last line in the grid
961 if (!emptyline && row + 1 < nrows())
964 string const s = verboseHLine(rowinfo_[nrows()].lines_);
965 if (!s.empty() && s != " ") {
973 int MathGridInset::colsep() const
979 int MathGridInset::rowsep() const
985 int MathGridInset::hlinesep() const
991 int MathGridInset::vlinesep() const
997 int MathGridInset::border() const
1003 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1005 if (idx + 1 == nargs())
1007 MathArray ar = cell(idx);
1009 cell(idx).erase(pos, cell(idx).size());
1012 cell(idx).insert(0, ar);
1016 dispatch_result MathGridInset::dispatch
1017 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1019 switch (cmd.action) {
1021 case LFUN_MOUSE_RELEASE:
1022 //if (cmd.button() == mouse_button::button3) {
1023 // GridInsetMailer mailer(*this);
1024 // mailer.showDialog();
1025 // return DISPATCHED;
1029 case LFUN_INSET_DIALOG_UPDATE: {
1030 GridInsetMailer mailer(*this);
1031 mailer.updateDialog(cmd.view());
1035 // insert file functions
1036 case LFUN_DELETE_LINE_FORWARD:
1037 //autocorrect_ = false;
1047 if (pos > cell(idx).size())
1048 pos = cell(idx).size();
1049 return DISPATCHED_POP;
1051 case LFUN_CELL_SPLIT:
1052 //bv->lockedInsetStoreUndo(Undo::EDIT);
1053 splitCell(idx, pos);
1054 return DISPATCHED_POP;
1056 case LFUN_BREAKLINE: {
1057 //bv->lockedInsetStoreUndo(Undo::INSERT);
1058 row_type const r = row(idx);
1062 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1063 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1066 splitCell(idx, pos);
1067 std::swap(cell(idx), cell(idx + ncols() - 1));
1070 pos = cell(idx).size();
1072 //mathcursor->normalize();
1073 return DISPATCHED_POP;
1076 case LFUN_TABULAR_FEATURE: {
1077 //lyxerr << "handling tabular-feature " << cmd.argument << "\n";
1078 istringstream is(cmd.argument);
1081 if (s == "valign-top")
1083 else if (s == "valign-center")
1085 else if (s == "valign-bottom")
1087 else if (s == "align-left")
1088 halign('l', col(idx));
1089 else if (s == "align-right")
1090 halign('r', col(idx));
1091 else if (s == "align-center")
1092 halign('c', col(idx));
1093 else if (s == "append-row")
1094 for (int i = 0, n = extractInt(is); i < n; ++i)
1096 else if (s == "delete-row")
1097 for (int i = 0, n = extractInt(is); i < n; ++i) {
1102 else if (s == "copy-row")
1103 for (int i = 0, n = extractInt(is); i < n; ++i)
1105 else if (s == "swap-row")
1107 else if (s == "append-column")
1108 for (int i = 0, n = extractInt(is); i < n; ++i) {
1109 row_type r = row(idx);
1110 col_type c = col(idx);
1114 else if (s == "delete-column")
1115 for (int i = 0, n = extractInt(is); i < n; ++i) {
1116 row_type r = row(idx);
1117 col_type c = col(idx);
1123 else if (s == "copy-column")
1125 else if (s == "swap-column")
1128 return UNDISPATCHED;
1129 lyxerr << "returning DISPATCHED_POP\n";
1130 return DISPATCHED_POP;
1134 //lyxerr << "pasting '" << cmd.argument << "'\n";
1135 MathGridInset grid(1, 1);
1136 mathed_parse_normal(grid, cmd.argument);
1137 if (grid.nargs() == 1) {
1138 // single cell/part of cell
1139 cell(idx).insert(pos, grid.cell(0));
1140 pos += grid.cell(0).size();
1143 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1144 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1145 for (row_type r = 0; r < numrows; ++r) {
1146 for (col_type c = 0; c < numcols; ++c) {
1147 idx_type i = index(r + row(idx), c + col(idx));
1148 cell(i).append(grid.cell(grid.index(r, c)));
1150 // append the left over horizontal cells to the last column
1151 idx_type i = index(r + row(idx), ncols() - 1);
1152 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1153 cell(i).append(grid.cell(grid.index(r, c)));
1155 // append the left over vertical cells to the last _cell_
1156 idx_type i = nargs() - 1;
1157 for (row_type r = numrows; r < grid.nrows(); ++r)
1158 for (col_type c = 0; c < grid.ncols(); ++c)
1159 cell(i).append(grid.cell(grid.index(r, c)));
1161 return DISPATCHED_POP;
1165 return MathNestInset::dispatch(cmd, idx, pos);
1167 return UNDISPATCHED;