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()
89 //////////////////////////////////////////////////////////////
92 InsetMathGrid::RowInfo::RowInfo()
93 : lines_(0), skip_(0), allow_newpage_(true)
98 int InsetMathGrid::RowInfo::skipPixels(MetricsInfo const & mi) const
100 return crskip_.inPixels(mi.base);
105 //////////////////////////////////////////////////////////////
108 InsetMathGrid::ColInfo::ColInfo()
109 : align_('c'), lines_(0)
113 //////////////////////////////////////////////////////////////
116 InsetMathGrid::InsetMathGrid(Buffer * buf)
117 : InsetMathNest(buf, 1),
127 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n)
128 : InsetMathNest(buf, m * n),
138 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n, char v,
140 : InsetMathNest(buf, m * n),
147 setVerticalAlignment(v);
148 setHorizontalAlignments(h);
152 Inset * InsetMathGrid::clone() const
154 return new InsetMathGrid(*this);
158 InsetMath::idx_type InsetMathGrid::index(row_type row, col_type col) const
160 return col + ncols() * row;
164 void InsetMathGrid::setDefaults()
167 lyxerr << "positive number of columns expected" << endl;
169 // lyxerr << "positive number of rows expected" << endl;
170 for (col_type col = 0; col < ncols(); ++col) {
171 colinfo_[col].align_ = defaultColAlign(col);
172 colinfo_[col].skip_ = defaultColSpace(col);
173 colinfo_[col].special_.clear();
175 for (idx_type idx = 0; idx < nargs(); ++idx)
176 cellinfo_[idx].multi_ = CELL_NORMAL;
180 bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
182 if (str == "\\hline") {
183 FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
185 if (getStatus(cur, fr, status)) {
186 if (status.enabled()) {
187 rowinfo_[cur.row()].lines_++;
192 return InsetMathNest::interpretString(cur, str);
196 void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
199 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
202 colinfo_[col].lines_++;
203 } else if ((c == 'p' || c == 'm' || c == 'b'||
204 c == '!' || c == '@' || c == '>' || c == '<') &&
205 it + 1 != hh.end() && *(it + 1) == '{') {
206 // @{decl.} and p{width} are standard LaTeX, the
207 // others are extensions by array.sty
208 bool const newcolumn = c == 'p' || c == 'm' || c == 'b';
210 // this declares a new column
212 // Only intercolumn stuff is allowed
213 // in the last dummy column
215 colinfo_[col].align_ = 'l';
217 // this is intercolumn stuff
218 if (colinfo_[col].special_.empty())
219 // Overtake possible lines
220 colinfo_[col].special_ = docstring(colinfo_[col].lines_, '|');
224 while (it != hh.end()) {
226 colinfo_[col].special_ += c;
232 if (brace_open > 0 && brace_open == brace_close)
237 colinfo_[col].lines_ = count(
238 colinfo_[col].special_.begin(),
239 colinfo_[col].special_.end(), '|');
240 LYXERR(Debug::MATHED, "special column separator: `"
241 << to_utf8(colinfo_[col].special_) << '\'');
243 colinfo_[col].lines_ = 0;
244 colinfo_[col].special_.clear();
246 } else if (col >= ncols()) {
247 // Only intercolumn stuff is allowed in the last
250 } else if (c == 'c' || c == 'l' || c == 'r') {
251 colinfo_[col].align_ = static_cast<char>(c);
252 if (!colinfo_[col].special_.empty()) {
253 colinfo_[col].special_ += c;
254 colinfo_[col].lines_ = count(
255 colinfo_[col].special_.begin(),
256 colinfo_[col].special_.end(), '|');
257 LYXERR(Debug::MATHED, "special column separator: `"
258 << to_utf8(colinfo_[col].special_) << '\'');
261 colinfo_[col].lines_ = 0;
262 colinfo_[col].special_.clear();
264 lyxerr << "unknown column separator: '" << c << "'" << endl;
269 col_type n = hh.size();
272 for (col_type col = 0; col < n; ++col)
273 colinfo_[col].align_ = hh[col];
278 InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh)
281 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
282 if (*it == 'c' || *it == 'l' || *it == 'r'||
283 *it == 'p' || *it == 'm' || *it == 'b')
285 // let's have at least one column, even if we did not recognize its
293 void InsetMathGrid::setHorizontalAlignment(char h, col_type col)
295 colinfo_[col].align_ = h;
296 if (!colinfo_[col].special_.empty()) {
297 char_type & c = colinfo_[col].special_[colinfo_[col].special_.size() - 1];
298 if (c == 'l' || c == 'c' || c == 'r')
301 // FIXME: Change alignment of p, m and b columns, too
305 char InsetMathGrid::horizontalAlignment(col_type col) const
307 return colinfo_[col].align_;
311 docstring InsetMathGrid::horizontalAlignments() const
314 for (col_type col = 0; col < ncols(); ++col) {
315 if (colinfo_[col].special_.empty()) {
316 res += docstring(colinfo_[col].lines_, '|');
317 res += colinfo_[col].align_;
319 res += colinfo_[col].special_;
321 if (colinfo_[ncols()].special_.empty())
322 return res + docstring(colinfo_[ncols()].lines_, '|');
323 return res + colinfo_[ncols()].special_;
327 void InsetMathGrid::setVerticalAlignment(char c)
333 char InsetMathGrid::verticalAlignment() const
339 InsetMathGrid::col_type InsetMathGrid::ncols() const
341 return colinfo_.size() - 1;
345 InsetMathGrid::row_type InsetMathGrid::nrows() const
347 return rowinfo_.size() - 1;
351 InsetMathGrid::col_type InsetMathGrid::col(idx_type idx) const
353 return idx % ncols();
357 InsetMathGrid::row_type InsetMathGrid::row(idx_type idx) const
359 return idx / ncols();
363 InsetMathGrid::col_type InsetMathGrid::ncellcols(idx_type idx) const
366 if (cellinfo_[idx].multi_ == CELL_NORMAL)
368 // If the cell at idx is already CELL_PART_OF_MULTICOLUMN we return
369 // the number of remaining columns, not the ones of the complete
370 // multicolumn cell. This makes it possible to always go to the next
371 // cell with idx + ncellcols(idx) - 1.
372 row_type const r = row(idx);
373 while (idx+cols < nargs() && row(idx+cols) == r &&
374 cellinfo_[idx+cols].multi_ == CELL_PART_OF_MULTICOLUMN)
380 void InsetMathGrid::vcrskip(Length const & crskip, row_type row)
382 rowinfo_[row].crskip_ = crskip;
386 Length InsetMathGrid::vcrskip(row_type row) const
388 return rowinfo_[row].crskip_;
392 void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
394 // let the cells adjust themselves
395 for (idx_type i = 0; i < nargs(); ++i) {
396 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
398 cell(i).metrics(mi, dimc);
402 BufferView & bv = *mi.base.bv;
404 // compute absolute sizes of vertical structure
405 for (row_type row = 0; row < nrows(); ++row) {
408 for (col_type col = 0; col < ncols(); ++col) {
409 idx_type const i = index(row, col);
410 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
411 Dimension const & dimc = cell(i).dimension(bv);
412 asc = max(asc, dimc.asc);
413 desc = max(desc, dimc.des);
416 rowinfo_[row].ascent_ = asc;
417 rowinfo_[row].descent_ = desc;
419 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
420 rowinfo_[nrows()].ascent_ = 0;
421 rowinfo_[nrows()].descent_ = 0;
423 // compute vertical offsets
424 rowinfo_[0].offset_ = 0;
425 for (row_type row = 1; row <= nrows(); ++row) {
426 rowinfo_[row].offset_ =
427 rowinfo_[row - 1].offset_ +
428 rowinfo_[row - 1].descent_ +
429 rowinfo_[row - 1].skipPixels(mi) +
431 rowinfo_[row].lines_ * hlinesep() +
432 rowinfo_[row].ascent_;
435 // adjust vertical offset
442 h = rowinfo_[nrows() - 1].offset_;
445 h = rowinfo_[nrows() - 1].offset_ / 2;
447 for (row_type row = 0; row <= nrows(); ++row)
448 rowinfo_[row].offset_ -= h;
451 // multicolumn cell widths, as a map from first column to width in a
452 // vector of last columns.
453 // This is only used if the grid has more than one row, since for
454 // one-row grids multicolumn cells do not need special handling
455 vector<map<col_type, int> > mcolwidths(ncols());
457 // compute absolute sizes of horizontal structure
458 for (col_type col = 0; col < ncols(); ++col) {
460 for (row_type row = 0; row < nrows(); ++row) {
461 idx_type const i = index(row, col);
462 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
463 int const w = cell(i).dimension(bv).wid;
464 col_type const cols = ncellcols(i);
465 if (cols > 1 && nrows() > 1) {
466 col_type last = col+cols-1;
467 LASSERT(last < ncols(), last = ncols()-1);
468 map<col_type, int>::iterator it =
469 mcolwidths[last].find(col);
470 if (it == mcolwidths[last].end())
471 mcolwidths[last][col] = w;
473 it->second = max(it->second, w);
478 colinfo_[col].width_ = wid;
480 colinfo_[ncols()].width_ = 0;
482 // compute horizontal offsets
483 colinfo_[0].offset_ = border();
484 for (col_type col = 1; col <= ncols(); ++col) {
485 colinfo_[col].offset_ =
486 colinfo_[col - 1].offset_ +
487 colinfo_[col - 1].width_ +
488 colinfo_[col - 1].skip_ +
490 colinfo_[col].lines_ * vlinesep();
493 // increase column widths for multicolumn cells if needed
494 // FIXME: multicolumn lines are not yet considered
495 for (col_type last = 0; last < ncols(); ++last) {
496 map<col_type, int> const & widths = mcolwidths[last];
497 // We increase the width of the last column of the multicol
498 // cell (some sort of left alignment). Since we iterate through
499 // the last and the first columns from left to right, we ensure
500 // that increased widths of previous columns are correctly
501 // taken into account for later columns, thus preventing
502 // unneeded width increasing.
503 for (map<col_type, int>::const_iterator it = widths.begin();
504 it != widths.end(); ++it) {
505 int const wid = it->second;
506 col_type const first = it->first;
507 int const nextoffset =
508 colinfo_[first].offset_ +
510 colinfo_[last].skip_ +
512 colinfo_[last+1].lines_ * vlinesep();
513 int const dx = nextoffset - colinfo_[last+1].offset_;
515 colinfo_[last].width_ += dx;
516 for (col_type col = last + 1; col <= ncols(); ++col)
517 colinfo_[col].offset_ += dx;
523 dim.wid = colinfo_[ncols() - 1].offset_
524 + colinfo_[ncols() - 1].width_
525 + vlinesep() * colinfo_[ncols()].lines_
528 dim.asc = - rowinfo_[0].offset_
529 + rowinfo_[0].ascent_
530 + hlinesep() * rowinfo_[0].lines_
533 dim.des = rowinfo_[nrows() - 1].offset_
534 + rowinfo_[nrows() - 1].descent_
535 + hlinesep() * rowinfo_[nrows()].lines_
540 // Increase ws_[i] for 'R' columns (except the first one)
541 for (int i = 1; i < nc_; ++i)
542 if (align_[i] == 'R')
543 ws_[i] += 10 * df_width;
544 // Increase ws_[i] for 'C' column
545 if (align_[0] == 'C')
546 if (ws_[0] < 7 * workwidth / 8)
547 ws_[0] = 7 * workwidth / 8;
551 for (cxrow = row_.begin(); cxrow; ++cxrow) {
554 for (int i = 0; i < nc_; ++i) {
556 if (cxrow->getTab(i) <= 0) {
557 cxrow->setTab(i, df_width);
565 lf = (ws_[i] - cxrow->getTab(i))/2;
569 lf = ws_[i] - cxrow->getTab(i);
572 if (cxrow == row_.begin())
574 else if (cxrow.is_last())
575 lf = ws_[i] - cxrow->getTab(i);
577 lf = (ws_[i] - cxrow->getTab(i))/2;
580 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
581 cxrow->setTab(i, lf + rg);
582 rg = ws_[i] - ww + colsep();
583 if (cxrow == row_.begin())
584 width += ws_[i] + colsep();
586 cxrow->setBaseline(cxrow->getBaseline() - ascent);
589 metricsMarkers2(dim);
590 // Cache the inset dimension.
591 setDimCache(mi, dim);
595 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
597 drawWithMargin(pi, x, y, 1, 1);
601 void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
602 int lmargin, int rmargin) const
604 Dimension const dim = dimension(*pi.base.bv);
605 BufferView const & bv = *pi.base.bv;
607 for (idx_type idx = 0; idx < nargs(); ++idx) {
608 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN) {
610 x + lmargin + cellXOffset(bv, idx),
611 y + cellYOffset(idx));
613 // draw inner lines cell by cell because of possible multicolumns
614 // FIXME: multicolumn lines are not yet considered
615 row_type const r = row(idx);
616 col_type const c = col(idx);
617 if (r > 0 && r < nrows()) {
618 for (unsigned int i = 0; i < rowinfo_[r].lines_; ++i) {
619 int yy = y + rowinfo_[r].offset_
620 - rowinfo_[r].ascent_
622 - hlinesep()/2 - rowsep()/2;
624 x + lmargin + colinfo_[c].offset_,
626 x + lmargin + colinfo_[c+1].offset_,
627 yy, Color_foreground);
630 if (c > 0 && c < ncols()) {
631 for (unsigned int i = 0; i < colinfo_[c].lines_; ++i) {
633 + colinfo_[c].offset_
635 - vlinesep()/2 - colsep()/2;
637 rowinfo_[r].offset_ - rowinfo_[r].ascent_,
639 rowinfo_[r].offset_ + rowinfo_[r].descent_,
646 // draw outer lines in one go
647 for (row_type row = 0; row <= nrows(); row += nrows())
648 for (unsigned int i = 0; i < rowinfo_[row].lines_; ++i) {
649 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
650 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
651 pi.pain.line(x + lmargin + 1, yy,
652 x + dim.width() - rmargin - 1, yy,
656 for (col_type col = 0; col <= ncols(); col += ncols())
657 for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
658 int xx = x + lmargin + colinfo_[col].offset_
659 - i * vlinesep() - vlinesep()/2 - colsep()/2;
660 pi.pain.line(xx, y - dim.ascent() + 1,
661 xx, y + dim.descent() - 1,
664 drawMarkers2(pi, x, y);
668 void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
670 // let the cells adjust themselves
671 for (idx_type i = 0; i < nargs(); ++i)
672 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
673 cell(i).metricsT(mi, dim);
675 // compute absolute sizes of vertical structure
676 for (row_type row = 0; row < nrows(); ++row) {
679 for (col_type col = 0; col < ncols(); ++col) {
680 idx_type const i = index(row, col);
681 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
682 //MathData const & c = cell(i);
685 asc = max(asc, dimc.ascent());
686 desc = max(desc, dimc.descent());
689 rowinfo_[row].ascent_ = asc;
690 rowinfo_[row].descent_ = desc;
692 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
693 rowinfo_[nrows()].ascent_ = 0;
694 rowinfo_[nrows()].descent_ = 0;
696 // compute vertical offsets
697 rowinfo_[0].offset_ = 0;
698 for (row_type row = 1; row <= nrows(); ++row) {
699 rowinfo_[row].offset_ =
700 rowinfo_[row - 1].offset_ +
701 rowinfo_[row - 1].descent_ +
702 //rowinfo_[row - 1].skipPixels(mi) +
704 //rowinfo_[row].lines_ * hlinesep() +
705 rowinfo_[row].ascent_;
708 // adjust vertical offset
715 h = rowinfo_[nrows() - 1].offset_;
718 h = rowinfo_[nrows() - 1].offset_ / 2;
720 for (row_type row = 0; row <= nrows(); ++row)
721 rowinfo_[row].offset_ -= h;
724 // compute absolute sizes of horizontal structure
725 for (col_type col = 0; col < ncols(); ++col) {
727 for (row_type row = 0; row < nrows(); ++row) {
729 //idx_type const i = index(row, col);
730 //if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
731 // wid = max(wid, cell(i).width());
733 colinfo_[col].width_ = wid;
735 colinfo_[ncols()].width_ = 0;
737 // compute horizontal offsets
738 colinfo_[0].offset_ = border();
739 for (col_type col = 1; col <= ncols(); ++col) {
740 colinfo_[col].offset_ =
741 colinfo_[col - 1].offset_ +
742 colinfo_[col - 1].width_ +
743 colinfo_[col - 1].skip_ +
745 //colinfo_[col].lines_ * vlinesep();
749 dim.wid = colinfo_[ncols() - 1].offset_
750 + colinfo_[ncols() - 1].width_
751 //+ vlinesep() * colinfo_[ncols()].lines_
754 dim.asc = -rowinfo_[0].offset_
755 + rowinfo_[0].ascent_
756 //+ hlinesep() * rowinfo_[0].lines_
759 dim.des = rowinfo_[nrows() - 1].offset_
760 + rowinfo_[nrows() - 1].descent_
761 //+ hlinesep() * rowinfo_[nrows()].lines_
766 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
768 // for (idx_type idx = 0; idx < nargs(); ++idx)
769 // if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
770 // cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
774 void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype)
777 for (idx_type idx = 0; idx < nargs(); ++idx)
778 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
779 cell(idx).updateBuffer(it, utype);
783 docstring InsetMathGrid::eolString(row_type row, bool fragile,
784 bool /*latex*/, bool last_eoln) const
788 if (!rowinfo_[row].crskip_.zero())
789 eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
790 else if(!rowinfo_[row].allow_newpage_)
793 // make sure an upcoming '[' does not break anything
794 if (row + 1 < nrows()) {
795 MathData const & c = cell(index(row + 1, 0));
796 if (!c.empty() && c.front()->getChar() == '[')
801 // only add \\ if necessary
802 if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
805 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
809 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
811 if (col + 1 == lastcol)
813 return from_ascii(" & ");
817 void InsetMathGrid::addRow(row_type row)
819 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
821 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData());
823 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
827 void InsetMathGrid::delRow(row_type row)
832 cells_type::iterator it = cells_.begin() + row * ncols();
833 cells_.erase(it, it + ncols());
835 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
836 cellinfo_.erase(jt, jt + ncols());
838 rowinfo_.erase(rowinfo_.begin() + row);
842 void InsetMathGrid::copyRow(row_type row)
845 for (col_type col = 0; col < ncols(); ++col)
846 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
850 void InsetMathGrid::swapRow(row_type row)
854 if (row + 1 == nrows())
856 for (col_type col = 0; col < ncols(); ++col)
857 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
861 void InsetMathGrid::addCol(col_type newcol)
863 const col_type nc = ncols();
864 const row_type nr = nrows();
865 cells_type new_cells((nc + 1) * nr);
866 vector<CellInfo> new_cellinfo((nc + 1) * nr);
868 for (row_type row = 0; row < nr; ++row)
869 for (col_type col = 0; col < nc; ++col) {
870 new_cells[row * (nc + 1) + col + (col >= newcol)]
871 = cells_[row * nc + col];
872 new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
873 = cellinfo_[row * nc + col];
875 swap(cells_, new_cells);
876 swap(cellinfo_, new_cellinfo);
879 inf.skip_ = defaultColSpace(newcol);
880 inf.align_ = defaultColAlign(newcol);
881 colinfo_.insert(colinfo_.begin() + newcol, inf);
885 void InsetMathGrid::delCol(col_type col)
891 vector<CellInfo> tmpcellinfo;
892 for (col_type i = 0; i < nargs(); ++i)
893 if (i % ncols() != col) {
894 tmpcells.push_back(cells_[i]);
895 tmpcellinfo.push_back(cellinfo_[i]);
897 swap(cells_, tmpcells);
898 swap(cellinfo_, tmpcellinfo);
900 colinfo_.erase(colinfo_.begin() + col);
904 void InsetMathGrid::copyCol(col_type col)
907 for (row_type row = 0; row < nrows(); ++row)
908 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
912 void InsetMathGrid::swapCol(col_type col)
916 if (col + 1 == ncols())
918 for (row_type row = 0; row < nrows(); ++row)
919 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
923 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
925 if (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN)
927 col_type c = col(idx);
928 int x = colinfo_[c].offset_;
929 char align = displayColAlign(idx);
930 Dimension const & celldim = cell(idx).dimension(bv);
931 if (align == 'r' || align == 'R')
932 x += cellWidth(idx) - celldim.wid;
933 if (align == 'c' || align == 'C')
934 x += (cellWidth(idx) - celldim.wid) / 2;
939 int InsetMathGrid::cellYOffset(idx_type idx) const
941 return rowinfo_[row(idx)].offset_;
945 int InsetMathGrid::cellWidth(idx_type idx) const
947 switch (cellinfo_[idx].multi_) {
949 return colinfo_[col(idx)].width_;
950 case CELL_BEGIN_OF_MULTICOLUMN: {
951 col_type c1 = col(idx);
952 col_type c2 = c1 + ncellcols(idx);
953 return colinfo_[c2].offset_
954 - colinfo_[c1].offset_
957 - colinfo_[c2].lines_ * vlinesep();
959 case CELL_PART_OF_MULTICOLUMN:
966 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
971 cur.idx() -= ncols();
973 if (cur.row() + 1 >= nrows())
975 cur.idx() += ncols();
977 // If we are in a multicolumn cell, move to the "real" cell
978 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
979 LASSERT(cur.idx() > 0, return false);
982 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
987 bool InsetMathGrid::idxBackward(Cursor & cur) const
989 // leave matrix if at the front edge
993 // If we are in a multicolumn cell, move to the "real" cell
994 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
995 LASSERT(cur.idx() > 0, return false);
998 cur.pos() = cur.lastpos();
1003 bool InsetMathGrid::idxForward(Cursor & cur) const
1005 // leave matrix if at the back edge
1006 if (cur.col() + 1 == ncols())
1009 // If we are in a multicolumn cell, move to the next cell
1010 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1011 // leave matrix if at the back edge
1012 if (cur.col() + 1 == ncols())
1021 bool InsetMathGrid::idxFirst(Cursor & cur) const
1028 cur.idx() = (nrows() - 1) * ncols();
1031 cur.idx() = ((nrows() - 1) / 2) * ncols();
1033 // If we are in a multicolumn cell, move to the "real" cell
1034 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1035 LASSERT(cur.idx() > 0, return false);
1043 bool InsetMathGrid::idxLast(Cursor & cur) const
1047 cur.idx() = ncols() - 1;
1050 cur.idx() = nargs() - 1;
1053 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
1055 // If we are in a multicolumn cell, move to the "real" cell
1056 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1057 LASSERT(cur.idx() > 0, return false);
1060 cur.pos() = cur.lastpos();
1065 bool InsetMathGrid::idxDelete(idx_type & idx)
1067 // nothing to do if we have just one row
1071 // nothing to do if we are in the middle of the last row of the inset
1072 if (idx + ncols() > nargs())
1075 // try to delete entire sequence of ncols() empty cells if possible
1076 for (idx_type i = idx; i < idx + ncols(); ++i)
1077 if (!cell(i).empty())
1080 // move cells if necessary
1081 for (idx_type i = index(row(idx), 0); i < idx; ++i)
1082 swap(cell(i), cell(i + ncols()));
1089 // undo effect of Ctrl-Tab (i.e. pull next cell)
1090 //if (idx + 1 != nargs())
1091 // cell(idx).swap(cell(idx + 1));
1093 // we handled the event..
1098 // reimplement old behaviour when pressing Delete in the last position
1100 void InsetMathGrid::idxGlue(idx_type idx)
1102 col_type c = col(idx);
1103 if (c + 1 == ncols()) {
1104 if (row(idx) + 1 != nrows()) {
1105 for (col_type cc = 0; cc < ncols(); ++cc)
1106 cell(idx).append(cell(idx + cc + 1));
1107 delRow(row(idx) + 1);
1110 idx_type idx_next = idx + 1;
1111 while (idx_next < nargs() &&
1112 cellinfo_[idx_next].multi_ == CELL_PART_OF_MULTICOLUMN)
1114 if (idx_next < nargs())
1115 cell(idx).append(cell(idx_next));
1116 col_type oldcol = c + 1;
1117 for (col_type cc = c + 2; cc < ncols(); ++cc)
1118 cell(idx - oldcol + cc) = cell(idx - oldcol + 1 + cc);
1119 cell(idx - c + ncols() - 1).clear();
1124 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
1126 return rowinfo_[row];
1130 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
1132 return rowinfo_[row];
1136 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
1138 row_type const ri = row(idx);
1139 row_type const r1 = min(row(from), row(to));
1140 row_type const r2 = max(row(from), row(to));
1141 col_type const ci = col(idx);
1142 col_type const c1 = min(col(from), col(to));
1143 col_type const c2 = max(col(from), col(to));
1144 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
1148 void InsetMathGrid::normalize(NormalStream & os) const
1151 for (row_type row = 0; row < nrows(); ++row) {
1153 for (col_type col = 0; col < ncols(); ++col) {
1154 idx_type const i = index(row, col);
1155 switch (cellinfo_[i].multi_) {
1157 os << "[cell " << cell(i) << ']';
1159 case CELL_BEGIN_OF_MULTICOLUMN:
1160 os << "[cell colspan="
1161 << static_cast<int>(ncellcols(i)) << ' '
1164 case CELL_PART_OF_MULTICOLUMN:
1174 void InsetMathGrid::mathmlize(MathStream & os) const
1176 bool const havetable = nrows() > 1 || ncols() > 1;
1178 os << MTag("mtable");
1179 char const * const celltag = havetable ? "mtd" : "mrow";
1180 for (row_type row = 0; row < nrows(); ++row) {
1183 for (col_type col = 0; col < ncols(); ++col) {
1184 idx_type const i = index(row, col);
1185 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1186 col_type const cellcols = ncellcols(i);
1188 if (havetable && cellcols > 1)
1189 attr << "colspan='" << cellcols << '\'';
1190 os << MTag(celltag, attr.str());
1191 os << cell(index(row, col));
1192 os << ETag(celltag);
1199 os << ETag("mtable");
1204 // We need to do something about alignment here.
1205 void InsetMathGrid::htmlize(HtmlStream & os, string attrib) const
1207 bool const havetable = nrows() > 1 || ncols() > 1;
1209 os << cell(index(0, 0));
1212 os << MTag("table", attrib);
1213 for (row_type row = 0; row < nrows(); ++row) {
1215 for (col_type col = 0; col < ncols(); ++col) {
1216 idx_type const i = index(row, col);
1217 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1218 col_type const cellcols = ncellcols(i);
1221 attr << "colspan='" << cellcols << '\'';
1222 os << MTag("td", attr.str());
1223 os << cell(index(row, col));
1229 os << ETag("table");
1233 void InsetMathGrid::htmlize(HtmlStream & os) const
1235 htmlize(os, "class='mathtable'");
1239 void InsetMathGrid::write(WriteStream & os) const
1241 write(os, 0, 0, nrows(), ncols());
1244 void InsetMathGrid::write(WriteStream & os,
1245 row_type beg_row, col_type beg_col,
1246 row_type end_row, col_type end_col) const
1248 MathEnsurer ensurer(os, false);
1250 for (row_type row = beg_row; row < end_row; ++row) {
1251 os << verboseHLine(rowinfo_[row].lines_);
1252 // don't write & and empty cells at end of line,
1253 // unless there are vertical lines
1254 col_type lastcol = 0;
1255 bool emptyline = true;
1256 bool last_eoln = true;
1257 for (col_type col = beg_col; col < end_col; ++col) {
1258 idx_type const idx = index(row, col);
1259 if (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN)
1261 bool const empty_cell = cell(idx).empty();
1264 if (!empty_cell || colinfo_[col + 1].lines_) {
1269 for (col_type col = beg_col; col < lastcol;) {
1271 idx_type const idx = index(row, col);
1272 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1274 while (s < ncols() &&
1275 cellinfo_[index(row, s)].multi_ == CELL_PART_OF_MULTICOLUMN)
1278 os << "\\multicolumn{" << nccols
1279 << "}{" << cellinfo_[idx].align_
1283 if (os.pendingBrace())
1284 ModeSpecifier specifier(os, TEXT_MODE);
1285 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1287 os << eocString(col, lastcol);
1290 eol = eolString(row, os.fragile(), os.latex(), last_eoln);
1292 // append newline only if line wasn't completely empty
1293 // and the formula is not written on a single line
1294 bool const empty = emptyline && eol.empty();
1295 if (!empty && nrows() > 1)
1298 // @TODO use end_row instead of nrows() ?
1299 docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
1311 int InsetMathGrid::colsep() const
1317 int InsetMathGrid::rowsep() const
1323 int InsetMathGrid::hlinesep() const
1329 int InsetMathGrid::vlinesep() const
1335 int InsetMathGrid::border() const
1341 void InsetMathGrid::splitCell(Cursor & cur)
1343 if (cur.idx() == cur.lastidx())
1345 MathData ar = cur.cell();
1346 ar.erase(0, cur.pos());
1347 cur.cell().erase(cur.pos(), cur.lastpos());
1349 while (cur.idx() << nargs() &&
1350 cellinfo_[cur.idx()].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1353 cur.cell().insert(0, ar);
1357 char InsetMathGrid::displayColAlign(idx_type idx) const
1359 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1360 // align_ may also contain lines like "||r|", so this is
1361 // not complete, but we catch at least the simple cases.
1362 if (cellinfo_[idx].align_ == "c")
1364 if (cellinfo_[idx].align_ == "l")
1366 if (cellinfo_[idx].align_ == "r")
1369 return colinfo_[col(idx)].align_;
1373 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1375 //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1377 Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
1379 FuncCode const act = cmd.action();
1382 // insert file functions
1383 case LFUN_LINE_DELETE_FORWARD:
1384 cur.recordUndoInset();
1385 //autocorrect_ = false;
1393 if (cur.idx() > cur.lastidx())
1394 cur.idx() = cur.lastidx();
1395 if (cur.pos() > cur.lastpos())
1396 cur.pos() = cur.lastpos();
1399 case LFUN_CELL_SPLIT:
1404 case LFUN_CELL_BACKWARD:
1406 cur.setSelection(false);
1407 if (!idxPrev(cur)) {
1408 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1413 case LFUN_CELL_FORWARD:
1414 // Can't handle selection by additional 'shift' as this is
1415 // hard bound to LFUN_CELL_BACKWARD
1416 cur.setSelection(false);
1417 if (!idxNext(cur)) {
1418 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1423 case LFUN_NEWLINE_INSERT: {
1424 cur.recordUndoInset();
1425 row_type const r = cur.row();
1429 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1430 swap(cell(index(r, c)), cell(index(r + 1, c)));
1434 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1437 cur.pos() = cur.lastpos();
1438 cur.forceBufferUpdate();
1439 //mathcursor->normalize();
1440 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1444 case LFUN_INSET_MODIFY: {
1445 cur.recordUndoInset();
1446 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1447 istringstream is(to_utf8(cmd.argument()));
1450 if (s != "tabular") {
1451 InsetMathNest::doDispatch(cur, cmd);
1455 if (s == "valign-top")
1456 setVerticalAlignment('t');
1457 else if (s == "valign-middle")
1458 setVerticalAlignment('c');
1459 else if (s == "valign-bottom")
1460 setVerticalAlignment('b');
1461 else if (s == "align-left")
1462 setHorizontalAlignment('l', cur.col());
1463 else if (s == "align-right")
1464 setHorizontalAlignment('r', cur.col());
1465 else if (s == "align-center")
1466 setHorizontalAlignment('c', cur.col());
1467 else if (s == "append-row")
1468 for (int i = 0, n = extractInt(is); i < n; ++i)
1470 else if (s == "delete-row") {
1471 cur.clearSelection(); // bug 4323
1472 for (int i = 0, n = extractInt(is); i < n; ++i) {
1474 if (cur.idx() >= nargs())
1475 cur.idx() -= ncols();
1477 cur.pos() = 0; // trick, see below
1479 else if (s == "copy-row") {
1480 // Here (as later) we save the cursor col/row
1481 // in order to restore it after operation.
1482 row_type const r = cur.row();
1483 col_type const c = cur.col();
1484 for (int i = 0, n = extractInt(is); i < n; ++i)
1486 cur.idx() = index(r, c);
1488 else if (s == "swap-row") {
1490 // Trick to suppress same-idx-means-different-cell
1494 else if (s == "add-hline-above")
1495 rowinfo_[cur.row()].lines_++;
1496 else if (s == "add-hline-below")
1497 rowinfo_[cur.row()+1].lines_++;
1498 else if (s == "delete-hline-above")
1499 rowinfo_[cur.row()].lines_--;
1500 else if (s == "delete-hline-below")
1501 rowinfo_[cur.row()+1].lines_--;
1502 else if (s == "append-column") {
1503 row_type const r = cur.row();
1504 col_type const c = cur.col();
1505 for (int i = 0, n = extractInt(is); i < n; ++i)
1506 addCol(cur.col() + 1);
1507 cur.idx() = index(r, c);
1509 else if (s == "delete-column") {
1510 cur.clearSelection(); // bug 4323
1511 row_type const r = cur.row();
1512 col_type const c = cur.col();
1513 for (int i = 0, n = extractInt(is); i < n; ++i)
1514 delCol(col(cur.idx()));
1515 cur.idx() = index(r, min(c, cur.ncols() - 1));
1516 cur.pos() = 0; // trick, see above
1518 else if (s == "copy-column") {
1519 row_type const r = cur.row();
1520 col_type const c = cur.col();
1522 cur.idx() = index(r, c);
1524 else if (s == "swap-column") {
1526 cur.pos() = 0; // trick, see above
1528 else if (s == "add-vline-left") {
1529 colinfo_[cur.col()].lines_++;
1530 if (!colinfo_[cur.col()].special_.empty())
1531 colinfo_[cur.col()].special_ += '|';
1533 else if (s == "add-vline-right") {
1534 colinfo_[cur.col()+1].lines_++;
1535 if (!colinfo_[cur.col()+1].special_.empty())
1536 colinfo_[cur.col()+1].special_.insert(0, 1, '|');
1538 else if (s == "delete-vline-left") {
1539 colinfo_[cur.col()].lines_--;
1540 docstring & special = colinfo_[cur.col()].special_;
1541 if (!special.empty()) {
1542 docstring::size_type i = special.rfind('|');
1543 LASSERT(i != docstring::npos, break);
1544 special.erase(i, 1);
1547 else if (s == "delete-vline-right") {
1548 colinfo_[cur.col()+1].lines_--;
1549 docstring & special = colinfo_[cur.col()+1].special_;
1550 if (!special.empty()) {
1551 docstring::size_type i = special.find('|');
1552 LASSERT(i != docstring::npos, break);
1553 special.erase(i, 1);
1560 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1561 //lyxerr << "returning FINISHED_LEFT" << endl;
1565 case LFUN_CLIPBOARD_PASTE:
1566 parseflg |= Parse::VERBATIM;
1569 if (cur.currentMode() <= TEXT_MODE)
1570 parseflg |= Parse::TEXTMODE;
1571 cur.message(_("Paste"));
1572 cap::replaceSelection(cur);
1574 if (cmd.argument().empty() && !theClipboard().isInternal())
1575 topaste = theClipboard().getAsText(Clipboard::PlainTextType);
1577 idocstringstream is(cmd.argument());
1580 topaste = cap::selection(n, buffer().params().documentClassPtr());
1582 InsetMathGrid grid(buffer_, 1, 1);
1583 if (!topaste.empty())
1584 if ((topaste.size() == 1 && isAscii(topaste))
1585 || !mathed_parse_normal(grid, topaste, parseflg)) {
1587 mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
1590 bool hline_enabled = false;
1591 FuncRequest fr = FuncRequest(LFUN_INSET_MODIFY, "tabular add-hline-above");
1593 if (getStatus(cur, fr, status))
1594 hline_enabled = status.enabled();
1595 if (grid.nargs() == 1) {
1596 // single cell/part of cell
1597 cur.recordUndoInset();
1598 cur.cell().insert(cur.pos(), grid.cell(0));
1599 cur.pos() += grid.cell(0).size();
1601 rowinfo_[cur.row()].lines_ += grid.rowinfo_[0].lines_;
1603 for (unsigned int l = 0; l < grid.rowinfo_[0].lines_; ++l) {
1604 cur.cell().insert(0,
1605 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1611 cur.recordUndoInset();
1612 col_type const numcols =
1613 min(grid.ncols(), ncols() - col(cur.idx()));
1614 row_type const numrows =
1615 min(grid.nrows(), nrows() - cur.row());
1616 for (row_type r = 0; r < numrows; ++r) {
1617 for (col_type c = 0; c < numcols; ++c) {
1618 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1619 cell(i).insert(0, grid.cell(grid.index(r, c)));
1622 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1624 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1625 idx_type i = index(r + cur.row(), 0);
1627 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1630 // append the left over horizontal cells to the last column
1631 idx_type i = index(r + cur.row(), ncols() - 1);
1632 for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
1633 cell(i).append(grid.cell(grid.index(r, c)));
1635 // append the left over vertical cells to the last _cell_
1636 idx_type i = nargs() - 1;
1637 for (row_type r = numrows; r < grid.nrows(); ++r) {
1638 for (col_type c = 0; c < grid.ncols(); ++c)
1639 cell(i).append(grid.cell(grid.index(r, c)));
1641 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1643 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1645 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1650 cur.clearSelection(); // bug 393
1651 // FIXME audit setBuffer calls
1652 cur.inset().setBuffer(*buffer_);
1653 cur.forceBufferUpdate();
1658 case LFUN_LINE_BEGIN:
1659 case LFUN_WORD_BACKWARD:
1660 case LFUN_WORD_LEFT:
1661 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1662 case LFUN_LINE_BEGIN_SELECT:
1663 case LFUN_WORD_BACKWARD_SELECT:
1664 case LFUN_WORD_LEFT_SELECT:
1665 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1666 act == LFUN_WORD_LEFT_SELECT ||
1667 act == LFUN_LINE_BEGIN_SELECT);
1668 cur.macroModeClose();
1669 if (cur.pos() != 0) {
1671 } else if (cur.idx() % cur.ncols() != 0) {
1672 cur.idx() -= cur.idx() % cur.ncols();
1674 } else if (cur.idx() != 0) {
1678 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1683 case LFUN_WORD_FORWARD:
1684 case LFUN_WORD_RIGHT:
1686 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1687 case LFUN_WORD_FORWARD_SELECT:
1688 case LFUN_WORD_RIGHT_SELECT:
1689 case LFUN_LINE_END_SELECT:
1690 cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
1691 act == LFUN_WORD_RIGHT_SELECT ||
1692 act == LFUN_LINE_END_SELECT);
1693 cur.macroModeClose();
1695 if (cur.pos() != cur.lastpos()) {
1696 cur.pos() = cur.lastpos();
1697 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1698 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1699 cur.pos() = cur.lastpos();
1700 } else if (cur.idx() != cur.lastidx()) {
1701 cur.idx() = cur.lastidx();
1702 cur.pos() = cur.lastpos();
1704 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1710 InsetMathNest::doDispatch(cur, cmd);
1715 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1716 FuncStatus & status) const
1718 switch (cmd.action()) {
1719 case LFUN_INSET_MODIFY: {
1720 istringstream is(to_utf8(cmd.argument()));
1723 if (s != "tabular") {
1724 // We only now about table actions here.
1727 if (&cur.inset() != this) {
1728 // Table actions requires that the cursor is _inside_ the
1730 status.setEnabled(false);
1731 status.message(from_utf8(N_("Cursor not in table")));
1735 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1736 status.setEnabled(false);
1737 status.message(from_utf8(N_("Only one row")));
1741 (s == "delete-column" || s == "swap-column")) {
1742 status.setEnabled(false);
1743 status.message(from_utf8(N_("Only one column")));
1746 if ((rowinfo_[cur.row()].lines_ == 0 &&
1747 s == "delete-hline-above") ||
1748 (rowinfo_[cur.row() + 1].lines_ == 0 &&
1749 s == "delete-hline-below")) {
1750 status.setEnabled(false);
1751 status.message(from_utf8(N_("No hline to delete")));
1755 if ((colinfo_[cur.col()].lines_ == 0 &&
1756 s == "delete-vline-left") ||
1757 (colinfo_[cur.col() + 1].lines_ == 0 &&
1758 s == "delete-vline-right")) {
1759 status.setEnabled(false);
1760 status.message(from_utf8(N_("No vline to delete")));
1763 if (s == "valign-top" || s == "valign-middle" ||
1764 s == "valign-bottom" || s == "align-left" ||
1765 s == "align-right" || s == "align-center") {
1766 status.setEnabled(true);
1767 char const ha = horizontalAlignment(cur.col());
1768 char const va = verticalAlignment();
1769 status.setOnOff((s == "align-left" && ha == 'l')
1770 || (s == "align-right" && ha == 'r')
1771 || (s == "align-center" && ha == 'c')
1772 || (s == "valign-top" && va == 't')
1773 || (s == "valign-bottom" && va == 'b')
1774 || (s == "valign-middle" && va == 'c'));
1777 if (s == "append-row" || s == "delete-row" ||
1778 s == "copy-row" || s == "swap-row" ||
1779 s == "add-hline-above" || s == "add-hline-below" ||
1780 s == "delete-hline-above" || s == "delete-hline-below" ||
1781 s == "append-column" || s == "delete-column" ||
1782 s == "copy-column" || s == "swap-column" ||
1783 s == "add-vline-left" || s == "add-vline-right" ||
1784 s == "delete-vline-left" || s == "delete-vline-right") {
1785 status.setEnabled(true);
1787 status.setEnabled(false);
1788 status.message(bformat(
1789 from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
1793 // FIXME: What did this code do?
1794 // Please check whether it is still needed!
1795 // should be more precise
1796 if (v_align_ == '\0') {
1797 status.enable(true);
1800 if (cmd.argument().empty()) {
1801 status.enable(false);
1804 if (!contains("tcb", cmd.argument()[0])) {
1805 status.enable(false);
1808 status.setOnOff(cmd.argument()[0] == v_align_);
1809 status.setEnabled(true);
1814 case LFUN_CELL_SPLIT:
1815 status.setEnabled(cur.idx() != cur.lastidx());
1818 case LFUN_CELL_BACKWARD:
1819 case LFUN_CELL_FORWARD:
1820 status.setEnabled(true);
1826 return InsetMathNest::getStatus(cur, cmd, status);