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"
20 /** Gridded math inset base class.
21 * This is the base to all grid-like editable math objects
23 class MathGridInset : public MathNestInset {
27 /// additional per-cell information
31 /// a dummy cell before a multicolumn cell
33 /// special multi colums alignment
35 /// these should be a per-cell property, but ok to have it here
36 /// for single-column grids like paragraphs
39 mutable pos_type begin_;
41 mutable pos_type end_;
44 /// 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
68 /// currently possible: 'l', 'c', 'r'
76 /// do we need a line to the left?
78 /// do we need a line to the right?
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 MathGridInset(char valign, string const & halign);
91 /// Note: columns first!
92 MathGridInset(col_type m, row_type n);
94 MathGridInset(col_type m, row_type n, char valign, string const & halign);
95 /// Ensures that the dialog is closed.
98 virtual std::auto_ptr<InsetBase> clone() const;
100 void metrics(MetricsInfo & mi) const;
102 void metrics(MetricsInfo & mi, Dimension &) const;
104 void draw(PainterInfo & pi, int x, int y) const;
106 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
108 void drawT(TextPainter & pi, int x, int y) const;
110 void halign(string const & align);
112 void halign(char c, col_type col);
114 char halign(col_type col) const;
116 string halign() const;
122 void vcrskip(LyXLength const &, row_type row);
124 LyXLength vcrskip(row_type row) const;
126 void resize(short int type, col_type cols);
128 const RowInfo & rowinfo(row_type row) const;
129 /// returns topmost row if passed (-1)
130 RowInfo & rowinfo(row_type row);
132 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
134 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
135 /// identifies GridInset
136 MathGridInset * asGridInset() { return this; }
137 /// identifies GridInset
138 MathGridInset const * asGridInset() const { return this; }
140 dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
143 col_type ncols() const;
145 row_type nrows() const;
147 col_type col(idx_type idx) const;
149 row_type row(idx_type idx) const;
152 bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
154 bool idxLeft(idx_type & idx, pos_type & pos) const;
156 bool idxRight(idx_type & idx, pos_type & pos) const;
158 bool idxFirst(idx_type & idx, pos_type & pos) const;
160 bool idxLast(idx_type & idx, pos_type & pos) const;
162 bool idxHome(idx_type & idx, pos_type & pos) const;
164 bool idxEnd(idx_type & idx, pos_type & pos) const;
166 bool idxDelete(idx_type & idx);
167 /// pulls cell after pressing erase
168 void idxGlue(idx_type idx);
171 virtual void addRow(row_type r);
173 virtual void delRow(row_type r);
175 virtual void copyRow(row_type r);
177 virtual void swapRow(row_type r);
179 virtual void addCol(col_type c);
181 virtual void delCol(col_type c);
183 virtual void copyCol(col_type c);
185 virtual void swapCol(col_type c);
187 virtual void appendRow();
189 idx_type index(row_type r, col_type c) const;
191 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
193 virtual int defaultColSpace(col_type) { return 0; }
195 virtual char defaultColAlign(col_type) { return 'c'; }
200 virtual int colsep() const;
202 virtual int rowsep() const;
204 virtual int hlinesep() const;
206 virtual int vlinesep() const;
208 virtual int border() const;
211 void write(WriteStream & os) const;
213 void normalize(NormalStream &) const;
215 //void maple(MapleStream &) const;
217 void mathmlize(MathMLStream &) const;
219 //void octave(OctaveStream &) const;
222 /// returns x offset of cell compared to inset
223 int cellXOffset(idx_type idx) const;
224 /// returns y offset of cell compared to inset
225 int cellYOffset(idx_type idx) const;
226 /// returns proper 'end of line' code for LaTeX
227 virtual string eolString(row_type row, bool fragile = false) const;
228 /// returns proper 'end of column' code for LaTeX
229 virtual string eocString(col_type col, col_type lastcol) const;
230 /// extract number of columns from alignment string
231 col_type guessColumns(string const & halign) const;
232 /// splits cells and shifts right part to the next cell
233 void splitCell(idx_type &, pos_type & pos);
237 std::vector<RowInfo> rowinfo_;
239 std::vector<ColInfo> colinfo_;
241 std::vector<CellInfo> cellinfo_;
243 char v_align_; // add approp. type