* BMenu now scrolls when you press page up/down, if possible.

* BMenuWindow no longer uses a fixed scroll step - instead, the menu sets it
  to the height of its first item.
* Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31389 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-07-03 12:09:16 +00:00
parent 9515252e02
commit 4e23bc0383
3 changed files with 136 additions and 80 deletions
+33 -9
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2001-2008, Haiku, Inc.
* Copyright 2001-2009, Haiku, Inc.
* Distributed under the terms of the MIT License.
*
* Authors:
@@ -8,6 +8,8 @@
* Rene Gollent ([email protected])
*/
#include <Menu.h>
#include <new>
#include <ctype.h>
#include <string.h>
@@ -18,13 +20,13 @@
#include <FindDirectory.h>
#include <Layout.h>
#include <LayoutUtils.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
#include <Messenger.h>
#include <Path.h>
#include <PropertyInfo.h>
#include <Screen.h>
#include <ScrollBar.h>
#include <Window.h>
#include <AppServerLink.h>
@@ -819,9 +821,7 @@ BMenu::MessageReceived(BMessage *msg)
switch (msg->what) {
case B_MOUSE_WHEEL_CHANGED:
{
//float deltaX = 0
float deltaY = 0;
//msg->FindFloat("be:wheel_delta_x", &deltaX);
msg->FindFloat("be:wheel_delta_y", &deltaY);
if (deltaY == 0)
return;
@@ -830,7 +830,9 @@ BMenu::MessageReceived(BMessage *msg)
if (window == NULL)
return;
window->TryScrollBy(deltaY);
float smallStep;
window->GetSteps(&smallStep, NULL);
window->TryScrollBy(deltaY * smallStep);
break;
}
default:
@@ -890,6 +892,21 @@ BMenu::KeyDown(const char *bytes, int32 numBytes)
}
break;
case B_PAGE_UP:
case B_PAGE_DOWN:
{
BMenuWindow *window = dynamic_cast<BMenuWindow *>(Window());
if (window == NULL || !window->HasScrollers())
break;
int32 deltaY = bytes[0] == B_PAGE_UP ? -1 : 1;
float largeStep;
window->GetSteps(NULL, &largeStep);
window->TryScrollBy(deltaY * largeStep);
break;
}
case B_ENTER:
case B_SPACE:
if (fSelected) {
@@ -1426,6 +1443,13 @@ BMenu::_Show(bool selectFirstItem)
fAttachAborted = false;
window->AttachMenu(this);
if (ItemAt(0) != NULL) {
float width, height;
ItemAt(0)->GetContentSize(&width, &height);
window->SetSmallStep(ceilf(height));
}
// Menu didn't have the time to add its items: aborting...
if (fAttachAborted) {
window->DetachMenu();
@@ -2213,7 +2237,7 @@ BMenu::_CalcFrame(BPoint where, bool *scrollOn)
if (frame.right > screenFrame.right)
frame.OffsetBy(screenFrame.right - frame.right, 0);
}
if (!scroll) {
// basically, if this returns false, it means
// that the menu frame won't fit completely inside the screen
@@ -2221,10 +2245,10 @@ BMenu::_CalcFrame(BPoint where, bool *scrollOn)
// not left/right
scroll = screenFrame.Height() < frame.Height();
}
if (scrollOn != NULL)
*scrollOn = scroll;
return frame;
}
@@ -2286,7 +2310,7 @@ BMenu::_InvokeItem(BMenuItem *item, bool now)
rootMenu = parent;
parent = rootMenu->Supermenu();
} while (parent != NULL);
if (rootMenu->LockLooper()) {
item->Invoke();
rootMenu->UnlockLooper();