3 #include "math_gridinset.h"
4 #include "math_mathmlstream.h"
5 #include "math_streamstr.h"
7 #include "funcrequest.h"
8 #include "frontends/Painter.h"
13 #include "insets/mailinset.h"
24 class GridInsetMailer : public MailInset {
26 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
28 virtual string const & name() const
30 static string const theName = "tabular";
34 virtual string const inset2string(Buffer const &) const
37 //data << name() << " active_cell " << inset.getActCell() << '\n';
38 data << name() << " active_cell " << 0 << '\n';
41 return STRCONV(data.str());
45 InsetBase & inset() const { return inset_; }
46 MathGridInset & inset_;
50 void mathed_parse_normal(MathGridInset &, string const & argument);
54 string verboseHLine(int n)
57 for (int i = 0; i < n; ++i)
65 int extractInt(istream & is)
69 return (num == 0) ? 1 : num;
75 //////////////////////////////////////////////////////////////
78 MathGridInset::CellInfo::CellInfo()
85 //////////////////////////////////////////////////////////////
88 MathGridInset::RowInfo::RowInfo()
94 int MathGridInset::RowInfo::skipPixels() const
96 return crskip_.inBP();
101 //////////////////////////////////////////////////////////////
104 MathGridInset::ColInfo::ColInfo()
105 : align_('c'), leftline_(false), rightline_(false), lines_(0)
109 //////////////////////////////////////////////////////////////
112 MathGridInset::MathGridInset(char v, string const & h)
113 : MathNestInset(guessColumns(h)),
115 colinfo_(guessColumns(h) + 1),
116 cellinfo_(1 * guessColumns(h))
121 //lyxerr << "created grid with " << ncols() << " columns" << endl;
125 MathGridInset::MathGridInset()
136 MathGridInset::MathGridInset(col_type m, row_type n)
137 : MathNestInset(m * n),
147 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
148 : MathNestInset(m * n),
160 MathGridInset::~MathGridInset()
162 GridInsetMailer mailer(*this);
167 auto_ptr<InsetBase> MathGridInset::clone() const
169 return auto_ptr<InsetBase>(new MathGridInset(*this));
173 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
175 return col + ncols() * row;
179 void MathGridInset::setDefaults()
182 lyxerr << "positive number of columns expected" << endl;
184 // lyxerr << "positive number of rows expected" << endl;
185 for (col_type col = 0; col < ncols(); ++col) {
186 colinfo_[col].align_ = defaultColAlign(col);
187 colinfo_[col].skip_ = defaultColSpace(col);
192 void MathGridInset::halign(string const & hh)
195 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
200 colinfo_[col].lines_++;
201 } else if (c == 'c' || c == 'l' || c == 'r') {
202 colinfo_[col].align_ = c;
204 colinfo_[col].lines_ = 0;
206 lyxerr << "unknown column separator: '" << c << "'" << endl;
211 col_type n = hh.size();
214 for (col_type col = 0; col < n; ++col)
215 colinfo_[col].align_ = hh[col];
220 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
223 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
224 if (*it == 'c' || *it == 'l' || *it == 'r')
226 // let's have at least one column, even if we did not recognize its
234 void MathGridInset::halign(char h, col_type col)
236 colinfo_[col].align_ = h;
240 char MathGridInset::halign(col_type col) const
242 return colinfo_[col].align_;
246 string MathGridInset::halign() const
249 for (col_type col = 0; col < ncols(); ++col) {
250 res += string(colinfo_[col].lines_, '|');
251 res += colinfo_[col].align_;
253 return res + string(colinfo_[ncols()].lines_, '|');
257 void MathGridInset::valign(char c)
263 char MathGridInset::valign() const
269 MathGridInset::col_type MathGridInset::ncols() const
271 return colinfo_.size() - 1;
275 MathGridInset::row_type MathGridInset::nrows() const
277 return rowinfo_.size() - 1;
281 MathGridInset::col_type MathGridInset::col(idx_type idx) const
283 return idx % ncols();
287 MathGridInset::row_type MathGridInset::row(idx_type idx) const
289 return idx / ncols();
293 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
295 rowinfo_[row].crskip_ = crskip;
299 LyXLength MathGridInset::vcrskip(row_type row) const
301 return rowinfo_[row].crskip_;
305 void MathGridInset::metrics(MetricsInfo & mi) const
307 // let the cells adjust themselves
308 MathNestInset::metrics(mi);
310 // compute absolute sizes of vertical structure
311 for (row_type row = 0; row < nrows(); ++row) {
314 for (col_type col = 0; col < ncols(); ++col) {
315 MathArray const & c = cell(index(row, col));
316 asc = max(asc, c.ascent());
317 desc = max(desc, c.descent());
319 rowinfo_[row].ascent_ = asc;
320 rowinfo_[row].descent_ = desc;
322 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
323 rowinfo_[nrows()].ascent_ = 0;
324 rowinfo_[nrows()].descent_ = 0;
326 // compute vertical offsets
327 rowinfo_[0].offset_ = 0;
328 for (row_type row = 1; row <= nrows(); ++row) {
329 rowinfo_[row].offset_ =
330 rowinfo_[row - 1].offset_ +
331 rowinfo_[row - 1].descent_ +
332 rowinfo_[row - 1].skipPixels() +
334 rowinfo_[row].lines_ * hlinesep() +
335 rowinfo_[row].ascent_;
338 // adjust vertical offset
345 h = rowinfo_[nrows() - 1].offset_;
348 h = rowinfo_[nrows() - 1].offset_ / 2;
350 for (row_type row = 0; row <= nrows(); ++row)
351 rowinfo_[row].offset_ -= h;
354 // compute absolute sizes of horizontal structure
355 for (col_type col = 0; col < ncols(); ++col) {
357 for (row_type row = 0; row < nrows(); ++row)
358 wid = max(wid, cell(index(row, col)).width());
359 colinfo_[col].width_ = wid;
361 colinfo_[ncols()].width_ = 0;
363 // compute horizontal offsets
364 colinfo_[0].offset_ = border();
365 for (col_type col = 1; col <= ncols(); ++col) {
366 colinfo_[col].offset_ =
367 colinfo_[col - 1].offset_ +
368 colinfo_[col - 1].width_ +
369 colinfo_[col - 1].skip_ +
371 colinfo_[col].lines_ * vlinesep();
375 dim_.wid = colinfo_[ncols() - 1].offset_
376 + colinfo_[ncols() - 1].width_
377 + vlinesep() * colinfo_[ncols()].lines_
380 dim_.asc = - rowinfo_[0].offset_
381 + rowinfo_[0].ascent_
382 + hlinesep() * rowinfo_[0].lines_
385 dim_.des = rowinfo_[nrows() - 1].offset_
386 + rowinfo_[nrows() - 1].descent_
387 + hlinesep() * rowinfo_[nrows()].lines_
392 // Increase ws_[i] for 'R' columns (except the first one)
393 for (int i = 1; i < nc_; ++i)
394 if (align_[i] == 'R')
395 ws_[i] += 10 * df_width;
396 // Increase ws_[i] for 'C' column
397 if (align_[0] == 'C')
398 if (ws_[0] < 7 * workwidth / 8)
399 ws_[0] = 7 * workwidth / 8;
403 for (cxrow = row_.begin(); cxrow; ++cxrow) {
406 for (int i = 0; i < nc_; ++i) {
408 if (cxrow->getTab(i) <= 0) {
409 cxrow->setTab(i, df_width);
417 lf = (ws_[i] - cxrow->getTab(i))/2;
421 lf = ws_[i] - cxrow->getTab(i);
424 if (cxrow == row_.begin())
426 else if (cxrow.is_last())
427 lf = ws_[i] - cxrow->getTab(i);
429 lf = (ws_[i] - cxrow->getTab(i))/2;
432 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
433 cxrow->setTab(i, lf + rg);
434 rg = ws_[i] - ww + colsep();
435 if (cxrow == row_.begin())
436 width += ws_[i] + colsep();
438 cxrow->setBaseline(cxrow->getBaseline() - ascent);
444 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
451 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
453 for (idx_type idx = 0; idx < nargs(); ++idx)
454 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
456 for (row_type row = 0; row <= nrows(); ++row)
457 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
458 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
459 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
460 pi.pain.line(x + 1, yy, x + dim_.width() - 1, yy);
463 for (col_type col = 0; col <= ncols(); ++col)
464 for (int i = 0; i < colinfo_[col].lines_; ++i) {
465 int xx = x + colinfo_[col].offset_
466 - i * vlinesep() - vlinesep()/2 - colsep()/2;
467 pi.pain.line(xx, y - dim_.ascent() + 1, xx, y + dim_.descent() - 1);
472 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
474 // let the cells adjust themselves
475 //MathNestInset::metrics(mi);
476 for (idx_type i = 0; i < nargs(); ++i)
477 cell(i).metricsT(mi, dim);
479 // compute absolute sizes of vertical structure
480 for (row_type row = 0; row < nrows(); ++row) {
483 for (col_type col = 0; col < ncols(); ++col) {
484 MathArray const & c = cell(index(row, col));
485 asc = max(asc, c.ascent());
486 desc = max(desc, c.descent());
488 rowinfo_[row].ascent_ = asc;
489 rowinfo_[row].descent_ = desc;
491 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
492 rowinfo_[nrows()].ascent_ = 0;
493 rowinfo_[nrows()].descent_ = 0;
495 // compute vertical offsets
496 rowinfo_[0].offset_ = 0;
497 for (row_type row = 1; row <= nrows(); ++row) {
498 rowinfo_[row].offset_ =
499 rowinfo_[row - 1].offset_ +
500 rowinfo_[row - 1].descent_ +
501 //rowinfo_[row - 1].skipPixels() +
503 //rowinfo_[row].lines_ * hlinesep() +
504 rowinfo_[row].ascent_;
507 // adjust vertical offset
514 h = rowinfo_[nrows() - 1].offset_;
517 h = rowinfo_[nrows() - 1].offset_ / 2;
519 for (row_type row = 0; row <= nrows(); ++row)
520 rowinfo_[row].offset_ -= h;
523 // compute absolute sizes of horizontal structure
524 for (col_type col = 0; col < ncols(); ++col) {
526 for (row_type row = 0; row < nrows(); ++row)
527 wid = max(wid, cell(index(row, col)).width());
528 colinfo_[col].width_ = wid;
530 colinfo_[ncols()].width_ = 0;
532 // compute horizontal offsets
533 colinfo_[0].offset_ = border();
534 for (col_type col = 1; col <= ncols(); ++col) {
535 colinfo_[col].offset_ =
536 colinfo_[col - 1].offset_ +
537 colinfo_[col - 1].width_ +
538 colinfo_[col - 1].skip_ +
540 //colinfo_[col].lines_ * vlinesep();
544 dim.wid = colinfo_[ncols() - 1].offset_
545 + colinfo_[ncols() - 1].width_
546 //+ vlinesep() * colinfo_[ncols()].lines_
549 dim.asc = -rowinfo_[0].offset_
550 + rowinfo_[0].ascent_
551 //+ hlinesep() * rowinfo_[0].lines_
554 dim.des = rowinfo_[nrows() - 1].offset_
555 + rowinfo_[nrows() - 1].descent_
556 //+ hlinesep() * rowinfo_[nrows()].lines_
561 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
563 for (idx_type idx = 0; idx < nargs(); ++idx)
564 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
568 string MathGridInset::eolString(row_type row, bool fragile) const
572 if (!rowinfo_[row].crskip_.zero())
573 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
575 // make sure an upcoming '[' does not break anything
576 if (row + 1 < nrows()) {
577 MathArray const & c = cell(index(row + 1, 0));
578 if (c.size() && c.front()->getChar() == '[')
583 // only add \\ if necessary
584 if (eol.empty() && row + 1 == nrows())
587 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
591 string MathGridInset::eocString(col_type col, col_type lastcol) const
593 if (col + 1 == lastcol)
599 void MathGridInset::addRow(row_type row)
601 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
603 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
605 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
609 void MathGridInset::appendRow()
611 rowinfo_.push_back(RowInfo());
612 //cells_.insert(cells_.end(), ncols(), MathArray());
613 for (col_type col = 0; col < ncols(); ++col) {
614 cells_.push_back(cells_type::value_type());
615 cellinfo_.push_back(CellInfo());
620 void MathGridInset::delRow(row_type row)
625 cells_type::iterator it = cells_.begin() + row * ncols();
626 cells_.erase(it, it + ncols());
628 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
629 cellinfo_.erase(jt, jt + ncols());
631 rowinfo_.erase(rowinfo_.begin() + row);
635 void MathGridInset::copyRow(row_type row)
638 for (col_type col = 0; col < ncols(); ++col)
639 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
643 void MathGridInset::swapRow(row_type row)
647 if (row + 1 == nrows())
649 for (col_type col = 0; col < ncols(); ++col)
650 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
654 void MathGridInset::addCol(col_type newcol)
656 const col_type nc = ncols();
657 const row_type nr = nrows();
658 cells_type new_cells((nc + 1) * nr);
659 vector<CellInfo> new_cellinfo((nc + 1) * nr);
661 for (row_type row = 0; row < nr; ++row)
662 for (col_type col = 0; col < nc; ++col) {
663 new_cells[row * (nc + 1) + col + (col > newcol)]
664 = cells_[row * nc + col];
665 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
666 = cellinfo_[row * nc + col];
668 swap(cells_, new_cells);
669 swap(cellinfo_, new_cellinfo);
672 inf.skip_ = defaultColSpace(newcol);
673 inf.align_ = defaultColAlign(newcol);
674 colinfo_.insert(colinfo_.begin() + newcol, inf);
678 void MathGridInset::delCol(col_type col)
684 vector<CellInfo> tmpcellinfo;
685 for (col_type i = 0; i < nargs(); ++i)
686 if (i % ncols() != col) {
687 tmpcells.push_back(cells_[i]);
688 tmpcellinfo.push_back(cellinfo_[i]);
690 swap(cells_, tmpcells);
691 swap(cellinfo_, tmpcellinfo);
693 colinfo_.erase(colinfo_.begin() + col);
697 void MathGridInset::copyCol(col_type col)
700 for (row_type row = 0; row < nrows(); ++row)
701 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
705 void MathGridInset::swapCol(col_type col)
709 if (col + 1 == ncols())
711 for (row_type row = 0; row < nrows(); ++row)
712 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
716 int MathGridInset::cellXOffset(idx_type idx) const
718 col_type c = col(idx);
719 int x = colinfo_[c].offset_;
720 char align = colinfo_[c].align_;
721 if (align == 'r' || align == 'R')
722 x += colinfo_[c].width_ - cell(idx).width();
723 if (align == 'c' || align == 'C')
724 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
729 int MathGridInset::cellYOffset(idx_type idx) const
731 return rowinfo_[row(idx)].offset_;
735 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
742 pos = cell(idx).x2pos(targetx - cell(idx).xo());
745 if (idx >= ncols() * (nrows() - 1))
748 pos = cell(idx).x2pos(targetx - cell(idx).xo());
754 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
756 // leave matrix if on the left hand edge
760 pos = cell(idx).size();
765 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
767 // leave matrix if on the right hand edge
768 if (col(idx) + 1 == ncols())
776 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
783 idx = (nrows() - 1) * ncols();
786 idx = ((nrows() - 1) / 2) * ncols();
793 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
803 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
805 pos = cell(idx).size();
810 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
817 idx -= idx % ncols();
830 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
832 if (pos < cell(idx).size()) {
833 pos = cell(idx).size();
836 if (col(idx) < ncols() - 1) {
837 idx = idx - idx % ncols() + ncols() - 1;
838 pos = cell(idx).size();
841 if (idx < nargs() - 1) {
843 pos = cell(idx).size();
850 bool MathGridInset::idxDelete(idx_type & idx)
852 // nothing to do if we have just one row
856 // nothing to do if we are in the middle of the last row of the inset
857 if (idx + ncols() > nargs())
860 // try to delete entire sequence of ncols() empty cells if possible
861 for (idx_type i = idx; i < idx + ncols(); ++i)
865 // move cells if necessary
866 for (idx_type i = index(row(idx), 0); i < idx; ++i)
867 std::swap(cell(i), cell(i + ncols()));
874 // undo effect of Ctrl-Tab (i.e. pull next cell)
875 //if (idx + 1 != nargs())
876 // cell(idx).swap(cell(idx + 1));
878 // we handled the event..
883 // reimplement old behaviour when pressing Delete in the last position
885 void MathGridInset::idxGlue(idx_type idx)
887 col_type c = col(idx);
888 if (c + 1 == ncols()) {
889 if (row(idx) + 1 != nrows()) {
890 for (col_type cc = 0; cc < ncols(); ++cc)
891 cell(idx).append(cell(idx + cc + 1));
892 delRow(row(idx) + 1);
895 cell(idx).append(cell(idx + 1));
896 for (col_type cc = c + 2; cc < ncols(); ++cc)
897 cell(idx - c + cc - 1) = cell(idx - c + cc);
898 cell(idx - c + ncols() - 1).clear();
903 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
905 return rowinfo_[row];
909 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
911 return rowinfo_[row];
915 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
917 row_type const ri = row(idx);
918 row_type const r1 = min(row(from), row(to));
919 row_type const r2 = max(row(from), row(to));
920 col_type const ci = col(idx);
921 col_type const c1 = min(col(from), col(to));
922 col_type const c2 = max(col(from), col(to));
923 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
928 void MathGridInset::normalize(NormalStream & os) const
931 for (row_type row = 0; row < nrows(); ++row) {
933 for (col_type col = 0; col < ncols(); ++col)
934 os << "[cell " << cell(index(row, col)) << ']';
941 void MathGridInset::mathmlize(MathMLStream & os) const
943 os << MTag("mtable");
944 for (row_type row = 0; row < nrows(); ++row) {
946 for (col_type col = 0; col < ncols(); ++col)
947 os << cell(index(row, col));
950 os << ETag("mtable");
954 void MathGridInset::write(WriteStream & os) const
956 for (row_type row = 0; row < nrows(); ++row) {
957 os << verboseHLine(rowinfo_[row].lines_);
958 // don't write & and empty cells at end of line
959 col_type lastcol = 0;
960 bool emptyline = true;
961 for (col_type col = 0; col < ncols(); ++col)
962 if (!cell(index(row, col)).empty()) {
966 for (col_type col = 0; col < lastcol; ++col)
967 os << cell(index(row, col)) << eocString(col, lastcol);
968 os << eolString(row, os.fragile());
969 // append newline only if line wasn't completely empty
970 // and this was not the last line in the grid
971 if (!emptyline && row + 1 < nrows())
974 string const s = verboseHLine(rowinfo_[nrows()].lines_);
975 if (!s.empty() && s != " ") {
983 int MathGridInset::colsep() const
989 int MathGridInset::rowsep() const
995 int MathGridInset::hlinesep() const
1001 int MathGridInset::vlinesep() const
1007 int MathGridInset::border() const
1013 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1015 if (idx + 1 == nargs())
1017 MathArray ar = cell(idx);
1019 cell(idx).erase(pos, cell(idx).size());
1022 cell(idx).insert(0, ar);
1026 dispatch_result MathGridInset::dispatch
1027 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1029 switch (cmd.action) {
1031 case LFUN_MOUSE_RELEASE:
1032 //if (cmd.button() == mouse_button::button3) {
1033 // GridInsetMailer(*this).showDialog();
1034 // return DISPATCHED;
1036 return UNDISPATCHED;
1038 case LFUN_INSET_DIALOG_UPDATE:
1039 GridInsetMailer(*this).updateDialog(cmd.view());
1040 return UNDISPATCHED;
1042 // insert file functions
1043 case LFUN_DELETE_LINE_FORWARD:
1044 //autocorrect_ = false;
1054 if (pos > cell(idx).size())
1055 pos = cell(idx).size();
1056 return DISPATCHED_POP;
1058 case LFUN_CELL_SPLIT:
1059 //recordUndo(bv, Undo::ATOMIC);
1060 splitCell(idx, pos);
1061 return DISPATCHED_POP;
1063 case LFUN_BREAKLINE: {
1064 //recordUndo(bv, Undo::INSERT);
1065 row_type const r = row(idx);
1069 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1070 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1073 splitCell(idx, pos);
1074 std::swap(cell(idx), cell(idx + ncols() - 1));
1077 pos = cell(idx).size();
1079 //mathcursor->normalize();
1080 return DISPATCHED_POP;
1083 case LFUN_TABULAR_FEATURE: {
1084 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1085 istringstream is(STRCONV(cmd.argument));
1088 if (s == "valign-top")
1090 else if (s == "valign-center")
1092 else if (s == "valign-bottom")
1094 else if (s == "align-left")
1095 halign('l', col(idx));
1096 else if (s == "align-right")
1097 halign('r', col(idx));
1098 else if (s == "align-center")
1099 halign('c', col(idx));
1100 else if (s == "append-row")
1101 for (int i = 0, n = extractInt(is); i < n; ++i)
1103 else if (s == "delete-row")
1104 for (int i = 0, n = extractInt(is); i < n; ++i) {
1109 else if (s == "copy-row")
1110 for (int i = 0, n = extractInt(is); i < n; ++i)
1112 else if (s == "swap-row")
1114 else if (s == "append-column")
1115 for (int i = 0, n = extractInt(is); i < n; ++i) {
1116 row_type r = row(idx);
1117 col_type c = col(idx);
1121 else if (s == "delete-column")
1122 for (int i = 0, n = extractInt(is); i < n; ++i) {
1123 row_type r = row(idx);
1124 col_type c = col(idx);
1130 else if (s == "copy-column")
1132 else if (s == "swap-column")
1135 return UNDISPATCHED;
1136 lyxerr << "returning DISPATCHED_POP" << endl;
1137 return DISPATCHED_POP;
1141 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1142 MathGridInset grid(1, 1);
1143 mathed_parse_normal(grid, cmd.argument);
1144 if (grid.nargs() == 1) {
1145 // single cell/part of cell
1146 cell(idx).insert(pos, grid.cell(0));
1147 pos += grid.cell(0).size();
1150 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1151 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1152 for (row_type r = 0; r < numrows; ++r) {
1153 for (col_type c = 0; c < numcols; ++c) {
1154 idx_type i = index(r + row(idx), c + col(idx));
1155 cell(i).append(grid.cell(grid.index(r, c)));
1157 // append the left over horizontal cells to the last column
1158 idx_type i = index(r + row(idx), ncols() - 1);
1159 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1160 cell(i).append(grid.cell(grid.index(r, c)));
1162 // append the left over vertical cells to the last _cell_
1163 idx_type i = nargs() - 1;
1164 for (row_type r = numrows; r < grid.nrows(); ++r)
1165 for (col_type c = 0; c < grid.ncols(); ++c)
1166 cell(i).append(grid.cell(grid.index(r, c)));
1168 return DISPATCHED_POP;
1172 return MathNestInset::dispatch(cmd, idx, pos);