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), offset_(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_ = 0;
428 for (row_type row = 1; row <= nrows(); ++row) {
429 rowinfo_[row].offset_ =
430 rowinfo_[row - 1].offset_ +
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_;
448 h = rowinfo_[nrows() - 1].offset_ / 2;
450 for (row_type row = 0; row <= nrows(); ++row)
451 rowinfo_[row].offset_ -= 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_
532 + rowinfo_[0].ascent_
533 + hlinesep() * rowinfo_[0].lines_
536 dim.des = rowinfo_[nrows() - 1].offset_
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)
545 if (align_[i] == 'R')
546 ws_[i] += 10 * df_width;
547 // Increase ws_[i] for 'C' column
548 if (align_[0] == 'C')
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(row_type row, unsigned int line) const
613 return rowinfo_[row].offset_
614 - rowinfo_[row].ascent_
616 - hlinesep()/2 - rowsep()/2;
620 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
622 BufferView const & bv = *pi.base.bv;
624 for (idx_type idx = 0; idx < nargs(); ++idx) {
625 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN) {
627 x + leftMargin() + cellXOffset(bv, idx),
628 y + cellYOffset(idx));
630 row_type r = row(idx);
631 int const yy1 = y + hLineVOffset(r, 0);
632 int const yy2 = y + hLineVOffset(r + 1, rowinfo_[r + 1].lines_ - 1);
633 auto draw_left_borders = [&](col_type c) {
634 for (unsigned int i = 0; i < colinfo_[c].lines_; ++i) {
635 int const xx = x + vLineHOffset(c, i);
636 pi.pain.line(xx, yy1, xx, yy2, Color_foreground);
639 col_type c = col(idx);
640 // Draw inner left borders cell-by-cell because of multicolumns
641 draw_left_borders(c);
642 // Draw the right border (only once)
644 draw_left_borders(ncols());
648 // Draw horizontal borders
649 for (row_type r = 0; r <= nrows(); ++r) {
650 int const xx1 = x + vLineHOffset(0, 0);
651 int const xx2 = x + vLineHOffset(ncols(), colinfo_[ncols()].lines_ - 1);
652 for (unsigned int i = 0; i < rowinfo_[r].lines_; ++i) {
653 int const yy = y + hLineVOffset(r, i);
654 pi.pain.line(xx1, yy, xx2, yy, Color_foreground);
660 void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
662 // let the cells adjust themselves
663 for (idx_type i = 0; i < nargs(); ++i)
664 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
665 cell(i).metricsT(mi, dim);
667 // compute absolute sizes of vertical structure
668 for (row_type row = 0; row < nrows(); ++row) {
671 for (col_type col = 0; col < ncols(); ++col) {
672 idx_type const i = index(row, col);
673 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
674 //MathData const & c = cell(i);
677 asc = max(asc, dimc.ascent());
678 desc = max(desc, dimc.descent());
681 rowinfo_[row].ascent_ = asc;
682 rowinfo_[row].descent_ = desc;
684 rowinfo_[nrows()].ascent_ = 0;
685 rowinfo_[nrows()].descent_ = 0;
687 // compute vertical offsets
688 rowinfo_[0].offset_ = 0;
689 for (row_type row = 1; row <= nrows(); ++row) {
690 rowinfo_[row].offset_ =
691 rowinfo_[row - 1].offset_ +
692 rowinfo_[row - 1].descent_ +
693 //rowinfo_[row - 1].skipPixels(mi) +
695 //rowinfo_[row].lines_ * hlinesep() +
696 rowinfo_[row].ascent_;
699 // adjust vertical offset
706 h = rowinfo_[nrows() - 1].offset_;
709 h = rowinfo_[nrows() - 1].offset_ / 2;
711 for (row_type row = 0; row <= nrows(); ++row)
712 rowinfo_[row].offset_ -= h;
715 // compute absolute sizes of horizontal structure
716 for (col_type col = 0; col < ncols(); ++col) {
718 for (row_type row = 0; row < nrows(); ++row) {
720 //idx_type const i = index(row, col);
721 //if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
722 // wid = max(wid, cell(i).width());
724 colinfo_[col].width_ = wid;
726 colinfo_[ncols()].width_ = 0;
728 // compute horizontal offsets
729 colinfo_[0].offset_ = border();
730 for (col_type col = 1; col <= ncols(); ++col) {
731 colinfo_[col].offset_ =
732 colinfo_[col - 1].offset_ +
733 colinfo_[col - 1].width_ +
734 displayColSpace(col - 1) +
736 //colinfo_[col].lines_ * vlinesep();
740 dim.wid = colinfo_[ncols() - 1].offset_
741 + colinfo_[ncols() - 1].width_
742 //+ vlinesep() * colinfo_[ncols()].lines_
745 dim.asc = -rowinfo_[0].offset_
746 + rowinfo_[0].ascent_
747 //+ hlinesep() * rowinfo_[0].lines_
750 dim.des = rowinfo_[nrows() - 1].offset_
751 + rowinfo_[nrows() - 1].descent_
752 //+ hlinesep() * rowinfo_[nrows()].lines_
757 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
759 // for (idx_type idx = 0; idx < nargs(); ++idx)
760 // if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
761 // cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
765 void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype)
768 for (idx_type idx = 0; idx < nargs(); ++idx)
769 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
770 cell(idx).updateBuffer(it, utype);
774 docstring InsetMathGrid::eolString(row_type row, bool fragile,
775 bool /*latex*/, bool last_eoln) const
779 if (!rowinfo_[row].crskip_.zero())
780 eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
781 else if(!rowinfo_[row].allow_newpage_)
784 // make sure an upcoming '[' does not break anything
785 if (row + 1 < nrows()) {
786 MathData const & c = cell(index(row + 1, 0));
787 if (!c.empty() && c.front()->getChar() == '[')
792 // only add \\ if necessary
793 if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
796 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
800 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
802 if (col + 1 == lastcol)
804 return from_ascii(" & ");
808 void InsetMathGrid::addRow(row_type row)
810 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
812 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData(buffer_));
814 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
818 void InsetMathGrid::delRow(row_type row)
823 cells_type::iterator it = cells_.begin() + row * ncols();
824 cells_.erase(it, it + ncols());
826 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
827 cellinfo_.erase(jt, jt + ncols());
829 rowinfo_.erase(rowinfo_.begin() + row);
833 void InsetMathGrid::copyRow(row_type row)
836 for (col_type col = 0; col < ncols(); ++col) {
837 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
838 // copying the cell does not set the buffer
839 cells_[(row + 1) * ncols() + col].setBuffer(*buffer_);
844 void InsetMathGrid::swapRow(row_type row)
848 if (row + 1 == nrows())
850 for (col_type col = 0; col < ncols(); ++col)
851 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
855 void InsetMathGrid::addCol(col_type newcol)
857 const col_type nc = ncols();
858 const row_type nr = nrows();
859 cells_type new_cells((nc + 1) * nr);
860 vector<CellInfo> new_cellinfo((nc + 1) * nr);
862 for (row_type row = 0; row < nr; ++row)
863 for (col_type col = 0; col < nc; ++col) {
864 new_cells[row * (nc + 1) + col + (col >= newcol)]
865 = cells_[row * nc + col];
866 new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
867 = cellinfo_[row * nc + col];
869 swap(cells_, new_cells);
870 // copying cells loses the buffer reference
872 swap(cellinfo_, new_cellinfo);
875 inf.skip_ = defaultColSpace(newcol);
876 inf.align_ = defaultColAlign(newcol);
877 colinfo_.insert(colinfo_.begin() + newcol, inf);
881 void InsetMathGrid::delCol(col_type col)
887 vector<CellInfo> tmpcellinfo;
888 for (col_type i = 0; i < nargs(); ++i)
889 if (i % ncols() != col) {
890 tmpcells.push_back(cells_[i]);
891 tmpcellinfo.push_back(cellinfo_[i]);
893 swap(cells_, tmpcells);
894 swap(cellinfo_, tmpcellinfo);
896 colinfo_.erase(colinfo_.begin() + col);
900 void InsetMathGrid::copyCol(col_type col)
903 for (row_type row = 0; row < nrows(); ++row) {
904 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
905 // copying the cell does not set the buffer
906 cells_[row * ncols() + col + 1].setBuffer(*buffer_);
911 void InsetMathGrid::swapCol(col_type col)
915 if (col + 1 == ncols())
917 for (row_type row = 0; row < nrows(); ++row)
918 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
922 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
924 if (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN)
926 col_type c = col(idx);
927 int x = colinfo_[c].offset_;
928 char align = displayColAlign(idx);
929 Dimension const & celldim = cell(idx).dimension(bv);
930 if (align == 'r' || align == 'R')
931 x += cellWidth(idx) - celldim.wid;
932 if (align == 'c' || align == 'C')
933 x += (cellWidth(idx) - celldim.wid) / 2;
938 int InsetMathGrid::cellYOffset(idx_type idx) const
940 return rowinfo_[row(idx)].offset_;
944 int InsetMathGrid::cellWidth(idx_type idx) const
946 switch (cellinfo_[idx].multi_) {
948 return colinfo_[col(idx)].width_;
949 case CELL_BEGIN_OF_MULTICOLUMN: {
950 col_type c1 = col(idx);
951 col_type c2 = c1 + ncellcols(idx);
952 return colinfo_[c2].offset_
953 - colinfo_[c1].offset_
954 - displayColSpace(c2)
956 - colinfo_[c2].lines_ * vlinesep();
958 case CELL_PART_OF_MULTICOLUMN:
965 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
970 cur.idx() -= ncols();
972 if (cur.row() + 1 >= nrows())
974 cur.idx() += ncols();
976 // If we are in a multicolumn cell, move to the "real" cell
977 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
978 LASSERT(cur.idx() > 0, return false);
981 // FIXME: this is only a workaround to avoid a crash if the inset
982 // in not in coord cache. The best would be to force a FitCursor
984 CoordCache::Arrays const & arraysCache = cur.bv().coordCache().arrays();
985 if (arraysCache.has(&cur.cell()))
986 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
993 bool InsetMathGrid::idxBackward(Cursor & cur) const
995 // leave matrix if at the front edge
999 // If we are in a multicolumn cell, move to the "real" cell
1000 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1001 LASSERT(cur.idx() > 0, return false);
1004 cur.pos() = cur.lastpos();
1009 bool InsetMathGrid::idxForward(Cursor & cur) const
1011 // leave matrix if at the back edge
1012 if (cur.col() + 1 == ncols())
1015 // If we are in a multicolumn cell, move to the next cell
1016 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1017 // leave matrix if at the back edge
1018 if (cur.col() + 1 == ncols())
1027 idx_type InsetMathGrid::firstIdx() const
1035 idx = (nrows() - 1) * ncols();
1038 idx = ((nrows() - 1) / 2) * ncols();
1040 // If we are in a multicolumn cell, move to the "real" cell
1041 while (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN) {
1042 LASSERT(idx > 0, return 0);
1049 idx_type InsetMathGrid::lastIdx() const
1060 idx = ((nrows() - 1) / 2 + 1) * ncols() - 1;
1062 // If we are in a multicolumn cell, move to the "real" cell
1063 while (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN) {
1064 LASSERT(idx > 0, return false);
1071 bool InsetMathGrid::idxDelete(idx_type & idx)
1073 // nothing to do if we have just one row
1077 // nothing to do if we are in the middle of the last row of the inset
1078 if (idx + ncols() > nargs())
1081 // try to delete entire sequence of ncols() empty cells if possible
1082 for (idx_type i = idx; i < idx + ncols(); ++i)
1083 if (!cell(i).empty())
1086 // move cells if necessary
1087 for (idx_type i = index(row(idx), 0); i < idx; ++i)
1088 swap(cell(i), cell(i + ncols()));
1095 // undo effect of Ctrl-Tab (i.e. pull next cell)
1096 //if (idx + 1 != nargs())
1097 // cell(idx).swap(cell(idx + 1));
1099 // we handled the event..
1104 // reimplement old behaviour when pressing Delete in the last position
1106 void InsetMathGrid::idxGlue(idx_type idx)
1108 col_type c = col(idx);
1109 if (c + 1 == ncols()) {
1110 if (row(idx) + 1 != nrows()) {
1111 for (col_type cc = 0; cc < ncols(); ++cc)
1112 cell(idx).append(cell(idx + cc + 1));
1113 delRow(row(idx) + 1);
1116 idx_type idx_next = idx + 1;
1117 while (idx_next < nargs() &&
1118 cellinfo_[idx_next].multi_ == CELL_PART_OF_MULTICOLUMN)
1120 if (idx_next < nargs())
1121 cell(idx).append(cell(idx_next));
1122 col_type oldcol = c + 1;
1123 for (col_type cc = c + 2; cc < ncols(); ++cc)
1124 cell(idx - oldcol + cc) = cell(idx - oldcol + 1 + cc);
1125 cell(idx - c + ncols() - 1).clear();
1130 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
1132 return rowinfo_[row];
1136 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
1138 return rowinfo_[row];
1142 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
1144 row_type const ri = row(idx);
1145 row_type const r1 = min(row(from), row(to));
1146 row_type const r2 = max(row(from), row(to));
1147 col_type const ci = col(idx);
1148 col_type const c1 = min(col(from), col(to));
1149 col_type const c2 = max(col(from), col(to));
1150 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
1154 void InsetMathGrid::normalize(NormalStream & os) const
1157 for (row_type row = 0; row < nrows(); ++row) {
1159 for (col_type col = 0; col < ncols(); ++col) {
1160 idx_type const i = index(row, col);
1161 switch (cellinfo_[i].multi_) {
1163 os << "[cell " << cell(i) << ']';
1165 case CELL_BEGIN_OF_MULTICOLUMN:
1166 os << "[cell colspan="
1167 << static_cast<int>(ncellcols(i)) << ' '
1170 case CELL_PART_OF_MULTICOLUMN:
1180 void InsetMathGrid::mathmlize(MathStream & os) const
1182 bool const havetable = nrows() > 1 || ncols() > 1;
1184 os << MTag("mtable");
1185 char const * const celltag = havetable ? "mtd" : "mrow";
1186 for (row_type row = 0; row < nrows(); ++row) {
1189 for (col_type col = 0; col < ncols(); ++col) {
1190 idx_type const i = index(row, col);
1191 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1192 col_type const cellcols = ncellcols(i);
1194 if (havetable && cellcols > 1)
1195 attr << "colspan='" << cellcols << '\'';
1196 os << MTag(celltag, attr.str());
1197 os << cell(index(row, col));
1198 os << ETag(celltag);
1205 os << ETag("mtable");
1210 // We need to do something about alignment here.
1211 void InsetMathGrid::htmlize(HtmlStream & os, string attrib) const
1213 bool const havetable = nrows() > 1 || ncols() > 1;
1215 os << cell(index(0, 0));
1218 os << MTag("table", attrib);
1219 for (row_type row = 0; row < nrows(); ++row) {
1221 for (col_type col = 0; col < ncols(); ++col) {
1222 idx_type const i = index(row, col);
1223 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1224 col_type const cellcols = ncellcols(i);
1227 attr << "colspan='" << cellcols << '\'';
1228 os << MTag("td", attr.str());
1229 os << cell(index(row, col));
1235 os << ETag("table");
1239 void InsetMathGrid::htmlize(HtmlStream & os) const
1241 htmlize(os, "class='mathtable'");
1245 void InsetMathGrid::validate(LaTeXFeatures & features) const
1247 if (features.runparams().math_flavor == OutputParams::MathAsHTML
1248 && (nrows() > 1 || ncols() > 1)) {
1249 // CSS taken from InsetMathCases
1250 features.addCSSSnippet(
1251 "table.mathtable{display: inline-block; text-align: center; border: none;"
1252 "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
1253 "table.mathtable td {text-align: left; border: none;}");
1255 InsetMathNest::validate(features);
1259 void InsetMathGrid::write(WriteStream & os) const
1261 write(os, 0, 0, nrows(), ncols());
1264 void InsetMathGrid::write(WriteStream & os,
1265 row_type beg_row, col_type beg_col,
1266 row_type end_row, col_type end_col) const
1268 MathEnsurer ensurer(os, false);
1270 for (row_type row = beg_row; row < end_row; ++row) {
1271 os << verboseHLine(rowinfo_[row].lines_);
1272 // don't write & and empty cells at end of line,
1273 // unless there are vertical lines
1274 col_type lastcol = 0;
1275 bool emptyline = true;
1276 bool last_eoln = true;
1277 for (col_type col = beg_col; col < end_col; ++col) {
1278 idx_type const idx = index(row, col);
1279 bool const empty_cell = cell(idx).empty();
1280 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL)
1282 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL ||
1283 colinfo_[col + 1].lines_) {
1288 for (col_type col = beg_col; col < end_col;) {
1290 idx_type const idx = index(row, col);
1291 TexRow::RowEntry entry = TexRow::mathEntry(id(),idx);
1292 os.texrow().start(entry);
1293 if (col >= lastcol) {
1297 Changer dummy = os.changeRowEntry(entry);
1298 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1300 while (s < ncols() &&
1301 cellinfo_[index(row, s)].multi_ == CELL_PART_OF_MULTICOLUMN)
1304 os << "\\multicolumn{" << nccols
1305 << "}{" << cellinfo_[idx].align_
1309 if (os.pendingBrace())
1310 ModeSpecifier specifier(os, TEXT_MODE);
1311 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1313 os << eocString(col + nccols - 1, lastcol);
1316 eol = eolString(row, os.fragile(), os.latex(), last_eoln);
1318 // append newline only if line wasn't completely empty
1319 // and the formula is not written on a single line
1320 bool const empty = emptyline && eol.empty();
1321 if (!empty && nrows() > 1)
1324 // @TODO use end_row instead of nrows() ?
1325 docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
1337 int InsetMathGrid::colsep() const
1343 int InsetMathGrid::rowsep() const
1349 int InsetMathGrid::hlinesep() const
1355 int InsetMathGrid::vlinesep() const
1361 int InsetMathGrid::border() const
1367 void InsetMathGrid::splitCell(Cursor & cur)
1369 if (cur.idx() == cur.lastidx())
1371 MathData ar = cur.cell();
1372 ar.erase(0, cur.pos());
1373 cur.cell().erase(cur.pos(), cur.lastpos());
1375 while (cur.idx() << nargs() &&
1376 cellinfo_[cur.idx()].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1379 cur.cell().insert(0, ar);
1383 char InsetMathGrid::displayColAlign(idx_type idx) const
1385 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1386 // align_ may also contain lines like "||r|", so this is
1387 // not complete, but we catch at least the simple cases.
1388 if (cellinfo_[idx].align_ == "c")
1390 if (cellinfo_[idx].align_ == "l")
1392 if (cellinfo_[idx].align_ == "r")
1395 return colinfo_[col(idx)].align_;
1399 int InsetMathGrid::displayColSpace(col_type col) const
1401 return colinfo_[col].skip_;
1404 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1406 //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1408 Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
1410 FuncCode const act = cmd.action();
1413 // insert file functions
1414 case LFUN_LINE_DELETE_FORWARD:
1415 cur.recordUndoInset();
1416 //autocorrect_ = false;
1424 if (cur.idx() > cur.lastidx())
1425 cur.idx() = cur.lastidx();
1426 if (cur.pos() > cur.lastpos())
1427 cur.pos() = cur.lastpos();
1430 case LFUN_CELL_SPLIT:
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() != MATH_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 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1669 case LFUN_LINE_BEGIN_SELECT:
1670 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1671 act == LFUN_WORD_LEFT_SELECT ||
1672 act == LFUN_LINE_BEGIN_SELECT);
1673 cur.macroModeClose();
1674 if (cur.pos() != 0) {
1676 } else if (cur.idx() % cur.ncols() != 0) {
1677 cur.idx() -= cur.idx() % cur.ncols();
1679 } else if (cur.idx() != 0) {
1683 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1689 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1691 case LFUN_LINE_END_SELECT:
1692 cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
1693 act == LFUN_WORD_RIGHT_SELECT ||
1694 act == LFUN_LINE_END_SELECT);
1695 cur.macroModeClose();
1697 if (cur.pos() != cur.lastpos()) {
1698 cur.pos() = cur.lastpos();
1699 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1700 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1701 cur.pos() = cur.lastpos();
1702 } else if (cur.idx() != cur.lastidx()) {
1703 cur.idx() = cur.lastidx();
1704 cur.pos() = cur.lastpos();
1706 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1712 InsetMathNest::doDispatch(cur, cmd);
1717 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1718 FuncStatus & status) const
1720 switch (cmd.action()) {
1721 case LFUN_TABULAR_FEATURE: {
1722 string s = cmd.getArg(0);
1723 if (&cur.inset() != this) {
1724 // Table actions requires that the cursor is _inside_ the
1726 status.setEnabled(false);
1727 status.message(from_utf8(N_("Cursor not in table")));
1730 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1731 status.setEnabled(false);
1732 status.message(from_utf8(N_("Only one row")));
1736 (s == "delete-column" || s == "swap-column")) {
1737 status.setEnabled(false);
1738 status.message(from_utf8(N_("Only one column")));
1741 if ((rowinfo_[cur.row()].lines_ == 0 &&
1742 s == "delete-hline-above") ||
1743 (rowinfo_[cur.row() + 1].lines_ == 0 &&
1744 s == "delete-hline-below")) {
1745 status.setEnabled(false);
1746 status.message(from_utf8(N_("No hline to delete")));
1750 if ((colinfo_[cur.col()].lines_ == 0 &&
1751 s == "delete-vline-left") ||
1752 (colinfo_[cur.col() + 1].lines_ == 0 &&
1753 s == "delete-vline-right")) {
1754 status.setEnabled(false);
1755 status.message(from_utf8(N_("No vline to delete")));
1758 if (s == "valign-top" || s == "valign-middle" ||
1759 s == "valign-bottom" || s == "align-left" ||
1760 s == "align-right" || s == "align-center") {
1761 status.setEnabled(true);
1762 char const ha = horizontalAlignment(cur.col());
1763 char const va = verticalAlignment();
1764 status.setOnOff((s == "align-left" && ha == 'l')
1765 || (s == "align-right" && ha == 'r')
1766 || (s == "align-center" && ha == 'c')
1767 || (s == "valign-top" && va == 't')
1768 || (s == "valign-bottom" && va == 'b')
1769 || (s == "valign-middle" && va == 'c'));
1772 if (s == "append-row" || s == "delete-row" ||
1773 s == "copy-row" || s == "swap-row" ||
1774 s == "add-hline-above" || s == "add-hline-below" ||
1775 s == "delete-hline-above" || s == "delete-hline-below" ||
1776 s == "append-column" || s == "delete-column" ||
1777 s == "copy-column" || s == "swap-column" ||
1778 s == "add-vline-left" || s == "add-vline-right" ||
1779 s == "delete-vline-left" || s == "delete-vline-right") {
1780 status.setEnabled(true);
1782 status.setEnabled(false);
1783 status.message(bformat(
1784 from_utf8(N_("Unknown tabular feature '%1$s'")),
1789 // FIXME: What did this code do?
1790 // Please check whether it is still needed!
1791 // should be more precise
1792 if (v_align_ == '\0') {
1793 status.enable(true);
1796 if (cmd.argument().empty()) {
1797 status.enable(false);
1800 if (!contains("tcb", cmd.argument()[0])) {
1801 status.enable(false);
1804 status.setOnOff(cmd.argument()[0] == v_align_);
1805 status.setEnabled(true);
1810 case LFUN_CELL_SPLIT:
1811 status.setEnabled(cur.idx() != cur.lastidx());
1814 case LFUN_CELL_BACKWARD:
1815 case LFUN_CELL_FORWARD:
1816 status.setEnabled(true);
1822 return InsetMathNest::getStatus(cur, cmd, status);
1827 char InsetMathGrid::colAlign(HullType type, col_type col, BufferParams const & bp)
1831 return "rcl"[col % 3];
1836 if (!bp.is_math_indent)
1846 return "rl"[col & 1];
1861 int InsetMathGrid::colSpace(HullType type, col_type col)
1863 int alignInterSpace = 0;
1878 alignInterSpace = 20;
1881 alignInterSpace = 0;
1884 alignInterSpace = 40;
1888 alignInterSpace = 60;
1891 return (col % 2) ? alignInterSpace : 0;