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