]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
c0b64f03e7c8154031470f468b2d375c098b078d
[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                 /// hline abow this row?
34                 bool upperline_;
35                 /// hline below this row?
36                 bool lowerline_;
37                 /// distance
38                 LyXLength 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                 /// additional amount to be skipped when drawing
58                 int skip_;
59         };
60
61 public: 
62         /// Note: columns first!
63         MathGridInset(col_type m, row_type n);
64         ///
65         MathGridInset(int m, int n, char valign, string const & halign);
66         ///
67         void write(MathWriteInfo & os) const;
68         ///
69         void writeNormal(std::ostream &) const;
70         ///
71         void metrics(MathMetricsInfo const & st) const;
72         ///
73         void draw(Painter &, int x, int y) const;
74         ///
75         void halign(string const &);
76         ///
77         void halign(char c, col_type col);
78         ///
79         char halign(col_type col) const;
80         ///
81         void valign(char c);
82         ///
83         char valign() const;
84         ///
85         void vskip(LyXLength const &, row_type row);
86         ///
87         LyXLength vskip(row_type row) const;
88         ///
89         void resize(short int type, col_type cols);
90         ///
91         const RowInfo & rowinfo(row_type row) const;
92         ///
93         RowInfo & rowinfo(row_type row);
94         /// identifies GridInset
95         virtual MathGridInset * asGridInset() { return this; }
96
97         ///
98         col_type ncols() const { return colinfo_.size(); }
99         ///
100         row_type nrows() const { return rowinfo_.size(); }
101         ///
102         col_type col(idx_type idx) const { return idx % ncols(); }
103         ///
104         row_type row(idx_type idx) const { return idx / ncols(); }
105         ///
106         int cellXOffset(idx_type idx) const;
107         ///
108         int cellYOffset(idx_type idx) const;
109
110         ///
111         bool idxUp(idx_type &, pos_type &) const;
112         ///
113         bool idxDown(idx_type &, pos_type &) const;
114         ///
115         bool idxLeft(idx_type &, pos_type &) const;
116         ///
117         bool idxRight(idx_type &, pos_type &) const;
118         ///
119         bool idxFirst(idx_type &, pos_type &) const;
120         ///
121         bool idxLast(idx_type &, pos_type &) const;
122         ///
123         void idxDelete(idx_type &, bool &, bool &);
124         ///
125         void idxDeleteRange(idx_type, idx_type);
126                         
127         ///
128         void addRow(row_type);
129         ///
130         void delRow(row_type);
131         ///
132         void addCol(col_type);
133         ///
134         void delCol(col_type);
135         ///
136         virtual void appendRow();
137         ///
138         idx_type index(row_type row, col_type col) const;
139         ///
140         std::vector<idx_type> idxBetween(idx_type from, idx_type to) const;
141         ///
142         virtual int defaultColSpace(col_type) { return 10; }
143         ///
144         virtual char defaultColAlign(col_type) { return 'c'; }
145         ///
146         void setDefaults();
147
148 protected:
149         /// returns proper 'end of line' code for LaTeX
150         string eolString(row_type row) const;
151         /// returns proper 'end of column' code for LaTeX
152         string eocString(col_type col) const;
153
154         /// row info
155         std::vector<RowInfo> rowinfo_;
156         /// column info
157         std::vector<ColInfo> colinfo_;
158         /// 
159         char v_align_; // add approp. type
160 };
161
162 #endif