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