Set a tooltip with the application name if hidden.

If Deskbar is set to hide application names show the application
name as a tooltip when you hover your mouse over the item.

* Style fixes.
* Save CountItems() into a variable outside the loop so that it only
  gets called once (micro-optimization/best-practice).
* Convert a for loop to a while loop that wasn't really being used
  used as a for loop anyway, the variables are declared and used
  outside the loop.
This commit is contained in:
John Scipione 2012-04-23 23:44:54 -04:00
parent 2ec676a4e8
commit 1f0c9f183e
4 changed files with 30 additions and 9 deletions

View File

@ -721,7 +721,7 @@ TBarView::DragStart()
if (fLastDragItem)
init_tracking_hook(fLastDragItem, NULL, NULL);
if (item) {
if (item != NULL) {
if (item == fLastDragItem)
return B_OK;

View File

@ -100,7 +100,7 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name,
float maxContentWidth = sMinimumWindowWidth + iconSize
- kMinimumIconSize;
SetMaxContentWidth(maxContentWidth);
}
}
}
@ -390,18 +390,27 @@ TExpandoMenuBar::MouseDown(BPoint where)
void
TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
{
if (!message) {
if (message == NULL) {
// force a cleanup
_FinishedDrag();
if (code == B_INSIDE_VIEW) {
// set the tooltip
TTeamMenuItem* item = TeamItemAtPoint(where);
if (item != NULL && !item->DrawLabel() && item->Name() != '\0')
SetToolTip(item->Name());
}
BMenuBar::MouseMoved(where, code, message);
return;
}
uint32 buttons;
if (!(Window()->CurrentMessage())
if (Window()->CurrentMessage() == NULL
|| Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons)
< B_OK)
< B_OK) {
buttons = 0;
}
if (buttons == 0)
return;
@ -426,7 +435,8 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
case B_INSIDE_VIEW:
if (fBarView->Dragging()) {
TTeamMenuItem* item = NULL;
for (int32 i = 0; i < CountItems(); i++) {
int32 itemCount = CountItems();
for (int32 i = 0; i < itemCount; i++) {
BMenuItem* _item = ItemAt(i);
if (_item->Frame().Contains(where)) {
item = dynamic_cast<TTeamMenuItem*>(_item);
@ -552,16 +562,18 @@ TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name,
firstApp++;
}
int32 count = CountItems(), i;
for (i = firstApp; i < count; i++) {
int32 i = firstApp;
int32 itemCount = CountItems();
while (i < itemCount) {
teamItem = dynamic_cast<TTeamMenuItem*>(ItemAt(i));
if (teamItem != NULL && strcasecmp(teamItem->Name(), name) > 0) {
AddItem(item, i);
break;
}
i++;
}
// was the item added to the list yet?
if (i == count)
if (i == itemCount)
AddItem(item);
} else
AddItem(item);

View File

@ -170,6 +170,13 @@ TTeamMenuItem::SetOverrideSelected(bool selected)
}
bool
TTeamMenuItem::DrawLabel() const
{
return fDrawLabel;
}
void
TTeamMenuItem::SetDrawLabel(bool drawLabel)
{

View File

@ -62,6 +62,8 @@ class TTeamMenuItem : public BMenuItem {
void SetOverrideWidth(float width);
void SetOverrideHeight(float height);
void SetOverrideSelected(bool selected);
bool DrawLabel() const;
void SetDrawLabel(bool drawLabel);
bool IsExpanded();