]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
enable direct input of #1...#9; some whitespace changes
[lyx.git] / src / mathed / math_gridinset.h
1 // -*- C++ -*-
2 #ifndef MATH_GRID_H
3 #define MATH_GRID_H
4
5 #include "math_nestinset.h"
6 #include "vspace.h"
7 #include "LString.h"
8
9 #ifdef __GNUG__
10 #pragma interface
11 #endif
12
13 /** Gridded math inset base class.
14     This is the base to all grid-like editable math objects
15     like array and eqnarray.
16     \author André Pönitz 2001
17 */
18
19 class MathGridInset : public MathNestInset {
20
21         /// additional per-row information
22         struct RowInfo {
23                 ///
24                 RowInfo();
25                 ///
26                 int skipPixels() const;
27                 /// cached descent
28                 mutable int descent_;
29                 /// cached ascent
30                 mutable int ascent_;
31                 /// cached offset
32                 mutable int offset_;
33                 /// how many hlines above this row?
34                 int lines_;
35                 /// parameter to the line break
36                 LyXLength crskip_;
37                 /// extra distance between lines
38                 int skip_;
39         };
40
41         // additional per-row information
42         struct ColInfo {
43                 ///     
44                 ColInfo();
45                 /// currently possible: 'l', 'c', 'r'
46                 char align_;
47                 /// cache for drawing
48                 int h_offset;
49                 /// cached width
50                 mutable int width_;
51                 /// cached offset
52                 mutable int offset_;
53                 /// do we need a line to the left? 
54                 bool leftline_;
55                 /// do we need a line to the right?
56                 bool rightline_;
57                 /// how many lines to the left of this column?
58                 int lines_;
59                 /// additional amount to be skipped when drawing
60                 int skip_;
61         };
62
63 public: 
64         /// constructor from columns description, creates one row
65         MathGridInset(char valign, string const & halign);
66         /// Note: columns first!
67         MathGridInset(col_type m, row_type n);
68         ///
69         MathGridInset(col_type m, row_type n, char valign, string const & halign);
70         ///
71         MathInset * clone() const;
72         ///
73         void metrics(MathMetricsInfo const & st) const;
74         ///
75         void draw(Painter &, int x, int y) const;
76         ///
77         void halign(string const &);
78         ///
79         void halign(char c, col_type col);
80         ///
81         char halign(col_type col) const;
82         ///
83         string halign() const;
84         ///
85         void valign(char c);
86         ///
87         char valign() const;
88         ///
89         void vcrskip(LyXLength const &, row_type row);
90         ///
91         LyXLength vcrskip(row_type row) const;
92         ///
93         void resize(short int type, col_type cols);
94         ///
95         const RowInfo & rowinfo(row_type row) const;
96         /// returns topmost row if passed (-1)
97         RowInfo & rowinfo(row_type row);
98         /// identifies GridInset
99         virtual MathGridInset * asGridInset() { return this; }
100
101         ///
102         col_type ncols() const;
103         ///
104         row_type nrows() const;
105         ///
106         col_type col(idx_type idx) const;
107         ///
108         row_type row(idx_type idx) const;
109         ///
110         int cellXOffset(idx_type idx) const;
111         ///
112         int cellYOffset(idx_type idx) const;
113
114         ///
115         bool idxUp(idx_type &) const;
116         ///
117         bool idxDown(idx_type &) const;
118         ///
119         bool idxLeft(idx_type &, pos_type &) const;
120         ///
121         bool idxRight(idx_type &, pos_type &) const;
122         ///
123         bool idxFirst(idx_type &, pos_type &) const;
124         ///
125         bool idxLast(idx_type &, pos_type &) const;
126         ///
127         bool idxHome(idx_type &, pos_type &) const;
128         ///
129         bool idxEnd(idx_type &, pos_type &) const;
130         ///
131         void idxDelete(idx_type &, bool &, bool &);
132         ///
133         void idxDeleteRange(idx_type, idx_type);
134                         
135         ///
136         virtual void addRow(row_type);
137         ///
138         virtual void delRow(row_type);
139         ///
140         virtual void addCol(col_type);
141         ///
142         virtual void delCol(col_type);
143         ///
144         virtual void appendRow();
145         ///
146         idx_type index(row_type row, col_type col) const;
147         ///
148         std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
149         ///
150         virtual int defaultColSpace(col_type) { return 0; }
151         ///
152         virtual char defaultColAlign(col_type) { return 'c'; }
153         ///
154         void setDefaults();
155
156         ///
157         void write(WriteStream & os) const;
158         ///
159         void normalize(NormalStream &) const;
160         ///
161         //void maplize(MapleStream &) const;
162         ///
163         void mathmlize(MathMLStream &) const;
164         ///
165         //void octavize(OctaveStream &) const;
166
167 protected:
168         /// returns proper 'end of line' code for LaTeX
169         string eolString(row_type row) const;
170         /// returns proper 'end of column' code for LaTeX
171         string eocString(col_type col) const;
172         /// extract number of columns from alignment string
173         col_type guessColumns(string const & halign) const;
174
175         /// row info
176         std::vector<RowInfo> rowinfo_;
177         /// column info
178         std::vector<ColInfo> colinfo_;
179         /// 
180         char v_align_; // add approp. type
181 };
182
183 #endif