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
19 class MathGridInset : public MathNestInset {
23 /// additional per-cell information
27 /// a dummy cell before a multicolumn cell
29 /// special multi colums alignment
31 /// these should be a per-cell property, but ok to have it here
32 /// for single-column grids like paragraphs
35 mutable pos_type begin_;
37 mutable pos_type end_;
40 /// additional per-row information
45 int skipPixels() const;
52 /// how many hlines above this row?
54 /// parameter to the line break
56 /// extra distance between lines
60 // additional per-row information
64 /// currently possible: 'l', 'c', 'r'
72 /// do we need a line to the left?
74 /// do we need a line to the right?
76 /// how many lines to the left of this column?
78 /// additional amount to be skipped when drawing
83 /// sets nrows and ncols to 1
85 /// constructor from columns description, creates one row
86 MathGridInset(char valign, string const & halign);
87 /// Note: columns first!
88 MathGridInset(col_type m, row_type n);
90 MathGridInset(col_type m, row_type n, char valign, string const & halign);
92 MathInset * clone() const;
94 void metrics(MathMetricsInfo & mi) const;
96 void draw(MathPainterInfo & pi, int x, int y) const;
98 void metricsT(TextMetricsInfo const & mi) const;
100 void drawT(TextPainter & pi, int x, int y) const;
102 void halign(string const & align);
104 void halign(char c, col_type col);
106 char halign(col_type col) const;
108 string halign() const;
114 void vcrskip(LyXLength const &, row_type row);
116 LyXLength vcrskip(row_type row) const;
118 void resize(short int type, col_type cols);
120 const RowInfo & rowinfo(row_type row) const;
121 /// returns topmost row if passed (-1)
122 RowInfo & rowinfo(row_type row);
124 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
126 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
127 /// identifies GridInset
128 MathGridInset * asGridInset() { return this; }
129 /// identifies GridInset
130 MathGridInset const * asGridInset() const { return this; }
132 result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
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(idx_type & idx, pos_type & pos, bool up, int targetx) const;
146 bool idxLeft(idx_type & idx, pos_type & pos) const;
148 bool idxRight(idx_type & idx, pos_type & pos) const;
150 bool idxFirst(idx_type & idx, pos_type & pos) const;
152 bool idxLast(idx_type & idx, pos_type & pos) const;
154 bool idxHome(idx_type & idx, pos_type & pos) const;
156 bool idxEnd(idx_type & idx, pos_type & pos) const;
158 bool idxDelete(idx_type & idx);
159 /// pulls cell after pressing erase
160 void idxGlue(idx_type idx);
163 virtual void addRow(row_type r);
165 virtual void delRow(row_type r);
167 virtual void addFancyRow(row_type r) { addRow(r); }
169 virtual void delFancyRow(row_type r) { delRow(r); }
171 virtual void addCol(col_type c);
173 virtual void delCol(col_type c);
175 virtual void addFancyCol(col_type c) { addCol(c); }
177 virtual void delFancyCol(col_type c) { delCol(c); }
179 virtual void appendRow();
181 idx_type index(row_type r, col_type c) const;
183 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
185 virtual int defaultColSpace(col_type) { return 0; }
187 virtual char defaultColAlign(col_type) { return 'c'; }
192 virtual int colsep() const;
194 virtual int rowsep() const;
196 virtual int hlinesep() const;
198 virtual int vlinesep() const;
200 virtual int border() const;
203 void write(WriteStream & os) const;
205 void normalize(NormalStream &) const;
207 //void maplize(MapleStream &) const;
209 void mathmlize(MathMLStream &) const;
211 //void octavize(OctaveStream &) 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 string eolString(row_type row, bool fragile = false) const;
220 /// returns proper 'end of column' code for LaTeX
221 virtual string eocString(col_type col) const;
222 /// extract number of columns from alignment string
223 col_type guessColumns(string const & halign) const;
224 /// splits cells and shifts right part to the next cell
225 void splitCell(idx_type &, pos_type & pos);
229 std::vector<RowInfo> rowinfo_;
231 std::vector<ColInfo> colinfo_;
233 std::vector<CellInfo> cellinfo_;
235 char v_align_; // add approp. type