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()
85 : multi_(CELL_NORMAL), glue_(0), begin_(0), end_(0)
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 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) {
635 + colinfo_[c].offset_
637 - vlinesep()/2 - colsep()/2;
639 rowinfo_[r].offset_ - rowinfo_[r].ascent_,
641 rowinfo_[r].offset_ + rowinfo_[r].descent_,
648 // draw outer lines in one go
649 for (row_type row = 0; row <= nrows(); row += nrows())
650 for (unsigned int i = 0; i < rowinfo_[row].lines_; ++i) {
651 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
652 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
653 pi.pain.line(x + lmargin + 1, yy,
654 x + dim.width() - rmargin - 1, yy,
658 for (col_type col = 0; col <= ncols(); col += ncols())
659 for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
660 int xx = x + lmargin + colinfo_[col].offset_
661 - i * vlinesep() - vlinesep()/2 - colsep()/2;
662 pi.pain.line(xx, y - dim.ascent() + 1,
663 xx, y + dim.descent() - 1,
666 drawMarkers2(pi, x, y);
670 void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
672 // let the cells adjust themselves
673 for (idx_type i = 0; i < nargs(); ++i)
674 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
675 cell(i).metricsT(mi, dim);
677 // compute absolute sizes of vertical structure
678 for (row_type row = 0; row < nrows(); ++row) {
681 for (col_type col = 0; col < ncols(); ++col) {
682 idx_type const i = index(row, col);
683 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
684 //MathData const & c = cell(i);
687 asc = max(asc, dimc.ascent());
688 desc = max(desc, dimc.descent());
691 rowinfo_[row].ascent_ = asc;
692 rowinfo_[row].descent_ = desc;
694 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
695 rowinfo_[nrows()].ascent_ = 0;
696 rowinfo_[nrows()].descent_ = 0;
698 // compute vertical offsets
699 rowinfo_[0].offset_ = 0;
700 for (row_type row = 1; row <= nrows(); ++row) {
701 rowinfo_[row].offset_ =
702 rowinfo_[row - 1].offset_ +
703 rowinfo_[row - 1].descent_ +
704 //rowinfo_[row - 1].skipPixels(mi) +
706 //rowinfo_[row].lines_ * hlinesep() +
707 rowinfo_[row].ascent_;
710 // adjust vertical offset
717 h = rowinfo_[nrows() - 1].offset_;
720 h = rowinfo_[nrows() - 1].offset_ / 2;
722 for (row_type row = 0; row <= nrows(); ++row)
723 rowinfo_[row].offset_ -= h;
726 // compute absolute sizes of horizontal structure
727 for (col_type col = 0; col < ncols(); ++col) {
729 for (row_type row = 0; row < nrows(); ++row) {
731 //idx_type const i = index(row, col);
732 //if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
733 // wid = max(wid, cell(i).width());
735 colinfo_[col].width_ = wid;
737 colinfo_[ncols()].width_ = 0;
739 // compute horizontal offsets
740 colinfo_[0].offset_ = border();
741 for (col_type col = 1; col <= ncols(); ++col) {
742 colinfo_[col].offset_ =
743 colinfo_[col - 1].offset_ +
744 colinfo_[col - 1].width_ +
745 displayColSpace(col - 1) +
747 //colinfo_[col].lines_ * vlinesep();
751 dim.wid = colinfo_[ncols() - 1].offset_
752 + colinfo_[ncols() - 1].width_
753 //+ vlinesep() * colinfo_[ncols()].lines_
756 dim.asc = -rowinfo_[0].offset_
757 + rowinfo_[0].ascent_
758 //+ hlinesep() * rowinfo_[0].lines_
761 dim.des = rowinfo_[nrows() - 1].offset_
762 + rowinfo_[nrows() - 1].descent_
763 //+ hlinesep() * rowinfo_[nrows()].lines_
768 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
770 // for (idx_type idx = 0; idx < nargs(); ++idx)
771 // if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
772 // cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
776 void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype)
779 for (idx_type idx = 0; idx < nargs(); ++idx)
780 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
781 cell(idx).updateBuffer(it, utype);
785 docstring InsetMathGrid::eolString(row_type row, bool fragile,
786 bool /*latex*/, bool last_eoln) const
790 if (!rowinfo_[row].crskip_.zero())
791 eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
792 else if(!rowinfo_[row].allow_newpage_)
795 // make sure an upcoming '[' does not break anything
796 if (row + 1 < nrows()) {
797 MathData const & c = cell(index(row + 1, 0));
798 if (!c.empty() && c.front()->getChar() == '[')
803 // only add \\ if necessary
804 if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
807 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
811 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
813 if (col + 1 == lastcol)
815 return from_ascii(" & ");
819 void InsetMathGrid::addRow(row_type row)
821 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
823 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData());
825 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
829 void InsetMathGrid::delRow(row_type row)
834 cells_type::iterator it = cells_.begin() + row * ncols();
835 cells_.erase(it, it + ncols());
837 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
838 cellinfo_.erase(jt, jt + ncols());
840 rowinfo_.erase(rowinfo_.begin() + row);
844 void InsetMathGrid::copyRow(row_type row)
847 for (col_type col = 0; col < ncols(); ++col)
848 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
852 void InsetMathGrid::swapRow(row_type row)
856 if (row + 1 == nrows())
858 for (col_type col = 0; col < ncols(); ++col)
859 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
863 void InsetMathGrid::addCol(col_type newcol)
865 const col_type nc = ncols();
866 const row_type nr = nrows();
867 cells_type new_cells((nc + 1) * nr);
868 vector<CellInfo> new_cellinfo((nc + 1) * nr);
870 for (row_type row = 0; row < nr; ++row)
871 for (col_type col = 0; col < nc; ++col) {
872 new_cells[row * (nc + 1) + col + (col >= newcol)]
873 = cells_[row * nc + col];
874 new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
875 = cellinfo_[row * nc + col];
877 swap(cells_, new_cells);
878 swap(cellinfo_, new_cellinfo);
881 inf.skip_ = defaultColSpace(newcol);
882 inf.align_ = defaultColAlign(newcol);
883 colinfo_.insert(colinfo_.begin() + newcol, inf);
887 void InsetMathGrid::delCol(col_type col)
893 vector<CellInfo> tmpcellinfo;
894 for (col_type i = 0; i < nargs(); ++i)
895 if (i % ncols() != col) {
896 tmpcells.push_back(cells_[i]);
897 tmpcellinfo.push_back(cellinfo_[i]);
899 swap(cells_, tmpcells);
900 swap(cellinfo_, tmpcellinfo);
902 colinfo_.erase(colinfo_.begin() + col);
906 void InsetMathGrid::copyCol(col_type col)
909 for (row_type row = 0; row < nrows(); ++row)
910 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
914 void InsetMathGrid::swapCol(col_type col)
918 if (col + 1 == ncols())
920 for (row_type row = 0; row < nrows(); ++row)
921 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
925 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
927 if (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN)
929 col_type c = col(idx);
930 int x = colinfo_[c].offset_;
931 char align = displayColAlign(idx);
932 Dimension const & celldim = cell(idx).dimension(bv);
933 if (align == 'r' || align == 'R')
934 x += cellWidth(idx) - celldim.wid;
935 if (align == 'c' || align == 'C')
936 x += (cellWidth(idx) - celldim.wid) / 2;
941 int InsetMathGrid::cellYOffset(idx_type idx) const
943 return rowinfo_[row(idx)].offset_;
947 int InsetMathGrid::cellWidth(idx_type idx) const
949 switch (cellinfo_[idx].multi_) {
951 return colinfo_[col(idx)].width_;
952 case CELL_BEGIN_OF_MULTICOLUMN: {
953 col_type c1 = col(idx);
954 col_type c2 = c1 + ncellcols(idx);
955 return colinfo_[c2].offset_
956 - colinfo_[c1].offset_
957 - displayColSpace(c2)
959 - colinfo_[c2].lines_ * vlinesep();
961 case CELL_PART_OF_MULTICOLUMN:
968 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
973 cur.idx() -= ncols();
975 if (cur.row() + 1 >= nrows())
977 cur.idx() += ncols();
979 // If we are in a multicolumn cell, move to the "real" cell
980 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
981 LASSERT(cur.idx() > 0, return false);
984 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
989 bool InsetMathGrid::idxBackward(Cursor & cur) const
991 // leave matrix if at the front edge
995 // If we are in a multicolumn cell, move to the "real" cell
996 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
997 LASSERT(cur.idx() > 0, return false);
1000 cur.pos() = cur.lastpos();
1005 bool InsetMathGrid::idxForward(Cursor & cur) const
1007 // leave matrix if at the back edge
1008 if (cur.col() + 1 == ncols())
1011 // If we are in a multicolumn cell, move to the next cell
1012 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1013 // leave matrix if at the back edge
1014 if (cur.col() + 1 == ncols())
1023 bool InsetMathGrid::idxFirst(Cursor & cur) const
1030 cur.idx() = (nrows() - 1) * ncols();
1033 cur.idx() = ((nrows() - 1) / 2) * ncols();
1035 // If we are in a multicolumn cell, move to the "real" cell
1036 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1037 LASSERT(cur.idx() > 0, return false);
1045 bool InsetMathGrid::idxLast(Cursor & cur) const
1049 cur.idx() = ncols() - 1;
1052 cur.idx() = nargs() - 1;
1055 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
1057 // If we are in a multicolumn cell, move to the "real" cell
1058 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1059 LASSERT(cur.idx() > 0, return false);
1062 cur.pos() = cur.lastpos();
1067 bool InsetMathGrid::idxDelete(idx_type & idx)
1069 // nothing to do if we have just one row
1073 // nothing to do if we are in the middle of the last row of the inset
1074 if (idx + ncols() > nargs())
1077 // try to delete entire sequence of ncols() empty cells if possible
1078 for (idx_type i = idx; i < idx + ncols(); ++i)
1079 if (!cell(i).empty())
1082 // move cells if necessary
1083 for (idx_type i = index(row(idx), 0); i < idx; ++i)
1084 swap(cell(i), cell(i + ncols()));
1091 // undo effect of Ctrl-Tab (i.e. pull next cell)
1092 //if (idx + 1 != nargs())
1093 // cell(idx).swap(cell(idx + 1));
1095 // we handled the event..
1100 // reimplement old behaviour when pressing Delete in the last position
1102 void InsetMathGrid::idxGlue(idx_type idx)
1104 col_type c = col(idx);
1105 if (c + 1 == ncols()) {
1106 if (row(idx) + 1 != nrows()) {
1107 for (col_type cc = 0; cc < ncols(); ++cc)
1108 cell(idx).append(cell(idx + cc + 1));
1109 delRow(row(idx) + 1);
1112 idx_type idx_next = idx + 1;
1113 while (idx_next < nargs() &&
1114 cellinfo_[idx_next].multi_ == CELL_PART_OF_MULTICOLUMN)
1116 if (idx_next < nargs())
1117 cell(idx).append(cell(idx_next));
1118 col_type oldcol = c + 1;
1119 for (col_type cc = c + 2; cc < ncols(); ++cc)
1120 cell(idx - oldcol + cc) = cell(idx - oldcol + 1 + cc);
1121 cell(idx - c + ncols() - 1).clear();
1126 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
1128 return rowinfo_[row];
1132 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
1134 return rowinfo_[row];
1138 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
1140 row_type const ri = row(idx);
1141 row_type const r1 = min(row(from), row(to));
1142 row_type const r2 = max(row(from), row(to));
1143 col_type const ci = col(idx);
1144 col_type const c1 = min(col(from), col(to));
1145 col_type const c2 = max(col(from), col(to));
1146 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
1150 void InsetMathGrid::normalize(NormalStream & os) const
1153 for (row_type row = 0; row < nrows(); ++row) {
1155 for (col_type col = 0; col < ncols(); ++col) {
1156 idx_type const i = index(row, col);
1157 switch (cellinfo_[i].multi_) {
1159 os << "[cell " << cell(i) << ']';
1161 case CELL_BEGIN_OF_MULTICOLUMN:
1162 os << "[cell colspan="
1163 << static_cast<int>(ncellcols(i)) << ' '
1166 case CELL_PART_OF_MULTICOLUMN:
1176 void InsetMathGrid::mathmlize(MathStream & os) const
1178 bool const havetable = nrows() > 1 || ncols() > 1;
1180 os << MTag("mtable");
1181 char const * const celltag = havetable ? "mtd" : "mrow";
1182 for (row_type row = 0; row < nrows(); ++row) {
1185 for (col_type col = 0; col < ncols(); ++col) {
1186 idx_type const i = index(row, col);
1187 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1188 col_type const cellcols = ncellcols(i);
1190 if (havetable && cellcols > 1)
1191 attr << "colspan='" << cellcols << '\'';
1192 os << MTag(celltag, attr.str());
1193 os << cell(index(row, col));
1194 os << ETag(celltag);
1201 os << ETag("mtable");
1206 // We need to do something about alignment here.
1207 void InsetMathGrid::htmlize(HtmlStream & os, string attrib) const
1209 bool const havetable = nrows() > 1 || ncols() > 1;
1211 os << cell(index(0, 0));
1214 os << MTag("table", attrib);
1215 for (row_type row = 0; row < nrows(); ++row) {
1217 for (col_type col = 0; col < ncols(); ++col) {
1218 idx_type const i = index(row, col);
1219 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1220 col_type const cellcols = ncellcols(i);
1223 attr << "colspan='" << cellcols << '\'';
1224 os << MTag("td", attr.str());
1225 os << cell(index(row, col));
1231 os << ETag("table");
1235 void InsetMathGrid::htmlize(HtmlStream & os) const
1237 htmlize(os, "class='mathtable'");
1241 void InsetMathGrid::validate(LaTeXFeatures & features) const
1243 if (features.runparams().math_flavor == OutputParams::MathAsHTML
1244 && (nrows() > 1 || ncols() > 1)) {
1245 // CSS taken from InsetMathCases
1246 features.addCSSSnippet(
1247 "table.mathtable{display: inline-block; text-align: center; border: none;"
1248 "border-left: thin solid black; vertical-align: middle; padding-left: 0.5ex;}\n"
1249 "table.mathtable td {text-align: left; border: none;}");
1254 void InsetMathGrid::write(WriteStream & os) const
1256 write(os, 0, 0, nrows(), ncols());
1259 void InsetMathGrid::write(WriteStream & os,
1260 row_type beg_row, col_type beg_col,
1261 row_type end_row, col_type end_col) const
1263 MathEnsurer ensurer(os, false);
1265 for (row_type row = beg_row; row < end_row; ++row) {
1266 os << verboseHLine(rowinfo_[row].lines_);
1267 // don't write & and empty cells at end of line,
1268 // unless there are vertical lines
1269 col_type lastcol = 0;
1270 bool emptyline = true;
1271 bool last_eoln = true;
1272 for (col_type col = beg_col; col < end_col; ++col) {
1273 idx_type const idx = index(row, col);
1274 bool const empty_cell = cell(idx).empty();
1275 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL)
1277 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL ||
1278 colinfo_[col + 1].lines_) {
1283 for (col_type col = beg_col; col < end_col;) {
1285 idx_type const idx = index(row, col);
1286 RowEntry entry = TexRow::mathEntry(id(),idx);
1287 os.texrow().start(entry);
1288 if (col >= lastcol) {
1292 Changer dummy = os.changeRowEntry(entry);
1293 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1295 while (s < ncols() &&
1296 cellinfo_[index(row, s)].multi_ == CELL_PART_OF_MULTICOLUMN)
1299 os << "\\multicolumn{" << nccols
1300 << "}{" << cellinfo_[idx].align_
1304 if (os.pendingBrace())
1305 ModeSpecifier specifier(os, TEXT_MODE);
1306 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1308 os << eocString(col + nccols - 1, lastcol);
1311 eol = eolString(row, os.fragile(), os.latex(), last_eoln);
1313 // append newline only if line wasn't completely empty
1314 // and the formula is not written on a single line
1315 bool const empty = emptyline && eol.empty();
1316 if (!empty && nrows() > 1)
1319 // @TODO use end_row instead of nrows() ?
1320 docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
1332 int InsetMathGrid::colsep() const
1338 int InsetMathGrid::rowsep() const
1344 int InsetMathGrid::hlinesep() const
1350 int InsetMathGrid::vlinesep() const
1356 int InsetMathGrid::border() const
1362 void InsetMathGrid::splitCell(Cursor & cur)
1364 if (cur.idx() == cur.lastidx())
1366 MathData ar = cur.cell();
1367 ar.erase(0, cur.pos());
1368 cur.cell().erase(cur.pos(), cur.lastpos());
1370 while (cur.idx() << nargs() &&
1371 cellinfo_[cur.idx()].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1374 cur.cell().insert(0, ar);
1378 char InsetMathGrid::displayColAlign(idx_type idx) const
1380 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1381 // align_ may also contain lines like "||r|", so this is
1382 // not complete, but we catch at least the simple cases.
1383 if (cellinfo_[idx].align_ == "c")
1385 if (cellinfo_[idx].align_ == "l")
1387 if (cellinfo_[idx].align_ == "r")
1390 return colinfo_[col(idx)].align_;
1394 int InsetMathGrid::displayColSpace(col_type col) const
1396 return colinfo_[col].skip_;
1399 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1401 //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1403 Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
1405 FuncCode const act = cmd.action();
1408 // insert file functions
1409 case LFUN_LINE_DELETE_FORWARD:
1410 cur.recordUndoInset();
1411 //autocorrect_ = false;
1419 if (cur.idx() > cur.lastidx())
1420 cur.idx() = cur.lastidx();
1421 if (cur.pos() > cur.lastpos())
1422 cur.pos() = cur.lastpos();
1425 case LFUN_CELL_SPLIT:
1430 case LFUN_CELL_BACKWARD:
1432 cur.selection(false);
1433 if (!idxPrev(cur)) {
1434 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1439 case LFUN_CELL_FORWARD:
1440 // Can't handle selection by additional 'shift' as this is
1441 // hard bound to LFUN_CELL_BACKWARD
1442 cur.selection(false);
1443 if (!idxNext(cur)) {
1444 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1449 case LFUN_NEWLINE_INSERT: {
1450 cur.recordUndoInset();
1451 row_type const r = cur.row();
1455 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1456 swap(cell(index(r, c)), cell(index(r + 1, c)));
1461 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1464 cur.pos() = cur.lastpos();
1465 cur.forceBufferUpdate();
1466 //mathcursor->normalize();
1467 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1471 case LFUN_TABULAR_FEATURE: {
1472 cur.recordUndoInset();
1473 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1474 istringstream is(to_utf8(cmd.argument()));
1477 if (s == "valign-top")
1478 setVerticalAlignment('t');
1479 else if (s == "valign-middle")
1480 setVerticalAlignment('c');
1481 else if (s == "valign-bottom")
1482 setVerticalAlignment('b');
1483 else if (s == "align-left")
1484 setHorizontalAlignment('l', cur.col());
1485 else if (s == "align-right")
1486 setHorizontalAlignment('r', cur.col());
1487 else if (s == "align-center")
1488 setHorizontalAlignment('c', cur.col());
1489 else if (s == "append-row")
1490 for (int i = 0, n = extractInt(is); i < n; ++i)
1492 else if (s == "delete-row") {
1493 cur.clearSelection(); // bug 4323
1494 for (int i = 0, n = extractInt(is); i < n; ++i) {
1496 if (cur.idx() >= nargs())
1497 cur.idx() -= ncols();
1499 cur.pos() = 0; // trick, see below
1501 else if (s == "copy-row") {
1502 // Here (as later) we save the cursor col/row
1503 // in order to restore it after operation.
1504 row_type const r = cur.row();
1505 col_type const c = cur.col();
1506 for (int i = 0, n = extractInt(is); i < n; ++i)
1508 cur.idx() = index(r, c);
1510 else if (s == "swap-row") {
1512 // Trick to suppress same-idx-means-different-cell
1516 else if (s == "add-hline-above")
1517 rowinfo_[cur.row()].lines_++;
1518 else if (s == "add-hline-below")
1519 rowinfo_[cur.row()+1].lines_++;
1520 else if (s == "delete-hline-above")
1521 rowinfo_[cur.row()].lines_--;
1522 else if (s == "delete-hline-below")
1523 rowinfo_[cur.row()+1].lines_--;
1524 else if (s == "append-column") {
1525 row_type const r = cur.row();
1526 col_type const c = cur.col();
1527 for (int i = 0, n = extractInt(is); i < n; ++i)
1528 addCol(cur.col() + 1);
1529 cur.idx() = index(r, c);
1531 else if (s == "delete-column") {
1532 cur.clearSelection(); // bug 4323
1533 row_type const r = cur.row();
1534 col_type const c = cur.col();
1535 for (int i = 0, n = extractInt(is); i < n; ++i)
1536 delCol(col(cur.idx()));
1537 cur.idx() = index(r, min(c, cur.ncols() - 1));
1538 cur.pos() = 0; // trick, see above
1540 else if (s == "copy-column") {
1541 row_type const r = cur.row();
1542 col_type const c = cur.col();
1544 cur.idx() = index(r, c);
1546 else if (s == "swap-column") {
1548 cur.pos() = 0; // trick, see above
1550 else if (s == "add-vline-left") {
1551 colinfo_[cur.col()].lines_++;
1552 if (!colinfo_[cur.col()].special_.empty())
1553 colinfo_[cur.col()].special_ += '|';
1555 else if (s == "add-vline-right") {
1556 colinfo_[cur.col()+1].lines_++;
1557 if (!colinfo_[cur.col()+1].special_.empty())
1558 colinfo_[cur.col()+1].special_.insert(0, 1, '|');
1560 else if (s == "delete-vline-left") {
1561 colinfo_[cur.col()].lines_--;
1562 docstring & special = colinfo_[cur.col()].special_;
1563 if (!special.empty()) {
1564 docstring::size_type i = special.rfind('|');
1565 LASSERT(i != docstring::npos, break);
1566 special.erase(i, 1);
1569 else if (s == "delete-vline-right") {
1570 colinfo_[cur.col()+1].lines_--;
1571 docstring & special = colinfo_[cur.col()+1].special_;
1572 if (!special.empty()) {
1573 docstring::size_type i = special.find('|');
1574 LASSERT(i != docstring::npos, break);
1575 special.erase(i, 1);
1582 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1583 //lyxerr << "returning FINISHED_LEFT" << endl;
1587 case LFUN_CLIPBOARD_PASTE:
1588 parseflg |= Parse::VERBATIM;
1591 if (cur.currentMode() <= TEXT_MODE)
1592 parseflg |= Parse::TEXTMODE;
1593 cur.message(_("Paste"));
1594 cap::replaceSelection(cur);
1596 if (cmd.argument().empty() && !theClipboard().isInternal())
1597 topaste = theClipboard().getAsText(frontend::Clipboard::PlainTextType);
1599 idocstringstream is(cmd.argument());
1602 topaste = cap::selection(n, buffer().params().documentClassPtr());
1604 InsetMathGrid grid(buffer_, 1, 1);
1605 if (!topaste.empty())
1606 if ((topaste.size() == 1 && isAscii(topaste))
1607 || !mathed_parse_normal(grid, topaste, parseflg)) {
1609 mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
1612 bool hline_enabled = false;
1613 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
1615 if (getStatus(cur, fr, status))
1616 hline_enabled = status.enabled();
1617 if (grid.nargs() == 1) {
1618 // single cell/part of cell
1619 cur.recordUndoInset();
1620 cur.cell().insert(cur.pos(), grid.cell(0));
1621 cur.pos() += grid.cell(0).size();
1623 rowinfo_[cur.row()].lines_ += grid.rowinfo_[0].lines_;
1625 for (unsigned int l = 0; l < grid.rowinfo_[0].lines_; ++l) {
1626 cur.cell().insert(0,
1627 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1633 cur.recordUndoInset();
1634 col_type const numcols =
1635 min(grid.ncols(), ncols() - col(cur.idx()));
1636 row_type const numrows =
1637 min(grid.nrows(), nrows() - cur.row());
1638 for (row_type r = 0; r < numrows; ++r) {
1639 for (col_type c = 0; c < numcols; ++c) {
1640 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1641 cell(i).insert(0, grid.cell(grid.index(r, c)));
1644 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1646 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1647 idx_type i = index(r + cur.row(), 0);
1649 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1652 // append the left over horizontal cells to the last column
1653 idx_type i = index(r + cur.row(), ncols() - 1);
1654 for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
1655 cell(i).append(grid.cell(grid.index(r, c)));
1657 // append the left over vertical cells to the last _cell_
1658 idx_type i = nargs() - 1;
1659 for (row_type r = numrows; r < grid.nrows(); ++r) {
1660 for (col_type c = 0; c < grid.ncols(); ++c)
1661 cell(i).append(grid.cell(grid.index(r, c)));
1663 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1665 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1667 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1672 cur.clearSelection(); // bug 393
1673 // FIXME audit setBuffer calls
1674 cur.inset().setBuffer(*buffer_);
1675 cur.forceBufferUpdate();
1680 case LFUN_LINE_BEGIN:
1681 case LFUN_WORD_BACKWARD:
1682 case LFUN_WORD_LEFT:
1683 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1685 case LFUN_LINE_BEGIN_SELECT:
1686 case LFUN_WORD_BACKWARD_SELECT:
1687 case LFUN_WORD_LEFT_SELECT:
1688 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1689 act == LFUN_WORD_LEFT_SELECT ||
1690 act == LFUN_LINE_BEGIN_SELECT);
1691 cur.macroModeClose();
1692 if (cur.pos() != 0) {
1694 } else if (cur.idx() % cur.ncols() != 0) {
1695 cur.idx() -= cur.idx() % cur.ncols();
1697 } else if (cur.idx() != 0) {
1701 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1706 case LFUN_WORD_FORWARD:
1707 case LFUN_WORD_RIGHT:
1709 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1711 case LFUN_WORD_FORWARD_SELECT:
1712 case LFUN_WORD_RIGHT_SELECT:
1713 case LFUN_LINE_END_SELECT:
1714 cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
1715 act == LFUN_WORD_RIGHT_SELECT ||
1716 act == LFUN_LINE_END_SELECT);
1717 cur.macroModeClose();
1719 if (cur.pos() != cur.lastpos()) {
1720 cur.pos() = cur.lastpos();
1721 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1722 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1723 cur.pos() = cur.lastpos();
1724 } else if (cur.idx() != cur.lastidx()) {
1725 cur.idx() = cur.lastidx();
1726 cur.pos() = cur.lastpos();
1728 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1734 InsetMathNest::doDispatch(cur, cmd);
1739 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1740 FuncStatus & status) const
1742 switch (cmd.action()) {
1743 case LFUN_TABULAR_FEATURE: {
1744 string s = cmd.getArg(0);
1745 if (&cur.inset() != this) {
1746 // Table actions requires that the cursor is _inside_ the
1748 status.setEnabled(false);
1749 status.message(from_utf8(N_("Cursor not in table")));
1752 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1753 status.setEnabled(false);
1754 status.message(from_utf8(N_("Only one row")));
1758 (s == "delete-column" || s == "swap-column")) {
1759 status.setEnabled(false);
1760 status.message(from_utf8(N_("Only one column")));
1763 if ((rowinfo_[cur.row()].lines_ == 0 &&
1764 s == "delete-hline-above") ||
1765 (rowinfo_[cur.row() + 1].lines_ == 0 &&
1766 s == "delete-hline-below")) {
1767 status.setEnabled(false);
1768 status.message(from_utf8(N_("No hline to delete")));
1772 if ((colinfo_[cur.col()].lines_ == 0 &&
1773 s == "delete-vline-left") ||
1774 (colinfo_[cur.col() + 1].lines_ == 0 &&
1775 s == "delete-vline-right")) {
1776 status.setEnabled(false);
1777 status.message(from_utf8(N_("No vline to delete")));
1780 if (s == "valign-top" || s == "valign-middle" ||
1781 s == "valign-bottom" || s == "align-left" ||
1782 s == "align-right" || s == "align-center") {
1783 status.setEnabled(true);
1784 char const ha = horizontalAlignment(cur.col());
1785 char const va = verticalAlignment();
1786 status.setOnOff((s == "align-left" && ha == 'l')
1787 || (s == "align-right" && ha == 'r')
1788 || (s == "align-center" && ha == 'c')
1789 || (s == "valign-top" && va == 't')
1790 || (s == "valign-bottom" && va == 'b')
1791 || (s == "valign-middle" && va == 'c'));
1794 if (s == "append-row" || s == "delete-row" ||
1795 s == "copy-row" || s == "swap-row" ||
1796 s == "add-hline-above" || s == "add-hline-below" ||
1797 s == "delete-hline-above" || s == "delete-hline-below" ||
1798 s == "append-column" || s == "delete-column" ||
1799 s == "copy-column" || s == "swap-column" ||
1800 s == "add-vline-left" || s == "add-vline-right" ||
1801 s == "delete-vline-left" || s == "delete-vline-right") {
1802 status.setEnabled(true);
1804 status.setEnabled(false);
1805 status.message(bformat(
1806 from_utf8(N_("Unknown tabular feature '%1$s'")),
1811 // FIXME: What did this code do?
1812 // Please check whether it is still needed!
1813 // should be more precise
1814 if (v_align_ == '\0') {
1815 status.enable(true);
1818 if (cmd.argument().empty()) {
1819 status.enable(false);
1822 if (!contains("tcb", cmd.argument()[0])) {
1823 status.enable(false);
1826 status.setOnOff(cmd.argument()[0] == v_align_);
1827 status.setEnabled(true);
1832 case LFUN_CELL_SPLIT:
1833 status.setEnabled(cur.idx() != cur.lastidx());
1836 case LFUN_CELL_BACKWARD:
1837 case LFUN_CELL_FORWARD:
1838 status.setEnabled(true);
1844 return InsetMathNest::getStatus(cur, cmd, status);
1849 char InsetMathGrid::colAlign(HullType type, col_type col)
1853 return "rcl"[col % 3];
1864 return "rl"[col & 1];
1879 int InsetMathGrid::colSpace(HullType type, col_type col)
1881 int alignInterSpace = 0;
1896 alignInterSpace = 20;
1899 alignInterSpace = 0;
1902 alignInterSpace = 40;
1906 alignInterSpace = 60;
1909 return (col % 2) ? alignInterSpace : 0;