]> git.lyx.org Git - lyx.git/blob - src/mathed/math_rowst.h
5c9c59383bd79d4c071738d269f0ab68533dcbae
[lyx.git] / src / mathed / math_rowst.h
1 // -*- C++ -*-
2 #ifndef MATH_ROWST_H
3 #define MATH_ROWST_H
4
5 #include <vector>
6
7 /** The physical structure of a row and aditional information is stored here.
8     It allows to manage the extra info independently of the paragraph data.  
9     Only used for multiline paragraphs.
10  */
11
12 class MathedRowStruct
13 {
14 public:
15         ///
16         typedef std::vector<int> Widths;
17         
18         ///
19         explicit
20         MathedRowStruct(int n)
21                 : asc_(0), desc_(0), y_(0), widths_(n + 1, 0),
22                   numbered_(true)
23                 {}
24         ///
25         string const & getLabel() const;
26         ///
27         bool isNumbered() const;
28         ///
29         int  getBaseline() const;
30         ///
31         void setBaseline(int b);
32         ///
33         int ascent() const;
34         ///
35         int descent() const;
36         ///
37         void ascent(int a);
38         ///
39         void descent(int d);
40         ///
41         int  getTab(int i) const;
42         /// 
43         void setLabel(string const & l);
44         ///
45         void setNumbered(bool nf);
46         ///
47         void setTab(int i, int t);
48         ///
49         friend class MathedRowSt;
50 protected:
51         /// Vericals 
52         int asc_;
53         ///
54         int desc_;
55         ///
56         int y_;
57         /// widths 
58         Widths widths_;
59         /// 
60         string label_;
61         ///
62         bool numbered_;
63 };
64
65 class MathedRowSt : public MathedRowStruct {
66 public:
67         ///
68         explicit MathedRowSt(int n)
69                         : MathedRowStruct(n), next_(0)
70                 {}
71         /// Should be const but...
72         MathedRowSt * getNext() const;
73         /// ...we couldn't use this.
74         void setNext(MathedRowSt * n);
75 //private:
76         ///
77         MathedRowSt * next_;
78 };
79
80
81 // The idea is to change this  MathedRowContainer  to mimic the behaviour
82 // of std::list<MathedRowStruct> in several small steps.  In the end it
83 // could be replaced by such a list and MathedRowSt can go as well. 
84  
85 struct MathedRowContainer {
86         ///
87         struct iterator {
88                 ///
89                 iterator(MathedRowContainer * m) : st_(m->data_) {}
90                 /// "better" conversion to bool
91                 operator void *() const { return st_; }
92                 ///
93                 MathedRowStruct & operator*() { return *st_; }
94                 ///
95                 MathedRowStruct * operator->() { return st_; }
96                 ///
97                 void operator++() { st_ = st_->next_; }
98                 ///
99                 bool is_last() const { return st_->next_ == 0; }
100                 ///
101                 bool operator==(const iterator & it) const { return st_ == it.st_; }
102
103         private:
104                 ///
105                 MathedRowSt * st_;
106         };
107
108         ///
109         MathedRowContainer() : data_(0) {}
110         ///
111         MathedRowContainer(MathedRowSt * data) : data_(data) {}
112
113         ///
114         iterator begin() { return iterator(this); }
115         ///
116         bool empty() const { return data_ == 0; }
117
118         ///
119         MathedRowSt * data_;
120 };
121
122
123
124 inline
125 MathedRowSt * MathedRowSt::getNext() const
126 {
127         return next_;
128 }
129
130
131 inline
132 void MathedRowSt::setNext(MathedRowSt * n)
133 {
134         next_ = n;
135 }
136
137
138 inline
139 string const & MathedRowStruct::getLabel() const
140 {
141         return label_;
142 }
143
144
145 inline
146 bool MathedRowStruct::isNumbered() const
147 {
148         return numbered_;
149 }
150
151
152 inline
153 int MathedRowStruct::getBaseline() const
154 {
155         return y_;
156 }
157
158
159 inline
160 void MathedRowStruct::setBaseline(int b)
161 {
162         y_ = b;
163 }
164
165
166 inline
167 int MathedRowStruct::ascent() const
168 {
169         return asc_;
170 }
171
172
173 inline
174 int MathedRowStruct::descent() const
175 {
176         return desc_;
177 }
178
179
180 inline
181 void MathedRowStruct::ascent(int a)
182 {
183         asc_ = a;
184 }
185
186
187 inline
188 void MathedRowStruct::descent(int d)
189 {
190         desc_ = d;
191 }
192
193
194 inline
195 int MathedRowStruct::getTab(int i) const
196 {
197         return widths_[i];
198 }
199
200
201 inline
202 void MathedRowStruct::setLabel(string const & l)
203 {
204         label_ = l;
205 }
206
207
208 inline
209 void MathedRowStruct::setNumbered(bool nf)
210 {
211         numbered_ = nf;
212 }
213
214
215 inline
216 void MathedRowStruct::setTab(int i, int t)
217 {
218         widths_[i] = t;
219 }
220 #endif