Fixed CalcFrame(): it could be called with Superitem() and Supermenu() == NULL.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13475 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-07-06 02:22:22 +00:00
parent 8ffa3fb9fa
commit 1b1b68919c
+30 -20
View File
@@ -1041,17 +1041,16 @@ BMenu::_show(bool selectFirstItem)
// Menu windows get the BMenu's handler name // Menu windows get the BMenu's handler name
fCachedMenuWindow = new BMenuWindow(Name()); fCachedMenuWindow = new BMenuWindow(Name());
fCachedMenuWindow->ChildAt(0)->AddChild(this); fCachedMenuWindow->ChildAt(0)->AddChild(this);
// We're doing this here because ConvertToScreen() needs: // We're doing this here because ConvertToScreen() needs:
// 1. The BView to be attached (see the above line). // 1. The BView to be attached (see the above line).
// 2. The looper locked or not running (the Show() call below starts the looper) // 2. The looper locked or not running (the Show() call below starts the looper)
if (fSuper != NULL) if (fSuper != NULL)
fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds()); fSuperbounds = fSuper->ConvertToScreen(fSuper->Bounds());
UpdateWindowViewSize(); UpdateWindowViewSize();
fCachedMenuWindow->Show(); fCachedMenuWindow->Show();
return true; return true;
} }
@@ -1065,7 +1064,6 @@ BMenu::_hide()
fCachedMenuWindow->Quit(); fCachedMenuWindow->Quit();
fCachedMenuWindow = NULL; fCachedMenuWindow = NULL;
} }
} }
@@ -1220,7 +1218,7 @@ BMenu::LayoutItems(int32 index)
ComputeLayout(index, true, true, &width, &height); ComputeLayout(index, true, true, &width, &height);
ResizeTo(width, height); ResizeTo(width, height);
// Move the BMenu to 1, 1, if it's attached to a BMenuWindow, // Move the BMenu to 1, 1, if it's attached to a BMenuWindow,
// (that means it's a BMenu, BMenuBars are attached to regular BWindows). // (that means it's a BMenu, BMenuBars are attached to regular BWindows).
// This is needed to be able to draw the frame around the BMenu. // This is needed to be able to draw the frame around the BMenu.
@@ -1235,11 +1233,11 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
{ {
if (Window() == NULL && Parent() == NULL) if (Window() == NULL && Parent() == NULL)
return; return;
// TODO: Take "bestFit", "moveItems", "index" into account, // TODO: Take "bestFit", "moveItems", "index" into account,
// Recalculate only the needed items, // Recalculate only the needed items,
// not the whole layout every time // not the whole layout every time
BRect frame(0, 0, 0, 0); BRect frame(0, 0, 0, 0);
float iWidth, iHeight; float iWidth, iHeight;
BMenuItem *item = NULL; BMenuItem *item = NULL;
@@ -1251,19 +1249,19 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
item = ItemAt(i); item = ItemAt(i);
if (item != NULL) { if (item != NULL) {
item->GetContentSize(&iWidth, &iHeight); item->GetContentSize(&iWidth, &iHeight);
if (item->fModifiers && item->fShortcutChar) if (item->fModifiers && item->fShortcutChar)
iWidth += 25.0f; iWidth += 25.0f;
item->fBounds.left = 0.0f; item->fBounds.left = 0.0f;
item->fBounds.top = frame.bottom; item->fBounds.top = frame.bottom;
item->fBounds.bottom = item->fBounds.top + iHeight + fPad.top + fPad.bottom; item->fBounds.bottom = item->fBounds.top + iHeight + fPad.top + fPad.bottom;
frame.right = max_c(frame.right, iWidth + fPad.left + fPad.right) + 20; frame.right = max_c(frame.right, iWidth + fPad.left + fPad.right) + 20;
frame.bottom = item->fBounds.bottom + 1.0f; frame.bottom = item->fBounds.bottom + 1.0f;
} }
} }
for (int32 i = 0; i < fItems.CountItems(); i++) for (int32 i = 0; i < fItems.CountItems(); i++)
ItemAt(i)->fBounds.right = frame.right; ItemAt(i)->fBounds.right = frame.right;
@@ -1271,7 +1269,7 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
frame.bottom--; frame.bottom--;
break; break;
} }
case B_ITEMS_IN_ROW: case B_ITEMS_IN_ROW:
{ {
font_height fh; font_height fh;
@@ -1283,23 +1281,23 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
item = ItemAt(i); item = ItemAt(i);
if (item != NULL) { if (item != NULL) {
item->GetContentSize(&iWidth, &iHeight); item->GetContentSize(&iWidth, &iHeight);
item->fBounds.left = frame.right; item->fBounds.left = frame.right;
item->fBounds.top = 0.0f; item->fBounds.top = 0.0f;
item->fBounds.right = item->fBounds.left + iWidth + fPad.left + fPad.right; item->fBounds.right = item->fBounds.left + iWidth + fPad.left + fPad.right;
frame.right = item->Frame().right + 1.0f; frame.right = item->Frame().right + 1.0f;
frame.bottom = max_c(frame.bottom, iHeight + fPad.top + fPad.bottom); frame.bottom = max_c(frame.bottom, iHeight + fPad.top + fPad.bottom);
} }
} }
for (int32 i = 0; i < fItems.CountItems(); i++) for (int32 i = 0; i < fItems.CountItems(); i++)
ItemAt(i)->fBounds.bottom = frame.bottom; ItemAt(i)->fBounds.bottom = frame.bottom;
frame.right = (float)ceil(frame.right) + 8.0f; frame.right = (float)ceil(frame.right) + 8.0f;
break; break;
} }
case B_ITEMS_IN_MATRIX: case B_ITEMS_IN_MATRIX:
{ {
for (int32 i = 0; i < CountItems(); i++) { for (int32 i = 0; i < CountItems(); i++) {
@@ -1313,7 +1311,7 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
} }
break; break;
} }
default: default:
break; break;
} }
@@ -1324,7 +1322,7 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
*width = Parent()->Frame().Width() + 1; *width = Parent()->Frame().Width() + 1;
else else
*width = Window()->Frame().Width() + 1; *width = Window()->Frame().Width() + 1;
*height = frame.Height(); *height = frame.Height();
} else { } else {
*width = frame.Width(); *width = frame.Width();
@@ -1385,6 +1383,18 @@ BMenu::CalcFrame(BPoint where, bool *scrollOn)
BMenu *superMenu = Supermenu(); BMenu *superMenu = Supermenu();
BMenuItem *superItem = Superitem(); BMenuItem *superItem = Superitem();
if (superMenu == NULL || superItem == NULL) {
// just move the window on screen
if (frame.bottom > screenFrame.bottom)
frame.OffsetBy(0, screenFrame.bottom - frame.bottom);
if (frame.right > screenFrame.right)
frame.OffsetBy(screenFrame.right - frame.right, 0);
return frame;
}
if (superMenu->Layout() == B_ITEMS_IN_COLUMN) { if (superMenu->Layout() == B_ITEMS_IN_COLUMN) {
if (frame.right > screenFrame.right) if (frame.right > screenFrame.right)
frame.OffsetBy(-superItem->Frame().Width() - frame.Width() - 2, 0); frame.OffsetBy(-superItem->Frame().Width() - frame.Width() - 2, 0);