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