Menus can be scrolled also using the mouse wheel

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27844 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Stefano Ceccherini 2008-10-03 06:03:27 +00:00
parent bf732017df
commit 4e0c2a797d
3 changed files with 62 additions and 14 deletions

View File

@ -34,8 +34,9 @@ class BMenuWindow : public BWindow {
void AttachScrollers();
void DetachScrollers();
bool CheckForScrolling(BPoint cursor);
bool CheckForScrolling(const BPoint &cursor);
bool TryScrollBy(const float &step);
private:
BMenu *fMenu;
BMenuFrame *fMenuFrame;
@ -45,7 +46,8 @@ class BMenuWindow : public BWindow {
float fValue;
float fLimit;
bool _Scroll(BPoint cursor);
bool _Scroll(const BPoint &cursor);
void _ScrollBy(const float &step);
};
} // namespace BPrivate

View File

@ -813,7 +813,30 @@ BMenu::Superitem() const
void
BMenu::MessageReceived(BMessage *msg)
{
BView::MessageReceived(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;
BMenuWindow *window = dynamic_cast<BMenuWindow *>(Window());
if (window == NULL)
return;
window->TryScrollBy(deltaY);
break;
}
default:
BView::MessageReceived(msg);
break;
}
}

View File

@ -336,7 +336,7 @@ BMenuWindow::DetachScrollers()
bool
BMenuWindow::CheckForScrolling(BPoint cursor)
BMenuWindow::CheckForScrolling(const BPoint &cursor)
{
if (!fMenuFrame || !fUpperScroller || !fLowerScroller)
return false;
@ -346,17 +346,45 @@ BMenuWindow::CheckForScrolling(BPoint cursor)
bool
BMenuWindow::_Scroll(BPoint cursor)
BMenuWindow::TryScrollBy(const float &step)
{
if (!fMenuFrame || !fUpperScroller || !fLowerScroller)
return false;
_ScrollBy(step);
return true;
}
bool
BMenuWindow::_Scroll(const BPoint &where)
{
ASSERT((fLowerScroller != NULL));
ASSERT((fUpperScroller != NULL));
ConvertFromScreen(&cursor);
const BPoint cursor = ConvertFromScreen(where);
BRect lowerFrame = fLowerScroller->Frame();
BRect upperFrame = fUpperScroller->Frame();
if (fLowerScroller->IsEnabled() && lowerFrame.Contains(cursor)) {
_ScrollBy(1);
} else if (fUpperScroller->IsEnabled() && upperFrame.Contains(cursor)) {
_ScrollBy(-1);
} else
return false;
snooze(10000);
return true;
}
void
BMenuWindow::_ScrollBy(const float &step)
{
if (step > 0) {
if (fValue == 0) {
fUpperScroller->SetEnabled(true);
fUpperScroller->Invalidate();
@ -374,7 +402,7 @@ BMenuWindow::_Scroll(BPoint cursor)
fMenu->ScrollBy(0, kScrollStep);
fValue += kScrollStep;
}
} else if (fUpperScroller->IsEnabled() && upperFrame.Contains(cursor)) {
} else if (step < 0) {
if (fValue == fLimit) {
fLowerScroller->SetEnabled(true);
fLowerScroller->Invalidate();
@ -390,11 +418,6 @@ BMenuWindow::_Scroll(BPoint cursor)
fMenu->ScrollBy(0, -kScrollStep);
fValue -= kScrollStep;
}
} else
return false;
snooze(10000);
return true;
}
}