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"
25 /** Gridded math inset base class.
26 * This is the base to all grid-like editable math objects
28 class InsetMathGrid : public InsetMathNest {
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
41 /// additional per-cell information
48 /// special multi columns alignment
52 /// additional per-row information
58 int skipPixels(MetricsInfo const & mi) const;
63 /// cached offset for each bufferview
64 mutable std::map<BufferView const *, int> offset;
65 /// how many hlines above this row?
67 /// parameter to the line break
69 /// extra distance between lines
71 /// Is a page break allowed after this row?
75 // additional per-row information
80 /// currently possible: 'l', 'c', 'r'
86 /// how many lines to the left of this column?
88 /// additional amount to the right to be skipped when drawing
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_.
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);
103 InsetMathGrid(Buffer * buf, col_type m, row_type n, char valign,
104 docstring const & halign);
106 marker_type marker(BufferView const *) const { return MARKER2; };
108 void metrics(MetricsInfo & mi, Dimension &) const;
110 void draw(PainterInfo & pi, int x, int y) const;
112 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
114 void drawT(TextPainter & pi, int x, int y) const;
116 void updateBuffer(ParIterator const &, UpdateType, bool const deleted = false);
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);
122 void setHorizontalAlignment(char c, col_type col);
124 char horizontalAlignment(col_type col) const;
126 docstring horizontalAlignments() const;
128 void setVerticalAlignment(char c);
130 char verticalAlignment() const;
132 void vcrskip(Length const &, row_type row);
134 Length vcrskip(row_type row) const;
136 void resize(short int type, col_type cols);
138 const RowInfo & rowinfo(row_type row) const;
139 /// returns topmost row if passed (-1)
140 RowInfo & rowinfo(row_type row);
142 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
144 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
145 /// identifies GridInset
146 InsetMathGrid * asGridInset() { return this; }
147 /// identifies GridInset
148 InsetMathGrid const * asGridInset() const { return this; }
150 bool isTable() const { return true; }
152 col_type ncols() const;
154 row_type nrows() const;
156 col_type col(idx_type idx) const;
158 row_type row(idx_type idx) const;
159 /// number of columns of cell \p idx
160 col_type ncellcols(idx_type idx) const;
163 bool idxUpDown(Cursor &, bool up) const;
165 bool idxBackward(Cursor &) const;
167 bool idxForward(Cursor &) const;
169 idx_type firstIdx() const;
171 idx_type lastIdx() const;
173 bool idxDelete(idx_type & idx);
174 /// pulls cell after pressing erase
175 void idxGlue(idx_type idx);
177 /// add a row, one row down
178 virtual void addRow(row_type r);
180 virtual void delRow(row_type r);
182 virtual void copyRow(row_type r);
184 virtual void swapRow(row_type r);
185 /// add a column, here
186 virtual void addCol(col_type c);
188 virtual void delCol(col_type c);
190 virtual void copyCol(col_type c);
192 virtual void swapCol(col_type c);
194 idx_type index(row_type r, col_type c) const;
196 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
198 virtual int defaultColSpace(col_type) { return 0; }
200 virtual char defaultColAlign(col_type) { return 'c'; }
204 virtual bool interpretString(Cursor & cur, docstring const & str);
207 virtual int colsep() const;
209 virtual int rowsep() const;
211 virtual int hlinesep() const;
213 virtual int vlinesep() const;
215 virtual int border() const;
217 virtual bool handlesMulticolumn() const { return false; }
220 void write(WriteStream & os) const;
222 void write(WriteStream & os,
223 row_type beg_row, col_type beg_col,
224 row_type end_row, col_type end_col) const;
226 void normalize(NormalStream &) const;
228 //void maple(MapleStream &) const;
230 void mathmlize(MathStream &) const;
232 void htmlize(HtmlStream &) const;
234 void htmlize(HtmlStream &, std::string attrib) const;
236 void validate(LaTeXFeatures & features) const;
238 //void octave(OctaveStream &) const;
242 void doDispatch(Cursor & cur, FuncRequest & cmd);
244 bool getStatus(Cursor & cur, FuncRequest const & cmd,
245 FuncStatus & flag) const;
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;
253 virtual int leftMargin() const { return 0; }
255 virtual int rightMargin() const { return 0; }
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;
271 // The following two functions are used in InsetMathHull and
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);
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;
284 InsetCode lyxCode() const { return MATH_GRID_CODE; }
288 /// rowinfo_[nrows()] is a dummy row used only for hlines.
289 std::vector<RowInfo> rowinfo_;
291 /// colinfo_[ncols()] is a dummy column used only for vlines.
292 std::vector<ColInfo> colinfo_;
294 std::vector<CellInfo> cellinfo_;
296 char v_align_; // FIXME: add approp. type
298 Inset * clone() const;