summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Basemenu.cc68
-rw-r--r--src/Basemenu.hh179
2 files changed, 123 insertions, 124 deletions
diff --git a/src/Basemenu.cc b/src/Basemenu.cc
index 713b2f7..559bb97 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.12 2002/03/19 14:30:42 fluxgen Exp $ 25// $Id: Basemenu.cc,v 1.13 2002/03/20 14:10:03 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
@@ -236,8 +236,8 @@ int Basemenu::insert(const char **ulabel, int pos, int function) {
236} 236}
237 237
238 238
239int Basemenu::remove(int index) { 239int Basemenu::remove(unsigned int index) {
240 if (index < 0 || index >= menuitems.size()) { 240 if (index >= menuitems.size()) {
241 #ifdef DEBUG 241 #ifdef DEBUG
242 std::cout << "Bad index (" << index << ") given to Basemenu::remove()" 242 std::cout << "Bad index (" << index << ") given to Basemenu::remove()"
243 << " -- should be between 0 and " << menuitems.size()-1 243 << " -- should be between 0 and " << menuitems.size()-1
@@ -264,9 +264,9 @@ int Basemenu::remove(int index) {
264 delete item; 264 delete item;
265 } 265 }
266 266
267 if (which_sub == index) 267 if (static_cast<unsigned int>(which_sub) == index)
268 which_sub = -1; 268 which_sub = -1;
269 else if (which_sub > index) 269 else if (static_cast<unsigned int>(which_sub) > index)
270 which_sub--; 270 which_sub--;
271 271
272 return menuitems.size(); 272 return menuitems.size();
@@ -426,13 +426,14 @@ void Basemenu::update(void) {
426 426
427 if (title_vis && visible) redrawTitle(); 427 if (title_vis && visible) redrawTitle();
428 428
429 int i = 0; 429 unsigned int i = 0;
430 for (i = 0; visible && i < menuitems.size(); i++) 430 for (i = 0; visible && i < menuitems.size(); i++) {
431 if (i == which_sub) { 431 if (i == (unsigned int)which_sub) {
432 drawItem(i, True, 0); 432 drawItem(i, True, 0);
433 drawSubmenu(i); 433 drawSubmenu(i);
434 } else 434 } else
435 drawItem(i, False, 0); 435 drawItem(i, False, 0);
436 }
436 437
437 if (parent && visible) 438 if (parent && visible)
438 parent->drawSubmenu(parent->which_sub); 439 parent->drawSubmenu(parent->which_sub);
@@ -541,15 +542,16 @@ void Basemenu::redrawTitle(void) {
541} 542}
542 543
543 544
544void Basemenu::drawSubmenu(int index) { 545void Basemenu::drawSubmenu(unsigned int index) {
545 if (which_sub >= 0 && which_sub != index) { 546 if (which_sub >= 0 && static_cast<unsigned int>(which_sub) != index &&
547 static_cast<unsigned int>(which_sub) < menuitems.size()) {
546 BasemenuItem *itmp = menuitems[which_sub]; 548 BasemenuItem *itmp = menuitems[which_sub];
547 549
548 if (! itmp->submenu()->isTorn()) 550 if (! itmp->submenu()->isTorn())
549 itmp->submenu()->internal_hide(); 551 itmp->submenu()->internal_hide();
550 } 552 }
551 553
552 if (index >= 0 && index < menuitems.size()) { 554 if (index < menuitems.size()) {
553 BasemenuItem *item = menuitems[index]; 555 BasemenuItem *item = menuitems[index];
554 if (item->submenu() && visible && (! item->submenu()->isTorn()) && 556 if (item->submenu() && visible && (! item->submenu()->isTorn()) &&
555 item->isEnabled()) { 557 item->isEnabled()) {
@@ -648,26 +650,26 @@ void Basemenu::drawSubmenu(int index) {
648} 650}
649 651
650 652
651Bool Basemenu::hasSubmenu(int index) { 653bool Basemenu::hasSubmenu(unsigned int index) {
652 if ((index >= 0) && (index < menuitems.size())) 654 if (index < menuitems.size())
653 if (menuitems[index]->submenu()) 655 if (menuitems[index]->submenu())
654 return True; 656 return true;
655 else 657 else
656 return False; 658 return false;
657 else 659 else
658 return False; 660 return false;
659} 661}
660 662
661 663
662void Basemenu::drawItem(int index, Bool highlight, Bool clear, 664void Basemenu::drawItem(unsigned int index, bool highlight, bool clear,
663 int x, int y, unsigned int w, unsigned int h) 665 int x, int y, unsigned int w, unsigned int h)
664{ 666{
665 if (index < 0 || index > menuitems.size()) return; 667 if (index >= menuitems.size()) return;
666 668
667 BasemenuItem *item = menuitems[index]; 669 BasemenuItem *item = menuitems[index];
668 if (! item) return; 670 if (! item) return;
669 671
670 Bool dotext = True, dohilite = True, dosel = True; 672 bool dotext = true, dohilite = true, dosel = true;
671 const char *text = item->label(); 673 const char *text = item->label();
672 int sbl = index / menu.persub, i = index - (sbl * menu.persub); 674 int sbl = index / menu.persub, i = index - (sbl * menu.persub);
673 int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h); 675 int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h);
@@ -843,39 +845,39 @@ void Basemenu::setLabel(const char *l) {
843} 845}
844 846
845 847
846void Basemenu::setItemSelected(int index, Bool sel) { 848void Basemenu::setItemSelected(unsigned int index, bool sel) {
847 if (index < 0 || index >= menuitems.size()) return; 849 if (index >= menuitems.size()) return;
848 850
849 BasemenuItem *item = find(index); 851 BasemenuItem *item = find(index);
850 if (! item) return; 852 if (! item) return;
851 853
852 item->setSelected(sel); 854 item->setSelected(sel);
853 if (visible) drawItem(index, (index == which_sub), True); 855 if (visible) drawItem(index, (index == (unsigned int)which_sub), true);
854} 856}
855 857
856 858
857Bool Basemenu::isItemSelected(int index) { 859bool Basemenu::isItemSelected(unsigned int index) {
858 if (index < 0 || index >= menuitems.size()) return False; 860 if (index >= menuitems.size()) return false;
859 861
860 BasemenuItem *item = find(index); 862 BasemenuItem *item = find(index);
861 if (! item) return False; 863 if (! item) return false;
862 864
863 return item->isSelected(); 865 return item->isSelected();
864} 866}
865 867
866 868
867void Basemenu::setItemEnabled(int index, Bool enable) { 869void Basemenu::setItemEnabled(unsigned int index, bool enable) {
868 if (index < 0 || index >= menuitems.size()) return; 870 if (index >= menuitems.size()) return;
869 871
870 BasemenuItem *item = find(index); 872 BasemenuItem *item = find(index);
871 if (! item) return; 873 if (! item) return;
872 874
873 item->setEnabled(enable); 875 item->setEnabled(enable);
874 if (visible) drawItem(index, (index == which_sub), True); 876 if (visible) drawItem(index, (index == static_cast<unsigned int>(which_sub)), True);
875} 877}
876 878
877 879
878Bool Basemenu::isItemEnabled(int index) { 880bool Basemenu::isItemEnabled(unsigned int index) {
879 if (index < 0 || index >= menuitems.size()) return False; 881 if (index < 0 || index >= menuitems.size()) return False;
880 882
881 BasemenuItem *item = find(index); 883 BasemenuItem *item = find(index);
@@ -890,7 +892,7 @@ void Basemenu::buttonPressEvent(XButtonEvent *be) {
890 int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h); 892 int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h);
891 int w = (sbl * menu.persub) + i; 893 int w = (sbl * menu.persub) + i;
892 894
893 if (w < menuitems.size() && w >= 0) { 895 if (w < static_cast<int>(menuitems.size()) && w >= 0) {
894 which_press = i; 896 which_press = i;
895 which_sbl = sbl; 897 which_sbl = sbl;
896 898
@@ -933,7 +935,7 @@ void Basemenu::buttonReleaseEvent(XButtonEvent *re) {
933 w = (sbl * menu.persub) + i, 935 w = (sbl * menu.persub) + i,
934 p = (which_sbl * menu.persub) + which_press; 936 p = (which_sbl * menu.persub) + which_press;
935 937
936 if (w < menuitems.size() && w >= 0) { 938 if (w < static_cast<int>(menuitems.size()) && w >= 0) {
937 drawItem(p, (p == which_sub), True); 939 drawItem(p, (p == which_sub), True);
938 940
939 if (p == w && isItemEnabled(w)) { 941 if (p == w && isItemEnabled(w)) {
@@ -979,7 +981,7 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) {
979 w = (sbl * menu.persub) + i; 981 w = (sbl * menu.persub) + i;
980 982
981 if ((i != which_press || sbl != which_sbl) && 983 if ((i != which_press || sbl != which_sbl) &&
982 (w < menuitems.size() && w >= 0)) { 984 (w < static_cast<int>(menuitems.size()) && w >= 0)) {
983 if (which_press != -1 && which_sbl != -1) { 985 if (which_press != -1 && which_sbl != -1) {
984 int p = (which_sbl * menu.persub) + which_press; 986 int p = (which_sbl * menu.persub) + which_press;
985 BasemenuItem *item = menuitems[p]; 987 BasemenuItem *item = menuitems[p];
@@ -1029,7 +1031,7 @@ void Basemenu::exposeEvent(XExposeEvent *ee) {
1029 for (i = sbl; i <= sbl_d; i++) { 1031 for (i = sbl; i <= sbl_d; i++) {
1030 // set the iterator to the first item in the sublevel needing redrawing 1032 // set the iterator to the first item in the sublevel needing redrawing
1031 int index = id + i * menu.persub; 1033 int index = id + i * menu.persub;
1032 if (index < menuitems.size() && index >= 0) { 1034 if (index < static_cast<int>(menuitems.size()) && index >= 0) {
1033 Menuitems::iterator it = menuitems.begin() + index; 1035 Menuitems::iterator it = menuitems.begin() + index;
1034 Menuitems::iterator it_end = menuitems.end(); 1036 Menuitems::iterator it_end = menuitems.end();
1035 for (ii = id; ii <= id_d && it != it_end; ++it, ii++) { 1037 for (ii = id; ii <= id_d && it != it_end; ++it, ii++) {
diff --git a/src/Basemenu.hh b/src/Basemenu.hh
index 14f7c67..d2794ff 100644
--- a/src/Basemenu.hh
+++ b/src/Basemenu.hh
@@ -22,10 +22,10 @@
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.7 2002/02/17 19:00:04 fluxgen Exp $ 25// $Id: Basemenu.hh,v 1.8 2002/03/20 14:10:03 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> 31#include <vector>
@@ -40,103 +40,100 @@ class BImageControl;
40class BScreen; 40class BScreen;
41 41
42class Basemenu { 42class Basemenu {
43public:
44 explicit Basemenu(BScreen *);
45 virtual ~Basemenu(void);
46
47 inline const Bool &isTorn(void) const { return torn; }
48 inline const Bool &isVisible(void) const { return visible; }
49
50 inline BScreen *getScreen(void) const { return screen; }
51
52 inline const Window &getWindowID(void) const { return menu.window; }
53
54 inline const char *getLabel(void) const { return menu.label; }
55
56 int insert(const char *, int = 0, const char * = (const char *) 0, int = -1);
57 int insert(const char **, int = -1, int = 0);
58 int insert(const char *, Basemenu *, int = -1);
59 int remove(unsigned int item);
60
61 inline const int &getX(void) const { return menu.x; }
62 inline const int &getY(void) const { return menu.y; }
63 inline int getCount(void) { return menuitems.size(); }
64 inline const int &getCurrentSubmenu(void) const { return which_sub; }
65
66 inline const unsigned int &getWidth(void) const { return menu.width; }
67 inline const unsigned int &getHeight(void) const { return menu.height; }
68 inline const unsigned int &getTitleHeight(void) const { return menu.title_h; }
69
70 inline void setInternalMenu(void) { internal_menu = True; }
71 inline void setAlignment(int a) { alignment = a; }
72 inline void setTorn(void) { torn = True; }
73 inline void removeParent(void) { if (internal_menu) parent = (Basemenu *) 0; }
74
75 bool hasSubmenu(unsigned int index);
76 bool isItemSelected(unsigned int index);
77 bool isItemEnabled(unsigned int index);
78
79 void buttonPressEvent(XButtonEvent *);
80 void buttonReleaseEvent(XButtonEvent *);
81 void motionNotifyEvent(XMotionEvent *);
82 void enterNotifyEvent(XCrossingEvent *);
83 void leaveNotifyEvent(XCrossingEvent *);
84 void exposeEvent(XExposeEvent *);
85 void reconfigure(void);
86 void setLabel(const char *n);
87 void move(int, int);
88 void update(void);
89 void setItemSelected(unsigned int index, bool val);
90 void setItemEnabled(unsigned int, bool val);
91
92 virtual void drawSubmenu(unsigned int index);
93 virtual void show(void);
94 virtual void hide(void);
95
96 enum { ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM };
97 enum { RIGHT = 1, LEFT };
98 enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND };
99
43private: 100private:
44 typedef std::vector<BasemenuItem *> Menuitems; 101 typedef std::vector<BasemenuItem *> Menuitems;
45 Menuitems menuitems; 102 Menuitems menuitems;
46 Fluxbox *fluxbox; 103 Fluxbox *fluxbox;
47 Basemenu *parent; 104 Basemenu *parent;
48 BImageControl *image_ctrl; 105 BImageControl *image_ctrl;
49 BScreen *screen; 106 BScreen *screen;
50 107
51 Bool moving, visible, movable, torn, internal_menu, title_vis, shifted, 108 Bool moving, visible, movable, torn, internal_menu, title_vis, shifted,
52 hide_tree; 109 hide_tree;
53 Display *display; 110 Display *display;
54 int which_sub, which_press, which_sbl, alignment; 111 int which_sub, which_press, which_sbl, alignment;
55 112
56 struct _menu { 113 struct _menu {
57 Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap; 114 Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap;
58 Window window, frame, title; 115 Window window, frame, title;
59 116
60 char *label; 117 char *label;
61 int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub, 118 int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub,
62 grab_x, grab_y; 119 grab_x, grab_y;
63 unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w, 120 unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w,
64 bevel_h; 121 bevel_h;
65 } menu; 122 } menu;
66 123
67 124
68protected: 125protected:
69 inline BasemenuItem *find(int index) { return menuitems[index]; } 126 inline BasemenuItem *find(unsigned int index) { return menuitems[index]; }
70 inline void setTitleVisibility(Bool b) { title_vis = b; } 127 inline void setTitleVisibility(bool b) { title_vis = b; }
71 inline void setMovable(Bool b) { movable = b; } 128 inline void setMovable(bool b) { movable = b; }
72 inline void setHideTree(Bool h) { hide_tree = h; } 129 inline void setHideTree(bool h) { hide_tree = h; }
73 inline void setMinimumSublevels(int m) { menu.minsub = m; } 130 inline void setMinimumSublevels(int m) { menu.minsub = m; }
74 131
75 virtual void itemSelected(int, int) = 0; 132 virtual void itemSelected(int, int) = 0;
76 virtual void drawItem(int, Bool = False, Bool = False, 133 virtual void drawItem(unsigned int index, bool highlight= false, bool clear= false,
77 int = -1, int = -1, unsigned int = 0, unsigned int = 0); 134 int x= -1, int y= -1, unsigned int width= 0, unsigned int height= 0);
78 virtual void redrawTitle(); 135 virtual void redrawTitle();
79 virtual void internal_hide(void); 136 virtual void internal_hide(void);
80
81
82public:
83 Basemenu(BScreen *);
84 virtual ~Basemenu(void);
85
86 inline const Bool &isTorn(void) const { return torn; }
87 inline const Bool &isVisible(void) const { return visible; }
88
89 inline BScreen *getScreen(void) { return screen; }
90
91 inline const Window &getWindowID(void) const { return menu.window; }
92
93 inline const char *getLabel(void) const { return menu.label; }
94
95 int insert(const char *, int = 0, const char * = (const char *) 0, int = -1);
96 int insert(const char **, int = -1, int = 0);
97 int insert(const char *, Basemenu *, int = -1);
98 int remove(int);
99
100 inline const int &getX(void) const { return menu.x; }
101 inline const int &getY(void) const { return menu.y; }
102 inline int getCount(void) { return menuitems.size(); }
103 inline const int &getCurrentSubmenu(void) const { return which_sub; }
104
105 inline const unsigned int &getWidth(void) const { return menu.width; }
106 inline const unsigned int &getHeight(void) const { return menu.height; }
107 inline const unsigned int &getTitleHeight(void) const { return menu.title_h; }
108
109 inline void setInternalMenu(void) { internal_menu = True; }
110 inline void setAlignment(int a) { alignment = a; }
111 inline void setTorn(void) { torn = True; }
112 inline void removeParent(void)
113 { if (internal_menu) parent = (Basemenu *) 0; }
114
115 Bool hasSubmenu(int);
116 Bool isItemSelected(int);
117 Bool isItemEnabled(int);
118
119 void buttonPressEvent(XButtonEvent *);
120 void buttonReleaseEvent(XButtonEvent *);
121 void motionNotifyEvent(XMotionEvent *);
122 void enterNotifyEvent(XCrossingEvent *);
123 void leaveNotifyEvent(XCrossingEvent *);
124 void exposeEvent(XExposeEvent *);
125 void reconfigure(void);
126 void setLabel(const char *n);
127 void move(int, int);
128 void update(void);
129 void setItemSelected(int, Bool);
130 void setItemEnabled(int, Bool);
131
132 virtual void drawSubmenu(int);
133 virtual void show(void);
134 virtual void hide(void);
135
136 enum { ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM };
137 enum { RIGHT = 1, LEFT };
138 enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND };
139
140}; 137};
141 138
142class BasemenuItem { 139class BasemenuItem {