all repos — fluxbox @ fa46eaeeaaa75e3f738032a35777aee9a2b35e7b

custom fork of the fluxbox windowmanager

back to stl vector
fluxgen fluxgen
commit

fa46eaeeaaa75e3f738032a35777aee9a2b35e7b

parent

bac6c2ddb5f10f430c0d63e37eab33a32ebb471f

2 files changed, 45 insertions(+), 68 deletions(-)

jump to
M src/Basemenu.ccsrc/Basemenu.cc

@@ -22,7 +22,7 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Basemenu.cc,v 1.8 2002/02/04 22:33:09 fluxgen Exp $ +// $Id: Basemenu.cc,v 1.9 2002/02/08 13:20:23 fluxgen Exp $ // stupid macros needed to access some functions in version 2 of the GNU C // library

@@ -196,12 +196,7 @@ XDestroyWindow(display, menu.window);

} -int Basemenu::insert(const char *l, int function, const char *e, int pos) { - char *label = 0, *exec = 0; - - if (l) label = StringUtil::strdup(l); - if (e) exec = StringUtil::strdup(e); - +int Basemenu::insert(const char *label, int function, const char *exec, int pos) { BasemenuItem *item = new BasemenuItem(label, function, exec); if (pos == -1) { menuitems.push_back(item);

@@ -213,11 +208,7 @@ return menuitems.size();

} -int Basemenu::insert(const char *l, Basemenu *submenu, int pos) { - char *label = 0; - - if (l) label = StringUtil::strdup(l); - +int Basemenu::insert(const char *label, Basemenu *submenu, int pos) { BasemenuItem *item = new BasemenuItem(label, submenu); if (pos == -1) { menuitems.push_back(item);

@@ -232,7 +223,8 @@ }

int Basemenu::insert(const char **ulabel, int pos, int function) { - BasemenuItem *item = new BasemenuItem(ulabel, function); + assert(ulabel); + BasemenuItem *item = new BasemenuItem(*ulabel, function); if (pos == -1) { menuitems.push_back(item); } else {

@@ -259,13 +251,8 @@ } else

tmp->internal_hide(); } - if (item->label()) - delete [] item->label(); - - if (item->exec()) - delete [] item->exec(); - delete item; + menuitems.erase(it); } if (which_sub == index)

@@ -323,8 +310,7 @@ Menuitems::iterator it_end = menuitems.end();

for (; it != it_end; ++it) { BasemenuItem *itmp = (*it); - const char *s = ((itmp->u && *itmp->u) ? *itmp->u : - ((itmp->l) ? itmp->l : (const char *) 0)); + const char *s = itmp->label(); int l = strlen(s); if (i18n->multibyte()) {

@@ -635,7 +621,7 @@ BasemenuItem *item = menuitems[index];

if (! item) return; Bool dotext = True, dohilite = True, dosel = True; - const char *text = (item->ulabel()) ? *item->ulabel() : item->label(); + 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); int hilite_x = item_x, hilite_y = item_y, hoff_x = 0, hoff_y = 0;
M src/Basemenu.hhsrc/Basemenu.hh

@@ -22,12 +22,14 @@ // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING

// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER // DEALINGS IN THE SOFTWARE. -// $Id: Basemenu.hh,v 1.5 2002/02/04 22:33:09 fluxgen Exp $ +// $Id: Basemenu.hh,v 1.6 2002/02/08 13:20:23 fluxgen Exp $ #ifndef _BASEMENU_HH_ #define _BASEMENU_HH_ #include <X11/Xlib.h> +#include <vector> +#include <string> // forward declarations class Basemenu;

@@ -36,8 +38,6 @@

class Fluxbox; class BImageControl; class BScreen; - -#include <vector> class Basemenu { private:

@@ -139,55 +139,46 @@ enum { EMPTY = 0, SQUARE, TRIANGLE, DIAMOND };

}; - class BasemenuItem { -private: - Basemenu *s; - const char **u, *l, *e; - int f, enabled, selected; +public: + BasemenuItem( + const char *label, + int function, + const char *exec = (const char *) 0) + : m_label(label ? label : "") + , m_exec(exec ? exec : "") + , m_submenu(0) + , m_function(function) + , m_enabled(true) + , m_selected(false) + { } - friend class Basemenu; + BasemenuItem(const char *label, Basemenu *submenu) + : m_label(label ? label : "") + , m_exec("") + , m_submenu(submenu) + , m_function(0) + , m_enabled(true) + , m_selected(false) + { } -public: - BasemenuItem(const char *lp, int fp, const char *ep = (const char *) 0) { - l = lp; - e = ep; - s = 0; - f = fp; - u = 0; - enabled = 1; - selected = 0; - } + inline const char *exec(void) const { return m_exec.c_str(); } + inline const char *label(void) const { return m_label.c_str(); } + inline int function(void) const { return m_function; } + inline Basemenu *submenu(void) { return m_submenu; } - BasemenuItem(const char *lp, Basemenu *mp) { - l = lp; - s = mp; - e = 0; - f = 0; - u = 0; - enabled = 1; - selected = 0; - } - - BasemenuItem(const char **up, int fp) { - u = up; - l = e = 0; - f = fp; - s = 0; - enabled = 1; - selected = 0; - } + inline bool isEnabled(void) const { return m_enabled; } + inline void setEnabled(bool enabled) { m_enabled = enabled; } + inline bool isSelected(void) const { return m_selected; } + inline void setSelected(bool selected) { m_selected = selected; } - inline const char *exec(void) const { return e; } - inline const char *label(void) const { return l; } - inline const char **ulabel(void) const { return u; } - inline const int &function(void) const { return f; } - inline Basemenu *submenu(void) { return s; } +private: + std::string m_label, m_exec; + Basemenu *m_submenu; + int m_function; + bool m_enabled, m_selected; - inline const int &isEnabled(void) const { return enabled; } - inline void setEnabled(int e) { enabled = e; } - inline const int &isSelected(void) const { return selected; } - inline void setSelected(int s) { selected = s; } + friend class Basemenu; };