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 "FuncStatus.h"
23 #include "funcrequest.h"
25 #include "frontends/Painter.h"
27 #include "support/std_sstream.h"
29 #include "insets/mailinset.h"
39 using std::istringstream;
40 using std::ostringstream;
44 class GridInsetMailer : public MailInset {
46 GridInsetMailer(MathGridInset & inset) : inset_(inset) {}
48 virtual string const & name() const
50 static string const theName = "tabular";
54 virtual string const inset2string(Buffer const &) const
57 //data << name() << " active_cell " << inset.getActCell() << '\n';
58 data << name() << " active_cell " << 0 << '\n';
65 InsetBase & inset() const { return inset_; }
66 MathGridInset & inset_;
70 void mathed_parse_normal(MathGridInset &, string const & argument);
74 string verboseHLine(int n)
77 for (int i = 0; i < n; ++i)
85 int extractInt(istream & is)
89 return (num == 0) ? 1 : num;
95 //////////////////////////////////////////////////////////////
98 MathGridInset::CellInfo::CellInfo()
105 //////////////////////////////////////////////////////////////
108 MathGridInset::RowInfo::RowInfo()
109 : lines_(0), skip_(0)
114 int MathGridInset::RowInfo::skipPixels() const
116 return crskip_.inBP();
121 //////////////////////////////////////////////////////////////
124 MathGridInset::ColInfo::ColInfo()
125 : align_('c'), leftline_(false), rightline_(false), lines_(0)
129 //////////////////////////////////////////////////////////////
132 MathGridInset::MathGridInset(char v, string const & h)
133 : MathNestInset(guessColumns(h)),
135 colinfo_(guessColumns(h) + 1),
136 cellinfo_(1 * guessColumns(h))
141 //lyxerr << "created grid with " << ncols() << " columns" << endl;
145 MathGridInset::MathGridInset()
156 MathGridInset::MathGridInset(col_type m, row_type n)
157 : MathNestInset(m * n),
167 MathGridInset::MathGridInset(col_type m, row_type n, char v, string const & h)
168 : MathNestInset(m * n),
180 MathGridInset::~MathGridInset()
182 GridInsetMailer mailer(*this);
187 auto_ptr<InsetBase> MathGridInset::clone() const
189 return auto_ptr<InsetBase>(new MathGridInset(*this));
193 MathInset::idx_type MathGridInset::index(row_type row, col_type col) const
195 return col + ncols() * row;
199 void MathGridInset::setDefaults()
202 lyxerr << "positive number of columns expected" << endl;
204 // lyxerr << "positive number of rows expected" << endl;
205 for (col_type col = 0; col < ncols(); ++col) {
206 colinfo_[col].align_ = defaultColAlign(col);
207 colinfo_[col].skip_ = defaultColSpace(col);
212 void MathGridInset::halign(string const & hh)
215 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it) {
220 colinfo_[col].lines_++;
221 } else if (c == 'c' || c == 'l' || c == 'r') {
222 colinfo_[col].align_ = c;
224 colinfo_[col].lines_ = 0;
226 lyxerr << "unknown column separator: '" << c << "'" << endl;
231 col_type n = hh.size();
234 for (col_type col = 0; col < n; ++col)
235 colinfo_[col].align_ = hh[col];
240 MathGridInset::col_type MathGridInset::guessColumns(string const & hh) const
243 for (string::const_iterator it = hh.begin(); it != hh.end(); ++it)
244 if (*it == 'c' || *it == 'l' || *it == 'r')
246 // let's have at least one column, even if we did not recognize its
254 void MathGridInset::halign(char h, col_type col)
256 colinfo_[col].align_ = h;
260 char MathGridInset::halign(col_type col) const
262 return colinfo_[col].align_;
266 string MathGridInset::halign() const
269 for (col_type col = 0; col < ncols(); ++col) {
270 res += string(colinfo_[col].lines_, '|');
271 res += colinfo_[col].align_;
273 return res + string(colinfo_[ncols()].lines_, '|');
277 void MathGridInset::valign(char c)
283 char MathGridInset::valign() const
289 MathGridInset::col_type MathGridInset::ncols() const
291 return colinfo_.size() - 1;
295 MathGridInset::row_type MathGridInset::nrows() const
297 return rowinfo_.size() - 1;
301 MathGridInset::col_type MathGridInset::col(idx_type idx) const
303 return idx % ncols();
307 MathGridInset::row_type MathGridInset::row(idx_type idx) const
309 return idx / ncols();
313 void MathGridInset::vcrskip(LyXLength const & crskip, row_type row)
315 rowinfo_[row].crskip_ = crskip;
319 LyXLength MathGridInset::vcrskip(row_type row) const
321 return rowinfo_[row].crskip_;
325 void MathGridInset::metrics(MetricsInfo & mi) const
327 // let the cells adjust themselves
328 MathNestInset::metrics(mi);
330 // compute absolute sizes of vertical structure
331 for (row_type row = 0; row < nrows(); ++row) {
334 for (col_type col = 0; col < ncols(); ++col) {
335 MathArray const & c = cell(index(row, col));
336 asc = max(asc, c.ascent());
337 desc = max(desc, c.descent());
339 rowinfo_[row].ascent_ = asc;
340 rowinfo_[row].descent_ = desc;
342 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
343 rowinfo_[nrows()].ascent_ = 0;
344 rowinfo_[nrows()].descent_ = 0;
346 // compute vertical offsets
347 rowinfo_[0].offset_ = 0;
348 for (row_type row = 1; row <= nrows(); ++row) {
349 rowinfo_[row].offset_ =
350 rowinfo_[row - 1].offset_ +
351 rowinfo_[row - 1].descent_ +
352 rowinfo_[row - 1].skipPixels() +
354 rowinfo_[row].lines_ * hlinesep() +
355 rowinfo_[row].ascent_;
358 // adjust vertical offset
365 h = rowinfo_[nrows() - 1].offset_;
368 h = rowinfo_[nrows() - 1].offset_ / 2;
370 for (row_type row = 0; row <= nrows(); ++row)
371 rowinfo_[row].offset_ -= h;
374 // compute absolute sizes of horizontal structure
375 for (col_type col = 0; col < ncols(); ++col) {
377 for (row_type row = 0; row < nrows(); ++row)
378 wid = max(wid, cell(index(row, col)).width());
379 colinfo_[col].width_ = wid;
381 colinfo_[ncols()].width_ = 0;
383 // compute horizontal offsets
384 colinfo_[0].offset_ = border();
385 for (col_type col = 1; col <= ncols(); ++col) {
386 colinfo_[col].offset_ =
387 colinfo_[col - 1].offset_ +
388 colinfo_[col - 1].width_ +
389 colinfo_[col - 1].skip_ +
391 colinfo_[col].lines_ * vlinesep();
395 dim_.wid = colinfo_[ncols() - 1].offset_
396 + colinfo_[ncols() - 1].width_
397 + vlinesep() * colinfo_[ncols()].lines_
400 dim_.asc = - rowinfo_[0].offset_
401 + rowinfo_[0].ascent_
402 + hlinesep() * rowinfo_[0].lines_
405 dim_.des = rowinfo_[nrows() - 1].offset_
406 + rowinfo_[nrows() - 1].descent_
407 + hlinesep() * rowinfo_[nrows()].lines_
412 // Increase ws_[i] for 'R' columns (except the first one)
413 for (int i = 1; i < nc_; ++i)
414 if (align_[i] == 'R')
415 ws_[i] += 10 * df_width;
416 // Increase ws_[i] for 'C' column
417 if (align_[0] == 'C')
418 if (ws_[0] < 7 * workwidth / 8)
419 ws_[0] = 7 * workwidth / 8;
423 for (cxrow = row_.begin(); cxrow; ++cxrow) {
426 for (int i = 0; i < nc_; ++i) {
428 if (cxrow->getTab(i) <= 0) {
429 cxrow->setTab(i, df_width);
437 lf = (ws_[i] - cxrow->getTab(i))/2;
441 lf = ws_[i] - cxrow->getTab(i);
444 if (cxrow == row_.begin())
446 else if (cxrow.is_last())
447 lf = ws_[i] - cxrow->getTab(i);
449 lf = (ws_[i] - cxrow->getTab(i))/2;
452 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
453 cxrow->setTab(i, lf + rg);
454 rg = ws_[i] - ww + colsep();
455 if (cxrow == row_.begin())
456 width += ws_[i] + colsep();
458 cxrow->setBaseline(cxrow->getBaseline() - ascent);
464 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
471 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
473 for (idx_type idx = 0; idx < nargs(); ++idx)
474 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
476 for (row_type row = 0; row <= nrows(); ++row)
477 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
478 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
479 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
480 pi.pain.line(x + 1, yy,
481 x + dim_.width() - 1, yy,
485 for (col_type col = 0; col <= ncols(); ++col)
486 for (int i = 0; i < colinfo_[col].lines_; ++i) {
487 int xx = x + colinfo_[col].offset_
488 - i * vlinesep() - vlinesep()/2 - colsep()/2;
489 pi.pain.line(xx, y - dim_.ascent() + 1,
490 xx, y + dim_.descent() - 1,
496 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
498 // let the cells adjust themselves
499 //MathNestInset::metrics(mi);
500 for (idx_type i = 0; i < nargs(); ++i)
501 cell(i).metricsT(mi, dim);
503 // compute absolute sizes of vertical structure
504 for (row_type row = 0; row < nrows(); ++row) {
507 for (col_type col = 0; col < ncols(); ++col) {
508 MathArray const & c = cell(index(row, col));
509 asc = max(asc, c.ascent());
510 desc = max(desc, c.descent());
512 rowinfo_[row].ascent_ = asc;
513 rowinfo_[row].descent_ = desc;
515 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
516 rowinfo_[nrows()].ascent_ = 0;
517 rowinfo_[nrows()].descent_ = 0;
519 // compute vertical offsets
520 rowinfo_[0].offset_ = 0;
521 for (row_type row = 1; row <= nrows(); ++row) {
522 rowinfo_[row].offset_ =
523 rowinfo_[row - 1].offset_ +
524 rowinfo_[row - 1].descent_ +
525 //rowinfo_[row - 1].skipPixels() +
527 //rowinfo_[row].lines_ * hlinesep() +
528 rowinfo_[row].ascent_;
531 // adjust vertical offset
538 h = rowinfo_[nrows() - 1].offset_;
541 h = rowinfo_[nrows() - 1].offset_ / 2;
543 for (row_type row = 0; row <= nrows(); ++row)
544 rowinfo_[row].offset_ -= h;
547 // compute absolute sizes of horizontal structure
548 for (col_type col = 0; col < ncols(); ++col) {
550 for (row_type row = 0; row < nrows(); ++row)
551 wid = max(wid, cell(index(row, col)).width());
552 colinfo_[col].width_ = wid;
554 colinfo_[ncols()].width_ = 0;
556 // compute horizontal offsets
557 colinfo_[0].offset_ = border();
558 for (col_type col = 1; col <= ncols(); ++col) {
559 colinfo_[col].offset_ =
560 colinfo_[col - 1].offset_ +
561 colinfo_[col - 1].width_ +
562 colinfo_[col - 1].skip_ +
564 //colinfo_[col].lines_ * vlinesep();
568 dim.wid = colinfo_[ncols() - 1].offset_
569 + colinfo_[ncols() - 1].width_
570 //+ vlinesep() * colinfo_[ncols()].lines_
573 dim.asc = -rowinfo_[0].offset_
574 + rowinfo_[0].ascent_
575 //+ hlinesep() * rowinfo_[0].lines_
578 dim.des = rowinfo_[nrows() - 1].offset_
579 + rowinfo_[nrows() - 1].descent_
580 //+ hlinesep() * rowinfo_[nrows()].lines_
585 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
587 for (idx_type idx = 0; idx < nargs(); ++idx)
588 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
592 string MathGridInset::eolString(row_type row, bool fragile) const
596 if (!rowinfo_[row].crskip_.zero())
597 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
599 // make sure an upcoming '[' does not break anything
600 if (row + 1 < nrows()) {
601 MathArray const & c = cell(index(row + 1, 0));
602 if (c.size() && c.front()->getChar() == '[')
607 // only add \\ if necessary
608 if (eol.empty() && row + 1 == nrows())
611 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
615 string MathGridInset::eocString(col_type col, col_type lastcol) const
617 if (col + 1 == lastcol)
623 void MathGridInset::addRow(row_type row)
625 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
627 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
629 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
633 void MathGridInset::appendRow()
635 rowinfo_.push_back(RowInfo());
636 //cells_.insert(cells_.end(), ncols(), MathArray());
637 for (col_type col = 0; col < ncols(); ++col) {
638 cells_.push_back(cells_type::value_type());
639 cellinfo_.push_back(CellInfo());
644 void MathGridInset::delRow(row_type row)
649 cells_type::iterator it = cells_.begin() + row * ncols();
650 cells_.erase(it, it + ncols());
652 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
653 cellinfo_.erase(jt, jt + ncols());
655 rowinfo_.erase(rowinfo_.begin() + row);
659 void MathGridInset::copyRow(row_type row)
662 for (col_type col = 0; col < ncols(); ++col)
663 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
667 void MathGridInset::swapRow(row_type row)
671 if (row + 1 == nrows())
673 for (col_type col = 0; col < ncols(); ++col)
674 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
678 void MathGridInset::addCol(col_type newcol)
680 const col_type nc = ncols();
681 const row_type nr = nrows();
682 cells_type new_cells((nc + 1) * nr);
683 vector<CellInfo> new_cellinfo((nc + 1) * nr);
685 for (row_type row = 0; row < nr; ++row)
686 for (col_type col = 0; col < nc; ++col) {
687 new_cells[row * (nc + 1) + col + (col > newcol)]
688 = cells_[row * nc + col];
689 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
690 = cellinfo_[row * nc + col];
692 swap(cells_, new_cells);
693 swap(cellinfo_, new_cellinfo);
696 inf.skip_ = defaultColSpace(newcol);
697 inf.align_ = defaultColAlign(newcol);
698 colinfo_.insert(colinfo_.begin() + newcol, inf);
702 void MathGridInset::delCol(col_type col)
708 vector<CellInfo> tmpcellinfo;
709 for (col_type i = 0; i < nargs(); ++i)
710 if (i % ncols() != col) {
711 tmpcells.push_back(cells_[i]);
712 tmpcellinfo.push_back(cellinfo_[i]);
714 swap(cells_, tmpcells);
715 swap(cellinfo_, tmpcellinfo);
717 colinfo_.erase(colinfo_.begin() + col);
721 void MathGridInset::copyCol(col_type col)
724 for (row_type row = 0; row < nrows(); ++row)
725 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
729 void MathGridInset::swapCol(col_type col)
733 if (col + 1 == ncols())
735 for (row_type row = 0; row < nrows(); ++row)
736 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
740 int MathGridInset::cellXOffset(idx_type idx) const
742 col_type c = col(idx);
743 int x = colinfo_[c].offset_;
744 char align = colinfo_[c].align_;
745 if (align == 'r' || align == 'R')
746 x += colinfo_[c].width_ - cell(idx).width();
747 if (align == 'c' || align == 'C')
748 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
753 int MathGridInset::cellYOffset(idx_type idx) const
755 return rowinfo_[row(idx)].offset_;
759 bool MathGridInset::idxUpDown(LCursor & cur, bool up) const
762 if (cur.idx() < ncols())
764 cur.idx() -= ncols();
766 if (cur.idx() >= ncols() * (nrows() - 1))
768 cur.idx() += ncols();
770 cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo());
775 bool MathGridInset::idxLeft(LCursor & cur) const
777 // leave matrix if on the left hand edge
781 cur.pos() = cur.lastpos();
786 bool MathGridInset::idxRight(LCursor & cur) const
788 // leave matrix if on the right hand edge
789 if (cur.col() + 1 == ncols())
797 bool MathGridInset::idxFirst(LCursor & cur) const
804 cur.idx() = (nrows() - 1) * ncols();
807 cur.idx() = ((nrows() - 1) / 2) * ncols();
814 bool MathGridInset::idxLast(LCursor & cur) const
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::idxDelete(idx_type & idx)
833 // nothing to do if we have just one row
837 // nothing to do if we are in the middle of the last row of the inset
838 if (idx + ncols() > nargs())
841 // try to delete entire sequence of ncols() empty cells if possible
842 for (idx_type i = idx; i < idx + ncols(); ++i)
846 // move cells if necessary
847 for (idx_type i = index(row(idx), 0); i < idx; ++i)
848 swap(cell(i), cell(i + ncols()));
855 // undo effect of Ctrl-Tab (i.e. pull next cell)
856 //if (idx + 1 != nargs())
857 // cell(idx).swap(cell(idx + 1));
859 // we handled the event..
864 // reimplement old behaviour when pressing Delete in the last position
866 void MathGridInset::idxGlue(idx_type idx)
868 col_type c = col(idx);
869 if (c + 1 == ncols()) {
870 if (row(idx) + 1 != nrows()) {
871 for (col_type cc = 0; cc < ncols(); ++cc)
872 cell(idx).append(cell(idx + cc + 1));
873 delRow(row(idx) + 1);
876 cell(idx).append(cell(idx + 1));
877 for (col_type cc = c + 2; cc < ncols(); ++cc)
878 cell(idx - c + cc - 1) = cell(idx - c + cc);
879 cell(idx - c + ncols() - 1).clear();
884 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
886 return rowinfo_[row];
890 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
892 return rowinfo_[row];
896 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
898 row_type const ri = row(idx);
899 row_type const r1 = min(row(from), row(to));
900 row_type const r2 = max(row(from), row(to));
901 col_type const ci = col(idx);
902 col_type const c1 = min(col(from), col(to));
903 col_type const c2 = max(col(from), col(to));
904 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
909 void MathGridInset::normalize(NormalStream & os) const
912 for (row_type row = 0; row < nrows(); ++row) {
914 for (col_type col = 0; col < ncols(); ++col)
915 os << "[cell " << cell(index(row, col)) << ']';
922 void MathGridInset::mathmlize(MathMLStream & os) const
924 os << MTag("mtable");
925 for (row_type row = 0; row < nrows(); ++row) {
927 for (col_type col = 0; col < ncols(); ++col)
928 os << cell(index(row, col));
931 os << ETag("mtable");
935 void MathGridInset::write(WriteStream & os) const
937 for (row_type row = 0; row < nrows(); ++row) {
938 os << verboseHLine(rowinfo_[row].lines_);
939 // don't write & and empty cells at end of line
940 col_type lastcol = 0;
941 bool emptyline = true;
942 for (col_type col = 0; col < ncols(); ++col)
943 if (!cell(index(row, col)).empty()) {
947 for (col_type col = 0; col < lastcol; ++col)
948 os << cell(index(row, col)) << eocString(col, lastcol);
949 os << eolString(row, os.fragile());
950 // append newline only if line wasn't completely empty
951 // and this was not the last line in the grid
952 if (!emptyline && row + 1 < nrows())
955 string const s = verboseHLine(rowinfo_[nrows()].lines_);
956 if (!s.empty() && s != " ") {
964 int MathGridInset::colsep() const
970 int MathGridInset::rowsep() const
976 int MathGridInset::hlinesep() const
982 int MathGridInset::vlinesep() const
988 int MathGridInset::border() const
994 void MathGridInset::splitCell(LCursor & cur)
996 if (cur.idx() == cur.lastidx())
998 MathArray ar = cur.cell();
999 ar.erase(0, cur.pos());
1000 cur.cell().erase(cur.pos(), cur.lastpos());
1003 cur.cell().insert(0, ar);
1007 void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
1009 //lyxerr << "*** MathGridInset: request: " << cmd << endl;
1010 switch (cmd.action) {
1012 case LFUN_MOUSE_RELEASE:
1013 //if (cmd.button() == mouse_button::button3) {
1014 // GridInsetMailer(*this).showDialog();
1015 // return DispatchResult(true, true);
1017 MathNestInset::priv_dispatch(cur, cmd);
1020 case LFUN_INSET_DIALOG_UPDATE:
1021 GridInsetMailer(*this).updateDialog(&cur.bv());
1024 // insert file functions
1025 case LFUN_DELETE_LINE_FORWARD:
1026 //autocorrect_ = false;
1034 if (cur.idx() > cur.lastidx())
1035 cur.idx() = cur.lastidx();
1036 if (cur.pos() > cur.lastpos())
1037 cur.pos() = cur.lastpos();
1040 case LFUN_CELL_SPLIT:
1041 ////recordUndo(cur, Undo::ATOMIC);
1045 case LFUN_BREAKLINE: {
1046 ////recordUndo(cur, Undo::INSERT);
1047 row_type const r = cur.row();
1051 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1052 swap(cell(index(r, c)), cell(index(r + 1, c)));
1056 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1059 cur.idx() = cur.lastpos();
1061 //mathcursor->normalize();
1062 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1066 case LFUN_TABULAR_FEATURE: {
1067 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1068 istringstream is(cmd.argument);
1071 if (s == "valign-top")
1073 else if (s == "valign-middle")
1075 else if (s == "valign-bottom")
1077 else if (s == "align-left")
1078 halign('l', col(cur.idx()));
1079 else if (s == "align-right")
1080 halign('r', col(cur.idx()));
1081 else if (s == "align-center")
1082 halign('c', col(cur.idx()));
1083 else if (s == "append-row")
1084 for (int i = 0, n = extractInt(is); i < n; ++i)
1086 else if (s == "delete-row")
1087 for (int i = 0, n = extractInt(is); i < n; ++i) {
1089 if (cur.idx() > nargs())
1090 cur.idx() -= ncols();
1092 else if (s == "copy-row")
1093 for (int i = 0, n = extractInt(is); i < n; ++i)
1095 else if (s == "swap-row")
1097 else if (s == "append-column")
1098 for (int i = 0, n = extractInt(is); i < n; ++i) {
1099 row_type r = cur.row();
1100 col_type c = col(cur.idx());
1102 cur.idx() = index(r, c);
1104 else if (s == "delete-column")
1105 for (int i = 0, n = extractInt(is); i < n; ++i) {
1106 row_type r = cur.row();
1107 col_type c = col(cur.idx());
1108 delCol(col(cur.idx()));
1109 cur.idx() = index(r, c);
1110 if (cur.idx() > nargs())
1111 cur.idx() -= ncols();
1113 else if (s == "copy-column")
1114 copyCol(col(cur.idx()));
1115 else if (s == "swap-column")
1116 swapCol(col(cur.idx()));
1121 lyxerr << "returning FINISHED_LEFT" << endl;
1126 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1127 MathGridInset grid(1, 1);
1128 mathed_parse_normal(grid, cmd.argument);
1129 if (grid.nargs() == 1) {
1130 // single cell/part of cell
1131 cur.cell().insert(cur.pos(), grid.cell(0));
1132 cur.pos() += grid.cell(0).size();
1135 col_type const numcols =
1136 min(grid.ncols(), ncols() - col(cur.idx()));
1137 row_type const numrows =
1138 min(grid.nrows(), nrows() - cur.row());
1139 for (row_type r = 0; r < numrows; ++r) {
1140 for (col_type c = 0; c < numcols; ++c) {
1141 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1142 cell(i).insert(0, grid.cell(grid.index(r, c)));
1144 // append the left over horizontal cells to the last column
1145 idx_type i = index(r + cur.row(), ncols() - 1);
1146 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1147 cell(i).append(grid.cell(grid.index(r, c)));
1149 // append the left over vertical cells to the last _cell_
1150 idx_type i = nargs() - 1;
1151 for (row_type r = numrows; r < grid.nrows(); ++r)
1152 for (col_type c = 0; c < grid.ncols(); ++c)
1153 cell(i).append(grid.cell(grid.index(r, c)));
1160 case LFUN_WORDLEFTSEL:
1162 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
1163 cur.macroModeClose();
1166 else if (cur.idx() != 0)
1169 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1172 case LFUN_WORDRIGHTSEL:
1173 case LFUN_WORDRIGHT:
1176 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
1177 cur.macroModeClose();
1179 if (cur.pos() != cur.lastpos())
1180 cur.pos() = cur.lastpos();
1181 else if (cur.idx() != cur.lastidx())
1182 cur.idx() = cur.lastidx();
1184 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1188 MathNestInset::priv_dispatch(cur, cmd);
1193 bool MathGridInset::getStatus(LCursor & cur, FuncRequest const & cmd,
1194 FuncStatus & flag) const
1197 switch (cmd.action) {
1198 case LFUN_TABULAR_FEATURE:
1200 // should be more precise
1201 if (v_align_ == '\0') {
1205 if (cmd.argument.empty()) {
1209 if (!contains("tcb", cmd.argument[0])) {
1213 flag.setOnOff(cmd.argument[0] == v_align_);
1218 ret = MathNestInset::getStatus(cur, cmd, flag);