]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
cosmetics
[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
7 #ifdef __GNUG__
8 #pragma interface
9 #endif
10
11 /** Gridded math inset base class.
12     This is the base to all grid-like editable math objects
13     like array and eqnarray.
14     \author André Pönitz 2001
15 */
16
17 class MathGridInset : public MathNestInset {
18
19         /// additional per-row information
20         struct RowInfo {
21                 ///
22                 RowInfo();
23                 /// cached descent
24                 mutable int descent_;
25                 /// cached ascent
26                 mutable int ascent_;
27                 /// cached offset
28                 mutable int offset_;
29                 /// hline abow this row?
30                 bool upperline_;
31                 /// hline below this row?
32                 bool lowerline_;
33         };
34
35         // additional per-row information
36         struct ColInfo {
37                 ///     
38                 ColInfo();
39                 ///
40                 char h_align_;
41                 /// cache for drawing
42                 int h_offset;
43                 /// cached width
44                 mutable int width_;
45                 /// cached offset
46                 mutable int offset_;
47                 /// 
48                 bool leftline_;
49                 ///
50                 bool rightline_;
51         };
52
53 public: 
54         ///
55         MathGridInset(int m, int n, string const & nm);
56         ///
57         void write(std::ostream &, bool fragile) const;
58         ///
59         void metrics(MathStyles st) const;
60         ///
61         void draw(Painter &, int x, int y) const;
62         ///
63         void halign(string const &);
64         ///
65         void halign(char c, int col);
66         ///
67         char halign(int col) const;
68         ///
69         void valign(char c);
70         ///
71         char valign() const;
72         ///
73         void resize(short int type, int cols);
74         ///
75         const RowInfo & rowinfo(int row) const;
76         ///
77         RowInfo & rowinfo(int row);
78         ///
79         bool isGrid() const { return true; }
80
81         ///
82         int ncols() const { return colinfo_.size(); }
83         ///
84         int nrows() const { return rowinfo_.size(); }
85         ///
86         int col(int idx) const { return idx % ncols(); }
87         ///
88         int row(int idx) const { return idx / ncols(); }
89
90         ///
91         bool idxUp(int &, int &) const;
92         ///
93         bool idxDown(int &, int &) const;
94         ///
95         bool idxLeft(int &, int &) const;
96         ///
97         bool idxRight(int &, int &) const;
98         ///
99         bool idxFirst(int &, int &) const;
100         ///
101         bool idxLast(int &, int &) const;
102         ///
103         void idxDelete(int &, bool &, bool &);
104         ///
105         void idxDeleteRange(int, int);
106                         
107         ///
108         void addRow(int);
109         ///
110         void delRow(int);
111         ///
112         void addCol(int);
113         ///
114         void delCol(int);
115         ///
116         virtual void appendRow();
117         ///
118         int index(int row, int col) const;
119         ///
120         std::vector<int> idxBetween(int from, int to) const;
121
122 protected:
123         /// row info
124         std::vector<RowInfo> rowinfo_;
125         /// column info
126         std::vector<ColInfo> colinfo_;
127         /// 
128         char v_align_; // add approp. type
129 };
130
131 #endif