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