back to stl vector
This commit is contained in:
parent
bac6c2ddb5
commit
fa46eaeeaa
2 changed files with 45 additions and 68 deletions
|
@ -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.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 @@ Basemenu::~Basemenu(void) {
|
|||
}
|
||||
|
||||
|
||||
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 @@ int Basemenu::insert(const char *l, int function, const char *e, int pos) {
|
|||
}
|
||||
|
||||
|
||||
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 *l, Basemenu *submenu, int pos) {
|
|||
|
||||
|
||||
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 @@ int Basemenu::remove(int index) {
|
|||
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 @@ void Basemenu::update(void) {
|
|||
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 @@ void Basemenu::drawItem(int index, Bool highlight, Bool clear,
|
|||
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;
|
||||
|
|
|
@ -22,12 +22,14 @@
|
|||
// 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;
|
||||
|
@ -37,8 +39,6 @@ class Fluxbox;
|
|||
class BImageControl;
|
||||
class BScreen;
|
||||
|
||||
#include <vector>
|
||||
|
||||
class Basemenu {
|
||||
private:
|
||||
typedef std::vector<BasemenuItem *> Menuitems;
|
||||
|
@ -139,55 +139,46 @@ public:
|
|||
|
||||
};
|
||||
|
||||
|
||||
class BasemenuItem {
|
||||
private:
|
||||
Basemenu *s;
|
||||
const char **u, *l, *e;
|
||||
int f, enabled, selected;
|
||||
|
||||
friend class Basemenu;
|
||||
|
||||
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;
|
||||
}
|
||||
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)
|
||||
{ }
|
||||
|
||||
BasemenuItem(const char *lp, Basemenu *mp) {
|
||||
l = lp;
|
||||
s = mp;
|
||||
e = 0;
|
||||
f = 0;
|
||||
u = 0;
|
||||
enabled = 1;
|
||||
selected = 0;
|
||||
}
|
||||
BasemenuItem(const char *label, Basemenu *submenu)
|
||||
: m_label(label ? label : "")
|
||||
, m_exec("")
|
||||
, m_submenu(submenu)
|
||||
, m_function(0)
|
||||
, m_enabled(true)
|
||||
, m_selected(false)
|
||||
{ }
|
||||
|
||||
BasemenuItem(const char **up, int fp) {
|
||||
u = up;
|
||||
l = e = 0;
|
||||
f = fp;
|
||||
s = 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; }
|
||||
|
||||
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; }
|
||||
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 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; }
|
||||
private:
|
||||
std::string m_label, m_exec;
|
||||
Basemenu *m_submenu;
|
||||
int m_function;
|
||||
bool m_enabled, m_selected;
|
||||
|
||||
friend class Basemenu;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue