]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathGrid.h
Don't parse multicolumn if the grid does not support it
[lyx.git] / src / mathed / InsetMathGrid.h
1 // -*- C++ -*-
2 /**
3  * \file InsetMathGrid.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef MATH_GRID_H
13 #define MATH_GRID_H
14
15 #include "InsetMathNest.h"
16 #include "Length.h"
17
18
19 namespace lyx {
20
21
22 /** Gridded math inset base class.
23  *  This is the base to all grid-like editable math objects
24  */
25 class InsetMathGrid : public InsetMathNest {
26 public:
27
28         enum Multicolumn {
29                 /// A normal cell
30                 CELL_NORMAL = 0,
31                 /// A multicolumn cell. The number of columns is <tt>1 + number
32                 /// of CELL_PART_OF_MULTICOLUMN cells</tt> that follow directly
33                 CELL_BEGIN_OF_MULTICOLUMN = 1,
34                 /// This is a dummy cell (part of a multicolumn cell)
35                 CELL_PART_OF_MULTICOLUMN = 2
36         };
37
38         /// additional per-cell information
39         class CellInfo {
40         public:
41                 ///
42                 CellInfo();
43                 /// multicolumn flag
44                 Multicolumn multi_;
45                 /// special multi colums alignment
46                 docstring align_;
47         };
48
49         /// additional per-row information
50         class RowInfo {
51         public:
52                 ///
53                 RowInfo();
54                 ///
55                 int skipPixels(MetricsInfo const & mi) const;
56                 /// cached descent
57                 mutable int descent_;
58                 /// cached ascent
59                 mutable int ascent_;
60                 /// cached offset
61                 mutable int offset_;
62                 /// how many hlines above this row?
63                 unsigned int lines_;
64                 /// parameter to the line break
65                 Length crskip_;
66                 /// extra distance between lines
67                 int skip_;
68                 /// Is a page break allowed after this row?
69                 bool allow_newpage_;
70         };
71
72         // additional per-row information
73         class ColInfo {
74         public:
75                 ///
76                 ColInfo();
77                 /// currently possible: 'l', 'c', 'r'
78                 char align_;
79                 /// cached width
80                 mutable int width_;
81                 /// cached offset
82                 mutable int offset_;
83                 /// how many lines to the left of this column?
84                 unsigned int lines_;
85                 /// additional amount to the right to be skipped when drawing
86                 int skip_;
87                 /// Special alignment.
88                 /// This does also contain align_ and lines_ if it is nonempty.
89                 /// It needs to be in sync with align_ and lines_ because some
90                 /// code only uses align_ and lines_.
91                 docstring special_;
92         };
93
94 public:
95         /// sets nrows and ncols to 1, vertical alingment to 'c'
96         InsetMathGrid(Buffer * buf);
97         /// Note: columns first!
98         InsetMathGrid(Buffer * buf, col_type m, row_type n);
99         ///
100         InsetMathGrid(Buffer * buf, col_type m, row_type n, char valign,
101                 docstring const & halign);
102         ///
103         void metrics(MetricsInfo & mi, Dimension &) const;
104         ///
105         void draw(PainterInfo & pi, int x, int y) const;
106         /// draw decorations.
107         void drawDecoration(PainterInfo & pi, int x, int y) const
108         { drawMarkers2(pi, x, y); }
109         ///
110         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
111         ///
112         void drawT(TextPainter & pi, int x, int y) const;
113         ///
114         void updateBuffer(ParIterator const &, UpdateType);
115         /// extract number of columns from alignment string
116         static col_type guessColumns(docstring const & halign);
117         /// accepts some LaTeX column codes: p,m,!,@,M,<,>
118         void setHorizontalAlignments(docstring const & align);
119         ///
120         void setHorizontalAlignment(char c, col_type col);
121         ///
122         char horizontalAlignment(col_type col) const;
123         ///
124         docstring horizontalAlignments() const;
125         /// 't', 'b', or 'm'
126         void setVerticalAlignment(char c);
127         ///
128         char verticalAlignment() const;
129         ///
130         void vcrskip(Length const &, row_type row);
131         ///
132         Length vcrskip(row_type row) const;
133         ///
134         void resize(short int type, col_type cols);
135         ///
136         const RowInfo & rowinfo(row_type row) const;
137         /// returns topmost row if passed (-1)
138         RowInfo & rowinfo(row_type row);
139         ///
140         const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
141         ///
142         CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
143         /// identifies GridInset
144         InsetMathGrid * asGridInset() { return this; }
145         /// identifies GridInset
146         InsetMathGrid const * asGridInset() const { return this; }
147         //
148         bool isTable() const { return true; }
149         ///
150         col_type ncols() const;
151         ///
152         row_type nrows() const;
153         ///
154         col_type col(idx_type idx) const;
155         ///
156         row_type row(idx_type idx) const;
157         /// number of columns of cell \p idx
158         col_type ncellcols(idx_type idx) const;
159
160         ///
161         bool idxUpDown(Cursor &, bool up) const;
162         ///
163         bool idxBackward(Cursor &) const;
164         ///
165         bool idxForward(Cursor &) const;
166         ///
167         bool idxFirst(Cursor &) const;
168         ///
169         bool idxLast(Cursor &) const;
170         ///
171         bool idxDelete(idx_type & idx);
172         /// pulls cell after pressing erase
173         void idxGlue(idx_type idx);
174
175         /// add a row, one row down
176         virtual void addRow(row_type r);
177         /// delete a row
178         virtual void delRow(row_type r);
179         /// copy a row
180         virtual void copyRow(row_type r);
181         /// swap two rows
182         virtual void swapRow(row_type r);
183         /// add a column, here
184         virtual void addCol(col_type c);
185         /// delete a column
186         virtual void delCol(col_type c);
187         /// copy a column
188         virtual void copyCol(col_type c);
189         /// swap two columns
190         virtual void swapCol(col_type c);
191         ///
192         idx_type index(row_type r, col_type c) const;
193         ///
194         bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
195         ///
196         virtual int defaultColSpace(col_type) { return 0; }
197         ///
198         virtual char defaultColAlign(col_type) { return 'c'; }
199         ///
200         void setDefaults();
201         ///
202         virtual bool interpretString(Cursor & cur, docstring const & str);
203
204         ///
205         virtual int colsep() const;
206         ///
207         virtual int rowsep() const;
208         ///
209         virtual int hlinesep() const;
210         ///
211         virtual int vlinesep() const;
212         ///
213         virtual int border() const;
214         ///
215         virtual bool handlesMulticolumn() const { return false; }
216
217         ///
218         void write(WriteStream & os) const;
219         ///
220         void write(WriteStream & os,
221                    row_type beg_row, col_type beg_col,
222                    row_type end_row, col_type end_col) const;
223         ///
224         void normalize(NormalStream &) const;
225         ///
226         //void maple(MapleStream &) const;
227         ///
228         void mathmlize(MathStream &) const;
229         /// 
230         void htmlize(HtmlStream &) const;
231         ///
232         void htmlize(HtmlStream &, std::string attrib) const;
233         ///
234         void validate(LaTeXFeatures & features) const;
235         ///
236         //void octave(OctaveStream &) const;
237
238 protected:
239         ///
240         void doDispatch(Cursor & cur, FuncRequest & cmd);
241         ///
242         bool getStatus(Cursor & cur, FuncRequest const & cmd,
243                 FuncStatus & flag) const;
244         /// returns x offset of cell compared to inset
245         int cellXOffset(BufferView const &, idx_type idx) const;
246         /// returns y offset of cell compared to inset
247         int cellYOffset(idx_type idx) const;
248         /// Width of cell, taking combined columns into account
249         int cellWidth(idx_type idx) const;
250         ///
251         virtual int leftMargin() const { return 1; }
252         ///
253         virtual int rightMargin() const { return 1; }
254
255         /// returns proper 'end of line' code for LaTeX
256         virtual docstring eolString(row_type row, bool fragile, bool latex,
257                         bool last_eoln) const;
258         /// returns proper 'end of column' code for LaTeX
259         virtual docstring eocString(col_type col, col_type lastcol) const;
260         /// splits cells and shifts right part to the next cell
261         void splitCell(Cursor & cur);
262         /// Column alignment for display of cell \p idx.
263         /// Must not be written to file!
264         virtual char displayColAlign(idx_type idx) const;
265         /// Column spacing for display of column \p col.
266         /// Must not be written to file!
267         virtual int displayColSpace(col_type col) const;
268
269         // The following two functions are used in InsetMathHull and
270         // InsetMathSplit.
271         /// The value of a fixed col align for a certain hull type 
272         static char colAlign(HullType type, col_type col);
273         /// The value of a fixed col spacing for a certain hull type
274         static int colSpace(HullType type, col_type col);
275
276         /// positions of vertical and horizontal lines
277         int vLineHOffset(col_type col, unsigned int line) const;
278         int hLineVOffset(row_type row, unsigned int line) const;
279
280         /// row info.
281         /// rowinfo_[nrows()] is a dummy row used only for hlines.
282         std::vector<RowInfo> rowinfo_;
283         /// column info.
284         /// colinfo_[ncols()] is a dummy column used only for vlines.
285         std::vector<ColInfo> colinfo_;
286         /// cell info
287         std::vector<CellInfo> cellinfo_;
288         ///
289         InsetCode lyxCode() const { return MATH_GRID_CODE; }
290
291 private:
292         ///
293         char v_align_; // FIXME: add approp. type
294         ///
295         Inset * clone() const;
296 };
297
298
299 } // namespace lyx
300
301 #endif