CalcFrame() no longer returns the maximum frame, but the one that should be

used.
Changed CalcFrame() so that it tries to find the best on-screen location - works
already, though it might have to be improved.
Moved ScreenLocation() so that it's close to CalcFrame(). Changed the position
for B_ITEMS_IN_COLUMNS a bit (they now appear one pixel lower).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13470 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-07-05 23:14:01 +00:00
parent 5c228514df
commit 4da171eff7
+54 -32
View File
@@ -886,29 +886,6 @@ BMenu::BMenu(BRect frame, const char *name, uint32 resizingMode, uint32 flags,
} }
BPoint
BMenu::ScreenLocation()
{
BMenu *superMenu = Supermenu();
BMenuItem *superItem = Superitem();
if (superMenu == NULL && superItem == NULL) {
debugger("BMenu can't determine where to draw."
"Override BMenu::ScreenLocation() to determine location.");
}
BPoint point;
if (superMenu->Layout() == B_ITEMS_IN_COLUMN)
point = superItem->Frame().RightTop();
else
point = superItem->Frame().LeftBottom() + BPoint(1.0f, 1.0f);
superMenu->ConvertToScreen(&point);
return point;
}
void void
BMenu::SetItemMargins(float left, float top, float right, float bottom) BMenu::SetItemMargins(float left, float top, float right, float bottom)
{ {
@@ -1359,6 +1336,7 @@ BMenu::ComputeLayout(int32 index, bool bestFit, bool moveItems,
BRect BRect
BMenu::Bump(BRect current, BPoint extent, int32 index) const BMenu::Bump(BRect current, BPoint extent, int32 index) const
{ {
// ToDo: what's this?
return BRect(); return BRect();
} }
@@ -1366,16 +1344,61 @@ BMenu::Bump(BRect current, BPoint extent, int32 index) const
BPoint BPoint
BMenu::ItemLocInRect(BRect frame) const BMenu::ItemLocInRect(BRect frame) const
{ {
// ToDo: what's this?
return BPoint(); return BPoint();
} }
BPoint
BMenu::ScreenLocation()
{
BMenu *superMenu = Supermenu();
BMenuItem *superItem = Superitem();
if (superMenu == NULL && superItem == NULL) {
debugger("BMenu can't determine where to draw."
"Override BMenu::ScreenLocation() to determine location.");
}
BPoint point;
if (superMenu->Layout() == B_ITEMS_IN_COLUMN)
point = superItem->Frame().RightTop() + BPoint(1.0f, 1.0f);
else
point = superItem->Frame().LeftBottom() + BPoint(1.0f, 1.0f);
superMenu->ConvertToScreen(&point);
return point;
}
BRect BRect
BMenu::CalcFrame(BPoint where, bool *scrollOn) BMenu::CalcFrame(BPoint where, bool *scrollOn)
{ {
// TODO: Improve me // TODO: Improve me
BRect frame = BScreen(MenuWindow()).Frame(); BRect bounds = Bounds();
frame.left += where.x + 2; BRect frame = bounds.OffsetToCopy(where);
BScreen screen(Window());
BRect screenFrame = screen.Frame();
BMenu *superMenu = Supermenu();
BMenuItem *superItem = Superitem();
if (superMenu->Layout() == B_ITEMS_IN_COLUMN) {
if (frame.right > screenFrame.right)
frame.OffsetBy(-superItem->Frame().Width() - frame.Width() - 2, 0);
if (frame.bottom > screenFrame.bottom)
frame.OffsetBy(0, screenFrame.bottom - frame.bottom);
} else {
if (frame.bottom > screenFrame.bottom)
frame.OffsetBy(0, -superItem->Frame().Height() - frame.Height() - 3);
if (frame.right > screenFrame.right)
frame.OffsetBy(screenFrame.right - frame.right, 0);
}
return frame; return frame;
} }
@@ -1688,13 +1711,12 @@ BMenu::UpdateWindowViewSize(bool upWind)
// TODO: Improve this, we already resize the menu // TODO: Improve this, we already resize the menu
// in "LayoutItems()" // in "LayoutItems()"
bool scroll; bool scroll;
BRect maxFrame = CalcFrame(ScreenLocation(), &scroll); BRect frame = CalcFrame(ScreenLocation(), &scroll);
float width = min_c(Frame().Width(), maxFrame.Width()); //float width = min_c(Frame().Width(), maxFrame.Width());
ResizeTo(width, Frame().Height()); ResizeTo(frame.Width(), frame.Height());
if (fCachedMenuWindow != NULL) {
fCachedMenuWindow->ResizeTo(Bounds().Width() + 2, Bounds().Height() + 2); fCachedMenuWindow->ResizeTo(Bounds().Width() + 2, Bounds().Height() + 2);
fCachedMenuWindow->MoveTo(ScreenLocation()); fCachedMenuWindow->MoveTo(frame.LeftTop());
}
} }