]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
0f8bfb68d881cf9d6b45eb73239a4fba5b330832
[lyx.git] / src / mathed / math_gridinset.h
1 // -*- C++ -*-
2 #ifndef MATH_GRID_H
3 #define MATH_GRID_H
4
5 #include "math_nestinset.h"
6 #include "vspace.h"
7 #include "LString.h"
8
9 #ifdef __GNUG__
10 #pragma interface
11 #endif
12
13 /** Gridded math inset base class.
14     This is the base to all grid-like editable math objects
15     like array and eqnarray.
16     \author André Pönitz 2001
17 */
18
19 class MathGridInset : public MathNestInset {
20
21 public:
22
23         /// additional per-cell information
24         struct CellInfo {
25                 ///
26                 CellInfo();
27                 /// a dummy cell before a multicolumn cell
28                 int dummy_;
29                 /// special multi colums alignment
30                 string align_;
31                 /// these should be a per-cell property, but ok to have it here
32                 /// for single-column grids like paragraphs
33                 mutable int glue_;
34                 ///
35                 mutable pos_type begin_;
36                 ///
37                 mutable pos_type end_;
38         };
39
40         /// additional per-row information
41         struct RowInfo {
42                 ///
43                 RowInfo();
44                 ///
45                 int skipPixels() const;
46                 /// cached descent
47                 mutable int descent_;
48                 /// cached ascent
49                 mutable int ascent_;
50                 /// cached offset
51                 mutable int offset_;
52                 /// how many hlines above this row?
53                 int lines_;
54                 /// parameter to the line break
55                 LyXLength crskip_;
56                 /// extra distance between lines
57                 int skip_;
58         };
59
60         // additional per-row information
61         struct ColInfo {
62                 ///
63                 ColInfo();
64                 /// currently possible: 'l', 'c', 'r'
65                 char align_;
66                 /// cache for drawing
67                 int h_offset;
68                 /// cached width
69                 mutable int width_;
70                 /// cached offset
71                 mutable int offset_;
72                 /// do we need a line to the left?
73                 bool leftline_;
74                 /// do we need a line to the right?
75                 bool rightline_;
76                 /// how many lines to the left of this column?
77                 int lines_;
78                 /// additional amount to be skipped when drawing
79                 int skip_;
80         };
81
82 public:
83         /// sets nrows and ncols to 1
84         MathGridInset();
85         /// constructor from columns description, creates one row
86         MathGridInset(char valign, string const & halign);
87         /// Note: columns first!
88         MathGridInset(col_type m, row_type n);
89         ///
90         MathGridInset(col_type m, row_type n, char valign, string const & halign);
91         ///
92         MathInset * clone() const;
93         ///
94         void metrics(MathMetricsInfo & mi) const;
95         ///
96         void draw(MathPainterInfo & pi, int x, int y) const;
97         ///
98         void metricsT(TextMetricsInfo const & mi) const;
99         ///
100         void drawT(TextPainter & pi, int x, int y) const;
101         ///
102         void halign(string const & align);
103         ///
104         void halign(char c, col_type col);
105         ///
106         char halign(col_type col) const;
107         ///
108         string halign() const;
109         ///
110         void valign(char c);
111         ///
112         char valign() const;
113         ///
114         void vcrskip(LyXLength const &, row_type row);
115         ///
116         LyXLength vcrskip(row_type row) const;
117         ///
118         void resize(short int type, col_type cols);
119         ///
120         const RowInfo & rowinfo(row_type row) const;
121         /// returns topmost row if passed (-1)
122         RowInfo & rowinfo(row_type row);
123         ///
124         const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
125         /// 
126         CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
127         /// identifies GridInset
128         MathGridInset * asGridInset() { return this; }
129         /// identifies GridInset
130         MathGridInset const * asGridInset() const { return this; }
131
132         ///
133         col_type ncols() const;
134         ///
135         row_type nrows() const;
136         ///
137         col_type col(idx_type idx) const;
138         ///
139         row_type row(idx_type idx) const;
140
141         ///
142         bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
143         ///
144         bool idxLeft(idx_type & idx, pos_type & pos) const;
145         ///
146         bool idxRight(idx_type & idx, pos_type & pos) const;
147         ///
148         bool idxFirst(idx_type & idx, pos_type & pos) const;
149         ///
150         bool idxLast(idx_type & idx, pos_type & pos) const;
151         ///
152         bool idxHome(idx_type & idx, pos_type & pos) const;
153         ///
154         bool idxEnd(idx_type & idx, pos_type & pos) const;
155         ///
156         bool idxDelete(idx_type & idx);
157         /// pulls cell after pressing erase
158         void idxGlue(idx_type idx);
159
160         ///
161         virtual void addRow(row_type r);
162         ///
163         virtual void delRow(row_type r);
164         ///
165         virtual void addFancyRow(row_type r) { addRow(r); }
166         ///
167         virtual void delFancyRow(row_type r) { delRow(r); }
168         ///
169         virtual void addCol(col_type c);
170         ///
171         virtual void delCol(col_type c);
172         ///
173         virtual void addFancyCol(col_type c) { addCol(c); }
174         ///
175         virtual void delFancyCol(col_type c) { delCol(c); }
176         ///
177         virtual void appendRow();
178         ///
179         idx_type index(row_type r, col_type c) const;
180         ///
181         bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
182         ///
183         virtual int defaultColSpace(col_type) { return 0; }
184         ///
185         virtual char defaultColAlign(col_type) { return 'c'; }
186         ///
187         void setDefaults();
188
189         ///
190         virtual int colsep() const;
191         ///
192         virtual int rowsep() const;
193         ///
194         virtual int hlinesep() const;
195         ///
196         virtual int vlinesep() const;
197         ///
198         virtual int border() const;
199
200         ///
201         void write(WriteStream & os) const;
202         ///
203         void normalize(NormalStream &) const;
204         ///
205         //void maplize(MapleStream &) const;
206         ///
207         void mathmlize(MathMLStream &) const;
208         ///
209         //void octavize(OctaveStream &) const;
210
211 protected:
212         /// returns x offset of cell compared to inset
213         int cellXOffset(idx_type idx) const;
214         /// returns y offset of cell compared to inset
215         int cellYOffset(idx_type idx) const;
216         /// returns proper 'end of line' code for LaTeX
217         string eolString(row_type row, bool fragile = false) const;
218         /// returns proper 'end of column' code for LaTeX
219         string eocString(col_type col) const;
220         /// extract number of columns from alignment string
221         col_type guessColumns(string const & halign) const;
222
223 public:
224         /// row info
225         std::vector<RowInfo> rowinfo_;
226         /// column info
227         std::vector<ColInfo> colinfo_;
228         /// cell info
229         std::vector<CellInfo> cellinfo_;
230         ///
231         char v_align_; // add approp. type
232 };
233
234 #endif