From 3b330a5f6225f48f299371d5154bfb89db495903 Mon Sep 17 00:00:00 2001 From: fluxgen <fluxgen> Date: Wed, 20 Mar 2002 14:10:03 +0000 Subject: signed/unsigned warnings --- src/Basemenu.cc | 68 ++++++++++----------- src/Basemenu.hh | 179 ++++++++++++++++++++++++++++---------------------------- 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Basemenu.cc,v 1.12 2002/03/19 14:30:42 fluxgen Exp $ +// $Id: Basemenu.cc,v 1.13 2002/03/20 14:10:03 fluxgen Exp $ // stupid macros needed to access some functions in version 2 of the GNU C // library @@ -236,8 +236,8 @@ int Basemenu::insert(const char **ulabel, int pos, int function) { } -int Basemenu::remove(int index) { - if (index < 0 || index >= menuitems.size()) { +int Basemenu::remove(unsigned int index) { + if (index >= menuitems.size()) { #ifdef DEBUG std::cout << "Bad index (" << index << ") given to Basemenu::remove()" << " -- should be between 0 and " << menuitems.size()-1 @@ -264,9 +264,9 @@ int Basemenu::remove(int index) { delete item; } - if (which_sub == index) + if (static_cast<unsigned int>(which_sub) == index) which_sub = -1; - else if (which_sub > index) + else if (static_cast<unsigned int>(which_sub) > index) which_sub--; return menuitems.size(); @@ -426,13 +426,14 @@ void Basemenu::update(void) { if (title_vis && visible) redrawTitle(); - int i = 0; - for (i = 0; visible && i < menuitems.size(); i++) - if (i == which_sub) { + unsigned int i = 0; + for (i = 0; visible && i < menuitems.size(); i++) { + if (i == (unsigned int)which_sub) { drawItem(i, True, 0); drawSubmenu(i); } else drawItem(i, False, 0); + } if (parent && visible) parent->drawSubmenu(parent->which_sub); @@ -541,15 +542,16 @@ void Basemenu::redrawTitle(void) { } -void Basemenu::drawSubmenu(int index) { - if (which_sub >= 0 && which_sub != index) { +void Basemenu::drawSubmenu(unsigned int index) { + if (which_sub >= 0 && static_cast<unsigned int>(which_sub) != index && + static_cast<unsigned int>(which_sub) < menuitems.size()) { BasemenuItem *itmp = menuitems[which_sub]; if (! itmp->submenu()->isTorn()) itmp->submenu()->internal_hide(); } - if (index >= 0 && index < menuitems.size()) { + if (index < menuitems.size()) { BasemenuItem *item = menuitems[index]; if (item->submenu() && visible && (! item->submenu()->isTorn()) && item->isEnabled()) { @@ -648,26 +650,26 @@ void Basemenu::drawSubmenu(int index) { } -Bool Basemenu::hasSubmenu(int index) { - if ((index >= 0) && (index < menuitems.size())) +bool Basemenu::hasSubmenu(unsigned int index) { + if (index < menuitems.size()) if (menuitems[index]->submenu()) - return True; + return true; else - return False; + return false; else - return False; + return false; } -void Basemenu::drawItem(int index, Bool highlight, Bool clear, +void Basemenu::drawItem(unsigned int index, bool highlight, bool clear, int x, int y, unsigned int w, unsigned int h) { - if (index < 0 || index > menuitems.size()) return; + if (index >= menuitems.size()) return; BasemenuItem *item = menuitems[index]; if (! item) return; - Bool dotext = True, dohilite = True, dosel = True; + bool dotext = true, dohilite = true, dosel = true; const char *text = item->label(); int sbl = index / menu.persub, i = index - (sbl * menu.persub); int item_x = (sbl * menu.item_w), item_y = (i * menu.item_h); @@ -843,39 +845,39 @@ void Basemenu::setLabel(const char *l) { } -void Basemenu::setItemSelected(int index, Bool sel) { - if (index < 0 || index >= menuitems.size()) return; +void Basemenu::setItemSelected(unsigned int index, bool sel) { + if (index >= menuitems.size()) return; BasemenuItem *item = find(index); if (! item) return; item->setSelected(sel); - if (visible) drawItem(index, (index == which_sub), True); + if (visible) drawItem(index, (index == (unsigned int)which_sub), true); } -Bool Basemenu::isItemSelected(int index) { - if (index < 0 || index >= menuitems.size()) return False; +bool Basemenu::isItemSelected(unsigned int index) { + if (index >= menuitems.size()) return false; BasemenuItem *item = find(index); - if (! item) return False; + if (! item) return false; return item->isSelected(); } -void Basemenu::setItemEnabled(int index, Bool enable) { - if (index < 0 || index >= menuitems.size()) return; +void Basemenu::setItemEnabled(unsigned int index, bool enable) { + if (index >= menuitems.size()) return; BasemenuItem *item = find(index); if (! item) return; item->setEnabled(enable); - if (visible) drawItem(index, (index == which_sub), True); + if (visible) drawItem(index, (index == static_cast<unsigned int>(which_sub)), True); } -Bool Basemenu::isItemEnabled(int index) { +bool Basemenu::isItemEnabled(unsigned int index) { if (index < 0 || index >= menuitems.size()) return False; BasemenuItem *item = find(index); @@ -890,7 +892,7 @@ void Basemenu::buttonPressEvent(XButtonEvent *be) { int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h); int w = (sbl * menu.persub) + i; - if (w < menuitems.size() && w >= 0) { + if (w < static_cast<int>(menuitems.size()) && w >= 0) { which_press = i; which_sbl = sbl; @@ -933,7 +935,7 @@ void Basemenu::buttonReleaseEvent(XButtonEvent *re) { w = (sbl * menu.persub) + i, p = (which_sbl * menu.persub) + which_press; - if (w < menuitems.size() && w >= 0) { + if (w < static_cast<int>(menuitems.size()) && w >= 0) { drawItem(p, (p == which_sub), True); if (p == w && isItemEnabled(w)) { @@ -979,7 +981,7 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) { w = (sbl * menu.persub) + i; if ((i != which_press || sbl != which_sbl) && - (w < menuitems.size() && w >= 0)) { + (w < static_cast<int>(menuitems.size()) && w >= 0)) { if (which_press != -1 && which_sbl != -1) { int p = (which_sbl * menu.persub) + which_press; BasemenuItem *item = menuitems[p]; @@ -1029,7 +1031,7 @@ void Basemenu::exposeEvent(XExposeEvent *ee) { for (i = sbl; i <= sbl_d; i++) { // set the iterator to the first item in the sublevel needing redrawing int index = id + i * menu.persub; - if (index < menuitems.size() && index >= 0) { + if (index < static_cast<int>(menuitems.size()) && index >= 0) { Menuitems::iterator it = menuitems.begin() + index; Menuitems::iterator it_end = menuitems.end(); 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 @@ // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Basemenu.hh,v 1.7 2002/02/17 19:00:04 fluxgen Exp $ +// $Id: Basemenu.hh,v 1.8 2002/03/20 14:10:03 fluxgen Exp $ -#ifndef BASEMENU_HH -#define BASEMENU_HH +#ifndef BASEMENU_HH +#define BASEMENU_HH #include <X11/Xlib.h> #include <vector> @@ -40,103 +40,100 @@ class BImageControl; class BScreen; class Basemenu { +public: + explicit Basemenu(BScreen *); + virtual ~Basemenu(void); + + inline const Bool &isTorn(void) const { return torn; } + inline const Bool &isVisible(void) const { return visible; } + + inline BScreen *getScreen(void) const { return screen; } + + inline const Window &getWindowID(void) const { return menu.window; } + + inline const char *getLabel(void) const { return menu.label; } + + int insert(const char *, int = 0, const char * = (const char *) 0, int = -1); + int insert(const char **, int = -1, int = 0); + int insert(const char *, Basemenu *, int = -1); + int remove(unsigned int item); + + inline const int &getX(void) const { return menu.x; } + inline const int &getY(void) const { return menu.y; } + inline int getCount(void) { return menuitems.size(); } + inline const int &getCurrentSubmenu(void) const { return which_sub; } + + inline const unsigned int &getWidth(void) const { return menu.width; } + inline const unsigned int &getHeight(void) const { return menu.height; } + inline const unsigned int &getTitleHeight(void) const { return menu.title_h; } + + inline void setInternalMenu(void) { internal_menu = True; } + inline void setAlignment(int a) { alignment = a; } + inline void setTorn(void) { torn = True; } + inline void removeParent(void) { if (internal_menu) parent = (Basemenu *) 0; } + + bool hasSubmenu(unsigned int index); + bool isItemSelected(unsigned int index); + bool isItemEnabled(unsigned int index); + + void buttonPressEvent(XButtonEvent *); + void buttonReleaseEvent(XButtonEvent *); + void motionNotifyEvent(XMotionEvent *); + void enterNotifyEvent(XCrossingEvent *); + void leaveNotifyEvent(XCrossingEvent *); + void exposeEvent(XExposeEvent *); + void reconfigure(void); + void setLabel(const char *n); + void move(int, int); + void update(void); + void setItemSelected(unsigned int index, bool val); + void setItemEnabled(unsigned int, bool val); + + virtual void drawSubmenu(unsigned int index); + virtual void show(void); + virtual void hide(void); + + enum { ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM }; + enum { RIGHT = 1, LEFT }; + enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND }; + private: typedef std::vector<BasemenuItem *> Menuitems; Menuitems menuitems; - Fluxbox *fluxbox; - Basemenu *parent; - BImageControl *image_ctrl; - BScreen *screen; + Fluxbox *fluxbox; + Basemenu *parent; + BImageControl *image_ctrl; + BScreen *screen; - Bool moving, visible, movable, torn, internal_menu, title_vis, shifted, - hide_tree; - Display *display; - int which_sub, which_press, which_sbl, alignment; + Bool moving, visible, movable, torn, internal_menu, title_vis, shifted, + hide_tree; + Display *display; + int which_sub, which_press, which_sbl, alignment; - struct _menu { - Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap; - Window window, frame, title; + struct _menu { + Pixmap frame_pixmap, title_pixmap, hilite_pixmap, sel_pixmap; + Window window, frame, title; - char *label; - int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub, - grab_x, grab_y; - unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w, - bevel_h; - } menu; + char *label; + int x, y, x_move, y_move, x_shift, y_shift, sublevels, persub, minsub, + grab_x, grab_y; + unsigned int width, height, title_h, frame_h, item_w, item_h, bevel_w, + bevel_h; + } menu; protected: - inline BasemenuItem *find(int index) { return menuitems[index]; } - inline void setTitleVisibility(Bool b) { title_vis = b; } - inline void setMovable(Bool b) { movable = b; } - inline void setHideTree(Bool h) { hide_tree = h; } - inline void setMinimumSublevels(int m) { menu.minsub = m; } - - virtual void itemSelected(int, int) = 0; - virtual void drawItem(int, Bool = False, Bool = False, - int = -1, int = -1, unsigned int = 0, unsigned int = 0); - virtual void redrawTitle(); - virtual void internal_hide(void); - - -public: - Basemenu(BScreen *); - virtual ~Basemenu(void); - - inline const Bool &isTorn(void) const { return torn; } - inline const Bool &isVisible(void) const { return visible; } - - inline BScreen *getScreen(void) { return screen; } - - inline const Window &getWindowID(void) const { return menu.window; } - - inline const char *getLabel(void) const { return menu.label; } - - int insert(const char *, int = 0, const char * = (const char *) 0, int = -1); - int insert(const char **, int = -1, int = 0); - int insert(const char *, Basemenu *, int = -1); - int remove(int); - - inline const int &getX(void) const { return menu.x; } - inline const int &getY(void) const { return menu.y; } - inline int getCount(void) { return menuitems.size(); } - inline const int &getCurrentSubmenu(void) const { return which_sub; } - - inline const unsigned int &getWidth(void) const { return menu.width; } - inline const unsigned int &getHeight(void) const { return menu.height; } - inline const unsigned int &getTitleHeight(void) const { return menu.title_h; } - - inline void setInternalMenu(void) { internal_menu = True; } - inline void setAlignment(int a) { alignment = a; } - inline void setTorn(void) { torn = True; } - inline void removeParent(void) - { if (internal_menu) parent = (Basemenu *) 0; } - - Bool hasSubmenu(int); - Bool isItemSelected(int); - Bool isItemEnabled(int); - - void buttonPressEvent(XButtonEvent *); - void buttonReleaseEvent(XButtonEvent *); - void motionNotifyEvent(XMotionEvent *); - void enterNotifyEvent(XCrossingEvent *); - void leaveNotifyEvent(XCrossingEvent *); - void exposeEvent(XExposeEvent *); - void reconfigure(void); - void setLabel(const char *n); - void move(int, int); - void update(void); - void setItemSelected(int, Bool); - void setItemEnabled(int, Bool); - - virtual void drawSubmenu(int); - virtual void show(void); - virtual void hide(void); - - enum { ALIGNDONTCARE = 1, ALIGNTOP, ALIGNBOTTOM }; - enum { RIGHT = 1, LEFT }; - enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND }; - + inline BasemenuItem *find(unsigned int index) { return menuitems[index]; } + inline void setTitleVisibility(bool b) { title_vis = b; } + inline void setMovable(bool b) { movable = b; } + inline void setHideTree(bool h) { hide_tree = h; } + inline void setMinimumSublevels(int m) { menu.minsub = m; } + + virtual void itemSelected(int, int) = 0; + virtual void drawItem(unsigned int index, bool highlight= false, bool clear= false, + int x= -1, int y= -1, unsigned int width= 0, unsigned int height= 0); + virtual void redrawTitle(); + virtual void internal_hide(void); }; class BasemenuItem { -- cgit v0.11.2