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
67 // additional per-row information
72 /// currently possible: 'l', 'c', 'r'
80 /// how many lines to the left of this column?
82 /// additional amount to be skipped when drawing
87 /// sets nrows and ncols to 1
89 /// constructor from columns description, creates one row
90 InsetMathGrid(char valign, docstring const & halign);
91 /// Note: columns first!
92 InsetMathGrid(col_type m, row_type n);
94 InsetMathGrid(col_type m, row_type n, char valign, docstring const & halign);
95 /// Ensures that the dialog is closed.
98 void metrics(MetricsInfo & mi) const;
100 void 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;
107 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
109 void drawT(TextPainter & pi, int x, int y) const;
111 void halign(docstring const & align);
113 void halign(char c, col_type col);
115 char halign(col_type col) const;
117 docstring halign() const;
123 void vcrskip(LyXLength const &, row_type row);
125 LyXLength vcrskip(row_type row) const;
127 void resize(short int type, col_type cols);
129 const RowInfo & rowinfo(row_type row) const;
130 /// returns topmost row if passed (-1)
131 RowInfo & rowinfo(row_type row);
133 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
135 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
136 /// identifies GridInset
137 InsetMathGrid * asGridInset() { return this; }
138 /// identifies GridInset
139 InsetMathGrid const * asGridInset() const { return this; }
141 col_type ncols() const;
143 row_type nrows() const;
145 col_type col(idx_type idx) const;
147 row_type row(idx_type idx) const;
150 bool idxUpDown(LCursor &, bool up) const;
152 bool idxLeft(LCursor &) const;
154 bool idxRight(LCursor &) const;
156 bool idxFirst(LCursor &) const;
158 bool idxLast(LCursor &) const;
160 bool idxDelete(idx_type & idx);
161 /// pulls cell after pressing erase
162 void idxGlue(idx_type idx);
165 virtual void addRow(row_type r);
167 virtual void delRow(row_type r);
169 virtual void copyRow(row_type r);
171 virtual void swapRow(row_type r);
173 virtual void addCol(col_type c);
175 virtual void delCol(col_type c);
177 virtual void copyCol(col_type c);
179 virtual void swapCol(col_type c);
181 virtual void appendRow();
183 idx_type index(row_type r, col_type c) const;
185 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
187 virtual int defaultColSpace(col_type) { return 0; }
189 virtual char defaultColAlign(col_type) { return 'c'; }
194 virtual int colsep() const;
196 virtual int rowsep() const;
198 virtual int hlinesep() const;
200 virtual int vlinesep() const;
202 virtual int border() const;
205 void write(WriteStream & os) const;
207 void normalize(NormalStream &) const;
209 //void maple(MapleStream &) const;
211 void mathmlize(MathStream &) const;
213 //void octave(OctaveStream &) const;
216 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
218 bool getStatus(LCursor & cur, FuncRequest const & cmd,
219 FuncStatus & flag) const;
220 /// returns x offset of cell compared to inset
221 int cellXOffset(idx_type idx) const;
222 /// returns y offset of cell compared to inset
223 int cellYOffset(idx_type idx) const;
224 /// returns proper 'end of line' code for LaTeX
225 virtual docstring eolString(row_type row, bool emptyline,
227 /// returns proper 'end of column' code for LaTeX
228 virtual docstring eocString(col_type col, col_type lastcol) const;
229 /// extract number of columns from alignment string
230 col_type guessColumns(docstring const & halign) const;
231 /// splits cells and shifts right part to the next cell
232 void splitCell(LCursor & cur);
235 /// rowinfo_[nrows()] is a dummy row used only for hlines.
236 std::vector<RowInfo> rowinfo_;
238 /// colinfo_[ncols()] is a dummy column used only for vlines.
239 std::vector<ColInfo> colinfo_;
241 std::vector<CellInfo> cellinfo_;
243 char v_align_; // add approp. type
245 virtual std::auto_ptr<InsetBase> doClone() const;