]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathGrid.h
move everything into namespace lyx
[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 "lyxlength.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                 std::string 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                 LyXLength crskip_;
63                 /// extra distance between lines
64                 int skip_;
65         };
66
67         // additional per-row information
68         class ColInfo {
69         public:
70                 ///
71                 ColInfo();
72                 /// currently possible: 'l', 'c', 'r'
73                 char align_;
74                 /// cache for drawing
75                 int h_offset;
76                 /// cached width
77                 mutable int width_;
78                 /// cached offset
79                 mutable int offset_;
80                 /// how many lines to the left of this column?
81                 unsigned int lines_;
82                 /// additional amount to be skipped when drawing
83                 int skip_;
84         };
85
86 public:
87         /// sets nrows and ncols to 1
88         InsetMathGrid();
89         /// constructor from columns description, creates one row
90         InsetMathGrid(char valign, std::string const & halign);
91         /// Note: columns first!
92         InsetMathGrid(col_type m, row_type n);
93         ///
94         InsetMathGrid(col_type m, row_type n, char valign, std::string const & halign);
95         /// Ensures that the dialog is closed.
96         ~InsetMathGrid();
97         ///
98         void metrics(MetricsInfo & mi) const;
99         ///
100         void 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         ///
107         void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
108         ///
109         void drawT(TextPainter & pi, int x, int y) const;
110         ///
111         void halign(std::string const & align);
112         ///
113         void halign(char c, col_type col);
114         ///
115         char halign(col_type col) const;
116         ///
117         std::string halign() const;
118         ///
119         void valign(char c);
120         ///
121         char valign() const;
122         ///
123         void vcrskip(LyXLength const &, row_type row);
124         ///
125         LyXLength vcrskip(row_type row) const;
126         ///
127         void resize(short int type, col_type cols);
128         ///
129         const RowInfo & rowinfo(row_type row) const;
130         /// returns topmost row if passed (-1)
131         RowInfo & rowinfo(row_type row);
132         ///
133         const CellInfo & cellinfo(idx_type idx) const { return cellinfo_[idx]; }
134         ///
135         CellInfo & cellinfo(idx_type idx) { return cellinfo_[idx]; }
136         /// identifies GridInset
137         InsetMathGrid * asGridInset() { return this; }
138         /// identifies GridInset
139         InsetMathGrid const * asGridInset() const { return this; }
140         ///
141         col_type ncols() const;
142         ///
143         row_type nrows() const;
144         ///
145         col_type col(idx_type idx) const;
146         ///
147         row_type row(idx_type idx) const;
148
149         ///
150         bool idxUpDown(LCursor &, bool up) const;
151         ///
152         bool idxLeft(LCursor &) const;
153         ///
154         bool idxRight(LCursor &) const;
155         ///
156         bool idxFirst(LCursor &) const;
157         ///
158         bool idxLast(LCursor &) const;
159         ///
160         bool idxDelete(idx_type & idx);
161         /// pulls cell after pressing erase
162         void idxGlue(idx_type idx);
163
164         /// add a row
165         virtual void addRow(row_type r);
166         /// delete a row
167         virtual void delRow(row_type r);
168         /// copy a row
169         virtual void copyRow(row_type r);
170         /// swap two rows
171         virtual void swapRow(row_type r);
172         /// add a column
173         virtual void addCol(col_type c);
174         /// delete a column
175         virtual void delCol(col_type c);
176         /// copy a column
177         virtual void copyCol(col_type c);
178         /// swap two columns
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 maple(MapleStream &) const;
210         ///
211         void mathmlize(MathMLStream &) const;
212         ///
213         //void octave(OctaveStream &) const;
214
215 protected:
216         virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
217         ///
218         bool getStatus(LCursor & cur, FuncRequest const & cmd,
219                 FuncStatus & flag) const;
220         /// returns x offset of cell compared to inset
221         int cellXOffset(idx_type idx) const;
222         /// returns y offset of cell compared to inset
223         int cellYOffset(idx_type idx) const;
224         /// returns proper 'end of line' code for LaTeX
225         virtual std::string eolString(row_type row, bool emptyline,
226                                       bool fragile) const;
227         /// returns proper 'end of column' code for LaTeX
228         virtual std::string eocString(col_type col, col_type lastcol) const;
229         /// extract number of columns from alignment string
230         col_type guessColumns(std::string const & halign) const;
231         /// splits cells and shifts right part to the next cell
232         void splitCell(LCursor & cur);
233
234         /// row info.
235         /// rowinfo_[nrows()] is a dummy row used only for hlines.
236         std::vector<RowInfo> rowinfo_;
237         /// column info.
238         /// colinfo_[ncols()] is a dummy column used only for vlines.
239         std::vector<ColInfo> colinfo_;
240         /// cell info
241         std::vector<CellInfo> cellinfo_;
242         ///
243         char v_align_; // add approp. type
244 private:
245         virtual std::auto_ptr<InsetBase> doClone() const;
246 };
247
248
249
250 } // namespace lyx
251 #endif