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