3 * \file math_gridinset.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
15 #include "math_nestinset.h"
16 #include "lyxlength.h"
19 /** Gridded math inset base class.
20 * This is the base to all grid-like editable math objects
22 class MathGridInset : public MathNestInset {
25 /// additional per-cell information
29 /// a dummy cell before a multicolumn cell
31 /// special multi colums alignment
33 /// these should be a per-cell property, but ok to have it here
34 /// for single-column grids like paragraphs
37 mutable pos_type begin_;
39 mutable pos_type end_;
42 /// additional per-row information
47 int skipPixels() const;
54 /// how many hlines above this row?
56 /// parameter to the line break
58 /// extra distance between lines
62 // additional per-row information
66 /// currently possible: 'l', 'c', 'r'
74 /// do we need a line to the left?
76 /// do we need a line to the right?
78 /// how many lines to the left of this column?
80 /// additional amount to be skipped when drawing
85 /// sets nrows and ncols to 1
87 /// constructor from columns description, creates one row
88 MathGridInset(char valign, std::string const & halign);
89 /// Note: columns first!
90 MathGridInset(col_type m, row_type n);
92 MathGridInset(col_type m, row_type n, char valign, std::string const & halign);
93 /// Ensures that the dialog is closed.
96 void metrics(MetricsInfo & mi) const;
98 void metrics(MetricsInfo & mi, Dimension &) const;
100 void draw(PainterInfo & pi, int x, int y) const;
102 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
104 void drawT(TextPainter & pi, int x, int y) const;
106 void halign(std::string const & align);
108 void halign(char c, col_type col);
110 char halign(col_type col) const;
112 std::string halign() const;
118 void vcrskip(LyXLength const &, row_type row);
120 LyXLength vcrskip(row_type row) const;
122 void resize(short int type, col_type cols);
124 const RowInfo & rowinfo(row_type row) const;
125 /// returns topmost row if passed (-1)
126 RowInfo & rowinfo(row_type row);
128 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
130 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
131 /// identifies GridInset
132 MathGridInset * asGridInset() { return this; }
133 /// identifies GridInset
134 MathGridInset const * asGridInset() const { return this; }
136 col_type ncols() const;
138 row_type nrows() const;
140 col_type col(idx_type idx) const;
142 row_type row(idx_type idx) const;
145 bool idxUpDown(LCursor &, bool up) const;
147 bool idxLeft(LCursor &) const;
149 bool idxRight(LCursor &) const;
151 bool idxFirst(LCursor &) const;
153 bool idxLast(LCursor &) const;
155 bool idxDelete(idx_type & idx);
156 /// pulls cell after pressing erase
157 void idxGlue(idx_type idx);
160 virtual void addRow(row_type r);
162 virtual void delRow(row_type r);
164 virtual void copyRow(row_type r);
166 virtual void swapRow(row_type r);
168 virtual void addCol(col_type c);
170 virtual void delCol(col_type c);
172 virtual void copyCol(col_type c);
174 virtual void swapCol(col_type c);
176 virtual void appendRow();
178 idx_type index(row_type r, col_type c) const;
180 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
182 virtual int defaultColSpace(col_type) { return 0; }
184 virtual char defaultColAlign(col_type) { return 'c'; }
189 virtual int colsep() const;
191 virtual int rowsep() const;
193 virtual int hlinesep() const;
195 virtual int vlinesep() const;
197 virtual int border() const;
200 void write(WriteStream & os) const;
202 void normalize(NormalStream &) const;
204 //void maple(MapleStream &) const;
206 void mathmlize(MathMLStream &) const;
208 //void octave(OctaveStream &) const;
211 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
213 bool getStatus(LCursor & cur, FuncRequest const & cmd,
214 FuncStatus & flag) const;
215 /// returns x offset of cell compared to inset
216 int cellXOffset(idx_type idx) const;
217 /// returns y offset of cell compared to inset
218 int cellYOffset(idx_type idx) const;
219 /// returns proper 'end of line' code for LaTeX
220 virtual std::string eolString(row_type row, bool fragile = false) const;
221 /// returns proper 'end of column' code for LaTeX
222 virtual std::string eocString(col_type col, col_type lastcol) const;
223 /// extract number of columns from alignment string
224 col_type guessColumns(std::string const & halign) const;
225 /// splits cells and shifts right part to the next cell
226 void splitCell(LCursor & cur);
230 std::vector<RowInfo> rowinfo_;
232 std::vector<ColInfo> colinfo_;
234 std::vector<CellInfo> cellinfo_;
236 char v_align_; // add approp. type
238 virtual std::auto_ptr<InsetBase> doClone() const;