3 * \file InsetMathGrid.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "InsetMathNest.h"
22 /** Gridded math inset base class.
23 * This is the base to all grid-like editable math objects
25 class InsetMathGrid : public InsetMathNest {
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
38 /// additional per-cell information
45 /// special multi colums alignment
49 /// additional per-row information
55 int skipPixels(MetricsInfo const & mi) const;
62 /// how many hlines above this row?
64 /// parameter to the line break
66 /// extra distance between lines
68 /// Is a page break allowed after this row?
72 // additional per-row information
77 /// currently possible: 'l', 'c', 'r'
83 /// how many lines to the left of this column?
85 /// additional amount to the right to be skipped when drawing
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_.
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);
100 InsetMathGrid(Buffer * buf, col_type m, row_type n, char valign,
101 docstring const & halign);
103 marker_type marker(BufferView const *) const { return MARKER2; };
105 void metrics(MetricsInfo & mi, Dimension &) const;
107 void draw(PainterInfo & pi, int x, int y) const;
109 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
111 void drawT(TextPainter & pi, int x, int y) const;
113 void updateBuffer(ParIterator const &, UpdateType);
114 /// extract number of columns from alignment string
115 static col_type guessColumns(docstring const & halign);
116 /// accepts some LaTeX column codes: p,m,!,@,M,<,>
117 void setHorizontalAlignments(docstring const & align);
119 void setHorizontalAlignment(char c, col_type col);
121 char horizontalAlignment(col_type col) const;
123 docstring horizontalAlignments() const;
125 void setVerticalAlignment(char c);
127 char verticalAlignment() const;
129 void vcrskip(Length const &, row_type row);
131 Length vcrskip(row_type row) const;
133 void resize(short int type, col_type cols);
135 const RowInfo & rowinfo(row_type row) const;
136 /// returns topmost row if passed (-1)
137 RowInfo & rowinfo(row_type row);
139 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
141 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
142 /// identifies GridInset
143 InsetMathGrid * asGridInset() { return this; }
144 /// identifies GridInset
145 InsetMathGrid const * asGridInset() const { return this; }
147 bool isTable() const { return true; }
149 col_type ncols() const;
151 row_type nrows() const;
153 col_type col(idx_type idx) const;
155 row_type row(idx_type idx) const;
156 /// number of columns of cell \p idx
157 col_type ncellcols(idx_type idx) const;
160 bool idxUpDown(Cursor &, bool up) const;
162 bool idxBackward(Cursor &) const;
164 bool idxForward(Cursor &) const;
166 bool idxFirst(Cursor &) const;
168 bool idxLast(Cursor &) const;
170 bool idxDelete(idx_type & idx);
171 /// pulls cell after pressing erase
172 void idxGlue(idx_type idx);
174 /// add a row, one row down
175 virtual void addRow(row_type r);
177 virtual void delRow(row_type r);
179 virtual void copyRow(row_type r);
181 virtual void swapRow(row_type r);
182 /// add a column, here
183 virtual void addCol(col_type c);
185 virtual void delCol(col_type c);
187 virtual void copyCol(col_type c);
189 virtual void swapCol(col_type c);
191 idx_type index(row_type r, col_type c) const;
193 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
195 virtual int defaultColSpace(col_type) { return 0; }
197 virtual char defaultColAlign(col_type) { return 'c'; }
201 virtual bool interpretString(Cursor & cur, docstring const & str);
204 virtual int colsep() const;
206 virtual int rowsep() const;
208 virtual int hlinesep() const;
210 virtual int vlinesep() const;
212 virtual int border() const;
214 virtual bool handlesMulticolumn() const { return false; }
217 void write(WriteStream & os) const;
219 void write(WriteStream & os,
220 row_type beg_row, col_type beg_col,
221 row_type end_row, col_type end_col) const;
223 void normalize(NormalStream &) const;
225 //void maple(MapleStream &) const;
227 void mathmlize(MathStream &) const;
229 void htmlize(HtmlStream &) const;
231 void htmlize(HtmlStream &, std::string attrib) const;
233 void validate(LaTeXFeatures & features) const;
235 //void octave(OctaveStream &) const;
239 void doDispatch(Cursor & cur, FuncRequest & cmd);
241 bool getStatus(Cursor & cur, FuncRequest const & cmd,
242 FuncStatus & flag) const;
243 /// returns x offset of cell compared to inset
244 int cellXOffset(BufferView const &, idx_type idx) const;
245 /// returns y offset of cell compared to inset
246 int cellYOffset(idx_type idx) const;
247 /// Width of cell, taking combined columns into account
248 int cellWidth(idx_type idx) const;
250 virtual int leftMargin() const { return 0; }
252 virtual int rightMargin() const { return 0; }
254 /// returns proper 'end of line' code for LaTeX
255 virtual docstring eolString(row_type row, bool fragile, bool latex,
256 bool last_eoln) const;
257 /// returns proper 'end of column' code for LaTeX
258 virtual docstring eocString(col_type col, col_type lastcol) const;
259 /// splits cells and shifts right part to the next cell
260 void splitCell(Cursor & cur);
261 /// Column alignment for display of cell \p idx.
262 /// Must not be written to file!
263 virtual char displayColAlign(idx_type idx) const;
264 /// Column spacing for display of column \p col.
265 /// Must not be written to file!
266 virtual int displayColSpace(col_type col) const;
268 // The following two functions are used in InsetMathHull and
270 /// The value of a fixed col align for a certain hull type
271 static char colAlign(HullType type, col_type col);
272 /// The value of a fixed col spacing for a certain hull type
273 static int colSpace(HullType type, col_type col);
275 /// positions of vertical and horizontal lines
276 int vLineHOffset(col_type col, unsigned int line) const;
277 int hLineVOffset(row_type row, unsigned int line) const;
280 /// rowinfo_[nrows()] is a dummy row used only for hlines.
281 std::vector<RowInfo> rowinfo_;
283 /// colinfo_[ncols()] is a dummy column used only for vlines.
284 std::vector<ColInfo> colinfo_;
286 std::vector<CellInfo> cellinfo_;
288 InsetCode lyxCode() const { return MATH_GRID_CODE; }
292 char v_align_; // FIXME: add approp. type
294 Inset * clone() const;