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