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