Assume AddItem and RemoveItem could fail and handle those cases.

This is some defensive coding that assumes that the AddTeamMenu(),
RemoveTeamMenu(), AddSeperatorItem(), and RemoveSeperatorItem()
methods might fail and tries to compensate. Although it is unlikely
to be the case that these methods could fail I am trying to prevent
the bug that caused #9151 to happen.
This commit is contained in:
John Scipione
2012-11-14 14:29:09 -05:00
parent cb7c5f05bb
commit 11f46c6d37
+14 -14
View File
@@ -113,9 +113,11 @@ TBarMenuBar::AddTeamMenu()
delete fAppListMenuItem; delete fAppListMenuItem;
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());
AddItem(fAppListMenuItem);
SmartResize(frame.Width() - 1.0f, frame.Height()); if (AddItem(fAppListMenuItem)) {
SmartResize(frame.Width() - 1.0f, frame.Height());
} else
SmartResize(frame.Width(), frame.Height());
} }
@@ -125,14 +127,12 @@ TBarMenuBar::RemoveTeamMenu()
if (CountItems() < 2) if (CountItems() < 2)
return; return;
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);
} }
BRect frame(Frame());
SmartResize(frame.Width(), frame.Height());
} }
@@ -147,10 +147,12 @@ TBarMenuBar::AddSeperatorItem()
delete fSeparatorItem; delete fSeparatorItem;
fSeparatorItem = new TTeamMenuItem(kSepItemWidth, fSeparatorItem = new TTeamMenuItem(kSepItemWidth,
frame.Height() - 2, false); frame.Height() - 2, false);
AddItem(fSeparatorItem);
fSeparatorItem->SetEnabled(false); fSeparatorItem->SetEnabled(false);
SmartResize(frame.Width() - 1.0f, frame.Height()); if (AddItem(fSeparatorItem))
SmartResize(frame.Width() - 1.0f, frame.Height());
else
SmartResize(frame.Width(), frame.Height());
} }
@@ -160,14 +162,12 @@ TBarMenuBar::RemoveSeperatorItem()
if (CountItems() < 2) if (CountItems() < 2)
return; return;
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);
} }
BRect frame(Frame());
SmartResize(frame.Width(), frame.Height());
} }