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