]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathGrid.h
fix bug 4132: parse some more column specifiers
[lyx.git] / src / mathed / InsetMathGrid.h
1 // -*- C++ -*-
2 /**
3  * \file InsetMathGrid.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef MATH_GRID_H
13 #define MATH_GRID_H
14
15 #include "InsetMathNest.h"
16 #include "Length.h"
17
18
19 namespace lyx {
20
21
22 /** Gridded math inset base class.
23  *  This is the base to all grid-like editable math objects
24  */
25 class InsetMathGrid : public InsetMathNest {
26 public:
27
28         /// additional per-cell information
29         class CellInfo {
30         public:
31                 ///
32                 CellInfo();
33                 /// a dummy cell before a multicolumn cell
34                 int dummy_;
35                 /// special multi colums alignment
36                 docstring align_;
37                 /// these should be a per-cell property, but ok to have it here
38                 /// for single-column grids like paragraphs
39                 mutable int glue_;
40                 ///
41                 mutable pos_type begin_;
42                 ///
43                 mutable pos_type end_;
44         };
45
46         /// additional per-row information
47         class RowInfo {
48         public:
49                 ///
50                 RowInfo();
51                 ///
52                 int skipPixels() const;
53                 /// cached descent
54                 mutable int descent_;
55                 /// cached ascent
56                 mutable int ascent_;
57                 /// cached offset
58                 mutable int offset_;
59                 /// how many hlines above this row?
60                 unsigned int lines_;
61                 /// parameter to the line break
62                 Length crskip_;
63                 /// extra distance between lines
64                 int skip_;
65                 /// Is a page break allowed after this row?
66                 bool allow_pagebreak_;
67         };
68
69         // additional per-row information
70         class ColInfo {
71         public:
72                 ///
73                 ColInfo();
74                 /// currently possible: 'l', 'c', 'r'
75                 char align_;
76                 /// cache for drawing
77                 int h_offset;
78                 /// cached width
79                 mutable int width_;
80                 /// cached offset
81                 mutable int offset_;
82                 /// how many lines to the left of this column?
83                 unsigned int lines_;
84                 /// additional amount to be skipped when drawing
85                 int skip_;
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_.
90                 docstring special_;
91         };
92
93 public:
94         /// sets nrows and ncols to 1
95         InsetMathGrid();
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);
100         ///
101         InsetMathGrid(col_type m, row_type n, char valign, docstring const & halign);
102         ///
103         void metrics(MetricsInfo & mi) const;
104         ///
105         bool metrics(MetricsInfo & mi, Dimension &) const;
106         ///
107         void draw(PainterInfo & pi, int x, int y) const;
108         ///
109         void drawWithMargin(PainterInfo & pi, int x, int y,
110                 int lmargin = 0, int rmargin = 0) const;
111         /// draw decorations.
112         void drawDecoration(PainterInfo & pi, int x, int y) const
113         { drawMarkers2(pi, x, y); }
114         ///
115         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
116         ///
117         void drawT(TextPainter & pi, int x, int y) const;
118         ///
119         void halign(docstring const & align);
120         ///
121         void halign(char c, col_type col);
122         ///
123         char halign(col_type col) const;
124         ///
125         docstring halign() const;
126         ///
127         void valign(char c);
128         ///
129         char valign() const;
130         ///
131         void vcrskip(Length const &, row_type row);
132         ///
133         Length vcrskip(row_type row) const;
134         ///
135         void resize(short int type, col_type cols);
136         ///
137         const RowInfo & rowinfo(row_type row) const;
138         /// returns topmost row if passed (-1)
139         RowInfo & rowinfo(row_type row);
140         ///
141         const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
142         ///
143         CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
144         /// identifies GridInset
145         InsetMathGrid * asGridInset() { return this; }
146         /// identifies GridInset
147         InsetMathGrid const * asGridInset() const { return this; }
148         ///
149         col_type ncols() const;
150         ///
151         row_type nrows() const;
152         ///
153         col_type col(idx_type idx) const;
154         ///
155         row_type row(idx_type idx) const;
156
157         ///
158         bool idxUpDown(Cursor &, bool up) const;
159         ///
160         bool idxLeft(Cursor &) const;
161         ///
162         bool idxRight(Cursor &) const;
163         ///
164         bool idxFirst(Cursor &) const;
165         ///
166         bool idxLast(Cursor &) const;
167         ///
168         bool idxDelete(idx_type & idx);
169         /// pulls cell after pressing erase
170         void idxGlue(idx_type idx);
171
172         /// add a row
173         virtual void addRow(row_type r);
174         /// delete a row
175         virtual void delRow(row_type r);
176         /// copy a row
177         virtual void copyRow(row_type r);
178         /// swap two rows
179         virtual void swapRow(row_type r);
180         /// add a column
181         virtual void addCol(col_type c);
182         /// delete a column
183         virtual void delCol(col_type c);
184         /// copy a column
185         virtual void copyCol(col_type c);
186         /// swap two columns
187         virtual void swapCol(col_type c);
188         ///
189         virtual void appendRow();
190         ///
191         idx_type index(row_type r, col_type c) const;
192         ///
193         bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
194         ///
195         virtual int defaultColSpace(col_type) { return 0; }
196         ///
197         virtual char defaultColAlign(col_type) { return 'c'; }
198         ///
199         void setDefaults();
200
201         ///
202         virtual int colsep() const;
203         ///
204         virtual int rowsep() const;
205         ///
206         virtual int hlinesep() const;
207         ///
208         virtual int vlinesep() const;
209         ///
210         virtual int border() const;
211
212         ///
213         void write(WriteStream & os) const;
214         ///
215         void normalize(NormalStream &) const;
216         ///
217         //void maple(MapleStream &) const;
218         ///
219         void mathmlize(MathStream &) const;
220         ///
221         //void octave(OctaveStream &) const;
222
223 protected:
224         virtual void doDispatch(Cursor & cur, FuncRequest & cmd);
225         ///
226         bool getStatus(Cursor & cur, FuncRequest const & cmd,
227                 FuncStatus & flag) const;
228         /// returns x offset of cell compared to inset
229         int cellXOffset(idx_type idx) const;
230         /// returns y offset of cell compared to inset
231         int cellYOffset(idx_type idx) const;
232         /// returns proper 'end of line' code for LaTeX
233         virtual docstring eolString(row_type row, bool emptyline,
234                                       bool fragile) const;
235         /// returns proper 'end of column' code for LaTeX
236         virtual docstring eocString(col_type col, col_type lastcol) const;
237         /// extract number of columns from alignment string
238         col_type guessColumns(docstring const & halign) const;
239         /// splits cells and shifts right part to the next cell
240         void splitCell(Cursor & cur);
241
242         /// row info.
243         /// rowinfo_[nrows()] is a dummy row used only for hlines.
244         std::vector<RowInfo> rowinfo_;
245         /// column info.
246         /// colinfo_[ncols()] is a dummy column used only for vlines.
247         std::vector<ColInfo> colinfo_;
248         /// cell info
249         std::vector<CellInfo> cellinfo_;
250         ///
251         char v_align_; // add approp. type
252 private:
253         virtual std::auto_ptr<Inset> doClone() const;
254 };
255
256
257
258 } // namespace lyx
259 #endif