In case the BMenu is inside a BMenuField, override the items width to

span over the BMenuField's width. Note that if the BMenu is already
wider, we don't shrink it, at least for now.
Fixes #5015.
This commit is contained in:
Stefano Ceccherini 2013-04-13 10:28:48 +02:00
parent c57854947d
commit 501201761b
2 changed files with 19 additions and 9 deletions

View File

@ -214,7 +214,7 @@ private:
bool moveItems, float* width, bool moveItems, float* width,
float* height); float* height);
void _ComputeColumnLayout(int32 index, bool bestFit, void _ComputeColumnLayout(int32 index, bool bestFit,
bool moveItems, BRect& outRect); bool moveItems, BRect* override, BRect& outRect);
void _ComputeRowLayout(int32 index, bool bestFit, void _ComputeRowLayout(int32 index, bool bestFit,
bool moveItems, BRect& outRect); bool moveItems, BRect& outRect);
void _ComputeMatrixLayout(BRect& outRect); void _ComputeMatrixLayout(BRect& outRect);

View File

@ -2119,9 +2119,18 @@ BMenu::_ComputeLayout(int32 index, bool bestFit, bool moveItems,
switch (fLayout) { switch (fLayout) {
case B_ITEMS_IN_COLUMN: case B_ITEMS_IN_COLUMN:
_ComputeColumnLayout(index, bestFit, moveItems, frame); {
break; BRect parentFrame;
BRect* overrideFrame = NULL;
if (dynamic_cast<_BMCMenuBar_*>(Supermenu()) != NULL) {
parentFrame = Supermenu()->Bounds();
overrideFrame = &parentFrame;
}
_ComputeColumnLayout(index, bestFit, moveItems, overrideFrame,
frame);
break;
}
case B_ITEMS_IN_ROW: case B_ITEMS_IN_ROW:
_ComputeRowLayout(index, bestFit, moveItems, frame); _ComputeRowLayout(index, bestFit, moveItems, frame);
break; break;
@ -2164,7 +2173,7 @@ BMenu::_ComputeLayout(int32 index, bool bestFit, bool moveItems,
void void
BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems, BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems,
BRect& frame) BRect* overrideFrame, BRect& frame)
{ {
BFont font; BFont font;
GetFont(&font); GetFont(&font);
@ -2174,7 +2183,9 @@ BMenu::_ComputeColumnLayout(int32 index, bool bestFit, bool moveItems,
bool option = false; bool option = false;
if (index > 0) if (index > 0)
frame = ItemAt(index - 1)->Frame(); frame = ItemAt(index - 1)->Frame();
else else if (overrideFrame != NULL) {
frame.Set(0, 0, overrideFrame->right, -1);
} else
frame.Set(0, 0, 0, -1); frame.Set(0, 0, 0, -1);
for (; index < fItems.CountItems(); index++) { for (; index < fItems.CountItems(); index++) {
@ -2326,13 +2337,12 @@ BMenu::_CalcFrame(BPoint where, bool* scrollOn)
BMenu* superMenu = Supermenu(); BMenu* superMenu = Supermenu();
BMenuItem* superItem = Superitem(); BMenuItem* superItem = Superitem();
bool scroll = false;
// TODO: Horrible hack: // TODO: Horrible hack:
// When added to a BMenuField, a BPopUpMenu is the child of // When added to a BMenuField, a BPopUpMenu is the child of
// a _BMCMenuBar_ to "fake" the menu hierarchy // a _BMCMenuBar_ to "fake" the menu hierarchy
if (superMenu == NULL || superItem == NULL bool inMenuField = dynamic_cast<_BMCMenuBar_*>(superMenu) != NULL;
|| dynamic_cast<_BMCMenuBar_*>(superMenu) != NULL) { bool scroll = false;
if (superMenu == NULL || superItem == NULL || inMenuField) {
// just move the window on screen // just move the window on screen
if (frame.bottom > screenFrame.bottom) if (frame.bottom > screenFrame.bottom)