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_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
422 rowinfo_[nrows()].ascent_ = 0;
423 rowinfo_[nrows()].descent_ = 0;
425 // compute vertical offsets
426 rowinfo_[0].offset_ = 0;
427 for (row_type row = 1; row <= nrows(); ++row) {
428 rowinfo_[row].offset_ =
429 rowinfo_[row - 1].offset_ +
430 rowinfo_[row - 1].descent_ +
431 rowinfo_[row - 1].skipPixels(mi) +
433 rowinfo_[row].lines_ * hlinesep() +
434 rowinfo_[row].ascent_;
437 // adjust vertical offset
444 h = rowinfo_[nrows() - 1].offset_;
447 h = rowinfo_[nrows() - 1].offset_ / 2;
449 for (row_type row = 0; row <= nrows(); ++row)
450 rowinfo_[row].offset_ -= h;
453 // multicolumn cell widths, as a map from first column to width in a
454 // vector of last columns.
455 // This is only used if the grid has more than one row, since for
456 // one-row grids multicolumn cells do not need special handling
457 vector<map<col_type, int> > mcolwidths(ncols());
459 // compute absolute sizes of horizontal structure
460 for (col_type col = 0; col < ncols(); ++col) {
462 for (row_type row = 0; row < nrows(); ++row) {
463 idx_type const i = index(row, col);
464 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
465 int const w = cell(i).dimension(bv).wid;
466 col_type const cols = ncellcols(i);
467 if (cols > 1 && nrows() > 1) {
468 col_type last = col+cols-1;
469 LASSERT(last < ncols(), last = ncols()-1);
470 map<col_type, int>::iterator it =
471 mcolwidths[last].find(col);
472 if (it == mcolwidths[last].end())
473 mcolwidths[last][col] = w;
475 it->second = max(it->second, w);
480 colinfo_[col].width_ = wid;
482 colinfo_[ncols()].width_ = 0;
484 // compute horizontal offsets
485 colinfo_[0].offset_ = border();
486 for (col_type col = 1; col <= ncols(); ++col) {
487 colinfo_[col].offset_ =
488 colinfo_[col - 1].offset_ +
489 colinfo_[col - 1].width_ +
490 displayColSpace(col - 1) +
492 colinfo_[col].lines_ * vlinesep();
495 // increase column widths for multicolumn cells if needed
496 // FIXME: multicolumn lines are not yet considered
497 for (col_type last = 0; last < ncols(); ++last) {
498 map<col_type, int> const & widths = mcolwidths[last];
499 // We increase the width of the last column of the multicol
500 // cell (some sort of left alignment). Since we iterate through
501 // the last and the first columns from left to right, we ensure
502 // that increased widths of previous columns are correctly
503 // taken into account for later columns, thus preventing
504 // unneeded width increasing.
505 for (map<col_type, int>::const_iterator it = widths.begin();
506 it != widths.end(); ++it) {
507 int const wid = it->second;
508 col_type const first = it->first;
509 int const nextoffset =
510 colinfo_[first].offset_ +
512 displayColSpace(last) +
514 colinfo_[last+1].lines_ * vlinesep();
515 int const dx = nextoffset - colinfo_[last+1].offset_;
517 colinfo_[last].width_ += dx;
518 for (col_type col = last + 1; col <= ncols(); ++col)
519 colinfo_[col].offset_ += dx;
525 dim.wid = colinfo_[ncols() - 1].offset_
526 + colinfo_[ncols() - 1].width_
527 + vlinesep() * colinfo_[ncols()].lines_
530 dim.asc = - rowinfo_[0].offset_
531 + rowinfo_[0].ascent_
532 + hlinesep() * rowinfo_[0].lines_
535 dim.des = rowinfo_[nrows() - 1].offset_
536 + rowinfo_[nrows() - 1].descent_
537 + hlinesep() * rowinfo_[nrows()].lines_
542 // Increase ws_[i] for 'R' columns (except the first one)
543 for (int i = 1; i < nc_; ++i)
544 if (align_[i] == 'R')
545 ws_[i] += 10 * df_width;
546 // Increase ws_[i] for 'C' column
547 if (align_[0] == 'C')
548 if (ws_[0] < 7 * workwidth / 8)
549 ws_[0] = 7 * workwidth / 8;
553 for (cxrow = row_.begin(); cxrow; ++cxrow) {
556 for (int i = 0; i < nc_; ++i) {
558 if (cxrow->getTab(i) <= 0) {
559 cxrow->setTab(i, df_width);
567 lf = (ws_[i] - cxrow->getTab(i))/2;
571 lf = ws_[i] - cxrow->getTab(i);
574 if (cxrow == row_.begin())
576 else if (cxrow.is_last())
577 lf = ws_[i] - cxrow->getTab(i);
579 lf = (ws_[i] - cxrow->getTab(i))/2;
582 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
583 cxrow->setTab(i, lf + rg);
584 rg = ws_[i] - ww + colsep();
585 if (cxrow == row_.begin())
586 width += ws_[i] + colsep();
588 cxrow->setBaseline(cxrow->getBaseline() - ascent);
591 metricsMarkers2(dim);
592 // Cache the inset dimension.
593 setDimCache(mi, dim);
597 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
599 drawWithMargin(pi, x, y, 1, 1);
603 void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
604 int lmargin, int rmargin) const
606 Dimension const dim = dimension(*pi.base.bv);
607 BufferView const & bv = *pi.base.bv;
609 for (idx_type idx = 0; idx < nargs(); ++idx) {
610 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN) {
612 x + lmargin + cellXOffset(bv, idx),
613 y + cellYOffset(idx));
615 // draw inner lines cell by cell because of possible multicolumns
616 // FIXME: multicolumn lines are not yet considered
617 row_type const r = row(idx);
618 col_type const c = col(idx);
619 if (r > 0 && r < nrows()) {
620 for (unsigned int i = 0; i < rowinfo_[r].lines_; ++i) {
621 int const yy = y + rowinfo_[r].offset_
622 - rowinfo_[r].ascent_
624 - hlinesep()/2 - rowsep()/2;
626 x + lmargin + colinfo_[c].offset_,
628 x + lmargin + colinfo_[c+1].offset_,
629 yy, Color_foreground);
632 if (c > 0 && c < ncols()) {
633 for (unsigned int i = 0; i < colinfo_[c].lines_; ++i) {
634 int const xx = x + lmargin
635 + colinfo_[c].offset_
637 - vlinesep()/2 - colsep()/2;
639 // prevRowHasLine needs to be changed if multicolumn lines are supported
640 bool const prevRowHasLine(r > 0);
642 // start from offset of previous row to create a continous line
643 top_offset = rowinfo_[r - 1].offset_ + rowinfo_[r - 1].descent_;
645 top_offset = rowinfo_[r].offset_- rowinfo_[r].ascent_;
646 pi.pain.line(xx, y + top_offset,
647 xx, y + rowinfo_[r].offset_ + rowinfo_[r].descent_,
654 // draw outer lines in one go
655 for (row_type row = 0; row <= nrows(); row += nrows())
656 for (unsigned int i = 0; i < rowinfo_[row].lines_; ++i) {
657 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
658 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
659 pi.pain.line(x + lmargin + 1, yy,
660 x + dim.width() - rmargin - 1, yy,
664 for (col_type col = 0; col <= ncols(); col += ncols())
665 for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
666 int xx = x + lmargin + colinfo_[col].offset_
667 - i * vlinesep() - vlinesep()/2 - colsep()/2;
668 pi.pain.line(xx, y - dim.ascent() + 1,
669 xx, y + dim.descent() - 1,
672 drawMarkers2(pi, x, y);
676 void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
678 // let the cells adjust themselves
679 for (idx_type i = 0; i < nargs(); ++i)
680 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
681 cell(i).metricsT(mi, dim);
683 // compute absolute sizes of vertical structure
684 for (row_type row = 0; row < nrows(); ++row) {
687 for (col_type col = 0; col < ncols(); ++col) {
688 idx_type const i = index(row, col);
689 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
690 //MathData const & c = cell(i);
693 asc = max(asc, dimc.ascent());
694 desc = max(desc, dimc.descent());
697 rowinfo_[row].ascent_ = asc;
698 rowinfo_[row].descent_ = desc;
700 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
701 rowinfo_[nrows()].ascent_ = 0;
702 rowinfo_[nrows()].descent_ = 0;
704 // compute vertical offsets
705 rowinfo_[0].offset_ = 0;
706 for (row_type row = 1; row <= nrows(); ++row) {
707 rowinfo_[row].offset_ =
708 rowinfo_[row - 1].offset_ +
709 rowinfo_[row - 1].descent_ +
710 //rowinfo_[row - 1].skipPixels(mi) +
712 //rowinfo_[row].lines_ * hlinesep() +
713 rowinfo_[row].ascent_;
716 // adjust vertical offset
723 h = rowinfo_[nrows() - 1].offset_;
726 h = rowinfo_[nrows() - 1].offset_ / 2;
728 for (row_type row = 0; row <= nrows(); ++row)
729 rowinfo_[row].offset_ -= h;
732 // compute absolute sizes of horizontal structure
733 for (col_type col = 0; col < ncols(); ++col) {
735 for (row_type row = 0; row < nrows(); ++row) {
737 //idx_type const i = index(row, col);
738 //if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
739 // wid = max(wid, cell(i).width());
741 colinfo_[col].width_ = wid;
743 colinfo_[ncols()].width_ = 0;
745 // compute horizontal offsets
746 colinfo_[0].offset_ = border();
747 for (col_type col = 1; col <= ncols(); ++col) {
748 colinfo_[col].offset_ =
749 colinfo_[col - 1].offset_ +
750 colinfo_[col - 1].width_ +
751 displayColSpace(col - 1) +
753 //colinfo_[col].lines_ * vlinesep();
757 dim.wid = colinfo_[ncols() - 1].offset_
758 + colinfo_[ncols() - 1].width_
759 //+ vlinesep() * colinfo_[ncols()].lines_
762 dim.asc = -rowinfo_[0].offset_
763 + rowinfo_[0].ascent_
764 //+ hlinesep() * rowinfo_[0].lines_
767 dim.des = rowinfo_[nrows() - 1].offset_
768 + rowinfo_[nrows() - 1].descent_
769 //+ hlinesep() * rowinfo_[nrows()].lines_
774 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
776 // for (idx_type idx = 0; idx < nargs(); ++idx)
777 // if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
778 // cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
782 void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype)
785 for (idx_type idx = 0; idx < nargs(); ++idx)
786 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
787 cell(idx).updateBuffer(it, utype);
791 docstring InsetMathGrid::eolString(row_type row, bool fragile,
792 bool /*latex*/, bool last_eoln) const
796 if (!rowinfo_[row].crskip_.zero())
797 eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
798 else if(!rowinfo_[row].allow_newpage_)
801 // make sure an upcoming '[' does not break anything
802 if (row + 1 < nrows()) {
803 MathData const & c = cell(index(row + 1, 0));
804 if (!c.empty() && c.front()->getChar() == '[')
809 // only add \\ if necessary
810 if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
813 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
817 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
819 if (col + 1 == lastcol)
821 return from_ascii(" & ");
825 void InsetMathGrid::addRow(row_type row)
827 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
829 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData());
831 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
835 void InsetMathGrid::delRow(row_type row)
840 cells_type::iterator it = cells_.begin() + row * ncols();
841 cells_.erase(it, it + ncols());
843 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
844 cellinfo_.erase(jt, jt + ncols());
846 rowinfo_.erase(rowinfo_.begin() + row);
850 void InsetMathGrid::copyRow(row_type row)
853 for (col_type col = 0; col < ncols(); ++col)
854 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
858 void InsetMathGrid::swapRow(row_type row)
862 if (row + 1 == nrows())
864 for (col_type col = 0; col < ncols(); ++col)
865 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
869 void InsetMathGrid::addCol(col_type newcol)
871 const col_type nc = ncols();
872 const row_type nr = nrows();
873 cells_type new_cells((nc + 1) * nr);
874 vector<CellInfo> new_cellinfo((nc + 1) * nr);
876 for (row_type row = 0; row < nr; ++row)
877 for (col_type col = 0; col < nc; ++col) {
878 new_cells[row * (nc + 1) + col + (col >= newcol)]
879 = cells_[row * nc + col];
880 new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
881 = cellinfo_[row * nc + col];
883 swap(cells_, new_cells);
884 swap(cellinfo_, new_cellinfo);
887 inf.skip_ = defaultColSpace(newcol);
888 inf.align_ = defaultColAlign(newcol);
889 colinfo_.insert(colinfo_.begin() + newcol, inf);
893 void InsetMathGrid::delCol(col_type col)
899 vector<CellInfo> tmpcellinfo;
900 for (col_type i = 0; i < nargs(); ++i)
901 if (i % ncols() != col) {
902 tmpcells.push_back(cells_[i]);
903 tmpcellinfo.push_back(cellinfo_[i]);
905 swap(cells_, tmpcells);
906 swap(cellinfo_, tmpcellinfo);
908 colinfo_.erase(colinfo_.begin() + col);
912 void InsetMathGrid::copyCol(col_type col)
915 for (row_type row = 0; row < nrows(); ++row)
916 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
920 void InsetMathGrid::swapCol(col_type col)
924 if (col + 1 == ncols())
926 for (row_type row = 0; row < nrows(); ++row)
927 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
931 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
933 if (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN)
935 col_type c = col(idx);
936 int x = colinfo_[c].offset_;
937 char align = displayColAlign(idx);
938 Dimension const & celldim = cell(idx).dimension(bv);
939 if (align == 'r' || align == 'R')
940 x += cellWidth(idx) - celldim.wid;
941 if (align == 'c' || align == 'C')
942 x += (cellWidth(idx) - celldim.wid) / 2;
947 int InsetMathGrid::cellYOffset(idx_type idx) const
949 return rowinfo_[row(idx)].offset_;
953 int InsetMathGrid::cellWidth(idx_type idx) const
955 switch (cellinfo_[idx].multi_) {
957 return colinfo_[col(idx)].width_;
958 case CELL_BEGIN_OF_MULTICOLUMN: {
959 col_type c1 = col(idx);
960 col_type c2 = c1 + ncellcols(idx);
961 return colinfo_[c2].offset_
962 - colinfo_[c1].offset_
963 - displayColSpace(c2)
965 - colinfo_[c2].lines_ * vlinesep();
967 case CELL_PART_OF_MULTICOLUMN:
974 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
979 cur.idx() -= ncols();
981 if (cur.row() + 1 >= nrows())
983 cur.idx() += ncols();
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.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
995 bool InsetMathGrid::idxBackward(Cursor & cur) const
997 // leave matrix if at the front edge
1001 // If we are in a multicolumn cell, move to the "real" cell
1002 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1003 LASSERT(cur.idx() > 0, return false);
1006 cur.pos() = cur.lastpos();
1011 bool InsetMathGrid::idxForward(Cursor & cur) const
1013 // leave matrix if at the back edge
1014 if (cur.col() + 1 == ncols())
1017 // If we are in a multicolumn cell, move to the next cell
1018 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1019 // leave matrix if at the back edge
1020 if (cur.col() + 1 == ncols())
1029 bool InsetMathGrid::idxFirst(Cursor & cur) const
1036 cur.idx() = (nrows() - 1) * ncols();
1039 cur.idx() = ((nrows() - 1) / 2) * ncols();
1041 // If we are in a multicolumn cell, move to the "real" cell
1042 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1043 LASSERT(cur.idx() > 0, return false);
1051 bool InsetMathGrid::idxLast(Cursor & cur) const
1055 cur.idx() = ncols() - 1;
1058 cur.idx() = nargs() - 1;
1061 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
1063 // If we are in a multicolumn cell, move to the "real" cell
1064 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1065 LASSERT(cur.idx() > 0, return false);
1068 cur.pos() = cur.lastpos();
1073 bool InsetMathGrid::idxDelete(idx_type & idx)
1075 // nothing to do if we have just one row
1079 // nothing to do if we are in the middle of the last row of the inset
1080 if (idx + ncols() > nargs())
1083 // try to delete entire sequence of ncols() empty cells if possible
1084 for (idx_type i = idx; i < idx + ncols(); ++i)
1085 if (!cell(i).empty())
1088 // move cells if necessary
1089 for (idx_type i = index(row(idx), 0); i < idx; ++i)
1090 swap(cell(i), cell(i + ncols()));
1097 // undo effect of Ctrl-Tab (i.e. pull next cell)
1098 //if (idx + 1 != nargs())
1099 // cell(idx).swap(cell(idx + 1));
1101 // we handled the event..
1106 // reimplement old behaviour when pressing Delete in the last position
1108 void InsetMathGrid::idxGlue(idx_type idx)
1110 col_type c = col(idx);
1111 if (c + 1 == ncols()) {
1112 if (row(idx) + 1 != nrows()) {
1113 for (col_type cc = 0; cc < ncols(); ++cc)
1114 cell(idx).append(cell(idx + cc + 1));
1115 delRow(row(idx) + 1);
1118 idx_type idx_next = idx + 1;
1119 while (idx_next < nargs() &&
1120 cellinfo_[idx_next].multi_ == CELL_PART_OF_MULTICOLUMN)
1122 if (idx_next < nargs())
1123 cell(idx).append(cell(idx_next));
1124 col_type oldcol = c + 1;
1125 for (col_type cc = c + 2; cc < ncols(); ++cc)
1126 cell(idx - oldcol + cc) = cell(idx - oldcol + 1 + cc);
1127 cell(idx - c + ncols() - 1).clear();
1132 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
1134 return rowinfo_[row];
1138 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
1140 return rowinfo_[row];
1144 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
1146 row_type const ri = row(idx);
1147 row_type const r1 = min(row(from), row(to));
1148 row_type const r2 = max(row(from), row(to));
1149 col_type const ci = col(idx);
1150 col_type const c1 = min(col(from), col(to));
1151 col_type const c2 = max(col(from), col(to));
1152 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
1156 void InsetMathGrid::normalize(NormalStream & os) const
1159 for (row_type row = 0; row < nrows(); ++row) {
1161 for (col_type col = 0; col < ncols(); ++col) {
1162 idx_type const i = index(row, col);
1163 switch (cellinfo_[i].multi_) {
1165 os << "[cell " << cell(i) << ']';
1167 case CELL_BEGIN_OF_MULTICOLUMN:
1168 os << "[cell colspan="
1169 << static_cast<int>(ncellcols(i)) << ' '
1172 case CELL_PART_OF_MULTICOLUMN:
1182 void InsetMathGrid::mathmlize(MathStream & os) const
1184 bool const havetable = nrows() > 1 || ncols() > 1;
1186 os << MTag("mtable");
1187 char const * const celltag = havetable ? "mtd" : "mrow";
1188 for (row_type row = 0; row < nrows(); ++row) {
1191 for (col_type col = 0; col < ncols(); ++col) {
1192 idx_type const i = index(row, col);
1193 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1194 col_type const cellcols = ncellcols(i);
1196 if (havetable && cellcols > 1)
1197 attr << "colspan='" << cellcols << '\'';
1198 os << MTag(celltag, attr.str());
1199 os << cell(index(row, col));
1200 os << ETag(celltag);
1207 os << ETag("mtable");
1212 // We need to do something about alignment here.
1213 void InsetMathGrid::htmlize(HtmlStream & os, string attrib) const
1215 bool const havetable = nrows() > 1 || ncols() > 1;
1217 os << cell(index(0, 0));
1220 os << MTag("table", attrib);
1221 for (row_type row = 0; row < nrows(); ++row) {
1223 for (col_type col = 0; col < ncols(); ++col) {
1224 idx_type const i = index(row, col);
1225 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1226 col_type const cellcols = ncellcols(i);
1229 attr << "colspan='" << cellcols << '\'';
1230 os << MTag("td", attr.str());
1231 os << cell(index(row, col));
1237 os << ETag("table");
1241 void InsetMathGrid::htmlize(HtmlStream & os) const
1243 htmlize(os, "class='mathtable'");
1247 void InsetMathGrid::validate(LaTeXFeatures & features) const
1249 if (features.runparams().math_flavor == OutputParams::MathAsHTML
1250 && (nrows() > 1 || ncols() > 1)) {
1251 // CSS taken from InsetMathCases
1252 features.addCSSSnippet(
1253 "table.mathtable{display: inline-block; text-align: center; border: none;"
1254 "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
1255 "table.mathtable td {text-align: left; border: none;}");
1257 InsetMathNest::validate(features);
1261 void InsetMathGrid::write(WriteStream & os) const
1263 write(os, 0, 0, nrows(), ncols());
1266 void InsetMathGrid::write(WriteStream & os,
1267 row_type beg_row, col_type beg_col,
1268 row_type end_row, col_type end_col) const
1270 MathEnsurer ensurer(os, false);
1272 for (row_type row = beg_row; row < end_row; ++row) {
1273 os << verboseHLine(rowinfo_[row].lines_);
1274 // don't write & and empty cells at end of line,
1275 // unless there are vertical lines
1276 col_type lastcol = 0;
1277 bool emptyline = true;
1278 bool last_eoln = true;
1279 for (col_type col = beg_col; col < end_col; ++col) {
1280 idx_type const idx = index(row, col);
1281 bool const empty_cell = cell(idx).empty();
1282 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL)
1284 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL ||
1285 colinfo_[col + 1].lines_) {
1290 for (col_type col = beg_col; col < end_col;) {
1292 idx_type const idx = index(row, col);
1293 RowEntry entry = TexRow::mathEntry(id(),idx);
1294 os.texrow().start(entry);
1295 if (col >= lastcol) {
1299 Changer dummy = os.changeRowEntry(entry);
1300 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1302 while (s < ncols() &&
1303 cellinfo_[index(row, s)].multi_ == CELL_PART_OF_MULTICOLUMN)
1306 os << "\\multicolumn{" << nccols
1307 << "}{" << cellinfo_[idx].align_
1311 if (os.pendingBrace())
1312 ModeSpecifier specifier(os, TEXT_MODE);
1313 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1315 os << eocString(col + nccols - 1, lastcol);
1318 eol = eolString(row, os.fragile(), os.latex(), last_eoln);
1320 // append newline only if line wasn't completely empty
1321 // and the formula is not written on a single line
1322 bool const empty = emptyline && eol.empty();
1323 if (!empty && nrows() > 1)
1326 // @TODO use end_row instead of nrows() ?
1327 docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
1339 int InsetMathGrid::colsep() const
1345 int InsetMathGrid::rowsep() const
1351 int InsetMathGrid::hlinesep() const
1357 int InsetMathGrid::vlinesep() const
1363 int InsetMathGrid::border() const
1369 void InsetMathGrid::splitCell(Cursor & cur)
1371 if (cur.idx() == cur.lastidx())
1373 MathData ar = cur.cell();
1374 ar.erase(0, cur.pos());
1375 cur.cell().erase(cur.pos(), cur.lastpos());
1377 while (cur.idx() << nargs() &&
1378 cellinfo_[cur.idx()].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1381 cur.cell().insert(0, ar);
1385 char InsetMathGrid::displayColAlign(idx_type idx) const
1387 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1388 // align_ may also contain lines like "||r|", so this is
1389 // not complete, but we catch at least the simple cases.
1390 if (cellinfo_[idx].align_ == "c")
1392 if (cellinfo_[idx].align_ == "l")
1394 if (cellinfo_[idx].align_ == "r")
1397 return colinfo_[col(idx)].align_;
1401 int InsetMathGrid::displayColSpace(col_type col) const
1403 return colinfo_[col].skip_;
1406 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1408 //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1410 Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
1412 FuncCode const act = cmd.action();
1415 // insert file functions
1416 case LFUN_LINE_DELETE_FORWARD:
1417 cur.recordUndoInset();
1418 //autocorrect_ = false;
1426 if (cur.idx() > cur.lastidx())
1427 cur.idx() = cur.lastidx();
1428 if (cur.pos() > cur.lastpos())
1429 cur.pos() = cur.lastpos();
1432 case LFUN_CELL_SPLIT:
1437 case LFUN_CELL_BACKWARD:
1439 cur.selection(false);
1440 if (!idxPrev(cur)) {
1441 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1446 case LFUN_CELL_FORWARD:
1447 // Can't handle selection by additional 'shift' as this is
1448 // hard bound to LFUN_CELL_BACKWARD
1449 cur.selection(false);
1450 if (!idxNext(cur)) {
1451 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1456 case LFUN_NEWLINE_INSERT: {
1457 cur.recordUndoInset();
1458 row_type const r = cur.row();
1462 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1463 swap(cell(index(r, c)), cell(index(r + 1, c)));
1468 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1471 cur.pos() = cur.lastpos();
1472 cur.forceBufferUpdate();
1473 //mathcursor->normalize();
1474 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1478 case LFUN_TABULAR_FEATURE: {
1479 cur.recordUndoInset();
1480 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1481 istringstream is(to_utf8(cmd.argument()));
1484 if (s == "valign-top")
1485 setVerticalAlignment('t');
1486 else if (s == "valign-middle")
1487 setVerticalAlignment('c');
1488 else if (s == "valign-bottom")
1489 setVerticalAlignment('b');
1490 else if (s == "align-left")
1491 setHorizontalAlignment('l', cur.col());
1492 else if (s == "align-right")
1493 setHorizontalAlignment('r', cur.col());
1494 else if (s == "align-center")
1495 setHorizontalAlignment('c', cur.col());
1496 else if (s == "append-row")
1497 for (int i = 0, n = extractInt(is); i < n; ++i)
1499 else if (s == "delete-row") {
1500 cur.clearSelection(); // bug 4323
1501 for (int i = 0, n = extractInt(is); i < n; ++i) {
1503 if (cur.idx() >= nargs())
1504 cur.idx() -= ncols();
1506 cur.pos() = 0; // trick, see below
1508 else if (s == "copy-row") {
1509 // Here (as later) we save the cursor col/row
1510 // in order to restore it after operation.
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)
1515 cur.idx() = index(r, c);
1517 else if (s == "swap-row") {
1519 // Trick to suppress same-idx-means-different-cell
1523 else if (s == "add-hline-above")
1524 rowinfo_[cur.row()].lines_++;
1525 else if (s == "add-hline-below")
1526 rowinfo_[cur.row()+1].lines_++;
1527 else if (s == "delete-hline-above")
1528 rowinfo_[cur.row()].lines_--;
1529 else if (s == "delete-hline-below")
1530 rowinfo_[cur.row()+1].lines_--;
1531 else if (s == "append-column") {
1532 row_type const r = cur.row();
1533 col_type const c = cur.col();
1534 for (int i = 0, n = extractInt(is); i < n; ++i)
1535 addCol(cur.col() + 1);
1536 cur.idx() = index(r, c);
1538 else if (s == "delete-column") {
1539 cur.clearSelection(); // bug 4323
1540 row_type const r = cur.row();
1541 col_type const c = cur.col();
1542 for (int i = 0, n = extractInt(is); i < n; ++i)
1543 delCol(col(cur.idx()));
1544 cur.idx() = index(r, min(c, cur.ncols() - 1));
1545 cur.pos() = 0; // trick, see above
1547 else if (s == "copy-column") {
1548 row_type const r = cur.row();
1549 col_type const c = cur.col();
1551 cur.idx() = index(r, c);
1553 else if (s == "swap-column") {
1555 cur.pos() = 0; // trick, see above
1557 else if (s == "add-vline-left") {
1558 colinfo_[cur.col()].lines_++;
1559 if (!colinfo_[cur.col()].special_.empty())
1560 colinfo_[cur.col()].special_ += '|';
1562 else if (s == "add-vline-right") {
1563 colinfo_[cur.col()+1].lines_++;
1564 if (!colinfo_[cur.col()+1].special_.empty())
1565 colinfo_[cur.col()+1].special_.insert(0, 1, '|');
1567 else if (s == "delete-vline-left") {
1568 colinfo_[cur.col()].lines_--;
1569 docstring & special = colinfo_[cur.col()].special_;
1570 if (!special.empty()) {
1571 docstring::size_type i = special.rfind('|');
1572 LASSERT(i != docstring::npos, break);
1573 special.erase(i, 1);
1576 else if (s == "delete-vline-right") {
1577 colinfo_[cur.col()+1].lines_--;
1578 docstring & special = colinfo_[cur.col()+1].special_;
1579 if (!special.empty()) {
1580 docstring::size_type i = special.find('|');
1581 LASSERT(i != docstring::npos, break);
1582 special.erase(i, 1);
1589 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1590 //lyxerr << "returning FINISHED_LEFT" << endl;
1594 case LFUN_CLIPBOARD_PASTE:
1595 parseflg |= Parse::VERBATIM;
1598 if (cur.currentMode() <= TEXT_MODE)
1599 parseflg |= Parse::TEXTMODE;
1600 cur.message(_("Paste"));
1601 cap::replaceSelection(cur);
1603 if (cmd.argument().empty() && !theClipboard().isInternal())
1604 topaste = theClipboard().getAsText(frontend::Clipboard::PlainTextType);
1606 idocstringstream is(cmd.argument());
1609 topaste = cap::selection(n, buffer().params().documentClassPtr());
1611 InsetMathGrid grid(buffer_, 1, 1);
1612 if (!topaste.empty())
1613 if ((topaste.size() == 1 && isAscii(topaste))
1614 || !mathed_parse_normal(grid, topaste, parseflg)) {
1616 mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
1619 bool hline_enabled = false;
1620 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
1622 if (getStatus(cur, fr, status))
1623 hline_enabled = status.enabled();
1624 if (grid.nargs() == 1) {
1625 // single cell/part of cell
1626 cur.recordUndoInset();
1627 cur.cell().insert(cur.pos(), grid.cell(0));
1628 cur.pos() += grid.cell(0).size();
1630 rowinfo_[cur.row()].lines_ += grid.rowinfo_[0].lines_;
1632 for (unsigned int l = 0; l < grid.rowinfo_[0].lines_; ++l) {
1633 cur.cell().insert(0,
1634 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1640 cur.recordUndoInset();
1641 col_type const numcols =
1642 min(grid.ncols(), ncols() - col(cur.idx()));
1643 row_type const numrows =
1644 min(grid.nrows(), nrows() - cur.row());
1645 for (row_type r = 0; r < numrows; ++r) {
1646 for (col_type c = 0; c < numcols; ++c) {
1647 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1648 cell(i).insert(0, grid.cell(grid.index(r, c)));
1651 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1653 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1654 idx_type i = index(r + cur.row(), 0);
1656 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1659 // append the left over horizontal cells to the last column
1660 idx_type i = index(r + cur.row(), ncols() - 1);
1661 for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
1662 cell(i).append(grid.cell(grid.index(r, c)));
1664 // append the left over vertical cells to the last _cell_
1665 idx_type i = nargs() - 1;
1666 for (row_type r = numrows; r < grid.nrows(); ++r) {
1667 for (col_type c = 0; c < grid.ncols(); ++c)
1668 cell(i).append(grid.cell(grid.index(r, c)));
1670 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1672 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1674 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1679 cur.clearSelection(); // bug 393
1680 // FIXME audit setBuffer calls
1681 cur.inset().setBuffer(*buffer_);
1682 cur.forceBufferUpdate();
1687 case LFUN_LINE_BEGIN:
1688 case LFUN_WORD_BACKWARD:
1689 case LFUN_WORD_LEFT:
1690 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1692 case LFUN_LINE_BEGIN_SELECT:
1693 case LFUN_WORD_BACKWARD_SELECT:
1694 case LFUN_WORD_LEFT_SELECT:
1695 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1696 act == LFUN_WORD_LEFT_SELECT ||
1697 act == LFUN_LINE_BEGIN_SELECT);
1698 cur.macroModeClose();
1699 if (cur.pos() != 0) {
1701 } else if (cur.idx() % cur.ncols() != 0) {
1702 cur.idx() -= cur.idx() % cur.ncols();
1704 } else if (cur.idx() != 0) {
1708 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1713 case LFUN_WORD_FORWARD:
1714 case LFUN_WORD_RIGHT:
1716 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1718 case LFUN_WORD_FORWARD_SELECT:
1719 case LFUN_WORD_RIGHT_SELECT:
1720 case LFUN_LINE_END_SELECT:
1721 cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
1722 act == LFUN_WORD_RIGHT_SELECT ||
1723 act == LFUN_LINE_END_SELECT);
1724 cur.macroModeClose();
1726 if (cur.pos() != cur.lastpos()) {
1727 cur.pos() = cur.lastpos();
1728 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1729 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1730 cur.pos() = cur.lastpos();
1731 } else if (cur.idx() != cur.lastidx()) {
1732 cur.idx() = cur.lastidx();
1733 cur.pos() = cur.lastpos();
1735 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1741 InsetMathNest::doDispatch(cur, cmd);
1746 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1747 FuncStatus & status) const
1749 switch (cmd.action()) {
1750 case LFUN_TABULAR_FEATURE: {
1751 string s = cmd.getArg(0);
1752 if (&cur.inset() != this) {
1753 // Table actions requires that the cursor is _inside_ the
1755 status.setEnabled(false);
1756 status.message(from_utf8(N_("Cursor not in table")));
1759 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1760 status.setEnabled(false);
1761 status.message(from_utf8(N_("Only one row")));
1765 (s == "delete-column" || s == "swap-column")) {
1766 status.setEnabled(false);
1767 status.message(from_utf8(N_("Only one column")));
1770 if ((rowinfo_[cur.row()].lines_ == 0 &&
1771 s == "delete-hline-above") ||
1772 (rowinfo_[cur.row() + 1].lines_ == 0 &&
1773 s == "delete-hline-below")) {
1774 status.setEnabled(false);
1775 status.message(from_utf8(N_("No hline to delete")));
1779 if ((colinfo_[cur.col()].lines_ == 0 &&
1780 s == "delete-vline-left") ||
1781 (colinfo_[cur.col() + 1].lines_ == 0 &&
1782 s == "delete-vline-right")) {
1783 status.setEnabled(false);
1784 status.message(from_utf8(N_("No vline to delete")));
1787 if (s == "valign-top" || s == "valign-middle" ||
1788 s == "valign-bottom" || s == "align-left" ||
1789 s == "align-right" || s == "align-center") {
1790 status.setEnabled(true);
1791 char const ha = horizontalAlignment(cur.col());
1792 char const va = verticalAlignment();
1793 status.setOnOff((s == "align-left" && ha == 'l')
1794 || (s == "align-right" && ha == 'r')
1795 || (s == "align-center" && ha == 'c')
1796 || (s == "valign-top" && va == 't')
1797 || (s == "valign-bottom" && va == 'b')
1798 || (s == "valign-middle" && va == 'c'));
1801 if (s == "append-row" || s == "delete-row" ||
1802 s == "copy-row" || s == "swap-row" ||
1803 s == "add-hline-above" || s == "add-hline-below" ||
1804 s == "delete-hline-above" || s == "delete-hline-below" ||
1805 s == "append-column" || s == "delete-column" ||
1806 s == "copy-column" || s == "swap-column" ||
1807 s == "add-vline-left" || s == "add-vline-right" ||
1808 s == "delete-vline-left" || s == "delete-vline-right") {
1809 status.setEnabled(true);
1811 status.setEnabled(false);
1812 status.message(bformat(
1813 from_utf8(N_("Unknown tabular feature '%1$s'")),
1818 // FIXME: What did this code do?
1819 // Please check whether it is still needed!
1820 // should be more precise
1821 if (v_align_ == '\0') {
1822 status.enable(true);
1825 if (cmd.argument().empty()) {
1826 status.enable(false);
1829 if (!contains("tcb", cmd.argument()[0])) {
1830 status.enable(false);
1833 status.setOnOff(cmd.argument()[0] == v_align_);
1834 status.setEnabled(true);
1839 case LFUN_CELL_SPLIT:
1840 status.setEnabled(cur.idx() != cur.lastidx());
1843 case LFUN_CELL_BACKWARD:
1844 case LFUN_CELL_FORWARD:
1845 status.setEnabled(true);
1851 return InsetMathNest::getStatus(cur, cmd, status);
1856 char InsetMathGrid::colAlign(HullType type, col_type col)
1860 return "rcl"[col % 3];
1871 return "rl"[col & 1];
1886 int InsetMathGrid::colSpace(HullType type, col_type col)
1888 int alignInterSpace = 0;
1903 alignInterSpace = 20;
1906 alignInterSpace = 0;
1909 alignInterSpace = 40;
1913 alignInterSpace = 60;
1916 return (col % 2) ? alignInterSpace : 0;