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