]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
ws changes only
[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         /// local dispatcher
139         dispatch_result dispatch(FuncRequest const & cmd, idx_type & idx, pos_type & pos);
140
141         ///
142         col_type ncols() const;
143         ///
144         row_type nrows() const;
145         ///
146         col_type col(idx_type idx) const;
147         ///
148         row_type row(idx_type idx) const;
149
150         ///
151         bool idxUpDown(idx_type & idx, pos_type & pos, bool up, int targetx) const;
152         ///
153         bool idxLeft(idx_type & idx, pos_type & pos) const;
154         ///
155         bool idxRight(idx_type & idx, pos_type & pos) const;
156         ///
157         bool idxFirst(idx_type & idx, pos_type & pos) const;
158         ///
159         bool idxLast(idx_type & idx, pos_type & pos) const;
160         ///
161         bool idxHome(idx_type & idx, pos_type & pos) const;
162         ///
163         bool idxEnd(idx_type & idx, pos_type & pos) const;
164         ///
165         bool idxDelete(idx_type & idx);
166         /// pulls cell after pressing erase
167         void idxGlue(idx_type idx);
168
169         ///
170         virtual void addRow(row_type r);
171         ///
172         virtual void delRow(row_type r);
173         ///
174         virtual void copyRow(row_type r);
175         ///
176         virtual void swapRow(row_type r);
177         ///
178         virtual void addCol(col_type c);
179         ///
180         virtual void delCol(col_type c);
181         ///
182         virtual void copyCol(col_type c);
183         ///
184         virtual void swapCol(col_type c);
185         ///
186         virtual void appendRow();
187         ///
188         idx_type index(row_type r, col_type c) const;
189         ///
190         bool idxBetween(idx_type idx, idx_type from, idx_type to) const;
191         ///
192         virtual int defaultColSpace(col_type) { return 0; }
193         ///
194         virtual char defaultColAlign(col_type) { return 'c'; }
195         ///
196         void setDefaults();
197
198         ///
199         virtual int colsep() const;
200         ///
201         virtual int rowsep() const;
202         ///
203         virtual int hlinesep() const;
204         ///
205         virtual int vlinesep() const;
206         ///
207         virtual int border() const;
208
209         ///
210         void write(WriteStream & os) const;
211         ///
212         void normalize(NormalStream &) const;
213         ///
214         //void maple(MapleStream &) const;
215         ///
216         void mathmlize(MathMLStream &) const;
217         ///
218         //void octave(OctaveStream &) const;
219
220 protected:
221         /// returns x offset of cell compared to inset
222         int cellXOffset(idx_type idx) const;
223         /// returns y offset of cell compared to inset
224         int cellYOffset(idx_type idx) const;
225         /// returns proper 'end of line' code for LaTeX
226         virtual std::string eolString(row_type row, bool fragile = false) 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(idx_type &, pos_type & pos);
233
234 public:
235         /// row info
236         std::vector<RowInfo> rowinfo_;
237         /// column info
238         std::vector<ColInfo> colinfo_;
239         /// cell info
240         std::vector<CellInfo> cellinfo_;
241         ///
242         char v_align_; // add approp. type
243 };
244
245 #endif