* 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:
Stephan Aßmus
2007-08-30 22:36:14 +00:00
parent caacab3726
commit 3a38a48561
3 changed files with 30 additions and 17 deletions
+1
View File
@@ -57,6 +57,7 @@ private:
bool fFixedSize; bool fFixedSize;
BMessageRunner *fRunner; BMessageRunner *fRunner;
bool fShowPopUpMarker; bool fShowPopUpMarker;
float fPreviousWidth;
}; };
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
+26 -14
View File
@@ -55,15 +55,15 @@ _BMCFilter_::operator=(const _BMCFilter_ &)
} }
_BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField) _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixedSize, BMenuField *menuField)
: BMenuBar(frame, "_mc_mb_", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_ITEMS_IN_ROW, : BMenuBar(frame, "_mc_mb_", B_FOLLOW_LEFT | B_FOLLOW_TOP, B_ITEMS_IN_ROW,
!fixed_size) !fixedSize)
{ {
SetFlags(Flags() | B_FRAME_EVENTS); SetFlags(Flags() | B_FRAME_EVENTS);
SetBorder(B_BORDER_CONTENTS); SetBorder(B_BORDER_CONTENTS);
fMenuField = menuField; fMenuField = menuField;
fFixedSize = fixed_size; fFixedSize = fixedSize;
fRunner = NULL; fRunner = NULL;
fShowPopUpMarker = true; fShowPopUpMarker = true;
@@ -76,6 +76,8 @@ _BMCMenuBar_::_BMCMenuBar_(BRect frame, bool fixed_size, BMenuField *menuField)
SetItemMargins(left, top, right, bottom); SetItemMargins(left, top, right, bottom);
SetMaxContentWidth(frame.Width() - (left + right)); SetMaxContentWidth(frame.Width() - (left + right));
fPreviousWidth = frame.Width();
} }
@@ -115,6 +117,8 @@ _BMCMenuBar_::AttachedToWindow()
BMenuBar *menuBar = Window()->KeyMenuBar(); BMenuBar *menuBar = Window()->KeyMenuBar();
BMenuBar::AttachedToWindow(); BMenuBar::AttachedToWindow();
if (fFixedSize)
SetResizingMode(B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP);
Window()->SetKeyMenuBar(menuBar); Window()->SetKeyMenuBar(menuBar);
} }
@@ -227,27 +231,32 @@ _BMCMenuBar_::FrameResized(float width, float height)
{ {
// we need to take care of resizing and cleaning up // we need to take care of resizing and cleaning up
// the parent menu field // 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 (Window()) {
if (diff > 0) { if (diff > 0) {
// clean up the dirty right border of // clean up the dirty right border of
// the menu field when enlarging // the menu field when enlarging
BRect dirty(fMenuField->Bounds()); BRect dirty(fMenuField->Bounds());
dirty.left = dirty.right - 2; dirty.left = dirty.right - diff - 2;
fMenuField->Invalidate(dirty); fMenuField->Invalidate(dirty);
// clean up the arrow part // clean up the arrow part
dirty = Bounds(); dirty = Bounds();
dirty.right -= diff; dirty.left = dirty.right - diff - 12;
dirty.left = dirty.right - 12;
Invalidate(dirty); Invalidate(dirty);
} else if (diff < 0) { } else if (diff < 0) {
// clean up the dirty right line of // clean up the dirty right line of
// the menu field when shrinking // the menu field when shrinking
BRect dirty(fMenuField->Bounds()); BRect dirty(fMenuField->Bounds());
dirty.left = dirty.right + diff + 1; dirty.left = dirty.right - 2;
dirty.right = dirty.left + 1;
fMenuField->Invalidate(dirty); fMenuField->Invalidate(dirty);
// clean up the arrow part // 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 if (!fFixedSize) {
// of the size of the parent menu field as well // we have been shrinked or enlarged and need to take
// NOTE: no worries about follow mode, we follow left and top // of the size of the parent menu field as well
fMenuField->ResizeBy(diff + 2, 0.0); // NOTE: no worries about follow mode, we follow left and top
// in autosize mode
fMenuField->ResizeBy(diff + 2, 0.0);
}
BMenuBar::FrameResized(width, height); BMenuBar::FrameResized(width, height);
} }
+3 -3
View File
@@ -526,7 +526,7 @@ BMenuField::SetDivider(float divider)
fMenuBar->MoveTo(fDivider + 1, kVMargin); fMenuBar->MoveTo(fDivider + 1, kVMargin);
if (fFixedSizeMB) { if (fFixedSizeMB) {
fMenuBar->ResizeTo(Bounds().Width() - fDivider + 1 - 2, fMenuBar->ResizeTo(Bounds().Width() - fDivider - 2,
dirty.Height()); dirty.Height());
} }
@@ -760,7 +760,7 @@ BMenuField::InitObject2()
float height = floorf(fontHeight.ascent + fontHeight.descent float height = floorf(fontHeight.ascent + fontHeight.descent
+ fontHeight.leading) + 7; + fontHeight.leading) + 7;
fMenuBar->ResizeTo(Bounds().Width() - fDivider, height); fMenuBar->ResizeTo(Bounds().Width() - fDivider - 2, height);
fMenuBar->AddFilter(new _BMCFilter_(this, B_MOUSE_DOWN)); fMenuBar->AddFilter(new _BMCFilter_(this, B_MOUSE_DOWN));
} }
@@ -883,7 +883,7 @@ BMenuField::_InitMenuBar(BMenu* menu, BRect frame, bool fixedSize)
InitMenu(menu); InitMenu(menu);
fMenuBar = new _BMCMenuBar_(BRect(frame.left + fDivider + 1, 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); fixedSize, this);
// by default align the menu bar left in the available space // by default align the menu bar left in the available space