diff --git a/headers/os/interface/MenuScrollView.h b/headers/os/interface/MenuScrollView.h index 2a1904e437..1a1cb6dea9 100644 --- a/headers/os/interface/MenuScrollView.h +++ b/headers/os/interface/MenuScrollView.h @@ -16,17 +16,17 @@ class BLayout; class BMenu; class BMenuScroller; +class BPoint; class BMenuScrollView : public BView { public: - BMenuScrollView(BMenu* menu); + BMenuScrollView(BRect frame, BMenu* menu); virtual ~BMenuScrollView(); virtual void AttachedToWindow(); virtual void DetachedFromWindow(); - virtual void Draw(BRect updateRect); - virtual void FrameResized(float newWidth, float newHeight); + virtual void MouseDown(BPoint where); void AttachScrollers(); void DetachScrollers(); @@ -34,6 +34,7 @@ public: void SetSmallStep(float step); void GetSteps(float* _smallStep, float* _largeStep) const; + bool CheckForScrolling(const BPoint& cursor); bool TryScrollBy(const float& step); diff --git a/src/apps/deskbar/BarView.cpp b/src/apps/deskbar/BarView.cpp index d174166929..a1307ea3b5 100644 --- a/src/apps/deskbar/BarView.cpp +++ b/src/apps/deskbar/BarView.cpp @@ -443,6 +443,9 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap) void TBarView::PlaceApplicationBar() { + if (fExpando != NULL) + SaveExpandedItems(); + if (fMenuScrollView != NULL) { fMenuScrollView->RemoveSelf(); delete fMenuScrollView; @@ -455,10 +458,16 @@ TBarView::PlaceApplicationBar() fExpando = NULL; } - if (fState == kMiniState) - return; - BRect screenFrame = (BScreen(Window())).Frame(); + if (fState == kMiniState) { + SizeWindow(screenFrame); + PositionWindow(screenFrame); + Window()->UpdateIfNeeded(); + Invalidate(); + return; + } + + BRect menuScrollFrame(0, 0, 0, 0); BRect expandoFrame(0, 0, 0, 0); if (fVertical) { // top left/right @@ -472,6 +481,9 @@ TBarView::PlaceApplicationBar() expandoFrame.right = fBarMenuBar->Frame().Width(); else expandoFrame.right = sMinimumWindowWidth; + + menuScrollFrame = expandoFrame; + menuScrollFrame.bottom = screenFrame.bottom; } else { // top or bottom expandoFrame.top = 0; @@ -481,6 +493,8 @@ TBarView::PlaceApplicationBar() expandoFrame.right = fDragRegion->Frame().left - 1; else expandoFrame.right = screenFrame.Width(); + + menuScrollFrame = expandoFrame; } bool hideLabels = ((TBarApp*)be_app)->Settings()->hideLabels; @@ -488,9 +502,8 @@ TBarView::PlaceApplicationBar() fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fVertical, !hideLabels && fState != kFullState); - fMenuScrollView = new BMenuScrollView(fExpando); + fMenuScrollView = new BMenuScrollView(menuScrollFrame, fExpando); AddChild(fMenuScrollView); -//printf("fExpando bottom: %f, fMenuScrollView bottom: %f\n", fExpando->Frame().bottom, fMenuScrollView->Frame().bottom); if (fVertical) ExpandItems(); @@ -527,7 +540,12 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height) } else if (fState == kExpandoState) { if (fVertical) { // top left or right - windowHeight = fMenuScrollView->Frame().bottom; + if (fTrayLocation != 0) + windowHeight = fDragRegion->Frame().bottom + 1; + else + windowHeight = fBarMenuBar->Frame().bottom + 1; + + windowHeight += fExpando->Bounds().Height(); } else { // top or bottom, full fExpando->CheckItemSizes(0); @@ -556,11 +574,10 @@ TBarView::SizeWindow(BRect screenFrame) Window()->ResizeTo(windowWidth, windowHeight); if (fExpando != NULL) { - if (fMenuScrollView != NULL) { - fMenuScrollView->ResizeTo(fExpando->Bounds().Width(), - fExpando->Bounds().Height()); - } - fExpando->CheckForSizeOverrun(); + if (fExpando->CheckForSizeOverrun()) + fMenuScrollView->AttachScrollers(); + else + fMenuScrollView->DetachScrollers(); } } diff --git a/src/apps/deskbar/ExpandoMenuBar.cpp b/src/apps/deskbar/ExpandoMenuBar.cpp index 246d7bfcf2..2b9bacbd97 100644 --- a/src/apps/deskbar/ExpandoMenuBar.cpp +++ b/src/apps/deskbar/ExpandoMenuBar.cpp @@ -83,7 +83,6 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name, fVertical(vertical), fOverflow(false), fDrawLabel(drawLabel), - fIsScrolling(false), fShowTeamExpander(static_cast(be_app)->Settings()->superExpando), fExpandNewTeams(static_cast(be_app)->Settings()->expandNewTeams), fDeskbarMenuWidth(kDefaultDeskbarMenuWidth), @@ -194,10 +193,6 @@ TExpandoMenuBar::AttachedToWindow() ResizeTo(itemWidth, 0); } - BMenuScrollView* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu != NULL) - scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height()); - if (fVertical) { sDoMonitor = true; sMonThread = spawn_thread(monitor_team_windows, @@ -427,14 +422,6 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message) // force a cleanup _FinishedDrag(); - // check for scrolling menu - BMenuScrollView* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu != NULL) { - BPoint screenLocation = ConvertToScreen(where); - while(scrollMenu->CheckForScrolling(screenLocation)) - TExpandoMenuBar::MouseMoved(where, code, message); - } - switch (code) { case B_ENTERED_VIEW: case B_INSIDE_VIEW: @@ -825,35 +812,20 @@ TExpandoMenuBar::DrawBackground(BRect) /*! Something to help determine if we are showing too many apps need to add in scrolling functionality. */ -void +bool TExpandoMenuBar::CheckForSizeOverrun() { - if (!fVertical) { - fIsScrolling = false; - return; - } - - BMenuScrollView* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu == NULL) - return; + if (!fVertical) + return false; BRect screenFrame = (BScreen(Window())).Frame(); - fIsScrolling = Window()->Frame().bottom > screenFrame.bottom; - - if (fIsScrolling) - scrollMenu->AttachScrollers(); - else - scrollMenu->DetachScrollers(); + return Window()->Frame().bottom > screenFrame.bottom; } void TExpandoMenuBar::SizeWindow(int32 delta) { - BMenuScrollView* scrollMenu = dynamic_cast(Parent()); - if (scrollMenu != NULL) - scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height()); - // instead of resizing the window here and there in the // code the resize method will be centered in one place // thus, the same behavior (good or bad) will be used diff --git a/src/apps/deskbar/ExpandoMenuBar.h b/src/apps/deskbar/ExpandoMenuBar.h index 2bd1bd68c5..5a08a0b67e 100644 --- a/src/apps/deskbar/ExpandoMenuBar.h +++ b/src/apps/deskbar/ExpandoMenuBar.h @@ -83,7 +83,7 @@ class TExpandoMenuBar : public BMenuBar { menu_layout MenuLayout() const; void SizeWindow(int32 delta); - void CheckForSizeOverrun(); + bool CheckForSizeOverrun(); private: static int CompareByName(const void* first, const void* second); @@ -98,7 +98,6 @@ class TExpandoMenuBar : public BMenuBar { bool fVertical : 1; bool fOverflow : 1; bool fDrawLabel : 1; - bool fIsScrolling : 1; bool fShowTeamExpander : 1; bool fExpandNewTeams : 1; diff --git a/src/kits/interface/MenuScrollView.cpp b/src/kits/interface/MenuScrollView.cpp index e67d3d384d..385988100e 100644 --- a/src/kits/interface/MenuScrollView.cpp +++ b/src/kits/interface/MenuScrollView.cpp @@ -14,15 +14,13 @@ #include #include #include -#include -#include #include +#include #include - -#include +#include -const int kDefaultScrollStep = 8; +const int kDefaultScrollStep = 19; const int kScrollerHeight = 12; @@ -160,9 +158,9 @@ BMenuDownScroller::Draw(BRect updateRect) // #pragma mark - -BMenuScrollView::BMenuScrollView(BMenu *menu) +BMenuScrollView::BMenuScrollView(BRect frame, BMenu* menu) : - BView("menu scroll view", B_WILL_DRAW | B_FRAME_EVENTS), + BView(frame, "menu scroll view", B_FOLLOW_NONE, B_WILL_DRAW | B_FRAME_EVENTS), fMenu(menu), fUpperScroller(NULL), fLowerScroller(NULL), @@ -201,14 +199,9 @@ BMenuScrollView::AttachedToWindow() if (fMenu == NULL) return; + fMenu->MoveTo(0, 0); + AddChild(fMenu); - - // Move the scroll menu into position - MoveTo(fMenu->Frame().LeftTop()); - - BFont font; - fMenu->GetFont(&font); - SetFont(&font); } @@ -229,33 +222,13 @@ BMenuScrollView::DetachedFromWindow() void -BMenuScrollView::Draw(BRect updateRect) +BMenuScrollView::MouseDown(BPoint where) { - if (be_control_look != NULL) - return; - - SetHighColor(tint_color(ui_color(B_MENU_BACKGROUND_COLOR), B_DARKEN_2_TINT)); - BRect bounds(Bounds()); - - StrokeLine(BPoint(bounds.right, bounds.top), - BPoint(bounds.right, bounds.bottom - 1)); - StrokeLine(BPoint(bounds.left + 1, bounds.bottom), - BPoint(bounds.right, bounds.bottom)); + } -void -BMenuScrollView::FrameResized(float newWidth, float newHeight) -{ - BView::FrameResized(newWidth, newHeight); - - if (fMenu != NULL) { - if (HasScrollers()) - fMenu->MoveTo(0, kScrollerHeight); - else - fMenu->MoveTo(0, 0); - } -} +// #pragma mark - void @@ -268,7 +241,8 @@ BMenuScrollView::AttachScrollers() BRect screenFrame = (BScreen(Window())).Frame(); if (HasScrollers()) { - fLimit = Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; + fLimit = Window()->Frame().bottom + 2 * kScrollerHeight + - screenFrame.bottom; return; } @@ -280,6 +254,8 @@ BMenuScrollView::AttachScrollers() AddChild(fUpperScroller, fMenu); } + fMenu->MoveBy(0, kScrollerHeight); + if (fLowerScroller == NULL) { fLowerScroller = new BMenuDownScroller( BRect(0, frame.bottom - kScrollerHeight + 1, frame.right, @@ -290,7 +266,8 @@ BMenuScrollView::AttachScrollers() fUpperScroller->SetEnabled(false); fLowerScroller->SetEnabled(true); - fLimit = Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; + fLimit = Window()->Frame().bottom + 2 * kScrollerHeight + - screenFrame.bottom; fValue = 0; } @@ -317,9 +294,7 @@ BMenuScrollView::DetachScrollers() // We don't remember the position where the last scrolling // ended, so scroll back to the beginning. fMenu->ScrollTo(0, 0); - // Since the scrollers were removed move back up. - //fMenu->ResizeBy(0, 2 * kScrollerHeight); - //fMenu->MoveBy(0, -kScrollerHeight); + fMenu->MoveBy(0, -kScrollerHeight); fValue = 0; } }