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"
24 /** Gridded math inset base class.
25 * This is the base to all grid-like editable math objects
27 class InsetMathGrid : public InsetMathNest {
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
40 /// additional per-cell information
47 /// special multi colums alignment
51 /// additional per-row information
57 int skipPixels(MetricsInfo const & mi) const;
64 /// how many hlines above this row?
66 /// parameter to the line break
68 /// extra distance between lines
70 /// Is a page break allowed after this row?
74 // additional per-row information
79 /// currently possible: 'l', 'c', 'r'
85 /// how many lines to the left of this column?
87 /// additional amount to the right to be skipped when drawing
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_.
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);
102 InsetMathGrid(Buffer * buf, col_type m, row_type n, char valign,
103 docstring const & halign);
105 marker_type marker(BufferView const *) const { return MARKER2; };
107 void metrics(MetricsInfo & mi, Dimension &) const;
109 void draw(PainterInfo & pi, int x, int y) const;
111 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
113 void drawT(TextPainter & pi, int x, int y) const;
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);
121 void setHorizontalAlignment(char c, col_type col);
123 char horizontalAlignment(col_type col) const;
125 docstring horizontalAlignments() const;
127 void setVerticalAlignment(char c);
129 char verticalAlignment() const;
131 void vcrskip(Length const &, row_type row);
133 Length vcrskip(row_type row) const;
135 void resize(short int type, col_type cols);
137 const RowInfo & rowinfo(row_type row) const;
138 /// returns topmost row if passed (-1)
139 RowInfo & rowinfo(row_type row);
141 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
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; }
149 bool isTable() const { return true; }
151 col_type ncols() const;
153 row_type nrows() const;
155 col_type col(idx_type idx) const;
157 row_type row(idx_type idx) const;
158 /// number of columns of cell \p idx
159 col_type ncellcols(idx_type idx) const;
162 bool idxUpDown(Cursor &, bool up) const;
164 bool idxBackward(Cursor &) const;
166 bool idxForward(Cursor &) const;
168 idx_type firstIdx() const;
170 idx_type lastIdx() const;
172 bool idxDelete(idx_type & idx);
173 /// pulls cell after pressing erase
174 void idxGlue(idx_type idx);
176 /// add a row, one row down
177 virtual void addRow(row_type r);
179 virtual void delRow(row_type r);
181 virtual void copyRow(row_type r);
183 virtual void swapRow(row_type r);
184 /// add a column, here
185 virtual void addCol(col_type c);
187 virtual void delCol(col_type c);
189 virtual void copyCol(col_type c);
191 virtual void swapCol(col_type c);
193 idx_type index(row_type r, col_type c) const;
195 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
197 virtual int defaultColSpace(col_type) { return 0; }
199 virtual char defaultColAlign(col_type) { return 'c'; }
203 virtual bool interpretString(Cursor & cur, docstring const & str);
206 virtual int colsep() const;
208 virtual int rowsep() const;
210 virtual int hlinesep() const;
212 virtual int vlinesep() const;
214 virtual int border() const;
216 virtual bool handlesMulticolumn() const { return false; }
219 void write(WriteStream & os) const;
221 void write(WriteStream & os,
222 row_type beg_row, col_type beg_col,
223 row_type end_row, col_type end_col) const;
225 void normalize(NormalStream &) const;
227 //void maple(MapleStream &) const;
229 void mathmlize(MathStream &) const;
231 void htmlize(HtmlStream &) const;
233 void htmlize(HtmlStream &, std::string attrib) const;
235 void validate(LaTeXFeatures & features) const;
237 //void octave(OctaveStream &) const;
241 void doDispatch(Cursor & cur, FuncRequest & cmd);
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;
252 virtual int leftMargin() const { return 0; }
254 virtual int rightMargin() const { return 0; }
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;
270 // The following two functions are used in InsetMathHull and
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);
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;
283 /// rowinfo_[nrows()] is a dummy row used only for hlines.
284 std::vector<RowInfo> rowinfo_;
286 /// colinfo_[ncols()] is a dummy column used only for vlines.
287 std::vector<ColInfo> colinfo_;
289 std::vector<CellInfo> cellinfo_;
291 InsetCode lyxCode() const { return MATH_GRID_CODE; }
295 char v_align_; // FIXME: add approp. type
297 Inset * clone() const;