From 6031e62420fec7cc6c360bb210ca860a4a60e0f0 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Sun, 26 May 2013 01:52:23 -0400 Subject: [PATCH] Move constants to BMCPrivate.h and refactor We use these constants in both MenuField.cpp and BMCPrivate.cpp Incorporate kMarginWidth into kPopUpIndicatorWidth. A small code simplication in FrameResized() along with replacing bare numbers with magic constants. --- headers/private/interface/BMCPrivate.h | 6 ++++++ src/kits/interface/BMCPrivate.cpp | 26 ++++++++++---------------- src/kits/interface/MenuField.cpp | 3 --- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/headers/private/interface/BMCPrivate.h b/headers/private/interface/BMCPrivate.h index 5c9678c388..f6c1bc4c82 100644 --- a/headers/private/interface/BMCPrivate.h +++ b/headers/private/interface/BMCPrivate.h @@ -16,6 +16,12 @@ #include +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 a494e772e5..1d8f60db96 100644 --- a/src/kits/interface/BMCPrivate.cpp +++ b/src/kits/interface/BMCPrivate.cpp @@ -22,10 +22,6 @@ #include -static const float kPopUpIndicatorWidth = 10.0f; -static const float kMarginWidth = 3.0f; - - _BMCFilter_::_BMCFilter_(BMenuField* menuField, uint32 what) : BMessageFilter(B_ANY_DELIVERY, B_ANY_SOURCE, what), @@ -178,30 +174,29 @@ _BMCMenuBar_::FrameResized(float width, float height) float diff = width - fPreviousWidth; fPreviousWidth = width; - if (Window()) { + if (Window() != NULL && diff != 0) { + BRect dirty(fMenuField->Bounds()); if (diff > 0) { // clean up the dirty right border of // the menu field when enlarging - BRect dirty(fMenuField->Bounds()); - dirty.right = Frame().right + 2; - dirty.left = dirty.left - diff - 4; + dirty.right = Frame().right + kVMargin; + dirty.left = dirty.left - diff - kVMargin * 2; fMenuField->Invalidate(dirty); // clean up the arrow part dirty = Bounds(); - dirty.left = dirty.right - diff - 12; + dirty.left = dirty.right - diff - kPopUpIndicatorWidth; Invalidate(dirty); } else if (diff < 0) { // clean up the dirty right line of // the menu field when shrinking - BRect dirty(fMenuField->Bounds()); - dirty.left = Frame().right - 2; - dirty.right = dirty.left - diff + 4; + dirty.left = Frame().right - kVMargin; + dirty.right = dirty.left - diff + kVMargin * 2; fMenuField->Invalidate(dirty); // clean up the arrow part dirty = Bounds(); - dirty.left = dirty.right - 12; + dirty.left = dirty.right - kPopUpIndicatorWidth; Invalidate(dirty); } } @@ -275,7 +270,7 @@ _BMCMenuBar_::MinSize() if (fShowPopUpMarker) { // account for popup indicator + a few pixels margin - size.width += kPopUpIndicatorWidth + kMarginWidth; + size.width += kPopUpIndicatorWidth; } return BLayoutUtils::ComposeSize(ExplicitMinSize(), size); @@ -322,8 +317,7 @@ _BMCMenuBar_::_Init(bool setMaxContentWidth) left = right = be_control_look->DefaultLabelSpacing(); SetItemMargins(left, top, - right + fShowPopUpMarker ? kPopUpIndicatorWidth + kMarginWidth : 0, - bottom); + right + fShowPopUpMarker ? kPopUpIndicatorWidth : 0, bottom); fPreviousWidth = Bounds().Width(); diff --git a/src/kits/interface/MenuField.cpp b/src/kits/interface/MenuField.cpp index 0ff622d89e..1be5d10b5d 100644 --- a/src/kits/interface/MenuField.cpp +++ b/src/kits/interface/MenuField.cpp @@ -131,9 +131,6 @@ struct BMenuField::LayoutData { // #pragma mark - -static float kVMargin = 2.0f; - - BMenuField::BMenuField(BRect frame, const char* name, const char* label, BMenu* menu, uint32 resizingMode, uint32 flags) :