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