Alter Add and Remove methods to return whether or not the add or remove succeeded.

This commit is contained in:
John Scipione
2012-11-14 14:39:10 -05:00
parent 11f46c6d37
commit fc18a4f5b3
2 changed files with 33 additions and 15 deletions
+29 -11
View File
@@ -102,11 +102,11 @@ TBarMenuBar::SmartResize(float width, float height)
} }
void bool
TBarMenuBar::AddTeamMenu() TBarMenuBar::AddTeamMenu()
{ {
if (CountItems() > 1) if (CountItems() > 1)
return; return false;
BRect frame(Frame()); BRect frame(Frame());
@@ -114,33 +114,42 @@ TBarMenuBar::AddTeamMenu()
fAppListMenuItem = new TBarMenuTitle(0.0f, 0.0f, fAppListMenuItem = new TBarMenuTitle(0.0f, 0.0f,
AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_TeamIcon), new TTeamMenu()); AppResSet()->FindBitmap(B_MESSAGE_TYPE, R_TeamIcon), new TTeamMenu());
if (AddItem(fAppListMenuItem)) { bool added = AddItem(fAppListMenuItem);
if (added)
SmartResize(frame.Width() - 1.0f, frame.Height()); SmartResize(frame.Width() - 1.0f, frame.Height());
} else else
SmartResize(frame.Width(), frame.Height()); SmartResize(frame.Width(), frame.Height());
return added;
} }
void bool
TBarMenuBar::RemoveTeamMenu() TBarMenuBar::RemoveTeamMenu()
{ {
if (CountItems() < 2) if (CountItems() < 2)
return; return false;
bool removed = false;
if (fAppListMenuItem != NULL if (fAppListMenuItem != NULL
&& RemoveItem(static_cast<BMenuItem*>(fAppListMenuItem))) { && RemoveItem(static_cast<BMenuItem*>(fAppListMenuItem))) {
delete fAppListMenuItem; delete fAppListMenuItem;
fAppListMenuItem = NULL; fAppListMenuItem = NULL;
SmartResize(-1, -1); SmartResize(-1, -1);
removed = true;
} }
return removed;
} }
void bool
TBarMenuBar::AddSeperatorItem() TBarMenuBar::AddSeperatorItem()
{ {
if (CountItems() > 1) if (CountItems() > 1)
return; return false;
BRect frame(Frame()); BRect frame(Frame());
@@ -149,25 +158,34 @@ TBarMenuBar::AddSeperatorItem()
frame.Height() - 2, false); frame.Height() - 2, false);
fSeparatorItem->SetEnabled(false); fSeparatorItem->SetEnabled(false);
if (AddItem(fSeparatorItem)) bool added = AddItem(fSeparatorItem);
if (added)
SmartResize(frame.Width() - 1.0f, frame.Height()); SmartResize(frame.Width() - 1.0f, frame.Height());
else else
SmartResize(frame.Width(), frame.Height()); SmartResize(frame.Width(), frame.Height());
return added;
} }
void bool
TBarMenuBar::RemoveSeperatorItem() TBarMenuBar::RemoveSeperatorItem()
{ {
if (CountItems() < 2) if (CountItems() < 2)
return; return false;
bool removed = false;
if (fSeparatorItem != NULL if (fSeparatorItem != NULL
&& RemoveItem(static_cast<BMenuItem*>(fSeparatorItem))) { && RemoveItem(static_cast<BMenuItem*>(fSeparatorItem))) {
delete fSeparatorItem; delete fSeparatorItem;
fSeparatorItem = NULL; fSeparatorItem = NULL;
SmartResize(-1, -1); SmartResize(-1, -1);
removed = true;
} }
return removed;
} }
+4 -4
View File
@@ -60,11 +60,11 @@ class TBarMenuBar : public BMenuBar {
void DrawBackground(BRect); void DrawBackground(BRect);
void SmartResize(float width = -1.0f, float height = -1.0f); void SmartResize(float width = -1.0f, float height = -1.0f);
void AddTeamMenu(); bool AddTeamMenu();
void RemoveTeamMenu(); bool RemoveTeamMenu();
void AddSeperatorItem(); bool AddSeperatorItem();
void RemoveSeperatorItem(); bool RemoveSeperatorItem();
void InitTrackingHook(bool (* hookfunction)(BMenu*, void*), void* state, void InitTrackingHook(bool (* hookfunction)(BMenu*, void*), void* state,
bool both = false); bool both = false);