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:
@@ -34,7 +34,8 @@ class BMenuWindow : public BWindow {
|
|||||||
void AttachScrollers();
|
void AttachScrollers();
|
||||||
void DetachScrollers();
|
void DetachScrollers();
|
||||||
|
|
||||||
bool CheckForScrolling(BPoint cursor);
|
bool CheckForScrolling(const BPoint &cursor);
|
||||||
|
bool TryScrollBy(const float &step);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BMenu *fMenu;
|
BMenu *fMenu;
|
||||||
@@ -45,7 +46,8 @@ class BMenuWindow : public BWindow {
|
|||||||
float fValue;
|
float fValue;
|
||||||
float fLimit;
|
float fLimit;
|
||||||
|
|
||||||
bool _Scroll(BPoint cursor);
|
bool _Scroll(const BPoint &cursor);
|
||||||
|
void _ScrollBy(const float &step);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace BPrivate
|
} // namespace BPrivate
|
||||||
|
|||||||
@@ -813,7 +813,30 @@ BMenu::Superitem() const
|
|||||||
void
|
void
|
||||||
BMenu::MessageReceived(BMessage *msg)
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -336,7 +336,7 @@ BMenuWindow::DetachScrollers()
|
|||||||
|
|
||||||
|
|
||||||
bool
|
bool
|
||||||
BMenuWindow::CheckForScrolling(BPoint cursor)
|
BMenuWindow::CheckForScrolling(const BPoint &cursor)
|
||||||
{
|
{
|
||||||
if (!fMenuFrame || !fUpperScroller || !fLowerScroller)
|
if (!fMenuFrame || !fUpperScroller || !fLowerScroller)
|
||||||
return false;
|
return false;
|
||||||
@@ -346,17 +346,45 @@ BMenuWindow::CheckForScrolling(BPoint cursor)
|
|||||||
|
|
||||||
|
|
||||||
bool
|
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((fLowerScroller != NULL));
|
||||||
ASSERT((fUpperScroller != NULL));
|
ASSERT((fUpperScroller != NULL));
|
||||||
|
|
||||||
ConvertFromScreen(&cursor);
|
const BPoint cursor = ConvertFromScreen(where);
|
||||||
|
|
||||||
BRect lowerFrame = fLowerScroller->Frame();
|
BRect lowerFrame = fLowerScroller->Frame();
|
||||||
BRect upperFrame = fUpperScroller->Frame();
|
BRect upperFrame = fUpperScroller->Frame();
|
||||||
|
|
||||||
if (fLowerScroller->IsEnabled() && lowerFrame.Contains(cursor)) {
|
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) {
|
if (fValue == 0) {
|
||||||
fUpperScroller->SetEnabled(true);
|
fUpperScroller->SetEnabled(true);
|
||||||
fUpperScroller->Invalidate();
|
fUpperScroller->Invalidate();
|
||||||
@@ -374,7 +402,7 @@ BMenuWindow::_Scroll(BPoint cursor)
|
|||||||
fMenu->ScrollBy(0, kScrollStep);
|
fMenu->ScrollBy(0, kScrollStep);
|
||||||
fValue += kScrollStep;
|
fValue += kScrollStep;
|
||||||
}
|
}
|
||||||
} else if (fUpperScroller->IsEnabled() && upperFrame.Contains(cursor)) {
|
} else if (step < 0) {
|
||||||
if (fValue == fLimit) {
|
if (fValue == fLimit) {
|
||||||
fLowerScroller->SetEnabled(true);
|
fLowerScroller->SetEnabled(true);
|
||||||
fLowerScroller->Invalidate();
|
fLowerScroller->Invalidate();
|
||||||
@@ -390,11 +418,6 @@ BMenuWindow::_Scroll(BPoint cursor)
|
|||||||
fMenu->ScrollBy(0, -kScrollStep);
|
fMenu->ScrollBy(0, -kScrollStep);
|
||||||
fValue -= kScrollStep;
|
fValue -= kScrollStep;
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
return false;
|
|
||||||
|
|
||||||
snooze(10000);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user