5 #include "math_nestinset.h"
13 /** Gridded math inset base class.
14 This is the base to all grid-like editable math objects
15 like array and eqnarray.
16 * \author André Pönitz 2001
18 * Full author contact details are available in file CREDITS
21 class MathGridInset : public MathNestInset {
25 /// additional per-cell information
29 /// a dummy cell before a multicolumn cell
31 /// special multi colums alignment
33 /// these should be a per-cell property, but ok to have it here
34 /// for single-column grids like paragraphs
37 mutable pos_type begin_;
39 mutable pos_type end_;
42 /// additional per-row information
47 int skipPixels() const;
54 /// how many hlines above this row?
56 /// parameter to the line break
58 /// extra distance between lines
62 // additional per-row information
66 /// currently possible: 'l', 'c', 'r'
74 /// do we need a line to the left?
76 /// do we need a line to the right?
78 /// how many lines to the left of this column?
80 /// additional amount to be skipped when drawing
85 /// sets nrows and ncols to 1
87 /// constructor from columns description, creates one row
88 MathGridInset(char valign, string const & halign);
89 /// Note: columns first!
90 MathGridInset(col_type m, row_type n);
92 MathGridInset(col_type m, row_type n, char valign, string const & halign);
94 MathInset * clone() const;
96 void metrics(MathMetricsInfo & mi) const;
98 void draw(MathPainterInfo & pi, int x, int y) const;
100 void metricsT(TextMetricsInfo const & mi) const;
102 void drawT(TextPainter & pi, int x, int y) const;
104 void halign(string const & align);
106 void halign(char c, col_type col);
108 char halign(col_type col) const;
110 string halign() const;
116 void vcrskip(LyXLength const &, row_type row);
118 LyXLength vcrskip(row_type row) const;
120 void resize(short int type, col_type cols);
122 const RowInfo & rowinfo(row_type row) const;
123 /// returns topmost row if passed (-1)
124 RowInfo & rowinfo(row_type row);
126 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
128 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
129 /// identifies GridInset
130 MathGridInset * asGridInset() { return this; }
131 /// identifies GridInset
132 MathGridInset const * asGridInset() const { return this; }
134 result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
137 col_type ncols() const;
139 row_type nrows() const;
141 col_type col(idx_type idx) const;
143 row_type row(idx_type idx) const;
146 bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
148 bool idxLeft(idx_type & idx, pos_type & pos) const;
150 bool idxRight(idx_type & idx, pos_type & pos) const;
152 bool idxFirst(idx_type & idx, pos_type & pos) const;
154 bool idxLast(idx_type & idx, pos_type & pos) const;
156 bool idxHome(idx_type & idx, pos_type & pos) const;
158 bool idxEnd(idx_type & idx, pos_type & pos) 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 maplize(MapleStream &) const;
211 void mathmlize(MathMLStream &) const;
213 //void octavize(OctaveStream &) const;
216 /// returns x offset of cell compared to inset
217 int cellXOffset(idx_type idx) const;
218 /// returns y offset of cell compared to inset
219 int cellYOffset(idx_type idx) const;
220 /// returns proper 'end of line' code for LaTeX
221 virtual string eolString(row_type row, bool fragile = false) const;
222 /// returns proper 'end of column' code for LaTeX
223 virtual string eocString(col_type col, col_type lastcol) const;
224 /// extract number of columns from alignment string
225 col_type guessColumns(string const & halign) const;
226 /// splits cells and shifts right part to the next cell
227 void splitCell(idx_type &, pos_type & pos);
231 std::vector<RowInfo> rowinfo_;
233 std::vector<ColInfo> colinfo_;
235 std::vector<CellInfo> cellinfo_;
237 char v_align_; // add approp. type