]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
iterators for MathArray; 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);
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         int cellXOffset(int idx) const;
91         ///
92         int cellYOffset(int idx) const;
93
94         ///
95         bool idxUp(int &, int &) const;
96         ///
97         bool idxDown(int &, int &) const;
98         ///
99         bool idxLeft(int &, int &) const;
100         ///
101         bool idxRight(int &, int &) const;
102         ///
103         bool idxFirst(int &, int &) const;
104         ///
105         bool idxLast(int &, int &) const;
106         ///
107         void idxDelete(int &, bool &, bool &);
108         ///
109         void idxDeleteRange(int, int);
110                         
111         ///
112         void addRow(int);
113         ///
114         void delRow(int);
115         ///
116         void addCol(int);
117         ///
118         void delCol(int);
119         ///
120         virtual void appendRow();
121         ///
122         int index(int row, int col) const;
123         ///
124         std::vector<int> idxBetween(int from, int to) const;
125
126 protected:
127         /// row info
128         std::vector<RowInfo> rowinfo_;
129         /// column info
130         std::vector<ColInfo> colinfo_;
131         /// 
132         char v_align_; // add approp. type
133 };
134
135 #endif