]> Dogcows Code - chaz/openbox/blobdiff - src/Basemenu.cc
sync with the 2.0 branch
[chaz/openbox] / src / Basemenu.cc
index 7358df3c3a6c814791ed62416a4b67cf89d788f4..3556d00a9034bf30fecdf7c7176296f5bd69d197 100644 (file)
@@ -46,6 +46,7 @@ using namespace std;
 #include "i18n.hh"
 #include "blackbox.hh"
 #include "Basemenu.hh"
+#include "Font.hh"
 #include "GCCache.hh"
 #include "Image.hh"
 #include "Screen.hh"
@@ -83,34 +84,21 @@ Basemenu::Basemenu(BScreen *scrn) {
     which_press =
     which_sbl = -1;
 
+  menu.sublevels =
+    menu.persub =
+    menu.minsub = 0;
+
   menu.frame_pixmap =
     menu.title_pixmap =
-    menu.hilite_pixmap =
-    menu.sel_pixmap = None;
+    menu.hilite_pixmap = None;
 
   menu.bevel_w = screen->getBevelWidth();
 
-  if (i18n.multibyte())
-    menu.width = menu.title_h = menu.item_w = menu.frame_h =
-      screen->getMenuStyle()->t_fontset_extents->max_ink_extent.height +
-      (menu.bevel_w  * 2);
-  else
-    menu.width = menu.title_h = menu.item_w = menu.frame_h =
-      screen->getMenuStyle()->t_font->ascent +
-      screen->getMenuStyle()->t_font->descent + (menu.bevel_w * 2);
-
-  menu.sublevels =
-    menu.persub =
-    menu.minsub = 0;
+  const MenuStyle* const style = screen->getMenuStyle();
+  menu.width = menu.title_h = menu.item_w = menu.frame_h =
+    style->t_font->height() + (menu.bevel_w  * 2);
 
-  MenuStyle *style = screen->getMenuStyle();
-  if (i18n.multibyte()) {
-    menu.item_h = style->f_fontset_extents->max_ink_extent.height +
-      (menu.bevel_w);
-  } else {
-    menu.item_h = style->f_font->ascent + style->f_font->descent +
-      (menu.bevel_w);
-  }
+  menu.item_h = style->f_font->height() + menu.bevel_w;
 
   menu.height = menu.title_h + screen->getBorderWidth() + menu.frame_h;
 
@@ -154,26 +142,25 @@ Basemenu::Basemenu(BScreen *scrn) {
   // completely created.  items must be inserted and it must be update()'d
 }
 
+
 Basemenu::~Basemenu(void) {
   XUnmapWindow(display, menu.window);
 
   if (shown && shown->getWindowID() == getWindowID())
     shown = (Basemenu *) 0;
 
-  MenuItems::const_iterator it = menuitems.begin();
-  while (it != menuitems.end()) {
-    BasemenuItem *item = *it;
-    if ((! internal_menu)) {
-      Basemenu *tmp = (Basemenu *) item->submenu();
+  MenuItems::const_iterator it = menuitems.begin(),
+    end = menuitems.end();
+  for (; it != end; ++it) {
+    if (! internal_menu) {
+      Basemenu *tmp = (*it)->submenu();
       if (tmp) {
-        if (! tmp->internal_menu) {
+        if (! tmp->internal_menu)
           delete tmp;
-        } else {
+        else
           tmp->internal_hide();
-        }
       }
     }
-    ++it;
   }
 
   std::for_each(menuitems.begin(), menuitems.end(), PointerAssassin());
@@ -187,9 +174,6 @@ Basemenu::~Basemenu(void) {
   if (menu.hilite_pixmap)
     image_ctrl->removeImage(menu.hilite_pixmap);
 
-  if (menu.sel_pixmap)
-    image_ctrl->removeImage(menu.sel_pixmap);
-
   blackbox->removeMenuSearch(menu.title);
   XDestroyWindow(display, menu.title);
 
@@ -213,7 +197,7 @@ int Basemenu::insert(BasemenuItem *item, int pos) {
   if (pos < 0) {
     menuitems.push_back(item);
   } else {
-    assert(pos < static_cast<signed>(menuitems.size()));
+    assert(pos <= static_cast<signed>(menuitems.size()));
     menuitems.insert((menuitems.begin() + pos), item);
   }
   return menuitems.size();
@@ -239,14 +223,13 @@ int Basemenu::remove(int index) {
   BasemenuItem *item = find(index);
   if (! item) return -1;
 
-  if ((! internal_menu)) {
-    Basemenu *tmp = (Basemenu *) item->submenu();
+  if (! internal_menu) {
+    Basemenu *tmp = item->submenu();
     if (tmp) {
-      if (! tmp->internal_menu) {
+      if (! tmp->internal_menu)
         delete tmp;
-      } else {
+      else
         tmp->internal_hide();
-      }
     }
   }
 
@@ -264,32 +247,14 @@ int Basemenu::remove(int index) {
 
 
 void Basemenu::update(void) {
-  MenuStyle *style = screen->getMenuStyle();
-  if (i18n.multibyte()) {
-    menu.item_h = style->f_fontset_extents->max_ink_extent.height +
-      menu.bevel_w;
-    menu.title_h = style->t_fontset_extents->max_ink_extent.height +
-      (menu.bevel_w * 2);
-  } else {
-    menu.item_h = style->f_font->ascent + style->f_font->descent +
-      menu.bevel_w;
-    menu.title_h = style->t_font->ascent + style->t_font->descent +
-      (menu.bevel_w * 2);
-  }
+  const MenuStyle* const style = screen->getMenuStyle();
+  menu.item_h = (style->f_font->height() < 9 ? 9 : style->f_font->height()) +
+                menu.bevel_w;  // 9 for the menu pixmaps (checkmarks)
+  menu.title_h = style->t_font->height() + menu.bevel_w * 2;
 
   if (title_vis) {
-    const char *s = getLabel();
-    int l = strlen(s);
-
-    if (i18n.multibyte()) {
-      XRectangle ink, logical;
-      XmbTextExtents(screen->getMenuStyle()->t_fontset, s, l, &ink, &logical);
-      menu.item_w = logical.width;
-    } else {
-      menu.item_w = XTextWidth(screen->getMenuStyle()->t_font, s, l);
-    }
-
-    menu.item_w += (menu.bevel_w * 2);
+    menu.item_w = screen->getMenuStyle()->t_font->measureString(menu.label) +
+      menu.bevel_w * 2;
   }  else {
     menu.item_w = 1;
   }
@@ -297,18 +262,8 @@ void Basemenu::update(void) {
   unsigned int ii = 0;
   MenuItems::iterator it = menuitems.begin(), end = menuitems.end();
   for (; it != end; ++it) {
-    BasemenuItem *tmp = *it;
-    const char *s = tmp->l.c_str();
-    int l = strlen(s);
-
-    if (i18n.multibyte()) {
-      XRectangle ink, logical;
-      XmbTextExtents(screen->getMenuStyle()->f_fontset, s, l, &ink, &logical);
-      ii = logical.width;
-    } else
-      ii = XTextWidth(screen->getMenuStyle()->f_font, s, l);
-
-    ii += (menu.bevel_w * 2) + (menu.item_h * 2);
+    ii = screen->getMenuStyle()->f_font->measureString((*it)->l) +
+      (menu.bevel_w * 2) + (menu.item_h * 2);
 
     menu.item_w = ((menu.item_w < ii) ? ii : menu.item_w);
   }
@@ -316,7 +271,7 @@ void Basemenu::update(void) {
   if (! menuitems.empty()) {
     menu.sublevels = 1;
 
-    unsigned int menu_size = menuitems.size();
+    const unsigned int menu_size = menuitems.size();
     while (((menu.item_h * (menu_size + 1) / menu.sublevels)
             + menu.title_h + screen->getBorderWidth()) >
            screen->getHeight())
@@ -381,16 +336,6 @@ void Basemenu::update(void) {
   }
   if (tmp) image_ctrl->removeImage(tmp);
 
-  tmp = menu.sel_pixmap;
-  if (texture->texture() == (BTexture::Flat | BTexture::Solid)) {
-    menu.sel_pixmap = None;
-  } else {
-    int hw = menu.item_h / 2;
-    menu.sel_pixmap =
-      image_ctrl->renderImage(hw, hw, *texture);
-  }
-  if (tmp) image_ctrl->removeImage(tmp);
-
   XResizeWindow(display, menu.window, menu.width, menu.height);
 
   if (title_vis)
@@ -439,10 +384,10 @@ void Basemenu::show(void) {
 
 
 void Basemenu::hide(void) {
-  if ((! torn) && hide_tree && parent && parent->isVisible()) {
+  if (! torn && hide_tree && parent && parent->isVisible()) {
     Basemenu *p = parent;
 
-    while (p->isVisible() && (! p->torn) && p->parent) p = p->parent;
+    while (p->isVisible() && ! p->torn && p->parent) p = p->parent;
     p->internal_hide();
   } else {
     internal_hide();
@@ -455,7 +400,7 @@ void Basemenu::internal_hide(void) {
   if (tmp)
     tmp->submenu()->internal_hide();
 
-  if (parent && (! torn)) {
+  if (parent && ! torn) {
     parent->drawItem(parent->which_sub, False, True);
 
     parent->which_sub = -1;
@@ -482,19 +427,11 @@ void Basemenu::move(int x, int y) {
 void Basemenu::redrawTitle(void) {
   const char *text = (! menu.label.empty()) ? getLabel() :
     i18n(BasemenuSet, BasemenuBlackboxMenu, "Blackbox Menu");
-  int dx = menu.bevel_w, len = strlen(text);
+  int dx = menu.bevel_w;
   unsigned int l;
+  const MenuStyle* const style = screen->getMenuStyle();
 
-  if (i18n.multibyte()) {
-    XRectangle ink, logical;
-    XmbTextExtents(screen->getMenuStyle()->t_fontset, text, len,
-                   &ink, &logical);
-    l = logical.width;
-  } else {
-    l = XTextWidth(screen->getMenuStyle()->t_font, text, len);
-  }
-
-  l +=  (menu.bevel_w * 2);
+  l = style->t_font->measureString(text) + menu.bevel_w * 2;
 
   switch (screen->getMenuStyle()->t_justify) {
   case RightJustify:
@@ -510,15 +447,8 @@ void Basemenu::redrawTitle(void) {
     break;
   }
 
-  MenuStyle *style = screen->getMenuStyle();
-  BPen pen(style->t_text, style->t_font);
-  if (i18n.multibyte())
-    XmbDrawString(display, menu.title, style->t_fontset, pen.gc(), dx,
-                  (menu.bevel_w - style->t_fontset_extents->max_ink_extent.y),
-                  text, len);
-  else
-    XDrawString(display, menu.title, pen.gc(), dx,
-                (style->t_font->ascent + menu.bevel_w), text, len);
+  style->t_font->drawString(menu.title, dx, menu.bevel_w,
+                            style->t_text, text);
 }
 
 
@@ -531,12 +461,13 @@ void Basemenu::drawSubmenu(int index) {
   item = find(index);
   if (! item)
     return;
+
   Basemenu *submenu = item->submenu();
 
   if (submenu && visible && ! submenu->isTorn() && item->isEnabled()) {
     if (submenu->parent != this) submenu->parent = this;
-    int sbl = index / menu.persub, i = index - (sbl * menu.persub),
-      x = menu.x + ((menu.item_w * (sbl + 1)) + screen->getBorderWidth()), y;
+    const int sbl = index / menu.persub, i = index - (sbl * menu.persub);
+    int x = menu.x + ((menu.item_w * (sbl + 1)) + screen->getBorderWidth()), y;
 
     if (alignment == AlignTop) {
       y = (((shifted) ? menu.y_shift : menu.y) +
@@ -594,30 +525,19 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
   BasemenuItem *item = find(index);
   if (! item) return;
 
-  bool dotext = True, dohilite = True, dosel = True;
+  bool dotext = True, dohilite = True, dosel = True, dooppsel = True;
   const char *text = item->label();
-  int sbl = index / menu.persub, i = index - (sbl * menu.persub);
+  const int sbl = index / menu.persub, i = index - (sbl * menu.persub);
+  const unsigned int half_w = menu.item_h / 2, quarter_w = menu.item_h / 4;
   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;
-  int text_x = 0, text_y = 0, len = strlen(text), sel_x = 0, sel_y = 0;
+  int text_x = 0, text_y = 0, sel_x = 0, oppsel_x = 0, sel_y = 0;
   unsigned int hilite_w = menu.item_w, hilite_h = menu.item_h, text_w = 0,
     text_h = 0;
-  unsigned int half_w = menu.item_h / 2, quarter_w = menu.item_h / 4;
 
   if (text) {
-    if (i18n.multibyte()) {
-      XRectangle ink, logical;
-      XmbTextExtents(screen->getMenuStyle()->f_fontset,
-                     text, len, &ink, &logical);
-      text_w = logical.width;
-      text_y = item_y + (menu.bevel_w / 2) -
-        screen->getMenuStyle()->f_fontset_extents->max_ink_extent.y;
-    } else {
-      text_w = XTextWidth(screen->getMenuStyle()->f_font, text, len);
-      text_y =  item_y +
-        screen->getMenuStyle()->f_font->ascent +
-        (menu.bevel_w / 2);
-    }
+    text_w = screen->getMenuStyle()->f_font->measureString(text);
+    text_y = item_y + menu.bevel_w / 2;
 
     switch(screen->getMenuStyle()->f_justify) {
     case LeftJustify:
@@ -636,17 +556,23 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
     text_h = menu.item_h - menu.bevel_w;
   }
 
-  MenuStyle *style = screen->getMenuStyle();
-  BPen pen((highlight || item->isSelected()) ? style->h_text : style->f_text),
-      textpen((highlight) ? style->h_text :
-              item->isEnabled() ? style->f_text : style->d_text, style->f_font),
-      hipen(style->hilite.color());
+  const MenuStyle* const style = screen->getMenuStyle();
+  const BPen hipen(style->hilite.color());
+  // match the text color
+  const BPen pen((highlight ? style->h_text :
+                  (item->isEnabled() ? style->f_text :
+                   style->d_text)));
 
 
   sel_x = item_x;
   if (screen->getMenuStyle()->bullet_pos == Right)
     sel_x += (menu.item_w - menu.item_h - menu.bevel_w);
   sel_x += quarter_w;
+  oppsel_x = sel_x;
+  if (screen->getMenuStyle()->bullet_pos == Right)
+    oppsel_x -= (menu.item_w - menu.item_h - menu.bevel_w);
+  else
+    oppsel_x += (menu.item_w - menu.item_h - menu.bevel_w);
   sel_y = item_y + quarter_w;
 
   if (clear) {
@@ -667,7 +593,7 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
     }
 
     // check if we need to redraw the text
-    int text_ry = item_y + (menu.bevel_w / 2);
+    const int text_ry = item_y + (menu.bevel_w / 2);
     if (! (max(text_x, x) <= min<signed>(text_x + text_w, x + w) &&
            max(text_ry, y) <= min<signed>(text_ry + text_h, y + h)))
       dotext = False;
@@ -676,6 +602,12 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
     if (! (max(sel_x, x) <= min<signed>(sel_x + half_w, x + w) &&
            max(sel_y, y) <= min<signed>(sel_y + half_w, y + h)))
       dosel = False;
+    
+    // check if we need to redraw the select pixmap/menu bullet
+    // on the opposite side of the menu
+    if (! (max(oppsel_x, x) <= min<signed>(oppsel_x + half_w, x + w) &&
+           max(sel_y, y) <= min<signed>(sel_y + half_w, y + h)))
+      dooppsel = False;
   }
 
   if (dohilite && highlight && (menu.hilite_pixmap != ParentRelative)) {
@@ -686,46 +618,68 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
     else
       XFillRectangle(display, menu.frame, hipen.gc(),
                      hilite_x, hilite_y, hilite_w, hilite_h);
-  } else if (dosel && item->isSelected() &&
-             (menu.sel_pixmap != ParentRelative)) {
-    if (menu.sel_pixmap)
-      XCopyArea(display, menu.sel_pixmap, menu.frame, hipen.gc(), 0, 0,
-                half_w, half_w, sel_x, sel_y);
-    else
-      XFillRectangle(display, menu.frame, hipen.gc(), sel_x, sel_y, half_w, half_w);
+  }
+  
+  if (dooppsel && item->isSelected()) {
+      XPoint pts[6];
+
+      pts[0].x = oppsel_x + 0;
+      pts[0].y = sel_y + 2;
+      
+      pts[1].x = 0;
+      pts[1].y = 3;
+      
+      pts[2].x = 2;
+      pts[2].y = 3;
+      
+      pts[3].x = 5;
+      pts[3].y = -5;
+      
+      
+      pts[4].x = 0;
+      pts[4].y = -3;
+      
+      pts[5].x = -5;
+      pts[5].y = 5;
+
+      XFillPolygon(display, menu.frame, pen.gc(), pts, 6, Nonconvex,
+                   CoordModePrevious);
   }
 
   if (dotext && text) {
-    if (i18n.multibyte())
-      XmbDrawString(display, menu.frame, screen->getMenuStyle()->f_fontset,
-                    textpen.gc(), text_x, text_y, text, len);
-    else
-      XDrawString(display, menu.frame, textpen.gc(), text_x, text_y, text, len);
+    style->f_font->drawString(menu.frame, text_x, text_y,
+                              (highlight ? style->h_text :
+                               (item->isEnabled() ? style->f_text :
+                                style->d_text)),
+                              text);
   }
 
   if (dosel && item->submenu()) {
+    const int bullet_size = 3;
+
     switch (screen->getMenuStyle()->bullet) {
     case Square:
-      XDrawRectangle(display, menu.frame, pen.gc(), sel_x, sel_y, half_w, half_w);
+      XDrawRectangle(display, menu.frame, pen.gc(), sel_x, sel_y,
+                     bullet_size * 2, bullet_size * 2);
       break;
 
     case Triangle:
       XPoint tri[3];
 
       if (screen->getMenuStyle()->bullet_pos == Right) {
-        tri[0].x = sel_x + quarter_w - 2;
-        tri[0].y = sel_y + quarter_w - 2;
-        tri[1].x = 4;
-        tri[1].y = 2;
-        tri[2].x = -4;
-        tri[2].y = 2;
+        tri[0].x = sel_x + quarter_w - bullet_size;
+        tri[0].y = sel_y + quarter_w - bullet_size;
+        tri[1].x = 2 * bullet_size;
+        tri[1].y = bullet_size;
+        tri[2].x = -(2 * bullet_size);
+        tri[2].y = bullet_size;
       } else {
-        tri[0].x = sel_x + quarter_w - 2;
+        tri[0].x = sel_x + quarter_w - bullet_size;
         tri[0].y = item_y + half_w;
-        tri[1].x = 4;
-        tri[1].y = 2;
+        tri[1].x = 2 * bullet_size;
+        tri[1].y = bullet_size;
         tri[2].x = 0;
-        tri[2].y = -4;
+        tri[2].y = -(2 * bullet_size);
       }
 
       XFillPolygon(display, menu.frame, pen.gc(), tri, 3, Convex,
@@ -735,14 +689,14 @@ void Basemenu::drawItem(int index, bool highlight, bool clear,
     case Diamond:
       XPoint dia[4];
 
-      dia[0].x = sel_x + quarter_w - 3;
+      dia[0].x = sel_x + quarter_w - bullet_size;
       dia[0].y = item_y + half_w;
-      dia[1].x = 3;
-      dia[1].y = -3;
-      dia[2].x = 3;
-      dia[2].y = 3;
-      dia[3].x = -3;
-      dia[3].y = 3;
+      dia[1].x = bullet_size;
+      dia[1].y = -bullet_size;
+      dia[2].x = bullet_size;
+      dia[2].y = bullet_size;
+      dia[3].x = -bullet_size;
+      dia[3].y = bullet_size;
 
       XFillPolygon(display, menu.frame, pen.gc(), dia, 4, Convex,
                    CoordModePrevious);
@@ -797,9 +751,9 @@ bool Basemenu::isItemEnabled(int index) {
 
 void Basemenu::buttonPressEvent(XButtonEvent *be) {
   if (be->window == menu.frame) {
-    int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h);
-    int w = (sbl * menu.persub) + i;
-
+    const int sbl = (be->x / menu.item_w), i = (be->y / menu.item_h),
+      w = (sbl * menu.persub) + i;
+    
     BasemenuItem *item = find(w);
     if (item) {
       which_press = i;
@@ -837,7 +791,7 @@ void Basemenu::buttonReleaseEvent(XButtonEvent *re) {
     if (re->button == 3) {
       hide();
     } else {
-      int sbl = (re->x / menu.item_w), i = (re->y / menu.item_h),
+      const int sbl = (re->x / menu.item_w), i = (re->y / menu.item_h),
         ix = sbl * menu.item_w, iy = i * menu.item_h,
         w = (sbl * menu.persub) + i,
         p = (which_sbl * menu.persub) + which_press;
@@ -863,7 +817,7 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) {
   if (me->window == menu.title && (me->state & Button1Mask)) {
     if (movable) {
       if (! moving) {
-        if (parent && (! torn)) {
+        if (parent && ! torn) {
           parent->drawItem(parent->which_sub, False, True);
           parent->which_sub = -1;
         }
@@ -882,32 +836,34 @@ void Basemenu::motionNotifyEvent(XMotionEvent *me) {
           drawSubmenu(which_sub);
       }
     }
-  } else if ((! (me->state & Button1Mask)) && me->window == menu.frame &&
+  } else if (me->window == menu.frame &&
              me->x >= 0 && me->x < static_cast<signed>(menu.width) &&
              me->y >= 0 && me->y < static_cast<signed>(menu.frame_h)) {
-    int sbl = (me->x / menu.item_w), i = (me->y / menu.item_h),
+    const int sbl = (me->x / menu.item_w), i = (me->y / menu.item_h),
       w = (sbl * menu.persub) + i;
 
     if ((i != which_press || sbl != which_sbl) &&
         (w >= 0 && w < static_cast<signed>(menuitems.size()))) {
       if (which_press != -1 && which_sbl != -1) {
-        int p = (which_sbl * menu.persub) + which_press;
+        const int p = (which_sbl * menu.persub) + which_press;
         BasemenuItem *item = find(p);
+        if (! item) return;
 
         drawItem(p, False, True);
-        if (item->submenu())
-          if (item->submenu()->isVisible() &&
-              (! item->submenu()->isTorn())) {
-            item->submenu()->internal_hide();
-            which_sub = -1;
-          }
+        if (item->submenu() &&
+            item->submenu()->isVisible() &&
+            ! item->submenu()->isTorn()) {
+          item->submenu()->internal_hide();
+          which_sub = -1;
+        }
       }
 
       which_press = i;
       which_sbl = sbl;
 
       BasemenuItem *itmp = find(w);
-
+      if (! itmp) return;
+      
       if (itmp->submenu())
         drawSubmenu(w);
       else
@@ -921,27 +877,26 @@ void Basemenu::exposeEvent(XExposeEvent *ee) {
   if (ee->window == menu.title) {
     redrawTitle();
   } else if (ee->window == menu.frame) {
-    // this is a compilicated algorithm... lets do it step by step...
+    // this is a complicated algorithm... lets do it step by step...
     // first... we see in which sub level the expose starts... and how many
     // items down in that sublevel
 
-    int sbl = (ee->x / menu.item_w), id = (ee->y / menu.item_h),
+    const int sbl = (ee->x / menu.item_w), id = (ee->y / menu.item_h),
       // next... figure out how many sublevels over the redraw spans
-      sbl_d = ((ee->x + ee->width) / menu.item_w),
+      sbl_d = ((ee->x + ee->width) / menu.item_w);
       // then we see how many items down to redraw
-      id_d = ((ee->y + ee->height) / menu.item_h);
+    int id_d = ((ee->y + ee->height) / menu.item_h);
 
     if (id_d > menu.persub) id_d = menu.persub;
 
     // draw the sublevels and the number of items the exposure spans
     MenuItems::iterator it,
       end = menuitems.end();
-    int i, ii;
-    for (i = sbl; i <= sbl_d; i++) {
+    for (int i = sbl; i <= sbl_d; i++) {
       // set the iterator to the first item in the sublevel needing redrawing
       it = menuitems.begin() + (id + (i * menu.persub));
-      for (ii = id; ii <= id_d && it != end; ++it, ii++) {
-        int index = ii + (i * menu.persub);
+      for (int ii = id; ii <= id_d && it != end; ++it, ii++) {
+        const int index = ii + (i * menu.persub);
         // redraw the item
         drawItem(index, (which_sub == index), False,
                  ee->x, ee->y, ee->width, ee->height);
@@ -978,10 +933,10 @@ void Basemenu::enterNotifyEvent(XCrossingEvent *ce) {
     if (which_sub != -1) {
       BasemenuItem *tmp = find(which_sub);
       if (tmp->submenu()->isVisible()) {
-        int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h),
+        const int sbl = (ce->x / menu.item_w), i = (ce->y / menu.item_h),
           w = (sbl * menu.persub) + i;
 
-        if (w != which_sub && (! tmp->submenu()->isTorn())) {
+        if (w != which_sub && ! tmp->submenu()->isTorn()) {
           tmp->submenu()->internal_hide();
 
           drawItem(which_sub, False, True);
@@ -996,7 +951,7 @@ void Basemenu::enterNotifyEvent(XCrossingEvent *ce) {
 void Basemenu::leaveNotifyEvent(XCrossingEvent *ce) {
   if (ce->window == menu.frame) {
     if (which_press != -1 && which_sbl != -1 && menuitems.size() > 0) {
-      int p = (which_sbl * menu.persub) + which_press;
+      const int p = (which_sbl * menu.persub) + which_press;
 
       drawItem(p, (p == which_sub), True);
 
@@ -1027,6 +982,6 @@ void Basemenu::reconfigure(void) {
 
 void Basemenu::changeItemLabel(unsigned int index, const string& label) {
   BasemenuItem *item = find(index);
-  assert(item);
-  item->newLabel(label);
+  if (item)
+    item->newLabel(label);
 }
This page took 0.036708 seconds and 4 git commands to generate.