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"
16 #include "lyxlength.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);
97 /// Ensures that the dialog is closed.
100 void metrics(MetricsInfo & mi) const;
102 bool metrics(MetricsInfo & mi, Dimension &) const;
104 void draw(PainterInfo & pi, int x, int y) const;
106 void drawWithMargin(PainterInfo & pi, int x, int y,
107 int lmargin = 0, int rmargin = 0) const;
108 /// draw decorations.
109 void drawDecoration(PainterInfo & pi, int x, int y) const
110 { drawMarkers2(pi, x, y); }
112 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
114 void drawT(TextPainter & pi, int x, int y) const;
116 void halign(docstring const & align);
118 void halign(char c, col_type col);
120 char halign(col_type col) const;
122 docstring halign() const;
128 void vcrskip(LyXLength const &, row_type row);
130 LyXLength vcrskip(row_type row) const;
132 void resize(short int type, col_type cols);
134 const RowInfo & rowinfo(row_type row) const;
135 /// returns topmost row if passed (-1)
136 RowInfo & rowinfo(row_type row);
138 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
140 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
141 /// identifies GridInset
142 InsetMathGrid * asGridInset() { return this; }
143 /// identifies GridInset
144 InsetMathGrid const * asGridInset() const { return this; }
146 col_type ncols() const;
148 row_type nrows() const;
150 col_type col(idx_type idx) const;
152 row_type row(idx_type idx) const;
155 bool idxUpDown(LCursor &, bool up) const;
157 bool idxLeft(LCursor &) const;
159 bool idxRight(LCursor &) const;
161 bool idxFirst(LCursor &) const;
163 bool idxLast(LCursor &) const;
165 bool idxDelete(idx_type & idx);
166 /// pulls cell after pressing erase
167 void idxGlue(idx_type idx);
170 virtual void addRow(row_type r);
172 virtual void delRow(row_type r);
174 virtual void copyRow(row_type r);
176 virtual void swapRow(row_type r);
178 virtual void addCol(col_type c);
180 virtual void delCol(col_type c);
182 virtual void copyCol(col_type c);
184 virtual void swapCol(col_type c);
186 virtual void appendRow();
188 idx_type index(row_type r, col_type c) const;
190 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
192 virtual int defaultColSpace(col_type) { return 0; }
194 virtual char defaultColAlign(col_type) { return 'c'; }
199 virtual int colsep() const;
201 virtual int rowsep() const;
203 virtual int hlinesep() const;
205 virtual int vlinesep() const;
207 virtual int border() const;
210 void write(WriteStream & os) const;
212 void normalize(NormalStream &) const;
214 //void maple(MapleStream &) const;
216 void mathmlize(MathStream &) const;
218 //void octave(OctaveStream &) const;
221 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
223 bool getStatus(LCursor & cur, FuncRequest const & cmd,
224 FuncStatus & flag) const;
225 /// returns x offset of cell compared to inset
226 int cellXOffset(idx_type idx) const;
227 /// returns y offset of cell compared to inset
228 int cellYOffset(idx_type idx) const;
229 /// returns proper 'end of line' code for LaTeX
230 virtual docstring eolString(row_type row, bool emptyline,
232 /// returns proper 'end of column' code for LaTeX
233 virtual docstring eocString(col_type col, col_type lastcol) const;
234 /// extract number of columns from alignment string
235 col_type guessColumns(docstring const & halign) const;
236 /// splits cells and shifts right part to the next cell
237 void splitCell(LCursor & cur);
240 /// rowinfo_[nrows()] is a dummy row used only for hlines.
241 std::vector<RowInfo> rowinfo_;
243 /// colinfo_[ncols()] is a dummy column used only for vlines.
244 std::vector<ColInfo> colinfo_;
246 std::vector<CellInfo> cellinfo_;
248 char v_align_; // add approp. type
250 virtual std::auto_ptr<InsetBase> doClone() const;