]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
merge MathArray and MathXArray classes.
[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         virtual MathGridInset * asGridInset() { return this; }
129
130         ///
131         col_type ncols() const;
132         ///
133         row_type nrows() const;
134         ///
135         col_type col(idx_type idx) const;
136         ///
137         row_type row(idx_type idx) const;
138
139         ///
140         bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
141         ///
142         bool idxLeft(idx_type & idx, pos_type & pos) const;
143         ///
144         bool idxRight(idx_type & idx, pos_type & pos) const;
145         ///
146         bool idxFirst(idx_type & idx, pos_type & pos) const;
147         ///
148         bool idxLast(idx_type & idx, pos_type & pos) const;
149         ///
150         bool idxHome(idx_type & idx, pos_type & pos) const;
151         ///
152         bool idxEnd(idx_type & idx, pos_type & pos) const;
153         ///
154         bool idxDelete(idx_type & idx);
155         /// pulls cell after pressing erase
156         void idxGlue(idx_type idx);
157
158         ///
159         virtual void addRow(row_type r);
160         ///
161         virtual void delRow(row_type r);
162         ///
163         virtual void addFancyRow(row_type r) { addRow(r); }
164         ///
165         virtual void delFancyRow(row_type r) { addRow(r); }
166         ///
167         virtual void addCol(col_type c);
168         ///
169         virtual void delCol(col_type c);
170         ///
171         virtual void addFancyCol(col_type c) { addCol(c); }
172         ///
173         virtual void delFancyCol(col_type c) { addCol(c); }
174         ///
175         virtual void appendRow();
176         ///
177         idx_type index(row_type r, col_type c) const;
178         ///
179         bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
180         ///
181         virtual int defaultColSpace(col_type) { return 0; }
182         ///
183         virtual char defaultColAlign(col_type) { return 'c'; }
184         ///
185         void setDefaults();
186
187         ///
188         virtual int colsep() const;
189         ///
190         virtual int rowsep() const;
191         ///
192         virtual int hlinesep() const;
193         ///
194         virtual int vlinesep() const;
195         ///
196         virtual int border() const;
197
198         ///
199         void write(WriteStream & os) const;
200         ///
201         void normalize(NormalStream &) const;
202         ///
203         //void maplize(MapleStream &) const;
204         ///
205         void mathmlize(MathMLStream &) const;
206         ///
207         //void octavize(OctaveStream &) const;
208
209 protected:
210         /// returns x offset of cell compared to inset
211         int cellXOffset(idx_type idx) const;
212         /// returns y offset of cell compared to inset
213         int cellYOffset(idx_type idx) const;
214         /// returns proper 'end of line' code for LaTeX
215         string eolString(row_type row, bool fragile = false) const;
216         /// returns proper 'end of column' code for LaTeX
217         string eocString(col_type col) const;
218         /// extract number of columns from alignment string
219         col_type guessColumns(string const & halign) const;
220
221 public:
222         /// row info
223         std::vector<RowInfo> rowinfo_;
224         /// column info
225         std::vector<ColInfo> colinfo_;
226         /// cell info
227         std::vector<CellInfo> cellinfo_;
228         ///
229         char v_align_; // add approp. type
230 };
231
232 #endif