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