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