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.
This commit is contained in:
John Scipione
2012-05-02 23:45:54 -04:00
parent 1cd61330ec
commit dc05c262ac
3 changed files with 37 additions and 12 deletions
+33 -8
View File
@@ -45,6 +45,7 @@ All rights reserved.
#include <NodeInfo.h> #include <NodeInfo.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
#include <ToolTip.h>
#include "BarApp.h" #include "BarApp.h"
#include "BarMenuTitle.h" #include "BarMenuTitle.h"
@@ -395,19 +396,43 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
// force a cleanup // force a cleanup
_FinishedDrag(); _FinishedDrag();
if (code == B_INSIDE_VIEW) { switch (code) {
TTeamMenuItem* item = TeamItemAtPoint(where); 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->HasLabel()) {
if (!item->DrawLabel() && item != fLastMousedOverItem) { // item has a visible label, set the item and break out
// set the tooltip
SetToolTip(item->Name());
} else
fLastMousedOverItem = item; 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); BMenuBar::MouseMoved(where, code, message);
return; return;
} }
+2 -2
View File
@@ -171,14 +171,14 @@ TTeamMenuItem::SetOverrideSelected(bool selected)
bool bool
TTeamMenuItem::DrawLabel() const TTeamMenuItem::HasLabel() const
{ {
return fDrawLabel; return fDrawLabel;
} }
void void
TTeamMenuItem::SetDrawLabel(bool drawLabel) TTeamMenuItem::SetHasLabel(bool drawLabel)
{ {
fDrawLabel = drawLabel; fDrawLabel = drawLabel;
} }
+2 -2
View File
@@ -64,8 +64,8 @@ class TTeamMenuItem : public BMenuItem {
void SetOverrideHeight(float height); void SetOverrideHeight(float height);
void SetOverrideSelected(bool selected); void SetOverrideSelected(bool selected);
bool DrawLabel() const; bool HasLabel() const;
void SetDrawLabel(bool drawLabel); void SetHasLabel(bool drawLabel);
bool IsExpanded(); bool IsExpanded();
void ToggleExpandState(bool resizeWindow); void ToggleExpandState(bool resizeWindow);