]> git.lyx.org Git - lyx.git/blob - src/Bullet.h
small changes to ButtonController usage
[lyx.git] / src / Bullet.h
1 // -*- C++ -*-
2 /* This is the bullet class definition file.
3  * This file is part of
4  * ====================================================== 
5  *
6  *           LyX, The Document Processor
7  *
8  *           Copyright 1995 Matthias Ettrich
9  *           Copyright 1995-2000 The LyX Team.
10  *
11  *           This file Copyright 1997-1999
12  *           Allan Rae
13  * ====================================================== */
14
15 #ifndef BULLET_H
16 #define BULLET_H
17
18 #ifdef __GNUG__
19 #pragma interface
20 #endif
21
22 #include "LString.h"
23
24 #include "support/LAssert.h"
25
26 ///
27 class Bullet {
28 public:
29         ///
30         Bullet(int f = -1, int c = -1, int s = -1);
31
32         ///
33         explicit Bullet(string const &);
34
35         ///
36         void setCharacter(int);
37         ///
38         void setFont(int);
39         ///
40         void setSize(int);
41         ///
42         void setText(string const &);
43         ///
44         int getCharacter() const;
45         ///
46         int getFont() const;
47         ///
48         int getSize() const;
49         ///
50         string const & getText() const;
51         ///
52         char const * c_str() const;
53         ///
54         Bullet & operator = (Bullet const &);
55         ///
56         friend bool operator==(Bullet const &, Bullet const &);
57         ///
58         friend bool operator!=(Bullet const & b1, Bullet const & b2) {
59                 return !(b1 == b2);
60         }
61 protected:
62 #ifdef ENABLE_ASSERTIONS
63         ///
64         void testInvariant() const {
65                 Assert(font >= MIN);
66                 Assert(font < FONTMAX);
67                 Assert(character >= MIN);
68                 Assert(character < CHARMAX);
69                 Assert(size >= MIN);
70                 Assert(size < SIZEMAX);
71                 Assert(user_text >= -1);
72                 Assert(user_text <= 1);
73                 // now some relational/operational tests
74                 if (user_text == 1) {
75                         Assert(font == -1 && (character == -1 && size == -1));
76                         //        Assert(!text.empty()); // this isn't necessarily an error
77                 }
78                 //      else if (user_text == -1) {
79                 //        Assert(!text.empty()); // this also isn't necessarily an error
80                 //      }
81                 //      else {
82                 //        // user_text == 0
83                 //        Assert(text.empty()); // not usually true
84                 //      }
85         }
86 #endif
87 private:
88         /**
89            This enum makes adding additional panels or changing panel sizes
90            easier. Since you only need change these values for all tests to
91            be correct for the new values.
92            
93            Note: MAX means the size of the array so to test you need:
94            (x < MAX)  *not* (x <= MAX)
95         */
96         enum {
97                 ///
98                 MIN = -1,
99                 ///
100                 FONTMAX = 6,
101                 ///
102                 CHARMAX = 36,
103                 ///
104                 SIZEMAX = 10
105         };
106         
107         ///
108         void generateText() const;
109         ///
110         static string bulletSize(short int);
111         ///
112         static string bulletEntry(short int, short int);
113         
114         ///
115         short font;
116         ///
117         short character;
118         ///
119         short size;
120         
121         // size, character and font are array indices to access 
122         // the predefined arrays of LaTeX equivalent strings.
123         
124         /** flag indicates if user has control of text (1)
125             or if I can use it to generate strings (0)
126             or have already (-1)
127         */
128         mutable short user_text; 
129         
130         //NOTE: Arranging these four shorts above to be together
131         //      like this should ensure they are in a single cache line
132         
133         /** text may contain a user-defined LaTeX symbol command
134             or one generated internally from the font, character
135             and size settings.
136         */
137         mutable string text;
138 };
139
140
141 /*----------------Inline Bullet Member Functions------------------*/
142
143 inline
144 Bullet::Bullet(string const & t) 
145         :  font(MIN), character(MIN), size(MIN), user_text(1), text(t)
146 {
147 #ifdef ENABLE_ASSERTIONS
148         testInvariant();
149 #endif
150 }
151
152
153 inline
154 void Bullet::setCharacter(int c)
155 {
156         if (c < MIN || c >= CHARMAX) {
157                 character = MIN;
158         } else {
159                 character = c;
160         }
161         user_text = 0;
162 #ifdef ENABLE_ASSERTIONS
163         testInvariant();
164 #endif
165 }
166
167
168 inline
169 void Bullet::setFont(int f)
170 {
171         if (f < MIN || f >= FONTMAX) {
172                 font = MIN;
173         } else {
174                 font = f;
175         }
176         user_text = 0;
177 #ifdef ENABLE_ASSERTIONS
178         testInvariant();
179 #endif
180 }
181
182
183 inline
184 void Bullet::setSize(int s)
185 {
186         if (s < MIN || s >= SIZEMAX) {
187                 size = MIN;
188         } else {
189                 size = s;
190         }
191         user_text = 0;
192 #ifdef ENABLE_ASSERTIONS
193         testInvariant();
194 #endif
195 }
196
197
198 inline
199 void Bullet::setText(string const & t)
200 {
201         font = character = size = MIN;
202         user_text = 1;
203         text = t;
204 #ifdef ENABLE_ASSERTIONS
205         testInvariant();
206 #endif
207 }
208
209
210 inline
211 int Bullet::getCharacter() const
212 {
213         return character;
214 }
215
216
217 inline
218 int Bullet::getFont() const
219 {
220         return font;
221 }
222
223
224 inline
225 int Bullet::getSize() const
226 {
227         return size;
228 }
229
230
231 inline
232 Bullet & Bullet::operator=(Bullet const & b)
233 {
234 #ifdef ENABLE_ASSERTIONS
235         b.testInvariant();
236 #endif
237         font = b.font;
238         character = b.character;
239         size = b.size;
240         user_text = b.user_text;
241         text = b.text;
242 #ifdef ENABLE_ASSERTIONS
243         this->testInvariant();
244 #endif
245         return *this;
246 }
247
248
249 inline
250 char const * Bullet::c_str() const
251 {
252         return getText().c_str();
253 }
254
255
256 /*-----------------End Bullet Member Functions-----------------*/
257
258 ///
259 extern
260 Bullet const ITEMIZE_DEFAULTS[];
261
262 #endif /* BULLET_H_ */