]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
enable insertion of spaces in all \textxxx modes.
[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 & st) const;
86         ///
87         void draw(MathPainterInfo &, int x, int y) const;
88         ///
89         void metricsT(TextMetricsInfo const & st) const;
90         ///
91         void drawT(TextPainter &, int x, int y) const;
92         ///
93         void halign(string const &);
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         int cellXOffset(idx_type idx) const;
131         ///
132         int cellYOffset(idx_type idx) const;
133
134         ///
135         bool idxUpDown(idx_type &, bool) const;
136         ///
137         bool idxLeft(idx_type &, pos_type &) const;
138         ///
139         bool idxRight(idx_type &, pos_type &) const;
140         ///
141         bool idxFirst(idx_type &, pos_type &) const;
142         ///
143         bool idxLast(idx_type &, pos_type &) const;
144         ///
145         bool idxHome(idx_type &, pos_type &) const;
146         ///
147         bool idxEnd(idx_type &, pos_type &) const;
148         ///
149         bool idxDelete(idx_type &);
150         /// pulls cell after pressing erase
151         void idxGlue(idx_type idx);
152
153         ///
154         virtual void addRow(row_type);
155         ///
156         virtual void delRow(row_type);
157         ///
158         virtual void addFancyRow(row_type r) { addRow(r); }
159         ///
160         virtual void delFancyRow(row_type r) { addRow(r); }
161         ///
162         virtual void addCol(col_type);
163         ///
164         virtual void delCol(col_type);
165         ///
166         virtual void addFancyCol(col_type c) { addCol(c); }
167         ///
168         virtual void delFancyCol(col_type c) { addCol(c); }
169         ///
170         virtual void appendRow();
171         ///
172         idx_type index(row_type row, col_type col) const;
173         ///
174         std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
175         ///
176         virtual int defaultColSpace(col_type) { return 0; }
177         ///
178         virtual char defaultColAlign(col_type) { return 'c'; }
179         ///
180         void setDefaults();
181
182         ///
183         virtual int colsep() const;
184         ///
185         virtual int rowsep() const;
186         ///
187         virtual int hlinesep() const;
188         ///
189         virtual int vlinesep() const;
190         ///
191         virtual int border() const;
192
193         ///
194         void write(WriteStream & os) const;
195         ///
196         void normalize(NormalStream &) const;
197         ///
198         //void maplize(MapleStream &) const;
199         ///
200         void mathmlize(MathMLStream &) const;
201         ///
202         //void octavize(OctaveStream &) const;
203
204 protected:
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