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 {
21 /// additional per-cell information
25 /// a dummy cell before a multicolumn cell
27 /// special multi colums alignment
29 /// these should be a per-cell property, but ok to have it here
30 /// for single-column grids like paragraphs
33 mutable pos_type begin_;
35 mutable pos_type end_;
38 /// additional per-row information
43 int skipPixels() const;
50 /// how many hlines above this row?
52 /// parameter to the line break
54 /// extra distance between lines
58 // additional per-row information
62 /// currently possible: 'l', 'c', 'r'
70 /// do we need a line to the left?
72 /// do we need a line to the right?
74 /// how many lines to the left of this column?
76 /// additional amount to be skipped when drawing
81 /// sets nrows and ncols to 1
83 /// constructor from columns description, creates one row
84 MathGridInset(char valign, string const & halign);
85 /// Note: columns first!
86 MathGridInset(col_type m, row_type n);
88 MathGridInset(col_type m, row_type n, char valign, string const & halign);
90 MathInset * clone() const;
92 void metrics(MathMetricsInfo & mi) const;
94 void draw(MathPainterInfo & pi, int x, int y) const;
96 void metricsT(TextMetricsInfo const & mi) const;
98 void drawT(TextPainter & pi, int x, int y) const;
100 void halign(string const & align);
102 void halign(char c, col_type col);
104 char halign(col_type col) const;
106 string halign() const;
112 void vcrskip(LyXLength const &, row_type row);
114 LyXLength vcrskip(row_type row) const;
116 void resize(short int type, col_type cols);
118 const RowInfo & rowinfo(row_type row) const;
119 /// returns topmost row if passed (-1)
120 RowInfo & rowinfo(row_type row);
122 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
124 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
125 /// identifies GridInset
126 virtual MathGridInset * asGridInset() { return this; }
129 col_type ncols() const;
131 row_type nrows() const;
133 col_type col(idx_type idx) const;
135 row_type row(idx_type idx) const;
138 bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
140 bool idxLeft(idx_type & idx, pos_type & pos) const;
142 bool idxRight(idx_type & idx, pos_type & pos) const;
144 bool idxFirst(idx_type & idx, pos_type & pos) const;
146 bool idxLast(idx_type & idx, pos_type & pos) const;
148 bool idxHome(idx_type & idx, pos_type & pos) const;
150 bool idxEnd(idx_type & idx, pos_type & pos) const;
152 bool idxDelete(idx_type & idx);
153 /// pulls cell after pressing erase
154 void idxGlue(idx_type idx);
157 virtual void addRow(row_type r);
159 virtual void delRow(row_type r);
161 virtual void addFancyRow(row_type r) { addRow(r); }
163 virtual void delFancyRow(row_type r) { addRow(r); }
165 virtual void addCol(col_type c);
167 virtual void delCol(col_type c);
169 virtual void addFancyCol(col_type c) { addCol(c); }
171 virtual void delFancyCol(col_type c) { addCol(c); }
173 virtual void appendRow();
175 idx_type index(row_type r, col_type c) const;
177 std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
179 virtual int defaultColSpace(col_type) { return 0; }
181 virtual char defaultColAlign(col_type) { return 'c'; }
186 virtual int colsep() const;
188 virtual int rowsep() const;
190 virtual int hlinesep() const;
192 virtual int vlinesep() const;
194 virtual int border() const;
197 void write(WriteStream & os) const;
199 void normalize(NormalStream &) const;
201 //void maplize(MapleStream &) const;
203 void mathmlize(MathMLStream &) const;
205 //void octavize(OctaveStream &) const;
208 /// returns x offset of cell compared to inset
209 int cellXOffset(idx_type idx) const;
210 /// returns y offset of cell compared to inset
211 int cellYOffset(idx_type idx) const;
212 /// returns proper 'end of line' code for LaTeX
213 string eolString(row_type row, bool fragile = false) const;
214 /// returns proper 'end of column' code for LaTeX
215 string eocString(col_type col) const;
216 /// extract number of columns from alignment string
217 col_type guessColumns(string const & halign) const;
221 std::vector<RowInfo> rowinfo_;
223 std::vector<ColInfo> colinfo_;
225 std::vector<CellInfo> cellinfo_;
227 char v_align_; // add approp. type