From 01636e8f2af4878e9181ff1a18721494e5222e75 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 15 May 2013 19:44:52 -0400 Subject: [PATCH] Adjust menu field's menu bar height in auto mode On IRC diver pointed out to me that KeymapSwitcher had a menu field that was drawing as just a line since my recent change to BMenuField. I did a little research and discovered that this was because the menu field in KeymapSwitch was not using the layout APIs and it's frame rect was set to 0 height. I did a little more research and experimented with menu fields in BeOS R5. I discovered that in R5 if the menu field is set to auto-size mode then the menu bar inside ignores the height of the menu field frame and uses the BMenuBar's preferred height instead. So, I adjusted the BMenuField code in Haiku accordingly. This should make Haiku match the behavior of BeOS R5 in auto-size mode. For fixed-size mode it should also work the same, although some more testing is needed to see if there are any regressions there. --- src/kits/interface/BMCPrivate.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/kits/interface/BMCPrivate.cpp b/src/kits/interface/BMCPrivate.cpp index f1dde0267d..491b00d0f7 100644 --- a/src/kits/interface/BMCPrivate.cpp +++ b/src/kits/interface/BMCPrivate.cpp @@ -11,6 +11,8 @@ #include +#include + #include #include #include @@ -137,10 +139,16 @@ _BMCMenuBar_::AttachedToWindow() void _BMCMenuBar_::Draw(BRect updateRect) { - if (fFixedSize || Bounds().Width() > fMenuField->_MenuBarWidth()) { - // Set the width of the menu bar because the menu bar bounds have - // been expanded by the selected menu item. + // Set the width of the menu bar because the menu bar bounds may have + // been expanded by the selected menu item. + if (fFixedSize) ResizeTo(fMenuField->_MenuBarWidth(), Bounds().Height()); + else { + // For compatability with BeOS R5 set the height to the preferred height + // in auto-size mode ignoring the height of the menu field. + float height; + BMenuBar::GetPreferredSize(NULL, &height); + ResizeTo(std::min(Bounds().Width(), fMenuField->_MenuBarWidth()), height); } BRect rect(Bounds()); rgb_color base = ui_color(B_MENU_BACKGROUND_COLOR);