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