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());
82 //////////////////////////////////////////////////////////////
85 InsetMathGrid::CellInfo::CellInfo()
91 //////////////////////////////////////////////////////////////
94 InsetMathGrid::RowInfo::RowInfo()
95 : descent(0), ascent(0), lines(0), skip(0),
101 int InsetMathGrid::RowInfo::skipPixels(MetricsInfo const & mi) const
103 return mi.base.inPixels(crskip);
108 //////////////////////////////////////////////////////////////
111 InsetMathGrid::ColInfo::ColInfo()
112 : align('c'), width(0), offset(0), lines(0), skip(0)
116 //////////////////////////////////////////////////////////////
119 InsetMathGrid::InsetMathGrid(Buffer * buf)
120 : InsetMathNest(buf, 1),
130 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n)
131 : InsetMathNest(buf, m * n),
141 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n, char v,
143 : InsetMathNest(buf, m * n),
150 setVerticalAlignment(v);
151 setHorizontalAlignments(h);
155 Inset * InsetMathGrid::clone() const
157 return new InsetMathGrid(*this);
161 InsetMath::idx_type InsetMathGrid::index(row_type row, col_type col) const
163 return col + ncols() * row;
167 void InsetMathGrid::setDefaults()
170 lyxerr << "positive number of columns expected" << endl;
172 // lyxerr << "positive number of rows expected" << endl;
173 for (col_type col = 0; col < ncols(); ++col) {
174 colinfo_[col].align = defaultColAlign(col);
175 colinfo_[col].skip = defaultColSpace(col);
176 colinfo_[col].special.clear();
178 for (idx_type idx = 0; idx < nargs(); ++idx)
179 cellinfo_[idx].multi = CELL_NORMAL;
183 bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
185 if (str == "\\hline") {
186 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
188 if (getStatus(cur, fr, status)) {
189 if (status.enabled()) {
190 rowinfo_[cur.row()].lines++;
195 return InsetMathNest::interpretString(cur, str);
199 void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
202 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
205 colinfo_[col].lines++;
206 } else if ((c == 'p' || c == 'm' || c == 'b'||
207 c == '!' || c == '@' || c == '>' || c == '<') &&
208 it + 1 != hh.end() && *(it + 1) == '{') {
209 // @{decl.} and p{width} are standard LaTeX, the
210 // others are extensions by array.sty
211 bool const newcolumn = c == 'p' || c == 'm' || c == 'b';
213 // this declares a new column
215 // Only intercolumn stuff is allowed
216 // in the last dummy column
218 colinfo_[col].align = 'l';
220 // this is intercolumn stuff
221 if (colinfo_[col].special.empty())
222 // Overtake possible lines
223 colinfo_[col].special = docstring(colinfo_[col].lines, '|');
227 while (it != hh.end()) {
229 colinfo_[col].special += c;
235 if (brace_open > 0 && brace_open == brace_close)
240 colinfo_[col].lines = count(
241 colinfo_[col].special.begin(),
242 colinfo_[col].special.end(), '|');
243 LYXERR(Debug::MATHED, "special column separator: `"
244 << to_utf8(colinfo_[col].special) << '\'');
246 colinfo_[col].lines = 0;
247 colinfo_[col].special.clear();
249 } else if (col >= ncols()) {
250 // Only intercolumn stuff is allowed in the last
253 } else if (c == 'c' || c == 'l' || c == 'r') {
254 colinfo_[col].align = static_cast<char>(c);
255 if (!colinfo_[col].special.empty()) {
256 colinfo_[col].special += c;
257 colinfo_[col].lines = count(
258 colinfo_[col].special.begin(),
259 colinfo_[col].special.end(), '|');
260 LYXERR(Debug::MATHED, "special column separator: `"
261 << to_utf8(colinfo_[col].special) << '\'');
264 colinfo_[col].lines = 0;
265 colinfo_[col].special.clear();
267 lyxerr << "unknown column separator: '" << c << "'" << endl;
272 col_type n = hh.size();
275 for (col_type col = 0; col < n; ++col)
276 colinfo_[col].align = hh[col];
281 InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh)
284 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
285 if (*it == 'c' || *it == 'l' || *it == 'r'||
286 *it == 'p' || *it == 'm' || *it == 'b')
288 // let's have at least one column, even if we did not recognize its
296 void InsetMathGrid::setHorizontalAlignment(char h, col_type col)
298 colinfo_[col].align = h;
299 if (!colinfo_[col].special.empty()) {
300 char_type & c = colinfo_[col].special[colinfo_[col].special.size() - 1];
301 if (c == 'l' || c == 'c' || c == 'r')
304 // FIXME: Change alignment of p, m and b columns, too
308 char InsetMathGrid::horizontalAlignment(col_type col) const
310 return colinfo_[col].align;
314 docstring InsetMathGrid::horizontalAlignments() const
317 for (col_type col = 0; col < ncols(); ++col) {
318 if (colinfo_[col].special.empty()) {
319 res += docstring(colinfo_[col].lines, '|');
320 res += colinfo_[col].align;
322 res += colinfo_[col].special;
324 if (colinfo_[ncols()].special.empty())
325 return res + docstring(colinfo_[ncols()].lines, '|');
326 return res + colinfo_[ncols()].special;
330 void InsetMathGrid::setVerticalAlignment(char c)
336 char InsetMathGrid::verticalAlignment() const
342 InsetMathGrid::col_type InsetMathGrid::ncols() const
344 return colinfo_.size() - 1;
348 InsetMathGrid::row_type InsetMathGrid::nrows() const
350 return rowinfo_.size() - 1;
354 InsetMathGrid::col_type InsetMathGrid::col(idx_type idx) const
356 return idx % ncols();
360 InsetMathGrid::row_type InsetMathGrid::row(idx_type idx) const
362 return idx / ncols();
366 InsetMathGrid::col_type InsetMathGrid::ncellcols(idx_type idx) const
369 if (cellinfo_[idx].multi == CELL_NORMAL)
371 // If the cell at idx is already CELL_PART_OF_MULTICOLUMN we return
372 // the number of remaining columns, not the ones of the complete
373 // multicolumn cell. This makes it possible to always go to the next
374 // cell with idx + ncellcols(idx) - 1.
375 row_type const r = row(idx);
376 while (idx+cols < nargs() && row(idx+cols) == r &&
377 cellinfo_[idx+cols].multi == CELL_PART_OF_MULTICOLUMN)
383 void InsetMathGrid::vcrskip(Length const & crskip, row_type row)
385 rowinfo_[row].crskip = crskip;
389 Length InsetMathGrid::vcrskip(row_type row) const
391 return rowinfo_[row].crskip;
395 void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
397 // let the cells adjust themselves
398 for (idx_type i = 0; i < nargs(); ++i) {
399 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
401 // the 'false' is to make sure that the cell is tall enough
402 cell(i).metrics(mi, dimc, false);
406 BufferView & bv = *mi.base.bv;
408 // compute absolute sizes of vertical structure
409 for (row_type row = 0; row < nrows(); ++row) {
412 for (col_type col = 0; col < ncols(); ++col) {
413 idx_type const i = index(row, col);
414 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
415 Dimension const & dimc = cell(i).dimension(bv);
416 asc = max(asc, dimc.asc);
417 desc = max(desc, dimc.des);
420 rowinfo_[row].ascent = asc;
421 rowinfo_[row].descent = desc;
423 rowinfo_[nrows()].ascent = 0;
424 rowinfo_[nrows()].descent = 0;
426 // compute vertical offsets
427 rowinfo_[0].offset[&bv] = 0;
428 for (row_type row = 1; row <= nrows(); ++row) {
429 rowinfo_[row].offset[&bv] =
430 rowinfo_[row - 1].offset[&bv] +
431 rowinfo_[row - 1].descent +
432 rowinfo_[row - 1].skipPixels(mi) +
434 rowinfo_[row].lines * hlinesep() +
435 rowinfo_[row].ascent;
438 // adjust vertical offset
445 h = rowinfo_[nrows() - 1].offset[&bv];
448 h = rowinfo_[nrows() - 1].offset[&bv] / 2;
450 for (row_type row = 0; row <= nrows(); ++row)
451 rowinfo_[row].offset[&bv] -= h;
454 // multicolumn cell widths, as a map from first column to width in a
455 // vector of last columns.
456 // This is only used if the grid has more than one row, since for
457 // one-row grids multicolumn cells do not need special handling
458 vector<map<col_type, int> > mcolwidths(ncols());
460 // compute absolute sizes of horizontal structure
461 for (col_type col = 0; col < ncols(); ++col) {
463 for (row_type row = 0; row < nrows(); ++row) {
464 idx_type const i = index(row, col);
465 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
466 int const w = cell(i).dimension(bv).wid;
467 col_type const cols = ncellcols(i);
468 if (cols > 1 && nrows() > 1) {
469 col_type last = col+cols-1;
470 LASSERT(last < ncols(), last = ncols()-1);
471 map<col_type, int>::iterator it =
472 mcolwidths[last].find(col);
473 if (it == mcolwidths[last].end())
474 mcolwidths[last][col] = w;
476 it->second = max(it->second, w);
481 colinfo_[col].width = wid;
483 colinfo_[ncols()].width = 0;
485 // compute horizontal offsets
486 colinfo_[0].offset = border() + colinfo_[0].lines * vlinesep();;
487 for (col_type col = 1; col <= ncols(); ++col) {
488 colinfo_[col].offset =
489 colinfo_[col - 1].offset +
490 colinfo_[col - 1].width +
491 displayColSpace(col - 1) +
493 colinfo_[col].lines * vlinesep();
496 // increase column widths for multicolumn cells if needed
497 // FIXME: multicolumn lines are not yet considered
498 for (col_type last = 0; last < ncols(); ++last) {
499 map<col_type, int> const & widths = mcolwidths[last];
500 // We increase the width of the last column of the multicol
501 // cell (some sort of left alignment). Since we iterate through
502 // the last and the first columns from left to right, we ensure
503 // that increased widths of previous columns are correctly
504 // taken into account for later columns, thus preventing
505 // unneeded width increasing.
506 for (map<col_type, int>::const_iterator it = widths.begin();
507 it != widths.end(); ++it) {
508 int const wid = it->second;
509 col_type const first = it->first;
510 int const nextoffset =
511 colinfo_[first].offset +
513 displayColSpace(last) +
515 colinfo_[last+1].lines * vlinesep();
516 int const dx = nextoffset - colinfo_[last+1].offset;
518 colinfo_[last].width += dx;
519 for (col_type col = last + 1; col <= ncols(); ++col)
520 colinfo_[col].offset += dx;
526 dim.wid = colinfo_[ncols() - 1].offset
527 + colinfo_[ncols() - 1].width
528 + vlinesep() * colinfo_[ncols()].lines
531 dim.asc = - rowinfo_[0].offset[&bv]
533 + hlinesep() * rowinfo_[0].lines
536 dim.des = rowinfo_[nrows() - 1].offset[&bv]
537 + rowinfo_[nrows() - 1].descent
538 + hlinesep() * rowinfo_[nrows()].lines
543 // Increase ws_[i] for 'R' columns (except the first one)
544 for (int i = 1; i < nc_; ++i)
546 ws_[i] += 10 * df_width;
547 // Increase ws_[i] for 'C' column
549 if (ws_[0] < 7 * workwidth / 8)
550 ws_[0] = 7 * workwidth / 8;
554 for (cxrow = row_.begin(); cxrow; ++cxrow) {
557 for (int i = 0; i < nc_; ++i) {
559 if (cxrow->getTab(i) <= 0) {
560 cxrow->setTab(i, df_width);
568 lf = (ws_[i] - cxrow->getTab(i))/2;
572 lf = ws_[i] - cxrow->getTab(i);
575 if (cxrow == row_.begin())
577 else if (cxrow.is_last())
578 lf = ws_[i] - cxrow->getTab(i);
580 lf = (ws_[i] - cxrow->getTab(i))/2;
583 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
584 cxrow->setTab(i, lf + rg);
585 rg = ws_[i] - ww + colsep();
586 if (cxrow == row_.begin())
587 width += ws_[i] + colsep();
589 cxrow->setBaseline(cxrow->getBaseline() - ascent);
592 dim.wid += leftMargin() + rightMargin();
596 int InsetMathGrid::vLineHOffset(col_type col, unsigned int line) const
599 return leftMargin() + colinfo_[col].offset
600 - (colinfo_[col].lines - line - 1) * vlinesep()
601 - vlinesep()/2 - colsep()/2;
603 LASSERT(col == ncols(), return 0);
604 return leftMargin() + colinfo_[col-1].offset + colinfo_[col-1].width
606 + vlinesep()/2 + colsep()/2;
611 int InsetMathGrid::hLineVOffset(BufferView const & bv, row_type row,
612 unsigned int line) const
614 return rowinfo_[row].offset[&bv]
615 - rowinfo_[row].ascent
617 - hlinesep()/2 - rowsep()/2;
621 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
623 BufferView const & bv = *pi.base.bv;
625 for (idx_type idx = 0; idx < nargs(); ++idx) {
626 if (cellinfo_[idx].multi != CELL_PART_OF_MULTICOLUMN) {
628 x + leftMargin() + cellXOffset(bv, idx),
629 y + cellYOffset(bv, idx));
631 row_type r = row(idx);
632 int const yy1 = y + hLineVOffset(bv, r, 0);
633 int const yy2 = y + hLineVOffset(bv, r + 1, rowinfo_[r + 1].lines - 1);
634 auto draw_left_borders = [&](col_type c) {
635 for (unsigned int i = 0; i < colinfo_[c].lines; ++i) {
636 int const xx = x + vLineHOffset(c, i);
637 pi.pain.line(xx, yy1, xx, yy2, Color_foreground);
640 col_type c = col(idx);
641 // Draw inner left borders cell-by-cell because of multicolumns
642 draw_left_borders(c);
643 // Draw the right border (only once)
645 draw_left_borders(ncols());
649 // Draw horizontal borders
650 for (row_type r = 0; r <= nrows(); ++r) {
651 int const xx1 = x + vLineHOffset(0, 0);
652 int const xx2 = x + vLineHOffset(ncols(), colinfo_[ncols()].lines - 1);
653 for (unsigned int i = 0; i < rowinfo_[r].lines; ++i) {
654 int const yy = y + hLineVOffset(bv, r, i);
655 pi.pain.line(xx1, yy, xx2, yy, Color_foreground);
661 void InsetMathGrid::metricsT(TextMetricsInfo const & /*mi*/, Dimension & /*dim*/) const
663 // FIXME: this does not compile anymore with offset being a map
664 // It is not worth fixing it at this point since the code is basically dead.
666 // let the cells adjust themselves
667 for (idx_type i = 0; i < nargs(); ++i)
668 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN)
669 cell(i).metricsT(mi, dim);
671 // compute absolute sizes of vertical structure
672 for (row_type row = 0; row < nrows(); ++row) {
675 for (col_type col = 0; col < ncols(); ++col) {
676 idx_type const i = index(row, col);
677 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
678 //MathData const & c = cell(i);
681 asc = max(asc, dimc.ascent());
682 desc = max(desc, dimc.descent());
685 rowinfo_[row].ascent = asc;
686 rowinfo_[row].descent = desc;
688 rowinfo_[nrows()].ascent = 0;
689 rowinfo_[nrows()].descent = 0;
691 // compute vertical offsets
692 rowinfo_[0].offset[&bv] = 0;
693 for (row_type row = 1; row <= nrows(); ++row) {
694 rowinfo_[row].offset[&bv] =
695 rowinfo_[row - 1].offset +
696 rowinfo_[row - 1].descent +
697 //rowinfo_[row - 1].skipPixels(mi) +
699 //rowinfo_[row].lines * hlinesep() +
700 rowinfo_[row].ascent;
703 // adjust vertical offset
710 h = rowinfo_[nrows() - 1].offset;
713 h = rowinfo_[nrows() - 1].offset / 2;
715 for (row_type row = 0; row <= nrows(); ++row)
716 rowinfo_[row].offset -= h;
719 // compute absolute sizes of horizontal structure
720 for (col_type col = 0; col < ncols(); ++col) {
722 for (row_type row = 0; row < nrows(); ++row) {
724 //idx_type const i = index(row, col);
725 //if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN)
726 // wid = max(wid, cell(i).width());
728 colinfo_[col].width = wid;
730 colinfo_[ncols()].width = 0;
732 // compute horizontal offsets
733 colinfo_[0].offset = border();
734 for (col_type col = 1; col <= ncols(); ++col) {
735 colinfo_[col].offset =
736 colinfo_[col - 1].offset +
737 colinfo_[col - 1].width +
738 displayColSpace(col - 1) +
740 //colinfo_[col].lines * vlinesep();
744 dim.wid = colinfo_[ncols() - 1].offset
745 + colinfo_[ncols() - 1].width
746 //+ vlinesep() * colinfo_[ncols()].lines
749 dim.asc = -rowinfo_[0].offset
751 //+ hlinesep() * rowinfo_[0].lines
754 dim.des = rowinfo_[nrows() - 1].offset
755 + rowinfo_[nrows() - 1].descent
756 //+ hlinesep() * rowinfo_[nrows()].lines
762 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
764 // for (idx_type idx = 0; idx < nargs(); ++idx)
765 // if (cellinfo_[idx].multi != CELL_PART_OF_MULTICOLUMN)
766 // cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
770 void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype, bool const deleted)
773 for (idx_type idx = 0; idx < nargs(); ++idx)
774 if (cellinfo_[idx].multi != CELL_PART_OF_MULTICOLUMN)
775 cell(idx).updateBuffer(it, utype, deleted);
779 docstring InsetMathGrid::eolString(row_type row, bool fragile,
780 bool /*latex*/, bool last_eoln) const
784 if (!rowinfo_[row].crskip.zero())
785 eol += '[' + from_utf8(rowinfo_[row].crskip.asLatexString()) + ']';
786 else if(!rowinfo_[row].allow_newpage)
789 // make sure an upcoming '[' does not break anything
790 if (row + 1 < nrows()) {
791 MathData const & c = cell(index(row + 1, 0));
792 if (!c.empty() && c.front()->getChar() == '[')
797 // only add \\ if necessary
798 if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
801 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
805 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
807 if (col + 1 == lastcol)
809 return from_ascii(" & ");
813 void InsetMathGrid::addRow(row_type row)
815 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
817 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData(buffer_));
819 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
823 void InsetMathGrid::delRow(row_type row)
828 cells_type::iterator it = cells_.begin() + row * ncols();
829 cells_.erase(it, it + ncols());
831 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
832 cellinfo_.erase(jt, jt + ncols());
834 rowinfo_.erase(rowinfo_.begin() + row);
838 void InsetMathGrid::copyRow(row_type row)
841 for (col_type col = 0; col < ncols(); ++col) {
842 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
843 // copying the cell does not set the buffer
844 cells_[(row + 1) * ncols() + col].setBuffer(*buffer_);
849 void InsetMathGrid::swapRow(row_type row)
853 if (row + 1 == nrows())
855 for (col_type col = 0; col < ncols(); ++col)
856 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
860 void InsetMathGrid::addCol(col_type newcol)
862 const col_type nc = ncols();
863 const row_type nr = nrows();
864 cells_type new_cells((nc + 1) * nr);
865 vector<CellInfo> new_cellinfo((nc + 1) * nr);
867 for (row_type row = 0; row < nr; ++row)
868 for (col_type col = 0; col < nc; ++col) {
869 new_cells[row * (nc + 1) + col + (col >= newcol)]
870 = cells_[row * nc + col];
871 new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
872 = cellinfo_[row * nc + col];
874 swap(cells_, new_cells);
875 // copying cells loses the buffer reference
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 // copying cells loses the buffer reference
901 swap(cellinfo_, tmpcellinfo);
903 colinfo_.erase(colinfo_.begin() + col);
907 void InsetMathGrid::copyCol(col_type col)
910 for (row_type row = 0; row < nrows(); ++row) {
911 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
912 // copying the cell does not set the buffer
913 cells_[row * ncols() + col + 1].setBuffer(*buffer_);
918 void InsetMathGrid::swapCol(col_type col)
922 if (col + 1 == ncols())
924 for (row_type row = 0; row < nrows(); ++row)
925 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
929 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
931 if (cellinfo_[idx].multi == CELL_PART_OF_MULTICOLUMN)
933 col_type c = col(idx);
934 int x = colinfo_[c].offset;
935 char align = displayColAlign(idx);
936 Dimension const & celldim = cell(idx).dimension(bv);
937 if (align == 'r' || align == 'R')
938 x += cellWidth(idx) - celldim.wid;
939 if (align == 'c' || align == 'C')
940 x += (cellWidth(idx) - celldim.wid) / 2;
945 int InsetMathGrid::cellYOffset(BufferView const & bv, idx_type idx) const
947 return rowinfo_[row(idx)].offset[&bv];
951 int InsetMathGrid::cellWidth(idx_type idx) const
953 switch (cellinfo_[idx].multi) {
955 return colinfo_[col(idx)].width;
956 case CELL_BEGIN_OF_MULTICOLUMN: {
957 col_type c1 = col(idx);
958 col_type c2 = c1 + ncellcols(idx);
959 return colinfo_[c2].offset
960 - colinfo_[c1].offset
961 - displayColSpace(c2)
963 - colinfo_[c2].lines * vlinesep();
965 case CELL_PART_OF_MULTICOLUMN:
972 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
977 cur.idx() -= ncols();
979 if (cur.row() + 1 >= nrows())
981 cur.idx() += ncols();
983 // If we are in a multicolumn cell, move to the "real" cell
984 while (cellinfo_[cur.idx()].multi == CELL_PART_OF_MULTICOLUMN) {
985 LASSERT(cur.idx() > 0, return false);
988 // FIXME: this is only a workaround to avoid a crash if the inset
989 // in not in coord cache. The best would be to force a FitCursor
991 CoordCache::Arrays const & arraysCache = cur.bv().coordCache().arrays();
992 if (arraysCache.has(&cur.cell()))
993 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
1000 bool InsetMathGrid::idxBackward(Cursor & cur) const
1002 // leave matrix if at the front edge
1006 // If we are in a multicolumn cell, move to the "real" cell
1007 while (cellinfo_[cur.idx()].multi == CELL_PART_OF_MULTICOLUMN) {
1008 LASSERT(cur.idx() > 0, return false);
1011 cur.pos() = cur.lastpos();
1016 bool InsetMathGrid::idxForward(Cursor & cur) const
1018 // leave matrix if at the back edge
1019 if (cur.col() + 1 == ncols())
1022 // If we are in a multicolumn cell, move to the next cell
1023 while (cellinfo_[cur.idx()].multi == CELL_PART_OF_MULTICOLUMN) {
1024 // leave matrix if at the back edge
1025 if (cur.col() + 1 == ncols())
1034 idx_type InsetMathGrid::firstIdx() const
1042 idx = (nrows() - 1) * ncols();
1045 idx = ((nrows() - 1) / 2) * ncols();
1047 // If we are in a multicolumn cell, move to the "real" cell
1048 while (cellinfo_[idx].multi == CELL_PART_OF_MULTICOLUMN) {
1049 LASSERT(idx > 0, return 0);
1056 idx_type InsetMathGrid::lastIdx() const
1067 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
1069 // If we are in a multicolumn cell, move to the "real" cell
1070 while (cellinfo_[idx].multi == CELL_PART_OF_MULTICOLUMN) {
1071 LASSERT(idx > 0, return false);
1078 bool InsetMathGrid::idxDelete(idx_type & idx)
1080 // nothing to do if we have just one row
1084 // nothing to do if we are in the middle of the last row of the inset
1085 if (idx + ncols() > nargs())
1088 // try to delete entire sequence of ncols() empty cells if possible
1089 for (idx_type i = idx; i < idx + ncols(); ++i)
1090 if (!cell(i).empty())
1093 // move cells if necessary
1094 for (idx_type i = index(row(idx), 0); i < idx; ++i)
1095 swap(cell(i), cell(i + ncols()));
1102 // undo effect of Ctrl-Tab (i.e. pull next cell)
1103 //if (idx + 1 != nargs())
1104 // cell(idx).swap(cell(idx + 1));
1106 // we handled the event..
1111 // reimplement old behaviour when pressing Delete in the last position
1113 void InsetMathGrid::idxGlue(idx_type idx)
1115 col_type c = col(idx);
1116 if (c + 1 == ncols()) {
1117 if (row(idx) + 1 != nrows()) {
1118 for (col_type cc = 0; cc < ncols(); ++cc)
1119 cell(idx).append(cell(idx + cc + 1));
1120 delRow(row(idx) + 1);
1123 idx_type idx_next = idx + 1;
1124 while (idx_next < nargs() &&
1125 cellinfo_[idx_next].multi == CELL_PART_OF_MULTICOLUMN)
1127 if (idx_next < nargs())
1128 cell(idx).append(cell(idx_next));
1129 col_type oldcol = c + 1;
1130 for (col_type cc = c + 2; cc < ncols(); ++cc)
1131 cell(idx - oldcol + cc) = cell(idx - oldcol + 1 + cc);
1132 cell(idx - c + ncols() - 1).clear();
1137 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
1139 return rowinfo_[row];
1143 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
1145 return rowinfo_[row];
1149 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
1151 row_type const ri = row(idx);
1152 row_type const r1 = min(row(from), row(to));
1153 row_type const r2 = max(row(from), row(to));
1154 col_type const ci = col(idx);
1155 col_type const c1 = min(col(from), col(to));
1156 col_type const c2 = max(col(from), col(to));
1157 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
1161 void InsetMathGrid::normalize(NormalStream & os) const
1164 for (row_type row = 0; row < nrows(); ++row) {
1166 for (col_type col = 0; col < ncols(); ++col) {
1167 idx_type const i = index(row, col);
1168 switch (cellinfo_[i].multi) {
1170 os << "[cell " << cell(i) << ']';
1172 case CELL_BEGIN_OF_MULTICOLUMN:
1173 os << "[cell colspan="
1174 << static_cast<int>(ncellcols(i)) << ' '
1177 case CELL_PART_OF_MULTICOLUMN:
1187 void InsetMathGrid::mathmlize(MathStream & os) const
1189 bool const havetable = nrows() > 1 || ncols() > 1;
1191 os << MTag("mtable");
1192 char const * const celltag = havetable ? "mtd" : "mrow";
1193 for (row_type row = 0; row < nrows(); ++row) {
1196 for (col_type col = 0; col < ncols(); ++col) {
1197 idx_type const i = index(row, col);
1198 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
1199 col_type const cellcols = ncellcols(i);
1201 if (havetable && cellcols > 1)
1202 attr << "colspan='" << cellcols << '\'';
1203 os << MTag(celltag, attr.str());
1204 os << cell(index(row, col));
1205 os << ETag(celltag);
1212 os << ETag("mtable");
1217 // We need to do something about alignment here.
1218 void InsetMathGrid::htmlize(HtmlStream & os, string attrib) const
1220 bool const havetable = nrows() > 1 || ncols() > 1;
1222 os << cell(index(0, 0));
1225 os << MTag("table", attrib);
1226 for (row_type row = 0; row < nrows(); ++row) {
1228 for (col_type col = 0; col < ncols(); ++col) {
1229 idx_type const i = index(row, col);
1230 if (cellinfo_[i].multi != CELL_PART_OF_MULTICOLUMN) {
1231 col_type const cellcols = ncellcols(i);
1234 attr << "colspan='" << cellcols << '\'';
1235 os << MTag("td", attr.str());
1236 os << cell(index(row, col));
1242 os << ETag("table");
1246 void InsetMathGrid::htmlize(HtmlStream & os) const
1248 htmlize(os, "class='mathtable'");
1252 void InsetMathGrid::validate(LaTeXFeatures & features) const
1254 if (features.runparams().math_flavor == OutputParams::MathAsHTML
1255 && (nrows() > 1 || ncols() > 1)) {
1256 // CSS taken from InsetMathCases
1257 features.addCSSSnippet(
1258 "table.mathtable{display: inline-block; text-align: center; border: none;"
1259 "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
1260 "table.mathtable td {text-align: left; border: none;}");
1262 InsetMathNest::validate(features);
1266 void InsetMathGrid::write(WriteStream & os) const
1268 write(os, 0, 0, nrows(), ncols());
1271 void InsetMathGrid::write(WriteStream & os,
1272 row_type beg_row, col_type beg_col,
1273 row_type end_row, col_type end_col) const
1275 MathEnsurer ensurer(os, false);
1277 for (row_type row = beg_row; row < end_row; ++row) {
1278 os << verboseHLine(rowinfo_[row].lines);
1279 // don't write & and empty cells at end of line,
1280 // unless there are vertical lines
1281 col_type lastcol = 0;
1282 bool emptyline = true;
1283 bool last_eoln = true;
1284 for (col_type col = beg_col; col < end_col; ++col) {
1285 idx_type const idx = index(row, col);
1286 bool const empty_cell = cell(idx).empty();
1287 if (!empty_cell || cellinfo_[idx].multi != CELL_NORMAL)
1289 if (!empty_cell || cellinfo_[idx].multi != CELL_NORMAL ||
1290 colinfo_[col + 1].lines) {
1295 for (col_type col = beg_col; col < end_col;) {
1297 idx_type const idx = index(row, col);
1298 TexRow::RowEntry entry = TexRow::mathEntry(id(),idx);
1299 os.texrow().start(entry);
1300 if (col >= lastcol) {
1304 Changer dummy = os.changeRowEntry(entry);
1305 if (cellinfo_[idx].multi == CELL_BEGIN_OF_MULTICOLUMN) {
1307 while (s < ncols() &&
1308 cellinfo_[index(row, s)].multi == CELL_PART_OF_MULTICOLUMN)
1311 os << "\\multicolumn{" << nccols
1312 << "}{" << cellinfo_[idx].align
1316 if (os.pendingBrace())
1317 ModeSpecifier specifier(os, TEXT_MODE);
1318 if (cellinfo_[idx].multi == CELL_BEGIN_OF_MULTICOLUMN)
1320 os << eocString(col + nccols - 1, lastcol);
1323 eol = eolString(row, os.fragile(), os.latex(), last_eoln);
1325 // append newline only if line wasn't completely empty
1326 // and the formula is not written on a single line
1327 bool const empty = emptyline && eol.empty();
1328 if (!empty && nrows() > 1)
1331 // @TODO use end_row instead of nrows() ?
1332 docstring const s = verboseHLine(rowinfo_[nrows()].lines);
1344 int InsetMathGrid::colsep() const
1350 int InsetMathGrid::rowsep() const
1356 int InsetMathGrid::hlinesep() const
1362 int InsetMathGrid::vlinesep() const
1368 int InsetMathGrid::border() const
1374 void InsetMathGrid::splitCell(Cursor & cur)
1376 if (cur.idx() == cur.lastidx())
1378 MathData ar = cur.cell();
1379 ar.erase(0, cur.pos());
1380 cur.cell().erase(cur.pos(), cur.lastpos());
1382 while (cur.idx() << nargs() &&
1383 cellinfo_[cur.idx()].multi == CELL_BEGIN_OF_MULTICOLUMN)
1386 cur.cell().insert(0, ar);
1390 char InsetMathGrid::displayColAlign(idx_type idx) const
1392 if (cellinfo_[idx].multi == CELL_BEGIN_OF_MULTICOLUMN) {
1393 // align may also contain lines like "||r|", so this is
1394 // not complete, but we catch at least the simple cases.
1395 if (cellinfo_[idx].align == "c")
1397 if (cellinfo_[idx].align == "l")
1399 if (cellinfo_[idx].align == "r")
1402 return colinfo_[col(idx)].align;
1406 int InsetMathGrid::displayColSpace(col_type col) const
1408 return colinfo_[col].skip;
1411 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1413 //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1415 Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
1417 FuncCode const act = cmd.action();
1420 // insert file functions
1421 case LFUN_LINE_DELETE_FORWARD:
1422 cur.recordUndoInset();
1423 //autocorrect_ = false;
1431 if (cur.idx() > cur.lastidx())
1432 cur.idx() = cur.lastidx();
1433 if (cur.pos() > cur.lastpos())
1434 cur.pos() = cur.lastpos();
1437 case LFUN_CELL_SPLIT:
1442 case LFUN_NEWLINE_INSERT: {
1443 cur.recordUndoInset();
1444 row_type const r = cur.row();
1448 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1449 swap(cell(index(r, c)), cell(index(r + 1, c)));
1454 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1457 cur.pos() = cur.lastpos();
1458 cur.forceBufferUpdate();
1459 //mathcursor->normalize();
1460 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1464 case LFUN_TABULAR_FEATURE: {
1465 cur.recordUndoInset();
1466 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1467 istringstream is(to_utf8(cmd.argument()));
1470 if (s == "valign-top")
1471 setVerticalAlignment('t');
1472 else if (s == "valign-middle")
1473 setVerticalAlignment('c');
1474 else if (s == "valign-bottom")
1475 setVerticalAlignment('b');
1476 else if (s == "align-left")
1477 setHorizontalAlignment('l', cur.col());
1478 else if (s == "align-right")
1479 setHorizontalAlignment('r', cur.col());
1480 else if (s == "align-center")
1481 setHorizontalAlignment('c', cur.col());
1482 else if (s == "append-row")
1483 for (int i = 0, n = extractInt(is); i < n; ++i)
1485 else if (s == "delete-row") {
1486 cur.clearSelection(); // bug 4323
1487 for (int i = 0, n = extractInt(is); i < n; ++i) {
1489 if (cur.idx() >= nargs())
1490 cur.idx() -= ncols();
1492 cur.pos() = 0; // trick, see below
1494 else if (s == "copy-row") {
1495 // Here (as later) we save the cursor col/row
1496 // in order to restore it after operation.
1497 row_type const r = cur.row();
1498 col_type const c = cur.col();
1499 for (int i = 0, n = extractInt(is); i < n; ++i)
1501 cur.idx() = index(r, c);
1503 else if (s == "swap-row") {
1505 // Trick to suppress same-idx-means-different-cell
1509 else if (s == "add-hline-above")
1510 rowinfo_[cur.row()].lines++;
1511 else if (s == "add-hline-below")
1512 rowinfo_[cur.row()+1].lines++;
1513 else if (s == "delete-hline-above")
1514 rowinfo_[cur.row()].lines--;
1515 else if (s == "delete-hline-below")
1516 rowinfo_[cur.row()+1].lines--;
1517 else if (s == "append-column") {
1518 row_type const r = cur.row();
1519 col_type const c = cur.col();
1520 for (int i = 0, n = extractInt(is); i < n; ++i)
1521 addCol(cur.col() + 1);
1522 cur.idx() = index(r, c);
1524 else if (s == "delete-column") {
1525 cur.clearSelection(); // bug 4323
1526 row_type const r = cur.row();
1527 col_type const c = cur.col();
1528 for (int i = 0, n = extractInt(is); i < n; ++i)
1529 delCol(col(cur.idx()));
1530 cur.idx() = index(r, min(c, cur.ncols() - 1));
1531 cur.pos() = 0; // trick, see above
1533 else if (s == "copy-column") {
1534 row_type const r = cur.row();
1535 col_type const c = cur.col();
1537 cur.idx() = index(r, c);
1539 else if (s == "swap-column") {
1541 cur.pos() = 0; // trick, see above
1543 else if (s == "add-vline-left") {
1544 colinfo_[cur.col()].lines++;
1545 if (!colinfo_[cur.col()].special.empty())
1546 colinfo_[cur.col()].special += '|';
1548 else if (s == "add-vline-right") {
1549 colinfo_[cur.col()+1].lines++;
1550 if (!colinfo_[cur.col()+1].special.empty())
1551 colinfo_[cur.col()+1].special.insert(0, 1, '|');
1553 else if (s == "delete-vline-left") {
1554 colinfo_[cur.col()].lines--;
1555 docstring & special = colinfo_[cur.col()].special;
1556 if (!special.empty()) {
1557 docstring::size_type i = special.rfind('|');
1558 LASSERT(i != docstring::npos, break);
1559 special.erase(i, 1);
1562 else if (s == "delete-vline-right") {
1563 colinfo_[cur.col()+1].lines--;
1564 docstring & special = colinfo_[cur.col()+1].special;
1565 if (!special.empty()) {
1566 docstring::size_type i = special.find('|');
1567 LASSERT(i != docstring::npos, break);
1568 special.erase(i, 1);
1575 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1576 //lyxerr << "returning FINISHED_LEFT" << endl;
1580 case LFUN_CLIPBOARD_PASTE:
1581 parseflg |= Parse::VERBATIM;
1584 if (cur.currentMode() != MATH_MODE)
1585 parseflg |= Parse::TEXTMODE;
1586 cur.message(_("Paste"));
1587 cap::replaceSelection(cur);
1589 if (cmd.argument().empty() && !theClipboard().isInternal())
1590 topaste = theClipboard().getAsText(frontend::Clipboard::PlainTextType);
1592 idocstringstream is(cmd.argument());
1595 topaste = cap::selection(n, buffer().params().documentClassPtr());
1597 InsetMathGrid grid(buffer_, 1, 1);
1598 if (!topaste.empty())
1599 if ((topaste.size() == 1 && isAscii(topaste))
1600 || !mathed_parse_normal(grid, topaste, parseflg)) {
1602 mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
1605 bool hline_enabled = false;
1606 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
1608 if (getStatus(cur, fr, status))
1609 hline_enabled = status.enabled();
1610 if (grid.nargs() == 1) {
1611 // single cell/part of cell
1612 cur.recordUndoInset();
1613 cur.cell().insert(cur.pos(), grid.cell(0));
1614 cur.pos() += grid.cell(0).size();
1616 rowinfo_[cur.row()].lines += grid.rowinfo_[0].lines;
1618 for (unsigned int l = 0; l < grid.rowinfo_[0].lines; ++l) {
1619 cur.cell().insert(0,
1620 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1626 cur.recordUndoInset();
1627 col_type const numcols =
1628 min(grid.ncols(), ncols() - col(cur.idx()));
1629 row_type const numrows =
1630 min(grid.nrows(), nrows() - cur.row());
1631 for (row_type r = 0; r < numrows; ++r) {
1632 for (col_type c = 0; c < numcols; ++c) {
1633 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1634 cell(i).insert(c == 0 ? cur.pos() : 0,
1635 grid.cell(grid.index(r, c)));
1638 rowinfo_[r].lines += grid.rowinfo_[r].lines;
1640 for (unsigned int l = 0; l < grid.rowinfo_[r].lines; ++l) {
1641 idx_type i = index(r + cur.row(), 0);
1643 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1646 // append the left over horizontal cells to the last column
1647 idx_type i = index(r + cur.row(), ncols() - 1);
1648 for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
1649 cell(i).append(grid.cell(grid.index(r, c)));
1651 // append the left over vertical cells to the last _cell_
1652 idx_type i = nargs() - 1;
1653 for (row_type r = numrows; r < grid.nrows(); ++r) {
1654 for (col_type c = 0; c < grid.ncols(); ++c)
1655 cell(i).append(grid.cell(grid.index(r, c)));
1657 rowinfo_[r].lines += grid.rowinfo_[r].lines;
1659 for (unsigned int l = 0; l < grid.rowinfo_[r].lines; ++l) {
1661 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1666 cur.clearSelection(); // bug 393
1667 // FIXME audit setBuffer calls
1668 cur.inset().setBuffer(*buffer_);
1669 cur.forceBufferUpdate();
1674 case LFUN_LINE_BEGIN:
1675 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1677 case LFUN_LINE_BEGIN_SELECT:
1678 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1679 act == LFUN_WORD_LEFT_SELECT ||
1680 act == LFUN_LINE_BEGIN_SELECT);
1681 cur.macroModeClose();
1682 if (cur.pos() != 0) {
1684 } else if (cur.idx() % cur.ncols() != 0) {
1685 cur.idx() -= cur.idx() % cur.ncols();
1687 } else if (cur.idx() != 0) {
1691 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1697 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
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'")),
1799 case LFUN_CELL_SPLIT:
1800 status.setEnabled(cur.idx() != cur.lastidx());
1803 case LFUN_CELL_BACKWARD:
1804 case LFUN_CELL_FORWARD:
1805 status.setEnabled(true);
1811 return InsetMathNest::getStatus(cur, cmd, status);
1815 char InsetMathGrid::colAlign(HullType type, col_type col) const
1819 return "rcl"[col % 3];
1825 // Partly revert 44816adce63
1826 // because the following test leads to crash
1827 // Open a new lyx-file
1828 // select findadv dialog
1829 // in the search-field enter math
1830 // use math-mutate gather ===> crash (because isValidBuffer() == false)
1831 LASSERT(isBufferValid(),
1832 LYXERR0("Buffer not set correctly. Please report!");
1835 if (buffer().params().is_math_indent)
1845 return "rl"[col & 1];
1860 int InsetMathGrid::colSpace(HullType type, col_type col)
1862 int alignInterSpace = 0;
1877 alignInterSpace = 20;
1880 alignInterSpace = 0;
1883 alignInterSpace = 40;
1887 alignInterSpace = 60;
1890 return (col % 2) ? alignInterSpace : 0;