5 #include "math_nestinset.h"
8 #include "math_gridinfo.h"
11 /** Gridded math inset base class.
12 This is the base to all grid-like editable math objects
13 like array and eqnarray.
14 * \author André Pönitz 2001
16 * Full author contact details are available in file CREDITS
19 class MathGridInset : public MathNestInset {
23 /// additional per-cell information
24 struct CellInfo : public ::CellInfo {
28 mutable pos_type begin_;
30 mutable pos_type end_;
33 /// additional per-row information
34 struct RowInfo : public ::RowInfo {
41 int skipPixels() const;
42 /// how many hlines above this row?
44 /// parameter to the line break
46 /// extra distance between lines on screen
57 // additional per-row information
58 struct ColInfo : public ::ColInfo {
66 /// additional amount to be skipped on screen
76 /// sets nrows and ncols to 1
78 /// constructor from columns description, creates one row
79 MathGridInset(char valign, string const & halign);
80 /// Note: columns first!
81 MathGridInset(col_type m, row_type n);
83 MathGridInset(col_type m, row_type n, char valign, string const & halign);
84 /// Ensures that the dialog is closed.
87 MathInset * clone() const;
89 void metrics(MetricsInfo & mi) const;
91 void draw(PainterInfo & pi, int x, int y) const;
93 void metricsT(TextMetricsInfo const & mi) const;
95 void drawT(TextPainter & pi, int x, int y) const;
97 void halign(string const & align);
99 void halign(char c, col_type col);
101 char halign(col_type col) const;
103 string halign() const;
109 void vcrskip(LyXLength const &, row_type row);
111 LyXLength vcrskip(row_type row) const;
113 void resize(short int type, col_type cols);
115 const RowInfo & rowinfo(row_type row) const;
116 /// returns topmost row if passed (-1)
117 RowInfo & rowinfo(row_type row);
119 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
121 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
122 /// identifies GridInset
123 MathGridInset * asGridInset() { return this; }
124 /// identifies GridInset
125 MathGridInset const * asGridInset() const { return this; }
127 dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
130 col_type ncols() const;
132 row_type nrows() const;
134 col_type col(idx_type idx) const;
136 row_type row(idx_type idx) const;
139 bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
141 bool idxLeft(idx_type & idx, pos_type & pos) const;
143 bool idxRight(idx_type & idx, pos_type & pos) const;
145 bool idxFirst(idx_type & idx, pos_type & pos) const;
147 bool idxLast(idx_type & idx, pos_type & pos) const;
149 bool idxHome(idx_type & idx, pos_type & pos) const;
151 bool idxEnd(idx_type & idx, pos_type & pos) const;
153 bool idxDelete(idx_type & idx);
154 /// pulls cell after pressing erase
155 void idxGlue(idx_type idx);
158 virtual void addRow(row_type r);
160 virtual void delRow(row_type r);
162 virtual void copyRow(row_type r);
164 virtual void swapRow(row_type r);
166 virtual void addCol(col_type c);
168 virtual void delCol(col_type c);
170 virtual void copyCol(col_type c);
172 virtual void swapCol(col_type c);
174 virtual void appendRow();
176 idx_type index(row_type r, col_type c) const;
178 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
180 virtual int defaultColSpace(col_type) { return 0; }
182 virtual char defaultColAlign(col_type) { return 'c'; }
187 virtual int colsep() const;
189 virtual int rowsep() const;
191 virtual int hlinesep() const;
193 virtual int vlinesep() const;
195 virtual int border() const;
198 void write(WriteStream & os) const;
200 void normalize(NormalStream &) const;
202 //void maple(MapleStream &) const;
204 void mathmlize(MathMLStream &) const;
206 //void octave(OctaveStream &) const;
209 /// returns x offset of cell compared to inset
210 int cellXOffset(idx_type idx) const;
211 /// returns y offset of cell compared to inset
212 int cellYOffset(idx_type idx) const;
213 /// returns proper 'end of line' code for LaTeX
214 virtual string eolString(row_type row, bool fragile = false) const;
215 /// returns proper 'end of column' code for LaTeX
216 virtual string eocString(col_type col, col_type lastcol) const;
217 /// splits cells and shifts right part to the next cell
218 void splitCell(idx_type &, pos_type & pos);
222 std::vector<RowInfo> rowinfo_;
224 std::vector<ColInfo> colinfo_;
226 std::vector<CellInfo> cellinfo_;
228 char v_align_; // add approp. type