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);
461 metricsMarkers2(dim_);
465 void MathGridInset::metrics(MetricsInfo & mi, Dimension & dim) const
472 void MathGridInset::draw(PainterInfo & pi, int x, int y) const
474 for (idx_type idx = 0; idx < nargs(); ++idx)
475 cell(idx).draw(pi, x + cellXOffset(idx), y + cellYOffset(idx));
477 for (row_type row = 0; row <= nrows(); ++row)
478 for (int i = 0; i < rowinfo_[row].lines_; ++i) {
479 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
480 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
481 pi.pain.line(x + 1, yy,
482 x + dim_.width() - 1, yy,
486 for (col_type col = 0; col <= ncols(); ++col)
487 for (int i = 0; i < colinfo_[col].lines_; ++i) {
488 int xx = x + colinfo_[col].offset_
489 - i * vlinesep() - vlinesep()/2 - colsep()/2;
490 pi.pain.line(xx, y - dim_.ascent() + 1,
491 xx, y + dim_.descent() - 1,
494 drawMarkers2(pi, x, y);
498 void MathGridInset::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
500 // let the cells adjust themselves
501 //MathNestInset::metrics(mi);
502 for (idx_type i = 0; i < nargs(); ++i)
503 cell(i).metricsT(mi, dim);
505 // compute absolute sizes of vertical structure
506 for (row_type row = 0; row < nrows(); ++row) {
509 for (col_type col = 0; col < ncols(); ++col) {
510 MathArray const & c = cell(index(row, col));
511 asc = max(asc, c.ascent());
512 desc = max(desc, c.descent());
514 rowinfo_[row].ascent_ = asc;
515 rowinfo_[row].descent_ = desc;
517 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
518 rowinfo_[nrows()].ascent_ = 0;
519 rowinfo_[nrows()].descent_ = 0;
521 // compute vertical offsets
522 rowinfo_[0].offset_ = 0;
523 for (row_type row = 1; row <= nrows(); ++row) {
524 rowinfo_[row].offset_ =
525 rowinfo_[row - 1].offset_ +
526 rowinfo_[row - 1].descent_ +
527 //rowinfo_[row - 1].skipPixels() +
529 //rowinfo_[row].lines_ * hlinesep() +
530 rowinfo_[row].ascent_;
533 // adjust vertical offset
540 h = rowinfo_[nrows() - 1].offset_;
543 h = rowinfo_[nrows() - 1].offset_ / 2;
545 for (row_type row = 0; row <= nrows(); ++row)
546 rowinfo_[row].offset_ -= h;
549 // compute absolute sizes of horizontal structure
550 for (col_type col = 0; col < ncols(); ++col) {
552 for (row_type row = 0; row < nrows(); ++row)
553 wid = max(wid, cell(index(row, col)).width());
554 colinfo_[col].width_ = wid;
556 colinfo_[ncols()].width_ = 0;
558 // compute horizontal offsets
559 colinfo_[0].offset_ = border();
560 for (col_type col = 1; col <= ncols(); ++col) {
561 colinfo_[col].offset_ =
562 colinfo_[col - 1].offset_ +
563 colinfo_[col - 1].width_ +
564 colinfo_[col - 1].skip_ +
566 //colinfo_[col].lines_ * vlinesep();
570 dim.wid = colinfo_[ncols() - 1].offset_
571 + colinfo_[ncols() - 1].width_
572 //+ vlinesep() * colinfo_[ncols()].lines_
575 dim.asc = -rowinfo_[0].offset_
576 + rowinfo_[0].ascent_
577 //+ hlinesep() * rowinfo_[0].lines_
580 dim.des = rowinfo_[nrows() - 1].offset_
581 + rowinfo_[nrows() - 1].descent_
582 //+ hlinesep() * rowinfo_[nrows()].lines_
587 void MathGridInset::drawT(TextPainter & pain, int x, int y) const
589 for (idx_type idx = 0; idx < nargs(); ++idx)
590 cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
594 string MathGridInset::eolString(row_type row, bool fragile) const
598 if (!rowinfo_[row].crskip_.zero())
599 eol += '[' + rowinfo_[row].crskip_.asLatexString() + ']';
601 // make sure an upcoming '[' does not break anything
602 if (row + 1 < nrows()) {
603 MathArray const & c = cell(index(row + 1, 0));
604 if (c.size() && c.front()->getChar() == '[')
609 // only add \\ if necessary
610 if (eol.empty() && row + 1 == nrows())
613 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
617 string MathGridInset::eocString(col_type col, col_type lastcol) const
619 if (col + 1 == lastcol)
625 void MathGridInset::addRow(row_type row)
627 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
629 (cells_.begin() + (row + 1) * ncols(), ncols(), MathArray());
631 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
635 void MathGridInset::appendRow()
637 rowinfo_.push_back(RowInfo());
638 //cells_.insert(cells_.end(), ncols(), MathArray());
639 for (col_type col = 0; col < ncols(); ++col) {
640 cells_.push_back(cells_type::value_type());
641 cellinfo_.push_back(CellInfo());
646 void MathGridInset::delRow(row_type row)
651 cells_type::iterator it = cells_.begin() + row * ncols();
652 cells_.erase(it, it + ncols());
654 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
655 cellinfo_.erase(jt, jt + ncols());
657 rowinfo_.erase(rowinfo_.begin() + row);
661 void MathGridInset::copyRow(row_type row)
664 for (col_type col = 0; col < ncols(); ++col)
665 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
669 void MathGridInset::swapRow(row_type row)
673 if (row + 1 == nrows())
675 for (col_type col = 0; col < ncols(); ++col)
676 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
680 void MathGridInset::addCol(col_type newcol)
682 const col_type nc = ncols();
683 const row_type nr = nrows();
684 cells_type new_cells((nc + 1) * nr);
685 vector<CellInfo> new_cellinfo((nc + 1) * nr);
687 for (row_type row = 0; row < nr; ++row)
688 for (col_type col = 0; col < nc; ++col) {
689 new_cells[row * (nc + 1) + col + (col > newcol)]
690 = cells_[row * nc + col];
691 new_cellinfo[row * (nc + 1) + col + (col > newcol)]
692 = cellinfo_[row * nc + col];
694 swap(cells_, new_cells);
695 swap(cellinfo_, new_cellinfo);
698 inf.skip_ = defaultColSpace(newcol);
699 inf.align_ = defaultColAlign(newcol);
700 colinfo_.insert(colinfo_.begin() + newcol, inf);
704 void MathGridInset::delCol(col_type col)
710 vector<CellInfo> tmpcellinfo;
711 for (col_type i = 0; i < nargs(); ++i)
712 if (i % ncols() != col) {
713 tmpcells.push_back(cells_[i]);
714 tmpcellinfo.push_back(cellinfo_[i]);
716 swap(cells_, tmpcells);
717 swap(cellinfo_, tmpcellinfo);
719 colinfo_.erase(colinfo_.begin() + col);
723 void MathGridInset::copyCol(col_type col)
726 for (row_type row = 0; row < nrows(); ++row)
727 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
731 void MathGridInset::swapCol(col_type col)
735 if (col + 1 == ncols())
737 for (row_type row = 0; row < nrows(); ++row)
738 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
742 int MathGridInset::cellXOffset(idx_type idx) const
744 col_type c = col(idx);
745 int x = colinfo_[c].offset_;
746 char align = colinfo_[c].align_;
747 if (align == 'r' || align == 'R')
748 x += colinfo_[c].width_ - cell(idx).width();
749 if (align == 'c' || align == 'C')
750 x += (colinfo_[c].width_ - cell(idx).width()) / 2;
755 int MathGridInset::cellYOffset(idx_type idx) const
757 return rowinfo_[row(idx)].offset_;
761 bool MathGridInset::idxUpDown(LCursor & cur, bool up) const
764 if (cur.idx() < ncols())
766 cur.idx() -= ncols();
768 if (cur.idx() >= ncols() * (nrows() - 1))
770 cur.idx() += ncols();
772 cur.pos() = cur.cell().x2pos(cur.x_target() - cur.cell().xo());
777 bool MathGridInset::idxLeft(LCursor & cur) const
779 // leave matrix if on the left hand edge
783 cur.pos() = cur.lastpos();
788 bool MathGridInset::idxRight(LCursor & cur) const
790 // leave matrix if on the right hand edge
791 if (cur.col() + 1 == ncols())
799 bool MathGridInset::idxFirst(LCursor & cur) const
806 cur.idx() = (nrows() - 1) * ncols();
809 cur.idx() = ((nrows() - 1) / 2) * ncols();
816 bool MathGridInset::idxLast(LCursor & cur) const
820 cur.idx() = ncols() - 1;
823 cur.idx() = nargs() - 1;
826 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
828 cur.pos() = cur.lastpos();
833 bool MathGridInset::idxDelete(idx_type & idx)
835 // nothing to do if we have just one row
839 // nothing to do if we are in the middle of the last row of the inset
840 if (idx + ncols() > nargs())
843 // try to delete entire sequence of ncols() empty cells if possible
844 for (idx_type i = idx; i < idx + ncols(); ++i)
848 // move cells if necessary
849 for (idx_type i = index(row(idx), 0); i < idx; ++i)
850 swap(cell(i), cell(i + ncols()));
857 // undo effect of Ctrl-Tab (i.e. pull next cell)
858 //if (idx + 1 != nargs())
859 // cell(idx).swap(cell(idx + 1));
861 // we handled the event..
866 // reimplement old behaviour when pressing Delete in the last position
868 void MathGridInset::idxGlue(idx_type idx)
870 col_type c = col(idx);
871 if (c + 1 == ncols()) {
872 if (row(idx) + 1 != nrows()) {
873 for (col_type cc = 0; cc < ncols(); ++cc)
874 cell(idx).append(cell(idx + cc + 1));
875 delRow(row(idx) + 1);
878 cell(idx).append(cell(idx + 1));
879 for (col_type cc = c + 2; cc < ncols(); ++cc)
880 cell(idx - c + cc - 1) = cell(idx - c + cc);
881 cell(idx - c + ncols() - 1).clear();
886 MathGridInset::RowInfo const & MathGridInset::rowinfo(row_type row) const
888 return rowinfo_[row];
892 MathGridInset::RowInfo & MathGridInset::rowinfo(row_type row)
894 return rowinfo_[row];
898 bool MathGridInset::idxBetween(idx_type idx, idx_type from, idx_type to) const
900 row_type const ri = row(idx);
901 row_type const r1 = min(row(from), row(to));
902 row_type const r2 = max(row(from), row(to));
903 col_type const ci = col(idx);
904 col_type const c1 = min(col(from), col(to));
905 col_type const c2 = max(col(from), col(to));
906 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
911 void MathGridInset::normalize(NormalStream & os) const
914 for (row_type row = 0; row < nrows(); ++row) {
916 for (col_type col = 0; col < ncols(); ++col)
917 os << "[cell " << cell(index(row, col)) << ']';
924 void MathGridInset::mathmlize(MathMLStream & os) const
926 os << MTag("mtable");
927 for (row_type row = 0; row < nrows(); ++row) {
929 for (col_type col = 0; col < ncols(); ++col)
930 os << cell(index(row, col));
933 os << ETag("mtable");
937 void MathGridInset::write(WriteStream & os) const
939 for (row_type row = 0; row < nrows(); ++row) {
940 os << verboseHLine(rowinfo_[row].lines_);
941 // don't write & and empty cells at end of line
942 col_type lastcol = 0;
943 bool emptyline = true;
944 for (col_type col = 0; col < ncols(); ++col)
945 if (!cell(index(row, col)).empty()) {
949 for (col_type col = 0; col < lastcol; ++col)
950 os << cell(index(row, col)) << eocString(col, lastcol);
951 os << eolString(row, os.fragile());
952 // append newline only if line wasn't completely empty
953 // and this was not the last line in the grid
954 if (!emptyline && row + 1 < nrows())
957 string const s = verboseHLine(rowinfo_[nrows()].lines_);
958 if (!s.empty() && s != " ") {
966 int MathGridInset::colsep() const
972 int MathGridInset::rowsep() const
978 int MathGridInset::hlinesep() const
984 int MathGridInset::vlinesep() const
990 int MathGridInset::border() const
996 void MathGridInset::splitCell(LCursor & cur)
998 if (cur.idx() == cur.lastidx())
1000 MathArray ar = cur.cell();
1001 ar.erase(0, cur.pos());
1002 cur.cell().erase(cur.pos(), cur.lastpos());
1005 cur.cell().insert(0, ar);
1009 void MathGridInset::priv_dispatch(LCursor & cur, FuncRequest & cmd)
1011 //lyxerr << "*** MathGridInset: request: " << cmd << endl;
1012 switch (cmd.action) {
1014 case LFUN_MOUSE_RELEASE:
1015 //if (cmd.button() == mouse_button::button3) {
1016 // GridInsetMailer(*this).showDialog();
1017 // return DispatchResult(true, true);
1019 MathNestInset::priv_dispatch(cur, cmd);
1022 case LFUN_INSET_DIALOG_UPDATE:
1023 GridInsetMailer(*this).updateDialog(&cur.bv());
1026 // insert file functions
1027 case LFUN_DELETE_LINE_FORWARD:
1028 //autocorrect_ = false;
1036 if (cur.idx() > cur.lastidx())
1037 cur.idx() = cur.lastidx();
1038 if (cur.pos() > cur.lastpos())
1039 cur.pos() = cur.lastpos();
1042 case LFUN_CELL_SPLIT:
1043 ////recordUndo(cur, Undo::ATOMIC);
1047 case LFUN_BREAKLINE: {
1048 ////recordUndo(cur, Undo::INSERT);
1049 row_type const r = cur.row();
1053 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1054 swap(cell(index(r, c)), cell(index(r + 1, c)));
1058 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1061 cur.idx() = cur.lastpos();
1063 //mathcursor->normalize();
1064 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1068 case LFUN_TABULAR_FEATURE: {
1069 //lyxerr << "handling tabular-feature " << cmd.argument << endl;
1070 istringstream is(cmd.argument);
1073 if (s == "valign-top")
1075 else if (s == "valign-middle")
1077 else if (s == "valign-bottom")
1079 else if (s == "align-left")
1080 halign('l', col(cur.idx()));
1081 else if (s == "align-right")
1082 halign('r', col(cur.idx()));
1083 else if (s == "align-center")
1084 halign('c', col(cur.idx()));
1085 else if (s == "append-row")
1086 for (int i = 0, n = extractInt(is); i < n; ++i)
1088 else if (s == "delete-row")
1089 for (int i = 0, n = extractInt(is); i < n; ++i) {
1091 if (cur.idx() > nargs())
1092 cur.idx() -= ncols();
1094 else if (s == "copy-row")
1095 for (int i = 0, n = extractInt(is); i < n; ++i)
1097 else if (s == "swap-row")
1099 else if (s == "append-column")
1100 for (int i = 0, n = extractInt(is); i < n; ++i) {
1101 row_type r = cur.row();
1102 col_type c = col(cur.idx());
1104 cur.idx() = index(r, c);
1106 else if (s == "delete-column")
1107 for (int i = 0, n = extractInt(is); i < n; ++i) {
1108 row_type r = cur.row();
1109 col_type c = col(cur.idx());
1110 delCol(col(cur.idx()));
1111 cur.idx() = index(r, c);
1112 if (cur.idx() > nargs())
1113 cur.idx() -= ncols();
1115 else if (s == "copy-column")
1116 copyCol(col(cur.idx()));
1117 else if (s == "swap-column")
1118 swapCol(col(cur.idx()));
1123 lyxerr << "returning FINISHED_LEFT" << endl;
1128 //lyxerr << "pasting '" << cmd.argument << "'" << endl;
1129 MathGridInset grid(1, 1);
1130 mathed_parse_normal(grid, cmd.argument);
1131 if (grid.nargs() == 1) {
1132 // single cell/part of cell
1133 cur.cell().insert(cur.pos(), grid.cell(0));
1134 cur.pos() += grid.cell(0).size();
1137 col_type const numcols =
1138 min(grid.ncols(), ncols() - col(cur.idx()));
1139 row_type const numrows =
1140 min(grid.nrows(), nrows() - cur.row());
1141 for (row_type r = 0; r < numrows; ++r) {
1142 for (col_type c = 0; c < numcols; ++c) {
1143 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1144 cell(i).insert(0, grid.cell(grid.index(r, c)));
1146 // append the left over horizontal cells to the last column
1147 idx_type i = index(r + cur.row(), ncols() - 1);
1148 for (MathInset::col_type c = numcols; c < grid.ncols(); ++c)
1149 cell(i).append(grid.cell(grid.index(r, c)));
1151 // append the left over vertical cells to the last _cell_
1152 idx_type i = nargs() - 1;
1153 for (row_type r = numrows; r < grid.nrows(); ++r)
1154 for (col_type c = 0; c < grid.ncols(); ++c)
1155 cell(i).append(grid.cell(grid.index(r, c)));
1162 case LFUN_WORDLEFTSEL:
1164 cur.selHandle(cmd.action == LFUN_WORDLEFTSEL || cmd.action == LFUN_HOMESEL);
1165 cur.macroModeClose();
1168 else if (cur.idx() != 0)
1171 cmd = FuncRequest(LFUN_FINISHED_LEFT);
1174 case LFUN_WORDRIGHTSEL:
1175 case LFUN_WORDRIGHT:
1178 cur.selHandle(cmd.action == LFUN_WORDRIGHTSEL || cmd.action == LFUN_ENDSEL);
1179 cur.macroModeClose();
1181 if (cur.pos() != cur.lastpos())
1182 cur.pos() = cur.lastpos();
1183 else if (cur.idx() != cur.lastidx())
1184 cur.idx() = cur.lastidx();
1186 cmd = FuncRequest(LFUN_FINISHED_RIGHT);
1190 MathNestInset::priv_dispatch(cur, cmd);
1195 bool MathGridInset::getStatus(LCursor & cur, FuncRequest const & cmd,
1196 FuncStatus & flag) const
1199 switch (cmd.action) {
1200 case LFUN_TABULAR_FEATURE:
1202 // should be more precise
1203 if (v_align_ == '\0') {
1207 if (cmd.argument.empty()) {
1211 if (!contains("tcb", cmd.argument[0])) {
1215 flag.setOnOff(cmd.argument[0] == v_align_);
1220 ret = MathNestInset::getStatus(cur, cmd, flag);