Resize menu field if below minimum width in auto-size mode

... cancelling the normal item truncation behavior.
This funcationality comes from BeOS R5, we need to reproduce it for
backwards compat. KeymapSwitcher depends on it at least.

Minimum width is 20px, was set in last commit, comes from BeOS R5.
This commit is contained in:
John Scipione 2013-05-26 01:56:00 -04:00
parent 6031e62420
commit a1cf3ead5f
3 changed files with 16 additions and 3 deletions

View File

@ -19,7 +19,6 @@
static const float kVMargin = 2.0f;
static const float kMinMenuBarWidth = 20.0f;
// found by experimenting on BeOS R5
static const float kPopUpIndicatorWidth = 13.0f;
class BMessageRunner;

View File

@ -55,6 +55,9 @@ _BMCFilter_::Filter(BMessage* message, BHandler** handler)
// #pragma mark -
static const float kPopUpIndicatorWidth = 13.0f;
_BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixedSize, BMenuField* menuField)
:
BMenuBar(frame, "_mc_mb_", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_ITEMS_IN_ROW,

View File

@ -19,6 +19,7 @@
#include <ControlLook.h>
#include <LayoutUtils.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Message.h>
#include <BMCPrivate.h>
#include <Window.h>
@ -397,8 +398,18 @@ BMenuField::AllAttached()
TRACE("width: %.2f, height: %.2f\n", Frame().Width(), Frame().Height());
ResizeTo(Bounds().Width(),
fMenuBar->Bounds().Height() + kVMargin + kVMargin);
float width = Bounds().Width();
if (!fFixedSizeMB && _MenuBarWidth() < kMinMenuBarWidth) {
// The menu bar is too narrow, resize it to fit the menu items
BMenuItem* item = fMenuBar->ItemAt(0);
if (item != NULL) {
float right;
fMenuBar->GetItemMargins(NULL, NULL, &right, NULL);
width = item->Frame().Width() + kVMargin + _MenuBarOffset() + right;
}
}
ResizeTo(width, fMenuBar->Bounds().Height() + kVMargin * 2);
TRACE("width: %.2f, height: %.2f\n", Frame().Width(), Frame().Height());
}