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:
@@ -367,10 +367,10 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
|
|||||||
&& fBarView->ExpandoState() && item->IsExpanded()) {
|
&& fBarView->ExpandoState() && item->IsExpanded()) {
|
||||||
// expando mode window menu item
|
// expando mode window menu item
|
||||||
fLastMousedOverItem = menuItem;
|
fLastMousedOverItem = menuItem;
|
||||||
if (strcasecmp(windowMenuItem->Label(),
|
if (strcasecmp(windowMenuItem->TruncatedLabel(),
|
||||||
windowMenuItem->Name()) > 0) {
|
windowMenuItem->Label()) > 0) {
|
||||||
// label is truncated, set tooltip
|
// label is truncated, set tooltip
|
||||||
SetToolTip(windowMenuItem->Name());
|
SetToolTip(windowMenuItem->Label());
|
||||||
} else
|
} else
|
||||||
SetToolTip((const char*)NULL);
|
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) {
|
if (!dynamic_cast<TBarApp*>(be_app)->Settings()->hideLabels) {
|
||||||
// item has a visible label, set tool tip if truncated
|
// item has a visible label, set tool tip if truncated
|
||||||
fLastMousedOverItem = menuItem;
|
fLastMousedOverItem = menuItem;
|
||||||
if (strcasecmp(item->Label(), item->Name()) > 0) {
|
if (strcasecmp(item->TruncatedLabel(), item->Label()) > 0) {
|
||||||
// label is truncated, set tooltip
|
// label is truncated, set tooltip
|
||||||
SetToolTip(item->Name());
|
SetToolTip(item->Label());
|
||||||
} else
|
} else
|
||||||
SetToolTip((const char*)NULL);
|
SetToolTip((const char*)NULL);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetToolTip(item->Name());
|
SetToolTip(item->Label());
|
||||||
// new item, set the tooltip to the item name
|
// new item, set the tooltip to the item label
|
||||||
fLastMousedOverItem = menuItem;
|
fLastMousedOverItem = menuItem;
|
||||||
// save the current menuitem for the next MouseMoved() call
|
// save the current menuitem for the next MouseMoved() call
|
||||||
break;
|
break;
|
||||||
@@ -639,7 +639,7 @@ TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name,
|
|||||||
int32 itemCount = CountItems();
|
int32 itemCount = CountItems();
|
||||||
while (i < itemCount) {
|
while (i < itemCount) {
|
||||||
teamItem = dynamic_cast<TTeamMenuItem*>(ItemAt(i));
|
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);
|
AddItem(item, i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,7 +89,6 @@ TTeamMenuItem::~TTeamMenuItem()
|
|||||||
{
|
{
|
||||||
delete fTeam;
|
delete fTeam;
|
||||||
delete fIcon;
|
delete fIcon;
|
||||||
free(fName);
|
|
||||||
free(fSignature);
|
free(fSignature);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -418,27 +417,28 @@ TTeamMenuItem::_Init(BList* team, BBitmap* icon, char* name, char* signature,
|
|||||||
{
|
{
|
||||||
fTeam = team;
|
fTeam = team;
|
||||||
fIcon = icon;
|
fIcon = icon;
|
||||||
fName = name;
|
|
||||||
fSignature = signature;
|
fSignature = signature;
|
||||||
if (fName == NULL) {
|
|
||||||
|
if (name == NULL) {
|
||||||
char temp[32];
|
char temp[32];
|
||||||
snprintf(temp, sizeof(temp), "team %ld", (addr_t)team->ItemAt(0));
|
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;
|
fOverrideWidth = width;
|
||||||
fOverrideHeight = height;
|
fOverrideHeight = height;
|
||||||
|
|
||||||
fBarView = static_cast<TBarApp*>(be_app)->BarView();
|
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;
|
fOverriddenSelected = false;
|
||||||
|
|
||||||
fExpanded = false;
|
fExpanded = false;
|
||||||
|
|||||||
@@ -82,7 +82,6 @@ public:
|
|||||||
float LabelWidth() const { return fLabelWidth; };
|
float LabelWidth() const { return fLabelWidth; };
|
||||||
BList* Teams() const { return fTeam; };
|
BList* Teams() const { return fTeam; };
|
||||||
const char* Signature() const { return fSignature; };
|
const char* Signature() const { return fSignature; };
|
||||||
const char* Name() const { return fName; };
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void GetContentSize(float* width, float* height);
|
void GetContentSize(float* width, float* height);
|
||||||
@@ -100,7 +99,6 @@ private:
|
|||||||
private:
|
private:
|
||||||
BList* fTeam;
|
BList* fTeam;
|
||||||
BBitmap* fIcon;
|
BBitmap* fIcon;
|
||||||
char* fName;
|
|
||||||
char* fSignature;
|
char* fSignature;
|
||||||
|
|
||||||
float fOverrideWidth;
|
float fOverrideWidth;
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ TWindowMenu::AttachedToWindow()
|
|||||||
TWindowMenuItem* item
|
TWindowMenuItem* item
|
||||||
= static_cast<TWindowMenuItem*>(ItemAt(addIndex));
|
= static_cast<TWindowMenuItem*>(ItemAt(addIndex));
|
||||||
if (item != NULL
|
if (item != NULL
|
||||||
&& strcasecmp(item->Name(), wInfo->name) > 0) {
|
&& strcasecmp(item->Label(), wInfo->name) > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ const BRect kIconRect(1.0f, 1.0f, 13.0f, 14.0f);
|
|||||||
// #pragma mark - TWindowMenuItem
|
// #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)
|
bool currentWorkspace, bool dragging)
|
||||||
:
|
:
|
||||||
TTruncatableMenuItem(label, NULL),
|
TTruncatableMenuItem(name, NULL),
|
||||||
fID(id),
|
fID(id),
|
||||||
fMini(mini),
|
fMini(mini),
|
||||||
fCurrentWorkSpace(currentWorkspace),
|
fCurrentWorkSpace(currentWorkspace),
|
||||||
@@ -73,7 +73,7 @@ TWindowMenuItem::TWindowMenuItem(const char* label, int32 id, bool mini,
|
|||||||
fRequireUpdate(false),
|
fRequireUpdate(false),
|
||||||
fModified(false)
|
fModified(false)
|
||||||
{
|
{
|
||||||
_Init(label);
|
_Init(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -222,7 +222,7 @@ TWindowMenuItem::Invoke(BMessage* /*message*/)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TWindowMenuItem::SetTo(const char* label, int32 id, bool mini,
|
TWindowMenuItem::SetTo(const char* name, int32 id, bool mini,
|
||||||
bool currentWorkspace, bool dragging)
|
bool currentWorkspace, bool dragging)
|
||||||
{
|
{
|
||||||
fModified = fCurrentWorkSpace != currentWorkspace || fMini != mini;
|
fModified = fCurrentWorkSpace != currentWorkspace || fMini != mini;
|
||||||
@@ -233,7 +233,7 @@ TWindowMenuItem::SetTo(const char* label, int32 id, bool mini,
|
|||||||
fDragging = dragging;
|
fDragging = dragging;
|
||||||
fRequireUpdate = false;
|
fRequireUpdate = false;
|
||||||
|
|
||||||
_Init(label);
|
_Init(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ TWindowMenuItem::InsertIndexFor(BMenu* menu, int32 startIndex,
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TWindowMenuItem::_Init(const char* label)
|
TWindowMenuItem::_Init(const char* name)
|
||||||
{
|
{
|
||||||
if (fMini) {
|
if (fMini) {
|
||||||
fBitmap = fCurrentWorkSpace
|
fBitmap = fCurrentWorkSpace
|
||||||
@@ -268,13 +268,12 @@ TWindowMenuItem::_Init(const char* label)
|
|||||||
: AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_WindowShownSwitchIcon);
|
: AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_WindowShownSwitchIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
fName = label;
|
|
||||||
BFont font(be_plain_font);
|
BFont font(be_plain_font);
|
||||||
fLabelWidth = ceilf(font.StringWidth(label));
|
fLabelWidth = ceilf(font.StringWidth(name));
|
||||||
font_height fontHeight;
|
font_height fontHeight;
|
||||||
font.GetHeight(&fontHeight);
|
font.GetHeight(&fontHeight);
|
||||||
fLabelAscent = ceilf(fontHeight.ascent);
|
fLabelAscent = ceilf(fontHeight.ascent);
|
||||||
fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading);
|
fLabelDescent = ceilf(fontHeight.descent + fontHeight.leading);
|
||||||
|
|
||||||
SetLabel(label);
|
SetLabel(name);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,11 +47,11 @@ class BBitmap;
|
|||||||
// sub of TeamMenuItem all DB positions
|
// sub of TeamMenuItem all DB positions
|
||||||
class TWindowMenuItem : public TTruncatableMenuItem {
|
class TWindowMenuItem : public TTruncatableMenuItem {
|
||||||
public:
|
public:
|
||||||
TWindowMenuItem(const char* label, int32 id,
|
TWindowMenuItem(const char* name, int32 id,
|
||||||
bool mini, bool currentWorkSpace,
|
bool mini, bool currentWorkSpace,
|
||||||
bool dragging = false);
|
bool dragging = false);
|
||||||
|
|
||||||
void SetTo(const char* label, int32 id, bool mini,
|
void SetTo(const char* name, int32 id, bool mini,
|
||||||
bool currentWorkSpace,
|
bool currentWorkSpace,
|
||||||
bool dragging = false);
|
bool dragging = false);
|
||||||
|
|
||||||
@@ -60,7 +60,6 @@ public:
|
|||||||
|
|
||||||
int32 ID() const { return fID; };
|
int32 ID() const { return fID; };
|
||||||
bool Modified() const { return fModified; };
|
bool Modified() const { return fModified; };
|
||||||
const char* Name() const { return fName; };
|
|
||||||
|
|
||||||
bool RequiresUpdate() { return fRequireUpdate; };
|
bool RequiresUpdate() { return fRequireUpdate; };
|
||||||
void SetRequireUpdate(bool update)
|
void SetRequireUpdate(bool update)
|
||||||
@@ -76,7 +75,7 @@ protected:
|
|||||||
virtual void Draw();
|
virtual void Draw();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _Init(const char* label);
|
void _Init(const char* name);
|
||||||
|
|
||||||
int32 fID;
|
int32 fID;
|
||||||
bool fMini;
|
bool fMini;
|
||||||
@@ -89,7 +88,6 @@ private:
|
|||||||
bool fExpanded;
|
bool fExpanded;
|
||||||
bool fRequireUpdate;
|
bool fRequireUpdate;
|
||||||
bool fModified;
|
bool fModified;
|
||||||
const char* fName;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user