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(MetricsInfo
const & mi
) 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?
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, vertical alingment to 'c'
95 InsetMathGrid(Buffer
* buf
);
96 /// Note: columns first!
97 InsetMathGrid(Buffer
* buf
, col_type m
, row_type n
);
99 InsetMathGrid(Buffer
* buf
, col_type m
, row_type n
, char valign
,
100 docstring
const & halign
);
102 void metrics(MetricsInfo
& mi
, Dimension
&) const;
104 void draw(PainterInfo
& pi
, int x
, int y
) const;
106 void drawWithMargin(PainterInfo
& pi
, int x
, int y
,
107 int lmargin
= 0, int rmargin
= 0) const;
108 /// draw decorations.
109 void drawDecoration(PainterInfo
& pi
, int x
, int y
) const
110 { drawMarkers2(pi
, x
, y
); }
112 void metricsT(TextMetricsInfo
const & mi
, Dimension
& dim
) const;
114 void drawT(TextPainter
& pi
, int x
, int y
) const;
115 /// extract number of columns from alignment string
116 static col_type
guessColumns(docstring
const & halign
);
117 /// accepts some LaTeX column codes: p,m,!,@,M,<,>
118 void setHorizontalAlignments(docstring
const & align
);
120 void setHorizontalAlignment(char c
, col_type col
);
122 char horizontalAlignment(col_type col
) const;
124 docstring
horizontalAlignments() const;
126 void setVerticalAlignment(char c
);
128 char verticalAlignment() const;
130 void vcrskip(Length
const &, row_type row
);
132 Length
vcrskip(row_type row
) const;
134 void resize(short int type
, col_type cols
);
136 const RowInfo
& rowinfo(row_type row
) const;
137 /// returns topmost row if passed (-1)
138 RowInfo
& rowinfo(row_type row
);
140 const CellInfo
& cellinfo(idx_type idx
) const { return cellinfo_
[idx
]; }
142 CellInfo
& cellinfo(idx_type idx
) { return cellinfo_
[idx
]; }
143 /// identifies GridInset
144 InsetMathGrid
* asGridInset() { return this; }
145 /// identifies GridInset
146 InsetMathGrid
const * asGridInset() const { return this; }
148 col_type
ncols() const;
150 row_type
nrows() const;
152 col_type
col(idx_type idx
) const;
154 row_type
row(idx_type idx
) const;
157 bool idxUpDown(Cursor
&, bool up
) const;
159 bool idxBackward(Cursor
&) const;
161 bool idxForward(Cursor
&) const;
163 bool idxFirst(Cursor
&) const;
165 bool idxLast(Cursor
&) const;
167 bool idxDelete(idx_type
& idx
);
168 /// pulls cell after pressing erase
169 void idxGlue(idx_type idx
);
171 /// add a row, one row down
172 virtual void addRow(row_type r
);
174 virtual void delRow(row_type r
);
176 virtual void copyRow(row_type r
);
178 virtual void swapRow(row_type r
);
179 /// add a column, here
180 virtual void addCol(col_type c
);
182 virtual void delCol(col_type c
);
184 virtual void copyCol(col_type c
);
186 virtual void swapCol(col_type c
);
188 virtual void appendRow();
190 idx_type
index(row_type r
, col_type c
) const;
192 bool idxBetween(idx_type idx
, idx_type from
, idx_type to
) const;
194 virtual int defaultColSpace(col_type
) { return 0; }
196 virtual char defaultColAlign(col_type
) { return 'c'; }
201 virtual int colsep() const;
203 virtual int rowsep() const;
205 virtual int hlinesep() const;
207 virtual int vlinesep() const;
209 virtual int border() const;
212 void write(WriteStream
& os
) const;
214 void write(WriteStream
& os
,
215 row_type beg_row
, col_type beg_col
,
216 row_type end_row
, col_type end_col
) const;
218 void normalize(NormalStream
&) const;
220 //void maple(MapleStream &) const;
222 void mathmlize(MathStream
&) const;
224 //void octave(OctaveStream &) const;
228 void doDispatch(Cursor
& cur
, FuncRequest
& cmd
);
230 bool getStatus(Cursor
& cur
, FuncRequest
const & cmd
,
231 FuncStatus
& flag
) const;
232 /// returns x offset of cell compared to inset
233 int cellXOffset(BufferView
const &, idx_type idx
) const;
234 /// returns y offset of cell compared to inset
235 int cellYOffset(idx_type idx
) const;
236 /// returns proper 'end of line' code for LaTeX
237 virtual docstring
eolString(row_type row
, bool fragile
) const;
238 /// returns proper 'end of column' code for LaTeX
239 virtual docstring
eocString(col_type col
, col_type lastcol
) const;
240 /// splits cells and shifts right part to the next cell
241 void splitCell(Cursor
& cur
);
244 /// rowinfo_[nrows()] is a dummy row used only for hlines.
245 std::vector
<RowInfo
> rowinfo_
;
247 /// colinfo_[ncols()] is a dummy column used only for vlines.
248 std::vector
<ColInfo
> colinfo_
;
250 std::vector
<CellInfo
> cellinfo_
;
252 InsetCode
lyxCode() const { return MATH_GRID_CODE
; }
256 char v_align_
; // add approp. type
258 Inset
* clone() const;