From dc05c262acae19bcefcad3f17479c5054cf0a938 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 2 May 2012 23:45:54 -0400 Subject: [PATCH] Refactor Tooltip's in Deskbar. Only update the tooltip if the mouse goes over a new menu item making sure to exit if the item is NULL, there is a visible label, or it is the same item. If the mouse moves outside the view reset the last item to NULL. * Rename DrawLabel() and SetDrawLabel() to HasLabel() and SetHasLabel() to make it clear what these methods are setting a getting and setting a bool and not doing the actual work for drawing the label. --- src/apps/deskbar/ExpandoMenuBar.cpp | 41 +++++++++++++++++++++++------ src/apps/deskbar/TeamMenuItem.cpp | 4 +-- src/apps/deskbar/TeamMenuItem.h | 4 +-- 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 00343741aa..593a7b0fa8 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -45,6 +45,7 @@ All rights reserved. #include #include #include +#include #include "BarApp.h" #include "BarMenuTitle.h" @@ -395,19 +396,43 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message) // force a cleanup _FinishedDrag(); - if (code == B_INSIDE_VIEW) { - TTeamMenuItem* item = TeamItemAtPoint(where); + switch (code) { + case B_ENTERED_VIEW: + case B_INSIDE_VIEW: + { + TTeamMenuItem* item = TeamItemAtPoint(where); + if (item == NULL) { + // item is NULL, break out + fLastMousedOverItem = NULL; + break; + } - if (item != NULL) { - if (!item->DrawLabel() && item != fLastMousedOverItem) { - // set the tooltip - SetToolTip(item->Name()); - } else + if (item->HasLabel()) { + // item has a visible label, set the item and break out fLastMousedOverItem = item; + break; + } + + if (item == fLastMousedOverItem) { + // already set the tooltip for this item, break out + break; + } + + // new item, update the tooltip with the item name + SetToolTip(item->Name()); + + // save the current item for the next MouseMoved() call + fLastMousedOverItem = item; + + break; } + + case B_OUTSIDE_VIEW: + case B_EXITED_VIEW: + fLastMousedOverItem = NULL; + break; } - fLastMousedOverItem = NULL; BMenuBar::MouseMoved(where, code, message); return; } diff --git a/src/apps/deskbar/TeamMenuItem.cpp b/src/apps/deskbar/TeamMenuItem.cpp index 43eeed0cc8..c98b455027 100644 --- a/src/apps/deskbar/TeamMenuItem.cpp +++ b/src/apps/deskbar/TeamMenuItem.cpp @@ -171,14 +171,14 @@ TTeamMenuItem::SetOverrideSelected(bool selected) bool -TTeamMenuItem::DrawLabel() const +TTeamMenuItem::HasLabel() const { return fDrawLabel; } void -TTeamMenuItem::SetDrawLabel(bool drawLabel) +TTeamMenuItem::SetHasLabel(bool drawLabel) { fDrawLabel = drawLabel; } diff --git a/src/apps/deskbar/TeamMenuItem.h b/src/apps/deskbar/TeamMenuItem.h index 1e242a91ec..9ae1ed1548 100644 --- a/src/apps/deskbar/TeamMenuItem.h +++ b/src/apps/deskbar/TeamMenuItem.h @@ -64,8 +64,8 @@ class TTeamMenuItem : public BMenuItem { void SetOverrideHeight(float height); void SetOverrideSelected(bool selected); - bool DrawLabel() const; - void SetDrawLabel(bool drawLabel); + bool HasLabel() const; + void SetHasLabel(bool drawLabel); bool IsExpanded(); void ToggleExpandState(bool resizeWindow);