diff options
-rw-r--r-- | src/Basemenu.cc | 30 | ||||
-rw-r--r-- | src/Basemenu.hh | 89 |
2 files changed, 48 insertions, 71 deletions
diff --git a/src/Basemenu.cc b/src/Basemenu.cc index 4beca57..4abc055 100644 --- a/src/Basemenu.cc +++ b/src/Basemenu.cc | |||
@@ -22,7 +22,7 @@ | |||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
24 | 24 | ||
25 | // $Id: Basemenu.cc,v 1.8 2002/02/04 22:33:09 fluxgen Exp $ | 25 | // $Id: Basemenu.cc,v 1.9 2002/02/08 13:20:23 fluxgen Exp $ |
26 | 26 | ||
27 | // stupid macros needed to access some functions in version 2 of the GNU C | 27 | // stupid macros needed to access some functions in version 2 of the GNU C |
28 | // library | 28 | // library |
@@ -196,12 +196,7 @@ Basemenu::~Basemenu(void) { | |||
196 | } | 196 | } |
197 | 197 | ||
198 | 198 | ||
199 | int Basemenu::insert(const char *l, int function, const char *e, int pos) { | 199 | int Basemenu::insert(const char *label, int function, const char *exec, int pos) { |
200 | char *label = 0, *exec = 0; | ||
201 | |||
202 | if (l) label = StringUtil::strdup(l); | ||
203 | if (e) exec = StringUtil::strdup(e); | ||
204 | |||
205 | BasemenuItem *item = new BasemenuItem(label, function, exec); | 200 | BasemenuItem *item = new BasemenuItem(label, function, exec); |
206 | if (pos == -1) { | 201 | if (pos == -1) { |
207 | menuitems.push_back(item); | 202 | menuitems.push_back(item); |
@@ -213,11 +208,7 @@ int Basemenu::insert(const char *l, int function, const char *e, int pos) { | |||
213 | } | 208 | } |
214 | 209 | ||
215 | 210 | ||
216 | int Basemenu::insert(const char *l, Basemenu *submenu, int pos) { | 211 | int Basemenu::insert(const char *label, Basemenu *submenu, int pos) { |
217 | char *label = 0; | ||
218 | |||
219 | if (l) label = StringUtil::strdup(l); | ||
220 | |||
221 | BasemenuItem *item = new BasemenuItem(label, submenu); | 212 | BasemenuItem *item = new BasemenuItem(label, submenu); |
222 | if (pos == -1) { | 213 | if (pos == -1) { |
223 | menuitems.push_back(item); | 214 | menuitems.push_back(item); |
@@ -232,7 +223,8 @@ int Basemenu::insert(const char *l, Basemenu *submenu, int pos) { | |||
232 | 223 | ||
233 | 224 | ||
234 | int Basemenu::insert(const char **ulabel, int pos, int function) { | 225 | int Basemenu::insert(const char **ulabel, int pos, int function) { |
235 | BasemenuItem *item = new BasemenuItem(ulabel, function); | 226 | assert(ulabel); |
227 | BasemenuItem *item = new BasemenuItem(*ulabel, function); | ||
236 | if (pos == -1) { | 228 | if (pos == -1) { |
237 | menuitems.push_back(item); | 229 | menuitems.push_back(item); |
238 | } else { | 230 | } else { |
@@ -259,13 +251,8 @@ int Basemenu::remove(int index) { | |||
259 | tmp->internal_hide(); | 251 | tmp->internal_hide(); |
260 | } | 252 | } |
261 | 253 | ||
262 | if (item->label()) | ||
263 | delete [] item->label(); | ||
264 | |||
265 | if (item->exec()) | ||
266 | delete [] item->exec(); | ||
267 | |||
268 | delete item; | 254 | delete item; |
255 | menuitems.erase(it); | ||
269 | } | 256 | } |
270 | 257 | ||
271 | if (which_sub == index) | 258 | if (which_sub == index) |
@@ -323,8 +310,7 @@ void Basemenu::update(void) { | |||
323 | for (; it != it_end; ++it) { | 310 | for (; it != it_end; ++it) { |
324 | BasemenuItem *itmp = (*it); | 311 | BasemenuItem *itmp = (*it); |
325 | 312 | ||
326 | const char *s = ((itmp->u && *itmp->u) ? *itmp->u : | 313 | const char *s = itmp->label(); |
327 | ((itmp->l) ? itmp->l : (const char *) 0)); | ||
328 | int l = strlen(s); | 314 | int l = strlen(s); |
329 | 315 | ||
330 | if (i18n->multibyte()) { | 316 | if (i18n->multibyte()) { |
@@ -635,7 +621,7 @@ void Basemenu::drawItem(int index, Bool highlight, Bool clear, | |||
635 | if (! item) return; | 621 | if (! item) return; |
636 | 622 | ||
637 | Bool dotext = True, dohilite = True, dosel = True; | 623 | Bool dotext = True, dohilite = True, dosel = True; |
638 | const char *text = (item->ulabel()) ? *item->ulabel() : item->label(); | 624 | const char *text = item->label(); |
639 | int sbl = index / menu.persub, i = index - (sbl * menu.persub); | 625 | int sbl = index / menu.persub, i = index - (sbl * menu.persub); |
640 | int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h); | 626 | int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h); |
641 | int hilite_x = item_x, hilite_y = item_y, hoff_x = 0, hoff_y = 0; | 627 | int hilite_x = item_x, hilite_y = item_y, hoff_x = 0, hoff_y = 0; |
diff --git a/src/Basemenu.hh b/src/Basemenu.hh index af40983..126f06e 100644 --- a/src/Basemenu.hh +++ b/src/Basemenu.hh | |||
@@ -22,12 +22,14 @@ | |||
22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | 22 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
23 | // DEALINGS IN THE SOFTWARE. | 23 | // DEALINGS IN THE SOFTWARE. |
24 | 24 | ||
25 | // $Id: Basemenu.hh,v 1.5 2002/02/04 22:33:09 fluxgen Exp $ | 25 | // $Id: Basemenu.hh,v 1.6 2002/02/08 13:20:23 fluxgen Exp $ |
26 | 26 | ||
27 | #ifndef _BASEMENU_HH_ | 27 | #ifndef _BASEMENU_HH_ |
28 | #define _BASEMENU_HH_ | 28 | #define _BASEMENU_HH_ |
29 | 29 | ||
30 | #include <X11/Xlib.h> | 30 | #include <X11/Xlib.h> |
31 | #include <vector> | ||
32 | #include <string> | ||
31 | 33 | ||
32 | // forward declarations | 34 | // forward declarations |
33 | class Basemenu; | 35 | class Basemenu; |
@@ -37,8 +39,6 @@ class Fluxbox; | |||
37 | class BImageControl; | 39 | class BImageControl; |
38 | class BScreen; | 40 | class BScreen; |
39 | 41 | ||
40 | #include <vector> | ||
41 | |||
42 | class Basemenu { | 42 | class Basemenu { |
43 | private: | 43 | private: |
44 | typedef std::vector<BasemenuItem *> Menuitems; | 44 | typedef std::vector<BasemenuItem *> Menuitems; |
@@ -139,55 +139,46 @@ public: | |||
139 | 139 | ||
140 | }; | 140 | }; |
141 | 141 | ||
142 | |||
143 | class BasemenuItem { | 142 | class BasemenuItem { |
144 | private: | 143 | public: |
145 | Basemenu *s; | 144 | BasemenuItem( |
146 | const char **u, *l, *e; | 145 | const char *label, |
147 | int f, enabled, selected; | 146 | int function, |
147 | const char *exec = (const char *) 0) | ||
148 | : m_label(label ? label : "") | ||
149 | , m_exec(exec ? exec : "") | ||
150 | , m_submenu(0) | ||
151 | , m_function(function) | ||
152 | , m_enabled(true) | ||
153 | , m_selected(false) | ||
154 | { } | ||
155 | |||
156 | BasemenuItem(const char *label, Basemenu *submenu) | ||
157 | : m_label(label ? label : "") | ||
158 | , m_exec("") | ||
159 | , m_submenu(submenu) | ||
160 | , m_function(0) | ||
161 | , m_enabled(true) | ||
162 | , m_selected(false) | ||
163 | { } | ||
164 | |||
165 | inline const char *exec(void) const { return m_exec.c_str(); } | ||
166 | inline const char *label(void) const { return m_label.c_str(); } | ||
167 | inline int function(void) const { return m_function; } | ||
168 | inline Basemenu *submenu(void) { return m_submenu; } | ||
169 | |||
170 | inline bool isEnabled(void) const { return m_enabled; } | ||
171 | inline void setEnabled(bool enabled) { m_enabled = enabled; } | ||
172 | inline bool isSelected(void) const { return m_selected; } | ||
173 | inline void setSelected(bool selected) { m_selected = selected; } | ||
148 | 174 | ||
149 | friend class Basemenu; | 175 | private: |
176 | std::string m_label, m_exec; | ||
177 | Basemenu *m_submenu; | ||
178 | int m_function; | ||
179 | bool m_enabled, m_selected; | ||
150 | 180 | ||
151 | public: | 181 | friend class Basemenu; |
152 | BasemenuItem(const char *lp, int fp, const char *ep = (const char *) 0) { | ||
153 | l = lp; | ||
154 | e = ep; | ||
155 | s = 0; | ||
156 | f = fp; | ||
157 | u = 0; | ||
158 | enabled = 1; | ||
159 | selected = 0; | ||
160 | } | ||
161 | |||
162 | BasemenuItem(const char *lp, Basemenu *mp) { | ||
163 | l = lp; | ||
164 | s = mp; | ||
165 | e = 0; | ||
166 | f = 0; | ||
167 | u = 0; | ||
168 | enabled = 1; | ||
169 | selected = 0; | ||
170 | } | ||
171 | |||
172 | BasemenuItem(const char **up, int fp) { | ||
173 | u = up; | ||
174 | l = e = 0; | ||
175 | f = fp; | ||
176 | s = 0; | ||
177 | enabled = 1; | ||
178 | selected = 0; | ||
179 | } | ||
180 | |||
181 | inline const char *exec(void) const { return e; } | ||
182 | inline const char *label(void) const { return l; } | ||
183 | inline const char **ulabel(void) const { return u; } | ||
184 | inline const int &function(void) const { return f; } | ||
185 | inline Basemenu *submenu(void) { return s; } | ||
186 | |||
187 | inline const int &isEnabled(void) const { return enabled; } | ||
188 | inline void setEnabled(int e) { enabled = e; } | ||
189 | inline const int &isSelected(void) const { return selected; } | ||
190 | inline void setSelected(int s) { selected = s; } | ||
191 | }; | 182 | }; |
192 | 183 | ||
193 | 184 | ||