]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
52ff62a52bb78caf092b5671ddfdeea115a2c8cc
[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 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                 std::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, std::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, std::string const & halign);
93         /// Ensures that the dialog is closed.
94         ~MathGridInset();
95         ///
96         void metrics(MetricsInfo & mi) const;
97         ///
98         void metrics(MetricsInfo & mi, Dimension &) const;
99         ///
100         void draw(PainterInfo & pi, int x, int y) const;
101         ///
102         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
103         ///
104         void drawT(TextPainter & pi, int x, int y) const;
105         ///
106         void halign(std::string const & align);
107         ///
108         void halign(char c, col_type col);
109         ///
110         char halign(col_type col) const;
111         ///
112         std::string halign() const;
113         ///
114         void valign(char c);
115         ///
116         char valign() const;
117         ///
118         void vcrskip(LyXLength const &, row_type row);
119         ///
120         LyXLength vcrskip(row_type row) const;
121         ///
122         void resize(short int type, col_type cols);
123         ///
124         const RowInfo & rowinfo(row_type row) const;
125         /// returns topmost row if passed (-1)
126         RowInfo & rowinfo(row_type row);
127         ///
128         const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
129         ///
130         CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
131         /// identifies GridInset
132         MathGridInset * asGridInset() { return this; }
133         /// identifies GridInset
134         MathGridInset const * asGridInset() const { return this; }
135         ///
136         col_type ncols() const;
137         ///
138         row_type nrows() const;
139         ///
140         col_type col(idx_type idx) const;
141         ///
142         row_type row(idx_type idx) const;
143
144         ///
145         bool idxUpDown(LCursor &, bool up) const;
146         ///
147         bool idxLeft(LCursor &) const;
148         ///
149         bool idxRight(LCursor &) const;
150         ///
151         bool idxFirst(LCursor &) const;
152         ///
153         bool idxLast(LCursor &) const;
154         ///
155         bool idxDelete(idx_type & idx);
156         /// pulls cell after pressing erase
157         void idxGlue(idx_type idx);
158
159         ///
160         virtual void addRow(row_type r);
161         ///
162         virtual void delRow(row_type r);
163         ///
164         virtual void copyRow(row_type r);
165         ///
166         virtual void swapRow(row_type r);
167         ///
168         virtual void addCol(col_type c);
169         ///
170         virtual void delCol(col_type c);
171         ///
172         virtual void copyCol(col_type c);
173         ///
174         virtual void swapCol(col_type c);
175         ///
176         virtual void appendRow();
177         ///
178         idx_type index(row_type r, col_type c) const;
179         ///
180         bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
181         ///
182         virtual int defaultColSpace(col_type) { return 0; }
183         ///
184         virtual char defaultColAlign(col_type) { return 'c'; }
185         ///
186         void setDefaults();
187
188         ///
189         virtual int colsep() const;
190         ///
191         virtual int rowsep() const;
192         ///
193         virtual int hlinesep() const;
194         ///
195         virtual int vlinesep() const;
196         ///
197         virtual int border() const;
198
199         ///
200         void write(WriteStream & os) const;
201         ///
202         void normalize(NormalStream &) const;
203         ///
204         //void maple(MapleStream &) const;
205         ///
206         void mathmlize(MathMLStream &) const;
207         ///
208         //void octave(OctaveStream &) const;
209
210 protected:
211         ///
212         void priv_dispatch(LCursor & cur, FuncRequest & cmd);
213         ///
214         bool getStatus(LCursor & cur, FuncRequest const & cmd,
215                 FuncStatus & flag) const;
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 std::string eolString(row_type row, bool fragile = false) const;
222         /// returns proper 'end of column' code for LaTeX
223         virtual std::string eocString(col_type col, col_type lastcol) const;
224         /// extract number of columns from alignment string
225         col_type guessColumns(std::string const & halign) const;
226         /// splits cells and shifts right part to the next cell
227         void splitCell(LCursor & cur);
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 private:
239         virtual std::auto_ptr<InsetBase> doClone() const;
240 };
241
242 #endif