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 "BufferView.h"
20 #include "funcrequest.h"
23 #include "frontends/Painter.h"
25 #include "support/std_sstream.h"
27 #include "insets/mailinset.h"
37 using std::istringstream;
38 using std::ostringstream;
42 class GridInsetMailer : public MailInset {
44 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
46 virtual string const & name() const
48 static string const theName = "tabular";
52 virtual string const inset2string(Buffer const &) const
55 //data << name() << " active_cell " << inset.getActCell() << '\n';
56 data << name() << " active_cell " << 0 << '\n';
63 InsetBase & inset() const { return inset_; }
64 MathGridInset & inset_;
68 void mathed_parse_normal(MathGridInset &, string const & argument);
72 string verboseHLine(int n)
75 for (int i = 0; i < n; ++i)
83 int extractInt(istream & is)
87 return (num == 0) ? 1 : num;
93 //////////////////////////////////////////////////////////////
96 MathGridInset::CellInfo::CellInfo()
103 //////////////////////////////////////////////////////////////
106 MathGridInset::RowInfo::RowInfo()
107 : lines_(0), skip_(0)
112 int MathGridInset::RowInfo::skipPixels() const
114 return crskip_.inBP();
119 //////////////////////////////////////////////////////////////
122 MathGridInset::ColInfo::ColInfo()
123 : align_('c'), leftline_(false), rightline_(false), lines_(0)
127 //////////////////////////////////////////////////////////////
130 MathGridInset::MathGridInset(char v, string const & h)
131 : MathNestInset(guessColumns(h)),
133 colinfo_(guessColumns(h) + 1),
134 cellinfo_(1 * guessColumns(h))
139 //lyxerr << "created grid with " << ncols() << " columns" << endl;
143 MathGridInset::MathGridInset()
154 MathGridInset::MathGridInset(col_type m, row_type n)
155 : MathNestInset(m * n),
165 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
166 : MathNestInset(m * n),
178 MathGridInset::~MathGridInset()
180 GridInsetMailer mailer(*this);
185 auto_ptr<InsetBase> MathGridInset::clone() const
187 return auto_ptr<InsetBase>(new MathGridInset(*this));
191 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
193 return col + ncols() * row;
197 void MathGridInset::setDefaults()
200 lyxerr << "positive number of columns expected" << endl;
202 // lyxerr << "positive number of rows expected" << endl;
203 for (col_type col = 0; col < ncols(); ++col) {
204 colinfo_[col].align_ = defaultColAlign(col);
205 colinfo_[col].skip_ = defaultColSpace(col);
210 void MathGridInset::halign(string const & hh)
213 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
218 colinfo_[col].lines_++;
219 } else if (c == 'c' || c == 'l' || c == 'r') {
220 colinfo_[col].align_ = c;
222 colinfo_[col].lines_ = 0;
224 lyxerr << "unknown column separator: '" << c << "'" << endl;
229 col_type n = hh.size();
232 for (col_type col = 0; col < n; ++col)
233 colinfo_[col].align_ = hh[col];
238 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
241 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
242 if (*it == 'c' || *it == 'l' || *it == 'r')
244 // let's have at least one column, even if we did not recognize its
252 void MathGridInset::halign(char h, col_type col)
254 colinfo_[col].align_ = h;
258 char MathGridInset::halign(col_type col) const
260 return colinfo_[col].align_;
264 string MathGridInset::halign() const
267 for (col_type col = 0; col < ncols(); ++col) {
268 res += string(colinfo_[col].lines_, '|');
269 res += colinfo_[col].align_;
271 return res + string(colinfo_[ncols()].lines_, '|');
275 void MathGridInset::valign(char c)
281 char MathGridInset::valign() const
287 MathGridInset::col_type MathGridInset::ncols() const
289 return colinfo_.size() - 1;
293 MathGridInset::row_type MathGridInset::nrows() const
295 return rowinfo_.size() - 1;
299 MathGridInset::col_type MathGridInset::col(idx_type idx) const
301 return idx % ncols();
305 MathGridInset::row_type MathGridInset::row(idx_type idx) const
307 return idx / ncols();
311 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
313 rowinfo_[row].crskip_ = crskip;
317 LyXLength MathGridInset::vcrskip(row_type row) const
319 return rowinfo_[row].crskip_;
323 void MathGridInset::metrics(MetricsInfo & mi) const
325 // let the cells adjust themselves
326 MathNestInset::metrics(mi);
328 // compute absolute sizes of vertical structure
329 for (row_type row = 0; row < nrows(); ++row) {
332 for (col_type col = 0; col < ncols(); ++col) {
333 MathArray const & c = cell(index(row, col));
334 asc = max(asc, c.ascent());
335 desc = max(desc, c.descent());
337 rowinfo_[row].ascent_ = asc;
338 rowinfo_[row].descent_ = desc;
340 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
341 rowinfo_[nrows()].ascent_ = 0;
342 rowinfo_[nrows()].descent_ = 0;
344 // compute vertical offsets
345 rowinfo_[0].offset_ = 0;
346 for (row_type row = 1; row <= nrows(); ++row) {
347 rowinfo_[row].offset_ =
348 rowinfo_[row - 1].offset_ +
349 rowinfo_[row - 1].descent_ +
350 rowinfo_[row - 1].skipPixels() +
352 rowinfo_[row].lines_ * hlinesep() +
353 rowinfo_[row].ascent_;
356 // adjust vertical offset
363 h = rowinfo_[nrows() - 1].offset_;
366 h = rowinfo_[nrows() - 1].offset_ / 2;
368 for (row_type row = 0; row <= nrows(); ++row)
369 rowinfo_[row].offset_ -= h;
372 // compute absolute sizes of horizontal structure
373 for (col_type col = 0; col < ncols(); ++col) {
375 for (row_type row = 0; row < nrows(); ++row)
376 wid = max(wid, cell(index(row, col)).width());
377 colinfo_[col].width_ = wid;
379 colinfo_[ncols()].width_ = 0;
381 // compute horizontal offsets
382 colinfo_[0].offset_ = border();
383 for (col_type col = 1; col <= ncols(); ++col) {
384 colinfo_[col].offset_ =
385 colinfo_[col - 1].offset_ +
386 colinfo_[col - 1].width_ +
387 colinfo_[col - 1].skip_ +
389 colinfo_[col].lines_ * vlinesep();
393 dim_.wid = colinfo_[ncols() - 1].offset_
394 + colinfo_[ncols() - 1].width_
395 + vlinesep() * colinfo_[ncols()].lines_
398 dim_.asc = - rowinfo_[0].offset_
399 + rowinfo_[0].ascent_
400 + hlinesep() * rowinfo_[0].lines_
403 dim_.des = rowinfo_[nrows() - 1].offset_
404 + rowinfo_[nrows() - 1].descent_
405 + hlinesep() * rowinfo_[nrows()].lines_
410 // Increase ws_[i] for 'R' columns (except the first one)
411 for (int i = 1; i < nc_; ++i)
412 if (align_[i] == 'R')
413 ws_[i] += 10 * df_width;
414 // Increase ws_[i] for 'C' column
415 if (align_[0] == 'C')
416 if (ws_[0] < 7 * workwidth / 8)
417 ws_[0] = 7 * workwidth / 8;
421 for (cxrow = row_.begin(); cxrow; ++cxrow) {
424 for (int i = 0; i < nc_; ++i) {
426 if (cxrow->getTab(i) <= 0) {
427 cxrow->setTab(i, df_width);
435 lf = (ws_[i] - cxrow->getTab(i))/2;
439 lf = ws_[i] - cxrow->getTab(i);
442 if (cxrow == row_.begin())
444 else if (cxrow.is_last())
445 lf = ws_[i] - cxrow->getTab(i);
447 lf = (ws_[i] - cxrow->getTab(i))/2;
450 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
451 cxrow->setTab(i, lf + rg);
452 rg = ws_[i] - ww + colsep();
453 if (cxrow == row_.begin())
454 width += ws_[i] + colsep();
456 cxrow->setBaseline(cxrow->getBaseline() - ascent);
462 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
469 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
471 for (idx_type idx = 0; idx < nargs(); ++idx)
472 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
474 for (row_type row = 0; row <= nrows(); ++row)
475 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
476 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
477 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
478 pi.pain.line(x + 1, yy,
479 x + dim_.width() - 1, yy,
483 for (col_type col = 0; col <= ncols(); ++col)
484 for (int i = 0; i < colinfo_[col].lines_; ++i) {
485 int xx = x + colinfo_[col].offset_
486 - i * vlinesep() - vlinesep()/2 - colsep()/2;
487 pi.pain.line(xx, y - dim_.ascent() + 1,
488 xx, y + dim_.descent() - 1,
494 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
496 // let the cells adjust themselves
497 //MathNestInset::metrics(mi);
498 for (idx_type i = 0; i < nargs(); ++i)
499 cell(i).metricsT(mi, dim);
501 // compute absolute sizes of vertical structure
502 for (row_type row = 0; row < nrows(); ++row) {
505 for (col_type col = 0; col < ncols(); ++col) {
506 MathArray const & c = cell(index(row, col));
507 asc = max(asc, c.ascent());
508 desc = max(desc, c.descent());
510 rowinfo_[row].ascent_ = asc;
511 rowinfo_[row].descent_ = desc;
513 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
514 rowinfo_[nrows()].ascent_ = 0;
515 rowinfo_[nrows()].descent_ = 0;
517 // compute vertical offsets
518 rowinfo_[0].offset_ = 0;
519 for (row_type row = 1; row <= nrows(); ++row) {
520 rowinfo_[row].offset_ =
521 rowinfo_[row - 1].offset_ +
522 rowinfo_[row - 1].descent_ +
523 //rowinfo_[row - 1].skipPixels() +
525 //rowinfo_[row].lines_ * hlinesep() +
526 rowinfo_[row].ascent_;
529 // adjust vertical offset
536 h = rowinfo_[nrows() - 1].offset_;
539 h = rowinfo_[nrows() - 1].offset_ / 2;
541 for (row_type row = 0; row <= nrows(); ++row)
542 rowinfo_[row].offset_ -= h;
545 // compute absolute sizes of horizontal structure
546 for (col_type col = 0; col < ncols(); ++col) {
548 for (row_type row = 0; row < nrows(); ++row)
549 wid = max(wid, cell(index(row, col)).width());
550 colinfo_[col].width_ = wid;
552 colinfo_[ncols()].width_ = 0;
554 // compute horizontal offsets
555 colinfo_[0].offset_ = border();
556 for (col_type col = 1; col <= ncols(); ++col) {
557 colinfo_[col].offset_ =
558 colinfo_[col - 1].offset_ +
559 colinfo_[col - 1].width_ +
560 colinfo_[col - 1].skip_ +
562 //colinfo_[col].lines_ * vlinesep();
566 dim.wid = colinfo_[ncols() - 1].offset_
567 + colinfo_[ncols() - 1].width_
568 //+ vlinesep() * colinfo_[ncols()].lines_
571 dim.asc = -rowinfo_[0].offset_
572 + rowinfo_[0].ascent_
573 //+ hlinesep() * rowinfo_[0].lines_
576 dim.des = rowinfo_[nrows() - 1].offset_
577 + rowinfo_[nrows() - 1].descent_
578 //+ hlinesep() * rowinfo_[nrows()].lines_
583 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
585 for (idx_type idx = 0; idx < nargs(); ++idx)
586 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
590 string MathGridInset::eolString(row_type row, bool fragile) const
594 if (!rowinfo_[row].crskip_.zero())
595 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
597 // make sure an upcoming '[' does not break anything
598 if (row + 1 < nrows()) {
599 MathArray const & c = cell(index(row + 1, 0));
600 if (c.size() && c.front()->getChar() == '[')
605 // only add \\ if necessary
606 if (eol.empty() && row + 1 == nrows())
609 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
613 string MathGridInset::eocString(col_type col, col_type lastcol) const
615 if (col + 1 == lastcol)
621 void MathGridInset::addRow(row_type row)
623 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
625 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
627 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
631 void MathGridInset::appendRow()
633 rowinfo_.push_back(RowInfo());
634 //cells_.insert(cells_.end(), ncols(), MathArray());
635 for (col_type col = 0; col < ncols(); ++col) {
636 cells_.push_back(cells_type::value_type());
637 cellinfo_.push_back(CellInfo());
642 void MathGridInset::delRow(row_type row)
647 cells_type::iterator it = cells_.begin() + row * ncols();
648 cells_.erase(it, it + ncols());
650 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
651 cellinfo_.erase(jt, jt + ncols());
653 rowinfo_.erase(rowinfo_.begin() + row);
657 void MathGridInset::copyRow(row_type row)
660 for (col_type col = 0; col < ncols(); ++col)
661 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
665 void MathGridInset::swapRow(row_type row)
669 if (row + 1 == nrows())
671 for (col_type col = 0; col < ncols(); ++col)
672 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
676 void MathGridInset::addCol(col_type newcol)
678 const col_type nc = ncols();
679 const row_type nr = nrows();
680 cells_type new_cells((nc + 1) * nr);
681 vector<CellInfo> new_cellinfo((nc + 1) * nr);
683 for (row_type row = 0; row < nr; ++row)
684 for (col_type col = 0; col < nc; ++col) {
685 new_cells[row * (nc + 1) + col + (col > newcol)]
686 = cells_[row * nc + col];
687 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
688 = cellinfo_[row * nc + col];
690 swap(cells_, new_cells);
691 swap(cellinfo_, new_cellinfo);
694 inf.skip_ = defaultColSpace(newcol);
695 inf.align_ = defaultColAlign(newcol);
696 colinfo_.insert(colinfo_.begin() + newcol, inf);
700 void MathGridInset::delCol(col_type col)
706 vector<CellInfo> tmpcellinfo;
707 for (col_type i = 0; i < nargs(); ++i)
708 if (i % ncols() != col) {
709 tmpcells.push_back(cells_[i]);
710 tmpcellinfo.push_back(cellinfo_[i]);
712 swap(cells_, tmpcells);
713 swap(cellinfo_, tmpcellinfo);
715 colinfo_.erase(colinfo_.begin() + col);
719 void MathGridInset::copyCol(col_type col)
722 for (row_type row = 0; row < nrows(); ++row)
723 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
727 void MathGridInset::swapCol(col_type col)
731 if (col + 1 == ncols())
733 for (row_type row = 0; row < nrows(); ++row)
734 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
738 int MathGridInset::cellXOffset(idx_type idx) const
740 col_type c = col(idx);
741 int x = colinfo_[c].offset_;
742 char align = colinfo_[c].align_;
743 if (align == 'r' || align == 'R')
744 x += colinfo_[c].width_ - cell(idx).width();
745 if (align == 'c' || align == 'C')
746 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
751 int MathGridInset::cellYOffset(idx_type idx) const
753 return rowinfo_[row(idx)].offset_;
757 bool MathGridInset::idxUpDown(LCursor & cur, bool up) const
760 if (cur.idx() < ncols())
762 cur.idx() -= ncols();
764 if (cur.idx() >= ncols() * (nrows() - 1))
766 cur.idx() += ncols();
768 cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo());
773 bool MathGridInset::idxLeft(LCursor & cur) const
775 // leave matrix if on the left hand edge
779 cur.pos() = cur.lastpos();
784 bool MathGridInset::idxRight(LCursor & cur) const
786 // leave matrix if on the right hand edge
787 if (cur.col() + 1 == ncols())
795 bool MathGridInset::idxFirst(LCursor & cur) const
802 cur.idx() = (nrows() - 1) * ncols();
805 cur.idx() = ((nrows() - 1) / 2) * ncols();
812 bool MathGridInset::idxLast(LCursor & cur) const
816 cur.idx() = ncols() - 1;
819 cur.idx() = nargs() - 1;
822 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
824 cur.pos() = cur.lastpos();
829 bool MathGridInset::idxHome(LCursor & cur) const
836 cur.idx() -= cur.idx() % ncols();
849 bool MathGridInset::idxEnd(LCursor & cur) const
851 if (cur.pos() < cur.lastpos()) {
852 cur.pos() = cur.lastpos();
855 if (cur.col() < ncols() - 1) {
856 cur.idx() = cur.idx() - cur.idx() % ncols() + ncols() - 1;
857 cur.pos() = cur.lastpos();
860 if (cur.idx() < nargs() - 1) {
861 cur.idx() = nargs() - 1;
862 cur.pos() = cur.lastpos();
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 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(LCursor & cur)
1034 if (cur.idx() + 1 == nargs())
1036 MathArray ar = cur.cell();
1037 ar.erase(0, cur.pos());
1038 cur.cell().erase(cur.pos(), cur.lastpos());
1041 cur.cell().insert(0, ar);
1045 void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
1047 //lyxerr << "*** MathGridInset: request: " << cmd << endl;
1048 switch (cmd.action) {
1050 case LFUN_MOUSE_RELEASE:
1051 //if (cmd.button() == mouse_button::button3) {
1052 // GridInsetMailer(*this).showDialog();
1053 // return DispatchResult(true, true);
1055 MathNestInset::priv_dispatch(cur, cmd);
1058 case LFUN_INSET_DIALOG_UPDATE:
1059 GridInsetMailer(*this).updateDialog(&cur.bv());
1062 // insert file functions
1063 case LFUN_DELETE_LINE_FORWARD:
1064 //autocorrect_ = false;
1072 if (cur.idx() > cur.lastidx())
1073 cur.idx() = cur.lastidx();
1074 if (cur.pos() > cur.lastpos())
1075 cur.pos() = cur.lastpos();
1078 case LFUN_CELL_SPLIT:
1079 ////recordUndo(cur, Undo::ATOMIC);
1083 case LFUN_BREAKLINE: {
1084 ////recordUndo(cur, Undo::INSERT);
1085 row_type const r = cur.row();
1089 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1090 swap(cell(index(r, c)), cell(index(r + 1, c)));
1094 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1097 cur.idx() = cur.lastpos();
1099 //mathcursor->normalize();
1100 cur.dispatched(FINISHED);
1104 case LFUN_TABULAR_FEATURE: {
1105 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1106 istringstream is(cmd.argument);
1109 if (s == "valign-top")
1111 else if (s == "valign-middle")
1113 else if (s == "valign-bottom")
1115 else if (s == "align-left")
1116 halign('l', col(cur.idx()));
1117 else if (s == "align-right")
1118 halign('r', col(cur.idx()));
1119 else if (s == "align-center")
1120 halign('c', col(cur.idx()));
1121 else if (s == "append-row")
1122 for (int i = 0, n = extractInt(is); i < n; ++i)
1124 else if (s == "delete-row")
1125 for (int i = 0, n = extractInt(is); i < n; ++i) {
1127 if (cur.idx() > nargs())
1128 cur.idx() -= ncols();
1130 else if (s == "copy-row")
1131 for (int i = 0, n = extractInt(is); i < n; ++i)
1133 else if (s == "swap-row")
1135 else if (s == "append-column")
1136 for (int i = 0, n = extractInt(is); i < n; ++i) {
1137 row_type r = cur.row();
1138 col_type c = col(cur.idx());
1140 cur.idx() = index(r, c);
1142 else if (s == "delete-column")
1143 for (int i = 0, n = extractInt(is); i < n; ++i) {
1144 row_type r = cur.row();
1145 col_type c = col(cur.idx());
1146 delCol(col(cur.idx()));
1147 cur.idx() = index(r, c);
1148 if (cur.idx() > nargs())
1149 cur.idx() -= ncols();
1151 else if (s == "copy-column")
1152 copyCol(col(cur.idx()));
1153 else if (s == "swap-column")
1154 swapCol(col(cur.idx()));
1156 cur.notdispatched();
1159 lyxerr << "returning DispatchResult(true, FINISHED)" << endl;
1164 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1165 MathGridInset grid(1, 1);
1166 mathed_parse_normal(grid, cmd.argument);
1167 if (grid.nargs() == 1) {
1168 // single cell/part of cell
1169 cur.cell().insert(cur.pos(), grid.cell(0));
1170 cur.pos() += grid.cell(0).size();
1173 col_type const numcols =
1174 min(grid.ncols(), ncols() - col(cur.idx()));
1175 row_type const numrows =
1176 min(grid.nrows(), nrows() - cur.row());
1177 for (row_type r = 0; r < numrows; ++r) {
1178 for (col_type c = 0; c < numcols; ++c) {
1179 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1180 cell(i).insert(0, grid.cell(grid.index(r, c)));
1182 // append the left over horizontal cells to the last column
1183 idx_type i = index(r + cur.row(), ncols() - 1);
1184 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1185 cell(i).append(grid.cell(grid.index(r, c)));
1187 // append the left over vertical cells to the last _cell_
1188 idx_type i = nargs() - 1;
1189 for (row_type r = numrows; r < grid.nrows(); ++r)
1190 for (col_type c = 0; c < grid.ncols(); ++c)
1191 cell(i).append(grid.cell(grid.index(r, c)));
1197 MathNestInset::priv_dispatch(cur, cmd);