diff options
Diffstat (limited to 'src/Basemenu.cc')
-rw-r--r-- | src/Basemenu.cc | 117 |
1 files changed, 64 insertions, 53 deletions
diff --git a/src/Basemenu.cc b/src/Basemenu.cc index d92b3db..4beca57 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.7 2002/01/26 11:22:06 fluxgen Exp $ | 25 | // $Id: Basemenu.cc,v 1.8 2002/02/04 22:33:09 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 |
@@ -155,8 +155,6 @@ Basemenu::Basemenu(BScreen *scrn) { | |||
155 | screen->getVisual(), attrib_mask, &attrib); | 155 | screen->getVisual(), attrib_mask, &attrib); |
156 | fluxbox->saveMenuSearch(menu.frame, this); | 156 | fluxbox->saveMenuSearch(menu.frame, this); |
157 | 157 | ||
158 | menuitems = new LinkedList<BasemenuItem>; | ||
159 | |||
160 | // even though this is the end of the constructor the menu is still not | 158 | // even though this is the end of the constructor the menu is still not |
161 | // completely created. items must be inserted and it must be update()'d | 159 | // completely created. items must be inserted and it must be update()'d |
162 | } | 160 | } |
@@ -168,12 +166,10 @@ Basemenu::~Basemenu(void) { | |||
168 | if (shown && shown->getWindowID() == getWindowID()) | 166 | if (shown && shown->getWindowID() == getWindowID()) |
169 | shown = (Basemenu *) 0; | 167 | shown = (Basemenu *) 0; |
170 | 168 | ||
171 | int n = menuitems->count(); | 169 | int n = menuitems.size() - 1; |
172 | for (int i = 0; i < n; ++i) | 170 | for (int i = 0; i < n; ++i) |
173 | remove(0); | 171 | remove(0); |
174 | 172 | ||
175 | delete menuitems; | ||
176 | |||
177 | if (menu.label) | 173 | if (menu.label) |
178 | delete [] menu.label; | 174 | delete [] menu.label; |
179 | 175 | ||
@@ -207,9 +203,13 @@ int Basemenu::insert(const char *l, int function, const char *e, int pos) { | |||
207 | if (e) exec = StringUtil::strdup(e); | 203 | if (e) exec = StringUtil::strdup(e); |
208 | 204 | ||
209 | BasemenuItem *item = new BasemenuItem(label, function, exec); | 205 | BasemenuItem *item = new BasemenuItem(label, function, exec); |
210 | menuitems->insert(item, pos); | 206 | if (pos == -1) { |
207 | menuitems.push_back(item); | ||
208 | } else { | ||
209 | menuitems.insert(menuitems.begin() + pos, item); | ||
210 | } | ||
211 | 211 | ||
212 | return menuitems->count(); | 212 | return menuitems.size(); |
213 | } | 213 | } |
214 | 214 | ||
215 | 215 | ||
@@ -219,26 +219,35 @@ int Basemenu::insert(const char *l, Basemenu *submenu, int pos) { | |||
219 | if (l) label = StringUtil::strdup(l); | 219 | if (l) label = StringUtil::strdup(l); |
220 | 220 | ||
221 | BasemenuItem *item = new BasemenuItem(label, submenu); | 221 | BasemenuItem *item = new BasemenuItem(label, submenu); |
222 | menuitems->insert(item, pos); | 222 | if (pos == -1) { |
223 | menuitems.push_back(item); | ||
224 | } else { | ||
225 | menuitems.insert(menuitems.begin() + pos, item); | ||
226 | } | ||
223 | 227 | ||
224 | submenu->parent = this; | 228 | submenu->parent = this; |
225 | 229 | ||
226 | return menuitems->count(); | 230 | return menuitems.size(); |
227 | } | 231 | } |
228 | 232 | ||
229 | 233 | ||
230 | int Basemenu::insert(const char **ulabel, int pos, int function) { | 234 | int Basemenu::insert(const char **ulabel, int pos, int function) { |
231 | BasemenuItem *item = new BasemenuItem(ulabel, function); | 235 | BasemenuItem *item = new BasemenuItem(ulabel, function); |
232 | menuitems->insert(item, pos); | 236 | if (pos == -1) { |
237 | menuitems.push_back(item); | ||
238 | } else { | ||
239 | menuitems.insert(menuitems.begin() + pos, item); | ||
240 | } | ||
233 | 241 | ||
234 | return menuitems->count(); | 242 | return menuitems.size(); |
235 | } | 243 | } |
236 | 244 | ||
237 | 245 | ||
238 | int Basemenu::remove(int index) { | 246 | int Basemenu::remove(int index) { |
239 | if (index < 0 || index > menuitems->count()) return -1; | 247 | if (index < 0 || index > menuitems.size()) return -1; |
240 | 248 | ||
241 | BasemenuItem *item = menuitems->remove(index); | 249 | Menuitems::iterator it = menuitems.erase(menuitems.begin() + index); |
250 | BasemenuItem *item = (*it); | ||
242 | 251 | ||
243 | if (item) { | 252 | if (item) { |
244 | if ((! internal_menu) && (item->submenu())) { | 253 | if ((! internal_menu) && (item->submenu())) { |
@@ -247,8 +256,7 @@ int Basemenu::remove(int index) { | |||
247 | if (! tmp->internal_menu) { | 256 | if (! tmp->internal_menu) { |
248 | delete tmp; | 257 | delete tmp; |
249 | } else | 258 | } else |
250 | 259 | tmp->internal_hide(); | |
251 | tmp->internal_hide(); | ||
252 | } | 260 | } |
253 | 261 | ||
254 | if (item->label()) | 262 | if (item->label()) |
@@ -265,7 +273,7 @@ int Basemenu::remove(int index) { | |||
265 | else if (which_sub > index) | 273 | else if (which_sub > index) |
266 | which_sub--; | 274 | which_sub--; |
267 | 275 | ||
268 | return menuitems->count(); | 276 | return menuitems.size(); |
269 | } | 277 | } |
270 | 278 | ||
271 | 279 | ||
@@ -310,9 +318,10 @@ void Basemenu::update(void) { | |||
310 | menu.item_w = 1; | 318 | menu.item_w = 1; |
311 | 319 | ||
312 | int ii = 0; | 320 | int ii = 0; |
313 | LinkedListIterator<BasemenuItem> it(menuitems); | 321 | Menuitems::iterator it = menuitems.begin(); |
314 | for (; it.current(); it++) { | 322 | Menuitems::iterator it_end = menuitems.end(); |
315 | BasemenuItem *itmp = it.current(); | 323 | for (; it != it_end; ++it) { |
324 | BasemenuItem *itmp = (*it); | ||
316 | 325 | ||
317 | const char *s = ((itmp->u && *itmp->u) ? *itmp->u : | 326 | const char *s = ((itmp->u && *itmp->u) ? *itmp->u : |
318 | ((itmp->l) ? itmp->l : (const char *) 0)); | 327 | ((itmp->l) ? itmp->l : (const char *) 0)); |
@@ -330,18 +339,18 @@ void Basemenu::update(void) { | |||
330 | menu.item_w = ((menu.item_w < (unsigned int) ii) ? ii : menu.item_w); | 339 | menu.item_w = ((menu.item_w < (unsigned int) ii) ? ii : menu.item_w); |
331 | } | 340 | } |
332 | 341 | ||
333 | if (menuitems->count()) { | 342 | if (menuitems.size()) { |
334 | menu.sublevels = 1; | 343 | menu.sublevels = 1; |
335 | 344 | ||
336 | while (((menu.item_h * (menuitems->count() + 1) / menu.sublevels) | 345 | while (((menu.item_h * (menuitems.size() + 1) / menu.sublevels) |
337 | + menu.title_h + screen->getBorderWidth()) > | 346 | + menu.title_h + screen->getBorderWidth()) > |
338 | screen->getHeight()) | 347 | screen->getHeight()) |
339 | menu.sublevels++; | 348 | menu.sublevels++; |
340 | 349 | ||
341 | if (menu.sublevels < menu.minsub) menu.sublevels = menu.minsub; | 350 | if (menu.sublevels < menu.minsub) menu.sublevels = menu.minsub; |
342 | 351 | ||
343 | menu.persub = menuitems->count() / menu.sublevels; | 352 | menu.persub = menuitems.size() / menu.sublevels; |
344 | if (menuitems->count() % menu.sublevels) menu.persub++; | 353 | if (menuitems.size() % menu.sublevels) menu.persub++; |
345 | } else { | 354 | } else { |
346 | menu.sublevels = 0; | 355 | menu.sublevels = 0; |
347 | menu.persub = 0; | 356 | menu.persub = 0; |
@@ -423,7 +432,7 @@ void Basemenu::update(void) { | |||
423 | if (title_vis && visible) redrawTitle(); | 432 | if (title_vis && visible) redrawTitle(); |
424 | 433 | ||
425 | int i = 0; | 434 | int i = 0; |
426 | for (i = 0; visible && i < menuitems->count(); i++) | 435 | for (i = 0; visible && i < menuitems.size(); i++) |
427 | if (i == which_sub) { | 436 | if (i == which_sub) { |
428 | drawItem(i, True, 0); | 437 | drawItem(i, True, 0); |
429 | drawSubmenu(i); | 438 | drawSubmenu(i); |
@@ -464,7 +473,7 @@ void Basemenu::hide(void) { | |||
464 | 473 | ||
465 | void Basemenu::internal_hide(void) { | 474 | void Basemenu::internal_hide(void) { |
466 | if (which_sub != -1) { | 475 | if (which_sub != -1) { |
467 | BasemenuItem *tmp = menuitems->find(which_sub); | 476 | BasemenuItem *tmp = menuitems[which_sub]; |
468 | tmp->submenu()->internal_hide(); | 477 | tmp->submenu()->internal_hide(); |
469 | } | 478 | } |
470 | 479 | ||
@@ -539,14 +548,14 @@ void Basemenu::redrawTitle(void) { | |||
539 | 548 | ||
540 | void Basemenu::drawSubmenu(int index) { | 549 | void Basemenu::drawSubmenu(int index) { |
541 | if (which_sub != -1 && which_sub != index) { | 550 | if (which_sub != -1 && which_sub != index) { |
542 | BasemenuItem *itmp = menuitems->find(which_sub); | 551 | BasemenuItem *itmp = menuitems[which_sub]; |
543 | 552 | ||
544 | if (! itmp->submenu()->isTorn()) | 553 | if (! itmp->submenu()->isTorn()) |
545 | itmp->submenu()->internal_hide(); | 554 | itmp->submenu()->internal_hide(); |
546 | } | 555 | } |
547 | 556 | ||
548 | if (index >= 0 && index < menuitems->count()) { | 557 | if (index >= 0 && index < menuitems.size()) { |
549 | BasemenuItem *item = menuitems->find(index); | 558 | BasemenuItem *item = menuitems[index]; |
550 | if (item->submenu() && visible && (! item->submenu()->isTorn()) && | 559 | if (item->submenu() && visible && (! item->submenu()->isTorn()) && |
551 | item->isEnabled()) { | 560 | item->isEnabled()) { |
552 | 561 | ||
@@ -607,8 +616,8 @@ void Basemenu::drawSubmenu(int index) { | |||
607 | 616 | ||
608 | 617 | ||
609 | Bool Basemenu::hasSubmenu(int index) { | 618 | Bool Basemenu::hasSubmenu(int index) { |
610 | if ((index >= 0) && (index < menuitems->count())) | 619 | if ((index >= 0) && (index < menuitems.size())) |
611 | if (menuitems->find(index)->submenu()) | 620 | if (menuitems[index]->submenu()) |
612 | return True; | 621 | return True; |
613 | else | 622 | else |
614 | return False; | 623 | return False; |
@@ -620,9 +629,9 @@ Bool Basemenu::hasSubmenu(int index) { | |||
620 | void Basemenu::drawItem(int index, Bool highlight, Bool clear, | 629 | void Basemenu::drawItem(int index, Bool highlight, Bool clear, |
621 | int x, int y, unsigned int w, unsigned int h) | 630 | int x, int y, unsigned int w, unsigned int h) |
622 | { | 631 | { |
623 | if (index < 0 || index > menuitems->count()) return; | 632 | if (index < 0 || index > menuitems.size()) return; |
624 | 633 | ||
625 | BasemenuItem *item = menuitems->find(index); | 634 | BasemenuItem *item = menuitems[index]; |
626 | if (! item) return; | 635 | if (! item) return; |
627 | 636 | ||
628 | Bool dotext = True, dohilite = True, dosel = True; | 637 | Bool dotext = True, dohilite = True, dosel = True; |
@@ -802,7 +811,7 @@ void Basemenu::setLabel(const char *l) { | |||
802 | 811 | ||
803 | 812 | ||
804 | void Basemenu::setItemSelected(int index, Bool sel) { | 813 | void Basemenu::setItemSelected(int index, Bool sel) { |
805 | if (index < 0 || index >= menuitems->count()) return; | 814 | if (index < 0 || index >= menuitems.size()) return; |
806 | 815 | ||
807 | BasemenuItem *item = find(index); | 816 | BasemenuItem *item = find(index); |
808 | if (! item) return; | 817 | if (! item) return; |
@@ -813,7 +822,7 @@ void Basemenu::setItemSelected(int index, Bool sel) { | |||
813 | 822 | ||
814 | 823 | ||
815 | Bool Basemenu::isItemSelected(int index) { | 824 | Bool Basemenu::isItemSelected(int index) { |
816 | if (index < 0 || index >= menuitems->count()) return False; | 825 | if (index < 0 || index >= menuitems.size()) return False; |
817 | 826 | ||
818 | BasemenuItem *item = find(index); | 827 | BasemenuItem *item = find(index); |
819 | if (! item) return False; | 828 | if (! item) return False; |
@@ -823,7 +832,7 @@ Bool Basemenu::isItemSelected(int index) { | |||
823 | 832 | ||
824 | 833 | ||
825 | void Basemenu::setItemEnabled(int index, Bool enable) { | 834 | void Basemenu::setItemEnabled(int index, Bool enable) { |
826 | if (index < 0 || index >= menuitems->count()) return; | 835 | if (index < 0 || index >= menuitems.size()) return; |
827 | 836 | ||
828 | BasemenuItem *item = find(index); | 837 | BasemenuItem *item = find(index); |
829 | if (! item) return; | 838 | if (! item) return; |
@@ -834,7 +843,7 @@ void Basemenu::setItemEnabled(int index, Bool enable) { | |||
834 | 843 | ||
835 | 844 | ||
836 | Bool Basemenu::isItemEnabled(int index) { | 845 | Bool Basemenu::isItemEnabled(int index) { |
837 | if (index < 0 || index >= menuitems->count()) return False; | 846 | if (index < 0 || index >= menuitems.size()) return False; |
838 | 847 | ||
839 | BasemenuItem *item = find(index); | 848 | BasemenuItem *item = find(index); |
840 | if (! item) return False; | 849 | if (! item) return False; |
@@ -848,11 +857,11 @@ void Basemenu::buttonPressEvent(XButtonEvent *be) { | |||
848 | int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h); | 857 | int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h); |
849 | int w = (sbl * menu.persub) + i; | 858 | int w = (sbl * menu.persub) + i; |
850 | 859 | ||
851 | if (w < menuitems->count() && w >= 0) { | 860 | if (w < menuitems.size() && w >= 0) { |
852 | which_press = i; | 861 | which_press = i; |
853 | which_sbl = sbl; | 862 | which_sbl = sbl; |
854 | 863 | ||
855 | BasemenuItem *item = menuitems->find(w); | 864 | BasemenuItem *item = menuitems[w]; |
856 | 865 | ||
857 | if (item->submenu()) | 866 | if (item->submenu()) |
858 | drawSubmenu(w); | 867 | drawSubmenu(w); |
@@ -891,7 +900,7 @@ void Basemenu::buttonReleaseEvent(XButtonEvent *re) { | |||
891 | w = (sbl * menu.persub) + i, | 900 | w = (sbl * menu.persub) + i, |
892 | p = (which_sbl * menu.persub) + which_press; | 901 | p = (which_sbl * menu.persub) + which_press; |
893 | 902 | ||
894 | if (w < menuitems->count() && w >= 0) { | 903 | if (w < menuitems.size() && w >= 0) { |
895 | drawItem(p, (p == which_sub), True); | 904 | drawItem(p, (p == which_sub), True); |
896 | 905 | ||
897 | if (p == w && isItemEnabled(w)) { | 906 | if (p == w && isItemEnabled(w)) { |
@@ -937,10 +946,10 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) { | |||
937 | w = (sbl * menu.persub) + i; | 946 | w = (sbl * menu.persub) + i; |
938 | 947 | ||
939 | if ((i != which_press || sbl != which_sbl) && | 948 | if ((i != which_press || sbl != which_sbl) && |
940 | (w < menuitems->count() && w >= 0)) { | 949 | (w < menuitems.size() && w >= 0)) { |
941 | if (which_press != -1 && which_sbl != -1) { | 950 | if (which_press != -1 && which_sbl != -1) { |
942 | int p = (which_sbl * menu.persub) + which_press; | 951 | int p = (which_sbl * menu.persub) + which_press; |
943 | BasemenuItem *item = menuitems->find(p); | 952 | BasemenuItem *item = menuitems[p]; |
944 | 953 | ||
945 | drawItem(p, False, True); | 954 | drawItem(p, False, True); |
946 | if (item->submenu()) { | 955 | if (item->submenu()) { |
@@ -955,7 +964,7 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) { | |||
955 | which_press = i; | 964 | which_press = i; |
956 | which_sbl = sbl; | 965 | which_sbl = sbl; |
957 | 966 | ||
958 | BasemenuItem *itmp = menuitems->find(w); | 967 | BasemenuItem *itmp = menuitems[w]; |
959 | 968 | ||
960 | if (itmp->submenu()) | 969 | if (itmp->submenu()) |
961 | drawSubmenu(w); | 970 | drawSubmenu(w); |
@@ -970,8 +979,6 @@ void Basemenu::exposeEvent(XExposeEvent *ee) { | |||
970 | if (ee->window == menu.title) { | 979 | if (ee->window == menu.title) { |
971 | redrawTitle(); | 980 | redrawTitle(); |
972 | } else if (ee->window == menu.frame) { | 981 | } else if (ee->window == menu.frame) { |
973 | LinkedListIterator<BasemenuItem> it(menuitems); | ||
974 | |||
975 | // this is a compilicated algorithm... lets do it step by step... | 982 | // this is a compilicated algorithm... lets do it step by step... |
976 | // first... we see in which sub level the expose starts... and how many | 983 | // first... we see in which sub level the expose starts... and how many |
977 | // items down in that sublevel | 984 | // items down in that sublevel |
@@ -988,12 +995,16 @@ void Basemenu::exposeEvent(XExposeEvent *ee) { | |||
988 | int i, ii; | 995 | int i, ii; |
989 | for (i = sbl; i <= sbl_d; i++) { | 996 | for (i = sbl; i <= sbl_d; i++) { |
990 | // set the iterator to the first item in the sublevel needing redrawing | 997 | // set the iterator to the first item in the sublevel needing redrawing |
991 | it.set(id + (i * menu.persub)); | 998 | int index = id + i * menu.persub; |
992 | for (ii = id; ii <= id_d && it.current(); it++, ii++) { | 999 | if (index < menuitems.size() && index >= 0) { |
993 | int index = ii + (i * menu.persub); | 1000 | Menuitems::iterator it = menuitems.begin() + index; |
994 | // redraw the item | 1001 | Menuitems::iterator it_end = menuitems.end(); |
995 | drawItem(index, (which_sub == index), False, | 1002 | for (ii = id; ii <= id_d && it != it_end; ++it, ii++) { |
996 | ee->x, ee->y, ee->width, ee->height); | 1003 | int index = ii + (i * menu.persub); |
1004 | // redraw the item | ||
1005 | drawItem(index, (which_sub == index), False, | ||
1006 | ee->x, ee->y, ee->width, ee->height); | ||
1007 | } | ||
997 | } | 1008 | } |
998 | } | 1009 | } |
999 | } | 1010 | } |
@@ -1025,7 +1036,7 @@ void Basemenu::enterNotifyEvent(XCrossingEvent *ce) { | |||
1025 | XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift); | 1036 | XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift); |
1026 | 1037 | ||
1027 | if (which_sub != -1) { | 1038 | if (which_sub != -1) { |
1028 | BasemenuItem *tmp = menuitems->find(which_sub); | 1039 | BasemenuItem *tmp = menuitems[which_sub]; |
1029 | if (tmp->submenu()->isVisible()) { | 1040 | if (tmp->submenu()->isVisible()) { |
1030 | int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h), | 1041 | int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h), |
1031 | w = (sbl * menu.persub) + i; | 1042 | w = (sbl * menu.persub) + i; |
@@ -1044,7 +1055,7 @@ void Basemenu::enterNotifyEvent(XCrossingEvent *ce) { | |||
1044 | 1055 | ||
1045 | void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) { | 1056 | void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) { |
1046 | if (ce->window == menu.frame) { | 1057 | if (ce->window == menu.frame) { |
1047 | if (which_press != -1 && which_sbl != -1 && menuitems->count() > 0) { | 1058 | if (which_press != -1 && which_sbl != -1 && menuitems.size() > 0) { |
1048 | int p = (which_sbl * menu.persub) + which_press; | 1059 | int p = (which_sbl * menu.persub) + which_press; |
1049 | 1060 | ||
1050 | drawItem(p, (p == which_sub), True); | 1061 | drawItem(p, (p == which_sub), True); |