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