diff --git a/headers/private/interface/BMCPrivate.h b/headers/private/interface/BMCPrivate.h index c6f0bdead3..82097168d1 100644 --- a/headers/private/interface/BMCPrivate.h +++ b/headers/private/interface/BMCPrivate.h @@ -57,6 +57,7 @@ private: bool fFixedSize; BMessageRunner *fRunner; bool fShowPopUpMarker; + float fPreviousWidth; }; //------------------------------------------------------------------------------ diff --git a/src/kits/interface/BMCPrivate.cpp b/src/kits/interface/BMCPrivate.cpp index c3c1111eba..455e1b0cb0 100644 --- a/src/kits/interface/BMCPrivate.cpp +++ b/src/kits/interface/BMCPrivate.cpp @@ -55,15 +55,15 @@ _BMCFilter_::operator=(const _BMCFilter_ &) } -_BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField) - : BMenuBar(frame, "_mc_mb_", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_ITEMS_IN_ROW, - !fixed_size) +_BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixedSize, BMenuField *menuField) + : BMenuBar(frame, "_mc_mb_", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_ITEMS_IN_ROW, + !fixedSize) { SetFlags(Flags() | B_FRAME_EVENTS); SetBorder(B_BORDER_CONTENTS); fMenuField = menuField; - fFixedSize = fixed_size; + fFixedSize = fixedSize; fRunner = NULL; fShowPopUpMarker = true; @@ -76,6 +76,8 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField) SetItemMargins(left, top, right, bottom); SetMaxContentWidth(frame.Width() - (left + right)); + + fPreviousWidth = frame.Width(); } @@ -115,6 +117,8 @@ _BMCMenuBar_::AttachedToWindow() BMenuBar *menuBar = Window()->KeyMenuBar(); BMenuBar::AttachedToWindow(); + if (fFixedSize) + SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); Window()->SetKeyMenuBar(menuBar); } @@ -227,27 +231,32 @@ _BMCMenuBar_::FrameResized(float width, float height) { // we need to take care of resizing and cleaning up // the parent menu field - float diff = Frame().right - fMenuField->Bounds().right; + float diff; + if (fFixedSize) + diff = width - fPreviousWidth; + else + diff = Frame().right - fMenuField->Bounds().right; + + fPreviousWidth = width; + if (Window()) { if (diff > 0) { // clean up the dirty right border of // the menu field when enlarging BRect dirty(fMenuField->Bounds()); - dirty.left = dirty.right - 2; + dirty.left = dirty.right - diff - 2; fMenuField->Invalidate(dirty); // clean up the arrow part dirty = Bounds(); - dirty.right -= diff; - dirty.left = dirty.right - 12; + dirty.left = dirty.right - diff - 12; Invalidate(dirty); } else if (diff < 0) { // clean up the dirty right line of // the menu field when shrinking BRect dirty(fMenuField->Bounds()); - dirty.left = dirty.right + diff + 1; - dirty.right = dirty.left + 1; + dirty.left = dirty.right - 2; fMenuField->Invalidate(dirty); // clean up the arrow part @@ -257,10 +266,13 @@ _BMCMenuBar_::FrameResized(float width, float height) } } - // we have been shrinked or enlarged and need to take - // of the size of the parent menu field as well - // NOTE: no worries about follow mode, we follow left and top - fMenuField->ResizeBy(diff + 2, 0.0); + if (!fFixedSize) { + // we have been shrinked or enlarged and need to take + // of the size of the parent menu field as well + // NOTE: no worries about follow mode, we follow left and top + // in autosize mode + fMenuField->ResizeBy(diff + 2, 0.0); + } BMenuBar::FrameResized(width, height); } diff --git a/src/kits/interface/MenuField.cpp b/src/kits/interface/MenuField.cpp index 6762420e6c..382b2f38a1 100644 --- a/src/kits/interface/MenuField.cpp +++ b/src/kits/interface/MenuField.cpp @@ -526,7 +526,7 @@ BMenuField::SetDivider(float divider) fMenuBar->MoveTo(fDivider + 1, kVMargin); if (fFixedSizeMB) { - fMenuBar->ResizeTo(Bounds().Width() - fDivider + 1 - 2, + fMenuBar->ResizeTo(Bounds().Width() - fDivider - 2, dirty.Height()); } @@ -760,7 +760,7 @@ BMenuField::InitObject2() float height = floorf(fontHeight.ascent + fontHeight.descent + fontHeight.leading) + 7; - fMenuBar->ResizeTo(Bounds().Width() - fDivider, height); + fMenuBar->ResizeTo(Bounds().Width() - fDivider - 2, height); fMenuBar->AddFilter(new _BMCFilter_(this, B_MOUSE_DOWN)); } @@ -883,7 +883,7 @@ BMenuField::_InitMenuBar(BMenu* menu, BRect frame, bool fixedSize) InitMenu(menu); fMenuBar = new _BMCMenuBar_(BRect(frame.left + fDivider + 1, - frame.top + kVMargin, frame.right, frame.bottom - kVMargin), + frame.top + kVMargin, frame.right - 2, frame.bottom - kVMargin), fixedSize, this); // by default align the menu bar left in the available space