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
47 /// these should be a per-cell property, but ok to have it here
48 /// for single-column grids like paragraphs
51 mutable pos_type begin_;
53 mutable pos_type end_;
56 /// additional per-row information
62 int skipPixels(MetricsInfo const & mi) const;
69 /// how many hlines above this row?
71 /// parameter to the line break
73 /// extra distance between lines
75 /// Is a page break allowed after this row?
79 // additional per-row information
84 /// currently possible: 'l', 'c', 'r'
90 /// how many lines to the left of this column?
92 /// additional amount to the right to be skipped when drawing
94 /// Special alignment.
95 /// This does also contain align_ and lines_ if it is nonempty.
96 /// It needs to be in sync with align_ and lines_ because some
97 /// code only uses align_ and lines_.
102 /// sets nrows and ncols to 1, vertical alingment to 'c'
103 InsetMathGrid(Buffer * buf);
104 /// Note: columns first!
105 InsetMathGrid(Buffer * buf, col_type m, row_type n);
107 InsetMathGrid(Buffer * buf, col_type m, row_type n, char valign,
108 docstring const & halign);
110 void metrics(MetricsInfo & mi, Dimension &) const;
112 void draw(PainterInfo & pi, int x, int y) const;
114 void drawWithMargin(PainterInfo & pi, int x, int y,
115 int lmargin = 0, int rmargin = 0) const;
116 /// draw decorations.
117 void drawDecoration(PainterInfo & pi, int x, int y) const
118 { drawMarkers2(pi, x, y); }
120 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
122 void drawT(TextPainter & pi, int x, int y) const;
124 void updateBuffer(ParIterator const &, UpdateType);
125 /// extract number of columns from alignment string
126 static col_type guessColumns(docstring const & halign);
127 /// accepts some LaTeX column codes: p,m,!,@,M,<,>
128 void setHorizontalAlignments(docstring const & align);
130 void setHorizontalAlignment(char c, col_type col);
132 char horizontalAlignment(col_type col) const;
134 docstring horizontalAlignments() const;
136 void setVerticalAlignment(char c);
138 char verticalAlignment() const;
140 void vcrskip(Length const &, row_type row);
142 Length vcrskip(row_type row) const;
144 void resize(short int type, col_type cols);
146 const RowInfo & rowinfo(row_type row) const;
147 /// returns topmost row if passed (-1)
148 RowInfo & rowinfo(row_type row);
150 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
152 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
153 /// identifies GridInset
154 InsetMathGrid * asGridInset() { return this; }
155 /// identifies GridInset
156 InsetMathGrid const * asGridInset() const { return this; }
158 bool isTable() const { return true; }
160 col_type ncols() const;
162 row_type nrows() const;
164 col_type col(idx_type idx) const;
166 row_type row(idx_type idx) const;
167 /// number of columns of cell \p idx
168 col_type ncellcols(idx_type idx) const;
171 bool idxUpDown(Cursor &, bool up) const;
173 bool idxBackward(Cursor &) const;
175 bool idxForward(Cursor &) const;
177 bool idxFirst(Cursor &) const;
179 bool idxLast(Cursor &) const;
181 bool idxDelete(idx_type & idx);
182 /// pulls cell after pressing erase
183 void idxGlue(idx_type idx);
185 /// add a row, one row down
186 virtual void addRow(row_type r);
188 virtual void delRow(row_type r);
190 virtual void copyRow(row_type r);
192 virtual void swapRow(row_type r);
193 /// add a column, here
194 virtual void addCol(col_type c);
196 virtual void delCol(col_type c);
198 virtual void copyCol(col_type c);
200 virtual void swapCol(col_type c);
202 idx_type index(row_type r, col_type c) const;
204 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
206 virtual int defaultColSpace(col_type) { return 0; }
208 virtual char defaultColAlign(col_type) { return 'c'; }
212 virtual bool interpretString(Cursor & cur, docstring const & str);
215 virtual int colsep() const;
217 virtual int rowsep() const;
219 virtual int hlinesep() const;
221 virtual int vlinesep() const;
223 virtual int border() const;
226 void write(WriteStream & os) const;
228 void write(WriteStream & os,
229 row_type beg_row, col_type beg_col,
230 row_type end_row, col_type end_col) const;
232 void normalize(NormalStream &) const;
234 //void maple(MapleStream &) const;
236 void mathmlize(MathStream &) const;
238 void htmlize(HtmlStream &) const;
240 void htmlize(HtmlStream &, std::string attrib) const;
242 void validate(LaTeXFeatures & features) const;
244 //void octave(OctaveStream &) const;
248 void doDispatch(Cursor & cur, FuncRequest & cmd);
250 bool getStatus(Cursor & cur, FuncRequest const & cmd,
251 FuncStatus & flag) const;
252 /// returns x offset of cell compared to inset
253 int cellXOffset(BufferView const &, idx_type idx) const;
254 /// returns y offset of cell compared to inset
255 int cellYOffset(idx_type idx) const;
256 /// Width of cell, taking combined columns into account
257 int cellWidth(idx_type idx) const;
258 /// returns proper 'end of line' code for LaTeX
259 virtual docstring eolString(row_type row, bool fragile, bool latex,
260 bool last_eoln) const;
261 /// returns proper 'end of column' code for LaTeX
262 virtual docstring eocString(col_type col, col_type lastcol) const;
263 /// splits cells and shifts right part to the next cell
264 void splitCell(Cursor & cur);
265 /// Column alignment for display of cell \p idx.
266 /// Must not be written to file!
267 virtual char displayColAlign(idx_type idx) const;
268 /// Column spacing for display of column \p col.
269 /// Must not be written to file!
270 virtual int displayColSpace(col_type col) const;
272 // The following two functions are used in InsetMathHull and
274 /// The value of a fixed col align for a certain hull type
275 static char colAlign(HullType type, col_type col);
276 /// The value of a fixed col spacing for a certain hull type
277 static int colSpace(HullType type, col_type col);
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_; // add approp. type
294 Inset * clone() const;