From 11f46c6d37ec5dbc502b72538cdf3ab0f1005629 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 14 Nov 2012 14:29:09 -0500 Subject: [PATCH] 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. --- src/apps/deskbar/BarMenuBar.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/apps/deskbar/BarMenuBar.cpp b/src/apps/deskbar/BarMenuBar.cpp index f40abc8f5e..c3508a8eed 100644 --- a/src/apps/deskbar/BarMenuBar.cpp +++ b/src/apps/deskbar/BarMenuBar.cpp @@ -113,9 +113,11 @@ TBarMenuBar::AddTeamMenu() delete fAppListMenuItem; fAppListMenuItem = new TBarMenuTitle(0.0f, 0.0f, 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) return; - if (fAppListMenuItem != NULL) { - RemoveItem(static_cast(fAppListMenuItem)); + if (fAppListMenuItem != NULL + && RemoveItem(static_cast(fAppListMenuItem))) { delete fAppListMenuItem; fAppListMenuItem = NULL; + SmartResize(-1, -1); } - - BRect frame(Frame()); - SmartResize(frame.Width(), frame.Height()); } @@ -147,10 +147,12 @@ TBarMenuBar::AddSeperatorItem() delete fSeparatorItem; fSeparatorItem = new TTeamMenuItem(kSepItemWidth, frame.Height() - 2, false); - AddItem(fSeparatorItem); 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) return; - if (fSeparatorItem != NULL) { - RemoveItem(static_cast(fSeparatorItem)); + if (fSeparatorItem != NULL + && RemoveItem(static_cast(fSeparatorItem))) { delete fSeparatorItem; fSeparatorItem = NULL; + SmartResize(-1, -1); } - - BRect frame(Frame()); - SmartResize(frame.Width(), frame.Height()); }