3 * \file math_gridinset.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 "math_nestinset.h"
16 #include "lyxlength.h"
19 /** Gridded math inset base class.
20 * This is the base to all grid-like editable math objects
22 class MathGridInset : public MathNestInset {
25 /// additional per-cell information
30 /// a dummy cell before a multicolumn cell
32 /// special multi colums alignment
34 /// these should be a per-cell property, but ok to have it here
35 /// for single-column grids like paragraphs
38 mutable pos_type begin_;
40 mutable pos_type end_;
43 /// additional per-row information
49 int skipPixels() const;
56 /// how many hlines above this row?
58 /// parameter to the line break
60 /// extra distance between lines
64 // additional per-row information
69 /// currently possible: 'l', 'c', 'r'
77 /// how many lines to the left of this column?
79 /// additional amount to be skipped when drawing
84 /// sets nrows and ncols to 1
86 /// constructor from columns description, creates one row
87 MathGridInset(char valign, std::string const & halign);
88 /// Note: columns first!
89 MathGridInset(col_type m, row_type n);
91 MathGridInset(col_type m, row_type n, char valign, std::string const & halign);
92 /// Ensures that the dialog is closed.
95 void metrics(MetricsInfo & mi) const;
97 void metrics(MetricsInfo & mi, Dimension &) const;
99 void draw(PainterInfo & pi, int x, int y) const;
101 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
103 void drawT(TextPainter & pi, int x, int y) const;
105 void halign(std::string const & align);
107 void halign(char c, col_type col);
109 char halign(col_type col) const;
111 std::string halign() const;
117 void vcrskip(LyXLength const &, row_type row);
119 LyXLength vcrskip(row_type row) const;
121 void resize(short int type, col_type cols);
123 const RowInfo & rowinfo(row_type row) const;
124 /// returns topmost row if passed (-1)
125 RowInfo & rowinfo(row_type row);
127 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
129 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
130 /// identifies GridInset
131 MathGridInset * asGridInset() { return this; }
132 /// identifies GridInset
133 MathGridInset const * asGridInset() const { return this; }
135 col_type ncols() const;
137 row_type nrows() const;
139 col_type col(idx_type idx) const;
141 row_type row(idx_type idx) const;
144 bool idxUpDown(LCursor &, bool up) const;
146 bool idxLeft(LCursor &) const;
148 bool idxRight(LCursor &) const;
150 bool idxFirst(LCursor &) const;
152 bool idxLast(LCursor &) const;
154 bool idxDelete(idx_type & idx);
155 /// pulls cell after pressing erase
156 void idxGlue(idx_type idx);
159 virtual void addRow(row_type r);
161 virtual void delRow(row_type r);
163 virtual void copyRow(row_type r);
165 virtual void swapRow(row_type r);
167 virtual void addCol(col_type c);
169 virtual void delCol(col_type c);
171 virtual void copyCol(col_type c);
173 virtual void swapCol(col_type c);
175 virtual void appendRow();
177 idx_type index(row_type r, col_type c) const;
179 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
181 virtual int defaultColSpace(col_type) { return 0; }
183 virtual char defaultColAlign(col_type) { return 'c'; }
188 virtual int colsep() const;
190 virtual int rowsep() const;
192 virtual int hlinesep() const;
194 virtual int vlinesep() const;
196 virtual int border() const;
199 void write(WriteStream & os) const;
201 void normalize(NormalStream &) const;
203 //void maple(MapleStream &) const;
205 void mathmlize(MathMLStream &) const;
207 //void octave(OctaveStream &) const;
210 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
212 bool getStatus(LCursor & cur, FuncRequest const & cmd,
213 FuncStatus & flag) const;
214 /// returns x offset of cell compared to inset
215 int cellXOffset(idx_type idx) const;
216 /// returns y offset of cell compared to inset
217 int cellYOffset(idx_type idx) const;
218 /// returns proper 'end of line' code for LaTeX
219 virtual std::string eolString(row_type row, bool fragile = false) const;
220 /// returns proper 'end of column' code for LaTeX
221 virtual std::string eocString(col_type col, col_type lastcol) const;
222 /// extract number of columns from alignment string
223 col_type guessColumns(std::string const & halign) const;
224 /// splits cells and shifts right part to the next cell
225 void splitCell(LCursor & cur);
229 /// rowinfo_[nrows()] is a dummy row used only for hlines.
230 std::vector<RowInfo> rowinfo_;
232 /// colinfo_[ncols()] is a dummy column used only for vlines.
233 std::vector<ColInfo> colinfo_;
235 std::vector<CellInfo> cellinfo_;
237 char v_align_; // add approp. type
239 virtual std::auto_ptr<InsetBase> doClone() const;