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 string const theName = "tabular";
30 virtual string const inset2string() const
33 //data << name() << " active_cell " << inset.getActCell() << '\n';
34 data << name() << " active_cell " << 0 << '\n';
37 return STRCONV(data.str());
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 InsetBase * 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_.wid = colinfo_[ncols() - 1].offset_
372 + colinfo_[ncols() - 1].width_
373 + vlinesep() * colinfo_[ncols()].lines_
376 dim_.asc = - rowinfo_[0].offset_
377 + rowinfo_[0].ascent_
378 + hlinesep() * rowinfo_[0].lines_
381 dim_.des = 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::metrics(MetricsInfo & mi, Dimension & dim) const
447 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
449 for (idx_type idx = 0; idx < nargs(); ++idx)
450 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
452 for (row_type row = 0; row <= nrows(); ++row)
453 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
454 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
455 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
456 pi.pain.line(x + 1, yy, x + dim_.width() - 1, yy);
459 for (col_type col = 0; col <= ncols(); ++col)
460 for (int i = 0; i < colinfo_[col].lines_; ++i) {
461 int xx = x + colinfo_[col].offset_
462 - i * vlinesep() - vlinesep()/2 - colsep()/2;
463 pi.pain.line(xx, y - dim_.ascent() + 1, xx, y + dim_.descent() - 1);
468 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
470 // let the cells adjust themselves
471 //MathNestInset::metrics(mi);
472 for (idx_type i = 0; i < nargs(); ++i)
473 cell(i).metricsT(mi, dim);
475 // compute absolute sizes of vertical structure
476 for (row_type row = 0; row < nrows(); ++row) {
479 for (col_type col = 0; col < ncols(); ++col) {
480 MathArray const & c = cell(index(row, col));
481 asc = max(asc, c.ascent());
482 desc = max(desc, c.descent());
484 rowinfo_[row].ascent_ = asc;
485 rowinfo_[row].descent_ = desc;
487 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
488 rowinfo_[nrows()].ascent_ = 0;
489 rowinfo_[nrows()].descent_ = 0;
491 // compute vertical offsets
492 rowinfo_[0].offset_ = 0;
493 for (row_type row = 1; row <= nrows(); ++row) {
494 rowinfo_[row].offset_ =
495 rowinfo_[row - 1].offset_ +
496 rowinfo_[row - 1].descent_ +
497 //rowinfo_[row - 1].skipPixels() +
499 //rowinfo_[row].lines_ * hlinesep() +
500 rowinfo_[row].ascent_;
503 // adjust vertical offset
510 h = rowinfo_[nrows() - 1].offset_;
513 h = rowinfo_[nrows() - 1].offset_ / 2;
515 for (row_type row = 0; row <= nrows(); ++row)
516 rowinfo_[row].offset_ -= h;
519 // compute absolute sizes of horizontal structure
520 for (col_type col = 0; col < ncols(); ++col) {
522 for (row_type row = 0; row < nrows(); ++row)
523 wid = max(wid, cell(index(row, col)).width());
524 colinfo_[col].width_ = wid;
526 colinfo_[ncols()].width_ = 0;
528 // compute horizontal offsets
529 colinfo_[0].offset_ = border();
530 for (col_type col = 1; col <= ncols(); ++col) {
531 colinfo_[col].offset_ =
532 colinfo_[col - 1].offset_ +
533 colinfo_[col - 1].width_ +
534 colinfo_[col - 1].skip_ +
536 //colinfo_[col].lines_ * vlinesep();
540 dim.wid = colinfo_[ncols() - 1].offset_
541 + colinfo_[ncols() - 1].width_
542 //+ vlinesep() * colinfo_[ncols()].lines_
545 dim.asc = -rowinfo_[0].offset_
546 + rowinfo_[0].ascent_
547 //+ hlinesep() * rowinfo_[0].lines_
550 dim.des = rowinfo_[nrows() - 1].offset_
551 + rowinfo_[nrows() - 1].descent_
552 //+ hlinesep() * rowinfo_[nrows()].lines_
557 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
559 for (idx_type idx = 0; idx < nargs(); ++idx)
560 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
564 string MathGridInset::eolString(row_type row, bool fragile) const
568 if (!rowinfo_[row].crskip_.zero())
569 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
571 // make sure an upcoming '[' does not break anything
572 if (row + 1 < nrows()) {
573 MathArray const & c = cell(index(row + 1, 0));
574 if (c.size() && c.front()->getChar() == '[')
579 // only add \\ if necessary
580 if (eol.empty() && row + 1 == nrows())
583 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
587 string MathGridInset::eocString(col_type col, col_type lastcol) const
589 if (col + 1 == lastcol)
595 void MathGridInset::addRow(row_type row)
597 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
599 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
601 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
605 void MathGridInset::appendRow()
607 rowinfo_.push_back(RowInfo());
608 //cells_.insert(cells_.end(), ncols(), MathArray());
609 for (col_type col = 0; col < ncols(); ++col) {
610 cells_.push_back(cells_type::value_type());
611 cellinfo_.push_back(CellInfo());
616 void MathGridInset::delRow(row_type row)
621 cells_type::iterator it = cells_.begin() + row * ncols();
622 cells_.erase(it, it + ncols());
624 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
625 cellinfo_.erase(jt, jt + ncols());
627 rowinfo_.erase(rowinfo_.begin() + row);
631 void MathGridInset::copyRow(row_type row)
634 for (col_type col = 0; col < ncols(); ++col)
635 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
639 void MathGridInset::swapRow(row_type row)
643 if (row + 1 == nrows())
645 for (col_type col = 0; col < ncols(); ++col)
646 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
650 void MathGridInset::addCol(col_type newcol)
652 const col_type nc = ncols();
653 const row_type nr = nrows();
654 cells_type new_cells((nc + 1) * nr);
655 vector<CellInfo> new_cellinfo((nc + 1) * nr);
657 for (row_type row = 0; row < nr; ++row)
658 for (col_type col = 0; col < nc; ++col) {
659 new_cells[row * (nc + 1) + col + (col > newcol)]
660 = cells_[row * nc + col];
661 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
662 = cellinfo_[row * nc + col];
664 swap(cells_, new_cells);
665 swap(cellinfo_, new_cellinfo);
668 inf.skip_ = defaultColSpace(newcol);
669 inf.align_ = defaultColAlign(newcol);
670 colinfo_.insert(colinfo_.begin() + newcol, inf);
674 void MathGridInset::delCol(col_type col)
680 vector<CellInfo> tmpcellinfo;
681 for (col_type i = 0; i < nargs(); ++i)
682 if (i % ncols() != col) {
683 tmpcells.push_back(cells_[i]);
684 tmpcellinfo.push_back(cellinfo_[i]);
686 swap(cells_, tmpcells);
687 swap(cellinfo_, tmpcellinfo);
689 colinfo_.erase(colinfo_.begin() + col);
693 void MathGridInset::copyCol(col_type col)
696 for (row_type row = 0; row < nrows(); ++row)
697 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
701 void MathGridInset::swapCol(col_type col)
705 if (col + 1 == ncols())
707 for (row_type row = 0; row < nrows(); ++row)
708 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
712 int MathGridInset::cellXOffset(idx_type idx) const
714 col_type c = col(idx);
715 int x = colinfo_[c].offset_;
716 char align = colinfo_[c].align_;
717 if (align == 'r' || align == 'R')
718 x += colinfo_[c].width_ - cell(idx).width();
719 if (align == 'c' || align == 'C')
720 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
725 int MathGridInset::cellYOffset(idx_type idx) const
727 return rowinfo_[row(idx)].offset_;
731 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
738 pos = cell(idx).x2pos(targetx - cell(idx).xo());
741 if (idx >= ncols() * (nrows() - 1))
744 pos = cell(idx).x2pos(targetx - cell(idx).xo());
750 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
752 // leave matrix if on the left hand edge
756 pos = cell(idx).size();
761 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
763 // leave matrix if on the right hand edge
764 if (col(idx) + 1 == ncols())
772 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
779 idx = (nrows() - 1) * ncols();
782 idx = ((nrows() - 1) / 2) * ncols();
789 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
799 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
801 pos = cell(idx).size();
806 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
813 idx -= idx % ncols();
826 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
828 if (pos < cell(idx).size()) {
829 pos = cell(idx).size();
832 if (col(idx) < ncols() - 1) {
833 idx = idx - idx % ncols() + ncols() - 1;
834 pos = cell(idx).size();
837 if (idx < nargs() - 1) {
839 pos = cell(idx).size();
846 bool MathGridInset::idxDelete(idx_type & idx)
848 // nothing to do if we have just one row
852 // nothing to do if we are in the middle of the last row of the inset
853 if (idx + ncols() > nargs())
856 // try to delete entire sequence of ncols() empty cells if possible
857 for (idx_type i = idx; i < idx + ncols(); ++i)
861 // move cells if necessary
862 for (idx_type i = index(row(idx), 0); i < idx; ++i)
863 std::swap(cell(i), cell(i + ncols()));
870 // undo effect of Ctrl-Tab (i.e. pull next cell)
871 //if (idx + 1 != nargs())
872 // cell(idx).swap(cell(idx + 1));
874 // we handled the event..
879 // reimplement old behaviour when pressing Delete in the last position
881 void MathGridInset::idxGlue(idx_type idx)
883 col_type c = col(idx);
884 if (c + 1 == ncols()) {
885 if (row(idx) + 1 != nrows()) {
886 for (col_type cc = 0; cc < ncols(); ++cc)
887 cell(idx).append(cell(idx + cc + 1));
888 delRow(row(idx) + 1);
891 cell(idx).append(cell(idx + 1));
892 for (col_type cc = c + 2; cc < ncols(); ++cc)
893 cell(idx - c + cc - 1) = cell(idx - c + cc);
894 cell(idx - c + ncols() - 1).clear();
899 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
901 return rowinfo_[row];
905 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
907 return rowinfo_[row];
911 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
913 row_type const ri = row(idx);
914 row_type const r1 = min(row(from), row(to));
915 row_type const r2 = max(row(from), row(to));
916 col_type const ci = col(idx);
917 col_type const c1 = min(col(from), col(to));
918 col_type const c2 = max(col(from), col(to));
919 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
924 void MathGridInset::normalize(NormalStream & os) const
927 for (row_type row = 0; row < nrows(); ++row) {
929 for (col_type col = 0; col < ncols(); ++col)
930 os << "[cell " << cell(index(row, col)) << ']';
937 void MathGridInset::mathmlize(MathMLStream & os) const
939 os << MTag("mtable");
940 for (row_type row = 0; row < nrows(); ++row) {
942 for (col_type col = 0; col < ncols(); ++col)
943 os << cell(index(row, col));
946 os << ETag("mtable");
950 void MathGridInset::write(WriteStream & os) const
952 for (row_type row = 0; row < nrows(); ++row) {
953 os << verboseHLine(rowinfo_[row].lines_);
954 // don't write & and empty cells at end of line
955 col_type lastcol = 0;
956 bool emptyline = true;
957 for (col_type col = 0; col < ncols(); ++col)
958 if (!cell(index(row, col)).empty()) {
962 for (col_type col = 0; col < lastcol; ++col)
963 os << cell(index(row, col)) << eocString(col, lastcol);
964 os << eolString(row, os.fragile());
965 // append newline only if line wasn't completely empty
966 // and this was not the last line in the grid
967 if (!emptyline && row + 1 < nrows())
970 string const s = verboseHLine(rowinfo_[nrows()].lines_);
971 if (!s.empty() && s != " ") {
979 int MathGridInset::colsep() const
985 int MathGridInset::rowsep() const
991 int MathGridInset::hlinesep() const
997 int MathGridInset::vlinesep() const
1003 int MathGridInset::border() const
1009 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1011 if (idx + 1 == nargs())
1013 MathArray ar = cell(idx);
1015 cell(idx).erase(pos, cell(idx).size());
1018 cell(idx).insert(0, ar);
1022 dispatch_result MathGridInset::dispatch
1023 (FuncRequest const & cmd, idx_type & idx, pos_type & pos)
1025 switch (cmd.action) {
1027 case LFUN_MOUSE_RELEASE:
1028 //if (cmd.button() == mouse_button::button3) {
1029 // GridInsetMailer(*this).showDialog();
1030 // return DISPATCHED;
1032 return UNDISPATCHED;
1034 case LFUN_INSET_DIALOG_UPDATE:
1035 GridInsetMailer(*this).updateDialog(cmd.view());
1036 return UNDISPATCHED;
1038 // insert file functions
1039 case LFUN_DELETE_LINE_FORWARD:
1040 //autocorrect_ = false;
1050 if (pos > cell(idx).size())
1051 pos = cell(idx).size();
1052 return DISPATCHED_POP;
1054 case LFUN_CELL_SPLIT:
1055 //bv->lockedInsetStoreUndo(Undo::EDIT);
1056 splitCell(idx, pos);
1057 return DISPATCHED_POP;
1059 case LFUN_BREAKLINE: {
1060 //bv->lockedInsetStoreUndo(Undo::INSERT);
1061 row_type const r = row(idx);
1065 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1066 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1069 splitCell(idx, pos);
1070 std::swap(cell(idx), cell(idx + ncols() - 1));
1073 pos = cell(idx).size();
1075 //mathcursor->normalize();
1076 return DISPATCHED_POP;
1079 case LFUN_TABULAR_FEATURE: {
1080 //lyxerr << "handling tabular-feature " << cmd.argument << "\n";
1081 istringstream is(STRCONV(cmd.argument));
1084 if (s == "valign-top")
1086 else if (s == "valign-center")
1088 else if (s == "valign-bottom")
1090 else if (s == "align-left")
1091 halign('l', col(idx));
1092 else if (s == "align-right")
1093 halign('r', col(idx));
1094 else if (s == "align-center")
1095 halign('c', col(idx));
1096 else if (s == "append-row")
1097 for (int i = 0, n = extractInt(is); i < n; ++i)
1099 else if (s == "delete-row")
1100 for (int i = 0, n = extractInt(is); i < n; ++i) {
1105 else if (s == "copy-row")
1106 for (int i = 0, n = extractInt(is); i < n; ++i)
1108 else if (s == "swap-row")
1110 else if (s == "append-column")
1111 for (int i = 0, n = extractInt(is); i < n; ++i) {
1112 row_type r = row(idx);
1113 col_type c = col(idx);
1117 else if (s == "delete-column")
1118 for (int i = 0, n = extractInt(is); i < n; ++i) {
1119 row_type r = row(idx);
1120 col_type c = col(idx);
1126 else if (s == "copy-column")
1128 else if (s == "swap-column")
1131 return UNDISPATCHED;
1132 lyxerr << "returning DISPATCHED_POP\n";
1133 return DISPATCHED_POP;
1137 //lyxerr << "pasting '" << cmd.argument << "'\n";
1138 MathGridInset grid(1, 1);
1139 mathed_parse_normal(grid, cmd.argument);
1140 if (grid.nargs() == 1) {
1141 // single cell/part of cell
1142 cell(idx).insert(pos, grid.cell(0));
1143 pos += grid.cell(0).size();
1146 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1147 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1148 for (row_type r = 0; r < numrows; ++r) {
1149 for (col_type c = 0; c < numcols; ++c) {
1150 idx_type i = index(r + row(idx), c + col(idx));
1151 cell(i).append(grid.cell(grid.index(r, c)));
1153 // append the left over horizontal cells to the last column
1154 idx_type i = index(r + row(idx), ncols() - 1);
1155 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1156 cell(i).append(grid.cell(grid.index(r, c)));
1158 // append the left over vertical cells to the last _cell_
1159 idx_type i = nargs() - 1;
1160 for (row_type r = numrows; r < grid.nrows(); ++r)
1161 for (col_type c = 0; c < grid.ncols(); ++c)
1162 cell(i).append(grid.cell(grid.index(r, c)));
1164 return DISPATCHED_POP;
1168 return MathNestInset::dispatch(cmd, idx, pos);