From ca3a1c04518ebab574847a83e518c5fa407830a8 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 29 May 2013 23:56:08 -0400 Subject: [PATCH] BMenuField: If fixed size always set max content width When you resize, also set max content width. Create a SetMaxContentWidth() method that includes the margins. --- headers/private/interface/BMCPrivate.h | 1 + src/kits/interface/BMCPrivate.cpp | 17 ++++++++++++++--- src/kits/interface/MenuField.cpp | 25 +++++++++++++++---------- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/headers/private/interface/BMCPrivate.h b/headers/private/interface/BMCPrivate.h index 55fc56414e..5581d88d0f 100644 --- a/headers/private/interface/BMCPrivate.h +++ b/headers/private/interface/BMCPrivate.h @@ -51,6 +51,7 @@ public: virtual void FrameResized(float width, float height); virtual void MessageReceived(BMessage* msg); virtual void MakeFocus(bool focused = true); + virtual void SetMaxContentWidth(float width); void TogglePopUpMarker(bool show) { fShowPopUpMarker = show; } diff --git a/src/kits/interface/BMCPrivate.cpp b/src/kits/interface/BMCPrivate.cpp index da8719f4fb..023769aa1c 100644 --- a/src/kits/interface/BMCPrivate.cpp +++ b/src/kits/interface/BMCPrivate.cpp @@ -67,7 +67,7 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixedSize, BMenuField* menuField) fRunner(NULL), fShowPopUpMarker(true) { - _Init(true); + _Init(fixedSize); } @@ -79,7 +79,7 @@ _BMCMenuBar_::_BMCMenuBar_(BMenuField* menuField) fRunner(NULL), fShowPopUpMarker(true) { - _Init(false); + _Init(true); } @@ -265,6 +265,17 @@ _BMCMenuBar_::MakeFocus(bool focused) } +void +_BMCMenuBar_::SetMaxContentWidth(float width) +{ + float left; + float right; + GetItemMargins(&left, NULL, &right, NULL); + + BMenuBar::SetMaxContentWidth(width - (left + right)); +} + + BSize _BMCMenuBar_::MinSize() { @@ -325,5 +336,5 @@ _BMCMenuBar_::_Init(bool setMaxContentWidth) fPreviousWidth = Bounds().Width(); if (setMaxContentWidth) - SetMaxContentWidth(fPreviousWidth - (left + right)); + SetMaxContentWidth(fPreviousWidth); } diff --git a/src/kits/interface/MenuField.cpp b/src/kits/interface/MenuField.cpp index 9a87784938..e30fe662fa 100644 --- a/src/kits/interface/MenuField.cpp +++ b/src/kits/interface/MenuField.cpp @@ -539,6 +539,17 @@ BMenuField::FrameResized(float newWidth, float newHeight) { BView::FrameResized(newWidth, newHeight); + if (fFixedSizeMB) { + // we have let the menubar resize itself, but + // in fixed size mode, the menubar is supposed to + // be at the right end of the view always. Since + // the menu bar is in follow left/right mode then, + // resizing ourselfs might have caused the menubar + // to be outside now + fMenuBar->ResizeTo(_MenuBarWidth(), fMenuBar->Frame().Height()); + fMenuBar->SetMaxContentWidth(_MenuBarWidth()); + } + if (newHeight != fLayoutData->previous_height && Label()) { // The height changed, which means the label has to move and we // probably also invalidate a part of the borders around the menu bar. @@ -654,8 +665,10 @@ BMenuField::SetDivider(float position) fMenuBar->MoveTo(_MenuBarOffset(), kVMargin); - if (fFixedSizeMB) + if (fFixedSizeMB) { fMenuBar->ResizeTo(_MenuBarWidth(), dirty.Height()); + fMenuBar->SetMaxContentWidth(_MenuBarWidth()); + } dirty = dirty | fMenuBar->Frame(); dirty.InsetBy(-kVMargin, -kVMargin); @@ -722,15 +735,7 @@ BMenuField::ResizeToPreferred() BView::ResizeToPreferred(); - if (fFixedSizeMB) { - // we have let the menubar resize itself, but - // in fixed size mode, the menubar is supposed to - // be at the right end of the view always. Since - // the menu bar is in follow left/right mode then, - // resizing ourselfs might have caused the menubar - // to be outside now - fMenuBar->ResizeTo(_MenuBarWidth(), fMenuBar->Frame().Height()); - } + Invalidate(); }