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