From 08e29d7e2c16de74243be2bfbc4f380584b986ef Mon Sep 17 00:00:00 2001
From: Jessica Hamilton <jessica.l.hamilton@gmail.com>
Date: Sat, 4 May 2013 00:13:41 +1200
Subject: [PATCH] BMenu: scroll marked item into view when menu has scrollers
attached.
---
headers/private/interface/MenuWindow.h | 1 +
src/kits/interface/Menu.cpp | 14 ++++++++++++++
src/kits/interface/MenuWindow.cpp | 11 +++++++++++
3 files changed, 26 insertions(+)
diff --git a/headers/private/interface/MenuWindow.h b/headers/private/interface/MenuWindow.h
index 80c0371..eb1b943 100644
a
|
b
|
public:
|
40 | 40 | bool HasScrollers() const; |
41 | 41 | bool CheckForScrolling(const BPoint& cursor); |
42 | 42 | bool TryScrollBy(const float& step); |
| 43 | bool TryScrollTo(const float& where); |
43 | 44 | |
44 | 45 | private: |
45 | 46 | bool _Scroll(const BPoint& cursor); |
diff --git a/src/kits/interface/Menu.cpp b/src/kits/interface/Menu.cpp
index e8b7283..97373d6 100644
a
|
b
|
BMenu::_UpdateWindowViewSize(const bool &move)
|
2871 | 2871 | } |
2872 | 2872 | |
2873 | 2873 | window->AttachScrollers(); |
| 2874 | |
| 2875 | BMenuItem* selectedItem = FindMarked(); |
| 2876 | if (selectedItem != NULL && fLayout == B_ITEMS_IN_COLUMN) { |
| 2877 | // scroll to the selected item |
| 2878 | if (Supermenu() == NULL) { |
| 2879 | window->TryScrollTo(selectedItem->Frame().top); |
| 2880 | } else { |
| 2881 | BPoint point = selectedItem->Frame().LeftTop(); |
| 2882 | BPoint superpoint = Superitem()->Frame().LeftTop(); |
| 2883 | Supermenu()->ConvertToScreen(&superpoint); |
| 2884 | ConvertToScreen(&point); |
| 2885 | window->TryScrollTo(point.y - superpoint.y); |
| 2886 | } |
| 2887 | } |
2874 | 2888 | } |
2875 | 2889 | } else { |
2876 | 2890 | _CacheFontInfo(); |
diff --git a/src/kits/interface/MenuWindow.cpp b/src/kits/interface/MenuWindow.cpp
index b568f75..9523f67 100644
a
|
b
|
BMenuWindow::TryScrollBy(const float& step)
|
413 | 413 | |
414 | 414 | |
415 | 415 | bool |
| 416 | BMenuWindow::TryScrollTo(const float& where) |
| 417 | { |
| 418 | if (!fMenuFrame || !fUpperScroller || !fLowerScroller) |
| 419 | return false; |
| 420 | |
| 421 | _ScrollBy(where - fValue); |
| 422 | return true; |
| 423 | } |
| 424 | |
| 425 | |
| 426 | bool |
416 | 427 | BMenuWindow::_Scroll(const BPoint& where) |
417 | 428 | { |
418 | 429 | ASSERT((fLowerScroller != NULL)); |