]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
some support for the [x][x]alignat environments
[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         ///
63         MathGridInset(int m, int n);
64         ///
65         void write(std::ostream &, bool fragile) const;
66         ///
67         void metrics(MathStyles st) const;
68         ///
69         void draw(Painter &, int x, int y) const;
70         ///
71         void halign(string const &);
72         ///
73         void halign(char c, int col);
74         ///
75         char halign(int col) const;
76         ///
77         void valign(char c);
78         ///
79         char valign() const;
80         ///
81         void vskip(LyXLength const &, int row);
82         ///
83         LyXLength vskip(int row) const;
84         ///
85         void resize(short int type, int cols);
86         ///
87         const RowInfo & rowinfo(int row) const;
88         ///
89         RowInfo & rowinfo(int row);
90         ///
91         bool isGrid() const { return true; }
92
93         ///
94         int ncols() const { return colinfo_.size(); }
95         ///
96         int nrows() const { return rowinfo_.size(); }
97         ///
98         int col(int idx) const { return idx % ncols(); }
99         ///
100         int row(int idx) const { return idx / ncols(); }
101         ///
102         int cellXOffset(int idx) const;
103         ///
104         int cellYOffset(int idx) const;
105
106         ///
107         bool idxUp(int &, int &) const;
108         ///
109         bool idxDown(int &, int &) const;
110         ///
111         bool idxLeft(int &, int &) const;
112         ///
113         bool idxRight(int &, int &) const;
114         ///
115         bool idxFirst(int &, int &) const;
116         ///
117         bool idxLast(int &, int &) const;
118         ///
119         void idxDelete(int &, bool &, bool &);
120         ///
121         void idxDeleteRange(int, int);
122                         
123         ///
124         void addRow(int);
125         ///
126         void delRow(int);
127         ///
128         void addCol(int);
129         ///
130         void delCol(int);
131         ///
132         virtual void appendRow();
133         ///
134         int index(int row, int col) const;
135         ///
136         std::vector<int> idxBetween(int from, int to) const;
137         ///
138         virtual int defaultColSpace(int) { return 10; }
139         ///
140         virtual char defaultColAlign(int) { return 'c'; }
141
142 protected:
143         /// returns proper 'end of line' code for LaTeX
144         string eolString(int row) const;
145         /// returns proper 'end of column' code for LaTeX
146         string eocString(int col) const;
147
148         /// row info
149         std::vector<RowInfo> rowinfo_;
150         /// column info
151         std::vector<ColInfo> colinfo_;
152         /// 
153         char v_align_; // add approp. type
154 };
155
156 #endif