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