From a1cf3ead5f5e9b2857b9622bef5bc1742fd21151 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sun, 26 May 2013 01:56:00 -0400 Subject: [PATCH] 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. --- headers/private/interface/BMCPrivate.h | 1 - src/kits/interface/BMCPrivate.cpp | 3 +++ src/kits/interface/MenuField.cpp | 15 +++++++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/headers/private/interface/BMCPrivate.h b/headers/private/interface/BMCPrivate.h index f6c1bc4c82..0590fc7c52 100644 --- a/headers/private/interface/BMCPrivate.h +++ b/headers/private/interface/BMCPrivate.h @@ -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; diff --git a/src/kits/interface/BMCPrivate.cpp b/src/kits/interface/BMCPrivate.cpp index 1d8f60db96..da8719f4fb 100644 --- a/src/kits/interface/BMCPrivate.cpp +++ b/src/kits/interface/BMCPrivate.cpp @@ -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, diff --git a/src/kits/interface/MenuField.cpp b/src/kits/interface/MenuField.cpp index 1be5d10b5d..3c94b44c9f 100644 --- a/src/kits/interface/MenuField.cpp +++ b/src/kits/interface/MenuField.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -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()); }