2 * \file InsetMathGrid.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
14 #include "InsetMathGrid.h"
16 #include "InsetMathUnknown.h"
18 #include "MathParser.h"
19 #include "MathStream.h"
20 #include "MetricsInfo.h"
23 #include "BufferParams.h"
24 #include "BufferView.h"
25 #include "CutAndPaste.h"
26 #include "FuncStatus.h"
28 #include "FuncRequest.h"
30 #include "frontends/Clipboard.h"
31 #include "frontends/Painter.h"
33 #include "support/debug.h"
34 #include "support/docstream.h"
35 #include "support/gettext.h"
36 #include "support/lstrings.h"
37 #include "support/lassert.h"
42 using namespace lyx::support;
48 static docstring verboseHLine(int n)
51 for (int i = 0; i < n; ++i)
59 static int extractInt(istream & is)
63 return (num == 0) ? 1 : num;
67 static void resetGrid(InsetMathGrid & grid)
69 while (grid.ncols() > 1)
70 grid.delCol(grid.ncols() - 1);
71 while (grid.nrows() > 1)
72 grid.delRow(grid.nrows() - 1);
73 grid.cell(0).erase(0, grid.cell(0).size());
79 //////////////////////////////////////////////////////////////
82 InsetMathGrid::CellInfo::CellInfo()
83 : multi_(CELL_NORMAL), glue_(0), begin_(0), end_(0)
88 //////////////////////////////////////////////////////////////
91 InsetMathGrid::RowInfo::RowInfo()
92 : descent_(0), ascent_(0), offset_(0), lines_(0), skip_(0),
98 int InsetMathGrid::RowInfo::skipPixels(MetricsInfo const & mi) const
100 return crskip_.inPixels(mi.base);
105 //////////////////////////////////////////////////////////////
108 InsetMathGrid::ColInfo::ColInfo()
109 : align_('c'), width_(0), offset_(0), lines_(0), skip_(0)
113 //////////////////////////////////////////////////////////////
116 InsetMathGrid::InsetMathGrid(Buffer * buf)
117 : InsetMathNest(buf, 1),
127 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n)
128 : InsetMathNest(buf, m * n),
138 InsetMathGrid::InsetMathGrid(Buffer * buf, col_type m, row_type n, char v,
140 : InsetMathNest(buf, m * n),
147 setVerticalAlignment(v);
148 setHorizontalAlignments(h);
152 Inset * InsetMathGrid::clone() const
154 return new InsetMathGrid(*this);
158 InsetMath::idx_type InsetMathGrid::index(row_type row, col_type col) const
160 return col + ncols() * row;
164 void InsetMathGrid::setDefaults()
167 lyxerr << "positive number of columns expected" << endl;
169 // lyxerr << "positive number of rows expected" << endl;
170 for (col_type col = 0; col < ncols(); ++col) {
171 colinfo_[col].align_ = defaultColAlign(col);
172 colinfo_[col].skip_ = defaultColSpace(col);
173 colinfo_[col].special_.clear();
175 for (idx_type idx = 0; idx < nargs(); ++idx)
176 cellinfo_[idx].multi_ = CELL_NORMAL;
180 bool InsetMathGrid::interpretString(Cursor & cur, docstring const & str)
182 if (str == "\\hline") {
183 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
185 if (getStatus(cur, fr, status)) {
186 if (status.enabled()) {
187 rowinfo_[cur.row()].lines_++;
192 return InsetMathNest::interpretString(cur, str);
196 void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
199 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
202 colinfo_[col].lines_++;
203 } else if ((c == 'p' || c == 'm' || c == 'b'||
204 c == '!' || c == '@' || c == '>' || c == '<') &&
205 it + 1 != hh.end() && *(it + 1) == '{') {
206 // @{decl.} and p{width} are standard LaTeX, the
207 // others are extensions by array.sty
208 bool const newcolumn = c == 'p' || c == 'm' || c == 'b';
210 // this declares a new column
212 // Only intercolumn stuff is allowed
213 // in the last dummy column
215 colinfo_[col].align_ = 'l';
217 // this is intercolumn stuff
218 if (colinfo_[col].special_.empty())
219 // Overtake possible lines
220 colinfo_[col].special_ = docstring(colinfo_[col].lines_, '|');
224 while (it != hh.end()) {
226 colinfo_[col].special_ += c;
232 if (brace_open > 0 && brace_open == brace_close)
237 colinfo_[col].lines_ = count(
238 colinfo_[col].special_.begin(),
239 colinfo_[col].special_.end(), '|');
240 LYXERR(Debug::MATHED, "special column separator: `"
241 << to_utf8(colinfo_[col].special_) << '\'');
243 colinfo_[col].lines_ = 0;
244 colinfo_[col].special_.clear();
246 } else if (col >= ncols()) {
247 // Only intercolumn stuff is allowed in the last
250 } else if (c == 'c' || c == 'l' || c == 'r') {
251 colinfo_[col].align_ = static_cast<char>(c);
252 if (!colinfo_[col].special_.empty()) {
253 colinfo_[col].special_ += c;
254 colinfo_[col].lines_ = count(
255 colinfo_[col].special_.begin(),
256 colinfo_[col].special_.end(), '|');
257 LYXERR(Debug::MATHED, "special column separator: `"
258 << to_utf8(colinfo_[col].special_) << '\'');
261 colinfo_[col].lines_ = 0;
262 colinfo_[col].special_.clear();
264 lyxerr << "unknown column separator: '" << c << "'" << endl;
269 col_type n = hh.size();
272 for (col_type col = 0; col < n; ++col)
273 colinfo_[col].align_ = hh[col];
278 InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh)
281 for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
282 if (*it == 'c' || *it == 'l' || *it == 'r'||
283 *it == 'p' || *it == 'm' || *it == 'b')
285 // let's have at least one column, even if we did not recognize its
293 void InsetMathGrid::setHorizontalAlignment(char h, col_type col)
295 colinfo_[col].align_ = h;
296 if (!colinfo_[col].special_.empty()) {
297 char_type & c = colinfo_[col].special_[colinfo_[col].special_.size() - 1];
298 if (c == 'l' || c == 'c' || c == 'r')
301 // FIXME: Change alignment of p, m and b columns, too
305 char InsetMathGrid::horizontalAlignment(col_type col) const
307 return colinfo_[col].align_;
311 docstring InsetMathGrid::horizontalAlignments() const
314 for (col_type col = 0; col < ncols(); ++col) {
315 if (colinfo_[col].special_.empty()) {
316 res += docstring(colinfo_[col].lines_, '|');
317 res += colinfo_[col].align_;
319 res += colinfo_[col].special_;
321 if (colinfo_[ncols()].special_.empty())
322 return res + docstring(colinfo_[ncols()].lines_, '|');
323 return res + colinfo_[ncols()].special_;
327 void InsetMathGrid::setVerticalAlignment(char c)
333 char InsetMathGrid::verticalAlignment() const
339 InsetMathGrid::col_type InsetMathGrid::ncols() const
341 return colinfo_.size() - 1;
345 InsetMathGrid::row_type InsetMathGrid::nrows() const
347 return rowinfo_.size() - 1;
351 InsetMathGrid::col_type InsetMathGrid::col(idx_type idx) const
353 return idx % ncols();
357 InsetMathGrid::row_type InsetMathGrid::row(idx_type idx) const
359 return idx / ncols();
363 InsetMathGrid::col_type InsetMathGrid::ncellcols(idx_type idx) const
366 if (cellinfo_[idx].multi_ == CELL_NORMAL)
368 // If the cell at idx is already CELL_PART_OF_MULTICOLUMN we return
369 // the number of remaining columns, not the ones of the complete
370 // multicolumn cell. This makes it possible to always go to the next
371 // cell with idx + ncellcols(idx) - 1.
372 row_type const r = row(idx);
373 while (idx+cols < nargs() && row(idx+cols) == r &&
374 cellinfo_[idx+cols].multi_ == CELL_PART_OF_MULTICOLUMN)
380 void InsetMathGrid::vcrskip(Length const & crskip, row_type row)
382 rowinfo_[row].crskip_ = crskip;
386 Length InsetMathGrid::vcrskip(row_type row) const
388 return rowinfo_[row].crskip_;
392 void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
394 // let the cells adjust themselves
395 for (idx_type i = 0; i < nargs(); ++i) {
396 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
398 cell(i).metrics(mi, dimc);
402 BufferView & bv = *mi.base.bv;
404 // compute absolute sizes of vertical structure
405 for (row_type row = 0; row < nrows(); ++row) {
408 for (col_type col = 0; col < ncols(); ++col) {
409 idx_type const i = index(row, col);
410 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
411 Dimension const & dimc = cell(i).dimension(bv);
412 asc = max(asc, dimc.asc);
413 desc = max(desc, dimc.des);
416 rowinfo_[row].ascent_ = asc;
417 rowinfo_[row].descent_ = desc;
419 rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
420 rowinfo_[nrows()].ascent_ = 0;
421 rowinfo_[nrows()].descent_ = 0;
423 // compute vertical offsets
424 rowinfo_[0].offset_ = 0;
425 for (row_type row = 1; row <= nrows(); ++row) {
426 rowinfo_[row].offset_ =
427 rowinfo_[row - 1].offset_ +
428 rowinfo_[row - 1].descent_ +
429 rowinfo_[row - 1].skipPixels(mi) +
431 rowinfo_[row].lines_ * hlinesep() +
432 rowinfo_[row].ascent_;
435 // adjust vertical offset
442 h = rowinfo_[nrows() - 1].offset_;
445 h = rowinfo_[nrows() - 1].offset_ / 2;
447 for (row_type row = 0; row <= nrows(); ++row)
448 rowinfo_[row].offset_ -= h;
451 // multicolumn cell widths, as a map from first column to width in a
452 // vector of last columns.
453 // This is only used if the grid has more than one row, since for
454 // one-row grids multicolumn cells do not need special handling
455 vector<map<col_type, int> > mcolwidths(ncols());
457 // compute absolute sizes of horizontal structure
458 for (col_type col = 0; col < ncols(); ++col) {
460 for (row_type row = 0; row < nrows(); ++row) {
461 idx_type const i = index(row, col);
462 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
463 int const w = cell(i).dimension(bv).wid;
464 col_type const cols = ncellcols(i);
465 if (cols > 1 && nrows() > 1) {
466 col_type last = col+cols-1;
467 LASSERT(last < ncols(), last = ncols()-1);
468 map<col_type, int>::iterator it =
469 mcolwidths[last].find(col);
470 if (it == mcolwidths[last].end())
471 mcolwidths[last][col] = w;
473 it->second = max(it->second, w);
478 colinfo_[col].width_ = wid;
480 colinfo_[ncols()].width_ = 0;
482 // compute horizontal offsets
483 colinfo_[0].offset_ = border();
484 for (col_type col = 1; col <= ncols(); ++col) {
485 colinfo_[col].offset_ =
486 colinfo_[col - 1].offset_ +
487 colinfo_[col - 1].width_ +
488 displayColSpace(col - 1) +
490 colinfo_[col].lines_ * vlinesep();
493 // increase column widths for multicolumn cells if needed
494 // FIXME: multicolumn lines are not yet considered
495 for (col_type last = 0; last < ncols(); ++last) {
496 map<col_type, int> const & widths = mcolwidths[last];
497 // We increase the width of the last column of the multicol
498 // cell (some sort of left alignment). Since we iterate through
499 // the last and the first columns from left to right, we ensure
500 // that increased widths of previous columns are correctly
501 // taken into account for later columns, thus preventing
502 // unneeded width increasing.
503 for (map<col_type, int>::const_iterator it = widths.begin();
504 it != widths.end(); ++it) {
505 int const wid = it->second;
506 col_type const first = it->first;
507 int const nextoffset =
508 colinfo_[first].offset_ +
510 displayColSpace(last) +
512 colinfo_[last+1].lines_ * vlinesep();
513 int const dx = nextoffset - colinfo_[last+1].offset_;
515 colinfo_[last].width_ += dx;
516 for (col_type col = last + 1; col <= ncols(); ++col)
517 colinfo_[col].offset_ += dx;
523 dim.wid = colinfo_[ncols() - 1].offset_
524 + colinfo_[ncols() - 1].width_
525 + vlinesep() * colinfo_[ncols()].lines_
528 dim.asc = - rowinfo_[0].offset_
529 + rowinfo_[0].ascent_
530 + hlinesep() * rowinfo_[0].lines_
533 dim.des = rowinfo_[nrows() - 1].offset_
534 + rowinfo_[nrows() - 1].descent_
535 + hlinesep() * rowinfo_[nrows()].lines_
540 // Increase ws_[i] for 'R' columns (except the first one)
541 for (int i = 1; i < nc_; ++i)
542 if (align_[i] == 'R')
543 ws_[i] += 10 * df_width;
544 // Increase ws_[i] for 'C' column
545 if (align_[0] == 'C')
546 if (ws_[0] < 7 * workwidth / 8)
547 ws_[0] = 7 * workwidth / 8;
551 for (cxrow = row_.begin(); cxrow; ++cxrow) {
554 for (int i = 0; i < nc_; ++i) {
556 if (cxrow->getTab(i) <= 0) {
557 cxrow->setTab(i, df_width);
565 lf = (ws_[i] - cxrow->getTab(i))/2;
569 lf = ws_[i] - cxrow->getTab(i);
572 if (cxrow == row_.begin())
574 else if (cxrow.is_last())
575 lf = ws_[i] - cxrow->getTab(i);
577 lf = (ws_[i] - cxrow->getTab(i))/2;
580 int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
581 cxrow->setTab(i, lf + rg);
582 rg = ws_[i] - ww + colsep();
583 if (cxrow == row_.begin())
584 width += ws_[i] + colsep();
586 cxrow->setBaseline(cxrow->getBaseline() - ascent);
589 metricsMarkers2(dim);
590 // Cache the inset dimension.
591 setDimCache(mi, dim);
595 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
597 drawWithMargin(pi, x, y, 1, 1);
601 void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
602 int lmargin, int rmargin) const
604 Dimension const dim = dimension(*pi.base.bv);
605 BufferView const & bv = *pi.base.bv;
607 for (idx_type idx = 0; idx < nargs(); ++idx) {
608 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN) {
610 x + lmargin + cellXOffset(bv, idx),
611 y + cellYOffset(idx));
613 // draw inner lines cell by cell because of possible multicolumns
614 // FIXME: multicolumn lines are not yet considered
615 row_type const r = row(idx);
616 col_type const c = col(idx);
617 if (r > 0 && r < nrows()) {
618 for (unsigned int i = 0; i < rowinfo_[r].lines_; ++i) {
619 int yy = y + rowinfo_[r].offset_
620 - rowinfo_[r].ascent_
622 - hlinesep()/2 - rowsep()/2;
624 x + lmargin + colinfo_[c].offset_,
626 x + lmargin + colinfo_[c+1].offset_,
627 yy, Color_foreground);
630 if (c > 0 && c < ncols()) {
631 for (unsigned int i = 0; i < colinfo_[c].lines_; ++i) {
633 + colinfo_[c].offset_
635 - vlinesep()/2 - colsep()/2;
637 rowinfo_[r].offset_ - rowinfo_[r].ascent_,
639 rowinfo_[r].offset_ + rowinfo_[r].descent_,
646 // draw outer lines in one go
647 for (row_type row = 0; row <= nrows(); row += nrows())
648 for (unsigned int i = 0; i < rowinfo_[row].lines_; ++i) {
649 int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
650 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
651 pi.pain.line(x + lmargin + 1, yy,
652 x + dim.width() - rmargin - 1, yy,
656 for (col_type col = 0; col <= ncols(); col += ncols())
657 for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
658 int xx = x + lmargin + colinfo_[col].offset_
659 - i * vlinesep() - vlinesep()/2 - colsep()/2;
660 pi.pain.line(xx, y - dim.ascent() + 1,
661 xx, y + dim.descent() - 1,
664 drawMarkers2(pi, x, y);
668 void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
670 // let the cells adjust themselves
671 for (idx_type i = 0; i < nargs(); ++i)
672 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
673 cell(i).metricsT(mi, dim);
675 // compute absolute sizes of vertical structure
676 for (row_type row = 0; row < nrows(); ++row) {
679 for (col_type col = 0; col < ncols(); ++col) {
680 idx_type const i = index(row, col);
681 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
682 //MathData const & c = cell(i);
685 asc = max(asc, dimc.ascent());
686 desc = max(desc, dimc.descent());
689 rowinfo_[row].ascent_ = asc;
690 rowinfo_[row].descent_ = desc;
692 //rowinfo_[0].ascent_ += hlinesep() * rowinfo_[0].lines_;
693 rowinfo_[nrows()].ascent_ = 0;
694 rowinfo_[nrows()].descent_ = 0;
696 // compute vertical offsets
697 rowinfo_[0].offset_ = 0;
698 for (row_type row = 1; row <= nrows(); ++row) {
699 rowinfo_[row].offset_ =
700 rowinfo_[row - 1].offset_ +
701 rowinfo_[row - 1].descent_ +
702 //rowinfo_[row - 1].skipPixels(mi) +
704 //rowinfo_[row].lines_ * hlinesep() +
705 rowinfo_[row].ascent_;
708 // adjust vertical offset
715 h = rowinfo_[nrows() - 1].offset_;
718 h = rowinfo_[nrows() - 1].offset_ / 2;
720 for (row_type row = 0; row <= nrows(); ++row)
721 rowinfo_[row].offset_ -= h;
724 // compute absolute sizes of horizontal structure
725 for (col_type col = 0; col < ncols(); ++col) {
727 for (row_type row = 0; row < nrows(); ++row) {
729 //idx_type const i = index(row, col);
730 //if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN)
731 // wid = max(wid, cell(i).width());
733 colinfo_[col].width_ = wid;
735 colinfo_[ncols()].width_ = 0;
737 // compute horizontal offsets
738 colinfo_[0].offset_ = border();
739 for (col_type col = 1; col <= ncols(); ++col) {
740 colinfo_[col].offset_ =
741 colinfo_[col - 1].offset_ +
742 colinfo_[col - 1].width_ +
743 displayColSpace(col - 1) +
745 //colinfo_[col].lines_ * vlinesep();
749 dim.wid = colinfo_[ncols() - 1].offset_
750 + colinfo_[ncols() - 1].width_
751 //+ vlinesep() * colinfo_[ncols()].lines_
754 dim.asc = -rowinfo_[0].offset_
755 + rowinfo_[0].ascent_
756 //+ hlinesep() * rowinfo_[0].lines_
759 dim.des = rowinfo_[nrows() - 1].offset_
760 + rowinfo_[nrows() - 1].descent_
761 //+ hlinesep() * rowinfo_[nrows()].lines_
766 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
768 // for (idx_type idx = 0; idx < nargs(); ++idx)
769 // if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
770 // cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
774 void InsetMathGrid::updateBuffer(ParIterator const & it, UpdateType utype)
777 for (idx_type idx = 0; idx < nargs(); ++idx)
778 if (cellinfo_[idx].multi_ != CELL_PART_OF_MULTICOLUMN)
779 cell(idx).updateBuffer(it, utype);
783 docstring InsetMathGrid::eolString(row_type row, bool fragile,
784 bool /*latex*/, bool last_eoln) const
788 if (!rowinfo_[row].crskip_.zero())
789 eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
790 else if(!rowinfo_[row].allow_newpage_)
793 // make sure an upcoming '[' does not break anything
794 if (row + 1 < nrows()) {
795 MathData const & c = cell(index(row + 1, 0));
796 if (!c.empty() && c.front()->getChar() == '[')
801 // only add \\ if necessary
802 if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !last_eoln))
805 return (fragile ? "\\protect\\\\" : "\\\\") + eol;
809 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
811 if (col + 1 == lastcol)
813 return from_ascii(" & ");
817 void InsetMathGrid::addRow(row_type row)
819 rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
821 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData());
823 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
827 void InsetMathGrid::delRow(row_type row)
832 cells_type::iterator it = cells_.begin() + row * ncols();
833 cells_.erase(it, it + ncols());
835 vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
836 cellinfo_.erase(jt, jt + ncols());
838 rowinfo_.erase(rowinfo_.begin() + row);
842 void InsetMathGrid::copyRow(row_type row)
845 for (col_type col = 0; col < ncols(); ++col)
846 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
850 void InsetMathGrid::swapRow(row_type row)
854 if (row + 1 == nrows())
856 for (col_type col = 0; col < ncols(); ++col)
857 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
861 void InsetMathGrid::addCol(col_type newcol)
863 const col_type nc = ncols();
864 const row_type nr = nrows();
865 cells_type new_cells((nc + 1) * nr);
866 vector<CellInfo> new_cellinfo((nc + 1) * nr);
868 for (row_type row = 0; row < nr; ++row)
869 for (col_type col = 0; col < nc; ++col) {
870 new_cells[row * (nc + 1) + col + (col >= newcol)]
871 = cells_[row * nc + col];
872 new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
873 = cellinfo_[row * nc + col];
875 swap(cells_, new_cells);
876 swap(cellinfo_, new_cellinfo);
879 inf.skip_ = defaultColSpace(newcol);
880 inf.align_ = defaultColAlign(newcol);
881 colinfo_.insert(colinfo_.begin() + newcol, inf);
885 void InsetMathGrid::delCol(col_type col)
891 vector<CellInfo> tmpcellinfo;
892 for (col_type i = 0; i < nargs(); ++i)
893 if (i % ncols() != col) {
894 tmpcells.push_back(cells_[i]);
895 tmpcellinfo.push_back(cellinfo_[i]);
897 swap(cells_, tmpcells);
898 swap(cellinfo_, tmpcellinfo);
900 colinfo_.erase(colinfo_.begin() + col);
904 void InsetMathGrid::copyCol(col_type col)
907 for (row_type row = 0; row < nrows(); ++row)
908 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
912 void InsetMathGrid::swapCol(col_type col)
916 if (col + 1 == ncols())
918 for (row_type row = 0; row < nrows(); ++row)
919 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
923 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
925 if (cellinfo_[idx].multi_ == CELL_PART_OF_MULTICOLUMN)
927 col_type c = col(idx);
928 int x = colinfo_[c].offset_;
929 char align = displayColAlign(idx);
930 Dimension const & celldim = cell(idx).dimension(bv);
931 if (align == 'r' || align == 'R')
932 x += cellWidth(idx) - celldim.wid;
933 if (align == 'c' || align == 'C')
934 x += (cellWidth(idx) - celldim.wid) / 2;
939 int InsetMathGrid::cellYOffset(idx_type idx) const
941 return rowinfo_[row(idx)].offset_;
945 int InsetMathGrid::cellWidth(idx_type idx) const
947 switch (cellinfo_[idx].multi_) {
949 return colinfo_[col(idx)].width_;
950 case CELL_BEGIN_OF_MULTICOLUMN: {
951 col_type c1 = col(idx);
952 col_type c2 = c1 + ncellcols(idx);
953 return colinfo_[c2].offset_
954 - colinfo_[c1].offset_
955 - displayColSpace(c2)
957 - colinfo_[c2].lines_ * vlinesep();
959 case CELL_PART_OF_MULTICOLUMN:
966 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
971 cur.idx() -= ncols();
973 if (cur.row() + 1 >= nrows())
975 cur.idx() += ncols();
977 // If we are in a multicolumn cell, move to the "real" cell
978 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
979 LASSERT(cur.idx() > 0, return false);
982 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
987 bool InsetMathGrid::idxBackward(Cursor & cur) const
989 // leave matrix if at the front edge
993 // If we are in a multicolumn cell, move to the "real" cell
994 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
995 LASSERT(cur.idx() > 0, return false);
998 cur.pos() = cur.lastpos();
1003 bool InsetMathGrid::idxForward(Cursor & cur) const
1005 // leave matrix if at the back edge
1006 if (cur.col() + 1 == ncols())
1009 // If we are in a multicolumn cell, move to the next cell
1010 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1011 // leave matrix if at the back edge
1012 if (cur.col() + 1 == ncols())
1021 bool InsetMathGrid::idxFirst(Cursor & cur) const
1028 cur.idx() = (nrows() - 1) * ncols();
1031 cur.idx() = ((nrows() - 1) / 2) * ncols();
1033 // If we are in a multicolumn cell, move to the "real" cell
1034 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1035 LASSERT(cur.idx() > 0, return false);
1043 bool InsetMathGrid::idxLast(Cursor & cur) const
1047 cur.idx() = ncols() - 1;
1050 cur.idx() = nargs() - 1;
1053 cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
1055 // If we are in a multicolumn cell, move to the "real" cell
1056 while (cellinfo_[cur.idx()].multi_ == CELL_PART_OF_MULTICOLUMN) {
1057 LASSERT(cur.idx() > 0, return false);
1060 cur.pos() = cur.lastpos();
1065 bool InsetMathGrid::idxDelete(idx_type & idx)
1067 // nothing to do if we have just one row
1071 // nothing to do if we are in the middle of the last row of the inset
1072 if (idx + ncols() > nargs())
1075 // try to delete entire sequence of ncols() empty cells if possible
1076 for (idx_type i = idx; i < idx + ncols(); ++i)
1077 if (!cell(i).empty())
1080 // move cells if necessary
1081 for (idx_type i = index(row(idx), 0); i < idx; ++i)
1082 swap(cell(i), cell(i + ncols()));
1089 // undo effect of Ctrl-Tab (i.e. pull next cell)
1090 //if (idx + 1 != nargs())
1091 // cell(idx).swap(cell(idx + 1));
1093 // we handled the event..
1098 // reimplement old behaviour when pressing Delete in the last position
1100 void InsetMathGrid::idxGlue(idx_type idx)
1102 col_type c = col(idx);
1103 if (c + 1 == ncols()) {
1104 if (row(idx) + 1 != nrows()) {
1105 for (col_type cc = 0; cc < ncols(); ++cc)
1106 cell(idx).append(cell(idx + cc + 1));
1107 delRow(row(idx) + 1);
1110 idx_type idx_next = idx + 1;
1111 while (idx_next < nargs() &&
1112 cellinfo_[idx_next].multi_ == CELL_PART_OF_MULTICOLUMN)
1114 if (idx_next < nargs())
1115 cell(idx).append(cell(idx_next));
1116 col_type oldcol = c + 1;
1117 for (col_type cc = c + 2; cc < ncols(); ++cc)
1118 cell(idx - oldcol + cc) = cell(idx - oldcol + 1 + cc);
1119 cell(idx - c + ncols() - 1).clear();
1124 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
1126 return rowinfo_[row];
1130 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
1132 return rowinfo_[row];
1136 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
1138 row_type const ri = row(idx);
1139 row_type const r1 = min(row(from), row(to));
1140 row_type const r2 = max(row(from), row(to));
1141 col_type const ci = col(idx);
1142 col_type const c1 = min(col(from), col(to));
1143 col_type const c2 = max(col(from), col(to));
1144 return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
1148 void InsetMathGrid::normalize(NormalStream & os) const
1151 for (row_type row = 0; row < nrows(); ++row) {
1153 for (col_type col = 0; col < ncols(); ++col) {
1154 idx_type const i = index(row, col);
1155 switch (cellinfo_[i].multi_) {
1157 os << "[cell " << cell(i) << ']';
1159 case CELL_BEGIN_OF_MULTICOLUMN:
1160 os << "[cell colspan="
1161 << static_cast<int>(ncellcols(i)) << ' '
1164 case CELL_PART_OF_MULTICOLUMN:
1174 void InsetMathGrid::mathmlize(MathStream & os) const
1176 bool const havetable = nrows() > 1 || ncols() > 1;
1178 os << MTag("mtable");
1179 char const * const celltag = havetable ? "mtd" : "mrow";
1180 for (row_type row = 0; row < nrows(); ++row) {
1183 for (col_type col = 0; col < ncols(); ++col) {
1184 idx_type const i = index(row, col);
1185 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1186 col_type const cellcols = ncellcols(i);
1188 if (havetable && cellcols > 1)
1189 attr << "colspan='" << cellcols << '\'';
1190 os << MTag(celltag, attr.str());
1191 os << cell(index(row, col));
1192 os << ETag(celltag);
1199 os << ETag("mtable");
1204 // We need to do something about alignment here.
1205 void InsetMathGrid::htmlize(HtmlStream & os, string attrib) const
1207 bool const havetable = nrows() > 1 || ncols() > 1;
1209 os << cell(index(0, 0));
1212 os << MTag("table", attrib);
1213 for (row_type row = 0; row < nrows(); ++row) {
1215 for (col_type col = 0; col < ncols(); ++col) {
1216 idx_type const i = index(row, col);
1217 if (cellinfo_[i].multi_ != CELL_PART_OF_MULTICOLUMN) {
1218 col_type const cellcols = ncellcols(i);
1221 attr << "colspan='" << cellcols << '\'';
1222 os << MTag("td", attr.str());
1223 os << cell(index(row, col));
1229 os << ETag("table");
1233 void InsetMathGrid::htmlize(HtmlStream & os) const
1235 htmlize(os, "class='mathtable'");
1239 void InsetMathGrid::write(WriteStream & os) const
1241 write(os, 0, 0, nrows(), ncols());
1244 void InsetMathGrid::write(WriteStream & os,
1245 row_type beg_row, col_type beg_col,
1246 row_type end_row, col_type end_col) const
1248 MathEnsurer ensurer(os, false);
1250 for (row_type row = beg_row; row < end_row; ++row) {
1251 os << verboseHLine(rowinfo_[row].lines_);
1252 // don't write & and empty cells at end of line,
1253 // unless there are vertical lines
1254 col_type lastcol = 0;
1255 bool emptyline = true;
1256 bool last_eoln = true;
1257 for (col_type col = beg_col; col < end_col; ++col) {
1258 idx_type const idx = index(row, col);
1259 bool const empty_cell = cell(idx).empty();
1260 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL)
1262 if (!empty_cell || cellinfo_[idx].multi_ != CELL_NORMAL ||
1263 colinfo_[col + 1].lines_) {
1268 for (col_type col = beg_col; col < end_col;) {
1270 idx_type const idx = index(row, col);
1271 TexRow::RowEntry entry = os.texrow().mathEntry(id(),idx);
1272 os.texrow().startMath(id(),idx);
1273 if (col >= lastcol) {
1277 Changer dummy = os.changeRowEntry(entry);
1278 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1280 while (s < ncols() &&
1281 cellinfo_[index(row, s)].multi_ == CELL_PART_OF_MULTICOLUMN)
1284 os << "\\multicolumn{" << nccols
1285 << "}{" << cellinfo_[idx].align_
1289 if (os.pendingBrace())
1290 ModeSpecifier specifier(os, TEXT_MODE);
1291 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1293 os << eocString(col + nccols - 1, lastcol);
1296 eol = eolString(row, os.fragile(), os.latex(), last_eoln);
1298 // append newline only if line wasn't completely empty
1299 // and the formula is not written on a single line
1300 bool const empty = emptyline && eol.empty();
1301 if (!empty && nrows() > 1)
1304 // @TODO use end_row instead of nrows() ?
1305 docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
1317 int InsetMathGrid::colsep() const
1323 int InsetMathGrid::rowsep() const
1329 int InsetMathGrid::hlinesep() const
1335 int InsetMathGrid::vlinesep() const
1341 int InsetMathGrid::border() const
1347 void InsetMathGrid::splitCell(Cursor & cur)
1349 if (cur.idx() == cur.lastidx())
1351 MathData ar = cur.cell();
1352 ar.erase(0, cur.pos());
1353 cur.cell().erase(cur.pos(), cur.lastpos());
1355 while (cur.idx() << nargs() &&
1356 cellinfo_[cur.idx()].multi_ == CELL_BEGIN_OF_MULTICOLUMN)
1359 cur.cell().insert(0, ar);
1363 char InsetMathGrid::displayColAlign(idx_type idx) const
1365 if (cellinfo_[idx].multi_ == CELL_BEGIN_OF_MULTICOLUMN) {
1366 // align_ may also contain lines like "||r|", so this is
1367 // not complete, but we catch at least the simple cases.
1368 if (cellinfo_[idx].align_ == "c")
1370 if (cellinfo_[idx].align_ == "l")
1372 if (cellinfo_[idx].align_ == "r")
1375 return colinfo_[col(idx)].align_;
1379 int InsetMathGrid::displayColSpace(col_type col) const
1381 return colinfo_[col].skip_;
1384 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1386 //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1388 Parse::flags parseflg = Parse::QUIET | Parse::USETEXT;
1390 FuncCode const act = cmd.action();
1393 // insert file functions
1394 case LFUN_LINE_DELETE_FORWARD:
1395 cur.recordUndoInset();
1396 //autocorrect_ = false;
1404 if (cur.idx() > cur.lastidx())
1405 cur.idx() = cur.lastidx();
1406 if (cur.pos() > cur.lastpos())
1407 cur.pos() = cur.lastpos();
1410 case LFUN_CELL_SPLIT:
1415 case LFUN_CELL_BACKWARD:
1417 cur.selection(false);
1418 if (!idxPrev(cur)) {
1419 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1424 case LFUN_CELL_FORWARD:
1425 // Can't handle selection by additional 'shift' as this is
1426 // hard bound to LFUN_CELL_BACKWARD
1427 cur.selection(false);
1428 if (!idxNext(cur)) {
1429 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1434 case LFUN_NEWLINE_INSERT: {
1435 cur.recordUndoInset();
1436 row_type const r = cur.row();
1440 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1441 swap(cell(index(r, c)), cell(index(r + 1, c)));
1446 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1449 cur.pos() = cur.lastpos();
1450 cur.forceBufferUpdate();
1451 //mathcursor->normalize();
1452 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1456 case LFUN_TABULAR_FEATURE: {
1457 cur.recordUndoInset();
1458 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1459 istringstream is(to_utf8(cmd.argument()));
1462 if (s == "valign-top")
1463 setVerticalAlignment('t');
1464 else if (s == "valign-middle")
1465 setVerticalAlignment('c');
1466 else if (s == "valign-bottom")
1467 setVerticalAlignment('b');
1468 else if (s == "align-left")
1469 setHorizontalAlignment('l', cur.col());
1470 else if (s == "align-right")
1471 setHorizontalAlignment('r', cur.col());
1472 else if (s == "align-center")
1473 setHorizontalAlignment('c', cur.col());
1474 else if (s == "append-row")
1475 for (int i = 0, n = extractInt(is); i < n; ++i)
1477 else if (s == "delete-row") {
1478 cur.clearSelection(); // bug 4323
1479 for (int i = 0, n = extractInt(is); i < n; ++i) {
1481 if (cur.idx() >= nargs())
1482 cur.idx() -= ncols();
1484 cur.pos() = 0; // trick, see below
1486 else if (s == "copy-row") {
1487 // Here (as later) we save the cursor col/row
1488 // in order to restore it after operation.
1489 row_type const r = cur.row();
1490 col_type const c = cur.col();
1491 for (int i = 0, n = extractInt(is); i < n; ++i)
1493 cur.idx() = index(r, c);
1495 else if (s == "swap-row") {
1497 // Trick to suppress same-idx-means-different-cell
1501 else if (s == "add-hline-above")
1502 rowinfo_[cur.row()].lines_++;
1503 else if (s == "add-hline-below")
1504 rowinfo_[cur.row()+1].lines_++;
1505 else if (s == "delete-hline-above")
1506 rowinfo_[cur.row()].lines_--;
1507 else if (s == "delete-hline-below")
1508 rowinfo_[cur.row()+1].lines_--;
1509 else if (s == "append-column") {
1510 row_type const r = cur.row();
1511 col_type const c = cur.col();
1512 for (int i = 0, n = extractInt(is); i < n; ++i)
1513 addCol(cur.col() + 1);
1514 cur.idx() = index(r, c);
1516 else if (s == "delete-column") {
1517 cur.clearSelection(); // bug 4323
1518 row_type const r = cur.row();
1519 col_type const c = cur.col();
1520 for (int i = 0, n = extractInt(is); i < n; ++i)
1521 delCol(col(cur.idx()));
1522 cur.idx() = index(r, min(c, cur.ncols() - 1));
1523 cur.pos() = 0; // trick, see above
1525 else if (s == "copy-column") {
1526 row_type const r = cur.row();
1527 col_type const c = cur.col();
1529 cur.idx() = index(r, c);
1531 else if (s == "swap-column") {
1533 cur.pos() = 0; // trick, see above
1535 else if (s == "add-vline-left") {
1536 colinfo_[cur.col()].lines_++;
1537 if (!colinfo_[cur.col()].special_.empty())
1538 colinfo_[cur.col()].special_ += '|';
1540 else if (s == "add-vline-right") {
1541 colinfo_[cur.col()+1].lines_++;
1542 if (!colinfo_[cur.col()+1].special_.empty())
1543 colinfo_[cur.col()+1].special_.insert(0, 1, '|');
1545 else if (s == "delete-vline-left") {
1546 colinfo_[cur.col()].lines_--;
1547 docstring & special = colinfo_[cur.col()].special_;
1548 if (!special.empty()) {
1549 docstring::size_type i = special.rfind('|');
1550 LASSERT(i != docstring::npos, break);
1551 special.erase(i, 1);
1554 else if (s == "delete-vline-right") {
1555 colinfo_[cur.col()+1].lines_--;
1556 docstring & special = colinfo_[cur.col()+1].special_;
1557 if (!special.empty()) {
1558 docstring::size_type i = special.find('|');
1559 LASSERT(i != docstring::npos, break);
1560 special.erase(i, 1);
1567 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1568 //lyxerr << "returning FINISHED_LEFT" << endl;
1572 case LFUN_CLIPBOARD_PASTE:
1573 parseflg |= Parse::VERBATIM;
1576 if (cur.currentMode() <= TEXT_MODE)
1577 parseflg |= Parse::TEXTMODE;
1578 cur.message(_("Paste"));
1579 cap::replaceSelection(cur);
1581 if (cmd.argument().empty() && !theClipboard().isInternal())
1582 topaste = theClipboard().getAsText(Clipboard::PlainTextType);
1584 idocstringstream is(cmd.argument());
1587 topaste = cap::selection(n, buffer().params().documentClassPtr());
1589 InsetMathGrid grid(buffer_, 1, 1);
1590 if (!topaste.empty())
1591 if ((topaste.size() == 1 && isAscii(topaste))
1592 || !mathed_parse_normal(grid, topaste, parseflg)) {
1594 mathed_parse_normal(grid, topaste, parseflg | Parse::VERBATIM);
1597 bool hline_enabled = false;
1598 FuncRequest fr = FuncRequest(LFUN_TABULAR_FEATURE, "add-hline-above");
1600 if (getStatus(cur, fr, status))
1601 hline_enabled = status.enabled();
1602 if (grid.nargs() == 1) {
1603 // single cell/part of cell
1604 cur.recordUndoInset();
1605 cur.cell().insert(cur.pos(), grid.cell(0));
1606 cur.pos() += grid.cell(0).size();
1608 rowinfo_[cur.row()].lines_ += grid.rowinfo_[0].lines_;
1610 for (unsigned int l = 0; l < grid.rowinfo_[0].lines_; ++l) {
1611 cur.cell().insert(0,
1612 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1618 cur.recordUndoInset();
1619 col_type const numcols =
1620 min(grid.ncols(), ncols() - col(cur.idx()));
1621 row_type const numrows =
1622 min(grid.nrows(), nrows() - cur.row());
1623 for (row_type r = 0; r < numrows; ++r) {
1624 for (col_type c = 0; c < numcols; ++c) {
1625 idx_type i = index(r + cur.row(), c + col(cur.idx()));
1626 cell(i).insert(0, grid.cell(grid.index(r, c)));
1629 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1631 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1632 idx_type i = index(r + cur.row(), 0);
1634 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1637 // append the left over horizontal cells to the last column
1638 idx_type i = index(r + cur.row(), ncols() - 1);
1639 for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
1640 cell(i).append(grid.cell(grid.index(r, c)));
1642 // append the left over vertical cells to the last _cell_
1643 idx_type i = nargs() - 1;
1644 for (row_type r = numrows; r < grid.nrows(); ++r) {
1645 for (col_type c = 0; c < grid.ncols(); ++c)
1646 cell(i).append(grid.cell(grid.index(r, c)));
1648 rowinfo_[r].lines_ += grid.rowinfo_[r].lines_;
1650 for (unsigned int l = 0; l < grid.rowinfo_[r].lines_; ++l) {
1652 MathAtom(new InsetMathUnknown(from_ascii("\\hline"))));
1657 cur.clearSelection(); // bug 393
1658 // FIXME audit setBuffer calls
1659 cur.inset().setBuffer(*buffer_);
1660 cur.forceBufferUpdate();
1665 case LFUN_LINE_BEGIN:
1666 case LFUN_WORD_BACKWARD:
1667 case LFUN_WORD_LEFT:
1668 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1670 case LFUN_LINE_BEGIN_SELECT:
1671 case LFUN_WORD_BACKWARD_SELECT:
1672 case LFUN_WORD_LEFT_SELECT:
1673 cur.selHandle(act == LFUN_WORD_BACKWARD_SELECT ||
1674 act == LFUN_WORD_LEFT_SELECT ||
1675 act == LFUN_LINE_BEGIN_SELECT);
1676 cur.macroModeClose();
1677 if (cur.pos() != 0) {
1679 } else if (cur.idx() % cur.ncols() != 0) {
1680 cur.idx() -= cur.idx() % cur.ncols();
1682 } else if (cur.idx() != 0) {
1686 cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1691 case LFUN_WORD_FORWARD:
1692 case LFUN_WORD_RIGHT:
1694 cur.screenUpdateFlags(Update::Decoration | Update::FitCursor);
1696 case LFUN_WORD_FORWARD_SELECT:
1697 case LFUN_WORD_RIGHT_SELECT:
1698 case LFUN_LINE_END_SELECT:
1699 cur.selHandle(act == LFUN_WORD_FORWARD_SELECT ||
1700 act == LFUN_WORD_RIGHT_SELECT ||
1701 act == LFUN_LINE_END_SELECT);
1702 cur.macroModeClose();
1704 if (cur.pos() != cur.lastpos()) {
1705 cur.pos() = cur.lastpos();
1706 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1707 cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1708 cur.pos() = cur.lastpos();
1709 } else if (cur.idx() != cur.lastidx()) {
1710 cur.idx() = cur.lastidx();
1711 cur.pos() = cur.lastpos();
1713 cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1719 InsetMathNest::doDispatch(cur, cmd);
1724 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1725 FuncStatus & status) const
1727 switch (cmd.action()) {
1728 case LFUN_TABULAR_FEATURE: {
1729 string s = cmd.getArg(0);
1730 if (&cur.inset() != this) {
1731 // Table actions requires that the cursor is _inside_ the
1733 status.setEnabled(false);
1734 status.message(from_utf8(N_("Cursor not in table")));
1737 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1738 status.setEnabled(false);
1739 status.message(from_utf8(N_("Only one row")));
1743 (s == "delete-column" || s == "swap-column")) {
1744 status.setEnabled(false);
1745 status.message(from_utf8(N_("Only one column")));
1748 if ((rowinfo_[cur.row()].lines_ == 0 &&
1749 s == "delete-hline-above") ||
1750 (rowinfo_[cur.row() + 1].lines_ == 0 &&
1751 s == "delete-hline-below")) {
1752 status.setEnabled(false);
1753 status.message(from_utf8(N_("No hline to delete")));
1757 if ((colinfo_[cur.col()].lines_ == 0 &&
1758 s == "delete-vline-left") ||
1759 (colinfo_[cur.col() + 1].lines_ == 0 &&
1760 s == "delete-vline-right")) {
1761 status.setEnabled(false);
1762 status.message(from_utf8(N_("No vline to delete")));
1765 if (s == "valign-top" || s == "valign-middle" ||
1766 s == "valign-bottom" || s == "align-left" ||
1767 s == "align-right" || s == "align-center") {
1768 status.setEnabled(true);
1769 char const ha = horizontalAlignment(cur.col());
1770 char const va = verticalAlignment();
1771 status.setOnOff((s == "align-left" && ha == 'l')
1772 || (s == "align-right" && ha == 'r')
1773 || (s == "align-center" && ha == 'c')
1774 || (s == "valign-top" && va == 't')
1775 || (s == "valign-bottom" && va == 'b')
1776 || (s == "valign-middle" && va == 'c'));
1779 if (s == "append-row" || s == "delete-row" ||
1780 s == "copy-row" || s == "swap-row" ||
1781 s == "add-hline-above" || s == "add-hline-below" ||
1782 s == "delete-hline-above" || s == "delete-hline-below" ||
1783 s == "append-column" || s == "delete-column" ||
1784 s == "copy-column" || s == "swap-column" ||
1785 s == "add-vline-left" || s == "add-vline-right" ||
1786 s == "delete-vline-left" || s == "delete-vline-right") {
1787 status.setEnabled(true);
1789 status.setEnabled(false);
1790 status.message(bformat(
1791 from_utf8(N_("Unknown tabular feature '%1$s'")),
1796 // FIXME: What did this code do?
1797 // Please check whether it is still needed!
1798 // should be more precise
1799 if (v_align_ == '\0') {
1800 status.enable(true);
1803 if (cmd.argument().empty()) {
1804 status.enable(false);
1807 if (!contains("tcb", cmd.argument()[0])) {
1808 status.enable(false);
1811 status.setOnOff(cmd.argument()[0] == v_align_);
1812 status.setEnabled(true);
1817 case LFUN_CELL_SPLIT:
1818 status.setEnabled(cur.idx() != cur.lastidx());
1821 case LFUN_CELL_BACKWARD:
1822 case LFUN_CELL_FORWARD:
1823 status.setEnabled(true);
1829 return InsetMathNest::getStatus(cur, cmd, status);
1834 char InsetMathGrid::colAlign(HullType type, col_type col)
1838 return "rcl"[col % 3];
1849 return "rl"[col & 1];
1864 int InsetMathGrid::colSpace(HullType type, col_type col)
1866 int alignInterSpace = 0;
1881 alignInterSpace = 20;
1884 alignInterSpace = 0;
1887 alignInterSpace = 40;
1891 alignInterSpace = 60;
1894 return (col % 2) ? alignInterSpace : 0;