From fcfe60b02ec06525dbe76eedc110d20b7eb808f7 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 25 Jul 2012 00:35:35 -0400 Subject: [PATCH] Renamed BMenuScrollView to TScrollArrowView and moved it into Deskbar Also gave the Up Arrow and Down Arrow a scroll arrow. The up arrow works but the down arrow doesn't because the sibling menu is stealing the MouseDown event." --- src/apps/deskbar/BarView.cpp | 20 +- src/apps/deskbar/BarView.h | 4 +- src/apps/deskbar/ExpandoMenuBar.cpp | 8 +- src/apps/deskbar/Jamfile | 1 + .../deskbar/ScrollArrowView.cpp} | 248 ++++++++++-------- .../apps/deskbar/ScrollArrowView.h | 23 +- src/kits/interface/Jamfile | 1 - 7 files changed, 160 insertions(+), 145 deletions(-) rename src/{kits/interface/MenuScrollView.cpp => apps/deskbar/ScrollArrowView.cpp} (56%) rename headers/os/interface/MenuScrollView.h => src/apps/deskbar/ScrollArrowView.h (65%) diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index e915adf8e6..77b7a21c9e 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -48,7 +48,6 @@ All rights reserved. #include #include #include -#include #include #include "icons.h" @@ -60,6 +59,7 @@ All rights reserved. #include "ExpandoMenuBar.h" #include "FSUtils.h" #include "ResourceSet.h" +#include "ScrollArrowView.h" #include "StatusView.h" #include "TeamMenuItem.h" @@ -131,7 +131,7 @@ BarViewMessageFilter::Filter(BMessage* message, BHandler** target) TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, uint32 state, float) : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), - fMenuScrollView(NULL), + fScrollArrowView(NULL), fBarMenuBar(NULL), fExpando(NULL), fTrayLocation(1), @@ -450,10 +450,10 @@ TBarView::PlaceApplicationBar() fExpando = NULL; } - if (fMenuScrollView != NULL) { - fMenuScrollView->RemoveSelf(); - delete fMenuScrollView; - fMenuScrollView = NULL; + if (fScrollArrowView != NULL) { + fScrollArrowView->RemoveSelf(); + delete fScrollArrowView; + fScrollArrowView = NULL; } BRect screenFrame = (BScreen(Window())).Frame(); @@ -500,8 +500,8 @@ TBarView::PlaceApplicationBar() fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fVertical, !hideLabels && fState != kFullState); - fMenuScrollView = new BMenuScrollView(menuScrollFrame, fExpando); - AddChild(fMenuScrollView); + fScrollArrowView = new TScrollArrowView(menuScrollFrame, fExpando); + AddChild(fScrollArrowView); if (fVertical) ExpandItems(); @@ -573,9 +573,9 @@ TBarView::SizeWindow(BRect screenFrame) if (fExpando != NULL) { if (fExpando->CheckForSizeOverrun()) - fMenuScrollView->AttachScrollers(); + fScrollArrowView->AttachScrollers(); else - fMenuScrollView->DetachScrollers(); + fScrollArrowView->DetachScrollers(); } } diff --git a/src/apps/deskbar/BarView.h b/src/apps/deskbar/BarView.h index e118012300..41eea6bbd9 100644 --- a/src/apps/deskbar/BarView.h +++ b/src/apps/deskbar/BarView.h @@ -65,12 +65,12 @@ const float kStatusHeight = 22.0f; const float kHiddenDimension = 1.0f; const float kMaxPreventHidingDist = 80.0f; -class BMenuScrollView; class BShelf; class TBarMenuBar; class TExpandoMenuBar; class TReplicantTray; class TDragRegion; +class TScrollArrowView; class TTeamMenuItem; @@ -168,7 +168,7 @@ class TBarView : public BView { void ExpandItems(); void _ChangeState(BMessage* message); - BMenuScrollView* fMenuScrollView; + TScrollArrowView* fScrollArrowView; TBarMenuBar* fBarMenuBar; TExpandoMenuBar* fExpando; diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index d1ff430546..bb3a26ba33 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -42,7 +42,6 @@ All rights reserved. #include #include #include -#include #include #include #include @@ -56,6 +55,7 @@ All rights reserved. #include "DeskbarMenu.h" #include "DeskbarUtils.h" #include "ResourceSet.h" +#include "ScrollArrowView.h" #include "ShowHideMenuItem.h" #include "StatusView.h" #include "TeamMenuItem.h" @@ -269,8 +269,8 @@ TExpandoMenuBar::MessageReceived(BMessage* message) if (deltaY == 0) return; - BMenuScrollView* scrollMenu - = dynamic_cast(Parent()); + TScrollArrowView* scrollMenu + = dynamic_cast(Parent()); if (scrollMenu == NULL) return; @@ -284,7 +284,7 @@ TExpandoMenuBar::MessageReceived(BMessage* message) else deltaY *= smallStep; - scrollMenu->TryScrollBy(deltaY); + scrollMenu->ScrollBy(deltaY); break; } diff --git a/src/apps/deskbar/Jamfile b/src/apps/deskbar/Jamfile index 8fc34a1c55..86a8d55514 100644 --- a/src/apps/deskbar/Jamfile +++ b/src/apps/deskbar/Jamfile @@ -28,6 +28,7 @@ Application Deskbar : DeskbarUtils.cpp ExpandoMenuBar.cpp PreferencesWindow.cpp + ScrollArrowView.cpp ShowHideMenuItem.cpp StatusView.cpp StatusViewShelf.cpp diff --git a/src/kits/interface/MenuScrollView.cpp b/src/apps/deskbar/ScrollArrowView.cpp similarity index 56% rename from src/kits/interface/MenuScrollView.cpp rename to src/apps/deskbar/ScrollArrowView.cpp index c3faa0ebc1..8335e243bb 100644 --- a/src/kits/interface/MenuScrollView.cpp +++ b/src/apps/deskbar/ScrollArrowView.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2011, Haiku, Inc. + * Copyright 2012, Haiku, Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -9,7 +9,7 @@ */ -#include +#include "ScrollArrowView.h" #include #include @@ -24,10 +24,10 @@ const int kDefaultScrollStep = 19; const int kScrollerHeight = 12; -class BMenuScroller : public BView { +class ScrollArrow : public BView { public: - BMenuScroller(BRect frame); - virtual ~BMenuScroller(); + ScrollArrow(BRect frame); + virtual ~ScrollArrow(); bool IsEnabled() const { return fEnabled; }; void SetEnabled(bool enabled); @@ -37,28 +37,30 @@ private: }; -class BMenuUpScroller : public BMenuScroller { +class UpScrollArrow : public ScrollArrow { public: - BMenuUpScroller(BRect frame); - virtual ~BMenuUpScroller(); + UpScrollArrow(BRect frame); + virtual ~UpScrollArrow(); virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); }; -class BMenuDownScroller : public BMenuScroller { +class DownScrollArrow : public ScrollArrow { public: - BMenuDownScroller(BRect frame); - virtual ~BMenuDownScroller(); + DownScrollArrow(BRect frame); + virtual ~DownScrollArrow(); virtual void Draw(BRect updateRect); + virtual void MouseDown(BPoint where); }; // #pragma mark - -BMenuScroller::BMenuScroller(BRect frame) +ScrollArrow::ScrollArrow(BRect frame) : BView(frame, "menu scroll arrow", 0, B_WILL_DRAW | B_FRAME_EVENTS), fEnabled(false) @@ -67,13 +69,13 @@ BMenuScroller::BMenuScroller(BRect frame) } -BMenuScroller::~BMenuScroller() +ScrollArrow::~ScrollArrow() { } void -BMenuScroller::SetEnabled(bool enabled) +ScrollArrow::SetEnabled(bool enabled) { fEnabled = enabled; Invalidate(); @@ -83,20 +85,20 @@ BMenuScroller::SetEnabled(bool enabled) // #pragma mark - -BMenuUpScroller::BMenuUpScroller(BRect frame) +UpScrollArrow::UpScrollArrow(BRect frame) : - BMenuScroller(frame) + ScrollArrow(frame) { } -BMenuUpScroller::~BMenuUpScroller() +UpScrollArrow::~UpScrollArrow() { } void -BMenuUpScroller::Draw(BRect updateRect) +UpScrollArrow::Draw(BRect updateRect) { SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); @@ -117,23 +119,34 @@ BMenuUpScroller::Draw(BRect updateRect) } +void +UpScrollArrow::MouseDown(BPoint where) +{ + if (!IsEnabled()) + return; + + dynamic_cast(Parent())->ScrollBy(-kDefaultScrollStep); + snooze(5000); +} + + // #pragma mark - -BMenuDownScroller::BMenuDownScroller(BRect frame) +DownScrollArrow::DownScrollArrow(BRect frame) : - BMenuScroller(frame) + ScrollArrow(frame) { } -BMenuDownScroller::~BMenuDownScroller() +DownScrollArrow::~DownScrollArrow() { } void -BMenuDownScroller::Draw(BRect updateRect) +DownScrollArrow::Draw(BRect updateRect) { SetLowColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_1_TINT)); @@ -155,15 +168,26 @@ BMenuDownScroller::Draw(BRect updateRect) } +void +DownScrollArrow::MouseDown(BPoint where) +{ + if (!IsEnabled()) + return; + + dynamic_cast(Parent())->ScrollBy(kDefaultScrollStep); + snooze(5000); +} + + // #pragma mark - -BMenuScrollView::BMenuScrollView(BRect frame, BMenu* menu) +TScrollArrowView::TScrollArrowView(BRect frame, BMenu* menu) : BView(frame, "menu scroll view", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS), fMenu(menu), - fUpperScroller(NULL), - fLowerScroller(NULL), + fUpperScrollArrow(NULL), + fLowerScrollArrow(NULL), fScrollStep(kDefaultScrollStep), fValue(0), fLimit(0) @@ -171,24 +195,24 @@ BMenuScrollView::BMenuScrollView(BRect frame, BMenu* menu) } -BMenuScrollView::~BMenuScrollView() +TScrollArrowView::~TScrollArrowView() { - if (fUpperScroller != NULL) { - fUpperScroller->RemoveSelf(); - delete fUpperScroller; - fUpperScroller = NULL; + if (fUpperScrollArrow != NULL) { + fUpperScrollArrow->RemoveSelf(); + delete fUpperScrollArrow; + fUpperScrollArrow = NULL; } - if (fLowerScroller != NULL) { - fLowerScroller->RemoveSelf(); - delete fLowerScroller; - fLowerScroller = NULL; + if (fLowerScrollArrow != NULL) { + fLowerScrollArrow->RemoveSelf(); + delete fLowerScrollArrow; + fLowerScrollArrow = NULL; } } void -BMenuScrollView::AttachedToWindow() +TScrollArrowView::AttachedToWindow() { BView::AttachedToWindow(); @@ -201,18 +225,18 @@ BMenuScrollView::AttachedToWindow() void -BMenuScrollView::DetachedFromWindow() +TScrollArrowView::DetachedFromWindow() { BView::DetachedFromWindow(); if (fMenu != NULL) fMenu->RemoveSelf(); - if (fUpperScroller != NULL) - fUpperScroller->RemoveSelf(); + if (fUpperScrollArrow != NULL) + fUpperScrollArrow->RemoveSelf(); - if (fLowerScroller != NULL) - fLowerScroller->RemoveSelf(); + if (fLowerScrollArrow != NULL) + fLowerScrollArrow->RemoveSelf(); } @@ -220,7 +244,7 @@ BMenuScrollView::DetachedFromWindow() void -BMenuScrollView::AttachScrollers() +TScrollArrowView::AttachScrollers() { if (fMenu == NULL) return; @@ -236,23 +260,23 @@ BMenuScrollView::AttachScrollers() fMenu->MakeFocus(true); - if (fUpperScroller == NULL) { - fUpperScroller = new BMenuUpScroller( + if (fUpperScrollArrow == NULL) { + fUpperScrollArrow = new UpScrollArrow( BRect(0, 0, frame.right, kScrollerHeight - 1)); - AddChild(fUpperScroller, fMenu); + AddChild(fUpperScrollArrow); } fMenu->MoveBy(0, kScrollerHeight); - if (fLowerScroller == NULL) { - fLowerScroller = new BMenuDownScroller( + if (fLowerScrollArrow == NULL) { + fLowerScrollArrow = new DownScrollArrow( BRect(0, frame.bottom - kScrollerHeight + 1, frame.right, frame.bottom)); - AddChild(fLowerScroller); + AddChild(fLowerScrollArrow, fMenu); } - fUpperScroller->SetEnabled(false); - fLowerScroller->SetEnabled(true); + fUpperScrollArrow->SetEnabled(false); + fLowerScrollArrow->SetEnabled(true); fLimit = Window()->Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; @@ -261,21 +285,21 @@ BMenuScrollView::AttachScrollers() void -BMenuScrollView::DetachScrollers() +TScrollArrowView::DetachScrollers() { if (!HasScrollers()) return; - if (fLowerScroller) { - fLowerScroller->RemoveSelf(); - delete fLowerScroller; - fLowerScroller = NULL; + if (fLowerScrollArrow) { + fLowerScrollArrow->RemoveSelf(); + delete fLowerScrollArrow; + fLowerScrollArrow = NULL; } - if (fUpperScroller) { - fUpperScroller->RemoveSelf(); - delete fUpperScroller; - fUpperScroller = NULL; + if (fUpperScrollArrow) { + fUpperScrollArrow->RemoveSelf(); + delete fUpperScrollArrow; + fUpperScrollArrow = NULL; } if (fMenu) { @@ -289,21 +313,21 @@ BMenuScrollView::DetachScrollers() bool -BMenuScrollView::HasScrollers() const +TScrollArrowView::HasScrollers() const { - return fMenu != NULL && fUpperScroller != NULL && fLowerScroller != NULL; + return fMenu != NULL && fUpperScrollArrow != NULL && fLowerScrollArrow != NULL; } void -BMenuScrollView::SetSmallStep(float step) +TScrollArrowView::SetSmallStep(float step) { fScrollStep = step; } void -BMenuScrollView::GetSteps(float* _smallStep, float* _largeStep) const +TScrollArrowView::GetSteps(float* _smallStep, float* _largeStep) const { if (_smallStep != NULL) *_smallStep = fScrollStep; @@ -316,8 +340,45 @@ BMenuScrollView::GetSteps(float* _smallStep, float* _largeStep) const } +void +TScrollArrowView::ScrollBy(const float& step) +{ + if (!HasScrollers()) + return; + + if (step > 0) { + if (fValue == 0) + fUpperScrollArrow->SetEnabled(true); + + if (fValue + step >= fLimit) { + // If we reached the limit, only scroll to the end + fMenu->ScrollBy(0, fLimit - fValue); + fValue = fLimit; + fLowerScrollArrow->SetEnabled(false); + } else { + fMenu->ScrollBy(0, step); + fValue += step; + } + fMenu->Invalidate(); + } else if (step < 0) { + if (fValue == fLimit) + fLowerScrollArrow->SetEnabled(true); + + if (fValue + step <= 0) { + fMenu->ScrollBy(0, -fValue); + fValue = 0; + fUpperScrollArrow->SetEnabled(false); + } else { + fMenu->ScrollBy(0, step); + fValue += step; + } + fMenu->Invalidate(); + } +} + + bool -BMenuScrollView::CheckForScrolling(const BPoint &cursor) +TScrollArrowView::CheckForScrolling(const BPoint &cursor) { if (!HasScrollers()) return false; @@ -327,30 +388,19 @@ BMenuScrollView::CheckForScrolling(const BPoint &cursor) bool -BMenuScrollView::TryScrollBy(const float& step) +TScrollArrowView::_Scroll(const BPoint& where) { - if (!HasScrollers()) - return false; - - _ScrollBy(step); - return true; -} - - -bool -BMenuScrollView::_Scroll(const BPoint& where) -{ - ASSERT((fLowerScroller != NULL)); - ASSERT((fUpperScroller != NULL)); + ASSERT((fLowerScrollArrow != NULL)); + ASSERT((fUpperScrollArrow != NULL)); const BPoint cursor = ConvertFromScreen(where); - const BRect &lowerFrame = fLowerScroller->Frame(); - const BRect &upperFrame = fUpperScroller->Frame(); + const BRect &lowerFrame = fLowerScrollArrow->Frame(); + const BRect &upperFrame = fUpperScrollArrow->Frame(); int32 delta = 0; - if (fLowerScroller->IsEnabled() && lowerFrame.Contains(cursor)) + if (fLowerScrollArrow->IsEnabled() && lowerFrame.Contains(cursor)) delta = 1; - else if (fUpperScroller->IsEnabled() && upperFrame.Contains(cursor)) + else if (fUpperScrollArrow->IsEnabled() && upperFrame.Contains(cursor)) delta = -1; if (delta == 0) @@ -358,43 +408,9 @@ BMenuScrollView::_Scroll(const BPoint& where) float smallStep; GetSteps(&smallStep, NULL); - _ScrollBy(smallStep * delta); + ScrollBy(smallStep * delta); snooze(5000); return true; } - - -void -BMenuScrollView::_ScrollBy(const float& step) -{ - if (step > 0) { - if (fValue == 0) - fUpperScroller->SetEnabled(true); - - if (fValue + step >= fLimit) { - // If we reached the limit, only scroll to the end - fMenu->ScrollBy(0, fLimit - fValue); - fValue = fLimit; - fLowerScroller->SetEnabled(false); - } else { - fMenu->ScrollBy(0, step); - fValue += step; - } - fMenu->Invalidate(); - } else if (step < 0) { - if (fValue == fLimit) - fLowerScroller->SetEnabled(true); - - if (fValue + step <= 0) { - fMenu->ScrollBy(0, -fValue); - fValue = 0; - fUpperScroller->SetEnabled(false); - } else { - fMenu->ScrollBy(0, step); - fValue += step; - } - fMenu->Invalidate(); - } -} diff --git a/headers/os/interface/MenuScrollView.h b/src/apps/deskbar/ScrollArrowView.h similarity index 65% rename from headers/os/interface/MenuScrollView.h rename to src/apps/deskbar/ScrollArrowView.h index 37359a82fa..ad2b1893b0 100644 --- a/headers/os/interface/MenuScrollView.h +++ b/src/apps/deskbar/ScrollArrowView.h @@ -1,5 +1,5 @@ /* - * Copyright 2011, Haiku, Inc. + * Copyright 2012, Haiku, Inc. * Distributed under the terms of the MIT License. * * Authors: @@ -7,22 +7,22 @@ * Stefano Ceccherini (stefano.ceccherini@gmail.com) * John Scipione (jscipione@gmail.com) */ -#ifndef MENU_SCROLL_VIEW_H -#define MENU_SCROLL_VIEW_H +#ifndef SCROLL_ARROW_VIEW_H +#define SCROLL_ARROW_VIEW_H #include class BLayout; class BMenu; -class BMenuScroller; +class ScrollArrow; class BPoint; -class BMenuScrollView : public BView { +class TScrollArrowView : public BView { public: - BMenuScrollView(BRect frame, BMenu* menu); - virtual ~BMenuScrollView(); + TScrollArrowView(BRect frame, BMenu* menu); + virtual ~TScrollArrowView(); virtual void AttachedToWindow(); virtual void DetachedFromWindow(); @@ -35,16 +35,15 @@ public: void GetSteps(float* _smallStep, float* _largeStep) const; bool CheckForScrolling(const BPoint& cursor); - bool TryScrollBy(const float& step); + void ScrollBy(const float& step); protected: bool _Scroll(const BPoint& cursor); - void _ScrollBy(const float& step); private: BMenu* fMenu; - BMenuScroller* fUpperScroller; - BMenuScroller* fLowerScroller; + ScrollArrow* fUpperScrollArrow; + ScrollArrow* fLowerScrollArrow; float fScrollStep; float fValue; @@ -52,4 +51,4 @@ private: }; -#endif // MENU_SCROLL_VIEW_H +#endif // SCROLL_ARROW_VIEW_H diff --git a/src/kits/interface/Jamfile b/src/kits/interface/Jamfile index 5726843de7..81c59e0b32 100644 --- a/src/kits/interface/Jamfile +++ b/src/kits/interface/Jamfile @@ -82,7 +82,6 @@ MergeObject interface_kit.o : MenuField.cpp MenuItem.cpp MenuPrivate.cpp - MenuScrollView.cpp MenuWindow.cpp OptionControl.cpp OptionPopUp.cpp