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