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()
{
if (CountItems() > 1)
return;
return false;
BRect frame(Frame());
@@ -114,33 +114,42 @@ TBarMenuBar::AddTeamMenu()
fAppListMenuItem = new TBarMenuTitle(0.0f, 0.0f,
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());
} else
else
SmartResize(frame.Width(), frame.Height());
return added;
}
void
bool
TBarMenuBar::RemoveTeamMenu()
{
if (CountItems() < 2)
return;
return false;
bool removed = false;
if (fAppListMenuItem != NULL
&& RemoveItem(static_cast<BMenuItem*>(fAppListMenuItem))) {
delete fAppListMenuItem;
fAppListMenuItem = NULL;
SmartResize(-1, -1);
removed = true;
}
return removed;
}
void
bool
TBarMenuBar::AddSeperatorItem()
{
if (CountItems() > 1)
return;
return false;
BRect frame(Frame());
@@ -149,25 +158,34 @@ TBarMenuBar::AddSeperatorItem()
frame.Height() - 2, false);
fSeparatorItem->SetEnabled(false);
if (AddItem(fSeparatorItem))
bool added = AddItem(fSeparatorItem);
if (added)
SmartResize(frame.Width() - 1.0f, frame.Height());
else
SmartResize(frame.Width(), frame.Height());
return added;
}
void
bool
TBarMenuBar::RemoveSeperatorItem()
{
if (CountItems() < 2)
return;
return false;
bool removed = false;
if (fSeparatorItem != NULL
&& RemoveItem(static_cast<BMenuItem*>(fSeparatorItem))) {
delete fSeparatorItem;
fSeparatorItem = NULL;
SmartResize(-1, -1);
removed = true;
}
return removed;
}
+4 -4
View File
@@ -60,11 +60,11 @@ class TBarMenuBar : public BMenuBar {
void DrawBackground(BRect);
void SmartResize(float width = -1.0f, float height = -1.0f);
void AddTeamMenu();
void RemoveTeamMenu();
bool AddTeamMenu();
bool RemoveTeamMenu();
void AddSeperatorItem();
void RemoveSeperatorItem();
bool AddSeperatorItem();
bool RemoveSeperatorItem();
void InitTrackingHook(bool (* hookfunction)(BMenu*, void*), void* state,
bool both = false);