Make the MenuScrollView a fixed size...

instead of trying to make it follow fExpando just make it a fixed
size on creation. It is invisible and extends to the bottom of the
screen. fExpando grows inside it, and the window follows fExpando.
When the window grows taller than the screenframe the arrows are
added. You can scroll with the mouse wheel, but I haven't yet gotten
scrolling to work from clicking. Deskbar still crashes when going
from Mini mode to vertical expando mode. I have no idea why.
This commit is contained in:
John Scipione
2012-11-12 22:03:17 -05:00
parent 49ff476d13
commit 7ee3b479d1
5 changed files with 54 additions and 90 deletions
+4 -3
View File
@@ -16,17 +16,17 @@
class BLayout; class BLayout;
class BMenu; class BMenu;
class BMenuScroller; class BMenuScroller;
class BPoint;
class BMenuScrollView : public BView { class BMenuScrollView : public BView {
public: public:
BMenuScrollView(BMenu* menu); BMenuScrollView(BRect frame, BMenu* menu);
virtual ~BMenuScrollView(); virtual ~BMenuScrollView();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void Draw(BRect updateRect); virtual void MouseDown(BPoint where);
virtual void FrameResized(float newWidth, float newHeight);
void AttachScrollers(); void AttachScrollers();
void DetachScrollers(); void DetachScrollers();
@@ -34,6 +34,7 @@ public:
void SetSmallStep(float step); void SetSmallStep(float step);
void GetSteps(float* _smallStep, float* _largeStep) const; void GetSteps(float* _smallStep, float* _largeStep) const;
bool CheckForScrolling(const BPoint& cursor); bool CheckForScrolling(const BPoint& cursor);
bool TryScrollBy(const float& step); bool TryScrollBy(const float& step);
+28 -11
View File
@@ -443,6 +443,9 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap)
void void
TBarView::PlaceApplicationBar() TBarView::PlaceApplicationBar()
{ {
if (fExpando != NULL)
SaveExpandedItems();
if (fMenuScrollView != NULL) { if (fMenuScrollView != NULL) {
fMenuScrollView->RemoveSelf(); fMenuScrollView->RemoveSelf();
delete fMenuScrollView; delete fMenuScrollView;
@@ -455,10 +458,16 @@ TBarView::PlaceApplicationBar()
fExpando = NULL; fExpando = NULL;
} }
if (fState == kMiniState)
return;
BRect screenFrame = (BScreen(Window())).Frame(); 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); BRect expandoFrame(0, 0, 0, 0);
if (fVertical) { if (fVertical) {
// top left/right // top left/right
@@ -472,6 +481,9 @@ TBarView::PlaceApplicationBar()
expandoFrame.right = fBarMenuBar->Frame().Width(); expandoFrame.right = fBarMenuBar->Frame().Width();
else else
expandoFrame.right = sMinimumWindowWidth; expandoFrame.right = sMinimumWindowWidth;
menuScrollFrame = expandoFrame;
menuScrollFrame.bottom = screenFrame.bottom;
} else { } else {
// top or bottom // top or bottom
expandoFrame.top = 0; expandoFrame.top = 0;
@@ -481,6 +493,8 @@ TBarView::PlaceApplicationBar()
expandoFrame.right = fDragRegion->Frame().left - 1; expandoFrame.right = fDragRegion->Frame().left - 1;
else else
expandoFrame.right = screenFrame.Width(); expandoFrame.right = screenFrame.Width();
menuScrollFrame = expandoFrame;
} }
bool hideLabels = ((TBarApp*)be_app)->Settings()->hideLabels; bool hideLabels = ((TBarApp*)be_app)->Settings()->hideLabels;
@@ -488,9 +502,8 @@ TBarView::PlaceApplicationBar()
fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar",
fVertical, !hideLabels && fState != kFullState); fVertical, !hideLabels && fState != kFullState);
fMenuScrollView = new BMenuScrollView(fExpando); fMenuScrollView = new BMenuScrollView(menuScrollFrame, fExpando);
AddChild(fMenuScrollView); AddChild(fMenuScrollView);
//printf("fExpando bottom: %f, fMenuScrollView bottom: %f\n", fExpando->Frame().bottom, fMenuScrollView->Frame().bottom);
if (fVertical) if (fVertical)
ExpandItems(); ExpandItems();
@@ -527,7 +540,12 @@ TBarView::GetPreferredWindowSize(BRect screenFrame, float* width, float* height)
} else if (fState == kExpandoState) { } else if (fState == kExpandoState) {
if (fVertical) { if (fVertical) {
// top left or right // 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 { } else {
// top or bottom, full // top or bottom, full
fExpando->CheckItemSizes(0); fExpando->CheckItemSizes(0);
@@ -556,11 +574,10 @@ TBarView::SizeWindow(BRect screenFrame)
Window()->ResizeTo(windowWidth, windowHeight); Window()->ResizeTo(windowWidth, windowHeight);
if (fExpando != NULL) { if (fExpando != NULL) {
if (fMenuScrollView != NULL) { if (fExpando->CheckForSizeOverrun())
fMenuScrollView->ResizeTo(fExpando->Bounds().Width(), fMenuScrollView->AttachScrollers();
fExpando->Bounds().Height()); else
} fMenuScrollView->DetachScrollers();
fExpando->CheckForSizeOverrun();
} }
} }
+4 -32
View File
@@ -83,7 +83,6 @@ TExpandoMenuBar::TExpandoMenuBar(TBarView* bar, BRect frame, const char* name,
fVertical(vertical), fVertical(vertical),
fOverflow(false), fOverflow(false),
fDrawLabel(drawLabel), fDrawLabel(drawLabel),
fIsScrolling(false),
fShowTeamExpander(static_cast<TBarApp*>(be_app)->Settings()->superExpando), fShowTeamExpander(static_cast<TBarApp*>(be_app)->Settings()->superExpando),
fExpandNewTeams(static_cast<TBarApp*>(be_app)->Settings()->expandNewTeams), fExpandNewTeams(static_cast<TBarApp*>(be_app)->Settings()->expandNewTeams),
fDeskbarMenuWidth(kDefaultDeskbarMenuWidth), fDeskbarMenuWidth(kDefaultDeskbarMenuWidth),
@@ -194,10 +193,6 @@ TExpandoMenuBar::AttachedToWindow()
ResizeTo(itemWidth, 0); ResizeTo(itemWidth, 0);
} }
BMenuScrollView* scrollMenu = dynamic_cast<BMenuScrollView*>(Parent());
if (scrollMenu != NULL)
scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height());
if (fVertical) { if (fVertical) {
sDoMonitor = true; sDoMonitor = true;
sMonThread = spawn_thread(monitor_team_windows, sMonThread = spawn_thread(monitor_team_windows,
@@ -427,14 +422,6 @@ TExpandoMenuBar::MouseMoved(BPoint where, uint32 code, const BMessage* message)
// force a cleanup // force a cleanup
_FinishedDrag(); _FinishedDrag();
// check for scrolling menu
BMenuScrollView* scrollMenu = dynamic_cast<BMenuScrollView*>(Parent());
if (scrollMenu != NULL) {
BPoint screenLocation = ConvertToScreen(where);
while(scrollMenu->CheckForScrolling(screenLocation))
TExpandoMenuBar::MouseMoved(where, code, message);
}
switch (code) { switch (code) {
case B_ENTERED_VIEW: case B_ENTERED_VIEW:
case B_INSIDE_VIEW: case B_INSIDE_VIEW:
@@ -825,35 +812,20 @@ TExpandoMenuBar::DrawBackground(BRect)
/*! Something to help determine if we are showing too many apps /*! Something to help determine if we are showing too many apps
need to add in scrolling functionality. need to add in scrolling functionality.
*/ */
void bool
TExpandoMenuBar::CheckForSizeOverrun() TExpandoMenuBar::CheckForSizeOverrun()
{ {
if (!fVertical) { if (!fVertical)
fIsScrolling = false; return false;
return;
}
BMenuScrollView* scrollMenu = dynamic_cast<BMenuScrollView*>(Parent());
if (scrollMenu == NULL)
return;
BRect screenFrame = (BScreen(Window())).Frame(); BRect screenFrame = (BScreen(Window())).Frame();
fIsScrolling = Window()->Frame().bottom > screenFrame.bottom; return Window()->Frame().bottom > screenFrame.bottom;
if (fIsScrolling)
scrollMenu->AttachScrollers();
else
scrollMenu->DetachScrollers();
} }
void void
TExpandoMenuBar::SizeWindow(int32 delta) TExpandoMenuBar::SizeWindow(int32 delta)
{ {
BMenuScrollView* scrollMenu = dynamic_cast<BMenuScrollView*>(Parent());
if (scrollMenu != NULL)
scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height());
// instead of resizing the window here and there in the // instead of resizing the window here and there in the
// code the resize method will be centered in one place // code the resize method will be centered in one place
// thus, the same behavior (good or bad) will be used // thus, the same behavior (good or bad) will be used
+1 -2
View File
@@ -83,7 +83,7 @@ class TExpandoMenuBar : public BMenuBar {
menu_layout MenuLayout() const; menu_layout MenuLayout() const;
void SizeWindow(int32 delta); void SizeWindow(int32 delta);
void CheckForSizeOverrun(); bool CheckForSizeOverrun();
private: private:
static int CompareByName(const void* first, const void* second); static int CompareByName(const void* first, const void* second);
@@ -98,7 +98,6 @@ class TExpandoMenuBar : public BMenuBar {
bool fVertical : 1; bool fVertical : 1;
bool fOverflow : 1; bool fOverflow : 1;
bool fDrawLabel : 1; bool fDrawLabel : 1;
bool fIsScrolling : 1;
bool fShowTeamExpander : 1; bool fShowTeamExpander : 1;
bool fExpandNewTeams : 1; bool fExpandNewTeams : 1;
+17 -42
View File
@@ -14,15 +14,13 @@
#include <ControlLook.h> #include <ControlLook.h>
#include <Debug.h> #include <Debug.h>
#include <InterfaceDefs.h> #include <InterfaceDefs.h>
#include <Layout.h>
#include <GroupLayout.h>
#include <Menu.h> #include <Menu.h>
#include <Point.h>
#include <Screen.h> #include <Screen.h>
#include <Window.h>
#include <MenuPrivate.h>
const int kDefaultScrollStep = 8; const int kDefaultScrollStep = 19;
const int kScrollerHeight = 12; const int kScrollerHeight = 12;
@@ -160,9 +158,9 @@ BMenuDownScroller::Draw(BRect updateRect)
// #pragma mark - // #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), fMenu(menu),
fUpperScroller(NULL), fUpperScroller(NULL),
fLowerScroller(NULL), fLowerScroller(NULL),
@@ -201,14 +199,9 @@ BMenuScrollView::AttachedToWindow()
if (fMenu == NULL) if (fMenu == NULL)
return; return;
fMenu->MoveTo(0, 0);
AddChild(fMenu); 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 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 // #pragma mark -
BMenuScrollView::FrameResized(float newWidth, float newHeight)
{
BView::FrameResized(newWidth, newHeight);
if (fMenu != NULL) {
if (HasScrollers())
fMenu->MoveTo(0, kScrollerHeight);
else
fMenu->MoveTo(0, 0);
}
}
void void
@@ -268,7 +241,8 @@ BMenuScrollView::AttachScrollers()
BRect screenFrame = (BScreen(Window())).Frame(); BRect screenFrame = (BScreen(Window())).Frame();
if (HasScrollers()) { if (HasScrollers()) {
fLimit = Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; fLimit = Window()->Frame().bottom + 2 * kScrollerHeight
- screenFrame.bottom;
return; return;
} }
@@ -280,6 +254,8 @@ BMenuScrollView::AttachScrollers()
AddChild(fUpperScroller, fMenu); AddChild(fUpperScroller, fMenu);
} }
fMenu->MoveBy(0, kScrollerHeight);
if (fLowerScroller == NULL) { if (fLowerScroller == NULL) {
fLowerScroller = new BMenuDownScroller( fLowerScroller = new BMenuDownScroller(
BRect(0, frame.bottom - kScrollerHeight + 1, frame.right, BRect(0, frame.bottom - kScrollerHeight + 1, frame.right,
@@ -290,7 +266,8 @@ BMenuScrollView::AttachScrollers()
fUpperScroller->SetEnabled(false); fUpperScroller->SetEnabled(false);
fLowerScroller->SetEnabled(true); fLowerScroller->SetEnabled(true);
fLimit = Frame().bottom + 2 * kScrollerHeight - screenFrame.bottom; fLimit = Window()->Frame().bottom + 2 * kScrollerHeight
- screenFrame.bottom;
fValue = 0; fValue = 0;
} }
@@ -317,9 +294,7 @@ BMenuScrollView::DetachScrollers()
// We don't remember the position where the last scrolling // We don't remember the position where the last scrolling
// ended, so scroll back to the beginning. // ended, so scroll back to the beginning.
fMenu->ScrollTo(0, 0); fMenu->ScrollTo(0, 0);
// Since the scrollers were removed move back up. fMenu->MoveBy(0, -kScrollerHeight);
//fMenu->ResizeBy(0, 2 * kScrollerHeight);
//fMenu->MoveBy(0, -kScrollerHeight);
fValue = 0; fValue = 0;
} }
} }