aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-03-18 15:42:34 (GMT)
committerfluxgen <fluxgen>2002-03-18 15:42:34 (GMT)
commit50e3ef9b4a065b951dfd762be7b487d42c81222b (patch)
treed7f97c5b459f6a2410e708ebbd7ca6d9778b699b
parent2604c09bb0bedeed8d1aee9a03be519ad5142d1a (diff)
downloadfluxbox_paul-50e3ef9b4a065b951dfd762be7b487d42c81222b.zip
fluxbox_paul-50e3ef9b4a065b951dfd762be7b487d42c81222b.tar.bz2
changed to std::max/min and fixed some if-statments
-rw-r--r--src/Basemenu.cc53
1 files changed, 31 insertions, 22 deletions
diff --git a/src/Basemenu.cc b/src/Basemenu.cc
index 8ef636a..5328a2b 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.10 2002/02/08 13:47:11 fluxgen Exp $ 25// $Id: Basemenu.cc,v 1.11 2002/03/18 15:42:34 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
@@ -49,6 +49,7 @@
49# include <string.h> 49# include <string.h>
50#endif // STDC_HEADERS 50#endif // STDC_HEADERS
51 51
52#include <iostream>
52 53
53static Basemenu *shown = (Basemenu *) 0; 54static Basemenu *shown = (Basemenu *) 0;
54 55
@@ -236,23 +237,31 @@ int Basemenu::insert(const char **ulabel, int pos, int function) {
236 237
237 238
238int Basemenu::remove(int index) { 239int Basemenu::remove(int index) {
239 if (index < 0 || index > menuitems.size()) return -1; 240 if (index < 0 || index >= menuitems.size()) {
241 #ifdef DEBUG
242 std::cout << "Bad index (" << index << ") given to Basemenu::remove()"
243 << " -- should be between 0 and " << menuitems.size()-1
244 << " inclusive."
245 << std::endl;
246 #endif
247 return -1;
248 }
240 249
241 Menuitems::iterator it = menuitems.begin() + index; 250 Menuitems::iterator it = menuitems.begin() + index;
242 BasemenuItem *item = (*it); 251 BasemenuItem *item = (*it);
243 252
244 if (item) { 253 if (item) {
254 menuitems.erase(it);
245 if ((! internal_menu) && (item->submenu())) { 255 if ((! internal_menu) && (item->submenu())) {
246 Basemenu *tmp = (Basemenu *) item->submenu(); 256 Basemenu *tmp = (Basemenu *) item->submenu();
247 257
248 if (! tmp->internal_menu) { 258 if (! tmp->internal_menu) {
249 delete tmp; 259 delete tmp;
250 } else 260 } else
251 tmp->internal_hide(); 261 tmp->internal_hide();
252 } 262 }
253 263
254 delete item; 264 delete item;
255 menuitems.erase(it);
256 } 265 }
257 266
258 if (which_sub == index) 267 if (which_sub == index)
@@ -458,7 +467,7 @@ void Basemenu::hide(void) {
458 467
459 468
460void Basemenu::internal_hide(void) { 469void Basemenu::internal_hide(void) {
461 if (which_sub != -1) { 470 if (which_sub >= 0) {
462 BasemenuItem *tmp = menuitems[which_sub]; 471 BasemenuItem *tmp = menuitems[which_sub];
463 tmp->submenu()->internal_hide(); 472 tmp->submenu()->internal_hide();
464 } 473 }
@@ -533,7 +542,7 @@ void Basemenu::redrawTitle(void) {
533 542
534 543
535void Basemenu::drawSubmenu(int index) { 544void Basemenu::drawSubmenu(int index) {
536 if (which_sub != -1 && which_sub != index) { 545 if (which_sub >= 0 && which_sub != index) {
537 BasemenuItem *itmp = menuitems[which_sub]; 546 BasemenuItem *itmp = menuitems[which_sub];
538 547
539 if (! itmp->submenu()->isTorn()) 548 if (! itmp->submenu()->isTorn())
@@ -682,27 +691,27 @@ void Basemenu::drawItem(int index, Bool highlight, Bool clear,
682 False); 691 False);
683 } else if (! (x == y && y == -1 && w == h && h == 0)) { 692 } else if (! (x == y && y == -1 && w == h && h == 0)) {
684 // calculate the which part of the hilite to redraw 693 // calculate the which part of the hilite to redraw
685 if (! (max(item_x, x) <= (signed) min(item_x + menu.item_w, x + w) && 694 if (! (std::max(item_x, x) <= (signed) std::min(item_x + menu.item_w, x + w) &&
686 max(item_y, y) <= (signed) min(item_y + menu.item_h, y + h))) { 695 std::max(item_y, y) <= (signed) std::min(item_y + menu.item_h, y + h))) {
687 dohilite = False; 696 dohilite = False;
688 } else { 697 } else {
689 hilite_x = max(item_x, x); 698 hilite_x = std::max(item_x, x);
690 hilite_y = max(item_y, y); 699 hilite_y = std::max(item_y, y);
691 hilite_w = min(item_x + menu.item_w, x + w) - hilite_x; 700 hilite_w = std::min(item_x + menu.item_w, x + w) - hilite_x;
692 hilite_h = min(item_y + menu.item_h, y + h) - hilite_y; 701 hilite_h = std::min(item_y + menu.item_h, y + h) - hilite_y;
693 hoff_x = hilite_x % menu.item_w; 702 hoff_x = hilite_x % menu.item_w;
694 hoff_y = hilite_y % menu.item_h; 703 hoff_y = hilite_y % menu.item_h;
695 } 704 }
696 705
697 // check if we need to redraw the text 706 // check if we need to redraw the text
698 int text_ry = item_y + (menu.bevel_w / 2); 707 int text_ry = item_y + (menu.bevel_w / 2);
699 if (! (max(text_x, x) <= (signed) min(text_x + text_w, x + w) && 708 if (! (std::max(text_x, x) <= (signed) std::min(text_x + text_w, x + w) &&
700 max(text_ry, y) <= (signed) min(text_ry + text_h, y + h))) 709 std::max(text_ry, y) <= (signed) std::min(text_ry + text_h, y + h)))
701 dotext = False; 710 dotext = False;
702 711
703 // check if we need to redraw the select pixmap/menu bullet 712 // check if we need to redraw the select pixmap/menu bullet
704 if (! (max(sel_x, x) <= (signed) min(sel_x + half_w, x + w) && 713 if (! (std::max(sel_x, x) <= (signed) std::min(sel_x + half_w, x + w) &&
705 max(sel_y, y) <= (signed) min(sel_y + half_w, y + h))) 714 std::max(sel_y, y) <= (signed) std::min(sel_y + half_w, y + h)))
706 dosel = False; 715 dosel = False;
707 716
708 } 717 }
@@ -866,7 +875,7 @@ void Basemenu::buttonReleaseEvent(XButtonEvent *re) {
866 if (moving) { 875 if (moving) {
867 moving = False; 876 moving = False;
868 877
869 if (which_sub != -1) 878 if (which_sub >= 0)
870 drawSubmenu(which_sub); 879 drawSubmenu(which_sub);
871 } 880 }
872 881
@@ -913,7 +922,7 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) {
913 922
914 moving = torn = True; 923 moving = torn = True;
915 924
916 if (which_sub != -1) 925 if (which_sub >= 0)
917 drawSubmenu(which_sub); 926 drawSubmenu(which_sub);
918 } else { 927 } else {
919 menu.x = me->x_root - menu.x_move, 928 menu.x = me->x_root - menu.x_move,
@@ -921,7 +930,7 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) {
921 930
922 XMoveWindow(display, menu.window, menu.x, menu.y); 931 XMoveWindow(display, menu.window, menu.x, menu.y);
923 932
924 if (which_sub != -1) 933 if (which_sub >= 0)
925 drawSubmenu(which_sub); 934 drawSubmenu(which_sub);
926 } 935 }
927 } 936 }
@@ -1021,7 +1030,7 @@ void Basemenu::enterNotifyEvent(XCrossingEvent *ce) {
1021 if (shifted) 1030 if (shifted)
1022 XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift); 1031 XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift);
1023 1032
1024 if (which_sub != -1) { 1033 if (which_sub >= 0) {
1025 BasemenuItem *tmp = menuitems[which_sub]; 1034 BasemenuItem *tmp = menuitems[which_sub];
1026 if (tmp->submenu()->isVisible()) { 1035 if (tmp->submenu()->isVisible()) {
1027 int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h), 1036 int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h),
@@ -1053,7 +1062,7 @@ void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) {
1053 XMoveWindow(display, menu.window, menu.x, menu.y); 1062 XMoveWindow(display, menu.window, menu.x, menu.y);
1054 shifted = False; 1063 shifted = False;
1055 1064
1056 if (which_sub != -1) drawSubmenu(which_sub); 1065 if (which_sub >= 0) drawSubmenu(which_sub);
1057 } 1066 }
1058 } 1067 }
1059} 1068}