2 * \file InsetMathGrid.cpp
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.
14 #include "InsetMathGrid.h"
16 #include "InsetMathUnknown.h"
18 #include "MathParser.h"
19 #include "MathStream.h"
20 #include "MetricsInfo.h"
23 #include "BufferParams.h"
24 #include "BufferView.h"
25 #include "CutAndPaste.h"
26 #include "FuncStatus.h"
28 #include "FuncRequest.h"
30 #include "frontends/Clipboard.h"
31 #include "frontends/Painter.h"
33 #include "support/debug.h"
34 #include "support/docstream.h"
35 #include "support/gettext.h"
36 #include "support/lstrings.h"
38 #include "support/lassert.h"
43 using namespace lyx::support;
49 static docstring verboseHLine(int n)
52 for (int i = 0; i < n; ++i)
60 static int extractInt(istream & is)
64 return (num == 0) ? 1 : num;
68 static void resetGrid(InsetMathGrid & grid)
70 while (grid.ncols() > 1)
71 grid.delCol(grid.ncols() - 1);
72 while (grid.nrows() > 1)
73 grid.delRow(grid.nrows() - 1);
74 grid.cell(0).erase(0, grid.cell(0).size());
80 //////////////////////////////////////////////////////////////
83 InsetMathGrid::CellInfo::CellInfo()
84 : multi_(CELL_NORMAL), glue_(0), begin_(0), end_(0)
89 //////////////////////////////////////////////////////////////
92 InsetMathGrid::RowInfo::RowInfo()
93 : descent_(0), ascent_(0), offset_(0), lines_(0), skip_(0),
99 int InsetMathGrid::RowInfo::skipPixels(MetricsInfo const & mi) const
101 return crskip_.inPixels(mi.base);
106 //////////////////////////////////////////////////////////////
109 InsetMathGrid::ColInfo::ColInfo()
110 : align_('c'), width_(0), offset_(0), lines_(0), skip_(0)
114 //////////////////////////////////////////////////////////////
117 InsetMathGrid::InsetMathGrid(Buffer * buf)
118 : InsetMathNest(buf, 1),
128 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n)
129 : InsetMathNest(buf, m * n),
139 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n, char v,
141 : InsetMathNest(buf, m * n),
148 setVerticalAlignment(v);
149 setHorizontalAlignments(h);
153 Inset * InsetMathGrid::clone() const
155 return new InsetMathGrid(*this);
159 InsetMath::idx_type InsetMathGrid::index(row_type row, col_type col) const
161 return col + ncols() * row;
165 void InsetMathGrid::setDefaults()
168 lyxerr << "positive number of columns expected" << endl;
170 // lyxerr << "positive number of rows expected" << endl;
171 for (col_type col = 0; col < ncols(); ++col) {
172 colinfo_[col].align_ = defaultColAlign(col);
173 colinfo_[col].skip_ = defaultColSpace(col);
174 colinfo_[col].special_.clear();
176 for (idx_type idx = 0; idx < nargs(); ++idx)
177 cellinfo_[idx].multi_ = CELL_NORMAL;
181 bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
183 if (str == "\\hline") {
184 FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
186 if (getStatus(cur, fr, status)) {
187 if (status.enabled()) {
188 rowinfo_[cur.row()].lines_++;
193 return InsetMathNest::interpretString(cur, str);
197 void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
200 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
203 colinfo_[col].lines_++;
204 } else if ((c == 'p' || c == 'm' || c == 'b'||
205 c == '!' || c == '@' || c == '>' || c == '<') &&
206 it + 1 != hh.end() && *(it + 1) == '{') {
207 // @{decl.} and p{width} are standard LaTeX, the
208 // others are extensions by array.sty
209 bool const newcolumn = c == 'p' || c == 'm' || c == 'b';
211 // this declares a new column
213 // Only intercolumn stuff is allowed
214 // in the last dummy column
216 colinfo_[col].align_ = 'l';
218 // this is intercolumn stuff
219 if (colinfo_[col].special_.empty())
220 // Overtake possible lines
221 colinfo_[col].special_ = docstring(colinfo_[col].lines_, '|');
225 while (it != hh.end()) {
227 colinfo_[col].special_ += c;
233 if (brace_open > 0 && brace_open == brace_close)
238 colinfo_[col].lines_ = count(
239 colinfo_[col].special_.begin(),
240 colinfo_[col].special_.end(), '|');
241 LYXERR(Debug::MATHED, "special column separator: `"
242 << to_utf8(colinfo_[col].special_) << '\'');
244 colinfo_[col].lines_ = 0;
245 colinfo_[col].special_.clear();
247 } else if (col >= ncols()) {
248 // Only intercolumn stuff is allowed in the last
251 } else if (c == 'c' || c == 'l' || c == 'r') {
252 colinfo_[col].align_ = static_cast<char>(c);
253 if (!colinfo_[col].special_.empty()) {
254 colinfo_[col].special_ += c;
255 colinfo_[col].lines_ = count(
256 colinfo_[col].special_.begin(),
257 colinfo_[col].special_.end(), '|');
258 LYXERR(Debug::MATHED, "special column separator: `"
259 << to_utf8(colinfo_[col].special_) << '\'');
262 colinfo_[col].lines_ = 0;
263 colinfo_[col].special_.clear();
265 lyxerr << "unknown column separator: '" << c << "'" << endl;
270 col_type n = hh.size();
273 for (col_type col = 0; col < n; ++col)
274 colinfo_[col].align_ = hh[col];
279 InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh)
282 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
283 if (*it == 'c' || *it == 'l' || *it == 'r'||
284 *it == 'p' || *it == 'm' || *it == 'b')
286 // let's have at least one column, even if we did not recognize its
294 void InsetMathGrid::setHorizontalAlignment(char h, col_type col)
296 colinfo_[col].align_ = h;
297 if (!colinfo_[col].special_.empty()) {
298 char_type & c = colinfo_[col].special_[colinfo_[col].special_.size() - 1];
299 if (c == 'l' || c == 'c' || c == 'r')
302 // FIXME: Change alignment of p, m and b columns, too
306 char InsetMathGrid::horizontalAlignment(col_type col) const
308 return colinfo_[col].align_;
312 docstring InsetMathGrid::horizontalAlignments() const
315 for (col_type col = 0; col < ncols(); ++col) {
316 if (colinfo_[col].special_.empty()) {
317 res += docstring(colinfo_[col].lines_, '|');
318 res += colinfo_[col].align_;
320 res += colinfo_[col].special_;
322 if (colinfo_[ncols()].special_.empty())
323 return res + docstring(colinfo_[ncols()].lines_, '|');
324 return res + colinfo_[ncols()].special_;
328 void InsetMathGrid::setVerticalAlignment(char c)
334 char InsetMathGrid::verticalAlignment() const
340 InsetMathGrid::col_type InsetMathGrid::ncols() const
342 return colinfo_.size() - 1;
346 InsetMathGrid::row_type InsetMathGrid::nrows() const
348 return rowinfo_.size() - 1;
352 InsetMathGrid::col_type InsetMathGrid::col(idx_type idx) const
354 return idx % ncols();
358 InsetMathGrid::row_type InsetMathGrid::row(idx_type idx) const
360 return idx / ncols();
364 InsetMathGrid::col_type InsetMathGrid::ncellcols(idx_type idx) const
367 if (cellinfo_[idx].multi_ == CELL_NORMAL)
369 // If the cell at idx is already CELL_PART_OF_MULTICOLUMN we return
370 // the number of remaining columns, not the ones of the complete
371 // multicolumn cell. This makes it possible to always go to the next
372 // cell with idx + ncellcols(idx) - 1.
373 row_type const r = row(idx);
374 while (idx+cols < nargs() && row(idx+cols) == r &&
375 cellinfo_[idx+cols].multi_ == CELL_PART_OF_MULTICOLUMN)
381 void InsetMathGrid::vcrskip(Length const & crskip, row_type row)
383 rowinfo_[row].crskip_ = crskip;
387 Length InsetMathGrid::vcrskip(row_type row) const
389 return rowinfo_[row].crskip_;
393 void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
395 // let the cells adjust themselves
396 for (idx_type i = 0; i < nargs(); ++i) {
397 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
399 cell(i).metrics(mi, dimc);
403 BufferView & bv = *mi.base.bv;
405 // compute absolute sizes of vertical structure
406 for (row_type row = 0; row < nrows(); ++row) {
409 for (col_type col = 0; col < ncols(); ++col) {
410 idx_type const i = index(row, col);
411 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
412 Dimension const & dimc = cell(i).dimension(bv);
413 asc = max(asc, dimc.asc);
414 desc = max(desc, dimc.des);
417 rowinfo_[row].ascent_ = asc;
418 rowinfo_[row].descent_ = desc;
420 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
421 rowinfo_[nrows()].ascent_ = 0;
422 rowinfo_[nrows()].descent_ = 0;
424 // compute vertical offsets
425 rowinfo_[0].offset_ = 0;
426 for (row_type row = 1; row <= nrows(); ++row) {
427 rowinfo_[row].offset_ =
428 rowinfo_[row - 1].offset_ +
429 rowinfo_[row - 1].descent_ +
430 rowinfo_[row - 1].skipPixels(mi) +
432 rowinfo_[row].lines_ * hlinesep() +
433 rowinfo_[row].ascent_;
436 // adjust vertical offset
443 h = rowinfo_[nrows() - 1].offset_;
446 h = rowinfo_[nrows() - 1].offset_ / 2;
448 for (row_type row = 0; row <= nrows(); ++row)
449 rowinfo_[row].offset_ -= h;
452 // multicolumn cell widths, as a map from first column to width in a
453 // vector of last columns.
454 // This is only used if the grid has more than one row, since for
455 // one-row grids multicolumn cells do not need special handling
456 vector<map<col_type, int> > mcolwidths(ncols());
458 // compute absolute sizes of horizontal structure
459 for (col_type col = 0; col < ncols(); ++col) {
461 for (row_type row = 0; row < nrows(); ++row) {
462 idx_type const i = index(row, col);
463 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
464 int const w = cell(i).dimension(bv).wid;
465 col_type const cols = ncellcols(i);
466 if (cols > 1 && nrows() > 1) {
467 col_type last = col+cols-1;
468 LASSERT(last < ncols(), last = ncols()-1);
469 map<col_type, int>::iterator it =
470 mcolwidths[last].find(col);
471 if (it == mcolwidths[last].end())
472 mcolwidths[last][col] = w;
474 it->second = max(it->second, w);
479 colinfo_[col].width_ = wid;
481 colinfo_[ncols()].width_ = 0;
483 // compute horizontal offsets
484 colinfo_[0].offset_ = border();
485 for (col_type col = 1; col <= ncols(); ++col) {
486 colinfo_[col].offset_ =
487 colinfo_[col - 1].offset_ +
488 colinfo_[col - 1].width_ +
489 colinfo_[col - 1].skip_ +
491 colinfo_[col].lines_ * vlinesep();
494 // increase column widths for multicolumn cells if needed
495 // FIXME: multicolumn lines are not yet considered
496 for (col_type last = 0; last < ncols(); ++last) {
497 map<col_type, int> const & widths = mcolwidths[last];
498 // We increase the width of the last column of the multicol
499 // cell (some sort of left alignment). Since we iterate through
500 // the last and the first columns from left to right, we ensure
501 // that increased widths of previous columns are correctly
502 // taken into account for later columns, thus preventing
503 // unneeded width increasing.
504 for (map<col_type, int>::const_iterator it = widths.begin();
505 it != widths.end(); ++it) {
506 int const wid = it->second;
507 col_type const first = it->first;
508 int const nextoffset =
509 colinfo_[first].offset_ +
511 colinfo_[last].skip_ +
513 colinfo_[last+1].lines_ * vlinesep();
514 int const dx = nextoffset - colinfo_[last+1].offset_;
516 colinfo_[last].width_ += dx;
517 for (col_type col = last + 1; col <= ncols(); ++col)
518 colinfo_[col].offset_ += dx;
524 dim.wid = colinfo_[ncols() - 1].offset_
525 + colinfo_[ncols() - 1].width_
526 + vlinesep() * colinfo_[ncols()].lines_
529 dim.asc = - rowinfo_[0].offset_
530 + rowinfo_[0].ascent_
531 + hlinesep() * rowinfo_[0].lines_
534 dim.des = rowinfo_[nrows() - 1].offset_
535 + rowinfo_[nrows() - 1].descent_
536 + hlinesep() * rowinfo_[nrows()].lines_
541 // Increase ws_[i] for 'R' columns (except the first one)
542 for (int i = 1; i < nc_; ++i)
543 if (align_[i] == 'R')
544 ws_[i] += 10 * df_width;
545 // Increase ws_[i] for 'C' column
546 if (align_[0] == 'C')
547 if (ws_[0] < 7 * workwidth / 8)
548 ws_[0] = 7 * workwidth / 8;
552 for (cxrow = row_.begin(); cxrow; ++cxrow) {
555 for (int i = 0; i < nc_; ++i) {
557 if (cxrow->getTab(i) <= 0) {
558 cxrow->setTab(i, df_width);
566 lf = (ws_[i] - cxrow->getTab(i))/2;
570 lf = ws_[i] - cxrow->getTab(i);
573 if (cxrow == row_.begin())
575 else if (cxrow.is_last())
576 lf = ws_[i] - cxrow->getTab(i);
578 lf = (ws_[i] - cxrow->getTab(i))/2;
581 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
582 cxrow->setTab(i, lf + rg);
583 rg = ws_[i] - ww + colsep();
584 if (cxrow == row_.begin())
585 width += ws_[i] + colsep();
587 cxrow->setBaseline(cxrow->getBaseline() - ascent);
590 metricsMarkers2(dim);
591 // Cache the inset dimension.
592 setDimCache(mi, dim);
596 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
598 drawWithMargin(pi, x, y, 1, 1);
602 void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
603 int lmargin, int rmargin) const
605 Dimension const dim = dimension(*pi.base.bv);
606 BufferView const & bv = *pi.base.bv;
608 for (idx_type idx = 0; idx < nargs(); ++idx) {
609 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN) {
611 x + lmargin + cellXOffset(bv, idx),
612 y + cellYOffset(idx));
614 // draw inner lines cell by cell because of possible multicolumns
615 // FIXME: multicolumn lines are not yet considered
616 row_type const r = row(idx);
617 col_type const c = col(idx);
618 if (r > 0 && r < nrows()) {
619 for (unsigned int i = 0; i < rowinfo_[r].lines_; ++i) {
620 int yy = y + rowinfo_[r].offset_
621 - rowinfo_[r].ascent_
623 - hlinesep()/2 - rowsep()/2;
625 x + lmargin + colinfo_[c].offset_,
627 x + lmargin + colinfo_[c+1].offset_,
628 yy, Color_foreground);
631 if (c > 0 && c < ncols()) {
632 for (unsigned int i = 0; i < colinfo_[c].lines_; ++i) {
634 + colinfo_[c].offset_
636 - vlinesep()/2 - colsep()/2;
638 rowinfo_[r].offset_ - rowinfo_[r].ascent_,
640 rowinfo_[r].offset_ + rowinfo_[r].descent_,
647 // draw outer lines in one go
648 for (row_type row = 0; row <= nrows(); row += nrows())
649 for (unsigned int i = 0; i < rowinfo_[row].lines_; ++i) {
650 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
651 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
652 pi.pain.line(x + lmargin + 1, yy,
653 x + dim.width() - rmargin - 1, yy,
657 for (col_type col = 0; col <= ncols(); col += ncols())
658 for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
659 int xx = x + lmargin + colinfo_[col].offset_
660 - i * vlinesep() - vlinesep()/2 - colsep()/2;
661 pi.pain.line(xx, y - dim.ascent() + 1,
662 xx, y + dim.descent() - 1,
665 drawMarkers2(pi, x, y);
669 void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
671 // let the cells adjust themselves
672 for (idx_type i = 0; i < nargs(); ++i)
673 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
674 cell(i).metricsT(mi, dim);
676 // compute absolute sizes of vertical structure
677 for (row_type row = 0; row < nrows(); ++row) {
680 for (col_type col = 0; col < ncols(); ++col) {
681 idx_type const i = index(row, col);
682 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
683 //MathData const & c = cell(i);
686 asc = max(asc, dimc.ascent());
687 desc = max(desc, dimc.descent());
690 rowinfo_[row].ascent_ = asc;
691 rowinfo_[row].descent_ = desc;
693 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
694 rowinfo_[nrows()].ascent_ = 0;
695 rowinfo_[nrows()].descent_ = 0;
697 // compute vertical offsets
698 rowinfo_[0].offset_ = 0;
699 for (row_type row = 1; row <= nrows(); ++row) {
700 rowinfo_[row].offset_ =
701 rowinfo_[row - 1].offset_ +
702 rowinfo_[row - 1].descent_ +
703 //rowinfo_[row - 1].skipPixels(mi) +
705 //rowinfo_[row].lines_ * hlinesep() +
706 rowinfo_[row].ascent_;
709 // adjust vertical offset
716 h = rowinfo_[nrows() - 1].offset_;
719 h = rowinfo_[nrows() - 1].offset_ / 2;
721 for (row_type row = 0; row <= nrows(); ++row)
722 rowinfo_[row].offset_ -= h;
725 // compute absolute sizes of horizontal structure
726 for (col_type col = 0; col < ncols(); ++col) {
728 for (row_type row = 0; row < nrows(); ++row) {
730 //idx_type const i = index(row, col);
731 //if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
732 // wid = max(wid, cell(i).width());
734 colinfo_[col].width_ = wid;
736 colinfo_[ncols()].width_ = 0;
738 // compute horizontal offsets
739 colinfo_[0].offset_ = border();
740 for (col_type col = 1; col <= ncols(); ++col) {
741 colinfo_[col].offset_ =
742 colinfo_[col - 1].offset_ +
743 colinfo_[col - 1].width_ +
744 colinfo_[col - 1].skip_ +
746 //colinfo_[col].lines_ * vlinesep();
750 dim.wid = colinfo_[ncols() - 1].offset_
751 + colinfo_[ncols() - 1].width_
752 //+ vlinesep() * colinfo_[ncols()].lines_
755 dim.asc = -rowinfo_[0].offset_
756 + rowinfo_[0].ascent_
757 //+ hlinesep() * rowinfo_[0].lines_
760 dim.des = rowinfo_[nrows() - 1].offset_
761 + rowinfo_[nrows() - 1].descent_
762 //+ hlinesep() * rowinfo_[nrows()].lines_
767 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
769 // for (idx_type idx = 0; idx < nargs(); ++idx)
770 // if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
771 // cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
775 void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype)
778 for (idx_type idx = 0; idx < nargs(); ++idx)
779 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
780 cell(idx).updateBuffer(it, utype);
784 docstring InsetMathGrid::eolString(row_type row, bool fragile,
785 bool /*latex*/, bool last_eoln) const
789 if (!rowinfo_[row].crskip_.zero())
790 eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
791 else if(!rowinfo_[row].allow_newpage_)
794 // make sure an upcoming '[' does not break anything
795 if (row + 1 < nrows()) {
796 MathData const & c = cell(index(row + 1, 0));
797 if (!c.empty() && c.front()->getChar() == '[')
802 // only add \\ if necessary
803 if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
806 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
810 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
812 if (col + 1 == lastcol)
814 return from_ascii(" & ");
818 void InsetMathGrid::addRow(row_type row)
820 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
822 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData());
824 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
828 void InsetMathGrid::delRow(row_type row)
833 cells_type::iterator it = cells_.begin() + row * ncols();
834 cells_.erase(it, it + ncols());
836 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
837 cellinfo_.erase(jt, jt + ncols());
839 rowinfo_.erase(rowinfo_.begin() + row);
843 void InsetMathGrid::copyRow(row_type row)
846 for (col_type col = 0; col < ncols(); ++col)
847 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
851 void InsetMathGrid::swapRow(row_type row)
855 if (row + 1 == nrows())
857 for (col_type col = 0; col < ncols(); ++col)
858 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
862 void InsetMathGrid::addCol(col_type newcol)
864 const col_type nc = ncols();
865 const row_type nr = nrows();
866 cells_type new_cells((nc + 1) * nr);
867 vector<CellInfo> new_cellinfo((nc + 1) * nr);
869 for (row_type row = 0; row < nr; ++row)
870 for (col_type col = 0; col < nc; ++col) {
871 new_cells[row * (nc + 1) + col + (col >= newcol)]
872 = cells_[row * nc + col];
873 new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
874 = cellinfo_[row * nc + col];
876 swap(cells_, new_cells);
877 swap(cellinfo_, new_cellinfo);
880 inf.skip_ = defaultColSpace(newcol);
881 inf.align_ = defaultColAlign(newcol);
882 colinfo_.insert(colinfo_.begin() + newcol, inf);
886 void InsetMathGrid::delCol(col_type col)
892 vector<CellInfo> tmpcellinfo;
893 for (col_type i = 0; i < nargs(); ++i)
894 if (i % ncols() != col) {
895 tmpcells.push_back(cells_[i]);
896 tmpcellinfo.push_back(cellinfo_[i]);
898 swap(cells_, tmpcells);
899 swap(cellinfo_, tmpcellinfo);
901 colinfo_.erase(colinfo_.begin() + col);
905 void InsetMathGrid::copyCol(col_type col)
908 for (row_type row = 0; row < nrows(); ++row)
909 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
913 void InsetMathGrid::swapCol(col_type col)
917 if (col + 1 == ncols())
919 for (row_type row = 0; row < nrows(); ++row)
920 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
924 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
926 if (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN)
928 col_type c = col(idx);
929 int x = colinfo_[c].offset_;
930 char align = displayColAlign(idx);
931 Dimension const & celldim = cell(idx).dimension(bv);
932 if (align == 'r' || align == 'R')
933 x += cellWidth(idx) - celldim.wid;
934 if (align == 'c' || align == 'C')
935 x += (cellWidth(idx) - celldim.wid) / 2;
940 int InsetMathGrid::cellYOffset(idx_type idx) const
942 return rowinfo_[row(idx)].offset_;
946 int InsetMathGrid::cellWidth(idx_type idx) const
948 switch (cellinfo_[idx].multi_) {
950 return colinfo_[col(idx)].width_;
951 case CELL_BEGIN_OF_MULTICOLUMN: {
952 col_type c1 = col(idx);
953 col_type c2 = c1 + ncellcols(idx);
954 return colinfo_[c2].offset_
955 - colinfo_[c1].offset_
958 - colinfo_[c2].lines_ * vlinesep();
960 case CELL_PART_OF_MULTICOLUMN:
967 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
972 cur.idx() -= ncols();
974 if (cur.row() + 1 >= nrows())
976 cur.idx() += ncols();
978 // If we are in a multicolumn cell, move to the "real" cell
979 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
980 LASSERT(cur.idx() > 0, return false);
983 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
988 bool InsetMathGrid::idxBackward(Cursor & cur) const
990 // leave matrix if at the front edge
994 // If we are in a multicolumn cell, move to the "real" cell
995 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
996 LASSERT(cur.idx() > 0, return false);
999 cur.pos() = cur.lastpos();
1004 bool InsetMathGrid::idxForward(Cursor & cur) const
1006 // leave matrix if at the back edge
1007 if (cur.col() + 1 == ncols())
1010 // If we are in a multicolumn cell, move to the next cell
1011 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1012 // leave matrix if at the back edge
1013 if (cur.col() + 1 == ncols())
1022 bool InsetMathGrid::idxFirst(Cursor & cur) const
1029 cur.idx() = (nrows() - 1) * ncols();
1032 cur.idx() = ((nrows() - 1) / 2) * ncols();
1034 // If we are in a multicolumn cell, move to the "real" cell
1035 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1036 LASSERT(cur.idx() > 0, return false);
1044 bool InsetMathGrid::idxLast(Cursor & cur) const
1048 cur.idx() = ncols() - 1;
1051 cur.idx() = nargs() - 1;
1054 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
1056 // If we are in a multicolumn cell, move to the "real" cell
1057 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1058 LASSERT(cur.idx() > 0, return false);
1061 cur.pos() = cur.lastpos();
1066 bool InsetMathGrid::idxDelete(idx_type & idx)
1068 // nothing to do if we have just one row
1072 // nothing to do if we are in the middle of the last row of the inset
1073 if (idx + ncols() > nargs())
1076 // try to delete entire sequence of ncols() empty cells if possible
1077 for (idx_type i = idx; i < idx + ncols(); ++i)
1078 if (!cell(i).empty())
1081 // move cells if necessary
1082 for (idx_type i = index(row(idx), 0); i < idx; ++i)
1083 swap(cell(i), cell(i + ncols()));
1090 // undo effect of Ctrl-Tab (i.e. pull next cell)
1091 //if (idx + 1 != nargs())
1092 // cell(idx).swap(cell(idx + 1));
1094 // we handled the event..
1099 // reimplement old behaviour when pressing Delete in the last position
1101 void InsetMathGrid::idxGlue(idx_type idx)
1103 col_type c = col(idx);
1104 if (c + 1 == ncols()) {
1105 if (row(idx) + 1 != nrows()) {
1106 for (col_type cc = 0; cc < ncols(); ++cc)
1107 cell(idx).append(cell(idx + cc + 1));
1108 delRow(row(idx) + 1);
1111 idx_type idx_next = idx + 1;
1112 while (idx_next < nargs() &&
1113 cellinfo_[idx_next].multi_ == CELL_PART_OF_MULTICOLUMN)
1115 if (idx_next < nargs())
1116 cell(idx).append(cell(idx_next));
1117 col_type oldcol = c + 1;
1118 for (col_type cc = c + 2; cc < ncols(); ++cc)
1119 cell(idx - oldcol + cc) = cell(idx - oldcol + 1 + cc);
1120 cell(idx - c + ncols() - 1).clear();
1125 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
1127 return rowinfo_[row];
1131 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
1133 return rowinfo_[row];
1137 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
1139 row_type const ri = row(idx);
1140 row_type const r1 = min(row(from), row(to));
1141 row_type const r2 = max(row(from), row(to));
1142 col_type const ci = col(idx);
1143 col_type const c1 = min(col(from), col(to));
1144 col_type const c2 = max(col(from), col(to));
1145 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
1149 void InsetMathGrid::normalize(NormalStream & os) const
1152 for (row_type row = 0; row < nrows(); ++row) {
1154 for (col_type col = 0; col < ncols(); ++col) {
1155 idx_type const i = index(row, col);
1156 switch (cellinfo_[i].multi_) {
1158 os << "[cell " << cell(i) << ']';
1160 case CELL_BEGIN_OF_MULTICOLUMN:
1161 os << "[cell colspan="
1162 << static_cast<int>(ncellcols(i)) << ' '
1165 case CELL_PART_OF_MULTICOLUMN:
1175 void InsetMathGrid::mathmlize(MathStream & os) const
1177 bool const havetable = nrows() > 1 || ncols() > 1;
1179 os << MTag("mtable");
1180 char const * const celltag = havetable ? "mtd" : "mrow";
1181 for (row_type row = 0; row < nrows(); ++row) {
1184 for (col_type col = 0; col < ncols(); ++col) {
1185 idx_type const i = index(row, col);
1186 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1187 col_type const cellcols = ncellcols(i);
1189 if (havetable && cellcols > 1)
1190 attr << "colspan='" << cellcols << '\'';
1191 os << MTag(celltag, attr.str());
1192 os << cell(index(row, col));
1193 os << ETag(celltag);
1200 os << ETag("mtable");
1205 // We need to do something about alignment here.
1206 void InsetMathGrid::htmlize(HtmlStream & os, string attrib) const
1208 bool const havetable = nrows() > 1 || ncols() > 1;
1210 os << cell(index(0, 0));
1213 os << MTag("table", attrib);
1214 for (row_type row = 0; row < nrows(); ++row) {
1216 for (col_type col = 0; col < ncols(); ++col) {
1217 idx_type const i = index(row, col);
1218 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1219 col_type const cellcols = ncellcols(i);
1222 attr << "colspan='" << cellcols << '\'';
1223 os << MTag("td", attr.str());
1224 os << cell(index(row, col));
1230 os << ETag("table");
1234 void InsetMathGrid::htmlize(HtmlStream & os) const
1236 htmlize(os, "class='mathtable'");
1240 void InsetMathGrid::write(WriteStream & os) const
1242 write(os, 0, 0, nrows(), ncols());
1245 void InsetMathGrid::write(WriteStream & os,
1246 row_type beg_row, col_type beg_col,
1247 row_type end_row, col_type end_col) const
1249 MathEnsurer ensurer(os, false);
1251 for (row_type row = beg_row; row < end_row; ++row) {
1252 os << verboseHLine(rowinfo_[row].lines_);
1253 // don't write & and empty cells at end of line,
1254 // unless there are vertical lines
1255 col_type lastcol = 0;
1256 bool emptyline = true;
1257 bool last_eoln = true;
1258 for (col_type col = beg_col; col < end_col; ++col) {
1259 idx_type const idx = index(row, col);
1260 bool const empty_cell = cell(idx).empty();
1261 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL)
1263 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL ||
1264 colinfo_[col + 1].lines_) {
1269 for (col_type col = beg_col; col < end_col;) {
1271 idx_type const idx = index(row, col);
1272 TexRow::RowEntry entry = os.texrow().mathEntry(id(),idx);
1273 os.texrow().startMath(id(),idx);
1274 if (col >= lastcol) {
1278 os.pushRowEntry(entry);
1279 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1281 while (s < ncols() &&
1282 cellinfo_[index(row, s)].multi_ == CELL_PART_OF_MULTICOLUMN)
1285 os << "\\multicolumn{" << nccols
1286 << "}{" << cellinfo_[idx].align_
1290 if (os.pendingBrace())
1291 ModeSpecifier specifier(os, TEXT_MODE);
1292 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1294 os << eocString(col + nccols - 1, lastcol);
1298 eol = eolString(row, os.fragile(), os.latex(), last_eoln);
1300 // append newline only if line wasn't completely empty
1301 // and the formula is not written on a single line
1302 bool const empty = emptyline && eol.empty();
1303 if (!empty && nrows() > 1)
1306 // @TODO use end_row instead of nrows() ?
1307 docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
1319 int InsetMathGrid::colsep() const
1325 int InsetMathGrid::rowsep() const
1331 int InsetMathGrid::hlinesep() const
1337 int InsetMathGrid::vlinesep() const
1343 int InsetMathGrid::border() const
1349 void InsetMathGrid::splitCell(Cursor & cur)
1351 if (cur.idx() == cur.lastidx())
1353 MathData ar = cur.cell();
1354 ar.erase(0, cur.pos());
1355 cur.cell().erase(cur.pos(), cur.lastpos());
1357 while (cur.idx() << nargs() &&
1358 cellinfo_[cur.idx()].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1361 cur.cell().insert(0, ar);
1365 char InsetMathGrid::displayColAlign(idx_type idx) const
1367 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1368 // align_ may also contain lines like "||r|", so this is
1369 // not complete, but we catch at least the simple cases.
1370 if (cellinfo_[idx].align_ == "c")
1372 if (cellinfo_[idx].align_ == "l")
1374 if (cellinfo_[idx].align_ == "r")
1377 return colinfo_[col(idx)].align_;
1381 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1383 //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1385 Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
1387 FuncCode const act = cmd.action();
1390 // insert file functions
1391 case LFUN_LINE_DELETE_FORWARD:
1392 cur.recordUndoInset();
1393 //autocorrect_ = false;
1401 if (cur.idx() > cur.lastidx())
1402 cur.idx() = cur.lastidx();
1403 if (cur.pos() > cur.lastpos())
1404 cur.pos() = cur.lastpos();
1407 case LFUN_CELL_SPLIT:
1412 case LFUN_CELL_BACKWARD:
1414 cur.setSelection(false);
1415 if (!idxPrev(cur)) {
1416 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1421 case LFUN_CELL_FORWARD:
1422 // Can't handle selection by additional 'shift' as this is
1423 // hard bound to LFUN_CELL_BACKWARD
1424 cur.setSelection(false);
1425 if (!idxNext(cur)) {
1426 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1431 case LFUN_NEWLINE_INSERT: {
1432 cur.recordUndoInset();
1433 row_type const r = cur.row();
1437 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1438 swap(cell(index(r, c)), cell(index(r + 1, c)));
1443 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1446 cur.pos() = cur.lastpos();
1447 cur.forceBufferUpdate();
1448 //mathcursor->normalize();
1449 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1453 case LFUN_INSET_MODIFY: {
1454 cur.recordUndoInset();
1455 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1456 istringstream is(to_utf8(cmd.argument()));
1459 if (s != "tabular") {
1460 InsetMathNest::doDispatch(cur, cmd);
1464 if (s == "valign-top")
1465 setVerticalAlignment('t');
1466 else if (s == "valign-middle")
1467 setVerticalAlignment('c');
1468 else if (s == "valign-bottom")
1469 setVerticalAlignment('b');
1470 else if (s == "align-left")
1471 setHorizontalAlignment('l', cur.col());
1472 else if (s == "align-right")
1473 setHorizontalAlignment('r', cur.col());
1474 else if (s == "align-center")
1475 setHorizontalAlignment('c', cur.col());
1476 else if (s == "append-row")
1477 for (int i = 0, n = extractInt(is); i < n; ++i)
1479 else if (s == "delete-row") {
1480 cur.clearSelection(); // bug 4323
1481 for (int i = 0, n = extractInt(is); i < n; ++i) {
1483 if (cur.idx() >= nargs())
1484 cur.idx() -= ncols();
1486 cur.pos() = 0; // trick, see below
1488 else if (s == "copy-row") {
1489 // Here (as later) we save the cursor col/row
1490 // in order to restore it after operation.
1491 row_type const r = cur.row();
1492 col_type const c = cur.col();
1493 for (int i = 0, n = extractInt(is); i < n; ++i)
1495 cur.idx() = index(r, c);
1497 else if (s == "swap-row") {
1499 // Trick to suppress same-idx-means-different-cell
1503 else if (s == "add-hline-above")
1504 rowinfo_[cur.row()].lines_++;
1505 else if (s == "add-hline-below")
1506 rowinfo_[cur.row()+1].lines_++;
1507 else if (s == "delete-hline-above")
1508 rowinfo_[cur.row()].lines_--;
1509 else if (s == "delete-hline-below")
1510 rowinfo_[cur.row()+1].lines_--;
1511 else if (s == "append-column") {
1512 row_type const r = cur.row();
1513 col_type const c = cur.col();
1514 for (int i = 0, n = extractInt(is); i < n; ++i)
1515 addCol(cur.col() + 1);
1516 cur.idx() = index(r, c);
1518 else if (s == "delete-column") {
1519 cur.clearSelection(); // bug 4323
1520 row_type const r = cur.row();
1521 col_type const c = cur.col();
1522 for (int i = 0, n = extractInt(is); i < n; ++i)
1523 delCol(col(cur.idx()));
1524 cur.idx() = index(r, min(c, cur.ncols() - 1));
1525 cur.pos() = 0; // trick, see above
1527 else if (s == "copy-column") {
1528 row_type const r = cur.row();
1529 col_type const c = cur.col();
1531 cur.idx() = index(r, c);
1533 else if (s == "swap-column") {
1535 cur.pos() = 0; // trick, see above
1537 else if (s == "add-vline-left") {
1538 colinfo_[cur.col()].lines_++;
1539 if (!colinfo_[cur.col()].special_.empty())
1540 colinfo_[cur.col()].special_ += '|';
1542 else if (s == "add-vline-right") {
1543 colinfo_[cur.col()+1].lines_++;
1544 if (!colinfo_[cur.col()+1].special_.empty())
1545 colinfo_[cur.col()+1].special_.insert(0, 1, '|');
1547 else if (s == "delete-vline-left") {
1548 colinfo_[cur.col()].lines_--;
1549 docstring & special = colinfo_[cur.col()].special_;
1550 if (!special.empty()) {
1551 docstring::size_type i = special.rfind('|');
1552 LASSERT(i != docstring::npos, break);
1553 special.erase(i, 1);
1556 else if (s == "delete-vline-right") {
1557 colinfo_[cur.col()+1].lines_--;
1558 docstring & special = colinfo_[cur.col()+1].special_;
1559 if (!special.empty()) {
1560 docstring::size_type i = special.find('|');
1561 LASSERT(i != docstring::npos, break);
1562 special.erase(i, 1);
1569 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1570 //lyxerr << "returning FINISHED_LEFT" << endl;
1574 case LFUN_CLIPBOARD_PASTE:
1575 parseflg |= Parse::VERBATIM;
1578 if (cur.currentMode() <= TEXT_MODE)
1579 parseflg |= Parse::TEXTMODE;
1580 cur.message(_("Paste"));
1581 cap::replaceSelection(cur);
1583 if (cmd.argument().empty() && !theClipboard().isInternal())
1584 topaste = theClipboard().getAsText(Clipboard::PlainTextType);
1586 idocstringstream is(cmd.argument());
1589 topaste = cap::selection(n, buffer().params().documentClassPtr());
1591 InsetMathGrid grid(buffer_, 1, 1);
1592 if (!topaste.empty())
1593 if ((topaste.size() == 1 && isAscii(topaste))
1594 || !mathed_parse_normal(grid, topaste, parseflg)) {
1596 mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
1599 bool hline_enabled = false;
1600 FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
1602 if (getStatus(cur, fr, status))
1603 hline_enabled = status.enabled();
1604 if (grid.nargs() == 1) {
1605 // single cell/part of cell
1606 cur.recordUndoInset();
1607 cur.cell().insert(cur.pos(), grid.cell(0));
1608 cur.pos() += grid.cell(0).size();
1610 rowinfo_[cur.row()].lines_ += grid.rowinfo_[0].lines_;
1612 for (unsigned int l = 0; l < grid.rowinfo_[0].lines_; ++l) {
1613 cur.cell().insert(0,
1614 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1620 cur.recordUndoInset();
1621 col_type const numcols =
1622 min(grid.ncols(), ncols() - col(cur.idx()));
1623 row_type const numrows =
1624 min(grid.nrows(), nrows() - cur.row());
1625 for (row_type r = 0; r < numrows; ++r) {
1626 for (col_type c = 0; c < numcols; ++c) {
1627 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1628 cell(i).insert(0, grid.cell(grid.index(r, c)));
1631 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1633 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1634 idx_type i = index(r + cur.row(), 0);
1636 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1639 // append the left over horizontal cells to the last column
1640 idx_type i = index(r + cur.row(), ncols() - 1);
1641 for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
1642 cell(i).append(grid.cell(grid.index(r, c)));
1644 // append the left over vertical cells to the last _cell_
1645 idx_type i = nargs() - 1;
1646 for (row_type r = numrows; r < grid.nrows(); ++r) {
1647 for (col_type c = 0; c < grid.ncols(); ++c)
1648 cell(i).append(grid.cell(grid.index(r, c)));
1650 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1652 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1654 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1659 cur.clearSelection(); // bug 393
1660 // FIXME audit setBuffer calls
1661 cur.inset().setBuffer(*buffer_);
1662 cur.forceBufferUpdate();
1667 case LFUN_LINE_BEGIN:
1668 case LFUN_WORD_BACKWARD:
1669 case LFUN_WORD_LEFT:
1670 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1672 case LFUN_LINE_BEGIN_SELECT:
1673 case LFUN_WORD_BACKWARD_SELECT:
1674 case LFUN_WORD_LEFT_SELECT:
1675 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1676 act == LFUN_WORD_LEFT_SELECT ||
1677 act == LFUN_LINE_BEGIN_SELECT);
1678 cur.macroModeClose();
1679 if (cur.pos() != 0) {
1681 } else if (cur.idx() % cur.ncols() != 0) {
1682 cur.idx() -= cur.idx() % cur.ncols();
1684 } else if (cur.idx() != 0) {
1688 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1693 case LFUN_WORD_FORWARD:
1694 case LFUN_WORD_RIGHT:
1696 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1698 case LFUN_WORD_FORWARD_SELECT:
1699 case LFUN_WORD_RIGHT_SELECT:
1700 case LFUN_LINE_END_SELECT:
1701 cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
1702 act == LFUN_WORD_RIGHT_SELECT ||
1703 act == LFUN_LINE_END_SELECT);
1704 cur.macroModeClose();
1706 if (cur.pos() != cur.lastpos()) {
1707 cur.pos() = cur.lastpos();
1708 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1709 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1710 cur.pos() = cur.lastpos();
1711 } else if (cur.idx() != cur.lastidx()) {
1712 cur.idx() = cur.lastidx();
1713 cur.pos() = cur.lastpos();
1715 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1721 InsetMathNest::doDispatch(cur, cmd);
1726 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1727 FuncStatus & status) const
1729 switch (cmd.action()) {
1730 case LFUN_INSET_MODIFY: {
1731 istringstream is(to_utf8(cmd.argument()));
1734 if (s != "tabular") {
1735 // We only now about table actions here.
1738 if (&cur.inset() != this) {
1739 // Table actions requires that the cursor is _inside_ the
1741 status.setEnabled(false);
1742 status.message(from_utf8(N_("Cursor not in table")));
1746 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1747 status.setEnabled(false);
1748 status.message(from_utf8(N_("Only one row")));
1752 (s == "delete-column" || s == "swap-column")) {
1753 status.setEnabled(false);
1754 status.message(from_utf8(N_("Only one column")));
1757 if ((rowinfo_[cur.row()].lines_ == 0 &&
1758 s == "delete-hline-above") ||
1759 (rowinfo_[cur.row() + 1].lines_ == 0 &&
1760 s == "delete-hline-below")) {
1761 status.setEnabled(false);
1762 status.message(from_utf8(N_("No hline to delete")));
1766 if ((colinfo_[cur.col()].lines_ == 0 &&
1767 s == "delete-vline-left") ||
1768 (colinfo_[cur.col() + 1].lines_ == 0 &&
1769 s == "delete-vline-right")) {
1770 status.setEnabled(false);
1771 status.message(from_utf8(N_("No vline to delete")));
1774 if (s == "valign-top" || s == "valign-middle" ||
1775 s == "valign-bottom" || s == "align-left" ||
1776 s == "align-right" || s == "align-center") {
1777 status.setEnabled(true);
1778 char const ha = horizontalAlignment(cur.col());
1779 char const va = verticalAlignment();
1780 status.setOnOff((s == "align-left" && ha == 'l')
1781 || (s == "align-right" && ha == 'r')
1782 || (s == "align-center" && ha == 'c')
1783 || (s == "valign-top" && va == 't')
1784 || (s == "valign-bottom" && va == 'b')
1785 || (s == "valign-middle" && va == 'c'));
1788 if (s == "append-row" || s == "delete-row" ||
1789 s == "copy-row" || s == "swap-row" ||
1790 s == "add-hline-above" || s == "add-hline-below" ||
1791 s == "delete-hline-above" || s == "delete-hline-below" ||
1792 s == "append-column" || s == "delete-column" ||
1793 s == "copy-column" || s == "swap-column" ||
1794 s == "add-vline-left" || s == "add-vline-right" ||
1795 s == "delete-vline-left" || s == "delete-vline-right") {
1796 status.setEnabled(true);
1798 status.setEnabled(false);
1799 status.message(bformat(
1800 from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
1804 // FIXME: What did this code do?
1805 // Please check whether it is still needed!
1806 // should be more precise
1807 if (v_align_ == '\0') {
1808 status.enable(true);
1811 if (cmd.argument().empty()) {
1812 status.enable(false);
1815 if (!contains("tcb", cmd.argument()[0])) {
1816 status.enable(false);
1819 status.setOnOff(cmd.argument()[0] == v_align_);
1820 status.setEnabled(true);
1825 case LFUN_CELL_SPLIT:
1826 status.setEnabled(cur.idx() != cur.lastidx());
1829 case LFUN_CELL_BACKWARD:
1830 case LFUN_CELL_FORWARD:
1831 status.setEnabled(true);
1837 return InsetMathNest::getStatus(cur, cmd, status);