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