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