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
30 /// a dummy cell before a multicolumn cell
32 /// special multi colums alignment
34 /// these should be a per-cell property, but ok to have it here
35 /// for single-column grids like paragraphs
38 mutable pos_type begin_;
40 mutable pos_type end_;
43 /// additional per-row information
49 int skipPixels() const;
56 /// how many hlines above this row?
58 /// parameter to the line break
60 /// extra distance between lines
64 // additional per-row information
69 /// currently possible: 'l', 'c', 'r'
77 /// how many lines to the left of this column?
79 /// additional amount to be skipped when drawing
84 /// sets nrows and ncols to 1
86 /// constructor from columns description, creates one row
87 MathGridInset(char valign, std::string const & halign);
88 /// Note: columns first!
89 MathGridInset(col_type m, row_type n);
91 MathGridInset(col_type m, row_type n, char valign, std::string const & halign);
92 /// Ensures that the dialog is closed.
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 drawWithMargin(PainterInfo & pi, int x, int y,
102 int lmargin = 0, int rmargin = 0) const;
104 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
106 void drawT(TextPainter & pi, int x, int y) const;
108 void halign(std::string const & align);
110 void halign(char c, col_type col);
112 char halign(col_type col) const;
114 std::string halign() const;
120 void vcrskip(LyXLength const &, row_type row);
122 LyXLength vcrskip(row_type row) const;
124 void resize(short int type, col_type cols);
126 const RowInfo & rowinfo(row_type row) const;
127 /// returns topmost row if passed (-1)
128 RowInfo & rowinfo(row_type row);
130 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
132 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
133 /// identifies GridInset
134 MathGridInset * asGridInset() { return this; }
135 /// identifies GridInset
136 MathGridInset const * asGridInset() const { return this; }
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(LCursor &, bool up) const;
149 bool idxLeft(LCursor &) const;
151 bool idxRight(LCursor &) const;
153 bool idxFirst(LCursor &) const;
155 bool idxLast(LCursor &) 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 maple(MapleStream &) const;
208 void mathmlize(MathMLStream &) const;
210 //void octave(OctaveStream &) const;
213 virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
215 bool getStatus(LCursor & cur, FuncRequest const & cmd,
216 FuncStatus & flag) 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 std::string eolString(row_type row, bool emptyline,
224 /// returns proper 'end of column' code for LaTeX
225 virtual std::string eocString(col_type col, col_type lastcol) const;
226 /// extract number of columns from alignment string
227 col_type guessColumns(std::string const & halign) const;
228 /// splits cells and shifts right part to the next cell
229 void splitCell(LCursor & cur);
232 /// rowinfo_[nrows()] is a dummy row used only for hlines.
233 std::vector<RowInfo> rowinfo_;
235 /// colinfo_[ncols()] is a dummy column used only for vlines.
236 std::vector<ColInfo> colinfo_;
238 std::vector<CellInfo> cellinfo_;
240 char v_align_; // add approp. type
242 virtual std::auto_ptr<InsetBase> doClone() const;