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 "CoordCache.h"
27 #include "CutAndPaste.h"
28 #include "FuncRequest.h"
29 #include "FuncStatus.h"
30 #include "LaTeXFeatures.h"
33 #include "frontends/Clipboard.h"
34 #include "frontends/Painter.h"
36 #include "support/debug.h"
37 #include "support/docstream.h"
38 #include "support/gettext.h"
39 #include "support/lstrings.h"
40 #include "support/lassert.h"
45 using namespace lyx::support;
51 static docstring verboseHLine(int n)
54 for (int i = 0; i < n; ++i)
62 static int extractInt(istream & is)
66 return (num == 0) ? 1 : num;
70 static void resetGrid(InsetMathGrid & grid)
72 while (grid.ncols() > 1)
73 grid.delCol(grid.ncols() - 1);
74 while (grid.nrows() > 1)
75 grid.delRow(grid.nrows() - 1);
76 grid.cell(0).erase(0, grid.cell(0).size());
81 //////////////////////////////////////////////////////////////
84 int InsetMathGrid::RowInfo::skipPixels(MetricsInfo const & mi) const
86 return mi.base.inPixels(crskip);
90 //////////////////////////////////////////////////////////////
93 InsetMathGrid::InsetMathGrid(Buffer * buf)
94 : InsetMathNest(buf, 1),
104 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n)
105 : InsetMathNest(buf, m * n),
115 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n, char v,
117 : InsetMathNest(buf, m * n),
124 setVerticalAlignment(v);
125 setHorizontalAlignments(h);
129 Inset * InsetMathGrid::clone() const
131 return new InsetMathGrid(*this);
135 idx_type InsetMathGrid::index(row_type row, col_type col) const
137 return col + ncols() * row;
141 void InsetMathGrid::setDefaults()
144 lyxerr << "positive number of columns expected" << endl;
146 // lyxerr << "positive number of rows expected" << endl;
147 for (col_type col = 0; col < ncols(); ++col) {
148 colinfo_[col].align = defaultColAlign(col);
149 colinfo_[col].skip = defaultColSpace(col);
150 colinfo_[col].special.clear();
152 for (idx_type idx = 0; idx < nargs(); ++idx)
153 cellinfo_[idx].multi = CELL_NORMAL;
157 bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
159 if (str == "\\hline") {
160 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
162 if (getStatus(cur, fr, status)) {
163 if (status.enabled()) {
164 rowinfo_[cur.row()].lines++;
169 return InsetMathNest::interpretString(cur, str);
173 void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
176 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
179 colinfo_[col].lines++;
180 } else if ((c == 'p' || c == 'm' || c == 'b'||
181 c == '!' || c == '@' || c == '>' || c == '<') &&
182 it + 1 != hh.end() && *(it + 1) == '{') {
183 // @{decl.} and p{width} are standard LaTeX, the
184 // others are extensions by array.sty
185 bool const newcolumn = c == 'p' || c == 'm' || c == 'b';
187 // this declares a new column
189 // Only intercolumn stuff is allowed
190 // in the last dummy column
192 colinfo_[col].align = 'l';
194 // this is intercolumn stuff
195 if (colinfo_[col].special.empty())
196 // Overtake possible lines
197 colinfo_[col].special = docstring(colinfo_[col].lines, '|');
201 while (it != hh.end()) {
203 colinfo_[col].special += c;
209 if (brace_open > 0 && brace_open == brace_close)
214 colinfo_[col].lines = count(
215 colinfo_[col].special.begin(),
216 colinfo_[col].special.end(), '|');
217 LYXERR(Debug::MATHED, "special column separator: `"
218 << to_utf8(colinfo_[col].special) << '\'');
220 colinfo_[col].lines = 0;
221 colinfo_[col].special.clear();
223 } else if (col >= ncols()) {
224 // Only intercolumn stuff is allowed in the last
227 } else if (c == 'c' || c == 'l' || c == 'r') {
228 colinfo_[col].align = static_cast<char>(c);
229 if (!colinfo_[col].special.empty()) {
230 colinfo_[col].special += c;
231 colinfo_[col].lines = count(
232 colinfo_[col].special.begin(),
233 colinfo_[col].special.end(), '|');
234 LYXERR(Debug::MATHED, "special column separator: `"
235 << to_utf8(colinfo_[col].special) << '\'');
238 colinfo_[col].lines = 0;
239 colinfo_[col].special.clear();
241 lyxerr << "unknown column separator: '" << c << "'" << endl;
246 col_type n = hh.size();
249 for (col_type col = 0; col < n; ++col)
250 colinfo_[col].align = hh[col];
255 col_type InsetMathGrid::guessColumns(docstring const & hh)
258 for (char_type const c : hh)
259 if (c == 'c' || c == 'l' || c == 'r'||
260 c == 'p' || c == 'm' || c == 'b')
262 // let's have at least one column, even if we did not recognize its
270 void InsetMathGrid::setHorizontalAlignment(char h, col_type col)
272 colinfo_[col].align = h;
273 if (!colinfo_[col].special.empty()) {
274 char_type & c = colinfo_[col].special[colinfo_[col].special.size() - 1];
275 if (c == 'l' || c == 'c' || c == 'r')
278 // FIXME: Change alignment of p, m and b columns, too
282 char InsetMathGrid::horizontalAlignment(col_type col) const
284 return colinfo_[col].align;
288 docstring InsetMathGrid::horizontalAlignments() const
291 for (col_type col = 0; col < ncols(); ++col) {
292 if (colinfo_[col].special.empty()) {
293 res += docstring(colinfo_[col].lines, '|');
294 res += colinfo_[col].align;
296 res += colinfo_[col].special;
298 if (colinfo_[ncols()].special.empty())
299 return res + docstring(colinfo_[ncols()].lines, '|');
300 return res + colinfo_[ncols()].special;
304 void InsetMathGrid::setVerticalAlignment(char c)
310 char InsetMathGrid::verticalAlignment() const
316 col_type InsetMathGrid::ncols() const
318 return colinfo_.size() - 1;
322 row_type InsetMathGrid::nrows() const
324 return rowinfo_.size() - 1;
328 col_type InsetMathGrid::col(idx_type idx) const
330 return idx % ncols();
334 row_type InsetMathGrid::row(idx_type idx) const
336 return idx / ncols();
340 col_type InsetMathGrid::ncellcols(idx_type idx) const
343 if (cellinfo_[idx].multi == CELL_NORMAL)
345 // If the cell at idx is already CELL_PART_OF_MULTICOLUMN we return
346 // the number of remaining columns, not the ones of the complete
347 // multicolumn cell. This makes it possible to always go to the next
348 // cell with idx + ncellcols(idx) - 1.
349 row_type const r = row(idx);
350 while (idx+cols < nargs() && row(idx+cols) == r &&
351 cellinfo_[idx+cols].multi == CELL_PART_OF_MULTICOLUMN)
357 void InsetMathGrid::vcrskip(Length const & crskip, row_type row)
359 rowinfo_[row].crskip = crskip;
363 Length InsetMathGrid::vcrskip(row_type row) const
365 return rowinfo_[row].crskip;
369 void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
371 // let the cells adjust themselves
372 for (idx_type i = 0; i < nargs(); ++i) {
373 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
375 // the 'false' is to make sure that the cell is tall enough
376 cell(i).metrics(mi, dimc, false);
380 BufferView & bv = *mi.base.bv;
382 // compute absolute sizes of vertical structure
383 for (row_type row = 0; row < nrows(); ++row) {
386 for (col_type col = 0; col < ncols(); ++col) {
387 idx_type const i = index(row, col);
388 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
389 Dimension const & dimc = cell(i).dimension(bv);
390 asc = max(asc, dimc.asc);
391 desc = max(desc, dimc.des);
394 rowinfo_[row].ascent = asc;
395 rowinfo_[row].descent = desc;
397 rowinfo_[nrows()].ascent = 0;
398 rowinfo_[nrows()].descent = 0;
400 // compute vertical offsets
401 rowinfo_[0].offset[&bv] = 0;
402 for (row_type row = 1; row <= nrows(); ++row) {
403 rowinfo_[row].offset[&bv] =
404 rowinfo_[row - 1].offset[&bv] +
405 rowinfo_[row - 1].descent +
406 rowinfo_[row - 1].skipPixels(mi) +
408 rowinfo_[row].lines * hlinesep() +
409 rowinfo_[row].ascent;
412 // adjust vertical offset
419 h = rowinfo_[nrows() - 1].offset[&bv];
422 h = rowinfo_[nrows() - 1].offset[&bv] / 2;
424 for (row_type row = 0; row <= nrows(); ++row)
425 rowinfo_[row].offset[&bv] -= h;
428 // multicolumn cell widths, as a map from first column to width in a
429 // vector of last columns.
430 // This is only used if the grid has more than one row, since for
431 // one-row grids multicolumn cells do not need special handling
432 vector<map<col_type, int> > mcolwidths(ncols());
434 // compute absolute sizes of horizontal structure
435 for (col_type col = 0; col < ncols(); ++col) {
437 for (row_type row = 0; row < nrows(); ++row) {
438 idx_type const i = index(row, col);
439 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
440 int const w = cell(i).dimension(bv).wid;
441 col_type const cols = ncellcols(i);
442 if (cols > 1 && nrows() > 1) {
443 col_type last = col+cols-1;
444 LASSERT(last < ncols(), last = ncols()-1);
445 map<col_type, int>::iterator it =
446 mcolwidths[last].find(col);
447 if (it == mcolwidths[last].end())
448 mcolwidths[last][col] = w;
450 it->second = max(it->second, w);
455 colinfo_[col].width = wid;
457 colinfo_[ncols()].width = 0;
459 // compute horizontal offsets
460 colinfo_[0].offset = border() + colinfo_[0].lines * vlinesep();
461 for (col_type col = 1; col <= ncols(); ++col) {
462 colinfo_[col].offset =
463 colinfo_[col - 1].offset +
464 colinfo_[col - 1].width +
465 displayColSpace(col - 1) +
467 colinfo_[col].lines * vlinesep();
470 // increase column widths for multicolumn cells if needed
471 // FIXME: multicolumn lines are not yet considered
472 for (col_type last = 0; last < ncols(); ++last) {
473 map<col_type, int> const & widths = mcolwidths[last];
474 // We increase the width of the last column of the multicol
475 // cell (some sort of left alignment). Since we iterate through
476 // the last and the first columns from left to right, we ensure
477 // that increased widths of previous columns are correctly
478 // taken into account for later columns, thus preventing
479 // unneeded width increasing.
480 for (map<col_type, int>::const_iterator it = widths.begin();
481 it != widths.end(); ++it) {
482 int const wid = it->second;
483 col_type const first = it->first;
484 int const nextoffset =
485 colinfo_[first].offset +
487 displayColSpace(last) +
489 colinfo_[last+1].lines * vlinesep();
490 int const dx = nextoffset - colinfo_[last+1].offset;
492 colinfo_[last].width += dx;
493 for (col_type col = last + 1; col <= ncols(); ++col)
494 colinfo_[col].offset += dx;
500 dim.wid = colinfo_[ncols() - 1].offset
501 + colinfo_[ncols() - 1].width
502 + vlinesep() * colinfo_[ncols()].lines
505 dim.asc = - rowinfo_[0].offset[&bv]
507 + hlinesep() * rowinfo_[0].lines
510 dim.des = rowinfo_[nrows() - 1].offset[&bv]
511 + rowinfo_[nrows() - 1].descent
512 + hlinesep() * rowinfo_[nrows()].lines
517 // Increase ws_[i] for 'R' columns (except the first one)
518 for (int i = 1; i < nc_; ++i)
520 ws_[i] += 10 * df_width;
521 // Increase ws_[i] for 'C' column
523 if (ws_[0] < 7 * workwidth / 8)
524 ws_[0] = 7 * workwidth / 8;
528 for (cxrow = row_.begin(); cxrow; ++cxrow) {
531 for (int i = 0; i < nc_; ++i) {
533 if (cxrow->getTab(i) <= 0) {
534 cxrow->setTab(i, df_width);
542 lf = (ws_[i] - cxrow->getTab(i))/2;
546 lf = ws_[i] - cxrow->getTab(i);
549 if (cxrow == row_.begin())
551 else if (cxrow.is_last())
552 lf = ws_[i] - cxrow->getTab(i);
554 lf = (ws_[i] - cxrow->getTab(i))/2;
557 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
558 cxrow->setTab(i, lf + rg);
559 rg = ws_[i] - ww + colsep();
560 if (cxrow == row_.begin())
561 width += ws_[i] + colsep();
563 cxrow->setBaseline(cxrow->getBaseline() - ascent);
566 dim.wid += leftMargin() + rightMargin();
570 int InsetMathGrid::vLineHOffset(col_type col, unsigned int line) const
573 return leftMargin() + colinfo_[col].offset
574 - (colinfo_[col].lines - line - 1) * vlinesep()
575 - vlinesep()/2 - colsep()/2;
577 LASSERT(col == ncols(), return 0);
578 return leftMargin() + colinfo_[col-1].offset + colinfo_[col-1].width
580 + vlinesep()/2 + colsep()/2;
585 int InsetMathGrid::hLineVOffset(BufferView const & bv, row_type row,
586 unsigned int line) const
588 return rowinfo_[row].offset[&bv]
589 - rowinfo_[row].ascent
591 - hlinesep()/2 - rowsep()/2;
595 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
597 BufferView const & bv = *pi.base.bv;
599 for (idx_type idx = 0; idx < nargs(); ++idx) {
600 if (cellinfo_[idx].multi != CELL_PART_OF_MULTICOLUMN) {
602 x + leftMargin() + cellXOffset(bv, idx),
603 y + cellYOffset(bv, idx));
605 row_type r = row(idx);
606 int const yy1 = y + hLineVOffset(bv, r, 0);
607 int const yy2 = y + hLineVOffset(bv, r + 1, rowinfo_[r + 1].lines - 1);
608 auto draw_left_borders = [&](col_type c) {
609 for (unsigned int i = 0; i < colinfo_[c].lines; ++i) {
610 int const xx = x + vLineHOffset(c, i);
611 pi.pain.line(xx, yy1, xx, yy2, Color_foreground);
614 col_type c = col(idx);
615 // Draw inner left borders cell-by-cell because of multicolumns
616 draw_left_borders(c);
617 // Draw the right border (only once)
619 draw_left_borders(ncols());
623 // Draw horizontal borders
624 for (row_type r = 0; r <= nrows(); ++r) {
625 int const xx1 = x + vLineHOffset(0, 0);
626 int const xx2 = x + vLineHOffset(ncols(), colinfo_[ncols()].lines - 1);
627 for (unsigned int i = 0; i < rowinfo_[r].lines; ++i) {
628 int const yy = y + hLineVOffset(bv, r, i);
629 pi.pain.line(xx1, yy, xx2, yy, Color_foreground);
635 void InsetMathGrid::metricsT(TextMetricsInfo const & /*mi*/, Dimension & /*dim*/) const
637 // FIXME: this does not compile anymore with offset being a map
638 // It is not worth fixing it at this point since the code is basically dead.
640 // let the cells adjust themselves
641 for (idx_type i = 0; i < nargs(); ++i)
642 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN)
643 cell(i).metricsT(mi, dim);
645 // compute absolute sizes of vertical structure
646 for (row_type row = 0; row < nrows(); ++row) {
649 for (col_type col = 0; col < ncols(); ++col) {
650 idx_type const i = index(row, col);
651 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
652 //MathData const & c = cell(i);
655 asc = max(asc, dimc.ascent());
656 desc = max(desc, dimc.descent());
659 rowinfo_[row].ascent = asc;
660 rowinfo_[row].descent = desc;
662 rowinfo_[nrows()].ascent = 0;
663 rowinfo_[nrows()].descent = 0;
665 // compute vertical offsets
666 rowinfo_[0].offset[&bv] = 0;
667 for (row_type row = 1; row <= nrows(); ++row) {
668 rowinfo_[row].offset[&bv] =
669 rowinfo_[row - 1].offset +
670 rowinfo_[row - 1].descent +
671 //rowinfo_[row - 1].skipPixels(mi) +
673 //rowinfo_[row].lines * hlinesep() +
674 rowinfo_[row].ascent;
677 // adjust vertical offset
684 h = rowinfo_[nrows() - 1].offset;
687 h = rowinfo_[nrows() - 1].offset / 2;
689 for (row_type row = 0; row <= nrows(); ++row)
690 rowinfo_[row].offset -= h;
693 // compute absolute sizes of horizontal structure
694 for (col_type col = 0; col < ncols(); ++col) {
696 for (row_type row = 0; row < nrows(); ++row) {
698 //idx_type const i = index(row, col);
699 //if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN)
700 // wid = max(wid, cell(i).width());
702 colinfo_[col].width = wid;
704 colinfo_[ncols()].width = 0;
706 // compute horizontal offsets
707 colinfo_[0].offset = border();
708 for (col_type col = 1; col <= ncols(); ++col) {
709 colinfo_[col].offset =
710 colinfo_[col - 1].offset +
711 colinfo_[col - 1].width +
712 displayColSpace(col - 1) +
714 //colinfo_[col].lines * vlinesep();
718 dim.wid = colinfo_[ncols() - 1].offset
719 + colinfo_[ncols() - 1].width
720 //+ vlinesep() * colinfo_[ncols()].lines
723 dim.asc = -rowinfo_[0].offset
725 //+ hlinesep() * rowinfo_[0].lines
728 dim.des = rowinfo_[nrows() - 1].offset
729 + rowinfo_[nrows() - 1].descent
730 //+ hlinesep() * rowinfo_[nrows()].lines
736 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
738 // for (idx_type idx = 0; idx < nargs(); ++idx)
739 // if (cellinfo_[idx].multi != CELL_PART_OF_MULTICOLUMN)
740 // cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
744 void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
747 for (idx_type idx = 0; idx < nargs(); ++idx)
748 if (cellinfo_[idx].multi != CELL_PART_OF_MULTICOLUMN)
749 cell(idx).updateBuffer(it, utype, deleted);
753 docstring InsetMathGrid::eolString(row_type row, bool fragile,
754 bool /*latex*/, bool last_eoln) const
758 if (!rowinfo_[row].crskip.zero())
759 eol += '[' + from_utf8(rowinfo_[row].crskip.asLatexString()) + ']';
760 else if(!rowinfo_[row].allow_newpage)
763 // make sure an upcoming '[' does not break anything
764 if (row + 1 < nrows()) {
765 MathData const & c = cell(index(row + 1, 0));
766 if (!c.empty() && c.front()->getChar() == '[')
771 // only add \\ if necessary
772 if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
775 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
779 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
781 if (col + 1 == lastcol)
783 return from_ascii(" & ");
787 void InsetMathGrid::addRow(row_type row)
789 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
791 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData(buffer_));
793 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
797 void InsetMathGrid::delRow(row_type row)
802 cells_type::iterator it = cells_.begin() + row * ncols();
803 cells_.erase(it, it + ncols());
805 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
806 cellinfo_.erase(jt, jt + ncols());
808 rowinfo_.erase(rowinfo_.begin() + row);
812 void InsetMathGrid::copyRow(row_type row)
815 for (col_type col = 0; col < ncols(); ++col) {
816 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
817 // copying the cell does not set the buffer
818 cells_[(row + 1) * ncols() + col].setBuffer(*buffer_);
823 void InsetMathGrid::swapRow(row_type row)
827 if (row + 1 == nrows())
829 for (col_type col = 0; col < ncols(); ++col)
830 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
834 void InsetMathGrid::addCol(col_type newcol)
836 const col_type nc = ncols();
837 const row_type nr = nrows();
838 cells_type new_cells((nc + 1) * nr);
839 vector<CellInfo> new_cellinfo((nc + 1) * nr);
841 for (row_type row = 0; row < nr; ++row)
842 for (col_type col = 0; col < nc; ++col) {
843 new_cells[row * (nc + 1) + col + (col >= newcol)]
844 = cells_[row * nc + col];
845 new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
846 = cellinfo_[row * nc + col];
848 swap(cells_, new_cells);
849 // copying cells loses the buffer reference
851 swap(cellinfo_, new_cellinfo);
854 inf.skip = defaultColSpace(newcol);
855 inf.align = defaultColAlign(newcol);
856 colinfo_.insert(colinfo_.begin() + newcol, inf);
860 void InsetMathGrid::delCol(col_type col)
866 vector<CellInfo> tmpcellinfo;
867 for (col_type i = 0; i < nargs(); ++i)
868 if (i % ncols() != col) {
869 tmpcells.push_back(cells_[i]);
870 tmpcellinfo.push_back(cellinfo_[i]);
872 swap(cells_, tmpcells);
873 // copying cells loses the buffer reference
875 swap(cellinfo_, tmpcellinfo);
877 colinfo_.erase(colinfo_.begin() + col);
881 void InsetMathGrid::copyCol(col_type col)
884 for (row_type row = 0; row < nrows(); ++row) {
885 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
886 // copying the cell does not set the buffer
887 cells_[row * ncols() + col + 1].setBuffer(*buffer_);
892 void InsetMathGrid::swapCol(col_type col)
896 if (col + 1 == ncols())
898 for (row_type row = 0; row < nrows(); ++row)
899 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
903 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
905 if (cellinfo_[idx].multi == CELL_PART_OF_MULTICOLUMN)
907 col_type c = col(idx);
908 int x = colinfo_[c].offset;
909 char align = displayColAlign(idx);
910 Dimension const & celldim = cell(idx).dimension(bv);
911 if (align == 'r' || align == 'R')
912 x += cellWidth(idx) - celldim.wid;
913 if (align == 'c' || align == 'C')
914 x += (cellWidth(idx) - celldim.wid) / 2;
919 int InsetMathGrid::cellYOffset(BufferView const & bv, idx_type idx) const
921 return rowinfo_[row(idx)].offset[&bv];
925 int InsetMathGrid::cellWidth(idx_type idx) const
927 switch (cellinfo_[idx].multi) {
929 return colinfo_[col(idx)].width;
930 case CELL_BEGIN_OF_MULTICOLUMN: {
931 col_type c1 = col(idx);
932 col_type c2 = c1 + ncellcols(idx);
933 return colinfo_[c2].offset
934 - colinfo_[c1].offset
935 - displayColSpace(c2)
937 - colinfo_[c2].lines * vlinesep();
939 case CELL_PART_OF_MULTICOLUMN:
946 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
951 cur.idx() -= ncols();
953 if (cur.row() + 1 >= nrows())
955 cur.idx() += ncols();
957 // If we are in a multicolumn cell, move to the "real" cell
958 while (cellinfo_[cur.idx()].multi == CELL_PART_OF_MULTICOLUMN) {
959 LASSERT(cur.idx() > 0, return false);
962 // FIXME: this is only a workaround to avoid a crash if the inset
963 // in not in coord cache. The best would be to force a FitCursor
965 CoordCache::Arrays const & arraysCache = cur.bv().coordCache().arrays();
966 if (arraysCache.has(&cur.cell()))
967 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
974 bool InsetMathGrid::idxBackward(Cursor & cur) const
976 // leave matrix if at the front edge
980 // If we are in a multicolumn cell, move to the "real" cell
981 while (cellinfo_[cur.idx()].multi == CELL_PART_OF_MULTICOLUMN) {
982 LASSERT(cur.idx() > 0, return false);
985 cur.pos() = cur.lastpos();
990 bool InsetMathGrid::idxForward(Cursor & cur) const
992 // leave matrix if at the back edge
993 if (cur.col() + 1 == ncols())
996 // If we are in a multicolumn cell, move to the next cell
997 while (cellinfo_[cur.idx()].multi == CELL_PART_OF_MULTICOLUMN) {
998 // leave matrix if at the back edge
999 if (cur.col() + 1 == ncols())
1008 idx_type InsetMathGrid::firstIdx() const
1016 idx = (nrows() - 1) * ncols();
1019 idx = ((nrows() - 1) / 2) * ncols();
1021 // If we are in a multicolumn cell, move to the "real" cell
1022 while (cellinfo_[idx].multi == CELL_PART_OF_MULTICOLUMN) {
1023 LASSERT(idx > 0, return 0);
1030 idx_type InsetMathGrid::lastIdx() const
1041 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
1043 // If we are in a multicolumn cell, move to the "real" cell
1044 while (cellinfo_[idx].multi == CELL_PART_OF_MULTICOLUMN) {
1045 LASSERT(idx > 0, return false);
1052 bool InsetMathGrid::idxDelete(idx_type & idx)
1054 // nothing to do if we have just one row
1058 // nothing to do if we are in the middle of the last row of the inset
1059 if (idx + ncols() > nargs())
1062 // try to delete entire sequence of ncols() empty cells if possible
1063 for (idx_type i = idx; i < idx + ncols(); ++i)
1064 if (!cell(i).empty())
1067 // move cells if necessary
1068 for (idx_type i = index(row(idx), 0); i < idx; ++i)
1069 swap(cell(i), cell(i + ncols()));
1076 // undo effect of Ctrl-Tab (i.e. pull next cell)
1077 //if (idx + 1 != nargs())
1078 // cell(idx).swap(cell(idx + 1));
1080 // we handled the event..
1085 // reimplement old behaviour when pressing Delete in the last position
1087 void InsetMathGrid::idxGlue(idx_type idx)
1089 col_type c = col(idx);
1090 if (c + 1 == ncols()) {
1091 if (row(idx) + 1 != nrows()) {
1092 for (col_type cc = 0; cc < ncols(); ++cc)
1093 cell(idx).append(cell(idx + cc + 1));
1094 delRow(row(idx) + 1);
1097 idx_type idx_next = idx + 1;
1098 while (idx_next < nargs() &&
1099 cellinfo_[idx_next].multi == CELL_PART_OF_MULTICOLUMN)
1101 if (idx_next < nargs())
1102 cell(idx).append(cell(idx_next));
1103 col_type oldcol = c + 1;
1104 for (col_type cc = c + 2; cc < ncols(); ++cc)
1105 cell(idx - oldcol + cc) = cell(idx - oldcol + 1 + cc);
1106 cell(idx - c + ncols() - 1).clear();
1111 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
1113 return rowinfo_[row];
1117 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
1119 return rowinfo_[row];
1123 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
1125 row_type const ri = row(idx);
1126 row_type const r1 = min(row(from), row(to));
1127 row_type const r2 = max(row(from), row(to));
1128 col_type const ci = col(idx);
1129 col_type const c1 = min(col(from), col(to));
1130 col_type const c2 = max(col(from), col(to));
1131 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
1135 void InsetMathGrid::normalize(NormalStream & os) const
1138 for (row_type row = 0; row < nrows(); ++row) {
1140 for (col_type col = 0; col < ncols(); ++col) {
1141 idx_type const i = index(row, col);
1142 switch (cellinfo_[i].multi) {
1144 os << "[cell " << cell(i) << ']';
1146 case CELL_BEGIN_OF_MULTICOLUMN:
1147 os << "[cell colspan="
1148 << static_cast<int>(ncellcols(i)) << ' '
1151 case CELL_PART_OF_MULTICOLUMN:
1161 void InsetMathGrid::mathmlize(MathMLStream & ms) const
1163 bool const havetable = nrows() > 1 || ncols() > 1;
1165 ms << MTag("mtable");
1166 char const * const celltag = havetable ? "mtd" : "mrow";
1167 for (row_type row = 0; row < nrows(); ++row) {
1170 for (col_type col = 0; col < ncols(); ++col) {
1171 idx_type const i = index(row, col);
1172 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
1173 col_type const cellcols = ncellcols(i);
1175 if (havetable && cellcols > 1)
1176 attr << "colspan='" << cellcols << '\'';
1177 ms << MTag(celltag, attr.str());
1178 ms << cell(index(row, col));
1179 ms << ETag(celltag);
1186 ms << ETag("mtable");
1191 // We need to do something about alignment here.
1192 void InsetMathGrid::htmlize(HtmlStream & os, string const & attrib) const
1194 bool const havetable = nrows() > 1 || ncols() > 1;
1196 os << cell(index(0, 0));
1199 os << MTag("table", attrib);
1200 for (row_type row = 0; row < nrows(); ++row) {
1202 for (col_type col = 0; col < ncols(); ++col) {
1203 idx_type const i = index(row, col);
1204 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
1205 col_type const cellcols = ncellcols(i);
1208 attr << "colspan='" << cellcols << '\'';
1209 os << MTag("td", attr.str());
1210 os << cell(index(row, col));
1216 os << ETag("table");
1220 void InsetMathGrid::htmlize(HtmlStream & os) const
1222 htmlize(os, "class='mathtable'");
1226 void InsetMathGrid::validate(LaTeXFeatures & features) const
1228 if (features.runparams().math_flavor == OutputParams::MathAsHTML
1229 && (nrows() > 1 || ncols() > 1)) {
1230 // CSS taken from InsetMathCases
1231 features.addCSSSnippet(
1232 "table.mathtable{display: inline-block; text-align: center; border: none;"
1233 "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
1234 "table.mathtable td {text-align: left; border: none;}");
1236 InsetMathNest::validate(features);
1240 void InsetMathGrid::write(TeXMathStream & os) const
1242 write(os, 0, 0, nrows(), ncols());
1245 void InsetMathGrid::write(TeXMathStream & 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 (last_eoln && (!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 const 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_NEWLINE_INSERT: {
1417 cur.recordUndoInset();
1418 row_type const r = cur.row();
1422 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1423 swap(cell(index(r, c)), cell(index(r + 1, c)));
1428 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1431 cur.pos() = cur.lastpos();
1432 cur.forceBufferUpdate();
1433 //mathcursor->normalize();
1434 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1438 case LFUN_TABULAR_FEATURE: {
1439 cur.recordUndoInset();
1440 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1441 istringstream is(to_utf8(cmd.argument()));
1444 if (s == "valign-top")
1445 setVerticalAlignment('t');
1446 else if (s == "valign-middle")
1447 setVerticalAlignment('c');
1448 else if (s == "valign-bottom")
1449 setVerticalAlignment('b');
1450 else if (s == "align-left")
1451 setHorizontalAlignment('l', cur.col());
1452 else if (s == "align-right")
1453 setHorizontalAlignment('r', cur.col());
1454 else if (s == "align-center")
1455 setHorizontalAlignment('c', cur.col());
1456 else if (s == "append-row")
1457 for (int i = 0, n = extractInt(is); i < n; ++i)
1459 else if (s == "delete-row") {
1460 cur.clearSelection(); // bug 4323
1461 for (int i = 0, n = extractInt(is); i < n; ++i) {
1463 if (cur.idx() >= nargs())
1464 cur.idx() -= ncols();
1466 cur.pos() = 0; // trick, see below
1468 else if (s == "copy-row") {
1469 // Here (as later) we save the cursor col/row
1470 // in order to restore it after operation.
1471 row_type const r = cur.row();
1472 col_type const c = cur.col();
1473 for (int i = 0, n = extractInt(is); i < n; ++i)
1475 cur.idx() = index(r, c);
1477 else if (s == "swap-row") {
1479 // Trick to suppress same-idx-means-different-cell
1483 else if (s == "add-hline-above")
1484 rowinfo_[cur.row()].lines++;
1485 else if (s == "add-hline-below")
1486 rowinfo_[cur.row()+1].lines++;
1487 else if (s == "delete-hline-above")
1488 rowinfo_[cur.row()].lines--;
1489 else if (s == "delete-hline-below")
1490 rowinfo_[cur.row()+1].lines--;
1491 else if (s == "append-column") {
1492 row_type const r = cur.row();
1493 col_type const c = cur.col();
1494 for (int i = 0, n = extractInt(is); i < n; ++i)
1495 addCol(cur.col() + 1);
1496 cur.idx() = index(r, c);
1498 else if (s == "delete-column") {
1499 cur.clearSelection(); // bug 4323
1500 row_type const r = cur.row();
1501 col_type const c = cur.col();
1502 for (int i = 0, n = extractInt(is); i < n; ++i)
1503 delCol(col(cur.idx()));
1504 cur.idx() = index(r, min(c, cur.ncols() - 1));
1505 cur.pos() = 0; // trick, see above
1507 else if (s == "copy-column") {
1508 row_type const r = cur.row();
1509 col_type const c = cur.col();
1511 cur.idx() = index(r, c);
1513 else if (s == "swap-column") {
1515 cur.pos() = 0; // trick, see above
1517 else if (s == "add-vline-left") {
1518 colinfo_[cur.col()].lines++;
1519 if (!colinfo_[cur.col()].special.empty())
1520 colinfo_[cur.col()].special += '|';
1522 else if (s == "add-vline-right") {
1523 colinfo_[cur.col()+1].lines++;
1524 if (!colinfo_[cur.col()+1].special.empty())
1525 colinfo_[cur.col()+1].special.insert(0, 1, '|');
1527 else if (s == "delete-vline-left") {
1528 colinfo_[cur.col()].lines--;
1529 docstring & special = colinfo_[cur.col()].special;
1530 if (!special.empty()) {
1531 docstring::size_type i = special.rfind('|');
1532 LASSERT(i != docstring::npos, break);
1533 special.erase(i, 1);
1536 else if (s == "delete-vline-right") {
1537 colinfo_[cur.col()+1].lines--;
1538 docstring & special = colinfo_[cur.col()+1].special;
1539 if (!special.empty()) {
1540 docstring::size_type i = special.find('|');
1541 LASSERT(i != docstring::npos, break);
1542 special.erase(i, 1);
1549 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1550 //lyxerr << "returning FINISHED_LEFT" << endl;
1554 case LFUN_CLIPBOARD_PASTE:
1555 parseflg |= Parse::VERBATIM;
1558 if (cur.currentMode() != MATH_MODE)
1559 parseflg |= Parse::TEXTMODE;
1560 cur.message(_("Paste"));
1561 cap::replaceSelection(cur);
1563 if (cmd.argument().empty() && !theClipboard().isInternal())
1564 topaste = theClipboard().getAsText(frontend::Clipboard::PlainTextType);
1566 idocstringstream is(cmd.argument());
1569 topaste = cap::selection(n, make_pair(buffer().params().documentClassPtr(),
1570 buffer().params().authors()), true);
1572 InsetMathGrid grid(buffer_, 1, 1);
1573 if (!topaste.empty())
1574 if ((topaste.size() == 1 && isAscii(topaste))
1575 || !mathed_parse_normal(grid, topaste, parseflg)) {
1577 mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
1580 bool hline_enabled = false;
1581 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
1583 if (getStatus(cur, fr, status))
1584 hline_enabled = status.enabled();
1585 if (grid.nargs() == 1) {
1586 // single cell/part of cell
1587 cur.recordUndoInset();
1588 cur.cell().insert(cur.pos(), grid.cell(0));
1589 cur.pos() += grid.cell(0).size();
1591 rowinfo_[cur.row()].lines += grid.rowinfo_[0].lines;
1593 for (unsigned int l = 0; l < grid.rowinfo_[0].lines; ++l) {
1594 cur.cell().insert(0,
1595 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1601 cur.recordUndoInset();
1602 col_type startcol = col(cur.idx());
1603 row_type startrow = cur.row();
1604 col_type oldncols = ncols();
1606 min(grid.ncols(), ncols() - startcol);
1607 row_type const numrows =
1608 min(grid.nrows(), nrows() - cur.row());
1609 for (row_type r = 0; r < numrows; ++r) {
1610 for (col_type c = 0; c < numcols; ++c) {
1611 idx_type i = index(r + startrow, c + startcol);
1612 pos_type const ipos = min(cur.pos(), pos_type(cell(i).size()));
1613 cell(i).insert(ipos, grid.cell(grid.index(r, c)));
1616 rowinfo_[r].lines += grid.rowinfo_[r].lines;
1618 for (unsigned int l = 0; l < grid.rowinfo_[r].lines; ++l) {
1619 idx_type i = index(r + startrow, 0);
1621 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1624 // append columns for the left over horizontal cells
1625 for (col_type c = numcols; c < grid.ncols(); ++c) {
1626 addCol(c + startcol);
1627 idx_type i = index(r + startrow, min(c + startcol, ncols() - 1));
1628 cell(i).append(grid.cell(grid.index(r, c)));
1632 // amend cursor position if cols have been appended
1633 cur.idx() += startrow * (ncols() - oldncols);
1634 // append rows for the left over vertical cells
1635 idx_type i = nargs() - 1;
1636 for (row_type r = numrows; r < grid.nrows(); ++r) {
1637 row_type crow = startrow + r;
1639 for (col_type c = 0; c < grid.ncols(); ++c)
1640 cell(index(min(crow, nrows() - 1), min(c + startcol, ncols() - 1))).append(grid.cell(grid.index(r, c)));
1642 rowinfo_[crow].lines += grid.rowinfo_[r].lines;
1644 for (unsigned int l = 0; l < grid.rowinfo_[r].lines; ++l) {
1646 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1651 cur.clearSelection(); // bug 393
1652 // FIXME audit setBuffer calls
1653 cur.inset().setBuffer(*buffer_);
1654 cur.forceBufferUpdate();
1659 case LFUN_LINE_BEGIN:
1660 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1662 case LFUN_LINE_BEGIN_SELECT:
1663 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1664 act == LFUN_WORD_LEFT_SELECT ||
1665 act == LFUN_LINE_BEGIN_SELECT);
1666 cur.macroModeClose();
1667 if (cur.pos() != 0) {
1669 } else if (cur.idx() % cur.ncols() != 0) {
1670 cur.idx() -= cur.idx() % cur.ncols();
1672 } else if (cur.idx() != 0) {
1676 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1682 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1684 case LFUN_LINE_END_SELECT:
1685 cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
1686 act == LFUN_WORD_RIGHT_SELECT ||
1687 act == LFUN_LINE_END_SELECT);
1688 cur.macroModeClose();
1690 if (cur.pos() != cur.lastpos()) {
1691 cur.pos() = cur.lastpos();
1692 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1693 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1694 cur.pos() = cur.lastpos();
1695 } else if (cur.idx() != cur.lastidx()) {
1696 cur.idx() = cur.lastidx();
1697 cur.pos() = cur.lastpos();
1699 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1705 InsetMathNest::doDispatch(cur, cmd);
1710 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1711 FuncStatus & status) const
1713 switch (cmd.action()) {
1714 case LFUN_TABULAR_FEATURE: {
1715 string s = cmd.getArg(0);
1716 if (&cur.inset() != this) {
1717 // Table actions requires that the cursor is _inside_ the
1719 status.setEnabled(false);
1720 status.message(from_utf8(N_("Cursor not in table")));
1723 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1724 status.setEnabled(false);
1725 status.message(from_utf8(N_("Only one row")));
1729 (s == "delete-column" || s == "swap-column")) {
1730 status.setEnabled(false);
1731 status.message(from_utf8(N_("Only one column")));
1734 if ((rowinfo_[cur.row()].lines == 0 &&
1735 s == "delete-hline-above") ||
1736 (rowinfo_[cur.row() + 1].lines == 0 &&
1737 s == "delete-hline-below")) {
1738 status.setEnabled(false);
1739 status.message(from_utf8(N_("No hline to delete")));
1743 if ((colinfo_[cur.col()].lines == 0 &&
1744 s == "delete-vline-left") ||
1745 (colinfo_[cur.col() + 1].lines == 0 &&
1746 s == "delete-vline-right")) {
1747 status.setEnabled(false);
1748 status.message(from_utf8(N_("No vline to delete")));
1751 if (s == "valign-top" || s == "valign-middle" ||
1752 s == "valign-bottom" || s == "align-left" ||
1753 s == "align-right" || s == "align-center") {
1754 status.setEnabled(true);
1755 char const ha = horizontalAlignment(cur.col());
1756 char const va = verticalAlignment();
1757 status.setOnOff((s == "align-left" && ha == 'l')
1758 || (s == "align-right" && ha == 'r')
1759 || (s == "align-center" && ha == 'c')
1760 || (s == "valign-top" && va == 't')
1761 || (s == "valign-bottom" && va == 'b')
1762 || (s == "valign-middle" && va == 'c'));
1765 if (s == "append-row" || s == "delete-row" ||
1766 s == "copy-row" || s == "swap-row" ||
1767 s == "add-hline-above" || s == "add-hline-below" ||
1768 s == "delete-hline-above" || s == "delete-hline-below" ||
1769 s == "append-column" || s == "delete-column" ||
1770 s == "copy-column" || s == "swap-column" ||
1771 s == "add-vline-left" || s == "add-vline-right" ||
1772 s == "delete-vline-left" || s == "delete-vline-right") {
1773 status.setEnabled(true);
1775 status.setEnabled(false);
1776 status.message(bformat(
1777 from_utf8(N_("Unknown tabular feature '%1$s'")),
1784 case LFUN_CELL_SPLIT:
1785 status.setEnabled(cur.idx() != cur.lastidx());
1788 case LFUN_CELL_BACKWARD:
1789 case LFUN_CELL_FORWARD:
1790 status.setEnabled(true);
1796 return InsetMathNest::getStatus(cur, cmd, status);
1800 char InsetMathGrid::colAlign(HullType type, col_type col) const
1804 return "rcl"[col % 3];
1809 LASSERT(isBufferValid(),
1810 LYXERR0("Buffer not set correctly. Please report!");
1812 if (buffer().params().is_math_indent)
1822 return "rl"[col & 1];
1837 int InsetMathGrid::colSpace(HullType type, col_type col)
1839 int alignInterSpace = 0;
1854 alignInterSpace = 20;
1857 alignInterSpace = 0;
1860 alignInterSpace = 40;
1864 alignInterSpace = 60;
1867 return (col % 2) ? alignInterSpace : 0;