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"
18 #include "BufferView.h"
19 #include "CutAndPaste.h"
20 #include "FuncStatus.h"
24 #include "funcrequest.h"
26 #include "frontends/Painter.h"
28 #include "support/std_sstream.h"
30 #include "insets/mailinset.h"
40 using std::istringstream;
41 using std::ostringstream;
45 class GridInsetMailer : public MailInset {
47 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
49 virtual string const & name() const
51 static string const theName = "tabular";
55 virtual string const inset2string(Buffer const &) const
58 //data << name() << " active_cell " << inset.getActCell() << '\n';
59 data << name() << " active_cell " << 0 << '\n';
66 InsetBase & inset() const { return inset_; }
67 MathGridInset & inset_;
71 void mathed_parse_normal(MathGridInset &, string const & argument);
75 string verboseHLine(int n)
78 for (int i = 0; i < n; ++i)
86 int extractInt(istream & is)
90 return (num == 0) ? 1 : num;
96 //////////////////////////////////////////////////////////////
99 MathGridInset::CellInfo::CellInfo()
106 //////////////////////////////////////////////////////////////
109 MathGridInset::RowInfo::RowInfo()
110 : lines_(0), skip_(0)
115 int MathGridInset::RowInfo::skipPixels() const
117 return crskip_.inBP();
122 //////////////////////////////////////////////////////////////
125 MathGridInset::ColInfo::ColInfo()
126 : align_('c'), leftline_(false), rightline_(false), lines_(0)
130 //////////////////////////////////////////////////////////////
133 MathGridInset::MathGridInset(char v, string const & h)
134 : MathNestInset(guessColumns(h)),
136 colinfo_(guessColumns(h) + 1),
137 cellinfo_(1 * guessColumns(h))
142 //lyxerr << "created grid with " << ncols() << " columns" << endl;
146 MathGridInset::MathGridInset()
157 MathGridInset::MathGridInset(col_type m, row_type n)
158 : MathNestInset(m * n),
168 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
169 : MathNestInset(m * n),
181 MathGridInset::~MathGridInset()
183 GridInsetMailer mailer(*this);
188 auto_ptr<InsetBase> MathGridInset::clone() const
190 return auto_ptr<InsetBase>(new MathGridInset(*this));
194 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
196 return col + ncols() * row;
200 void MathGridInset::setDefaults()
203 lyxerr << "positive number of columns expected" << endl;
205 // lyxerr << "positive number of rows expected" << endl;
206 for (col_type col = 0; col < ncols(); ++col) {
207 colinfo_[col].align_ = defaultColAlign(col);
208 colinfo_[col].skip_ = defaultColSpace(col);
213 void MathGridInset::halign(string const & hh)
216 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
221 colinfo_[col].lines_++;
222 } else if (c == 'c' || c == 'l' || c == 'r') {
223 colinfo_[col].align_ = c;
225 colinfo_[col].lines_ = 0;
227 lyxerr << "unknown column separator: '" << c << "'" << endl;
232 col_type n = hh.size();
235 for (col_type col = 0; col < n; ++col)
236 colinfo_[col].align_ = hh[col];
241 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
244 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
245 if (*it == 'c' || *it == 'l' || *it == 'r')
247 // let's have at least one column, even if we did not recognize its
255 void MathGridInset::halign(char h, col_type col)
257 colinfo_[col].align_ = h;
261 char MathGridInset::halign(col_type col) const
263 return colinfo_[col].align_;
267 string MathGridInset::halign() const
270 for (col_type col = 0; col < ncols(); ++col) {
271 res += string(colinfo_[col].lines_, '|');
272 res += colinfo_[col].align_;
274 return res + string(colinfo_[ncols()].lines_, '|');
278 void MathGridInset::valign(char c)
284 char MathGridInset::valign() const
290 MathGridInset::col_type MathGridInset::ncols() const
292 return colinfo_.size() - 1;
296 MathGridInset::row_type MathGridInset::nrows() const
298 return rowinfo_.size() - 1;
302 MathGridInset::col_type MathGridInset::col(idx_type idx) const
304 return idx % ncols();
308 MathGridInset::row_type MathGridInset::row(idx_type idx) const
310 return idx / ncols();
314 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
316 rowinfo_[row].crskip_ = crskip;
320 LyXLength MathGridInset::vcrskip(row_type row) const
322 return rowinfo_[row].crskip_;
326 void MathGridInset::metrics(MetricsInfo & mi) const
328 // let the cells adjust themselves
329 MathNestInset::metrics(mi);
331 // compute absolute sizes of vertical structure
332 for (row_type row = 0; row < nrows(); ++row) {
335 for (col_type col = 0; col < ncols(); ++col) {
336 MathArray const & c = cell(index(row, col));
337 asc = max(asc, c.ascent());
338 desc = max(desc, c.descent());
340 rowinfo_[row].ascent_ = asc;
341 rowinfo_[row].descent_ = desc;
343 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
344 rowinfo_[nrows()].ascent_ = 0;
345 rowinfo_[nrows()].descent_ = 0;
347 // compute vertical offsets
348 rowinfo_[0].offset_ = 0;
349 for (row_type row = 1; row <= nrows(); ++row) {
350 rowinfo_[row].offset_ =
351 rowinfo_[row - 1].offset_ +
352 rowinfo_[row - 1].descent_ +
353 rowinfo_[row - 1].skipPixels() +
355 rowinfo_[row].lines_ * hlinesep() +
356 rowinfo_[row].ascent_;
359 // adjust vertical offset
366 h = rowinfo_[nrows() - 1].offset_;
369 h = rowinfo_[nrows() - 1].offset_ / 2;
371 for (row_type row = 0; row <= nrows(); ++row)
372 rowinfo_[row].offset_ -= h;
375 // compute absolute sizes of horizontal structure
376 for (col_type col = 0; col < ncols(); ++col) {
378 for (row_type row = 0; row < nrows(); ++row)
379 wid = max(wid, cell(index(row, col)).width());
380 colinfo_[col].width_ = wid;
382 colinfo_[ncols()].width_ = 0;
384 // compute horizontal offsets
385 colinfo_[0].offset_ = border();
386 for (col_type col = 1; col <= ncols(); ++col) {
387 colinfo_[col].offset_ =
388 colinfo_[col - 1].offset_ +
389 colinfo_[col - 1].width_ +
390 colinfo_[col - 1].skip_ +
392 colinfo_[col].lines_ * vlinesep();
396 dim_.wid = colinfo_[ncols() - 1].offset_
397 + colinfo_[ncols() - 1].width_
398 + vlinesep() * colinfo_[ncols()].lines_
401 dim_.asc = - rowinfo_[0].offset_
402 + rowinfo_[0].ascent_
403 + hlinesep() * rowinfo_[0].lines_
406 dim_.des = rowinfo_[nrows() - 1].offset_
407 + rowinfo_[nrows() - 1].descent_
408 + hlinesep() * rowinfo_[nrows()].lines_
413 // Increase ws_[i] for 'R' columns (except the first one)
414 for (int i = 1; i < nc_; ++i)
415 if (align_[i] == 'R')
416 ws_[i] += 10 * df_width;
417 // Increase ws_[i] for 'C' column
418 if (align_[0] == 'C')
419 if (ws_[0] < 7 * workwidth / 8)
420 ws_[0] = 7 * workwidth / 8;
424 for (cxrow = row_.begin(); cxrow; ++cxrow) {
427 for (int i = 0; i < nc_; ++i) {
429 if (cxrow->getTab(i) <= 0) {
430 cxrow->setTab(i, df_width);
438 lf = (ws_[i] - cxrow->getTab(i))/2;
442 lf = ws_[i] - cxrow->getTab(i);
445 if (cxrow == row_.begin())
447 else if (cxrow.is_last())
448 lf = ws_[i] - cxrow->getTab(i);
450 lf = (ws_[i] - cxrow->getTab(i))/2;
453 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
454 cxrow->setTab(i, lf + rg);
455 rg = ws_[i] - ww + colsep();
456 if (cxrow == row_.begin())
457 width += ws_[i] + colsep();
459 cxrow->setBaseline(cxrow->getBaseline() - ascent);
462 metricsMarkers2(dim_);
466 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
473 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
475 for (idx_type idx = 0; idx < nargs(); ++idx)
476 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
478 for (row_type row = 0; row <= nrows(); ++row)
479 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
480 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
481 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
482 pi.pain.line(x + 1, yy,
483 x + dim_.width() - 1, yy,
487 for (col_type col = 0; col <= ncols(); ++col)
488 for (int i = 0; i < colinfo_[col].lines_; ++i) {
489 int xx = x + colinfo_[col].offset_
490 - i * vlinesep() - vlinesep()/2 - colsep()/2;
491 pi.pain.line(xx, y - dim_.ascent() + 1,
492 xx, y + dim_.descent() - 1,
495 drawMarkers2(pi, x, y);
499 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
501 // let the cells adjust themselves
502 //MathNestInset::metrics(mi);
503 for (idx_type i = 0; i < nargs(); ++i)
504 cell(i).metricsT(mi, dim);
506 // compute absolute sizes of vertical structure
507 for (row_type row = 0; row < nrows(); ++row) {
510 for (col_type col = 0; col < ncols(); ++col) {
511 MathArray const & c = cell(index(row, col));
512 asc = max(asc, c.ascent());
513 desc = max(desc, c.descent());
515 rowinfo_[row].ascent_ = asc;
516 rowinfo_[row].descent_ = desc;
518 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
519 rowinfo_[nrows()].ascent_ = 0;
520 rowinfo_[nrows()].descent_ = 0;
522 // compute vertical offsets
523 rowinfo_[0].offset_ = 0;
524 for (row_type row = 1; row <= nrows(); ++row) {
525 rowinfo_[row].offset_ =
526 rowinfo_[row - 1].offset_ +
527 rowinfo_[row - 1].descent_ +
528 //rowinfo_[row - 1].skipPixels() +
530 //rowinfo_[row].lines_ * hlinesep() +
531 rowinfo_[row].ascent_;
534 // adjust vertical offset
541 h = rowinfo_[nrows() - 1].offset_;
544 h = rowinfo_[nrows() - 1].offset_ / 2;
546 for (row_type row = 0; row <= nrows(); ++row)
547 rowinfo_[row].offset_ -= h;
550 // compute absolute sizes of horizontal structure
551 for (col_type col = 0; col < ncols(); ++col) {
553 for (row_type row = 0; row < nrows(); ++row)
554 wid = max(wid, cell(index(row, col)).width());
555 colinfo_[col].width_ = wid;
557 colinfo_[ncols()].width_ = 0;
559 // compute horizontal offsets
560 colinfo_[0].offset_ = border();
561 for (col_type col = 1; col <= ncols(); ++col) {
562 colinfo_[col].offset_ =
563 colinfo_[col - 1].offset_ +
564 colinfo_[col - 1].width_ +
565 colinfo_[col - 1].skip_ +
567 //colinfo_[col].lines_ * vlinesep();
571 dim.wid = colinfo_[ncols() - 1].offset_
572 + colinfo_[ncols() - 1].width_
573 //+ vlinesep() * colinfo_[ncols()].lines_
576 dim.asc = -rowinfo_[0].offset_
577 + rowinfo_[0].ascent_
578 //+ hlinesep() * rowinfo_[0].lines_
581 dim.des = rowinfo_[nrows() - 1].offset_
582 + rowinfo_[nrows() - 1].descent_
583 //+ hlinesep() * rowinfo_[nrows()].lines_
588 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
590 for (idx_type idx = 0; idx < nargs(); ++idx)
591 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
595 string MathGridInset::eolString(row_type row, bool fragile) const
599 if (!rowinfo_[row].crskip_.zero())
600 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
602 // make sure an upcoming '[' does not break anything
603 if (row + 1 < nrows()) {
604 MathArray const & c = cell(index(row + 1, 0));
605 if (c.size() && c.front()->getChar() == '[')
610 // only add \\ if necessary
611 if (eol.empty() && row + 1 == nrows())
614 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
618 string MathGridInset::eocString(col_type col, col_type lastcol) const
620 if (col + 1 == lastcol)
626 void MathGridInset::addRow(row_type row)
628 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
630 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
632 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
636 void MathGridInset::appendRow()
638 rowinfo_.push_back(RowInfo());
639 //cells_.insert(cells_.end(), ncols(), MathArray());
640 for (col_type col = 0; col < ncols(); ++col) {
641 cells_.push_back(cells_type::value_type());
642 cellinfo_.push_back(CellInfo());
647 void MathGridInset::delRow(row_type row)
652 cells_type::iterator it = cells_.begin() + row * ncols();
653 cells_.erase(it, it + ncols());
655 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
656 cellinfo_.erase(jt, jt + ncols());
658 rowinfo_.erase(rowinfo_.begin() + row);
662 void MathGridInset::copyRow(row_type row)
665 for (col_type col = 0; col < ncols(); ++col)
666 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
670 void MathGridInset::swapRow(row_type row)
674 if (row + 1 == nrows())
676 for (col_type col = 0; col < ncols(); ++col)
677 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
681 void MathGridInset::addCol(col_type newcol)
683 const col_type nc = ncols();
684 const row_type nr = nrows();
685 cells_type new_cells((nc + 1) * nr);
686 vector<CellInfo> new_cellinfo((nc + 1) * nr);
688 for (row_type row = 0; row < nr; ++row)
689 for (col_type col = 0; col < nc; ++col) {
690 new_cells[row * (nc + 1) + col + (col > newcol)]
691 = cells_[row * nc + col];
692 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
693 = cellinfo_[row * nc + col];
695 swap(cells_, new_cells);
696 swap(cellinfo_, new_cellinfo);
699 inf.skip_ = defaultColSpace(newcol);
700 inf.align_ = defaultColAlign(newcol);
701 colinfo_.insert(colinfo_.begin() + newcol, inf);
705 void MathGridInset::delCol(col_type col)
711 vector<CellInfo> tmpcellinfo;
712 for (col_type i = 0; i < nargs(); ++i)
713 if (i % ncols() != col) {
714 tmpcells.push_back(cells_[i]);
715 tmpcellinfo.push_back(cellinfo_[i]);
717 swap(cells_, tmpcells);
718 swap(cellinfo_, tmpcellinfo);
720 colinfo_.erase(colinfo_.begin() + col);
724 void MathGridInset::copyCol(col_type col)
727 for (row_type row = 0; row < nrows(); ++row)
728 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
732 void MathGridInset::swapCol(col_type col)
736 if (col + 1 == ncols())
738 for (row_type row = 0; row < nrows(); ++row)
739 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
743 int MathGridInset::cellXOffset(idx_type idx) const
745 col_type c = col(idx);
746 int x = colinfo_[c].offset_;
747 char align = colinfo_[c].align_;
748 if (align == 'r' || align == 'R')
749 x += colinfo_[c].width_ - cell(idx).width();
750 if (align == 'c' || align == 'C')
751 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
756 int MathGridInset::cellYOffset(idx_type idx) const
758 return rowinfo_[row(idx)].offset_;
762 bool MathGridInset::idxUpDown(LCursor & cur, bool up) const
765 if (cur.idx() < ncols())
767 cur.idx() -= ncols();
769 if (cur.idx() >= ncols() * (nrows() - 1))
771 cur.idx() += ncols();
773 cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo());
778 bool MathGridInset::idxLeft(LCursor & cur) const
780 // leave matrix if on the left hand edge
784 cur.pos() = cur.lastpos();
789 bool MathGridInset::idxRight(LCursor & cur) const
791 // leave matrix if on the right hand edge
792 if (cur.col() + 1 == ncols())
800 bool MathGridInset::idxFirst(LCursor & cur) const
807 cur.idx() = (nrows() - 1) * ncols();
810 cur.idx() = ((nrows() - 1) / 2) * ncols();
817 bool MathGridInset::idxLast(LCursor & cur) const
821 cur.idx() = ncols() - 1;
824 cur.idx() = nargs() - 1;
827 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
829 cur.pos() = cur.lastpos();
834 bool MathGridInset::idxDelete(idx_type & idx)
836 // nothing to do if we have just one row
840 // nothing to do if we are in the middle of the last row of the inset
841 if (idx + ncols() > nargs())
844 // try to delete entire sequence of ncols() empty cells if possible
845 for (idx_type i = idx; i < idx + ncols(); ++i)
849 // move cells if necessary
850 for (idx_type i = index(row(idx), 0); i < idx; ++i)
851 swap(cell(i), cell(i + ncols()));
858 // undo effect of Ctrl-Tab (i.e. pull next cell)
859 //if (idx + 1 != nargs())
860 // cell(idx).swap(cell(idx + 1));
862 // we handled the event..
867 // reimplement old behaviour when pressing Delete in the last position
869 void MathGridInset::idxGlue(idx_type idx)
871 col_type c = col(idx);
872 if (c + 1 == ncols()) {
873 if (row(idx) + 1 != nrows()) {
874 for (col_type cc = 0; cc < ncols(); ++cc)
875 cell(idx).append(cell(idx + cc + 1));
876 delRow(row(idx) + 1);
879 cell(idx).append(cell(idx + 1));
880 for (col_type cc = c + 2; cc < ncols(); ++cc)
881 cell(idx - c + cc - 1) = cell(idx - c + cc);
882 cell(idx - c + ncols() - 1).clear();
887 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
889 return rowinfo_[row];
893 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
895 return rowinfo_[row];
899 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
901 row_type const ri = row(idx);
902 row_type const r1 = min(row(from), row(to));
903 row_type const r2 = max(row(from), row(to));
904 col_type const ci = col(idx);
905 col_type const c1 = min(col(from), col(to));
906 col_type const c2 = max(col(from), col(to));
907 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
912 void MathGridInset::normalize(NormalStream & os) const
915 for (row_type row = 0; row < nrows(); ++row) {
917 for (col_type col = 0; col < ncols(); ++col)
918 os << "[cell " << cell(index(row, col)) << ']';
925 void MathGridInset::mathmlize(MathMLStream & os) const
927 os << MTag("mtable");
928 for (row_type row = 0; row < nrows(); ++row) {
930 for (col_type col = 0; col < ncols(); ++col)
931 os << cell(index(row, col));
934 os << ETag("mtable");
938 void MathGridInset::write(WriteStream & os) const
940 for (row_type row = 0; row < nrows(); ++row) {
941 os << verboseHLine(rowinfo_[row].lines_);
942 // don't write & and empty cells at end of line
943 col_type lastcol = 0;
944 bool emptyline = true;
945 for (col_type col = 0; col < ncols(); ++col)
946 if (!cell(index(row, col)).empty()) {
950 for (col_type col = 0; col < lastcol; ++col)
951 os << cell(index(row, col)) << eocString(col, lastcol);
952 os << eolString(row, os.fragile());
953 // append newline only if line wasn't completely empty
954 // and this was not the last line in the grid
955 if (!emptyline && row + 1 < nrows())
958 string const s = verboseHLine(rowinfo_[nrows()].lines_);
959 if (!s.empty() && s != " ") {
967 int MathGridInset::colsep() const
973 int MathGridInset::rowsep() const
979 int MathGridInset::hlinesep() const
985 int MathGridInset::vlinesep() const
991 int MathGridInset::border() const
997 void MathGridInset::splitCell(LCursor & cur)
999 if (cur.idx() == cur.lastidx())
1001 MathArray ar = cur.cell();
1002 ar.erase(0, cur.pos());
1003 cur.cell().erase(cur.pos(), cur.lastpos());
1006 cur.cell().insert(0, ar);
1010 void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
1012 //lyxerr << "*** MathGridInset: request: " << cmd << endl;
1013 switch (cmd.action) {
1015 case LFUN_MOUSE_RELEASE:
1016 //if (cmd.button() == mouse_button::button3) {
1017 // GridInsetMailer(*this).showDialog();
1018 // return DispatchResult(true, true);
1020 MathNestInset::priv_dispatch(cur, cmd);
1023 case LFUN_INSET_DIALOG_UPDATE:
1024 GridInsetMailer(*this).updateDialog(&cur.bv());
1027 // insert file functions
1028 case LFUN_DELETE_LINE_FORWARD:
1029 //autocorrect_ = false;
1037 if (cur.idx() > cur.lastidx())
1038 cur.idx() = cur.lastidx();
1039 if (cur.pos() > cur.lastpos())
1040 cur.pos() = cur.lastpos();
1043 case LFUN_CELL_SPLIT:
1044 ////recordUndo(cur, Undo::ATOMIC);
1048 case LFUN_BREAKLINE: {
1049 ////recordUndo(cur, Undo::INSERT);
1050 row_type const r = cur.row();
1054 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1055 swap(cell(index(r, c)), cell(index(r + 1, c)));
1059 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1062 cur.idx() = cur.lastpos();
1064 //mathcursor->normalize();
1065 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1069 case LFUN_TABULAR_FEATURE: {
1070 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1071 istringstream is(cmd.argument);
1074 if (s == "valign-top")
1076 else if (s == "valign-middle")
1078 else if (s == "valign-bottom")
1080 else if (s == "align-left")
1081 halign('l', col(cur.idx()));
1082 else if (s == "align-right")
1083 halign('r', col(cur.idx()));
1084 else if (s == "align-center")
1085 halign('c', col(cur.idx()));
1086 else if (s == "append-row")
1087 for (int i = 0, n = extractInt(is); i < n; ++i)
1089 else if (s == "delete-row")
1090 for (int i = 0, n = extractInt(is); i < n; ++i) {
1092 if (cur.idx() > nargs())
1093 cur.idx() -= ncols();
1095 else if (s == "copy-row")
1096 for (int i = 0, n = extractInt(is); i < n; ++i)
1098 else if (s == "swap-row")
1100 else if (s == "append-column")
1101 for (int i = 0, n = extractInt(is); i < n; ++i) {
1102 row_type r = cur.row();
1103 col_type c = col(cur.idx());
1105 cur.idx() = index(r, c);
1107 else if (s == "delete-column")
1108 for (int i = 0, n = extractInt(is); i < n; ++i) {
1109 row_type r = cur.row();
1110 col_type c = col(cur.idx());
1111 delCol(col(cur.idx()));
1112 cur.idx() = index(r, c);
1113 if (cur.idx() > nargs())
1114 cur.idx() -= ncols();
1116 else if (s == "copy-column")
1117 copyCol(col(cur.idx()));
1118 else if (s == "swap-column")
1119 swapCol(col(cur.idx()));
1124 lyxerr << "returning FINISHED_LEFT" << endl;
1129 lyxerr << "MathGridInset: PASTE: " << cmd << std::endl;
1130 istringstream is(cmd.argument);
1133 MathGridInset grid(1, 1);
1134 mathed_parse_normal(grid, lyx::cap::getSelection(cur.buffer(), n));
1135 if (grid.nargs() == 1) {
1136 // single cell/part of cell
1137 cur.cell().insert(cur.pos(), grid.cell(0));
1138 cur.pos() += grid.cell(0).size();
1141 col_type const numcols =
1142 min(grid.ncols(), ncols() - col(cur.idx()));
1143 row_type const numrows =
1144 min(grid.nrows(), nrows() - cur.row());
1145 for (row_type r = 0; r < numrows; ++r) {
1146 for (col_type c = 0; c < numcols; ++c) {
1147 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1148 cell(i).insert(0, grid.cell(grid.index(r, c)));
1150 // append the left over horizontal cells to the last column
1151 idx_type i = index(r + cur.row(), ncols() - 1);
1152 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1153 cell(i).append(grid.cell(grid.index(r, c)));
1155 // append the left over vertical cells to the last _cell_
1156 idx_type i = nargs() - 1;
1157 for (row_type r = numrows; r < grid.nrows(); ++r)
1158 for (col_type c = 0; c < grid.ncols(); ++c)
1159 cell(i).append(grid.cell(grid.index(r, c)));
1166 case LFUN_WORDLEFTSEL:
1168 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
1169 cur.macroModeClose();
1170 if (cur.pos() != 0) {
1172 } else if (cur.idx() % cur.ncols() != 0) {
1173 cur.idx() -= cur.idx() % cur.ncols();
1175 } else if (cur.idx() != 0) {
1179 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1183 case LFUN_WORDRIGHTSEL:
1184 case LFUN_WORDRIGHT:
1187 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
1188 cur.macroModeClose();
1190 if (cur.pos() != cur.lastpos()) {
1191 cur.pos() = cur.lastpos();
1192 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1193 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1194 cur.pos() = cur.lastpos();
1195 } else if (cur.idx() != cur.lastidx()) {
1196 cur.idx() = cur.lastidx();
1197 cur.pos() = cur.lastpos();
1199 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1204 MathNestInset::priv_dispatch(cur, cmd);
1209 bool MathGridInset::getStatus(LCursor & cur, FuncRequest const & cmd,
1210 FuncStatus & flag) const
1213 switch (cmd.action) {
1214 case LFUN_TABULAR_FEATURE:
1216 // should be more precise
1217 if (v_align_ == '\0') {
1221 if (cmd.argument.empty()) {
1225 if (!contains("tcb", cmd.argument[0])) {
1229 flag.setOnOff(cmd.argument[0] == v_align_);
1234 ret = MathNestInset::getStatus(cur, cmd, flag);