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 virtual MathGridInset * asGridInset() { return this; }
131 col_type ncols() const;
133 row_type nrows() const;
135 col_type col(idx_type idx) const;
137 row_type row(idx_type idx) const;
140 bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
142 bool idxLeft(idx_type & idx, pos_type & pos) const;
144 bool idxRight(idx_type & idx, pos_type & pos) const;
146 bool idxFirst(idx_type & idx, pos_type & pos) const;
148 bool idxLast(idx_type & idx, pos_type & pos) const;
150 bool idxHome(idx_type & idx, pos_type & pos) const;
152 bool idxEnd(idx_type & idx, pos_type & pos) 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 addFancyRow(row_type r) { addRow(r); }
165 virtual void delFancyRow(row_type r) { delRow(r); }
167 virtual void addCol(col_type c);
169 virtual void delCol(col_type c);
171 virtual void addFancyCol(col_type c) { addCol(c); }
173 virtual void delFancyCol(col_type c) { delCol(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 maplize(MapleStream &) const;
205 void mathmlize(MathMLStream &) const;
207 //void octavize(OctaveStream &) const;
210 /// returns x offset of cell compared to inset
211 int cellXOffset(idx_type idx) const;
212 /// returns y offset of cell compared to inset
213 int cellYOffset(idx_type idx) const;
214 /// returns proper 'end of line' code for LaTeX
215 string eolString(row_type row, bool fragile = false) const;
216 /// returns proper 'end of column' code for LaTeX
217 string eocString(col_type col) const;
218 /// extract number of columns from alignment string
219 col_type guessColumns(string const & halign) const;
223 std::vector<RowInfo> rowinfo_;
225 std::vector<ColInfo> colinfo_;
227 std::vector<CellInfo> cellinfo_;
229 char v_align_; // add approp. type