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 {
28 /// additional per-cell information
33 /// a dummy cell before a multicolumn cell
35 /// special multi colums alignment
37 /// these should be a per-cell property, but ok to have it here
38 /// for single-column grids like paragraphs
41 mutable pos_type begin_;
43 mutable pos_type end_;
46 /// additional per-row information
52 int skipPixels() const;
59 /// how many hlines above this row?
61 /// parameter to the line break
63 /// extra distance between lines
65 /// Is a page break allowed after this row?
66 bool allow_pagebreak_;
69 // additional per-row information
74 /// currently possible: 'l', 'c', 'r'
82 /// how many lines to the left of this column?
84 /// additional amount to be skipped when drawing
89 /// sets nrows and ncols to 1
91 /// constructor from columns description, creates one row
92 InsetMathGrid(char valign, docstring const & halign);
93 /// Note: columns first!
94 InsetMathGrid(col_type m, row_type n);
96 InsetMathGrid(col_type m, row_type n, char valign, docstring const & halign);
98 void metrics(MetricsInfo & mi) const;
100 bool metrics(MetricsInfo & mi, Dimension &) const;
102 void draw(PainterInfo & pi, int x, int y) const;
104 void drawWithMargin(PainterInfo & pi, int x, int y,
105 int lmargin = 0, int rmargin = 0) const;
106 /// draw decorations.
107 void drawDecoration(PainterInfo & pi, int x, int y) const
108 { drawMarkers2(pi, x, y); }
110 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
112 void drawT(TextPainter & pi, int x, int y) const;
114 void halign(docstring const & align);
116 void halign(char c, col_type col);
118 char halign(col_type col) const;
120 docstring halign() const;
126 void vcrskip(Length const &, row_type row);
128 Length vcrskip(row_type row) const;
130 void resize(short int type, col_type cols);
132 const RowInfo & rowinfo(row_type row) const;
133 /// returns topmost row if passed (-1)
134 RowInfo & rowinfo(row_type row);
136 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
138 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
139 /// identifies GridInset
140 InsetMathGrid * asGridInset() { return this; }
141 /// identifies GridInset
142 InsetMathGrid const * asGridInset() const { return this; }
144 col_type ncols() const;
146 row_type nrows() const;
148 col_type col(idx_type idx) const;
150 row_type row(idx_type idx) const;
153 bool idxUpDown(Cursor &, bool up) const;
155 bool idxLeft(Cursor &) const;
157 bool idxRight(Cursor &) const;
159 bool idxFirst(Cursor &) const;
161 bool idxLast(Cursor &) const;
163 bool idxDelete(idx_type & idx);
164 /// pulls cell after pressing erase
165 void idxGlue(idx_type idx);
168 virtual void addRow(row_type r);
170 virtual void delRow(row_type r);
172 virtual void copyRow(row_type r);
174 virtual void swapRow(row_type r);
176 virtual void addCol(col_type c);
178 virtual void delCol(col_type c);
180 virtual void copyCol(col_type c);
182 virtual void swapCol(col_type c);
184 virtual void appendRow();
186 idx_type index(row_type r, col_type c) const;
188 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
190 virtual int defaultColSpace(col_type) { return 0; }
192 virtual char defaultColAlign(col_type) { return 'c'; }
197 virtual int colsep() const;
199 virtual int rowsep() const;
201 virtual int hlinesep() const;
203 virtual int vlinesep() const;
205 virtual int border() const;
208 void write(WriteStream & os) const;
210 void normalize(NormalStream &) const;
212 //void maple(MapleStream &) const;
214 void mathmlize(MathStream &) const;
216 //void octave(OctaveStream &) const;
219 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
221 bool getStatus(Cursor & cur, FuncRequest const & cmd,
222 FuncStatus & flag) const;
223 /// returns x offset of cell compared to inset
224 int cellXOffset(idx_type idx) const;
225 /// returns y offset of cell compared to inset
226 int cellYOffset(idx_type idx) const;
227 /// returns proper 'end of line' code for LaTeX
228 virtual docstring eolString(row_type row, bool emptyline,
230 /// returns proper 'end of column' code for LaTeX
231 virtual docstring eocString(col_type col, col_type lastcol) const;
232 /// extract number of columns from alignment string
233 col_type guessColumns(docstring const & halign) const;
234 /// splits cells and shifts right part to the next cell
235 void splitCell(Cursor & cur);
238 /// rowinfo_[nrows()] is a dummy row used only for hlines.
239 std::vector<RowInfo> rowinfo_;
241 /// colinfo_[ncols()] is a dummy column used only for vlines.
242 std::vector<ColInfo> colinfo_;
244 std::vector<CellInfo> cellinfo_;
246 char v_align_; // add approp. type
248 virtual std::auto_ptr<Inset> doClone() const;