2 * \file InsetMathGrid.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
14 #include "InsetMathGrid.h"
16 #include "InsetMathUnknown.h"
18 #include "MathParser.h"
19 #include "MathStream.h"
20 #include "MetricsInfo.h"
23 #include "BufferParams.h"
24 #include "BufferView.h"
26 #include "CutAndPaste.h"
27 #include "FuncRequest.h"
28 #include "FuncStatus.h"
29 #include "LaTeXFeatures.h"
32 #include "frontends/Clipboard.h"
33 #include "frontends/Painter.h"
35 #include "support/debug.h"
36 #include "support/docstream.h"
37 #include "support/gettext.h"
38 #include "support/lstrings.h"
39 #include "support/lassert.h"
44 using namespace lyx::support;
50 static docstring verboseHLine(int n)
53 for (int i = 0; i < n; ++i)
61 static int extractInt(istream & is)
65 return (num == 0) ? 1 : num;
69 static void resetGrid(InsetMathGrid & grid)
71 while (grid.ncols() > 1)
72 grid.delCol(grid.ncols() - 1);
73 while (grid.nrows() > 1)
74 grid.delRow(grid.nrows() - 1);
75 grid.cell(0).erase(0, grid.cell(0).size());
81 //////////////////////////////////////////////////////////////
84 InsetMathGrid::CellInfo::CellInfo()
90 //////////////////////////////////////////////////////////////
93 InsetMathGrid::RowInfo::RowInfo()
94 : descent_(0), ascent_(0), offset_(0), lines_(0), skip_(0),
100 int InsetMathGrid::RowInfo::skipPixels(MetricsInfo const & mi) const
102 return crskip_.inPixels(mi.base);
107 //////////////////////////////////////////////////////////////
110 InsetMathGrid::ColInfo::ColInfo()
111 : align_('c'), width_(0), offset_(0), lines_(0), skip_(0)
115 //////////////////////////////////////////////////////////////
118 InsetMathGrid::InsetMathGrid(Buffer * buf)
119 : InsetMathNest(buf, 1),
129 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n)
130 : InsetMathNest(buf, m * n),
140 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n, char v,
142 : InsetMathNest(buf, m * n),
149 setVerticalAlignment(v);
150 setHorizontalAlignments(h);
154 Inset * InsetMathGrid::clone() const
156 return new InsetMathGrid(*this);
160 InsetMath::idx_type InsetMathGrid::index(row_type row, col_type col) const
162 return col + ncols() * row;
166 void InsetMathGrid::setDefaults()
169 lyxerr << "positive number of columns expected" << endl;
171 // lyxerr << "positive number of rows expected" << endl;
172 for (col_type col = 0; col < ncols(); ++col) {
173 colinfo_[col].align_ = defaultColAlign(col);
174 colinfo_[col].skip_ = defaultColSpace(col);
175 colinfo_[col].special_.clear();
177 for (idx_type idx = 0; idx < nargs(); ++idx)
178 cellinfo_[idx].multi_ = CELL_NORMAL;
182 bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
184 if (str == "\\hline") {
185 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
187 if (getStatus(cur, fr, status)) {
188 if (status.enabled()) {
189 rowinfo_[cur.row()].lines_++;
194 return InsetMathNest::interpretString(cur, str);
198 void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
201 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
204 colinfo_[col].lines_++;
205 } else if ((c == 'p' || c == 'm' || c == 'b'||
206 c == '!' || c == '@' || c == '>' || c == '<') &&
207 it + 1 != hh.end() && *(it + 1) == '{') {
208 // @{decl.} and p{width} are standard LaTeX, the
209 // others are extensions by array.sty
210 bool const newcolumn = c == 'p' || c == 'm' || c == 'b';
212 // this declares a new column
214 // Only intercolumn stuff is allowed
215 // in the last dummy column
217 colinfo_[col].align_ = 'l';
219 // this is intercolumn stuff
220 if (colinfo_[col].special_.empty())
221 // Overtake possible lines
222 colinfo_[col].special_ = docstring(colinfo_[col].lines_, '|');
226 while (it != hh.end()) {
228 colinfo_[col].special_ += c;
234 if (brace_open > 0 && brace_open == brace_close)
239 colinfo_[col].lines_ = count(
240 colinfo_[col].special_.begin(),
241 colinfo_[col].special_.end(), '|');
242 LYXERR(Debug::MATHED, "special column separator: `"
243 << to_utf8(colinfo_[col].special_) << '\'');
245 colinfo_[col].lines_ = 0;
246 colinfo_[col].special_.clear();
248 } else if (col >= ncols()) {
249 // Only intercolumn stuff is allowed in the last
252 } else if (c == 'c' || c == 'l' || c == 'r') {
253 colinfo_[col].align_ = static_cast<char>(c);
254 if (!colinfo_[col].special_.empty()) {
255 colinfo_[col].special_ += c;
256 colinfo_[col].lines_ = count(
257 colinfo_[col].special_.begin(),
258 colinfo_[col].special_.end(), '|');
259 LYXERR(Debug::MATHED, "special column separator: `"
260 << to_utf8(colinfo_[col].special_) << '\'');
263 colinfo_[col].lines_ = 0;
264 colinfo_[col].special_.clear();
266 lyxerr << "unknown column separator: '" << c << "'" << endl;
271 col_type n = hh.size();
274 for (col_type col = 0; col < n; ++col)
275 colinfo_[col].align_ = hh[col];
280 InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh)
283 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
284 if (*it == 'c' || *it == 'l' || *it == 'r'||
285 *it == 'p' || *it == 'm' || *it == 'b')
287 // let's have at least one column, even if we did not recognize its
295 void InsetMathGrid::setHorizontalAlignment(char h, col_type col)
297 colinfo_[col].align_ = h;
298 if (!colinfo_[col].special_.empty()) {
299 char_type & c = colinfo_[col].special_[colinfo_[col].special_.size() - 1];
300 if (c == 'l' || c == 'c' || c == 'r')
303 // FIXME: Change alignment of p, m and b columns, too
307 char InsetMathGrid::horizontalAlignment(col_type col) const
309 return colinfo_[col].align_;
313 docstring InsetMathGrid::horizontalAlignments() const
316 for (col_type col = 0; col < ncols(); ++col) {
317 if (colinfo_[col].special_.empty()) {
318 res += docstring(colinfo_[col].lines_, '|');
319 res += colinfo_[col].align_;
321 res += colinfo_[col].special_;
323 if (colinfo_[ncols()].special_.empty())
324 return res + docstring(colinfo_[ncols()].lines_, '|');
325 return res + colinfo_[ncols()].special_;
329 void InsetMathGrid::setVerticalAlignment(char c)
335 char InsetMathGrid::verticalAlignment() const
341 InsetMathGrid::col_type InsetMathGrid::ncols() const
343 return colinfo_.size() - 1;
347 InsetMathGrid::row_type InsetMathGrid::nrows() const
349 return rowinfo_.size() - 1;
353 InsetMathGrid::col_type InsetMathGrid::col(idx_type idx) const
355 return idx % ncols();
359 InsetMathGrid::row_type InsetMathGrid::row(idx_type idx) const
361 return idx / ncols();
365 InsetMathGrid::col_type InsetMathGrid::ncellcols(idx_type idx) const
368 if (cellinfo_[idx].multi_ == CELL_NORMAL)
370 // If the cell at idx is already CELL_PART_OF_MULTICOLUMN we return
371 // the number of remaining columns, not the ones of the complete
372 // multicolumn cell. This makes it possible to always go to the next
373 // cell with idx + ncellcols(idx) - 1.
374 row_type const r = row(idx);
375 while (idx+cols < nargs() && row(idx+cols) == r &&
376 cellinfo_[idx+cols].multi_ == CELL_PART_OF_MULTICOLUMN)
382 void InsetMathGrid::vcrskip(Length const & crskip, row_type row)
384 rowinfo_[row].crskip_ = crskip;
388 Length InsetMathGrid::vcrskip(row_type row) const
390 return rowinfo_[row].crskip_;
394 void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
396 // let the cells adjust themselves
397 for (idx_type i = 0; i < nargs(); ++i) {
398 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
400 cell(i).metrics(mi, dimc);
404 BufferView & bv = *mi.base.bv;
406 // compute absolute sizes of vertical structure
407 for (row_type row = 0; row < nrows(); ++row) {
410 for (col_type col = 0; col < ncols(); ++col) {
411 idx_type const i = index(row, col);
412 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
413 Dimension const & dimc = cell(i).dimension(bv);
414 asc = max(asc, dimc.asc);
415 desc = max(desc, dimc.des);
418 rowinfo_[row].ascent_ = asc;
419 rowinfo_[row].descent_ = desc;
421 rowinfo_[nrows()].ascent_ = 0;
422 rowinfo_[nrows()].descent_ = 0;
424 // compute vertical offsets
425 rowinfo_[0].offset_ = 0;
426 for (row_type row = 1; row <= nrows(); ++row) {
427 rowinfo_[row].offset_ =
428 rowinfo_[row - 1].offset_ +
429 rowinfo_[row - 1].descent_ +
430 rowinfo_[row - 1].skipPixels(mi) +
432 rowinfo_[row].lines_ * hlinesep() +
433 rowinfo_[row].ascent_;
436 // adjust vertical offset
443 h = rowinfo_[nrows() - 1].offset_;
446 h = rowinfo_[nrows() - 1].offset_ / 2;
448 for (row_type row = 0; row <= nrows(); ++row)
449 rowinfo_[row].offset_ -= h;
452 // multicolumn cell widths, as a map from first column to width in a
453 // vector of last columns.
454 // This is only used if the grid has more than one row, since for
455 // one-row grids multicolumn cells do not need special handling
456 vector<map<col_type, int> > mcolwidths(ncols());
458 // compute absolute sizes of horizontal structure
459 for (col_type col = 0; col < ncols(); ++col) {
461 for (row_type row = 0; row < nrows(); ++row) {
462 idx_type const i = index(row, col);
463 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
464 int const w = cell(i).dimension(bv).wid;
465 col_type const cols = ncellcols(i);
466 if (cols > 1 && nrows() > 1) {
467 col_type last = col+cols-1;
468 LASSERT(last < ncols(), last = ncols()-1);
469 map<col_type, int>::iterator it =
470 mcolwidths[last].find(col);
471 if (it == mcolwidths[last].end())
472 mcolwidths[last][col] = w;
474 it->second = max(it->second, w);
479 colinfo_[col].width_ = wid;
481 colinfo_[ncols()].width_ = 0;
483 // compute horizontal offsets
484 colinfo_[0].offset_ = border() + colinfo_[0].lines_ * vlinesep();;
485 for (col_type col = 1; col <= ncols(); ++col) {
486 colinfo_[col].offset_ =
487 colinfo_[col - 1].offset_ +
488 colinfo_[col - 1].width_ +
489 displayColSpace(col - 1) +
491 colinfo_[col].lines_ * vlinesep();
494 // increase column widths for multicolumn cells if needed
495 // FIXME: multicolumn lines are not yet considered
496 for (col_type last = 0; last < ncols(); ++last) {
497 map<col_type, int> const & widths = mcolwidths[last];
498 // We increase the width of the last column of the multicol
499 // cell (some sort of left alignment). Since we iterate through
500 // the last and the first columns from left to right, we ensure
501 // that increased widths of previous columns are correctly
502 // taken into account for later columns, thus preventing
503 // unneeded width increasing.
504 for (map<col_type, int>::const_iterator it = widths.begin();
505 it != widths.end(); ++it) {
506 int const wid = it->second;
507 col_type const first = it->first;
508 int const nextoffset =
509 colinfo_[first].offset_ +
511 displayColSpace(last) +
513 colinfo_[last+1].lines_ * vlinesep();
514 int const dx = nextoffset - colinfo_[last+1].offset_;
516 colinfo_[last].width_ += dx;
517 for (col_type col = last + 1; col <= ncols(); ++col)
518 colinfo_[col].offset_ += dx;
524 dim.wid = colinfo_[ncols() - 1].offset_
525 + colinfo_[ncols() - 1].width_
526 + vlinesep() * colinfo_[ncols()].lines_
529 dim.asc = - rowinfo_[0].offset_
530 + rowinfo_[0].ascent_
531 + hlinesep() * rowinfo_[0].lines_
534 dim.des = rowinfo_[nrows() - 1].offset_
535 + rowinfo_[nrows() - 1].descent_
536 + hlinesep() * rowinfo_[nrows()].lines_
541 // Increase ws_[i] for 'R' columns (except the first one)
542 for (int i = 1; i < nc_; ++i)
543 if (align_[i] == 'R')
544 ws_[i] += 10 * df_width;
545 // Increase ws_[i] for 'C' column
546 if (align_[0] == 'C')
547 if (ws_[0] < 7 * workwidth / 8)
548 ws_[0] = 7 * workwidth / 8;
552 for (cxrow = row_.begin(); cxrow; ++cxrow) {
555 for (int i = 0; i < nc_; ++i) {
557 if (cxrow->getTab(i) <= 0) {
558 cxrow->setTab(i, df_width);
566 lf = (ws_[i] - cxrow->getTab(i))/2;
570 lf = ws_[i] - cxrow->getTab(i);
573 if (cxrow == row_.begin())
575 else if (cxrow.is_last())
576 lf = ws_[i] - cxrow->getTab(i);
578 lf = (ws_[i] - cxrow->getTab(i))/2;
581 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
582 cxrow->setTab(i, lf + rg);
583 rg = ws_[i] - ww + colsep();
584 if (cxrow == row_.begin())
585 width += ws_[i] + colsep();
587 cxrow->setBaseline(cxrow->getBaseline() - ascent);
590 dim.wid += leftMargin() + rightMargin();
591 metricsMarkers2(mi, dim);
595 int InsetMathGrid::vLineHOffset(col_type col, unsigned int line) const
598 return leftMargin() + colinfo_[col].offset_
599 - (colinfo_[col].lines_ - line - 1) * vlinesep()
600 - vlinesep()/2 - colsep()/2;
602 LASSERT(col == ncols(), return 0);
603 return leftMargin() + colinfo_[col-1].offset_ + colinfo_[col-1].width_
605 + vlinesep()/2 + colsep()/2;
610 int InsetMathGrid::hLineVOffset(row_type row, unsigned int line) const
612 return rowinfo_[row].offset_
613 - rowinfo_[row].ascent_
615 - hlinesep()/2 - rowsep()/2;
619 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
621 BufferView const & bv = *pi.base.bv;
623 for (idx_type idx = 0; idx < nargs(); ++idx) {
624 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN) {
626 x + leftMargin() + cellXOffset(bv, idx),
627 y + cellYOffset(idx));
629 row_type r = row(idx);
630 int const yy1 = y + hLineVOffset(r, 0);
631 int const yy2 = y + hLineVOffset(r + 1, rowinfo_[r + 1].lines_ - 1);
632 auto draw_left_borders = [&](col_type c) {
633 for (unsigned int i = 0; i < colinfo_[c].lines_; ++i) {
634 int const xx = x + vLineHOffset(c, i);
635 pi.pain.line(xx, yy1, xx, yy2, Color_foreground);
638 col_type c = col(idx);
639 // Draw inner left borders cell-by-cell because of multicolumns
640 draw_left_borders(c);
641 // Draw the right border (only once)
643 draw_left_borders(ncols());
647 // Draw horizontal borders
648 for (row_type r = 0; r <= nrows(); ++r) {
649 int const xx1 = x + vLineHOffset(0, 0);
650 int const xx2 = x + vLineHOffset(ncols(), colinfo_[ncols()].lines_ - 1);
651 for (unsigned int i = 0; i < rowinfo_[r].lines_; ++i) {
652 int const yy = y + hLineVOffset(r, i);
653 pi.pain.line(xx1, yy, xx2, yy, Color_foreground);
657 drawMarkers2(pi, x, y);
661 void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
663 // let the cells adjust themselves
664 for (idx_type i = 0; i < nargs(); ++i)
665 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
666 cell(i).metricsT(mi, dim);
668 // compute absolute sizes of vertical structure
669 for (row_type row = 0; row < nrows(); ++row) {
672 for (col_type col = 0; col < ncols(); ++col) {
673 idx_type const i = index(row, col);
674 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
675 //MathData const & c = cell(i);
678 asc = max(asc, dimc.ascent());
679 desc = max(desc, dimc.descent());
682 rowinfo_[row].ascent_ = asc;
683 rowinfo_[row].descent_ = desc;
685 rowinfo_[nrows()].ascent_ = 0;
686 rowinfo_[nrows()].descent_ = 0;
688 // compute vertical offsets
689 rowinfo_[0].offset_ = 0;
690 for (row_type row = 1; row <= nrows(); ++row) {
691 rowinfo_[row].offset_ =
692 rowinfo_[row - 1].offset_ +
693 rowinfo_[row - 1].descent_ +
694 //rowinfo_[row - 1].skipPixels(mi) +
696 //rowinfo_[row].lines_ * hlinesep() +
697 rowinfo_[row].ascent_;
700 // adjust vertical offset
707 h = rowinfo_[nrows() - 1].offset_;
710 h = rowinfo_[nrows() - 1].offset_ / 2;
712 for (row_type row = 0; row <= nrows(); ++row)
713 rowinfo_[row].offset_ -= h;
716 // compute absolute sizes of horizontal structure
717 for (col_type col = 0; col < ncols(); ++col) {
719 for (row_type row = 0; row < nrows(); ++row) {
721 //idx_type const i = index(row, col);
722 //if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
723 // wid = max(wid, cell(i).width());
725 colinfo_[col].width_ = wid;
727 colinfo_[ncols()].width_ = 0;
729 // compute horizontal offsets
730 colinfo_[0].offset_ = border();
731 for (col_type col = 1; col <= ncols(); ++col) {
732 colinfo_[col].offset_ =
733 colinfo_[col - 1].offset_ +
734 colinfo_[col - 1].width_ +
735 displayColSpace(col - 1) +
737 //colinfo_[col].lines_ * vlinesep();
741 dim.wid = colinfo_[ncols() - 1].offset_
742 + colinfo_[ncols() - 1].width_
743 //+ vlinesep() * colinfo_[ncols()].lines_
746 dim.asc = -rowinfo_[0].offset_
747 + rowinfo_[0].ascent_
748 //+ hlinesep() * rowinfo_[0].lines_
751 dim.des = rowinfo_[nrows() - 1].offset_
752 + rowinfo_[nrows() - 1].descent_
753 //+ hlinesep() * rowinfo_[nrows()].lines_
758 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
760 // for (idx_type idx = 0; idx < nargs(); ++idx)
761 // if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
762 // cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
766 void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype)
769 for (idx_type idx = 0; idx < nargs(); ++idx)
770 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
771 cell(idx).updateBuffer(it, utype);
775 docstring InsetMathGrid::eolString(row_type row, bool fragile,
776 bool /*latex*/, bool last_eoln) const
780 if (!rowinfo_[row].crskip_.zero())
781 eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
782 else if(!rowinfo_[row].allow_newpage_)
785 // make sure an upcoming '[' does not break anything
786 if (row + 1 < nrows()) {
787 MathData const & c = cell(index(row + 1, 0));
788 if (!c.empty() && c.front()->getChar() == '[')
793 // only add \\ if necessary
794 if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
797 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
801 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
803 if (col + 1 == lastcol)
805 return from_ascii(" & ");
809 void InsetMathGrid::addRow(row_type row)
811 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
813 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData());
815 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
819 void InsetMathGrid::delRow(row_type row)
824 cells_type::iterator it = cells_.begin() + row * ncols();
825 cells_.erase(it, it + ncols());
827 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
828 cellinfo_.erase(jt, jt + ncols());
830 rowinfo_.erase(rowinfo_.begin() + row);
834 void InsetMathGrid::copyRow(row_type row)
837 for (col_type col = 0; col < ncols(); ++col)
838 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
842 void InsetMathGrid::swapRow(row_type row)
846 if (row + 1 == nrows())
848 for (col_type col = 0; col < ncols(); ++col)
849 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
853 void InsetMathGrid::addCol(col_type newcol)
855 const col_type nc = ncols();
856 const row_type nr = nrows();
857 cells_type new_cells((nc + 1) * nr);
858 vector<CellInfo> new_cellinfo((nc + 1) * nr);
860 for (row_type row = 0; row < nr; ++row)
861 for (col_type col = 0; col < nc; ++col) {
862 new_cells[row * (nc + 1) + col + (col >= newcol)]
863 = cells_[row * nc + col];
864 new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
865 = cellinfo_[row * nc + col];
867 swap(cells_, new_cells);
868 swap(cellinfo_, new_cellinfo);
871 inf.skip_ = defaultColSpace(newcol);
872 inf.align_ = defaultColAlign(newcol);
873 colinfo_.insert(colinfo_.begin() + newcol, inf);
877 void InsetMathGrid::delCol(col_type col)
883 vector<CellInfo> tmpcellinfo;
884 for (col_type i = 0; i < nargs(); ++i)
885 if (i % ncols() != col) {
886 tmpcells.push_back(cells_[i]);
887 tmpcellinfo.push_back(cellinfo_[i]);
889 swap(cells_, tmpcells);
890 swap(cellinfo_, tmpcellinfo);
892 colinfo_.erase(colinfo_.begin() + col);
896 void InsetMathGrid::copyCol(col_type col)
899 for (row_type row = 0; row < nrows(); ++row)
900 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
904 void InsetMathGrid::swapCol(col_type col)
908 if (col + 1 == ncols())
910 for (row_type row = 0; row < nrows(); ++row)
911 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
915 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
917 if (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN)
919 col_type c = col(idx);
920 int x = colinfo_[c].offset_;
921 char align = displayColAlign(idx);
922 Dimension const & celldim = cell(idx).dimension(bv);
923 if (align == 'r' || align == 'R')
924 x += cellWidth(idx) - celldim.wid;
925 if (align == 'c' || align == 'C')
926 x += (cellWidth(idx) - celldim.wid) / 2;
931 int InsetMathGrid::cellYOffset(idx_type idx) const
933 return rowinfo_[row(idx)].offset_;
937 int InsetMathGrid::cellWidth(idx_type idx) const
939 switch (cellinfo_[idx].multi_) {
941 return colinfo_[col(idx)].width_;
942 case CELL_BEGIN_OF_MULTICOLUMN: {
943 col_type c1 = col(idx);
944 col_type c2 = c1 + ncellcols(idx);
945 return colinfo_[c2].offset_
946 - colinfo_[c1].offset_
947 - displayColSpace(c2)
949 - colinfo_[c2].lines_ * vlinesep();
951 case CELL_PART_OF_MULTICOLUMN:
958 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
963 cur.idx() -= ncols();
965 if (cur.row() + 1 >= nrows())
967 cur.idx() += ncols();
969 // If we are in a multicolumn cell, move to the "real" cell
970 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
971 LASSERT(cur.idx() > 0, return false);
974 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
979 bool InsetMathGrid::idxBackward(Cursor & cur) const
981 // leave matrix if at the front edge
985 // If we are in a multicolumn cell, move to the "real" cell
986 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
987 LASSERT(cur.idx() > 0, return false);
990 cur.pos() = cur.lastpos();
995 bool InsetMathGrid::idxForward(Cursor & cur) const
997 // leave matrix if at the back edge
998 if (cur.col() + 1 == ncols())
1001 // If we are in a multicolumn cell, move to the next cell
1002 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1003 // leave matrix if at the back edge
1004 if (cur.col() + 1 == ncols())
1013 bool InsetMathGrid::idxFirst(Cursor & cur) const
1020 cur.idx() = (nrows() - 1) * ncols();
1023 cur.idx() = ((nrows() - 1) / 2) * ncols();
1025 // If we are in a multicolumn cell, move to the "real" cell
1026 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1027 LASSERT(cur.idx() > 0, return false);
1035 bool InsetMathGrid::idxLast(Cursor & cur) const
1039 cur.idx() = ncols() - 1;
1042 cur.idx() = nargs() - 1;
1045 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
1047 // If we are in a multicolumn cell, move to the "real" cell
1048 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1049 LASSERT(cur.idx() > 0, return false);
1052 cur.pos() = cur.lastpos();
1057 bool InsetMathGrid::idxDelete(idx_type & idx)
1059 // nothing to do if we have just one row
1063 // nothing to do if we are in the middle of the last row of the inset
1064 if (idx + ncols() > nargs())
1067 // try to delete entire sequence of ncols() empty cells if possible
1068 for (idx_type i = idx; i < idx + ncols(); ++i)
1069 if (!cell(i).empty())
1072 // move cells if necessary
1073 for (idx_type i = index(row(idx), 0); i < idx; ++i)
1074 swap(cell(i), cell(i + ncols()));
1081 // undo effect of Ctrl-Tab (i.e. pull next cell)
1082 //if (idx + 1 != nargs())
1083 // cell(idx).swap(cell(idx + 1));
1085 // we handled the event..
1090 // reimplement old behaviour when pressing Delete in the last position
1092 void InsetMathGrid::idxGlue(idx_type idx)
1094 col_type c = col(idx);
1095 if (c + 1 == ncols()) {
1096 if (row(idx) + 1 != nrows()) {
1097 for (col_type cc = 0; cc < ncols(); ++cc)
1098 cell(idx).append(cell(idx + cc + 1));
1099 delRow(row(idx) + 1);
1102 idx_type idx_next = idx + 1;
1103 while (idx_next < nargs() &&
1104 cellinfo_[idx_next].multi_ == CELL_PART_OF_MULTICOLUMN)
1106 if (idx_next < nargs())
1107 cell(idx).append(cell(idx_next));
1108 col_type oldcol = c + 1;
1109 for (col_type cc = c + 2; cc < ncols(); ++cc)
1110 cell(idx - oldcol + cc) = cell(idx - oldcol + 1 + cc);
1111 cell(idx - c + ncols() - 1).clear();
1116 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
1118 return rowinfo_[row];
1122 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
1124 return rowinfo_[row];
1128 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
1130 row_type const ri = row(idx);
1131 row_type const r1 = min(row(from), row(to));
1132 row_type const r2 = max(row(from), row(to));
1133 col_type const ci = col(idx);
1134 col_type const c1 = min(col(from), col(to));
1135 col_type const c2 = max(col(from), col(to));
1136 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
1140 void InsetMathGrid::normalize(NormalStream & os) const
1143 for (row_type row = 0; row < nrows(); ++row) {
1145 for (col_type col = 0; col < ncols(); ++col) {
1146 idx_type const i = index(row, col);
1147 switch (cellinfo_[i].multi_) {
1149 os << "[cell " << cell(i) << ']';
1151 case CELL_BEGIN_OF_MULTICOLUMN:
1152 os << "[cell colspan="
1153 << static_cast<int>(ncellcols(i)) << ' '
1156 case CELL_PART_OF_MULTICOLUMN:
1166 void InsetMathGrid::mathmlize(MathStream & os) const
1168 bool const havetable = nrows() > 1 || ncols() > 1;
1170 os << MTag("mtable");
1171 char const * const celltag = havetable ? "mtd" : "mrow";
1172 for (row_type row = 0; row < nrows(); ++row) {
1175 for (col_type col = 0; col < ncols(); ++col) {
1176 idx_type const i = index(row, col);
1177 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1178 col_type const cellcols = ncellcols(i);
1180 if (havetable && cellcols > 1)
1181 attr << "colspan='" << cellcols << '\'';
1182 os << MTag(celltag, attr.str());
1183 os << cell(index(row, col));
1184 os << ETag(celltag);
1191 os << ETag("mtable");
1196 // We need to do something about alignment here.
1197 void InsetMathGrid::htmlize(HtmlStream & os, string attrib) const
1199 bool const havetable = nrows() > 1 || ncols() > 1;
1201 os << cell(index(0, 0));
1204 os << MTag("table", attrib);
1205 for (row_type row = 0; row < nrows(); ++row) {
1207 for (col_type col = 0; col < ncols(); ++col) {
1208 idx_type const i = index(row, col);
1209 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1210 col_type const cellcols = ncellcols(i);
1213 attr << "colspan='" << cellcols << '\'';
1214 os << MTag("td", attr.str());
1215 os << cell(index(row, col));
1221 os << ETag("table");
1225 void InsetMathGrid::htmlize(HtmlStream & os) const
1227 htmlize(os, "class='mathtable'");
1231 void InsetMathGrid::validate(LaTeXFeatures & features) const
1233 if (features.runparams().math_flavor == OutputParams::MathAsHTML
1234 && (nrows() > 1 || ncols() > 1)) {
1235 // CSS taken from InsetMathCases
1236 features.addCSSSnippet(
1237 "table.mathtable{display: inline-block; text-align: center; border: none;"
1238 "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
1239 "table.mathtable td {text-align: left; border: none;}");
1241 InsetMathNest::validate(features);
1245 void InsetMathGrid::write(WriteStream & os) const
1247 write(os, 0, 0, nrows(), ncols());
1250 void InsetMathGrid::write(WriteStream & os,
1251 row_type beg_row, col_type beg_col,
1252 row_type end_row, col_type end_col) const
1254 MathEnsurer ensurer(os, false);
1256 for (row_type row = beg_row; row < end_row; ++row) {
1257 os << verboseHLine(rowinfo_[row].lines_);
1258 // don't write & and empty cells at end of line,
1259 // unless there are vertical lines
1260 col_type lastcol = 0;
1261 bool emptyline = true;
1262 bool last_eoln = true;
1263 for (col_type col = beg_col; col < end_col; ++col) {
1264 idx_type const idx = index(row, col);
1265 bool const empty_cell = cell(idx).empty();
1266 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL)
1268 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL ||
1269 colinfo_[col + 1].lines_) {
1274 for (col_type col = beg_col; col < end_col;) {
1276 idx_type const idx = index(row, col);
1277 TexRow::RowEntry entry = TexRow::mathEntry(id(),idx);
1278 os.texrow().start(entry);
1279 if (col >= lastcol) {
1283 Changer dummy = os.changeRowEntry(entry);
1284 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1286 while (s < ncols() &&
1287 cellinfo_[index(row, s)].multi_ == CELL_PART_OF_MULTICOLUMN)
1290 os << "\\multicolumn{" << nccols
1291 << "}{" << cellinfo_[idx].align_
1295 if (os.pendingBrace())
1296 ModeSpecifier specifier(os, TEXT_MODE);
1297 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1299 os << eocString(col + nccols - 1, lastcol);
1302 eol = eolString(row, os.fragile(), os.latex(), last_eoln);
1304 // append newline only if line wasn't completely empty
1305 // and the formula is not written on a single line
1306 bool const empty = emptyline && eol.empty();
1307 if (!empty && nrows() > 1)
1310 // @TODO use end_row instead of nrows() ?
1311 docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
1323 int InsetMathGrid::colsep() const
1329 int InsetMathGrid::rowsep() const
1335 int InsetMathGrid::hlinesep() const
1341 int InsetMathGrid::vlinesep() const
1347 int InsetMathGrid::border() const
1353 void InsetMathGrid::splitCell(Cursor & cur)
1355 if (cur.idx() == cur.lastidx())
1357 MathData ar = cur.cell();
1358 ar.erase(0, cur.pos());
1359 cur.cell().erase(cur.pos(), cur.lastpos());
1361 while (cur.idx() << nargs() &&
1362 cellinfo_[cur.idx()].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1365 cur.cell().insert(0, ar);
1369 char InsetMathGrid::displayColAlign(idx_type idx) const
1371 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1372 // align_ may also contain lines like "||r|", so this is
1373 // not complete, but we catch at least the simple cases.
1374 if (cellinfo_[idx].align_ == "c")
1376 if (cellinfo_[idx].align_ == "l")
1378 if (cellinfo_[idx].align_ == "r")
1381 return colinfo_[col(idx)].align_;
1385 int InsetMathGrid::displayColSpace(col_type col) const
1387 return colinfo_[col].skip_;
1390 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1392 //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1394 Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
1396 FuncCode const act = cmd.action();
1399 // insert file functions
1400 case LFUN_LINE_DELETE_FORWARD:
1401 cur.recordUndoInset();
1402 //autocorrect_ = false;
1410 if (cur.idx() > cur.lastidx())
1411 cur.idx() = cur.lastidx();
1412 if (cur.pos() > cur.lastpos())
1413 cur.pos() = cur.lastpos();
1416 case LFUN_CELL_SPLIT:
1421 case LFUN_CELL_BACKWARD:
1423 cur.selection(false);
1424 if (!idxPrev(cur)) {
1425 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1430 case LFUN_CELL_FORWARD:
1431 // Can't handle selection by additional 'shift' as this is
1432 // hard bound to LFUN_CELL_BACKWARD
1433 cur.selection(false);
1434 if (!idxNext(cur)) {
1435 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1440 case LFUN_NEWLINE_INSERT: {
1441 cur.recordUndoInset();
1442 row_type const r = cur.row();
1446 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1447 swap(cell(index(r, c)), cell(index(r + 1, c)));
1452 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1455 cur.pos() = cur.lastpos();
1456 cur.forceBufferUpdate();
1457 //mathcursor->normalize();
1458 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1462 case LFUN_TABULAR_FEATURE: {
1463 cur.recordUndoInset();
1464 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1465 istringstream is(to_utf8(cmd.argument()));
1468 if (s == "valign-top")
1469 setVerticalAlignment('t');
1470 else if (s == "valign-middle")
1471 setVerticalAlignment('c');
1472 else if (s == "valign-bottom")
1473 setVerticalAlignment('b');
1474 else if (s == "align-left")
1475 setHorizontalAlignment('l', cur.col());
1476 else if (s == "align-right")
1477 setHorizontalAlignment('r', cur.col());
1478 else if (s == "align-center")
1479 setHorizontalAlignment('c', cur.col());
1480 else if (s == "append-row")
1481 for (int i = 0, n = extractInt(is); i < n; ++i)
1483 else if (s == "delete-row") {
1484 cur.clearSelection(); // bug 4323
1485 for (int i = 0, n = extractInt(is); i < n; ++i) {
1487 if (cur.idx() >= nargs())
1488 cur.idx() -= ncols();
1490 cur.pos() = 0; // trick, see below
1492 else if (s == "copy-row") {
1493 // Here (as later) we save the cursor col/row
1494 // in order to restore it after operation.
1495 row_type const r = cur.row();
1496 col_type const c = cur.col();
1497 for (int i = 0, n = extractInt(is); i < n; ++i)
1499 cur.idx() = index(r, c);
1501 else if (s == "swap-row") {
1503 // Trick to suppress same-idx-means-different-cell
1507 else if (s == "add-hline-above")
1508 rowinfo_[cur.row()].lines_++;
1509 else if (s == "add-hline-below")
1510 rowinfo_[cur.row()+1].lines_++;
1511 else if (s == "delete-hline-above")
1512 rowinfo_[cur.row()].lines_--;
1513 else if (s == "delete-hline-below")
1514 rowinfo_[cur.row()+1].lines_--;
1515 else if (s == "append-column") {
1516 row_type const r = cur.row();
1517 col_type const c = cur.col();
1518 for (int i = 0, n = extractInt(is); i < n; ++i)
1519 addCol(cur.col() + 1);
1520 cur.idx() = index(r, c);
1522 else if (s == "delete-column") {
1523 cur.clearSelection(); // bug 4323
1524 row_type const r = cur.row();
1525 col_type const c = cur.col();
1526 for (int i = 0, n = extractInt(is); i < n; ++i)
1527 delCol(col(cur.idx()));
1528 cur.idx() = index(r, min(c, cur.ncols() - 1));
1529 cur.pos() = 0; // trick, see above
1531 else if (s == "copy-column") {
1532 row_type const r = cur.row();
1533 col_type const c = cur.col();
1535 cur.idx() = index(r, c);
1537 else if (s == "swap-column") {
1539 cur.pos() = 0; // trick, see above
1541 else if (s == "add-vline-left") {
1542 colinfo_[cur.col()].lines_++;
1543 if (!colinfo_[cur.col()].special_.empty())
1544 colinfo_[cur.col()].special_ += '|';
1546 else if (s == "add-vline-right") {
1547 colinfo_[cur.col()+1].lines_++;
1548 if (!colinfo_[cur.col()+1].special_.empty())
1549 colinfo_[cur.col()+1].special_.insert(0, 1, '|');
1551 else if (s == "delete-vline-left") {
1552 colinfo_[cur.col()].lines_--;
1553 docstring & special = colinfo_[cur.col()].special_;
1554 if (!special.empty()) {
1555 docstring::size_type i = special.rfind('|');
1556 LASSERT(i != docstring::npos, break);
1557 special.erase(i, 1);
1560 else if (s == "delete-vline-right") {
1561 colinfo_[cur.col()+1].lines_--;
1562 docstring & special = colinfo_[cur.col()+1].special_;
1563 if (!special.empty()) {
1564 docstring::size_type i = special.find('|');
1565 LASSERT(i != docstring::npos, break);
1566 special.erase(i, 1);
1573 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1574 //lyxerr << "returning FINISHED_LEFT" << endl;
1578 case LFUN_CLIPBOARD_PASTE:
1579 parseflg |= Parse::VERBATIM;
1582 if (cur.currentMode() != MATH_MODE)
1583 parseflg |= Parse::TEXTMODE;
1584 cur.message(_("Paste"));
1585 cap::replaceSelection(cur);
1587 if (cmd.argument().empty() && !theClipboard().isInternal())
1588 topaste = theClipboard().getAsText(frontend::Clipboard::PlainTextType);
1590 idocstringstream is(cmd.argument());
1593 topaste = cap::selection(n, buffer().params().documentClassPtr());
1595 InsetMathGrid grid(buffer_, 1, 1);
1596 if (!topaste.empty())
1597 if ((topaste.size() == 1 && isAscii(topaste))
1598 || !mathed_parse_normal(grid, topaste, parseflg)) {
1600 mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
1603 bool hline_enabled = false;
1604 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
1606 if (getStatus(cur, fr, status))
1607 hline_enabled = status.enabled();
1608 if (grid.nargs() == 1) {
1609 // single cell/part of cell
1610 cur.recordUndoInset();
1611 cur.cell().insert(cur.pos(), grid.cell(0));
1612 cur.pos() += grid.cell(0).size();
1614 rowinfo_[cur.row()].lines_ += grid.rowinfo_[0].lines_;
1616 for (unsigned int l = 0; l < grid.rowinfo_[0].lines_; ++l) {
1617 cur.cell().insert(0,
1618 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1624 cur.recordUndoInset();
1625 col_type const numcols =
1626 min(grid.ncols(), ncols() - col(cur.idx()));
1627 row_type const numrows =
1628 min(grid.nrows(), nrows() - cur.row());
1629 for (row_type r = 0; r < numrows; ++r) {
1630 for (col_type c = 0; c < numcols; ++c) {
1631 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1632 cell(i).insert(0, grid.cell(grid.index(r, c)));
1635 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1637 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1638 idx_type i = index(r + cur.row(), 0);
1640 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1643 // append the left over horizontal cells to the last column
1644 idx_type i = index(r + cur.row(), ncols() - 1);
1645 for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
1646 cell(i).append(grid.cell(grid.index(r, c)));
1648 // append the left over vertical cells to the last _cell_
1649 idx_type i = nargs() - 1;
1650 for (row_type r = numrows; r < grid.nrows(); ++r) {
1651 for (col_type c = 0; c < grid.ncols(); ++c)
1652 cell(i).append(grid.cell(grid.index(r, c)));
1654 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1656 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1658 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1663 cur.clearSelection(); // bug 393
1664 // FIXME audit setBuffer calls
1665 cur.inset().setBuffer(*buffer_);
1666 cur.forceBufferUpdate();
1671 case LFUN_LINE_BEGIN:
1672 case LFUN_WORD_BACKWARD:
1673 case LFUN_WORD_LEFT:
1674 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1676 case LFUN_LINE_BEGIN_SELECT:
1677 case LFUN_WORD_BACKWARD_SELECT:
1678 case LFUN_WORD_LEFT_SELECT:
1679 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1680 act == LFUN_WORD_LEFT_SELECT ||
1681 act == LFUN_LINE_BEGIN_SELECT);
1682 cur.macroModeClose();
1683 if (cur.pos() != 0) {
1685 } else if (cur.idx() % cur.ncols() != 0) {
1686 cur.idx() -= cur.idx() % cur.ncols();
1688 } else if (cur.idx() != 0) {
1692 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1697 case LFUN_WORD_FORWARD:
1698 case LFUN_WORD_RIGHT:
1700 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1702 case LFUN_WORD_FORWARD_SELECT:
1703 case LFUN_WORD_RIGHT_SELECT:
1704 case LFUN_LINE_END_SELECT:
1705 cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
1706 act == LFUN_WORD_RIGHT_SELECT ||
1707 act == LFUN_LINE_END_SELECT);
1708 cur.macroModeClose();
1710 if (cur.pos() != cur.lastpos()) {
1711 cur.pos() = cur.lastpos();
1712 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1713 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1714 cur.pos() = cur.lastpos();
1715 } else if (cur.idx() != cur.lastidx()) {
1716 cur.idx() = cur.lastidx();
1717 cur.pos() = cur.lastpos();
1719 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1725 InsetMathNest::doDispatch(cur, cmd);
1730 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1731 FuncStatus & status) const
1733 switch (cmd.action()) {
1734 case LFUN_TABULAR_FEATURE: {
1735 string s = cmd.getArg(0);
1736 if (&cur.inset() != this) {
1737 // Table actions requires that the cursor is _inside_ the
1739 status.setEnabled(false);
1740 status.message(from_utf8(N_("Cursor not in table")));
1743 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1744 status.setEnabled(false);
1745 status.message(from_utf8(N_("Only one row")));
1749 (s == "delete-column" || s == "swap-column")) {
1750 status.setEnabled(false);
1751 status.message(from_utf8(N_("Only one column")));
1754 if ((rowinfo_[cur.row()].lines_ == 0 &&
1755 s == "delete-hline-above") ||
1756 (rowinfo_[cur.row() + 1].lines_ == 0 &&
1757 s == "delete-hline-below")) {
1758 status.setEnabled(false);
1759 status.message(from_utf8(N_("No hline to delete")));
1763 if ((colinfo_[cur.col()].lines_ == 0 &&
1764 s == "delete-vline-left") ||
1765 (colinfo_[cur.col() + 1].lines_ == 0 &&
1766 s == "delete-vline-right")) {
1767 status.setEnabled(false);
1768 status.message(from_utf8(N_("No vline to delete")));
1771 if (s == "valign-top" || s == "valign-middle" ||
1772 s == "valign-bottom" || s == "align-left" ||
1773 s == "align-right" || s == "align-center") {
1774 status.setEnabled(true);
1775 char const ha = horizontalAlignment(cur.col());
1776 char const va = verticalAlignment();
1777 status.setOnOff((s == "align-left" && ha == 'l')
1778 || (s == "align-right" && ha == 'r')
1779 || (s == "align-center" && ha == 'c')
1780 || (s == "valign-top" && va == 't')
1781 || (s == "valign-bottom" && va == 'b')
1782 || (s == "valign-middle" && va == 'c'));
1785 if (s == "append-row" || s == "delete-row" ||
1786 s == "copy-row" || s == "swap-row" ||
1787 s == "add-hline-above" || s == "add-hline-below" ||
1788 s == "delete-hline-above" || s == "delete-hline-below" ||
1789 s == "append-column" || s == "delete-column" ||
1790 s == "copy-column" || s == "swap-column" ||
1791 s == "add-vline-left" || s == "add-vline-right" ||
1792 s == "delete-vline-left" || s == "delete-vline-right") {
1793 status.setEnabled(true);
1795 status.setEnabled(false);
1796 status.message(bformat(
1797 from_utf8(N_("Unknown tabular feature '%1$s'")),
1802 // FIXME: What did this code do?
1803 // Please check whether it is still needed!
1804 // should be more precise
1805 if (v_align_ == '\0') {
1806 status.enable(true);
1809 if (cmd.argument().empty()) {
1810 status.enable(false);
1813 if (!contains("tcb", cmd.argument()[0])) {
1814 status.enable(false);
1817 status.setOnOff(cmd.argument()[0] == v_align_);
1818 status.setEnabled(true);
1823 case LFUN_CELL_SPLIT:
1824 status.setEnabled(cur.idx() != cur.lastidx());
1827 case LFUN_CELL_BACKWARD:
1828 case LFUN_CELL_FORWARD:
1829 status.setEnabled(true);
1835 return InsetMathNest::getStatus(cur, cmd, status);
1840 char InsetMathGrid::colAlign(HullType type, col_type col)
1844 return "rcl"[col % 3];
1855 return "rl"[col & 1];
1870 int InsetMathGrid::colSpace(HullType type, col_type col)
1872 int alignInterSpace = 0;
1887 alignInterSpace = 20;
1890 alignInterSpace = 0;
1893 alignInterSpace = 40;
1897 alignInterSpace = 60;
1900 return (col % 2) ? alignInterSpace : 0;