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