* fixed size layout of BMenuBar on BMenuField in fixed size mode
(needs to account for the parts that the BMenuField draws, ie the shadow on the right) * fixed follow mode of BMenuBar in fixed size mode (B_FOLLOW_LEFT_RIGHT) * don't resize the BMenuField in fixed size mode (endless loop), this should be more robust anyways, since this endless loop would be triggered if an application tried to manually resize menuField->MenuBar() in auto resizing mode * fixed calculation of the parts that need to be redrawn on resize git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22127 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
caacab3726
commit
3a38a48561
@ -57,6 +57,7 @@ private:
|
||||
bool fFixedSize;
|
||||
BMessageRunner *fRunner;
|
||||
bool fShowPopUpMarker;
|
||||
float fPreviousWidth;
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user