screen.getVisual(), attrib_mask, &attrib);
openbox.saveMenuSearch(menu.frame, this);
- menuitems = new LinkedList<BasemenuItem>;
-
// even though this is the end of the constructor the menu is still not
// completely created. items must be inserted and it must be update()'d
}
if (shown && shown->getWindowID() == getWindowID())
shown = (Basemenu *) 0;
- int n = menuitems->count();
- for (int i = 0; i < n; ++i)
- remove(0);
-
- delete menuitems;
+ while (!menuitems.empty()) {
+ delete menuitems[0];
+ menuitems.erase(menuitems.begin());
+ }
if (menu.label)
delete [] menu.label;
if (e) exec = bstrdup(e);
BasemenuItem *item = new BasemenuItem(label, function, exec);
- menuitems->insert(item, pos);
+ if (pos == -1)
+ menuitems.push_back(item);
+ else
+ menuitems.insert(menuitems.begin() + pos, item);
- return menuitems->count();
+ return menuitems.size();
}
if (l) label = bstrdup(l);
BasemenuItem *item = new BasemenuItem(label, submenu);
- menuitems->insert(item, pos);
+ if (pos == -1)
+ menuitems.push_back(item);
+ else
+ menuitems.insert(menuitems.begin() + pos, item);
submenu->parent = this;
- return menuitems->count();
+ return menuitems.size();
}
int Basemenu::insert(const char **ulabel, int pos, int function) {
BasemenuItem *item = new BasemenuItem(ulabel, function);
- menuitems->insert(item, pos);
+ if (pos == -1)
+ menuitems.push_back(item);
+ else
+ menuitems.insert(menuitems.begin() + pos, item);
- return menuitems->count();
+ return menuitems.size();
}
int Basemenu::remove(int index) {
- if (index < 0 || index > menuitems->count()) return -1;
+ if (index < 0 || index > menuitems.size()) return -1;
- BasemenuItem *item = menuitems->remove(index);
+ BasemenuItem *item = menuitems[index];
+ menuitems.erase(menuitems.begin() + index);
if (item) {
- if ((! internal_menu) && (item->submenu())) {
+ if ((!internal_menu) && (item->submenu())) {
Basemenu *tmp = (Basemenu *) item->submenu();
if (! tmp->internal_menu) {
else if (which_sub > index)
which_sub--;
- return menuitems->count();
+ return menuitems.size();
}
}
int ii = 0;
- LinkedListIterator<BasemenuItem> it(menuitems);
- for (BasemenuItem *tmp = it.current(); tmp; it++, tmp = it.current()) {
- const char *s = ((tmp->u && *tmp->u) ? *tmp->u :
- ((tmp->l) ? tmp->l : (const char *) 0));
+ menuitemList::const_iterator it = menuitems.begin();
+ for (; it != menuitems.end(); it++) {
+ const char *s = (((*it)->u && *(*it)->u) ? *(*it)->u :
+ (((*it)->l) ? (*it)->l : (const char *) 0));
int l = strlen(s);
if (i18n->multibyte()) {
menu.item_w = ((menu.item_w < (unsigned int) ii) ? ii : menu.item_w);
}
- if (menuitems->count()) {
+ if (menuitems.size()) {
menu.sublevels = 1;
- while (((menu.item_h * (menuitems->count() + 1) / menu.sublevels)
+ while (((menu.item_h * (menuitems.size() + 1) / menu.sublevels)
+ menu.title_h + screen.getBorderWidth()) >
screen.size().h())
menu.sublevels++;
if (menu.sublevels < menu.minsub) menu.sublevels = menu.minsub;
- menu.persub = menuitems->count() / menu.sublevels;
- if (menuitems->count() % menu.sublevels) menu.persub++;
+ menu.persub = menuitems.size() / menu.sublevels;
+ if (menuitems.size() % menu.sublevels) menu.persub++;
} else {
menu.sublevels = 0;
menu.persub = 0;
if (title_vis && visible) redrawTitle();
- for (int i = 0; visible && i < menuitems->count(); i++) {
+ for (int i = 0; visible && i < menuitems.size(); i++) {
if (i == which_sub) {
drawItem(i, True, 0);
drawSubmenu(i);
void Basemenu::internal_hide(void) {
if (which_sub != -1) {
- BasemenuItem *tmp = menuitems->find(which_sub);
+ BasemenuItem *tmp = menuitems[which_sub];
tmp->submenu()->internal_hide();
}
void Basemenu::drawSubmenu(int index) {
if (which_sub != -1 && which_sub != index) {
- BasemenuItem *itmp = menuitems->find(which_sub);
+ BasemenuItem *itmp = menuitems[which_sub];
if (! itmp->submenu()->isTorn())
itmp->submenu()->internal_hide();
}
- if (index >= 0 && index < menuitems->count()) {
- BasemenuItem *item = menuitems->find(index);
+ if (index >= 0 && index < menuitems.size()) {
+ BasemenuItem *item = menuitems[index];
if (item->submenu() && visible && (! item->submenu()->isTorn()) &&
item->isEnabled()) {
if (item->submenu()->parent != this) item->submenu()->parent = this;
Bool Basemenu::hasSubmenu(int index) {
- if ((index >= 0) && (index < menuitems->count()))
- if (menuitems->find(index)->submenu())
+ if ((index >= 0) && (index < menuitems.size()))
+ if (menuitems[index]->submenu())
return True;
return False;
void Basemenu::drawItem(int index, Bool highlight, Bool clear,
int x, int y, unsigned int w, unsigned int h)
{
- if (index < 0 || index > menuitems->count()) return;
+ if (index < 0 || index > menuitems.size()) return;
- BasemenuItem *item = menuitems->find(index);
+ BasemenuItem *item = menuitems[index];
if (! item) return;
Bool dotext = True, dohilite = True, dosel = True;
void Basemenu::setItemSelected(int index, Bool sel) {
- if (index < 0 || index >= menuitems->count()) return;
+ if (index < 0 || index >= menuitems.size()) return;
BasemenuItem *item = find(index);
if (! item) return;
Bool Basemenu::isItemSelected(int index) {
- if (index < 0 || index >= menuitems->count()) return False;
+ if (index < 0 || index >= menuitems.size()) return False;
BasemenuItem *item = find(index);
if (! item) return False;
void Basemenu::setItemEnabled(int index, Bool enable) {
- if (index < 0 || index >= menuitems->count()) return;
+ if (index < 0 || index >= menuitems.size()) return;
BasemenuItem *item = find(index);
if (! item) return;
Bool Basemenu::isItemEnabled(int index) {
- if (index < 0 || index >= menuitems->count()) return False;
+ if (index < 0 || index >= menuitems.size()) return False;
BasemenuItem *item = find(index);
if (! item) return False;
int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h);
int w = (sbl * menu.persub) + i;
- if (w < menuitems->count() && w >= 0) {
+ if (w < menuitems.size() && w >= 0) {
which_press = i;
which_sbl = sbl;
- BasemenuItem *item = menuitems->find(w);
+ BasemenuItem *item = menuitems[w];
if (item->submenu())
drawSubmenu(w);
w = (sbl * menu.persub) + i,
p = (which_sbl * menu.persub) + which_press;
- if (w < menuitems->count() && w >= 0) {
+ if (w < menuitems.size() && w >= 0) {
drawItem(p, (p == which_sub), True);
if (p == w && isItemEnabled(w)) {
w = (sbl * menu.persub) + i;
if ((i != which_press || sbl != which_sbl) &&
- (w < menuitems->count() && w >= 0)) {
+ (w < menuitems.size() && w >= 0)) {
if (which_press != -1 && which_sbl != -1) {
int p = (which_sbl * menu.persub) + which_press;
- BasemenuItem *item = menuitems->find(p);
+ BasemenuItem *item = menuitems[p];
drawItem(p, False, True);
if (item->submenu())
which_press = i;
which_sbl = sbl;
- BasemenuItem *itmp = menuitems->find(w);
+ BasemenuItem *itmp = menuitems[w];
if (itmp->submenu())
drawSubmenu(w);
if (id_d > menu.persub) id_d = menu.persub;
// draw the sublevels and the number of items the exposure spans
- LinkedListIterator<BasemenuItem> it(menuitems);
+ menuitemList::const_iterator it = menuitems.begin();
int i, ii;
for (i = sbl; i <= sbl_d; i++) {
// set the iterator to the first item in the sublevel needing redrawing
- it.set(id + (i * menu.persub));
- for (ii = id; ii <= id_d && it.current(); it++, ii++) {
+ it = menuitems.begin() + (id + (i * menu.persub));
+ for (ii = id; ii <= id_d && it != menuitems.end(); it++, ii++) {
int index = ii + (i * menu.persub);
// redraw the item
drawItem(index, (which_sub == index), False,
XMoveWindow(display, menu.window, menu.x_shift, menu.y_shift);
if (which_sub != -1) {
- BasemenuItem *tmp = menuitems->find(which_sub);
+ BasemenuItem *tmp = menuitems[which_sub];
if (tmp->submenu()->isVisible()) {
int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h),
w = (sbl * menu.persub) + i;
void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) {
if (ce->window == menu.frame) {
- if (which_press != -1 && which_sbl != -1 && menuitems->count() > 0) {
+ if (which_press != -1 && which_sbl != -1 && menuitems.size() > 0) {
int p = (which_sbl * menu.persub) + which_press;
drawItem(p, (p == which_sub), True);