5 #include "math_nestinset.h"
10 /** Gridded math inset base class.
11 This is the base to all grid-like editable math objects
12 like array and eqnarray.
13 * \author André Pönitz 2001
15 * Full author contact details are available in file CREDITS
18 class MathGridInset : public MathNestInset {
22 /// additional per-cell information
26 /// a dummy cell before a multicolumn cell
28 /// special multi colums alignment
30 /// these should be a per-cell property, but ok to have it here
31 /// for single-column grids like paragraphs
34 mutable pos_type begin_;
36 mutable pos_type end_;
39 /// additional per-row information
44 int skipPixels() const;
51 /// how many hlines above this row?
53 /// parameter to the line break
55 /// extra distance between lines
59 // additional per-row information
63 /// currently possible: 'l', 'c', 'r'
71 /// do we need a line to the left?
73 /// do we need a line to the right?
75 /// how many lines to the left of this column?
77 /// additional amount to be skipped when drawing
82 /// sets nrows and ncols to 1
84 /// constructor from columns description, creates one row
85 MathGridInset(char valign, string const & halign);
86 /// Note: columns first!
87 MathGridInset(col_type m, row_type n);
89 MathGridInset(col_type m, row_type n, char valign, string const & halign);
91 MathInset * clone() const;
93 void metrics(MathMetricsInfo & mi) const;
95 void draw(MathPainterInfo & pi, int x, int y) const;
97 void metricsT(TextMetricsInfo const & mi) const;
99 void drawT(TextPainter & pi, int x, int y) const;
101 void halign(string const & align);
103 void halign(char c, col_type col);
105 char halign(col_type col) const;
107 string halign() const;
113 void vcrskip(LyXLength const &, row_type row);
115 LyXLength vcrskip(row_type row) const;
117 void resize(short int type, col_type cols);
119 const RowInfo & rowinfo(row_type row) const;
120 /// returns topmost row if passed (-1)
121 RowInfo & rowinfo(row_type row);
123 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
125 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
126 /// identifies GridInset
127 MathGridInset * asGridInset() { return this; }
128 /// identifies GridInset
129 MathGridInset const * asGridInset() const { return this; }
131 result_type dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
134 col_type ncols() const;
136 row_type nrows() const;
138 col_type col(idx_type idx) const;
140 row_type row(idx_type idx) const;
143 bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
145 bool idxLeft(idx_type & idx, pos_type & pos) const;
147 bool idxRight(idx_type & idx, pos_type & pos) const;
149 bool idxFirst(idx_type & idx, pos_type & pos) const;
151 bool idxLast(idx_type & idx, pos_type & pos) const;
153 bool idxHome(idx_type & idx, pos_type & pos) const;
155 bool idxEnd(idx_type & idx, pos_type & pos) const;
157 bool idxDelete(idx_type & idx);
158 /// pulls cell after pressing erase
159 void idxGlue(idx_type idx);
162 virtual void addRow(row_type r);
164 virtual void delRow(row_type r);
166 virtual void copyRow(row_type r);
168 virtual void swapRow(row_type r);
170 virtual void addCol(col_type c);
172 virtual void delCol(col_type c);
174 virtual void copyCol(col_type c);
176 virtual void swapCol(col_type c);
178 virtual void appendRow();
180 idx_type index(row_type r, col_type c) const;
182 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
184 virtual int defaultColSpace(col_type) { return 0; }
186 virtual char defaultColAlign(col_type) { return 'c'; }
191 virtual int colsep() const;
193 virtual int rowsep() const;
195 virtual int hlinesep() const;
197 virtual int vlinesep() const;
199 virtual int border() const;
202 void write(WriteStream & os) const;
204 void normalize(NormalStream &) const;
206 //void maplize(MapleStream &) const;
208 void mathmlize(MathMLStream &) const;
210 //void octavize(OctaveStream &) const;
213 /// returns x offset of cell compared to inset
214 int cellXOffset(idx_type idx) const;
215 /// returns y offset of cell compared to inset
216 int cellYOffset(idx_type idx) const;
217 /// returns proper 'end of line' code for LaTeX
218 virtual string eolString(row_type row, bool fragile = false) const;
219 /// returns proper 'end of column' code for LaTeX
220 virtual string eocString(col_type col, col_type lastcol) const;
221 /// extract number of columns from alignment string
222 col_type guessColumns(string const & halign) const;
223 /// splits cells and shifts right part to the next cell
224 void splitCell(idx_type &, pos_type & pos);
228 std::vector<RowInfo> rowinfo_;
230 std::vector<ColInfo> colinfo_;
232 std::vector<CellInfo> cellinfo_;
234 char v_align_; // add approp. type