3 * \file InsetMathGrid.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 "InsetMathNest.h"
22 /** Gridded math inset base class.
23 * This is the base to all grid-like editable math objects
25 class InsetMathGrid : public InsetMathNest {
28 /// additional per-cell information
33 /// a dummy cell before a multicolumn cell
35 /// special multi colums alignment
37 /// these should be a per-cell property, but ok to have it here
38 /// for single-column grids like paragraphs
41 mutable pos_type begin_;
43 mutable pos_type end_;
46 /// additional per-row information
52 int skipPixels() const;
59 /// how many hlines above this row?
61 /// parameter to the line break
63 /// extra distance between lines
65 /// Is a page break allowed after this row?
66 bool allow_pagebreak_;
69 // additional per-row information
74 /// currently possible: 'l', 'c', 'r'
82 /// how many lines to the left of this column?
84 /// additional amount to be skipped when drawing
86 /// Special alignment.
87 /// This does also contain align_ and lines_ if it is nonempty.
88 /// It needs to be in sync with align_ and lines_ because some
89 /// code only uses align_ and lines_.
94 /// sets nrows and ncols to 1
96 /// constructor from columns description, creates one row
97 InsetMathGrid(char valign, docstring const & halign);
98 /// Note: columns first!
99 InsetMathGrid(col_type m, row_type n);
101 InsetMathGrid(col_type m, row_type n, char valign, docstring const & halign);
103 void metrics(MetricsInfo & mi, Dimension &) const;
105 void draw(PainterInfo & pi, int x, int y) const;
107 void drawWithMargin(PainterInfo & pi, int x, int y,
108 int lmargin = 0, int rmargin = 0) const;
109 /// draw decorations.
110 void drawDecoration(PainterInfo & pi, int x, int y) const
111 { drawMarkers2(pi, x, y); }
113 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
115 void drawT(TextPainter & pi, int x, int y) const;
117 void halign(docstring const & align);
119 void halign(char c, col_type col);
121 char halign(col_type col) const;
123 docstring halign() const;
129 void vcrskip(Length const &, row_type row);
131 Length vcrskip(row_type row) const;
133 void resize(short int type, col_type cols);
135 const RowInfo & rowinfo(row_type row) const;
136 /// returns topmost row if passed (-1)
137 RowInfo & rowinfo(row_type row);
139 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
141 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
142 /// identifies GridInset
143 InsetMathGrid * asGridInset() { return this; }
144 /// identifies GridInset
145 InsetMathGrid const * asGridInset() const { return this; }
147 col_type ncols() const;
149 row_type nrows() const;
151 col_type col(idx_type idx) const;
153 row_type row(idx_type idx) const;
156 bool idxUpDown(Cursor &, bool up) const;
158 bool idxLeft(Cursor &) const;
160 bool idxRight(Cursor &) const;
162 bool idxFirst(Cursor &) const;
164 bool idxLast(Cursor &) const;
166 bool idxDelete(idx_type & idx);
167 /// pulls cell after pressing erase
168 void idxGlue(idx_type idx);
171 virtual void addRow(row_type r);
173 virtual void delRow(row_type r);
175 virtual void copyRow(row_type r);
177 virtual void swapRow(row_type r);
179 virtual void addCol(col_type c);
181 virtual void delCol(col_type c);
183 virtual void copyCol(col_type c);
185 virtual void swapCol(col_type c);
187 virtual void appendRow();
189 idx_type index(row_type r, col_type c) const;
191 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
193 virtual int defaultColSpace(col_type) { return 0; }
195 virtual char defaultColAlign(col_type) { return 'c'; }
200 virtual int colsep() const;
202 virtual int rowsep() const;
204 virtual int hlinesep() const;
206 virtual int vlinesep() const;
208 virtual int border() const;
211 void write(WriteStream & os) const;
213 void normalize(NormalStream &) const;
215 //void maple(MapleStream &) const;
217 void mathmlize(MathStream &) const;
219 //void octave(OctaveStream &) const;
222 virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
224 bool getStatus(Cursor & cur, FuncRequest const & cmd,
225 FuncStatus & flag) const;
226 /// returns x offset of cell compared to inset
227 int cellXOffset(BufferView const &, idx_type idx) const;
228 /// returns y offset of cell compared to inset
229 int cellYOffset(idx_type idx) const;
230 /// returns proper 'end of line' code for LaTeX
231 virtual docstring eolString(row_type row, bool emptyline,
233 /// returns proper 'end of column' code for LaTeX
234 virtual docstring eocString(col_type col, col_type lastcol) const;
235 /// extract number of columns from alignment string
236 col_type guessColumns(docstring const & halign) const;
237 /// splits cells and shifts right part to the next cell
238 void splitCell(Cursor & cur);
241 /// rowinfo_[nrows()] is a dummy row used only for hlines.
242 std::vector<RowInfo> rowinfo_;
244 /// colinfo_[ncols()] is a dummy column used only for vlines.
245 std::vector<ColInfo> colinfo_;
247 std::vector<CellInfo> cellinfo_;
249 char v_align_; // add approp. type
251 virtual Inset * clone() const;