2 * \file math_gridinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "math_gridinset.h"
14 #include "math_data.h"
15 #include "math_mathmlstream.h"
16 #include "math_streamstr.h"
17 #include "dispatchresult.h"
19 #include "funcrequest.h"
21 #include "frontends/Painter.h"
22 #include "support/std_sstream.h"
24 #include "insets/mailinset.h"
34 using std::istringstream;
35 using std::ostringstream;
39 class GridInsetMailer : public MailInset {
41 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
43 virtual string const & name() const
45 static string const theName = "tabular";
49 virtual string const inset2string(Buffer const &) const
52 //data << name() << " active_cell " << inset.getActCell() << '\n';
53 data << name() << " active_cell " << 0 << '\n';
60 InsetBase & inset() const { return inset_; }
61 MathGridInset & inset_;
65 void mathed_parse_normal(MathGridInset &, string const & argument);
69 string verboseHLine(int n)
72 for (int i = 0; i < n; ++i)
80 int extractInt(istream & is)
84 return (num == 0) ? 1 : num;
90 //////////////////////////////////////////////////////////////
93 MathGridInset::CellInfo::CellInfo()
100 //////////////////////////////////////////////////////////////
103 MathGridInset::RowInfo::RowInfo()
104 : lines_(0), skip_(0)
109 int MathGridInset::RowInfo::skipPixels() const
111 return crskip_.inBP();
116 //////////////////////////////////////////////////////////////
119 MathGridInset::ColInfo::ColInfo()
120 : align_('c'), leftline_(false), rightline_(false), lines_(0)
124 //////////////////////////////////////////////////////////////
127 MathGridInset::MathGridInset(char v, string const & h)
128 : MathNestInset(guessColumns(h)),
130 colinfo_(guessColumns(h) + 1),
131 cellinfo_(1 * guessColumns(h))
136 //lyxerr << "created grid with " << ncols() << " columns" << endl;
140 MathGridInset::MathGridInset()
151 MathGridInset::MathGridInset(col_type m, row_type n)
152 : MathNestInset(m * n),
162 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
163 : MathNestInset(m * n),
175 MathGridInset::~MathGridInset()
177 GridInsetMailer mailer(*this);
182 auto_ptr<InsetBase> MathGridInset::clone() const
184 return auto_ptr<InsetBase>(new MathGridInset(*this));
188 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
190 return col + ncols() * row;
194 void MathGridInset::setDefaults()
197 lyxerr << "positive number of columns expected" << endl;
199 // lyxerr << "positive number of rows expected" << endl;
200 for (col_type col = 0; col < ncols(); ++col) {
201 colinfo_[col].align_ = defaultColAlign(col);
202 colinfo_[col].skip_ = defaultColSpace(col);
207 void MathGridInset::halign(string const & hh)
210 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
215 colinfo_[col].lines_++;
216 } else if (c == 'c' || c == 'l' || c == 'r') {
217 colinfo_[col].align_ = c;
219 colinfo_[col].lines_ = 0;
221 lyxerr << "unknown column separator: '" << c << "'" << endl;
226 col_type n = hh.size();
229 for (col_type col = 0; col < n; ++col)
230 colinfo_[col].align_ = hh[col];
235 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
238 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
239 if (*it == 'c' || *it == 'l' || *it == 'r')
241 // let's have at least one column, even if we did not recognize its
249 void MathGridInset::halign(char h, col_type col)
251 colinfo_[col].align_ = h;
255 char MathGridInset::halign(col_type col) const
257 return colinfo_[col].align_;
261 string MathGridInset::halign() const
264 for (col_type col = 0; col < ncols(); ++col) {
265 res += string(colinfo_[col].lines_, '|');
266 res += colinfo_[col].align_;
268 return res + string(colinfo_[ncols()].lines_, '|');
272 void MathGridInset::valign(char c)
278 char MathGridInset::valign() const
284 MathGridInset::col_type MathGridInset::ncols() const
286 return colinfo_.size() - 1;
290 MathGridInset::row_type MathGridInset::nrows() const
292 return rowinfo_.size() - 1;
296 MathGridInset::col_type MathGridInset::col(idx_type idx) const
298 return idx % ncols();
302 MathGridInset::row_type MathGridInset::row(idx_type idx) const
304 return idx / ncols();
308 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
310 rowinfo_[row].crskip_ = crskip;
314 LyXLength MathGridInset::vcrskip(row_type row) const
316 return rowinfo_[row].crskip_;
320 void MathGridInset::metrics(MetricsInfo & mi) const
322 // let the cells adjust themselves
323 MathNestInset::metrics(mi);
325 // compute absolute sizes of vertical structure
326 for (row_type row = 0; row < nrows(); ++row) {
329 for (col_type col = 0; col < ncols(); ++col) {
330 MathArray const & c = cell(index(row, col));
331 asc = max(asc, c.ascent());
332 desc = max(desc, c.descent());
334 rowinfo_[row].ascent_ = asc;
335 rowinfo_[row].descent_ = desc;
337 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
338 rowinfo_[nrows()].ascent_ = 0;
339 rowinfo_[nrows()].descent_ = 0;
341 // compute vertical offsets
342 rowinfo_[0].offset_ = 0;
343 for (row_type row = 1; row <= nrows(); ++row) {
344 rowinfo_[row].offset_ =
345 rowinfo_[row - 1].offset_ +
346 rowinfo_[row - 1].descent_ +
347 rowinfo_[row - 1].skipPixels() +
349 rowinfo_[row].lines_ * hlinesep() +
350 rowinfo_[row].ascent_;
353 // adjust vertical offset
360 h = rowinfo_[nrows() - 1].offset_;
363 h = rowinfo_[nrows() - 1].offset_ / 2;
365 for (row_type row = 0; row <= nrows(); ++row)
366 rowinfo_[row].offset_ -= h;
369 // compute absolute sizes of horizontal structure
370 for (col_type col = 0; col < ncols(); ++col) {
372 for (row_type row = 0; row < nrows(); ++row)
373 wid = max(wid, cell(index(row, col)).width());
374 colinfo_[col].width_ = wid;
376 colinfo_[ncols()].width_ = 0;
378 // compute horizontal offsets
379 colinfo_[0].offset_ = border();
380 for (col_type col = 1; col <= ncols(); ++col) {
381 colinfo_[col].offset_ =
382 colinfo_[col - 1].offset_ +
383 colinfo_[col - 1].width_ +
384 colinfo_[col - 1].skip_ +
386 colinfo_[col].lines_ * vlinesep();
390 dim_.wid = colinfo_[ncols() - 1].offset_
391 + colinfo_[ncols() - 1].width_
392 + vlinesep() * colinfo_[ncols()].lines_
395 dim_.asc = - rowinfo_[0].offset_
396 + rowinfo_[0].ascent_
397 + hlinesep() * rowinfo_[0].lines_
400 dim_.des = rowinfo_[nrows() - 1].offset_
401 + rowinfo_[nrows() - 1].descent_
402 + hlinesep() * rowinfo_[nrows()].lines_
407 // Increase ws_[i] for 'R' columns (except the first one)
408 for (int i = 1; i < nc_; ++i)
409 if (align_[i] == 'R')
410 ws_[i] += 10 * df_width;
411 // Increase ws_[i] for 'C' column
412 if (align_[0] == 'C')
413 if (ws_[0] < 7 * workwidth / 8)
414 ws_[0] = 7 * workwidth / 8;
418 for (cxrow = row_.begin(); cxrow; ++cxrow) {
421 for (int i = 0; i < nc_; ++i) {
423 if (cxrow->getTab(i) <= 0) {
424 cxrow->setTab(i, df_width);
432 lf = (ws_[i] - cxrow->getTab(i))/2;
436 lf = ws_[i] - cxrow->getTab(i);
439 if (cxrow == row_.begin())
441 else if (cxrow.is_last())
442 lf = ws_[i] - cxrow->getTab(i);
444 lf = (ws_[i] - cxrow->getTab(i))/2;
447 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
448 cxrow->setTab(i, lf + rg);
449 rg = ws_[i] - ww + colsep();
450 if (cxrow == row_.begin())
451 width += ws_[i] + colsep();
453 cxrow->setBaseline(cxrow->getBaseline() - ascent);
459 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
466 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
468 for (idx_type idx = 0; idx < nargs(); ++idx)
469 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
471 for (row_type row = 0; row <= nrows(); ++row)
472 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
473 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
474 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
475 pi.pain.line(x + 1, yy,
476 x + dim_.width() - 1, yy,
480 for (col_type col = 0; col <= ncols(); ++col)
481 for (int i = 0; i < colinfo_[col].lines_; ++i) {
482 int xx = x + colinfo_[col].offset_
483 - i * vlinesep() - vlinesep()/2 - colsep()/2;
484 pi.pain.line(xx, y - dim_.ascent() + 1,
485 xx, y + dim_.descent() - 1,
491 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
493 // let the cells adjust themselves
494 //MathNestInset::metrics(mi);
495 for (idx_type i = 0; i < nargs(); ++i)
496 cell(i).metricsT(mi, dim);
498 // compute absolute sizes of vertical structure
499 for (row_type row = 0; row < nrows(); ++row) {
502 for (col_type col = 0; col < ncols(); ++col) {
503 MathArray const & c = cell(index(row, col));
504 asc = max(asc, c.ascent());
505 desc = max(desc, c.descent());
507 rowinfo_[row].ascent_ = asc;
508 rowinfo_[row].descent_ = desc;
510 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
511 rowinfo_[nrows()].ascent_ = 0;
512 rowinfo_[nrows()].descent_ = 0;
514 // compute vertical offsets
515 rowinfo_[0].offset_ = 0;
516 for (row_type row = 1; row <= nrows(); ++row) {
517 rowinfo_[row].offset_ =
518 rowinfo_[row - 1].offset_ +
519 rowinfo_[row - 1].descent_ +
520 //rowinfo_[row - 1].skipPixels() +
522 //rowinfo_[row].lines_ * hlinesep() +
523 rowinfo_[row].ascent_;
526 // adjust vertical offset
533 h = rowinfo_[nrows() - 1].offset_;
536 h = rowinfo_[nrows() - 1].offset_ / 2;
538 for (row_type row = 0; row <= nrows(); ++row)
539 rowinfo_[row].offset_ -= h;
542 // compute absolute sizes of horizontal structure
543 for (col_type col = 0; col < ncols(); ++col) {
545 for (row_type row = 0; row < nrows(); ++row)
546 wid = max(wid, cell(index(row, col)).width());
547 colinfo_[col].width_ = wid;
549 colinfo_[ncols()].width_ = 0;
551 // compute horizontal offsets
552 colinfo_[0].offset_ = border();
553 for (col_type col = 1; col <= ncols(); ++col) {
554 colinfo_[col].offset_ =
555 colinfo_[col - 1].offset_ +
556 colinfo_[col - 1].width_ +
557 colinfo_[col - 1].skip_ +
559 //colinfo_[col].lines_ * vlinesep();
563 dim.wid = colinfo_[ncols() - 1].offset_
564 + colinfo_[ncols() - 1].width_
565 //+ vlinesep() * colinfo_[ncols()].lines_
568 dim.asc = -rowinfo_[0].offset_
569 + rowinfo_[0].ascent_
570 //+ hlinesep() * rowinfo_[0].lines_
573 dim.des = rowinfo_[nrows() - 1].offset_
574 + rowinfo_[nrows() - 1].descent_
575 //+ hlinesep() * rowinfo_[nrows()].lines_
580 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
582 for (idx_type idx = 0; idx < nargs(); ++idx)
583 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
587 string MathGridInset::eolString(row_type row, bool fragile) const
591 if (!rowinfo_[row].crskip_.zero())
592 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
594 // make sure an upcoming '[' does not break anything
595 if (row + 1 < nrows()) {
596 MathArray const & c = cell(index(row + 1, 0));
597 if (c.size() && c.front()->getChar() == '[')
602 // only add \\ if necessary
603 if (eol.empty() && row + 1 == nrows())
606 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
610 string MathGridInset::eocString(col_type col, col_type lastcol) const
612 if (col + 1 == lastcol)
618 void MathGridInset::addRow(row_type row)
620 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
622 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
624 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
628 void MathGridInset::appendRow()
630 rowinfo_.push_back(RowInfo());
631 //cells_.insert(cells_.end(), ncols(), MathArray());
632 for (col_type col = 0; col < ncols(); ++col) {
633 cells_.push_back(cells_type::value_type());
634 cellinfo_.push_back(CellInfo());
639 void MathGridInset::delRow(row_type row)
644 cells_type::iterator it = cells_.begin() + row * ncols();
645 cells_.erase(it, it + ncols());
647 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
648 cellinfo_.erase(jt, jt + ncols());
650 rowinfo_.erase(rowinfo_.begin() + row);
654 void MathGridInset::copyRow(row_type row)
657 for (col_type col = 0; col < ncols(); ++col)
658 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
662 void MathGridInset::swapRow(row_type row)
666 if (row + 1 == nrows())
668 for (col_type col = 0; col < ncols(); ++col)
669 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
673 void MathGridInset::addCol(col_type newcol)
675 const col_type nc = ncols();
676 const row_type nr = nrows();
677 cells_type new_cells((nc + 1) * nr);
678 vector<CellInfo> new_cellinfo((nc + 1) * nr);
680 for (row_type row = 0; row < nr; ++row)
681 for (col_type col = 0; col < nc; ++col) {
682 new_cells[row * (nc + 1) + col + (col > newcol)]
683 = cells_[row * nc + col];
684 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
685 = cellinfo_[row * nc + col];
687 swap(cells_, new_cells);
688 swap(cellinfo_, new_cellinfo);
691 inf.skip_ = defaultColSpace(newcol);
692 inf.align_ = defaultColAlign(newcol);
693 colinfo_.insert(colinfo_.begin() + newcol, inf);
697 void MathGridInset::delCol(col_type col)
703 vector<CellInfo> tmpcellinfo;
704 for (col_type i = 0; i < nargs(); ++i)
705 if (i % ncols() != col) {
706 tmpcells.push_back(cells_[i]);
707 tmpcellinfo.push_back(cellinfo_[i]);
709 swap(cells_, tmpcells);
710 swap(cellinfo_, tmpcellinfo);
712 colinfo_.erase(colinfo_.begin() + col);
716 void MathGridInset::copyCol(col_type col)
719 for (row_type row = 0; row < nrows(); ++row)
720 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
724 void MathGridInset::swapCol(col_type col)
728 if (col + 1 == ncols())
730 for (row_type row = 0; row < nrows(); ++row)
731 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
735 int MathGridInset::cellXOffset(idx_type idx) const
737 col_type c = col(idx);
738 int x = colinfo_[c].offset_;
739 char align = colinfo_[c].align_;
740 if (align == 'r' || align == 'R')
741 x += colinfo_[c].width_ - cell(idx).width();
742 if (align == 'c' || align == 'C')
743 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
748 int MathGridInset::cellYOffset(idx_type idx) const
750 return rowinfo_[row(idx)].offset_;
754 bool MathGridInset::idxUpDown(idx_type & idx, pos_type & pos, bool up,
761 pos = cell(idx).x2pos(targetx - cell(idx).xo());
764 if (idx >= ncols() * (nrows() - 1))
767 pos = cell(idx).x2pos(targetx - cell(idx).xo());
773 bool MathGridInset::idxLeft(idx_type & idx, pos_type & pos) const
775 // leave matrix if on the left hand edge
779 pos = cell(idx).size();
784 bool MathGridInset::idxRight(idx_type & idx, pos_type & pos) const
786 // leave matrix if on the right hand edge
787 if (col(idx) + 1 == ncols())
795 bool MathGridInset::idxFirst(idx_type & idx, pos_type & pos) const
802 idx = (nrows() - 1) * ncols();
805 idx = ((nrows() - 1) / 2) * ncols();
812 bool MathGridInset::idxLast(idx_type & idx, pos_type & pos) const
822 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
824 pos = cell(idx).size();
829 bool MathGridInset::idxHome(idx_type & idx, pos_type & pos) const
836 idx -= idx % ncols();
849 bool MathGridInset::idxEnd(idx_type & idx, pos_type & pos) const
851 if (pos < cell(idx).size()) {
852 pos = cell(idx).size();
855 if (col(idx) < ncols() - 1) {
856 idx = idx - idx % ncols() + ncols() - 1;
857 pos = cell(idx).size();
860 if (idx < nargs() - 1) {
862 pos = cell(idx).size();
869 bool MathGridInset::idxDelete(idx_type & idx)
871 // nothing to do if we have just one row
875 // nothing to do if we are in the middle of the last row of the inset
876 if (idx + ncols() > nargs())
879 // try to delete entire sequence of ncols() empty cells if possible
880 for (idx_type i = idx; i < idx + ncols(); ++i)
884 // move cells if necessary
885 for (idx_type i = index(row(idx), 0); i < idx; ++i)
886 std::swap(cell(i), cell(i + ncols()));
893 // undo effect of Ctrl-Tab (i.e. pull next cell)
894 //if (idx + 1 != nargs())
895 // cell(idx).swap(cell(idx + 1));
897 // we handled the event..
902 // reimplement old behaviour when pressing Delete in the last position
904 void MathGridInset::idxGlue(idx_type idx)
906 col_type c = col(idx);
907 if (c + 1 == ncols()) {
908 if (row(idx) + 1 != nrows()) {
909 for (col_type cc = 0; cc < ncols(); ++cc)
910 cell(idx).append(cell(idx + cc + 1));
911 delRow(row(idx) + 1);
914 cell(idx).append(cell(idx + 1));
915 for (col_type cc = c + 2; cc < ncols(); ++cc)
916 cell(idx - c + cc - 1) = cell(idx - c + cc);
917 cell(idx - c + ncols() - 1).clear();
922 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
924 return rowinfo_[row];
928 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
930 return rowinfo_[row];
934 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
936 row_type const ri = row(idx);
937 row_type const r1 = min(row(from), row(to));
938 row_type const r2 = max(row(from), row(to));
939 col_type const ci = col(idx);
940 col_type const c1 = min(col(from), col(to));
941 col_type const c2 = max(col(from), col(to));
942 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
947 void MathGridInset::normalize(NormalStream & os) const
950 for (row_type row = 0; row < nrows(); ++row) {
952 for (col_type col = 0; col < ncols(); ++col)
953 os << "[cell " << cell(index(row, col)) << ']';
960 void MathGridInset::mathmlize(MathMLStream & os) const
962 os << MTag("mtable");
963 for (row_type row = 0; row < nrows(); ++row) {
965 for (col_type col = 0; col < ncols(); ++col)
966 os << cell(index(row, col));
969 os << ETag("mtable");
973 void MathGridInset::write(WriteStream & os) const
975 for (row_type row = 0; row < nrows(); ++row) {
976 os << verboseHLine(rowinfo_[row].lines_);
977 // don't write & and empty cells at end of line
978 col_type lastcol = 0;
979 bool emptyline = true;
980 for (col_type col = 0; col < ncols(); ++col)
981 if (!cell(index(row, col)).empty()) {
985 for (col_type col = 0; col < lastcol; ++col)
986 os << cell(index(row, col)) << eocString(col, lastcol);
987 os << eolString(row, os.fragile());
988 // append newline only if line wasn't completely empty
989 // and this was not the last line in the grid
990 if (!emptyline && row + 1 < nrows())
993 string const s = verboseHLine(rowinfo_[nrows()].lines_);
994 if (!s.empty() && s != " ") {
1002 int MathGridInset::colsep() const
1008 int MathGridInset::rowsep() const
1014 int MathGridInset::hlinesep() const
1020 int MathGridInset::vlinesep() const
1026 int MathGridInset::border() const
1032 void MathGridInset::splitCell(idx_type & idx, pos_type & pos)
1034 if (idx + 1 == nargs())
1036 MathArray ar = cell(idx);
1038 cell(idx).erase(pos, cell(idx).size());
1041 cell(idx).insert(0, ar);
1045 DispatchResult MathGridInset::priv_dispatch(FuncRequest const & cmd,
1046 idx_type & idx, pos_type & pos)
1048 switch (cmd.action) {
1050 case LFUN_MOUSE_RELEASE:
1051 //if (cmd.button() == mouse_button::button3) {
1052 // GridInsetMailer(*this).showDialog();
1053 // return DispatchResult(true);
1055 return DispatchResult(false);
1057 case LFUN_INSET_DIALOG_UPDATE:
1058 GridInsetMailer(*this).updateDialog(cmd.view());
1059 return DispatchResult(false);
1061 // insert file functions
1062 case LFUN_DELETE_LINE_FORWARD:
1063 //autocorrect_ = false;
1073 if (pos > cell(idx).size())
1074 pos = cell(idx).size();
1075 return DispatchResult(true, FINISHED);
1077 case LFUN_CELL_SPLIT:
1078 //recordUndo(bv, Undo::ATOMIC);
1079 splitCell(idx, pos);
1080 return DispatchResult(true, FINISHED);
1082 case LFUN_BREAKLINE: {
1083 //recordUndo(bv, Undo::INSERT);
1084 row_type const r = row(idx);
1088 for (col_type c = col(idx) + 1; c < ncols(); ++c)
1089 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1092 splitCell(idx, pos);
1093 std::swap(cell(idx), cell(idx + ncols() - 1));
1096 pos = cell(idx).size();
1098 //mathcursor->normalize();
1099 return DispatchResult(true, FINISHED);
1102 case LFUN_TABULAR_FEATURE: {
1103 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1104 istringstream is(cmd.argument);
1107 if (s == "valign-top")
1109 else if (s == "valign-middle")
1111 else if (s == "valign-bottom")
1113 else if (s == "align-left")
1114 halign('l', col(idx));
1115 else if (s == "align-right")
1116 halign('r', col(idx));
1117 else if (s == "align-center")
1118 halign('c', col(idx));
1119 else if (s == "append-row")
1120 for (int i = 0, n = extractInt(is); i < n; ++i)
1122 else if (s == "delete-row")
1123 for (int i = 0, n = extractInt(is); i < n; ++i) {
1128 else if (s == "copy-row")
1129 for (int i = 0, n = extractInt(is); i < n; ++i)
1131 else if (s == "swap-row")
1133 else if (s == "append-column")
1134 for (int i = 0, n = extractInt(is); i < n; ++i) {
1135 row_type r = row(idx);
1136 col_type c = col(idx);
1140 else if (s == "delete-column")
1141 for (int i = 0, n = extractInt(is); i < n; ++i) {
1142 row_type r = row(idx);
1143 col_type c = col(idx);
1149 else if (s == "copy-column")
1151 else if (s == "swap-column")
1154 return DispatchResult(false);
1155 lyxerr << "returning DispatchResult(true, FINISHED)" << endl;
1156 return DispatchResult(true, FINISHED);
1160 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1161 MathGridInset grid(1, 1);
1162 mathed_parse_normal(grid, cmd.argument);
1163 if (grid.nargs() == 1) {
1164 // single cell/part of cell
1165 cell(idx).insert(pos, grid.cell(0));
1166 pos += grid.cell(0).size();
1169 col_type const numcols = min(grid.ncols(), ncols() - col(idx));
1170 row_type const numrows = min(grid.nrows(), nrows() - row(idx));
1171 for (row_type r = 0; r < numrows; ++r) {
1172 for (col_type c = 0; c < numcols; ++c) {
1173 idx_type i = index(r + row(idx), c + col(idx));
1174 cell(i).insert(0, grid.cell(grid.index(r, c)));
1176 // append the left over horizontal cells to the last column
1177 idx_type i = index(r + row(idx), ncols() - 1);
1178 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1179 cell(i).append(grid.cell(grid.index(r, c)));
1181 // append the left over vertical cells to the last _cell_
1182 idx_type i = nargs() - 1;
1183 for (row_type r = numrows; r < grid.nrows(); ++r)
1184 for (col_type c = 0; c < grid.ncols(); ++c)
1185 cell(i).append(grid.cell(grid.index(r, c)));
1187 return DispatchResult(true, FINISHED);
1191 return MathNestInset::priv_dispatch(cmd, idx, pos);