]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
commit forgotten files.
[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         /// Ensures that the dialog is closed.
91         ~MathGridInset();
92         ///
93         MathInset * clone() const;
94         ///
95         void metrics(MathMetricsInfo & mi) const;
96         ///
97         void draw(MathPainterInfo & pi, int x, int y) const;
98         ///
99         void metricsT(TextMetricsInfo const & mi) const;
100         ///
101         void drawT(TextPainter & pi, int x, int y) const;
102         ///
103         void halign(string const & align);
104         ///
105         void halign(char c, col_type col);
106         ///
107         char halign(col_type col) const;
108         ///
109         string halign() const;
110         ///
111         void valign(char c);
112         ///
113         char valign() const;
114         ///
115         void vcrskip(LyXLength const &, row_type row);
116         ///
117         LyXLength vcrskip(row_type row) const;
118         ///
119         void resize(short int type, col_type cols);
120         ///
121         const RowInfo & rowinfo(row_type row) const;
122         /// returns topmost row if passed (-1)
123         RowInfo & rowinfo(row_type row);
124         ///
125         const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
126         ///
127         CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
128         /// identifies GridInset
129         MathGridInset * asGridInset() { return this; }
130         /// identifies GridInset
131         MathGridInset const * asGridInset() const { return this; }
132         /// local dispatcher
133         dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
134
135         ///
136         col_type ncols() const;
137         ///
138         row_type nrows() const;
139         ///
140         col_type col(idx_type idx) const;
141         ///
142         row_type row(idx_type idx) const;
143
144         ///
145         bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
146         ///
147         bool idxLeft(idx_type & idx, pos_type & pos) const;
148         ///
149         bool idxRight(idx_type & idx, pos_type & pos) const;
150         ///
151         bool idxFirst(idx_type & idx, pos_type & pos) const;
152         ///
153         bool idxLast(idx_type & idx, pos_type & pos) const;
154         ///
155         bool idxHome(idx_type & idx, pos_type & pos) const;
156         ///
157         bool idxEnd(idx_type & idx, pos_type & pos) const;
158         ///
159         bool idxDelete(idx_type & idx);
160         /// pulls cell after pressing erase
161         void idxGlue(idx_type idx);
162
163         ///
164         virtual void addRow(row_type r);
165         ///
166         virtual void delRow(row_type r);
167         ///
168         virtual void copyRow(row_type r);
169         ///
170         virtual void swapRow(row_type r);
171         ///
172         virtual void addCol(col_type c);
173         ///
174         virtual void delCol(col_type c);
175         ///
176         virtual void copyCol(col_type c);
177         ///
178         virtual void swapCol(col_type c);
179         ///
180         virtual void appendRow();
181         ///
182         idx_type index(row_type r, col_type c) const;
183         ///
184         bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
185         ///
186         virtual int defaultColSpace(col_type) { return 0; }
187         ///
188         virtual char defaultColAlign(col_type) { return 'c'; }
189         ///
190         void setDefaults();
191
192         ///
193         virtual int colsep() const;
194         ///
195         virtual int rowsep() const;
196         ///
197         virtual int hlinesep() const;
198         ///
199         virtual int vlinesep() const;
200         ///
201         virtual int border() const;
202
203         ///
204         void write(WriteStream & os) const;
205         ///
206         void normalize(NormalStream &) const;
207         ///
208         //void maple(MapleStream &) const;
209         ///
210         void mathmlize(MathMLStream &) const;
211         ///
212         //void octave(OctaveStream &) const;
213
214 protected:
215         /// returns x offset of cell compared to inset
216         int cellXOffset(idx_type idx) const;
217         /// returns y offset of cell compared to inset
218         int cellYOffset(idx_type idx) const;
219         /// returns proper 'end of line' code for LaTeX
220         virtual string eolString(row_type row, bool fragile = false) const;
221         /// returns proper 'end of column' code for LaTeX
222         virtual string eocString(col_type col, col_type lastcol) const;
223         /// extract number of columns from alignment string
224         col_type guessColumns(string const & halign) const;
225         /// splits cells and shifts right part to the next cell
226         void splitCell(idx_type &, pos_type & pos);
227
228 public:
229         /// row info
230         std::vector<RowInfo> rowinfo_;
231         /// column info
232         std::vector<ColInfo> colinfo_;
233         /// cell info
234         std::vector<CellInfo> cellinfo_;
235         ///
236         char v_align_; // add approp. type
237 };
238
239 #endif