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);
90 /// Ensures that the dialog is closed.
93 virtual std::auto_ptr<InsetBase> clone() const;
95 void metrics(MetricsInfo & mi) const;
97 void metrics(MetricsInfo & mi, Dimension &) const;
99 void draw(PainterInfo & pi, int x, int y) const;
101 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
103 void drawT(TextPainter & pi, int x, int y) const;
105 void halign(string const & align);
107 void halign(char c, col_type col);
109 char halign(col_type col) const;
111 string halign() const;
117 void vcrskip(LyXLength const &, row_type row);
119 LyXLength vcrskip(row_type row) const;
121 void resize(short int type, col_type cols);
123 const RowInfo & rowinfo(row_type row) const;
124 /// returns topmost row if passed (-1)
125 RowInfo & rowinfo(row_type row);
127 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
129 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
130 /// identifies GridInset
131 MathGridInset * asGridInset() { return this; }
132 /// identifies GridInset
133 MathGridInset const * asGridInset() const { return this; }
135 dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
138 col_type ncols() const;
140 row_type nrows() const;
142 col_type col(idx_type idx) const;
144 row_type row(idx_type idx) const;
147 bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
149 bool idxLeft(idx_type & idx, pos_type & pos) const;
151 bool idxRight(idx_type & idx, pos_type & pos) const;
153 bool idxFirst(idx_type & idx, pos_type & pos) const;
155 bool idxLast(idx_type & idx, pos_type & pos) const;
157 bool idxHome(idx_type & idx, pos_type & pos) const;
159 bool idxEnd(idx_type & idx, pos_type & pos) const;
161 bool idxDelete(idx_type & idx);
162 /// pulls cell after pressing erase
163 void idxGlue(idx_type idx);
166 virtual void addRow(row_type r);
168 virtual void delRow(row_type r);
170 virtual void copyRow(row_type r);
172 virtual void swapRow(row_type r);
174 virtual void addCol(col_type c);
176 virtual void delCol(col_type c);
178 virtual void copyCol(col_type c);
180 virtual void swapCol(col_type c);
182 virtual void appendRow();
184 idx_type index(row_type r, col_type c) const;
186 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
188 virtual int defaultColSpace(col_type) { return 0; }
190 virtual char defaultColAlign(col_type) { return 'c'; }
195 virtual int colsep() const;
197 virtual int rowsep() const;
199 virtual int hlinesep() const;
201 virtual int vlinesep() const;
203 virtual int border() const;
206 void write(WriteStream & os) const;
208 void normalize(NormalStream &) const;
210 //void maple(MapleStream &) const;
212 void mathmlize(MathMLStream &) const;
214 //void octave(OctaveStream &) const;
217 /// returns x offset of cell compared to inset
218 int cellXOffset(idx_type idx) const;
219 /// returns y offset of cell compared to inset
220 int cellYOffset(idx_type idx) const;
221 /// returns proper 'end of line' code for LaTeX
222 virtual string eolString(row_type row, bool fragile = false) const;
223 /// returns proper 'end of column' code for LaTeX
224 virtual string eocString(col_type col, col_type lastcol) const;
225 /// extract number of columns from alignment string
226 col_type guessColumns(string const & halign) const;
227 /// splits cells and shifts right part to the next cell
228 void splitCell(idx_type &, pos_type & pos);
232 std::vector<RowInfo> rowinfo_;
234 std::vector<ColInfo> colinfo_;
236 std::vector<CellInfo> cellinfo_;
238 char v_align_; // add approp. type