]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathGrid.cpp
1e4f2e8dff13a123a49db640cade9202f532c83a
[lyx.git] / src / mathed / InsetMathGrid.cpp
1 /**
2  * \file InsetMathGrid.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12 #include <algorithm>
13
14 #include "InsetMathGrid.h"
15
16 #include "MathData.h"
17 #include "MathParser.h"
18 #include "MathStream.h"
19 #include "MetricsInfo.h"
20
21 #include "BufferView.h"
22 #include "CutAndPaste.h"
23 #include "FuncStatus.h"
24 #include "Cursor.h"
25 #include "FuncRequest.h"
26
27 #include "frontends/Clipboard.h"
28 #include "frontends/Painter.h"
29
30 #include "support/debug.h"
31 #include "support/docstream.h"
32 #include "support/gettext.h"
33 #include "support/lstrings.h"
34
35 #include "support/lassert.h"
36
37 #include <sstream>
38
39 using namespace std;
40 using namespace lyx::support;
41
42
43 namespace lyx {
44
45 static docstring verboseHLine(int n)
46 {
47         docstring res;
48         for (int i = 0; i < n; ++i)
49                 res += "\\hline";
50         if (n)
51                 res += ' ';
52         return res;
53 }
54
55
56 static int extractInt(istream & is)
57 {
58         int num = 1;
59         is >> num;
60         return (num == 0) ? 1 : num;
61 }
62
63
64
65 //////////////////////////////////////////////////////////////
66
67
68 InsetMathGrid::CellInfo::CellInfo()
69         : dummy_(false)
70 {}
71
72
73
74 //////////////////////////////////////////////////////////////
75
76
77 InsetMathGrid::RowInfo::RowInfo()
78         : lines_(0), skip_(0), allow_newpage_(true)
79 {}
80
81
82
83 int InsetMathGrid::RowInfo::skipPixels() const
84 {
85         return crskip_.inBP();
86 }
87
88
89
90 //////////////////////////////////////////////////////////////
91
92
93 InsetMathGrid::ColInfo::ColInfo()
94         : align_('c'), lines_(0)
95 {}
96
97
98 //////////////////////////////////////////////////////////////
99
100
101 InsetMathGrid::InsetMathGrid()
102         : InsetMathNest(1),
103           rowinfo_(1 + 1),
104                 colinfo_(1 + 1),
105                 cellinfo_(1),
106                 v_align_('c')
107 {
108         setDefaults();
109 }
110
111
112 InsetMathGrid::InsetMathGrid(col_type m, row_type n)
113         : InsetMathNest(m * n),
114           rowinfo_(n + 1),
115                 colinfo_(m + 1),
116                 cellinfo_(m * n),
117                 v_align_('c')
118 {
119         setDefaults();
120 }
121
122
123 InsetMathGrid::InsetMathGrid(col_type m, row_type n, char v, docstring const & h)
124         : InsetMathNest(m * n),
125           rowinfo_(n + 1),
126           colinfo_(m + 1),
127                 cellinfo_(m * n),
128                 v_align_(v)
129 {
130         setDefaults();
131         setVerticalAlignment(v);
132         setHorizontalAlignments(h);
133 }
134
135
136 Inset * InsetMathGrid::clone() const
137 {
138         return new InsetMathGrid(*this);
139 }
140
141
142 InsetMath::idx_type InsetMathGrid::index(row_type row, col_type col) const
143 {
144         return col + ncols() * row;
145 }
146
147
148 void InsetMathGrid::setDefaults()
149 {
150         if (ncols() <= 0)
151                 lyxerr << "positive number of columns expected" << endl;
152         //if (nrows() <= 0)
153         //      lyxerr << "positive number of rows expected" << endl;
154         for (col_type col = 0; col < ncols(); ++col) {
155                 colinfo_[col].align_ = defaultColAlign(col);
156                 colinfo_[col].skip_  = defaultColSpace(col);
157                 colinfo_[col].special_.clear();
158         }
159 }
160
161
162 void InsetMathGrid::setHorizontalAlignments(docstring const & hh)
163 {
164         col_type col = 0;
165         for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it) {
166                 char_type c = *it;
167                 if (c == '|') {
168                         colinfo_[col].lines_++;
169                 } else if ((c == 'p' || c == 'm' || c == 'b'||
170                             c == '!' || c == '@' || c == '>' || c == '<') &&
171                            it + 1 != hh.end() && *(it + 1) == '{') {
172                         // @{decl.} and p{width} are standard LaTeX, the
173                         // others are extensions by array.sty
174                         bool const newcolumn = c == 'p' || c == 'm' || c == 'b';
175                         if (newcolumn) {
176                                 // this declares a new column
177                                 if (col >= ncols())
178                                         // Only intercolumn stuff is allowed
179                                         // in the last dummy column
180                                         break;
181                                 colinfo_[col].align_ = 'l';
182                         } else {
183                                 // this is intercolumn stuff
184                                 if (colinfo_[col].special_.empty())
185                                         // Overtake possible lines
186                                         colinfo_[col].special_ = docstring(colinfo_[col].lines_, '|');
187                         }
188                         int brace_open = 0;
189                         int brace_close = 0;
190                         while (it != hh.end()) {
191                                 c = *it;
192                                 colinfo_[col].special_ += c;
193                                 if (c == '{')
194                                         ++brace_open;
195                                 else if (c == '}')
196                                         ++brace_close;
197                                 ++it;
198                                 if (brace_open > 0 && brace_open == brace_close)
199                                         break;
200                         }
201                         --it;
202                         if (newcolumn) {
203                                 colinfo_[col].lines_ = count(
204                                         colinfo_[col].special_.begin(),
205                                         colinfo_[col].special_.end(), '|');
206                                 LYXERR(Debug::MATHED, "special column separator: `"
207                                         << to_utf8(colinfo_[col].special_) << '\'');
208                                 ++col;
209                                 colinfo_[col].lines_ = 0;
210                                 colinfo_[col].special_.clear();
211                         }
212                 } else if (col >= ncols()) {
213                         // Only intercolumn stuff is allowed in the last
214                         // dummy column
215                         break;
216                 } else if (c == 'c' || c == 'l' || c == 'r') {
217                         colinfo_[col].align_ = static_cast<char>(c);
218                         if (!colinfo_[col].special_.empty()) {
219                                 colinfo_[col].special_ += c;
220                                 colinfo_[col].lines_ = count(
221                                                 colinfo_[col].special_.begin(),
222                                                 colinfo_[col].special_.end(), '|');
223                                 LYXERR(Debug::MATHED, "special column separator: `"
224                                         << to_utf8(colinfo_[col].special_) << '\'');
225                         }
226                         ++col;
227                         colinfo_[col].lines_ = 0;
228                         colinfo_[col].special_.clear();
229                 } else {
230                         lyxerr << "unknown column separator: '" << c << "'" << endl;
231                 }
232         }
233
234 /*
235         col_type n = hh.size();
236         if (n > ncols())
237                 n = ncols();
238         for (col_type col = 0; col < n; ++col)
239                 colinfo_[col].align_ = hh[col];
240 */
241 }
242
243
244 InsetMathGrid::col_type InsetMathGrid::guessColumns(docstring const & hh)
245 {
246         col_type col = 0;
247         for (docstring::const_iterator it = hh.begin(); it != hh.end(); ++it)
248                 if (*it == 'c' || *it == 'l' || *it == 'r'||
249                     *it == 'p' || *it == 'm' || *it == 'b')
250                         ++col;
251         // let's have at least one column, even if we did not recognize its
252         // alignment
253         if (col == 0)
254                 col = 1;
255         return col;
256 }
257
258
259 void InsetMathGrid::setHorizontalAlignment(char h, col_type col)
260 {
261         colinfo_[col].align_ = h;
262         if (!colinfo_[col].special_.empty()) {
263                 char_type & c = colinfo_[col].special_[colinfo_[col].special_.size() - 1];
264                 if (c == 'l' || c == 'c' || c == 'r')
265                         c = h;
266         }
267         // FIXME: Change alignment of p, m and b columns, too
268 }
269
270
271 char InsetMathGrid::horizontalAlignment(col_type col) const
272 {
273         return colinfo_[col].align_;
274 }
275
276
277 docstring InsetMathGrid::horizontalAlignments() const
278 {
279         docstring res;
280         for (col_type col = 0; col < ncols(); ++col) {
281                 if (colinfo_[col].special_.empty()) {
282                         res += docstring(colinfo_[col].lines_, '|');
283                         res += colinfo_[col].align_;
284                 } else
285                         res += colinfo_[col].special_;
286         }
287         if (colinfo_[ncols()].special_.empty())
288                 return res + docstring(colinfo_[ncols()].lines_, '|');
289         return res + colinfo_[ncols()].special_;
290 }
291
292
293 void InsetMathGrid::setVerticalAlignment(char c)
294 {
295         v_align_ = c;
296 }
297
298
299 char InsetMathGrid::verticalAlignment() const
300 {
301         return v_align_;
302 }
303
304
305 InsetMathGrid::col_type InsetMathGrid::ncols() const
306 {
307         return colinfo_.size() - 1;
308 }
309
310
311 InsetMathGrid::row_type InsetMathGrid::nrows() const
312 {
313         return rowinfo_.size() - 1;
314 }
315
316
317 InsetMathGrid::col_type InsetMathGrid::col(idx_type idx) const
318 {
319         return idx % ncols();
320 }
321
322
323 InsetMathGrid::row_type InsetMathGrid::row(idx_type idx) const
324 {
325         return idx / ncols();
326 }
327
328
329 void InsetMathGrid::vcrskip(Length const & crskip, row_type row)
330 {
331         rowinfo_[row].crskip_ = crskip;
332 }
333
334
335 Length InsetMathGrid::vcrskip(row_type row) const
336 {
337         return rowinfo_[row].crskip_;
338 }
339
340
341 void InsetMathGrid::metrics(MetricsInfo & mi, Dimension & dim) const
342 {
343         // let the cells adjust themselves
344         InsetMathNest::metrics(mi);
345
346         BufferView & bv = *mi.base.bv;
347
348         // compute absolute sizes of vertical structure
349         for (row_type row = 0; row < nrows(); ++row) {
350                 int asc  = 0;
351                 int desc = 0;
352                 for (col_type col = 0; col < ncols(); ++col) {
353                         Dimension const & dimc = cell(index(row, col)).dimension(bv);
354                         asc  = max(asc,  dimc.asc);
355                         desc = max(desc, dimc.des);
356                 }
357                 rowinfo_[row].ascent_  = asc;
358                 rowinfo_[row].descent_ = desc;
359         }
360         rowinfo_[0].ascent_       += hlinesep() * rowinfo_[0].lines_;
361         rowinfo_[nrows()].ascent_  = 0;
362         rowinfo_[nrows()].descent_ = 0;
363
364         // compute vertical offsets
365         rowinfo_[0].offset_ = 0;
366         for (row_type row = 1; row <= nrows(); ++row) {
367                 rowinfo_[row].offset_  =
368                         rowinfo_[row - 1].offset_  +
369                         rowinfo_[row - 1].descent_ +
370                         rowinfo_[row - 1].skipPixels() +
371                         rowsep() +
372                         rowinfo_[row].lines_ * hlinesep() +
373                         rowinfo_[row].ascent_;
374         }
375
376         // adjust vertical offset
377         int h = 0;
378         switch (v_align_) {
379                 case 't':
380                         h = 0;
381                         break;
382                 case 'b':
383                         h = rowinfo_[nrows() - 1].offset_;
384                         break;
385                 default:
386                         h = rowinfo_[nrows() - 1].offset_ / 2;
387         }
388         for (row_type row = 0; row <= nrows(); ++row)
389                 rowinfo_[row].offset_ -= h;
390
391
392         // compute absolute sizes of horizontal structure
393         for (col_type col = 0; col < ncols(); ++col) {
394                 int wid = 0;
395                 for (row_type row = 0; row < nrows(); ++row)
396                         wid = max(wid, cell(index(row, col)).dimension(bv).wid);
397                 colinfo_[col].width_ = wid;
398         }
399         colinfo_[ncols()].width_  = 0;
400
401         // compute horizontal offsets
402         colinfo_[0].offset_ = border();
403         for (col_type col = 1; col <= ncols(); ++col) {
404                 colinfo_[col].offset_ =
405                         colinfo_[col - 1].offset_ +
406                         colinfo_[col - 1].width_ +
407                         colinfo_[col - 1].skip_ +
408                         colsep() +
409                         colinfo_[col].lines_ * vlinesep();
410         }
411
412
413         dim.wid   =   colinfo_[ncols() - 1].offset_
414                        + colinfo_[ncols() - 1].width_
415                  + vlinesep() * colinfo_[ncols()].lines_
416                        + border();
417
418         dim.asc  = - rowinfo_[0].offset_
419                        + rowinfo_[0].ascent_
420                  + hlinesep() * rowinfo_[0].lines_
421                        + border();
422
423         dim.des =   rowinfo_[nrows() - 1].offset_
424                        + rowinfo_[nrows() - 1].descent_
425                  + hlinesep() * rowinfo_[nrows()].lines_
426                        + border();
427
428
429 /*
430         // Increase ws_[i] for 'R' columns (except the first one)
431         for (int i = 1; i < nc_; ++i)
432                 if (align_[i] == 'R')
433                         ws_[i] += 10 * df_width;
434         // Increase ws_[i] for 'C' column
435         if (align_[0] == 'C')
436                 if (ws_[0] < 7 * workwidth / 8)
437                         ws_[0] = 7 * workwidth / 8;
438
439         // Adjust local tabs
440         width = colsep();
441         for (cxrow = row_.begin(); cxrow; ++cxrow) {
442                 int rg = COLSEP;
443                 int lf = 0;
444                 for (int i = 0; i < nc_; ++i) {
445                         bool isvoid = false;
446                         if (cxrow->getTab(i) <= 0) {
447                                 cxrow->setTab(i, df_width);
448                                 isvoid = true;
449                         }
450                         switch (align_[i]) {
451                         case 'l':
452                                 lf = 0;
453                                 break;
454                         case 'c':
455                                 lf = (ws_[i] - cxrow->getTab(i))/2;
456                                 break;
457                         case 'r':
458                         case 'R':
459                                 lf = ws_[i] - cxrow->getTab(i);
460                                 break;
461                         case 'C':
462                                 if (cxrow == row_.begin())
463                                         lf = 0;
464                                 else if (cxrow.is_last())
465                                         lf = ws_[i] - cxrow->getTab(i);
466                                 else
467                                         lf = (ws_[i] - cxrow->getTab(i))/2;
468                                 break;
469                         }
470                         int const ww = (isvoid) ? lf : lf + cxrow->getTab(i);
471                         cxrow->setTab(i, lf + rg);
472                         rg = ws_[i] - ww + colsep();
473                         if (cxrow == row_.begin())
474                                 width += ws_[i] + colsep();
475                 }
476                 cxrow->setBaseline(cxrow->getBaseline() - ascent);
477         }
478 */
479         metricsMarkers2(dim);
480         // Cache the inset dimension. 
481         setDimCache(mi, dim);
482 }
483
484
485 void InsetMathGrid::draw(PainterInfo & pi, int x, int y) const
486 {
487         drawWithMargin(pi, x, y, 1, 1);
488 }
489
490
491 void InsetMathGrid::drawWithMargin(PainterInfo & pi, int x, int y,
492         int lmargin, int rmargin) const
493 {
494         Dimension const dim = dimension(*pi.base.bv);
495         BufferView const & bv = *pi.base.bv;
496
497         for (idx_type idx = 0; idx < nargs(); ++idx)
498                 cell(idx).draw(pi, x + lmargin + cellXOffset(bv, idx),
499                         y + cellYOffset(idx));
500
501         for (row_type row = 0; row <= nrows(); ++row)
502                 for (unsigned int i = 0; i < rowinfo_[row].lines_; ++i) {
503                         int yy = y + rowinfo_[row].offset_ - rowinfo_[row].ascent_
504                                 - i * hlinesep() - hlinesep()/2 - rowsep()/2;
505                         pi.pain.line(x + lmargin + 1, yy,
506                                      x + dim.width() - rmargin - 1, yy,
507                                      Color_foreground);
508                 }
509
510         for (col_type col = 0; col <= ncols(); ++col)
511                 for (unsigned int i = 0; i < colinfo_[col].lines_; ++i) {
512                         int xx = x + lmargin + colinfo_[col].offset_
513                                 - i * vlinesep() - vlinesep()/2 - colsep()/2;
514                         pi.pain.line(xx, y - dim.ascent() + 1,
515                                      xx, y + dim.descent() - 1,
516                                      Color_foreground);
517                 }
518         drawMarkers2(pi, x, y);
519 }
520
521
522 void InsetMathGrid::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
523 {
524         // let the cells adjust themselves
525         //InsetMathNest::metrics(mi);
526         for (idx_type i = 0; i < nargs(); ++i)
527                 cell(i).metricsT(mi, dim);
528
529         // compute absolute sizes of vertical structure
530         for (row_type row = 0; row < nrows(); ++row) {
531                 int asc  = 0;
532                 int desc = 0;
533                 for (col_type col = 0; col < ncols(); ++col) {
534                         //MathData const & c = cell(index(row, col));
535                         // FIXME: BROKEN!
536                         Dimension dimc;
537                         asc  = max(asc,  dimc.ascent());
538                         desc = max(desc, dimc.descent());
539                 }
540                 rowinfo_[row].ascent_  = asc;
541                 rowinfo_[row].descent_ = desc;
542         }
543         //rowinfo_[0].ascent_       += hlinesep() * rowinfo_[0].lines_;
544         rowinfo_[nrows()].ascent_  = 0;
545         rowinfo_[nrows()].descent_ = 0;
546
547         // compute vertical offsets
548         rowinfo_[0].offset_ = 0;
549         for (row_type row = 1; row <= nrows(); ++row) {
550                 rowinfo_[row].offset_  =
551                         rowinfo_[row - 1].offset_  +
552                         rowinfo_[row - 1].descent_ +
553                         //rowinfo_[row - 1].skipPixels() +
554                         1 + //rowsep() +
555                         //rowinfo_[row].lines_ * hlinesep() +
556                         rowinfo_[row].ascent_;
557         }
558
559         // adjust vertical offset
560         int h = 0;
561         switch (v_align_) {
562                 case 't':
563                         h = 0;
564                         break;
565                 case 'b':
566                         h = rowinfo_[nrows() - 1].offset_;
567                         break;
568                 default:
569                         h = rowinfo_[nrows() - 1].offset_ / 2;
570         }
571         for (row_type row = 0; row <= nrows(); ++row)
572                 rowinfo_[row].offset_ -= h;
573
574
575         // compute absolute sizes of horizontal structure
576         for (col_type col = 0; col < ncols(); ++col) {
577                 int wid = 0;
578                 for (row_type row = 0; row < nrows(); ++row) {
579                         // FIXME: BROKEN!
580                         //wid = max(wid, cell(index(row, col)).width());
581                 }
582                 colinfo_[col].width_ = wid;
583         }
584         colinfo_[ncols()].width_  = 0;
585
586         // compute horizontal offsets
587         colinfo_[0].offset_ = border();
588         for (col_type col = 1; col <= ncols(); ++col) {
589                 colinfo_[col].offset_ =
590                         colinfo_[col - 1].offset_ +
591                         colinfo_[col - 1].width_ +
592                         colinfo_[col - 1].skip_ +
593                         1 ; //colsep() +
594                         //colinfo_[col].lines_ * vlinesep();
595         }
596
597
598         dim.wid  =  colinfo_[ncols() - 1].offset_
599                        + colinfo_[ncols() - 1].width_
600                  //+ vlinesep() * colinfo_[ncols()].lines_
601                        + 2;
602
603         dim.asc  = -rowinfo_[0].offset_
604                        + rowinfo_[0].ascent_
605                  //+ hlinesep() * rowinfo_[0].lines_
606                        + 1;
607
608         dim.des  =  rowinfo_[nrows() - 1].offset_
609                        + rowinfo_[nrows() - 1].descent_
610                  //+ hlinesep() * rowinfo_[nrows()].lines_
611                        + 1;
612 }
613
614
615 void InsetMathGrid::drawT(TextPainter & /*pain*/, int /*x*/, int /*y*/) const
616 {
617 //      for (idx_type idx = 0; idx < nargs(); ++idx)
618 //              cell(idx).drawT(pain, x + cellXOffset(idx), y + cellYOffset(idx));
619 }
620
621
622 docstring InsetMathGrid::eolString(row_type row, bool emptyline, bool fragile) const
623 {
624         docstring eol;
625
626         if (!rowinfo_[row].crskip_.zero())
627                 eol += '[' + from_utf8(rowinfo_[row].crskip_.asLatexString()) + ']';
628         else if(!rowinfo_[row].allow_newpage_)
629                 eol += '*';
630
631         // make sure an upcoming '[' does not break anything
632         if (row + 1 < nrows()) {
633                 MathData const & c = cell(index(row + 1, 0));
634                 if (c.size() && c.front()->getChar() == '[')
635                         //eol += "[0pt]";
636                         eol += "{}";
637         }
638
639         // only add \\ if necessary
640         if (eol.empty() && row + 1 == nrows() && (nrows() == 1 || !emptyline))
641                 return docstring();
642
643         return (fragile ? "\\protect\\\\" : "\\\\") + eol;
644 }
645
646
647 docstring InsetMathGrid::eocString(col_type col, col_type lastcol) const
648 {
649         if (col + 1 == lastcol)
650                 return docstring();
651         return from_ascii(" & ");
652 }
653
654
655 void InsetMathGrid::addRow(row_type row)
656 {
657         rowinfo_.insert(rowinfo_.begin() + row + 1, RowInfo());
658         cells_.insert
659                 (cells_.begin() + (row + 1) * ncols(), ncols(), MathData());
660         cellinfo_.insert
661                 (cellinfo_.begin() + (row + 1) * ncols(), ncols(), CellInfo());
662 }
663
664
665 void InsetMathGrid::appendRow()
666 {
667         rowinfo_.push_back(RowInfo());
668         //cells_.insert(cells_.end(), ncols(), MathData());
669         for (col_type col = 0; col < ncols(); ++col) {
670                 cells_.push_back(cells_type::value_type());
671                 cellinfo_.push_back(CellInfo());
672         }
673 }
674
675
676 void InsetMathGrid::delRow(row_type row)
677 {
678         if (nrows() == 1)
679                 return;
680
681         cells_type::iterator it = cells_.begin() + row * ncols();
682         cells_.erase(it, it + ncols());
683
684         vector<CellInfo>::iterator jt = cellinfo_.begin() + row * ncols();
685         cellinfo_.erase(jt, jt + ncols());
686
687         rowinfo_.erase(rowinfo_.begin() + row);
688 }
689
690
691 void InsetMathGrid::copyRow(row_type row)
692 {
693         addRow(row);
694         for (col_type col = 0; col < ncols(); ++col)
695                 cells_[(row + 1) * ncols() + col] = cells_[row * ncols() + col];
696 }
697
698
699 void InsetMathGrid::swapRow(row_type row)
700 {
701         if (nrows() == 1)
702                 return;
703         if (row + 1 == nrows())
704                 --row;
705         for (col_type col = 0; col < ncols(); ++col)
706                 swap(cells_[row * ncols() + col], cells_[(row + 1) * ncols() + col]);
707 }
708
709
710 void InsetMathGrid::addCol(col_type newcol)
711 {
712         const col_type nc = ncols();
713         const row_type nr = nrows();
714         cells_type new_cells((nc + 1) * nr);
715         vector<CellInfo> new_cellinfo((nc + 1) * nr);
716
717         for (row_type row = 0; row < nr; ++row)
718                 for (col_type col = 0; col < nc; ++col) {
719                         new_cells[row * (nc + 1) + col + (col >= newcol)]
720                                 = cells_[row * nc + col];
721                         new_cellinfo[row * (nc + 1) + col + (col >= newcol)]
722                                 = cellinfo_[row * nc + col];
723                 }
724         swap(cells_, new_cells);
725         swap(cellinfo_, new_cellinfo);
726
727         ColInfo inf;
728         inf.skip_  = defaultColSpace(newcol);
729         inf.align_ = defaultColAlign(newcol);
730         colinfo_.insert(colinfo_.begin() + newcol, inf);
731 }
732
733
734 void InsetMathGrid::delCol(col_type col)
735 {
736         if (ncols() == 1)
737                 return;
738
739         cells_type tmpcells;
740         vector<CellInfo> tmpcellinfo;
741         for (col_type i = 0; i < nargs(); ++i)
742                 if (i % ncols() != col) {
743                         tmpcells.push_back(cells_[i]);
744                         tmpcellinfo.push_back(cellinfo_[i]);
745                 }
746         swap(cells_, tmpcells);
747         swap(cellinfo_, tmpcellinfo);
748
749         colinfo_.erase(colinfo_.begin() + col);
750 }
751
752
753 void InsetMathGrid::copyCol(col_type col)
754 {
755         addCol(col);
756         for (row_type row = 0; row < nrows(); ++row)
757                 cells_[row * ncols() + col + 1] = cells_[row * ncols() + col];
758 }
759
760
761 void InsetMathGrid::swapCol(col_type col)
762 {
763         if (ncols() == 1)
764                 return;
765         if (col + 1 == ncols())
766                 --col;
767         for (row_type row = 0; row < nrows(); ++row)
768                 swap(cells_[row * ncols() + col], cells_[row * ncols() + col + 1]);
769 }
770
771
772 int InsetMathGrid::cellXOffset(BufferView const & bv, idx_type idx) const
773 {
774         col_type c = col(idx);
775         int x = colinfo_[c].offset_;
776         char align = colinfo_[c].align_;
777         Dimension const & celldim = cell(idx).dimension(bv);
778         if (align == 'r' || align == 'R')
779                 x += colinfo_[c].width_ - celldim.wid;
780         if (align == 'c' || align == 'C')
781                 x += (colinfo_[c].width_ - celldim.wid) / 2;
782         return x;
783 }
784
785
786 int InsetMathGrid::cellYOffset(idx_type idx) const
787 {
788         return rowinfo_[row(idx)].offset_;
789 }
790
791
792 bool InsetMathGrid::idxUpDown(Cursor & cur, bool up) const
793 {
794         if (up) {
795                 if (cur.row() == 0)
796                         return false;
797                 cur.idx() -= ncols();
798         } else {
799                 if (cur.row() + 1 >= nrows())
800                         return false;
801                 cur.idx() += ncols();
802         }
803         cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target() - cur.cell().xo(cur.bv()));
804         return true;
805 }
806
807
808 bool InsetMathGrid::idxBackward(Cursor & cur) const
809 {
810         // leave matrix if at the front edge
811         if (cur.col() == 0)
812                 return false;
813         --cur.idx();
814         cur.pos() = cur.lastpos();
815         return true;
816 }
817
818
819 bool InsetMathGrid::idxForward(Cursor & cur) const
820 {
821         // leave matrix if at the back edge
822         if (cur.col() + 1 == ncols())
823                 return false;
824         ++cur.idx();
825         cur.pos() = 0;
826         return true;
827 }
828
829
830 bool InsetMathGrid::idxFirst(Cursor & cur) const
831 {
832         switch (v_align_) {
833                 case 't':
834                         cur.idx() = 0;
835                         break;
836                 case 'b':
837                         cur.idx() = (nrows() - 1) * ncols();
838                         break;
839                 default:
840                         cur.idx() = ((nrows() - 1) / 2) * ncols();
841         }
842         cur.pos() = 0;
843         return true;
844 }
845
846
847 bool InsetMathGrid::idxLast(Cursor & cur) const
848 {
849         switch (v_align_) {
850                 case 't':
851                         cur.idx() = ncols() - 1;
852                         break;
853                 case 'b':
854                         cur.idx() = nargs() - 1;
855                         break;
856                 default:
857                         cur.idx() = ((nrows() - 1) / 2 + 1) * ncols() - 1;
858         }
859         cur.pos() = cur.lastpos();
860         return true;
861 }
862
863
864 bool InsetMathGrid::idxDelete(idx_type & idx)
865 {
866         // nothing to do if we have just one row
867         if (nrows() == 1)
868                 return false;
869
870         // nothing to do if we are in the middle of the last row of the inset
871         if (idx + ncols() > nargs())
872                 return false;
873
874         // try to delete entire sequence of ncols() empty cells if possible
875         for (idx_type i = idx; i < idx + ncols(); ++i)
876                 if (cell(i).size())
877                         return false;
878
879         // move cells if necessary
880         for (idx_type i = index(row(idx), 0); i < idx; ++i)
881                 swap(cell(i), cell(i + ncols()));
882
883         delRow(row(idx));
884
885         if (idx >= nargs())
886                 idx = nargs() - 1;
887
888         // undo effect of Ctrl-Tab (i.e. pull next cell)
889         //if (idx + 1 != nargs())
890         //      cell(idx).swap(cell(idx + 1));
891
892         // we handled the event..
893         return true;
894 }
895
896
897 // reimplement old behaviour when pressing Delete in the last position
898 // of a cell
899 void InsetMathGrid::idxGlue(idx_type idx)
900 {
901         col_type c = col(idx);
902         if (c + 1 == ncols()) {
903                 if (row(idx) + 1 != nrows()) {
904                         for (col_type cc = 0; cc < ncols(); ++cc)
905                                 cell(idx).append(cell(idx + cc + 1));
906                         delRow(row(idx) + 1);
907                 }
908         } else {
909                 cell(idx).append(cell(idx + 1));
910                 for (col_type cc = c + 2; cc < ncols(); ++cc)
911                         cell(idx - c + cc - 1) = cell(idx - c + cc);
912                 cell(idx - c + ncols() - 1).clear();
913         }
914 }
915
916
917 InsetMathGrid::RowInfo const & InsetMathGrid::rowinfo(row_type row) const
918 {
919         return rowinfo_[row];
920 }
921
922
923 InsetMathGrid::RowInfo & InsetMathGrid::rowinfo(row_type row)
924 {
925         return rowinfo_[row];
926 }
927
928
929 bool InsetMathGrid::idxBetween(idx_type idx, idx_type from, idx_type to) const
930 {
931         row_type const ri = row(idx);
932         row_type const r1 = min(row(from), row(to));
933         row_type const r2 = max(row(from), row(to));
934         col_type const ci = col(idx);
935         col_type const c1 = min(col(from), col(to));
936         col_type const c2 = max(col(from), col(to));
937         return r1 <= ri && ri <= r2 && c1 <= ci && ci <= c2;
938 }
939
940
941
942 void InsetMathGrid::normalize(NormalStream & os) const
943 {
944         os << "[grid ";
945         for (row_type row = 0; row < nrows(); ++row) {
946                 os << "[row ";
947                 for (col_type col = 0; col < ncols(); ++col)
948                         os << "[cell " << cell(index(row, col)) << ']';
949                 os << ']';
950         }
951         os << ']';
952 }
953
954
955 void InsetMathGrid::mathmlize(MathStream & os) const
956 {
957         os << MTag("mtable");
958         for (row_type row = 0; row < nrows(); ++row) {
959                 os << MTag("mtr");
960                 for (col_type col = 0; col < ncols(); ++col)
961                         os << cell(index(row, col));
962                 os << ETag("mtr");
963         }
964         os << ETag("mtable");
965 }
966
967
968 void InsetMathGrid::write(WriteStream & os) const
969 {
970         bool brace = os.pendingBrace();
971         os.pendingBrace(false);
972
973         docstring eol;
974         for (row_type row = 0; row < nrows(); ++row) {
975                 os << verboseHLine(rowinfo_[row].lines_);
976                 // don't write & and empty cells at end of line
977                 col_type lastcol = 0;
978                 bool emptyline = true;
979                 for (col_type col = 0; col < ncols(); ++col)
980                         if (!cell(index(row, col)).empty()) {
981                                 lastcol = col + 1;
982                                 emptyline = false;
983                         }
984                 for (col_type col = 0; col < lastcol; ++col) {
985                         os << cell(index(row, col));
986                         if (os.pendingBrace()) {
987                                 os.pendingBrace(false);
988                                 os.textMode(true);
989                                 os << '}';
990                         }
991                         os << eocString(col, lastcol);
992                 }
993                 eol = eolString(row, emptyline, os.fragile());
994                 os << eol;
995                 // append newline only if line wasn't completely empty
996                 // and this was not the last line in the grid
997                 if (!emptyline && row + 1 < nrows())
998                         os << "\n";
999         }
1000         docstring const s = verboseHLine(rowinfo_[nrows()].lines_);
1001         if (!s.empty()) {
1002                 if (eol.empty()) {
1003                         if (os.fragile())
1004                                 os << "\\protect";
1005                         os << "\\\\";
1006                 }
1007                 os << s;
1008         }
1009
1010         os.pendingBrace(brace);
1011 }
1012
1013
1014 int InsetMathGrid::colsep() const
1015 {
1016         return 6;
1017 }
1018
1019
1020 int InsetMathGrid::rowsep() const
1021 {
1022         return 6;
1023 }
1024
1025
1026 int InsetMathGrid::hlinesep() const
1027 {
1028         return 3;
1029 }
1030
1031
1032 int InsetMathGrid::vlinesep() const
1033 {
1034         return 3;
1035 }
1036
1037
1038 int InsetMathGrid::border() const
1039 {
1040         return 1;
1041 }
1042
1043
1044 void InsetMathGrid::splitCell(Cursor & cur)
1045 {
1046         if (cur.idx() == cur.lastidx())
1047                 return;
1048         MathData ar = cur.cell();
1049         ar.erase(0, cur.pos());
1050         cur.cell().erase(cur.pos(), cur.lastpos());
1051         ++cur.idx();
1052         cur.pos() = 0;
1053         cur.cell().insert(0, ar);
1054 }
1055
1056
1057 void InsetMathGrid::doDispatch(Cursor & cur, FuncRequest & cmd)
1058 {
1059         //lyxerr << "*** InsetMathGrid: request: " << cmd << endl;
1060         switch (cmd.action) {
1061
1062         // insert file functions
1063         case LFUN_LINE_DELETE:
1064                 // FIXME: We use recordUndoInset when a change reflects more
1065                 // than one cell, because recordUndo does not work for
1066                 // multiple cells. Unfortunately this puts the cursor in front
1067                 // of the inset after undo. This is (especilally for large
1068                 // grids) annoying.
1069                 cur.recordUndoInset();
1070                 //autocorrect_ = false;
1071                 //macroModeClose();
1072                 //if (selection_) {
1073                 //      selDel();
1074                 //      break;
1075                 //}
1076                 if (nrows() > 1)
1077                         delRow(cur.row());
1078                 if (cur.idx() > cur.lastidx())
1079                         cur.idx() = cur.lastidx();
1080                 if (cur.pos() > cur.lastpos())
1081                         cur.pos() = cur.lastpos();
1082                 break;
1083
1084         case LFUN_CELL_SPLIT:
1085                 cur.recordUndo();
1086                 splitCell(cur);
1087                 break;
1088
1089         case LFUN_CELL_BACKWARD:
1090                 // See below.
1091                 cur.selection() = false;
1092                 if (!idxPrev(cur)) {
1093                         cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1094                         cur.undispatched();
1095                 }
1096                 break;
1097
1098         case LFUN_CELL_FORWARD:
1099                 // Can't handle selection by additional 'shift' as this is
1100                 // hard bound to LFUN_CELL_BACKWARD
1101                 cur.selection() = false;
1102                 if (!idxNext(cur)) {
1103                         cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1104                         cur.undispatched();
1105                 }
1106                 break;
1107
1108         case LFUN_NEWLINE_INSERT: {
1109                 cur.recordUndoInset();
1110                 row_type const r = cur.row();
1111                 addRow(r);
1112
1113                 // split line
1114                 for (col_type c = col(cur.idx()) + 1; c < ncols(); ++c)
1115                         swap(cell(index(r, c)), cell(index(r + 1, c)));
1116
1117                 // split cell
1118                 splitCell(cur);
1119                 swap(cell(cur.idx()), cell(cur.idx() + ncols() - 1));
1120                 if (cur.idx() > 0)
1121                         --cur.idx();
1122                 cur.pos() = cur.lastpos();
1123
1124                 //mathcursor->normalize();
1125                 //cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1126                 break;
1127         }
1128
1129         case LFUN_TABULAR_FEATURE: {
1130                 cur.recordUndoInset();
1131                 //lyxerr << "handling tabular-feature " << to_utf8(cmd.argument()) << endl;
1132                 istringstream is(to_utf8(cmd.argument()));
1133                 string s;
1134                 is >> s;
1135                 if (s == "valign-top")
1136                         setVerticalAlignment('t');
1137                 else if (s == "valign-middle")
1138                         setVerticalAlignment('c');
1139                 else if (s == "valign-bottom")
1140                         setVerticalAlignment('b');
1141                 else if (s == "align-left")
1142                         setHorizontalAlignment('l', cur.col());
1143                 else if (s == "align-right")
1144                         setHorizontalAlignment('r', cur.col());
1145                 else if (s == "align-center")
1146                         setHorizontalAlignment('c', cur.col());
1147                 else if (s == "append-row")
1148                         for (int i = 0, n = extractInt(is); i < n; ++i)
1149                                 addRow(cur.row());
1150                 else if (s == "delete-row") {
1151                         cur.clearSelection(); // bug 4323
1152                         for (int i = 0, n = extractInt(is); i < n; ++i) {
1153                                 delRow(cur.row());
1154                                 if (cur.idx() >= nargs())
1155                                         cur.idx() -= ncols();
1156                         }
1157                         cur.pos() = 0; // trick, see below
1158                 }
1159                 else if (s == "copy-row") {
1160                         // Here (as later) we save the cursor col/row
1161                         // in order to restore it after operation.
1162                         row_type const r = cur.row();
1163                         col_type const c = cur.col();
1164                         for (int i = 0, n = extractInt(is); i < n; ++i)
1165                                 copyRow(cur.row());
1166                         cur.idx() = index(r, c);
1167                 }
1168                 else if (s == "swap-row") {
1169                         swapRow(cur.row());
1170                         // Trick to suppress same-idx-means-different-cell
1171                         // assertion crash:
1172                         cur.pos() = 0;
1173                 }
1174                 else if (s == "add-hline-above")
1175                         rowinfo_[cur.row()].lines_++;
1176                 else if (s == "add-hline-below")
1177                         rowinfo_[cur.row()+1].lines_++;
1178                 else if (s == "delete-hline-above")
1179                         rowinfo_[cur.row()].lines_--;
1180                 else if (s == "delete-hline-below")
1181                         rowinfo_[cur.row()+1].lines_--;
1182                 else if (s == "append-column") {
1183                         row_type const r = cur.row();
1184                         col_type const c = cur.col();
1185                         for (int i = 0, n = extractInt(is); i < n; ++i)
1186                                 addCol(cur.col() + 1);
1187                         cur.idx() = index(r, c);
1188                 }
1189                 else if (s == "delete-column") {
1190                         cur.clearSelection(); // bug 4323
1191                         row_type const r = cur.row();
1192                         col_type const c = cur.col();
1193                         for (int i = 0, n = extractInt(is); i < n; ++i)
1194                                 delCol(col(cur.idx()));
1195                         cur.idx() = index(r, min(c, cur.ncols() - 1));
1196                         cur.pos() = 0; // trick, see above
1197                 }
1198                 else if (s == "copy-column") {
1199                         row_type const r = cur.row();
1200                         col_type const c = cur.col();
1201                         copyCol(cur.col());
1202                         cur.idx() = index(r, c);
1203                 }
1204                 else if (s == "swap-column") {
1205                         swapCol(cur.col());
1206                         cur.pos() = 0; // trick, see above
1207                 }
1208                 else if (s == "add-vline-left") {
1209                         colinfo_[cur.col()].lines_++;
1210                         if (!colinfo_[cur.col()].special_.empty())
1211                                 colinfo_[cur.col()].special_ += '|';
1212                 }
1213                 else if (s == "add-vline-right") {
1214                         colinfo_[cur.col()+1].lines_++;
1215                         if (!colinfo_[cur.col()+1].special_.empty())
1216                                 colinfo_[cur.col()+1].special_.insert(0, 1, '|');
1217                 }
1218                 else if (s == "delete-vline-left") {
1219                         colinfo_[cur.col()].lines_--;
1220                         docstring & special = colinfo_[cur.col()].special_;
1221                         if (!special.empty()) {
1222                                 docstring::size_type i = special.rfind('|');
1223                                 LASSERT(i != docstring::npos, /**/);
1224                                 special.erase(i, 1);
1225                         }
1226                 }
1227                 else if (s == "delete-vline-right") {
1228                         colinfo_[cur.col()+1].lines_--;
1229                         docstring & special = colinfo_[cur.col()+1].special_;
1230                         if (!special.empty()) {
1231                                 docstring::size_type i = special.find('|');
1232                                 LASSERT(i != docstring::npos, /**/);
1233                                 special.erase(i, 1);
1234                         }
1235                 }
1236                 else {
1237                         cur.undispatched();
1238                         break;
1239                 }
1240                 // perhaps this should be FINISHED_BACKWARD -- just for clarity?
1241                 lyxerr << "returning FINISHED_LEFT" << endl;
1242                 break;
1243         }
1244
1245         case LFUN_PASTE: {
1246                 cur.message(_("Paste"));
1247                 cap::replaceSelection(cur);
1248                 docstring topaste;
1249                 if (cmd.argument().empty() && !theClipboard().isInternal())
1250                         topaste = theClipboard().getAsText();
1251                 else {
1252                         idocstringstream is(cmd.argument());
1253                         int n = 0;
1254                         is >> n;
1255                         topaste = cap::selection(n);
1256                 }
1257                 InsetMathGrid grid(1, 1);
1258                 if (!topaste.empty())
1259                         mathed_parse_normal(grid, topaste);
1260
1261                 if (grid.nargs() == 1) {
1262                         // single cell/part of cell
1263                         cur.recordUndo();
1264                         cur.cell().insert(cur.pos(), grid.cell(0));
1265                         cur.pos() += grid.cell(0).size();
1266                 } else {
1267                         // multiple cells
1268                         cur.recordUndoInset();
1269                         col_type const numcols =
1270                                 min(grid.ncols(), ncols() - col(cur.idx()));
1271                         row_type const numrows =
1272                                 min(grid.nrows(), nrows() - cur.row());
1273                         for (row_type r = 0; r < numrows; ++r) {
1274                                 for (col_type c = 0; c < numcols; ++c) {
1275                                         idx_type i = index(r + cur.row(), c + col(cur.idx()));
1276                                         cell(i).insert(0, grid.cell(grid.index(r, c)));
1277                                 }
1278                                 // append the left over horizontal cells to the last column
1279                                 idx_type i = index(r + cur.row(), ncols() - 1);
1280                                 for (InsetMath::col_type c = numcols; c < grid.ncols(); ++c)
1281                                         cell(i).append(grid.cell(grid.index(r, c)));
1282                         }
1283                         // append the left over vertical cells to the last _cell_
1284                         idx_type i = nargs() - 1;
1285                         for (row_type r = numrows; r < grid.nrows(); ++r)
1286                                 for (col_type c = 0; c < grid.ncols(); ++c)
1287                                         cell(i).append(grid.cell(grid.index(r, c)));
1288                 }
1289                 cur.clearSelection(); // bug 393
1290                 cur.finishUndo();
1291                 break;
1292         }
1293
1294         case LFUN_LINE_BEGIN_SELECT:
1295         case LFUN_LINE_BEGIN:
1296         case LFUN_WORD_BACKWARD_SELECT:
1297         case LFUN_WORD_BACKWARD:
1298         case LFUN_WORD_LEFT_SELECT:
1299         case LFUN_WORD_LEFT:
1300                 cur.selHandle(cmd.action == LFUN_WORD_BACKWARD_SELECT ||
1301                                 cmd.action == LFUN_WORD_LEFT_SELECT ||
1302                                 cmd.action == LFUN_LINE_BEGIN_SELECT);
1303                 cur.macroModeClose();
1304                 if (cur.pos() != 0) {
1305                         cur.pos() = 0;
1306                 } else if (cur.idx() % cur.ncols() != 0) {
1307                         cur.idx() -= cur.idx() % cur.ncols();
1308                         cur.pos() = 0;
1309                 } else if (cur.idx() != 0) {
1310                         cur.idx() = 0;
1311                         cur.pos() = 0;
1312                 } else {
1313                         cmd = FuncRequest(LFUN_FINISHED_BACKWARD);
1314                         cur.undispatched();
1315                 }
1316                 break;
1317
1318         case LFUN_WORD_FORWARD_SELECT:
1319         case LFUN_WORD_FORWARD:
1320         case LFUN_WORD_RIGHT_SELECT:
1321         case LFUN_WORD_RIGHT:
1322         case LFUN_LINE_END_SELECT:
1323         case LFUN_LINE_END:
1324                 cur.selHandle(cmd.action == LFUN_WORD_FORWARD_SELECT ||
1325                                 cmd.action == LFUN_WORD_RIGHT_SELECT ||
1326                                 cmd.action == LFUN_LINE_END_SELECT);
1327                 cur.macroModeClose();
1328                 cur.clearTargetX();
1329                 if (cur.pos() != cur.lastpos()) {
1330                         cur.pos() = cur.lastpos();
1331                 } else if ((cur.idx() + 1) % cur.ncols() != 0) {
1332                         cur.idx() += cur.ncols() - 1 - cur.idx() % cur.ncols();
1333                         cur.pos() = cur.lastpos();
1334                 } else if (cur.idx() != cur.lastidx()) {
1335                         cur.idx() = cur.lastidx();
1336                         cur.pos() = cur.lastpos();
1337                 } else {
1338                         cmd = FuncRequest(LFUN_FINISHED_FORWARD);
1339                         cur.undispatched();
1340                 }
1341                 break;
1342
1343         default:
1344                 InsetMathNest::doDispatch(cur, cmd);
1345         }
1346 }
1347
1348
1349 bool InsetMathGrid::getStatus(Cursor & cur, FuncRequest const & cmd,
1350                 FuncStatus & status) const
1351 {
1352         switch (cmd.action) {
1353         case LFUN_TABULAR_FEATURE: {
1354                 string const s = to_utf8(cmd.argument());
1355                 if (nrows() <= 1 && (s == "delete-row" || s == "swap-row")) {
1356                         status.setEnabled(false);
1357                         status.message(from_utf8(N_("Only one row")));
1358                         return true;
1359                 }
1360                 if (ncols() <= 1 &&
1361                     (s == "delete-column" || s == "swap-column")) {
1362                         status.setEnabled(false);
1363                         status.message(from_utf8(N_("Only one column")));
1364                         return true;
1365                 }
1366                 if ((rowinfo_[cur.row()].lines_ == 0 &&
1367                      s == "delete-hline-above") ||
1368                     (rowinfo_[cur.row() + 1].lines_ == 0 &&
1369                      s == "delete-hline-below")) {
1370                         status.setEnabled(false);
1371                         status.message(from_utf8(N_("No hline to delete")));
1372                         return true;
1373                 }
1374
1375                 if ((colinfo_[cur.col()].lines_ == 0 &&
1376                      s == "delete-vline-left") ||
1377                     (colinfo_[cur.col() + 1].lines_ == 0 &&
1378                      s == "delete-vline-right")) {
1379                         status.setEnabled(false);
1380                         status.message(from_utf8(N_("No vline to delete")));
1381                         return true;
1382                 }
1383                 if (s == "valign-top" || s == "valign-middle" ||
1384                     s == "valign-bottom" || s == "align-left" ||
1385                     s == "align-right" || s == "align-center" ||
1386                     s == "append-row" || s == "delete-row" ||
1387                     s == "copy-row" || s == "swap-row" ||
1388                     s == "add-hline-above" || s == "add-hline-below" ||
1389                     s == "delete-hline-above" || s == "delete-hline-below" ||
1390                     s == "append-column" || s == "delete-column" ||
1391                     s == "copy-column" || s == "swap-column" ||
1392                     s == "add-vline-left" || s == "add-vline-right" ||
1393                     s == "delete-vline-left" || s == "delete-vline-right")
1394                         status.setEnabled(true);
1395                 else {
1396                         status.setEnabled(false);
1397                         status.message(bformat(
1398                                 from_utf8(N_("Unknown tabular feature '%1$s'")), lyx::from_ascii(s)));
1399                 }
1400
1401                 char const ha = horizontalAlignment(cur.col());
1402                 char const va = verticalAlignment();
1403                 status.setOnOff((s == "align-left" && ha == 'l')
1404                            || (s == "align-right"   && ha == 'r')
1405                            || (s == "align-center"  && ha == 'c')
1406                            || (s == "valign-top"    && va == 't')
1407                            || (s == "valign-bottom" && va == 'b')
1408                            || (s == "valign-middle" && va == 'm'));
1409
1410 #if 0
1411                 // FIXME: What did this code do?
1412                 // Please check whether it is still needed!
1413                 // should be more precise
1414                 if (v_align_ == '\0') {
1415                         status.enable(true);
1416                         break;
1417                 }
1418                 if (cmd.argument().empty()) {
1419                         status.enable(false);
1420                         break;
1421                 }
1422                 if (!contains("tcb", cmd.argument()[0])) {
1423                         status.enable(false);
1424                         break;
1425                 }
1426                 status.setOnOff(cmd.argument()[0] == v_align_);
1427                 status.setEnabled(true);
1428 #endif
1429                 return true;
1430         }
1431
1432         case LFUN_CELL_SPLIT:
1433                 status.setEnabled(true);
1434                 return true;
1435
1436         case LFUN_CELL_BACKWARD:
1437         case LFUN_CELL_FORWARD:
1438                 status.setEnabled(true);
1439                 return true;
1440
1441         default:
1442                 return InsetMathNest::getStatus(cur, cmd, status);
1443         }
1444 }
1445
1446
1447 } // namespace lyx