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