]> git.lyx.org Git - lyx.git/blob - src/mathed/math_gridinset.h
Andre's mathinset shrink patch ; default .lyx extension when loading files
[lyx.git] / src / mathed / math_gridinset.h
1 // -*- C++ -*-
2 #ifndef MATH_GRID_H
3 #define MATH_GRID_H
4
5 #include "math_inset.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 MathInset {
18
19         /// additional per-row information
20         struct RowInfo {
21                 ///
22                 RowInfo();
23                 ///
24                 int descent_;
25                 ///
26                 int ascent_;
27                 /// 
28                 int offset_;
29                 ///
30                 bool upperline_;
31                 ///
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                 ///
44                 int width_;
45                 ///
46                 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         virtual MathInset * clone() const = 0;
58         ///
59         void write(std::ostream &, bool fragile) const;
60         ///
61         void metrics(MathStyles st);
62         ///
63         void draw(Painter &, int, int);
64         ///
65         void halign(string const &);
66         ///
67         void halign(char c, int col);
68         ///
69         char halign(int col) const;
70         ///
71         void valign(char c);
72         ///
73         char valign() const;
74         ///
75         void resize(short int type, int cols);
76         ///
77         const RowInfo & rowinfo(int row) const;
78         ///
79         RowInfo & rowinfo(int row);
80         ///
81         bool isGrid() const { return true; }
82
83         ///
84         int ncols() const { return colinfo_.size(); }
85         ///
86         int nrows() const { return rowinfo_.size(); }
87         ///
88         int col(int idx) const { return idx % ncols(); }
89         ///
90         int row(int idx) const { return idx / ncols(); }
91
92         ///
93         bool idxUp(int &, int &) const;
94         ///
95         bool idxDown(int &, int &) const;
96         ///
97         bool idxLeft(int &, int &) const;
98         ///
99         bool idxRight(int &, int &) const;
100         ///
101         bool idxFirst(int &, int &) const;
102         ///
103         bool idxLast(int &, int &) const;
104         ///
105         void idxDelete(int &, bool &, bool &);
106         ///
107         void idxDeleteRange(int, int);
108                         
109         ///
110         void addRow(int);
111         ///
112         void delRow(int);
113         ///
114         void addCol(int);
115         ///
116         void delCol(int);
117         ///
118         virtual void appendRow();
119         ///
120         int index(int row, int col) const;
121         ///
122         std::vector<int> idxBetween(int from, int to) const;
123
124 protected:
125         /// row info
126         std::vector<RowInfo> rowinfo_;
127         /// column info
128         std::vector<ColInfo> colinfo_;
129         /// 
130         char v_align_; // add approp. type
131 };
132
133 #endif