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 {
26 /// 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
48 int skipPixels() const;
55 /// how many hlines above this row?
57 /// parameter to the line break
59 /// extra distance between lines
63 // additional per-row information
67 /// currently possible: 'l', 'c', 'r'
75 /// do we need a line to the left?
77 /// do we need a line to the right?
79 /// how many lines to the left of this column?
81 /// additional amount to be skipped when drawing
86 /// sets nrows and ncols to 1
88 /// constructor from columns description, creates one row
89 MathGridInset(char valign, std::string const & halign);
90 /// Note: columns first!
91 MathGridInset(col_type m, row_type n);
93 MathGridInset(col_type m, row_type n, char valign, std::string const & halign);
94 /// Ensures that the dialog is closed.
97 virtual std::auto_ptr<InsetBase> clone() const;
99 void metrics(MetricsInfo & mi) const;
101 void metrics(MetricsInfo & mi, Dimension &) const;
103 void draw(PainterInfo & pi, int x, int y) const;
105 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
107 void drawT(TextPainter & pi, int x, int y) const;
109 void halign(std::string const & align);
111 void halign(char c, col_type col);
113 char halign(col_type col) const;
115 std::string halign() const;
121 void vcrskip(LyXLength const &, row_type row);
123 LyXLength vcrskip(row_type row) const;
125 void resize(short int type, col_type cols);
127 const RowInfo & rowinfo(row_type row) const;
128 /// returns topmost row if passed (-1)
129 RowInfo & rowinfo(row_type row);
131 const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
133 CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
134 /// identifies GridInset
135 MathGridInset * asGridInset() { return this; }
136 /// identifies GridInset
137 MathGridInset const * asGridInset() const { return this; }
139 col_type ncols() const;
141 row_type nrows() const;
143 col_type col(idx_type idx) const;
145 row_type row(idx_type idx) const;
148 bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
150 bool idxLeft(idx_type & idx, pos_type & pos) const;
152 bool idxRight(idx_type & idx, pos_type & pos) const;
154 bool idxFirst(idx_type & idx, pos_type & pos) const;
156 bool idxLast(idx_type & idx, pos_type & pos) const;
158 bool idxHome(idx_type & idx, pos_type & pos) const;
160 bool idxEnd(idx_type & idx, pos_type & pos) const;
162 bool idxDelete(idx_type & idx);
163 /// pulls cell after pressing erase
164 void idxGlue(idx_type idx);
167 virtual void addRow(row_type r);
169 virtual void delRow(row_type r);
171 virtual void copyRow(row_type r);
173 virtual void swapRow(row_type r);
175 virtual void addCol(col_type c);
177 virtual void delCol(col_type c);
179 virtual void copyCol(col_type c);
181 virtual void swapCol(col_type c);
183 virtual void appendRow();
185 idx_type index(row_type r, col_type c) const;
187 bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
189 virtual int defaultColSpace(col_type) { return 0; }
191 virtual char defaultColAlign(col_type) { return 'c'; }
196 virtual int colsep() const;
198 virtual int rowsep() const;
200 virtual int hlinesep() const;
202 virtual int vlinesep() const;
204 virtual int border() const;
207 void write(WriteStream & os) const;
209 void normalize(NormalStream &) const;
211 //void maple(MapleStream &) const;
213 void mathmlize(MathMLStream &) const;
215 //void octave(OctaveStream &) const;
221 priv_dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
223 /// returns x offset of cell compared to inset
224 int cellXOffset(idx_type idx) const;
225 /// returns y offset of cell compared to inset
226 int cellYOffset(idx_type idx) const;
227 /// returns proper 'end of line' code for LaTeX
228 virtual std::string eolString(row_type row, bool fragile = false) const;
229 /// returns proper 'end of column' code for LaTeX
230 virtual std::string eocString(col_type col, col_type lastcol) const;
231 /// extract number of columns from alignment string
232 col_type guessColumns(std::string const & halign) const;
233 /// splits cells and shifts right part to the next cell
234 void splitCell(idx_type &, pos_type & pos);
238 std::vector<RowInfo> rowinfo_;
240 std::vector<ColInfo> colinfo_;
242 std::vector<CellInfo> cellinfo_;
244 char v_align_; // add approp. type