Deskbar: Remove Name() and fName, replace with Label()

... from TeamMenuItem and WindowMenuItem.

It was confusing having Name(), Label(), and TruncatedLabel().

Name() == Label() because Label() never changes, the displayed
Label stored in TruncatedLabel() in both TeamWindowItem and
WindowMenuItem (remember they both inherit from
TruncatableMenuItem so they get that for free). So Name() was
redundant, by getting rid of it there is just Label() and TruncatedLabel()
which is all we need!
This commit is contained in:
John Scipione
2015-02-19 20:45:46 -05:00
parent ae181f353b
commit c38afcd62c
6 changed files with 31 additions and 36 deletions
+8 -8
View File
@@ -367,10 +367,10 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
&& fBarView->ExpandoState() && item->IsExpanded()) {
// expando mode window menu item
fLastMousedOverItem = menuItem;
if (strcasecmp(windowMenuItem->Label(),
windowMenuItem->Name()) > 0) {
if (strcasecmp(windowMenuItem->TruncatedLabel(),
windowMenuItem->Label()) > 0) {
// label is truncated, set tooltip
SetToolTip(windowMenuItem->Name());
SetToolTip(windowMenuItem->Label());
} else
SetToolTip((const char*)NULL);
@@ -380,17 +380,17 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
if (!dynamic_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
// item has a visible label, set tool tip if truncated
fLastMousedOverItem = menuItem;
if (strcasecmp(item->Label(), item->Name()) > 0) {
if (strcasecmp(item->TruncatedLabel(), item->Label()) > 0) {
// label is truncated, set tooltip
SetToolTip(item->Name());
SetToolTip(item->Label());
} else
SetToolTip((const char*)NULL);
break;
}
SetToolTip(item->Name());
// new item, set the tooltip to the item name
SetToolTip(item->Label());
// new item, set the tooltip to the item label
fLastMousedOverItem = menuItem;
// save the current menuitem for the next MouseMoved() call
break;
@@ -639,7 +639,7 @@ TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name,
int32 itemCount = CountItems();
while (i < itemCount) {
teamItem = dynamic_cast<TTeamMenuItem*>(ItemAt(i));
if (teamItem != NULL && strcasecmp(teamItem->Name(), name) > 0) {
if (teamItem != NULL && strcasecmp(teamItem->Label(), name) > 0) {
AddItem(item, i);
break;
}
+11 -11
View File
@@ -89,7 +89,6 @@ TTeamMenuItem::~TTeamMenuItem()
{
delete fTeam;
delete fIcon;
free(fName);
free(fSignature);
}
@@ -418,27 +417,28 @@ TTeamMenuItem::_Init(BList* team, BBitmap* icon, char* name, char* signature,
{
fTeam = team;
fIcon = icon;
fName = name;
fSignature = signature;
if (fName == NULL) {
if (name == NULL) {
char temp[32];
snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0));
fName = strdup(temp);
name = strdup(temp);
}
BFont font(be_plain_font);
fLabelWidth = ceilf(font.StringWidth(fName));
font_height fontHeight;
font.GetHeight(&fontHeight);
fLabelAscent = ceilf(fontHeight.ascent);
fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading);
SetLabel(fName);
SetLabel(name);
fOverrideWidth = width;
fOverrideHeight = height;
fBarView = static_cast<TBarApp*>(be_app)->BarView();
BFont font(be_plain_font);
fLabelWidth = ceilf(font.StringWidth(name));
font_height fontHeight;
font.GetHeight(&fontHeight);
fLabelAscent = ceilf(fontHeight.ascent);
fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading);
fOverriddenSelected = false;
fExpanded = false;
-2
View File
@@ -82,7 +82,6 @@ public:
float LabelWidth() const { return fLabelWidth; };
BList* Teams() const { return fTeam; };
const char* Signature() const { return fSignature; };
const char* Name() const { return fName; };
protected:
void GetContentSize(float* width, float* height);
@@ -100,7 +99,6 @@ private:
private:
BList* fTeam;
BBitmap* fIcon;
char* fName;
char* fSignature;
float fOverrideWidth;
+1 -1
View File
@@ -144,7 +144,7 @@ TWindowMenu::AttachedToWindow()
TWindowMenuItem* item
= static_cast<TWindowMenuItem*>(ItemAt(addIndex));
if (item != NULL
&& strcasecmp(item->Name(), wInfo->name) > 0) {
&& strcasecmp(item->Label(), wInfo->name) > 0) {
break;
}
}
+8 -9
View File
@@ -61,10 +61,10 @@ const BRect kIconRect(1.0f, 1.0f, 13.0f, 14.0f);
// #pragma mark - TWindowMenuItem
TWindowMenuItem::TWindowMenuItem(const char* label, int32 id, bool mini,
TWindowMenuItem::TWindowMenuItem(const char* name, int32 id, bool mini,
bool currentWorkspace, bool dragging)
:
TTruncatableMenuItem(label, NULL),
TTruncatableMenuItem(name, NULL),
fID(id),
fMini(mini),
fCurrentWorkSpace(currentWorkspace),
@@ -73,7 +73,7 @@ TWindowMenuItem::TWindowMenuItem(const char* label, int32 id, bool mini,
fRequireUpdate(false),
fModified(false)
{
_Init(label);
_Init(name);
}
@@ -222,7 +222,7 @@ TWindowMenuItem::Invoke(BMessage* /*message*/)
void
TWindowMenuItem::SetTo(const char* label, int32 id, bool mini,
TWindowMenuItem::SetTo(const char* name, int32 id, bool mini,
bool currentWorkspace, bool dragging)
{
fModified = fCurrentWorkSpace != currentWorkspace || fMini != mini;
@@ -233,7 +233,7 @@ TWindowMenuItem::SetTo(const char* label, int32 id, bool mini,
fDragging = dragging;
fRequireUpdate = false;
_Init(label);
_Init(name);
}
@@ -256,7 +256,7 @@ TWindowMenuItem::InsertIndexFor(BMenu* menu, int32 startIndex,
void
TWindowMenuItem::_Init(const char* label)
TWindowMenuItem::_Init(const char* name)
{
if (fMini) {
fBitmap = fCurrentWorkSpace
@@ -268,13 +268,12 @@ TWindowMenuItem::_Init(const char* label)
: AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_WindowShownSwitchIcon);
}
fName = label;
BFont font(be_plain_font);
fLabelWidth = ceilf(font.StringWidth(label));
fLabelWidth = ceilf(font.StringWidth(name));
font_height fontHeight;
font.GetHeight(&fontHeight);
fLabelAscent = ceilf(fontHeight.ascent);
fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading);
SetLabel(label);
SetLabel(name);
}
+3 -5
View File
@@ -47,11 +47,11 @@ class BBitmap;
// sub of TeamMenuItem all DB positions
class TWindowMenuItem : public TTruncatableMenuItem {
public:
TWindowMenuItem(const char* label, int32 id,
TWindowMenuItem(const char* name, int32 id,
bool mini, bool currentWorkSpace,
bool dragging = false);
void SetTo(const char* label, int32 id, bool mini,
void SetTo(const char* name, int32 id, bool mini,
bool currentWorkSpace,
bool dragging = false);
@@ -60,7 +60,6 @@ public:
int32 ID() const { return fID; };
bool Modified() const { return fModified; };
const char* Name() const { return fName; };
bool RequiresUpdate() { return fRequireUpdate; };
void SetRequireUpdate(bool update)
@@ -76,7 +75,7 @@ protected:
virtual void Draw();
private:
void _Init(const char* label);
void _Init(const char* name);
int32 fID;
bool fMini;
@@ -89,7 +88,6 @@ private:
bool fExpanded;
bool fRequireUpdate;
bool fModified;
const char* fName;
};