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(BufferView & bv, bool up, int targetx) const
756 CursorSlice & cur = cursorTip(bv);
758 if (cur.idx() < ncols())
760 cur.idx() -= ncols();
762 if (cur.idx() >= ncols() * (nrows() - 1))
764 cur.idx() += ncols();
766 cur.pos() = cur.cell().x2pos(targetx - cur.cell().xo());
771 bool MathGridInset::idxLeft(BufferView & bv) const
773 // leave matrix if on the left hand edge
774 CursorSlice & cur = cursorTip(bv);
778 cur.pos() = cur.lastpos();
783 bool MathGridInset::idxRight(BufferView & bv) const
785 // leave matrix if on the right hand edge
786 CursorSlice & cur = cursorTip(bv);
787 if (cur.col() + 1 == ncols())
795 bool MathGridInset::idxFirst(BufferView & bv) const
797 CursorSlice & cur = cursorTip(bv);
803 cur.idx() = (nrows() - 1) * ncols();
806 cur.idx() = ((nrows() - 1) / 2) * ncols();
813 bool MathGridInset::idxLast(BufferView & bv) const
815 CursorSlice & cur = cursorTip(bv);
818 cur.idx() = ncols() - 1;
821 cur.idx() = nargs() - 1;
824 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
826 cur.pos() = cur.lastpos();
831 bool MathGridInset::idxHome(BufferView & bv) const
833 CursorSlice & cur = cursorTip(bv);
839 cur.idx() -= cur.idx() % ncols();
852 bool MathGridInset::idxEnd(BufferView & bv) const
854 CursorSlice & cur = cursorTip(bv);
855 if (cur.pos() < cur.lastpos()) {
856 cur.pos() = cur.lastpos();
859 if (cur.col() < ncols() - 1) {
860 cur.idx() = cur.idx() - cur.idx() % ncols() + ncols() - 1;
861 cur.pos() = cur.lastpos();
864 if (cur.idx() < nargs() - 1) {
865 cur.idx() = nargs() - 1;
866 cur.pos() = cur.lastpos();
873 bool MathGridInset::idxDelete(idx_type & idx)
875 // nothing to do if we have just one row
879 // nothing to do if we are in the middle of the last row of the inset
880 if (idx + ncols() > nargs())
883 // try to delete entire sequence of ncols() empty cells if possible
884 for (idx_type i = idx; i < idx + ncols(); ++i)
888 // move cells if necessary
889 for (idx_type i = index(row(idx), 0); i < idx; ++i)
890 std::swap(cell(i), cell(i + ncols()));
897 // undo effect of Ctrl-Tab (i.e. pull next cell)
898 //if (idx + 1 != nargs())
899 // cell(idx).swap(cell(idx + 1));
901 // we handled the event..
906 // reimplement old behaviour when pressing Delete in the last position
908 void MathGridInset::idxGlue(idx_type idx)
910 col_type c = col(idx);
911 if (c + 1 == ncols()) {
912 if (row(idx) + 1 != nrows()) {
913 for (col_type cc = 0; cc < ncols(); ++cc)
914 cell(idx).append(cell(idx + cc + 1));
915 delRow(row(idx) + 1);
918 cell(idx).append(cell(idx + 1));
919 for (col_type cc = c + 2; cc < ncols(); ++cc)
920 cell(idx - c + cc - 1) = cell(idx - c + cc);
921 cell(idx - c + ncols() - 1).clear();
926 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
928 return rowinfo_[row];
932 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
934 return rowinfo_[row];
938 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
940 row_type const ri = row(idx);
941 row_type const r1 = min(row(from), row(to));
942 row_type const r2 = max(row(from), row(to));
943 col_type const ci = col(idx);
944 col_type const c1 = min(col(from), col(to));
945 col_type const c2 = max(col(from), col(to));
946 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
951 void MathGridInset::normalize(NormalStream & os) const
954 for (row_type row = 0; row < nrows(); ++row) {
956 for (col_type col = 0; col < ncols(); ++col)
957 os << "[cell " << cell(index(row, col)) << ']';
964 void MathGridInset::mathmlize(MathMLStream & os) const
966 os << MTag("mtable");
967 for (row_type row = 0; row < nrows(); ++row) {
969 for (col_type col = 0; col < ncols(); ++col)
970 os << cell(index(row, col));
973 os << ETag("mtable");
977 void MathGridInset::write(WriteStream & os) const
979 for (row_type row = 0; row < nrows(); ++row) {
980 os << verboseHLine(rowinfo_[row].lines_);
981 // don't write & and empty cells at end of line
982 col_type lastcol = 0;
983 bool emptyline = true;
984 for (col_type col = 0; col < ncols(); ++col)
985 if (!cell(index(row, col)).empty()) {
989 for (col_type col = 0; col < lastcol; ++col)
990 os << cell(index(row, col)) << eocString(col, lastcol);
991 os << eolString(row, os.fragile());
992 // append newline only if line wasn't completely empty
993 // and this was not the last line in the grid
994 if (!emptyline && row + 1 < nrows())
997 string const s = verboseHLine(rowinfo_[nrows()].lines_);
998 if (!s.empty() && s != " ") {
1006 int MathGridInset::colsep() const
1012 int MathGridInset::rowsep() const
1018 int MathGridInset::hlinesep() const
1024 int MathGridInset::vlinesep() const
1030 int MathGridInset::border() const
1036 void MathGridInset::splitCell(BufferView & bv)
1038 CursorSlice & cur = cursorTip(bv);
1039 if (cur.idx() + 1 == nargs())
1041 MathArray ar = cur.cell();
1042 ar.erase(0, cur.pos());
1043 cur.cell().erase(cur.pos(), cur.lastpos());
1046 cur.cell().insert(0, ar);
1051 MathGridInset::priv_dispatch(BufferView & bv, FuncRequest const & cmd)
1053 CursorSlice & cur = cursorTip(bv);
1054 switch (cmd.action) {
1056 case LFUN_MOUSE_RELEASE:
1057 //if (cmd.button() == mouse_button::button3) {
1058 // GridInsetMailer(*this).showDialog();
1059 // return DispatchResult(true, true);
1061 return DispatchResult(false);
1063 case LFUN_INSET_DIALOG_UPDATE:
1064 GridInsetMailer(*this).updateDialog(&bv);
1065 return DispatchResult(false);
1067 // insert file functions
1068 case LFUN_DELETE_LINE_FORWARD:
1069 //autocorrect_ = false;
1077 if (cur.idx() >= nargs())
1078 cur.idx() = nargs() - 1;
1079 if (cur.pos() > cur.lastpos())
1080 cur.pos() = cur.lastpos();
1081 return DispatchResult(true, FINISHED);
1083 case LFUN_CELL_SPLIT:
1084 //recordUndo(bv, Undo::ATOMIC);
1086 return DispatchResult(true, FINISHED);
1088 case LFUN_BREAKLINE: {
1089 //recordUndo(bv, Undo::INSERT);
1090 row_type const r = cur.row();
1094 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1095 std::swap(cell(index(r, c)), cell(index(r + 1, c)));
1099 std::swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1102 cur.idx() = cur.lastpos();
1104 //mathcursor->normalize();
1105 return DispatchResult(true, FINISHED);
1108 case LFUN_TABULAR_FEATURE: {
1109 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1110 istringstream is(cmd.argument);
1113 if (s == "valign-top")
1115 else if (s == "valign-middle")
1117 else if (s == "valign-bottom")
1119 else if (s == "align-left")
1120 halign('l', col(cur.idx()));
1121 else if (s == "align-right")
1122 halign('r', col(cur.idx()));
1123 else if (s == "align-center")
1124 halign('c', col(cur.idx()));
1125 else if (s == "append-row")
1126 for (int i = 0, n = extractInt(is); i < n; ++i)
1128 else if (s == "delete-row")
1129 for (int i = 0, n = extractInt(is); i < n; ++i) {
1131 if (cur.idx() > nargs())
1132 cur.idx() -= ncols();
1134 else if (s == "copy-row")
1135 for (int i = 0, n = extractInt(is); i < n; ++i)
1137 else if (s == "swap-row")
1139 else if (s == "append-column")
1140 for (int i = 0, n = extractInt(is); i < n; ++i) {
1141 row_type r = cur.row();
1142 col_type c = col(cur.idx());
1144 cur.idx() = index(r, c);
1146 else if (s == "delete-column")
1147 for (int i = 0, n = extractInt(is); i < n; ++i) {
1148 row_type r = cur.row();
1149 col_type c = col(cur.idx());
1150 delCol(col(cur.idx()));
1151 cur.idx() = index(r, c);
1152 if (cur.idx() > nargs())
1153 cur.idx() -= ncols();
1155 else if (s == "copy-column")
1156 copyCol(col(cur.idx()));
1157 else if (s == "swap-column")
1158 swapCol(col(cur.idx()));
1160 return DispatchResult(false);
1161 lyxerr << "returning DispatchResult(true, FINISHED)" << endl;
1162 return DispatchResult(true, FINISHED);
1166 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1167 MathGridInset grid(1, 1);
1168 mathed_parse_normal(grid, cmd.argument);
1169 if (grid.nargs() == 1) {
1170 // single cell/part of cell
1171 cur.cell().insert(cur.pos(), grid.cell(0));
1172 cur.pos() += grid.cell(0).size();
1175 col_type const numcols = min(grid.ncols(), ncols() -
1177 row_type const numrows = min(grid.nrows(), nrows() -
1179 for (row_type r = 0; r < numrows; ++r) {
1180 for (col_type c = 0; c < numcols; ++c) {
1181 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1182 cell(i).insert(0, grid.cell(grid.index(r, c)));
1184 // append the left over horizontal cells to the last column
1185 idx_type i = index(r + cur.row(), ncols() - 1);
1186 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1187 cell(i).append(grid.cell(grid.index(r, c)));
1189 // append the left over vertical cells to the last _cell_
1190 idx_type i = nargs() - 1;
1191 for (row_type r = numrows; r < grid.nrows(); ++r)
1192 for (col_type c = 0; c < grid.ncols(); ++c)
1193 cell(i).append(grid.cell(grid.index(r, c)));
1195 return DispatchResult(true, FINISHED);
1199 return MathNestInset::priv_dispatch(bv, cmd);