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"
26 #include "CutAndPaste.h"
27 #include "FuncRequest.h"
28 #include "FuncStatus.h"
31 #include "frontends/Clipboard.h"
32 #include "frontends/Painter.h"
34 #include "support/debug.h"
35 #include "support/docstream.h"
36 #include "support/gettext.h"
37 #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_TABULAR_FEATURE, "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 displayColSpace(col - 1) +
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 displayColSpace(last) +
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 displayColSpace(col - 1) +
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_
956 - displayColSpace(c2)
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 RowEntry entry = TexRow::mathEntry(id(),idx);
1273 os.texrow().start(entry);
1274 if (col >= lastcol) {
1278 Changer dummy = os.changeRowEntry(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);
1297 eol = eolString(row, os.fragile(), os.latex(), last_eoln);
1299 // append newline only if line wasn't completely empty
1300 // and the formula is not written on a single line
1301 bool const empty = emptyline && eol.empty();
1302 if (!empty && nrows() > 1)
1305 // @TODO use end_row instead of nrows() ?
1306 docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
1318 int InsetMathGrid::colsep() const
1324 int InsetMathGrid::rowsep() const
1330 int InsetMathGrid::hlinesep() const
1336 int InsetMathGrid::vlinesep() const
1342 int InsetMathGrid::border() const
1348 void InsetMathGrid::splitCell(Cursor & cur)
1350 if (cur.idx() == cur.lastidx())
1352 MathData ar = cur.cell();
1353 ar.erase(0, cur.pos());
1354 cur.cell().erase(cur.pos(), cur.lastpos());
1356 while (cur.idx() << nargs() &&
1357 cellinfo_[cur.idx()].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1360 cur.cell().insert(0, ar);
1364 char InsetMathGrid::displayColAlign(idx_type idx) const
1366 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1367 // align_ may also contain lines like "||r|", so this is
1368 // not complete, but we catch at least the simple cases.
1369 if (cellinfo_[idx].align_ == "c")
1371 if (cellinfo_[idx].align_ == "l")
1373 if (cellinfo_[idx].align_ == "r")
1376 return colinfo_[col(idx)].align_;
1380 int InsetMathGrid::displayColSpace(col_type col) const
1382 return colinfo_[col].skip_;
1385 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1387 //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1389 Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
1391 FuncCode const act = cmd.action();
1394 // insert file functions
1395 case LFUN_LINE_DELETE_FORWARD:
1396 cur.recordUndoInset();
1397 //autocorrect_ = false;
1405 if (cur.idx() > cur.lastidx())
1406 cur.idx() = cur.lastidx();
1407 if (cur.pos() > cur.lastpos())
1408 cur.pos() = cur.lastpos();
1411 case LFUN_CELL_SPLIT:
1416 case LFUN_CELL_BACKWARD:
1418 cur.selection(false);
1419 if (!idxPrev(cur)) {
1420 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1425 case LFUN_CELL_FORWARD:
1426 // Can't handle selection by additional 'shift' as this is
1427 // hard bound to LFUN_CELL_BACKWARD
1428 cur.selection(false);
1429 if (!idxNext(cur)) {
1430 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1435 case LFUN_NEWLINE_INSERT: {
1436 cur.recordUndoInset();
1437 row_type const r = cur.row();
1441 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1442 swap(cell(index(r, c)), cell(index(r + 1, c)));
1447 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1450 cur.pos() = cur.lastpos();
1451 cur.forceBufferUpdate();
1452 //mathcursor->normalize();
1453 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1457 case LFUN_TABULAR_FEATURE: {
1458 cur.recordUndoInset();
1459 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1460 istringstream is(to_utf8(cmd.argument()));
1463 if (s == "valign-top")
1464 setVerticalAlignment('t');
1465 else if (s == "valign-middle")
1466 setVerticalAlignment('c');
1467 else if (s == "valign-bottom")
1468 setVerticalAlignment('b');
1469 else if (s == "align-left")
1470 setHorizontalAlignment('l', cur.col());
1471 else if (s == "align-right")
1472 setHorizontalAlignment('r', cur.col());
1473 else if (s == "align-center")
1474 setHorizontalAlignment('c', cur.col());
1475 else if (s == "append-row")
1476 for (int i = 0, n = extractInt(is); i < n; ++i)
1478 else if (s == "delete-row") {
1479 cur.clearSelection(); // bug 4323
1480 for (int i = 0, n = extractInt(is); i < n; ++i) {
1482 if (cur.idx() >= nargs())
1483 cur.idx() -= ncols();
1485 cur.pos() = 0; // trick, see below
1487 else if (s == "copy-row") {
1488 // Here (as later) we save the cursor col/row
1489 // in order to restore it after operation.
1490 row_type const r = cur.row();
1491 col_type const c = cur.col();
1492 for (int i = 0, n = extractInt(is); i < n; ++i)
1494 cur.idx() = index(r, c);
1496 else if (s == "swap-row") {
1498 // Trick to suppress same-idx-means-different-cell
1502 else if (s == "add-hline-above")
1503 rowinfo_[cur.row()].lines_++;
1504 else if (s == "add-hline-below")
1505 rowinfo_[cur.row()+1].lines_++;
1506 else if (s == "delete-hline-above")
1507 rowinfo_[cur.row()].lines_--;
1508 else if (s == "delete-hline-below")
1509 rowinfo_[cur.row()+1].lines_--;
1510 else if (s == "append-column") {
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 addCol(cur.col() + 1);
1515 cur.idx() = index(r, c);
1517 else if (s == "delete-column") {
1518 cur.clearSelection(); // bug 4323
1519 row_type const r = cur.row();
1520 col_type const c = cur.col();
1521 for (int i = 0, n = extractInt(is); i < n; ++i)
1522 delCol(col(cur.idx()));
1523 cur.idx() = index(r, min(c, cur.ncols() - 1));
1524 cur.pos() = 0; // trick, see above
1526 else if (s == "copy-column") {
1527 row_type const r = cur.row();
1528 col_type const c = cur.col();
1530 cur.idx() = index(r, c);
1532 else if (s == "swap-column") {
1534 cur.pos() = 0; // trick, see above
1536 else if (s == "add-vline-left") {
1537 colinfo_[cur.col()].lines_++;
1538 if (!colinfo_[cur.col()].special_.empty())
1539 colinfo_[cur.col()].special_ += '|';
1541 else if (s == "add-vline-right") {
1542 colinfo_[cur.col()+1].lines_++;
1543 if (!colinfo_[cur.col()+1].special_.empty())
1544 colinfo_[cur.col()+1].special_.insert(0, 1, '|');
1546 else if (s == "delete-vline-left") {
1547 colinfo_[cur.col()].lines_--;
1548 docstring & special = colinfo_[cur.col()].special_;
1549 if (!special.empty()) {
1550 docstring::size_type i = special.rfind('|');
1551 LASSERT(i != docstring::npos, break);
1552 special.erase(i, 1);
1555 else if (s == "delete-vline-right") {
1556 colinfo_[cur.col()+1].lines_--;
1557 docstring & special = colinfo_[cur.col()+1].special_;
1558 if (!special.empty()) {
1559 docstring::size_type i = special.find('|');
1560 LASSERT(i != docstring::npos, break);
1561 special.erase(i, 1);
1568 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1569 //lyxerr << "returning FINISHED_LEFT" << endl;
1573 case LFUN_CLIPBOARD_PASTE:
1574 parseflg |= Parse::VERBATIM;
1577 if (cur.currentMode() <= TEXT_MODE)
1578 parseflg |= Parse::TEXTMODE;
1579 cur.message(_("Paste"));
1580 cap::replaceSelection(cur);
1582 if (cmd.argument().empty() && !theClipboard().isInternal())
1583 topaste = theClipboard().getAsText(frontend::Clipboard::PlainTextType);
1585 idocstringstream is(cmd.argument());
1588 topaste = cap::selection(n, buffer().params().documentClassPtr());
1590 InsetMathGrid grid(buffer_, 1, 1);
1591 if (!topaste.empty())
1592 if ((topaste.size() == 1 && isAscii(topaste))
1593 || !mathed_parse_normal(grid, topaste, parseflg)) {
1595 mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
1598 bool hline_enabled = false;
1599 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
1601 if (getStatus(cur, fr, status))
1602 hline_enabled = status.enabled();
1603 if (grid.nargs() == 1) {
1604 // single cell/part of cell
1605 cur.recordUndoInset();
1606 cur.cell().insert(cur.pos(), grid.cell(0));
1607 cur.pos() += grid.cell(0).size();
1609 rowinfo_[cur.row()].lines_ += grid.rowinfo_[0].lines_;
1611 for (unsigned int l = 0; l < grid.rowinfo_[0].lines_; ++l) {
1612 cur.cell().insert(0,
1613 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1619 cur.recordUndoInset();
1620 col_type const numcols =
1621 min(grid.ncols(), ncols() - col(cur.idx()));
1622 row_type const numrows =
1623 min(grid.nrows(), nrows() - cur.row());
1624 for (row_type r = 0; r < numrows; ++r) {
1625 for (col_type c = 0; c < numcols; ++c) {
1626 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1627 cell(i).insert(0, grid.cell(grid.index(r, c)));
1630 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1632 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1633 idx_type i = index(r + cur.row(), 0);
1635 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1638 // append the left over horizontal cells to the last column
1639 idx_type i = index(r + cur.row(), ncols() - 1);
1640 for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
1641 cell(i).append(grid.cell(grid.index(r, c)));
1643 // append the left over vertical cells to the last _cell_
1644 idx_type i = nargs() - 1;
1645 for (row_type r = numrows; r < grid.nrows(); ++r) {
1646 for (col_type c = 0; c < grid.ncols(); ++c)
1647 cell(i).append(grid.cell(grid.index(r, c)));
1649 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1651 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1653 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1658 cur.clearSelection(); // bug 393
1659 // FIXME audit setBuffer calls
1660 cur.inset().setBuffer(*buffer_);
1661 cur.forceBufferUpdate();
1666 case LFUN_LINE_BEGIN:
1667 case LFUN_WORD_BACKWARD:
1668 case LFUN_WORD_LEFT:
1669 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1671 case LFUN_LINE_BEGIN_SELECT:
1672 case LFUN_WORD_BACKWARD_SELECT:
1673 case LFUN_WORD_LEFT_SELECT:
1674 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1675 act == LFUN_WORD_LEFT_SELECT ||
1676 act == LFUN_LINE_BEGIN_SELECT);
1677 cur.macroModeClose();
1678 if (cur.pos() != 0) {
1680 } else if (cur.idx() % cur.ncols() != 0) {
1681 cur.idx() -= cur.idx() % cur.ncols();
1683 } else if (cur.idx() != 0) {
1687 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1692 case LFUN_WORD_FORWARD:
1693 case LFUN_WORD_RIGHT:
1695 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1697 case LFUN_WORD_FORWARD_SELECT:
1698 case LFUN_WORD_RIGHT_SELECT:
1699 case LFUN_LINE_END_SELECT:
1700 cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
1701 act == LFUN_WORD_RIGHT_SELECT ||
1702 act == LFUN_LINE_END_SELECT);
1703 cur.macroModeClose();
1705 if (cur.pos() != cur.lastpos()) {
1706 cur.pos() = cur.lastpos();
1707 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1708 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1709 cur.pos() = cur.lastpos();
1710 } else if (cur.idx() != cur.lastidx()) {
1711 cur.idx() = cur.lastidx();
1712 cur.pos() = cur.lastpos();
1714 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1720 InsetMathNest::doDispatch(cur, cmd);
1725 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1726 FuncStatus & status) const
1728 switch (cmd.action()) {
1729 case LFUN_TABULAR_FEATURE: {
1730 string s = cmd.getArg(0);
1731 if (&cur.inset() != this) {
1732 // Table actions requires that the cursor is _inside_ the
1734 status.setEnabled(false);
1735 status.message(from_utf8(N_("Cursor not in table")));
1738 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1739 status.setEnabled(false);
1740 status.message(from_utf8(N_("Only one row")));
1744 (s == "delete-column" || s == "swap-column")) {
1745 status.setEnabled(false);
1746 status.message(from_utf8(N_("Only one column")));
1749 if ((rowinfo_[cur.row()].lines_ == 0 &&
1750 s == "delete-hline-above") ||
1751 (rowinfo_[cur.row() + 1].lines_ == 0 &&
1752 s == "delete-hline-below")) {
1753 status.setEnabled(false);
1754 status.message(from_utf8(N_("No hline to delete")));
1758 if ((colinfo_[cur.col()].lines_ == 0 &&
1759 s == "delete-vline-left") ||
1760 (colinfo_[cur.col() + 1].lines_ == 0 &&
1761 s == "delete-vline-right")) {
1762 status.setEnabled(false);
1763 status.message(from_utf8(N_("No vline to delete")));
1766 if (s == "valign-top" || s == "valign-middle" ||
1767 s == "valign-bottom" || s == "align-left" ||
1768 s == "align-right" || s == "align-center") {
1769 status.setEnabled(true);
1770 char const ha = horizontalAlignment(cur.col());
1771 char const va = verticalAlignment();
1772 status.setOnOff((s == "align-left" && ha == 'l')
1773 || (s == "align-right" && ha == 'r')
1774 || (s == "align-center" && ha == 'c')
1775 || (s == "valign-top" && va == 't')
1776 || (s == "valign-bottom" && va == 'b')
1777 || (s == "valign-middle" && va == 'c'));
1780 if (s == "append-row" || s == "delete-row" ||
1781 s == "copy-row" || s == "swap-row" ||
1782 s == "add-hline-above" || s == "add-hline-below" ||
1783 s == "delete-hline-above" || s == "delete-hline-below" ||
1784 s == "append-column" || s == "delete-column" ||
1785 s == "copy-column" || s == "swap-column" ||
1786 s == "add-vline-left" || s == "add-vline-right" ||
1787 s == "delete-vline-left" || s == "delete-vline-right") {
1788 status.setEnabled(true);
1790 status.setEnabled(false);
1791 status.message(bformat(
1792 from_utf8(N_("Unknown tabular feature '%1$s'")),
1797 // FIXME: What did this code do?
1798 // Please check whether it is still needed!
1799 // should be more precise
1800 if (v_align_ == '\0') {
1801 status.enable(true);
1804 if (cmd.argument().empty()) {
1805 status.enable(false);
1808 if (!contains("tcb", cmd.argument()[0])) {
1809 status.enable(false);
1812 status.setOnOff(cmd.argument()[0] == v_align_);
1813 status.setEnabled(true);
1818 case LFUN_CELL_SPLIT:
1819 status.setEnabled(cur.idx() != cur.lastidx());
1822 case LFUN_CELL_BACKWARD:
1823 case LFUN_CELL_FORWARD:
1824 status.setEnabled(true);
1830 return InsetMathNest::getStatus(cur, cmd, status);
1835 char InsetMathGrid::colAlign(HullType type, col_type col)
1839 return "rcl"[col % 3];
1850 return "rl"[col & 1];
1865 int InsetMathGrid::colSpace(HullType type, col_type col)
1867 int alignInterSpace = 0;
1882 alignInterSpace = 20;
1885 alignInterSpace = 0;
1888 alignInterSpace = 40;
1892 alignInterSpace = 60;
1895 return (col % 2) ? alignInterSpace : 0;