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"
19 #include "dispatchresult.h"
21 #include "funcrequest.h"
24 #include "frontends/Painter.h"
26 #include "support/std_sstream.h"
28 #include "insets/mailinset.h"
38 using std::istringstream;
39 using std::ostringstream;
43 class GridInsetMailer : public MailInset {
45 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
47 virtual string const & name() const
49 static string const theName = "tabular";
53 virtual string const inset2string(Buffer const &) const
56 //data << name() << " active_cell " << inset.getActCell() << '\n';
57 data << name() << " active_cell " << 0 << '\n';
64 InsetBase & inset() const { return inset_; }
65 MathGridInset & inset_;
69 void mathed_parse_normal(MathGridInset &, string const & argument);
73 string verboseHLine(int n)
76 for (int i = 0; i < n; ++i)
84 int extractInt(istream & is)
88 return (num == 0) ? 1 : num;
94 //////////////////////////////////////////////////////////////
97 MathGridInset::CellInfo::CellInfo()
104 //////////////////////////////////////////////////////////////
107 MathGridInset::RowInfo::RowInfo()
108 : lines_(0), skip_(0)
113 int MathGridInset::RowInfo::skipPixels() const
115 return crskip_.inBP();
120 //////////////////////////////////////////////////////////////
123 MathGridInset::ColInfo::ColInfo()
124 : align_('c'), leftline_(false), rightline_(false), lines_(0)
128 //////////////////////////////////////////////////////////////
131 MathGridInset::MathGridInset(char v, string const & h)
132 : MathNestInset(guessColumns(h)),
134 colinfo_(guessColumns(h) + 1),
135 cellinfo_(1 * guessColumns(h))
140 //lyxerr << "created grid with " << ncols() << " columns" << endl;
144 MathGridInset::MathGridInset()
155 MathGridInset::MathGridInset(col_type m, row_type n)
156 : MathNestInset(m * n),
166 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
167 : MathNestInset(m * n),
179 MathGridInset::~MathGridInset()
181 GridInsetMailer mailer(*this);
186 auto_ptr<InsetBase> MathGridInset::clone() const
188 return auto_ptr<InsetBase>(new MathGridInset(*this));
192 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
194 return col + ncols() * row;
198 void MathGridInset::setDefaults()
201 lyxerr << "positive number of columns expected" << endl;
203 // lyxerr << "positive number of rows expected" << endl;
204 for (col_type col = 0; col < ncols(); ++col) {
205 colinfo_[col].align_ = defaultColAlign(col);
206 colinfo_[col].skip_ = defaultColSpace(col);
211 void MathGridInset::halign(string const & hh)
214 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
219 colinfo_[col].lines_++;
220 } else if (c == 'c' || c == 'l' || c == 'r') {
221 colinfo_[col].align_ = c;
223 colinfo_[col].lines_ = 0;
225 lyxerr << "unknown column separator: '" << c << "'" << endl;
230 col_type n = hh.size();
233 for (col_type col = 0; col < n; ++col)
234 colinfo_[col].align_ = hh[col];
239 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
242 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
243 if (*it == 'c' || *it == 'l' || *it == 'r')
245 // let's have at least one column, even if we did not recognize its
253 void MathGridInset::halign(char h, col_type col)
255 colinfo_[col].align_ = h;
259 char MathGridInset::halign(col_type col) const
261 return colinfo_[col].align_;
265 string MathGridInset::halign() const
268 for (col_type col = 0; col < ncols(); ++col) {
269 res += string(colinfo_[col].lines_, '|');
270 res += colinfo_[col].align_;
272 return res + string(colinfo_[ncols()].lines_, '|');
276 void MathGridInset::valign(char c)
282 char MathGridInset::valign() const
288 MathGridInset::col_type MathGridInset::ncols() const
290 return colinfo_.size() - 1;
294 MathGridInset::row_type MathGridInset::nrows() const
296 return rowinfo_.size() - 1;
300 MathGridInset::col_type MathGridInset::col(idx_type idx) const
302 return idx % ncols();
306 MathGridInset::row_type MathGridInset::row(idx_type idx) const
308 return idx / ncols();
312 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
314 rowinfo_[row].crskip_ = crskip;
318 LyXLength MathGridInset::vcrskip(row_type row) const
320 return rowinfo_[row].crskip_;
324 void MathGridInset::metrics(MetricsInfo & mi) const
326 // let the cells adjust themselves
327 MathNestInset::metrics(mi);
329 // compute absolute sizes of vertical structure
330 for (row_type row = 0; row < nrows(); ++row) {
333 for (col_type col = 0; col < ncols(); ++col) {
334 MathArray const & c = cell(index(row, col));
335 asc = max(asc, c.ascent());
336 desc = max(desc, c.descent());
338 rowinfo_[row].ascent_ = asc;
339 rowinfo_[row].descent_ = desc;
341 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
342 rowinfo_[nrows()].ascent_ = 0;
343 rowinfo_[nrows()].descent_ = 0;
345 // compute vertical offsets
346 rowinfo_[0].offset_ = 0;
347 for (row_type row = 1; row <= nrows(); ++row) {
348 rowinfo_[row].offset_ =
349 rowinfo_[row - 1].offset_ +
350 rowinfo_[row - 1].descent_ +
351 rowinfo_[row - 1].skipPixels() +
353 rowinfo_[row].lines_ * hlinesep() +
354 rowinfo_[row].ascent_;
357 // adjust vertical offset
364 h = rowinfo_[nrows() - 1].offset_;
367 h = rowinfo_[nrows() - 1].offset_ / 2;
369 for (row_type row = 0; row <= nrows(); ++row)
370 rowinfo_[row].offset_ -= h;
373 // compute absolute sizes of horizontal structure
374 for (col_type col = 0; col < ncols(); ++col) {
376 for (row_type row = 0; row < nrows(); ++row)
377 wid = max(wid, cell(index(row, col)).width());
378 colinfo_[col].width_ = wid;
380 colinfo_[ncols()].width_ = 0;
382 // compute horizontal offsets
383 colinfo_[0].offset_ = border();
384 for (col_type col = 1; col <= ncols(); ++col) {
385 colinfo_[col].offset_ =
386 colinfo_[col - 1].offset_ +
387 colinfo_[col - 1].width_ +
388 colinfo_[col - 1].skip_ +
390 colinfo_[col].lines_ * vlinesep();
394 dim_.wid = colinfo_[ncols() - 1].offset_
395 + colinfo_[ncols() - 1].width_
396 + vlinesep() * colinfo_[ncols()].lines_
399 dim_.asc = - rowinfo_[0].offset_
400 + rowinfo_[0].ascent_
401 + hlinesep() * rowinfo_[0].lines_
404 dim_.des = rowinfo_[nrows() - 1].offset_
405 + rowinfo_[nrows() - 1].descent_
406 + hlinesep() * rowinfo_[nrows()].lines_
411 // Increase ws_[i] for 'R' columns (except the first one)
412 for (int i = 1; i < nc_; ++i)
413 if (align_[i] == 'R')
414 ws_[i] += 10 * df_width;
415 // Increase ws_[i] for 'C' column
416 if (align_[0] == 'C')
417 if (ws_[0] < 7 * workwidth / 8)
418 ws_[0] = 7 * workwidth / 8;
422 for (cxrow = row_.begin(); cxrow; ++cxrow) {
425 for (int i = 0; i < nc_; ++i) {
427 if (cxrow->getTab(i) <= 0) {
428 cxrow->setTab(i, df_width);
436 lf = (ws_[i] - cxrow->getTab(i))/2;
440 lf = ws_[i] - cxrow->getTab(i);
443 if (cxrow == row_.begin())
445 else if (cxrow.is_last())
446 lf = ws_[i] - cxrow->getTab(i);
448 lf = (ws_[i] - cxrow->getTab(i))/2;
451 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
452 cxrow->setTab(i, lf + rg);
453 rg = ws_[i] - ww + colsep();
454 if (cxrow == row_.begin())
455 width += ws_[i] + colsep();
457 cxrow->setBaseline(cxrow->getBaseline() - ascent);
463 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
470 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
472 for (idx_type idx = 0; idx < nargs(); ++idx)
473 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
475 for (row_type row = 0; row <= nrows(); ++row)
476 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
477 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
478 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
479 pi.pain.line(x + 1, yy,
480 x + dim_.width() - 1, yy,
484 for (col_type col = 0; col <= ncols(); ++col)
485 for (int i = 0; i < colinfo_[col].lines_; ++i) {
486 int xx = x + colinfo_[col].offset_
487 - i * vlinesep() - vlinesep()/2 - colsep()/2;
488 pi.pain.line(xx, y - dim_.ascent() + 1,
489 xx, y + dim_.descent() - 1,
495 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
497 // let the cells adjust themselves
498 //MathNestInset::metrics(mi);
499 for (idx_type i = 0; i < nargs(); ++i)
500 cell(i).metricsT(mi, dim);
502 // compute absolute sizes of vertical structure
503 for (row_type row = 0; row < nrows(); ++row) {
506 for (col_type col = 0; col < ncols(); ++col) {
507 MathArray const & c = cell(index(row, col));
508 asc = max(asc, c.ascent());
509 desc = max(desc, c.descent());
511 rowinfo_[row].ascent_ = asc;
512 rowinfo_[row].descent_ = desc;
514 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
515 rowinfo_[nrows()].ascent_ = 0;
516 rowinfo_[nrows()].descent_ = 0;
518 // compute vertical offsets
519 rowinfo_[0].offset_ = 0;
520 for (row_type row = 1; row <= nrows(); ++row) {
521 rowinfo_[row].offset_ =
522 rowinfo_[row - 1].offset_ +
523 rowinfo_[row - 1].descent_ +
524 //rowinfo_[row - 1].skipPixels() +
526 //rowinfo_[row].lines_ * hlinesep() +
527 rowinfo_[row].ascent_;
530 // adjust vertical offset
537 h = rowinfo_[nrows() - 1].offset_;
540 h = rowinfo_[nrows() - 1].offset_ / 2;
542 for (row_type row = 0; row <= nrows(); ++row)
543 rowinfo_[row].offset_ -= h;
546 // compute absolute sizes of horizontal structure
547 for (col_type col = 0; col < ncols(); ++col) {
549 for (row_type row = 0; row < nrows(); ++row)
550 wid = max(wid, cell(index(row, col)).width());
551 colinfo_[col].width_ = wid;
553 colinfo_[ncols()].width_ = 0;
555 // compute horizontal offsets
556 colinfo_[0].offset_ = border();
557 for (col_type col = 1; col <= ncols(); ++col) {
558 colinfo_[col].offset_ =
559 colinfo_[col - 1].offset_ +
560 colinfo_[col - 1].width_ +
561 colinfo_[col - 1].skip_ +
563 //colinfo_[col].lines_ * vlinesep();
567 dim.wid = colinfo_[ncols() - 1].offset_
568 + colinfo_[ncols() - 1].width_
569 //+ vlinesep() * colinfo_[ncols()].lines_
572 dim.asc = -rowinfo_[0].offset_
573 + rowinfo_[0].ascent_
574 //+ hlinesep() * rowinfo_[0].lines_
577 dim.des = rowinfo_[nrows() - 1].offset_
578 + rowinfo_[nrows() - 1].descent_
579 //+ hlinesep() * rowinfo_[nrows()].lines_
584 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
586 for (idx_type idx = 0; idx < nargs(); ++idx)
587 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
591 string MathGridInset::eolString(row_type row, bool fragile) const
595 if (!rowinfo_[row].crskip_.zero())
596 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
598 // make sure an upcoming '[' does not break anything
599 if (row + 1 < nrows()) {
600 MathArray const & c = cell(index(row + 1, 0));
601 if (c.size() && c.front()->getChar() == '[')
606 // only add \\ if necessary
607 if (eol.empty() && row + 1 == nrows())
610 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
614 string MathGridInset::eocString(col_type col, col_type lastcol) const
616 if (col + 1 == lastcol)
622 void MathGridInset::addRow(row_type row)
624 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
626 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
628 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
632 void MathGridInset::appendRow()
634 rowinfo_.push_back(RowInfo());
635 //cells_.insert(cells_.end(), ncols(), MathArray());
636 for (col_type col = 0; col < ncols(); ++col) {
637 cells_.push_back(cells_type::value_type());
638 cellinfo_.push_back(CellInfo());
643 void MathGridInset::delRow(row_type row)
648 cells_type::iterator it = cells_.begin() + row * ncols();
649 cells_.erase(it, it + ncols());
651 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
652 cellinfo_.erase(jt, jt + ncols());
654 rowinfo_.erase(rowinfo_.begin() + row);
658 void MathGridInset::copyRow(row_type row)
661 for (col_type col = 0; col < ncols(); ++col)
662 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
666 void MathGridInset::swapRow(row_type row)
670 if (row + 1 == nrows())
672 for (col_type col = 0; col < ncols(); ++col)
673 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
677 void MathGridInset::addCol(col_type newcol)
679 const col_type nc = ncols();
680 const row_type nr = nrows();
681 cells_type new_cells((nc + 1) * nr);
682 vector<CellInfo> new_cellinfo((nc + 1) * nr);
684 for (row_type row = 0; row < nr; ++row)
685 for (col_type col = 0; col < nc; ++col) {
686 new_cells[row * (nc + 1) + col + (col > newcol)]
687 = cells_[row * nc + col];
688 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
689 = cellinfo_[row * nc + col];
691 swap(cells_, new_cells);
692 swap(cellinfo_, new_cellinfo);
695 inf.skip_ = defaultColSpace(newcol);
696 inf.align_ = defaultColAlign(newcol);
697 colinfo_.insert(colinfo_.begin() + newcol, inf);
701 void MathGridInset::delCol(col_type col)
707 vector<CellInfo> tmpcellinfo;
708 for (col_type i = 0; i < nargs(); ++i)
709 if (i % ncols() != col) {
710 tmpcells.push_back(cells_[i]);
711 tmpcellinfo.push_back(cellinfo_[i]);
713 swap(cells_, tmpcells);
714 swap(cellinfo_, tmpcellinfo);
716 colinfo_.erase(colinfo_.begin() + col);
720 void MathGridInset::copyCol(col_type col)
723 for (row_type row = 0; row < nrows(); ++row)
724 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
728 void MathGridInset::swapCol(col_type col)
732 if (col + 1 == ncols())
734 for (row_type row = 0; row < nrows(); ++row)
735 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
739 int MathGridInset::cellXOffset(idx_type idx) const
741 col_type c = col(idx);
742 int x = colinfo_[c].offset_;
743 char align = colinfo_[c].align_;
744 if (align == 'r' || align == 'R')
745 x += colinfo_[c].width_ - cell(idx).width();
746 if (align == 'c' || align == 'C')
747 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
752 int MathGridInset::cellYOffset(idx_type idx) const
754 return rowinfo_[row(idx)].offset_;
758 bool MathGridInset::idxUpDown(LCursor & cur, bool up) const
761 if (cur.idx() < ncols())
763 cur.idx() -= ncols();
765 if (cur.idx() >= ncols() * (nrows() - 1))
767 cur.idx() += ncols();
769 cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo());
774 bool MathGridInset::idxLeft(LCursor & cur) const
776 // leave matrix if on the left hand edge
780 cur.pos() = cur.lastpos();
785 bool MathGridInset::idxRight(LCursor & cur) const
787 // leave matrix if on the right hand edge
788 if (cur.col() + 1 == ncols())
796 bool MathGridInset::idxFirst(LCursor & cur) const
803 cur.idx() = (nrows() - 1) * ncols();
806 cur.idx() = ((nrows() - 1) / 2) * ncols();
813 bool MathGridInset::idxLast(LCursor & cur) const
817 cur.idx() = ncols() - 1;
820 cur.idx() = nargs() - 1;
823 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
825 cur.pos() = cur.lastpos();
830 bool MathGridInset::idxHome(LCursor & cur) const
837 cur.idx() -= cur.idx() % ncols();
850 bool MathGridInset::idxEnd(LCursor & cur) const
852 if (cur.pos() < cur.lastpos()) {
853 cur.pos() = cur.lastpos();
856 if (cur.col() < ncols() - 1) {
857 cur.idx() = cur.idx() - cur.idx() % ncols() + ncols() - 1;
858 cur.pos() = cur.lastpos();
861 if (cur.idx() < nargs() - 1) {
862 cur.idx() = nargs() - 1;
863 cur.pos() = cur.lastpos();
870 bool MathGridInset::idxDelete(idx_type & idx)
872 // nothing to do if we have just one row
876 // nothing to do if we are in the middle of the last row of the inset
877 if (idx + ncols() > nargs())
880 // try to delete entire sequence of ncols() empty cells if possible
881 for (idx_type i = idx; i < idx + ncols(); ++i)
885 // move cells if necessary
886 for (idx_type i = index(row(idx), 0); i < idx; ++i)
887 swap(cell(i), cell(i + ncols()));
894 // undo effect of Ctrl-Tab (i.e. pull next cell)
895 //if (idx + 1 != nargs())
896 // cell(idx).swap(cell(idx + 1));
898 // we handled the event..
903 // reimplement old behaviour when pressing Delete in the last position
905 void MathGridInset::idxGlue(idx_type idx)
907 col_type c = col(idx);
908 if (c + 1 == ncols()) {
909 if (row(idx) + 1 != nrows()) {
910 for (col_type cc = 0; cc < ncols(); ++cc)
911 cell(idx).append(cell(idx + cc + 1));
912 delRow(row(idx) + 1);
915 cell(idx).append(cell(idx + 1));
916 for (col_type cc = c + 2; cc < ncols(); ++cc)
917 cell(idx - c + cc - 1) = cell(idx - c + cc);
918 cell(idx - c + ncols() - 1).clear();
923 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
925 return rowinfo_[row];
929 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
931 return rowinfo_[row];
935 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
937 row_type const ri = row(idx);
938 row_type const r1 = min(row(from), row(to));
939 row_type const r2 = max(row(from), row(to));
940 col_type const ci = col(idx);
941 col_type const c1 = min(col(from), col(to));
942 col_type const c2 = max(col(from), col(to));
943 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
948 void MathGridInset::normalize(NormalStream & os) const
951 for (row_type row = 0; row < nrows(); ++row) {
953 for (col_type col = 0; col < ncols(); ++col)
954 os << "[cell " << cell(index(row, col)) << ']';
961 void MathGridInset::mathmlize(MathMLStream & os) const
963 os << MTag("mtable");
964 for (row_type row = 0; row < nrows(); ++row) {
966 for (col_type col = 0; col < ncols(); ++col)
967 os << cell(index(row, col));
970 os << ETag("mtable");
974 void MathGridInset::write(WriteStream & os) const
976 for (row_type row = 0; row < nrows(); ++row) {
977 os << verboseHLine(rowinfo_[row].lines_);
978 // don't write & and empty cells at end of line
979 col_type lastcol = 0;
980 bool emptyline = true;
981 for (col_type col = 0; col < ncols(); ++col)
982 if (!cell(index(row, col)).empty()) {
986 for (col_type col = 0; col < lastcol; ++col)
987 os << cell(index(row, col)) << eocString(col, lastcol);
988 os << eolString(row, os.fragile());
989 // append newline only if line wasn't completely empty
990 // and this was not the last line in the grid
991 if (!emptyline && row + 1 < nrows())
994 string const s = verboseHLine(rowinfo_[nrows()].lines_);
995 if (!s.empty() && s != " ") {
1003 int MathGridInset::colsep() const
1009 int MathGridInset::rowsep() const
1015 int MathGridInset::hlinesep() const
1021 int MathGridInset::vlinesep() const
1027 int MathGridInset::border() const
1033 void MathGridInset::splitCell(LCursor & cur)
1035 if (cur.idx() + 1 == nargs())
1037 MathArray ar = cur.cell();
1038 ar.erase(0, cur.pos());
1039 cur.cell().erase(cur.pos(), cur.lastpos());
1042 cur.cell().insert(0, ar);
1047 MathGridInset::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
1049 lyxerr << "*** MathGridInset: request: " << cmd << endl;
1050 switch (cmd.action) {
1052 case LFUN_MOUSE_RELEASE:
1053 //if (cmd.button() == mouse_button::button3) {
1054 // GridInsetMailer(*this).showDialog();
1055 // return DispatchResult(true, true);
1057 return DispatchResult(false);
1059 case LFUN_INSET_DIALOG_UPDATE:
1060 GridInsetMailer(*this).updateDialog(&cur.bv());
1061 return DispatchResult(false);
1063 // insert file functions
1064 case LFUN_DELETE_LINE_FORWARD:
1065 //autocorrect_ = false;
1073 if (cur.idx() >= nargs())
1074 cur.idx() = nargs() - 1;
1075 if (cur.pos() > cur.lastpos())
1076 cur.pos() = cur.lastpos();
1077 return DispatchResult(true, FINISHED);
1079 case LFUN_CELL_SPLIT:
1080 ////recordUndo(cur, Undo::ATOMIC);
1082 return DispatchResult(true, FINISHED);
1084 case LFUN_BREAKLINE: {
1085 ////recordUndo(cur, Undo::INSERT);
1086 row_type const r = cur.row();
1090 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1091 swap(cell(index(r, c)), cell(index(r + 1, c)));
1095 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1098 cur.idx() = cur.lastpos();
1100 //mathcursor->normalize();
1101 return DispatchResult(true, 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 return DispatchResult(false);
1157 lyxerr << "returning DispatchResult(true, FINISHED)" << endl;
1158 return DispatchResult(true, FINISHED);
1162 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1163 MathGridInset grid(1, 1);
1164 mathed_parse_normal(grid, cmd.argument);
1165 if (grid.nargs() == 1) {
1166 // single cell/part of cell
1167 cur.cell().insert(cur.pos(), grid.cell(0));
1168 cur.pos() += grid.cell(0).size();
1171 col_type const numcols = min(grid.ncols(), ncols() -
1173 row_type const numrows = min(grid.nrows(), nrows() -
1175 for (row_type r = 0; r < numrows; ++r) {
1176 for (col_type c = 0; c < numcols; ++c) {
1177 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1178 cell(i).insert(0, grid.cell(grid.index(r, c)));
1180 // append the left over horizontal cells to the last column
1181 idx_type i = index(r + cur.row(), ncols() - 1);
1182 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1183 cell(i).append(grid.cell(grid.index(r, c)));
1185 // append the left over vertical cells to the last _cell_
1186 idx_type i = nargs() - 1;
1187 for (row_type r = numrows; r < grid.nrows(); ++r)
1188 for (col_type c = 0; c < grid.ncols(); ++c)
1189 cell(i).append(grid.cell(grid.index(r, c)));
1191 return DispatchResult(true, FINISHED);
1195 return MathNestInset::priv_dispatch(cur, cmd);