* Dispatch the mousewheel-action to the window. * The window will scroll any compatible scrollbars if the mouse is pointed over the bar or its contents * @param w Window * @param nwid the widget where the scrollwheel was used * @param wheel scroll up or down */
| 818 | * @param wheel scroll up or down |
| 819 | */ |
| 820 | static void DispatchMouseWheelEvent(Window *w, NWidgetCore *nwid, int wheel) |
| 821 | { |
| 822 | if (nwid == nullptr) return; |
| 823 | |
| 824 | /* Using wheel on caption/shade-box shades or unshades the window. */ |
| 825 | if (nwid->type == WWT_CAPTION || nwid->type == WWT_SHADEBOX) { |
| 826 | w->SetShaded(wheel < 0); |
| 827 | return; |
| 828 | } |
| 829 | |
| 830 | /* Wheeling a vertical scrollbar. */ |
| 831 | if (nwid->type == NWID_VSCROLLBAR) { |
| 832 | NWidgetScrollbar *sb = static_cast<NWidgetScrollbar *>(nwid); |
| 833 | if (sb->GetCount() > sb->GetCapacity()) { |
| 834 | if (sb->UpdatePosition(wheel)) { |
| 835 | w->OnScrollbarScroll(nwid->GetIndex()); |
| 836 | w->SetDirty(); |
| 837 | } |
| 838 | } |
| 839 | return; |
| 840 | } |
| 841 | |
| 842 | /* Scroll the widget attached to the scrollbar. */ |
| 843 | Scrollbar *sb = (nwid->GetScrollbarIndex() >= 0 ? w->GetScrollbar(nwid->GetScrollbarIndex()) : nullptr); |
| 844 | if (sb != nullptr && sb->GetCount() > sb->GetCapacity()) { |
| 845 | if (sb->UpdatePosition(wheel)) { |
| 846 | w->OnScrollbarScroll(nwid->GetScrollbarIndex()); |
| 847 | w->SetDirty(); |
| 848 | } |
| 849 | } |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Returns whether a window may be shown or not. |
no test coverage detected