Make ScrollMenu not rely on Menu.cpp

Rename ScrollMenu.cpp to MenuScrollView.cpp

Half step towards making this class work as part of Deskbar without
extending any other classes. Scrolling works both with mouse and
scroll wheel. Redraws on scroll, need to make that work better.
Also need to move classes out of the Interface Kit and into Deskbar.
This commit is contained in:
John Scipione
2012-11-12 22:03:17 -05:00
parent cb55ef9fb5
commit 49ff476d13
10 changed files with 123 additions and 107 deletions
@@ -7,8 +7,8 @@
* Stefano Ceccherini (stefano.ceccherini@gmail.com) * Stefano Ceccherini (stefano.ceccherini@gmail.com)
* John Scipione (jscipione@gmail.com) * John Scipione (jscipione@gmail.com)
*/ */
#ifndef SCROLL_MENU_H #ifndef MENU_SCROLL_VIEW_H
#define SCROLL_MENU_H #define MENU_SCROLL_VIEW_H
#include <View.h> #include <View.h>
@@ -18,10 +18,10 @@ class BMenu;
class BMenuScroller; class BMenuScroller;
class BScrollMenu : public BView { class BMenuScrollView : public BView {
public: public:
BScrollMenu(BMenu* menu); BMenuScrollView(BMenu* menu);
virtual ~BScrollMenu(); virtual ~BMenuScrollView();
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
@@ -52,4 +52,4 @@ private:
}; };
#endif // SCROLL_MENU_H #endif // MENU_SCROLL_VIEW_H
+18 -15
View File
@@ -48,7 +48,7 @@ All rights reserved.
#include <NodeInfo.h> #include <NodeInfo.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
#include <ScrollMenu.h> #include <MenuScrollView.h>
#include <String.h> #include <String.h>
#include "icons.h" #include "icons.h"
@@ -131,7 +131,7 @@ BarViewMessageFilter::Filter(BMessage* message, BHandler** target)
TBarView::TBarView(BRect frame, bool vertical, bool left, bool top, TBarView::TBarView(BRect frame, bool vertical, bool left, bool top,
uint32 state, float) uint32 state, float)
: BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW), : BView(frame, "BarView", B_FOLLOW_ALL_SIDES, B_WILL_DRAW),
fBarScrollMenu(NULL), fMenuScrollView(NULL),
fBarMenuBar(NULL), fBarMenuBar(NULL),
fExpando(NULL), fExpando(NULL),
fTrayLocation(1), fTrayLocation(1),
@@ -443,11 +443,11 @@ TBarView::PlaceTray(bool vertSwap, bool leftSwap)
void void
TBarView::PlaceApplicationBar() TBarView::PlaceApplicationBar()
{ {
if (fBarScrollMenu != NULL) { if (fMenuScrollView != NULL) {
fBarScrollMenu->RemoveSelf(); fMenuScrollView->RemoveSelf();
delete fBarScrollMenu; delete fMenuScrollView;
// Also deletes fExpando // Also deletes fExpando
fBarScrollMenu = NULL; fMenuScrollView = NULL;
fExpando = NULL; fExpando = NULL;
} else if (fExpando != NULL) { } else if (fExpando != NULL) {
fExpando->RemoveSelf(); fExpando->RemoveSelf();
@@ -488,12 +488,9 @@ TBarView::PlaceApplicationBar()
fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar", fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar",
fVertical, !hideLabels && fState != kFullState); fVertical, !hideLabels && fState != kFullState);
if (fVertical) { fMenuScrollView = new BMenuScrollView(fExpando);
fBarScrollMenu = new BScrollMenu(fExpando); AddChild(fMenuScrollView);
AddChild(fBarScrollMenu); //printf("fExpando bottom: %f, fMenuScrollView bottom: %f\n", fExpando->Frame().bottom, fMenuScrollView->Frame().bottom);
//printf("fExpando bottom: %f, fBarScrollMenu bottom: %f\n", fExpando->Frame().bottom, fBarScrollMenu->Frame().bottom);
} else
AddChild(fExpando);
if (fVertical) if (fVertical)
ExpandItems(); ExpandItems();
@@ -530,7 +527,7 @@ 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 = fBarScrollMenu->Frame().bottom; windowHeight = fMenuScrollView->Frame().bottom;
} else { } else {
// top or bottom, full // top or bottom, full
fExpando->CheckItemSizes(0); fExpando->CheckItemSizes(0);
@@ -557,8 +554,14 @@ TBarView::SizeWindow(BRect screenFrame)
float windowWidth, windowHeight; float windowWidth, windowHeight;
GetPreferredWindowSize(screenFrame, &windowWidth, &windowHeight); GetPreferredWindowSize(screenFrame, &windowWidth, &windowHeight);
Window()->ResizeTo(windowWidth, windowHeight); Window()->ResizeTo(windowWidth, windowHeight);
if (fExpando)
if (fExpando != NULL) {
if (fMenuScrollView != NULL) {
fMenuScrollView->ResizeTo(fExpando->Bounds().Width(),
fExpando->Bounds().Height());
}
fExpando->CheckForSizeOverrun(); fExpando->CheckForSizeOverrun();
}
} }
@@ -687,7 +690,7 @@ TBarView::ExpandItems()
// Clean up the expanded items list // Clean up the expanded items list
RemoveExpandedItems(); RemoveExpandedItems();
fExpando->SizeWindow(); fExpando->SizeWindow(1);
} }
+2 -2
View File
@@ -65,7 +65,7 @@ const float kStatusHeight = 22.0f;
const float kHiddenDimension = 1.0f; const float kHiddenDimension = 1.0f;
const float kMaxPreventHidingDist = 80.0f; const float kMaxPreventHidingDist = 80.0f;
class BScrollMenu; class BMenuScrollView;
class BShelf; class BShelf;
class TBarMenuBar; class TBarMenuBar;
class TExpandoMenuBar; class TExpandoMenuBar;
@@ -168,7 +168,7 @@ class TBarView : public BView {
void ExpandItems(); void ExpandItems();
void _ChangeState(BMessage* message); void _ChangeState(BMessage* message);
BScrollMenu* fBarScrollMenu; BMenuScrollView* fMenuScrollView;
TBarMenuBar* fBarMenuBar; TBarMenuBar* fBarMenuBar;
TExpandoMenuBar* fExpando; TExpandoMenuBar* fExpando;
+54 -16
View File
@@ -45,7 +45,7 @@ All rights reserved.
#include <NodeInfo.h> #include <NodeInfo.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
#include <ScrollMenu.h> #include <MenuScrollView.h>
#include "icons.h" #include "icons.h"
@@ -194,6 +194,10 @@ 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,
@@ -263,6 +267,32 @@ TExpandoMenuBar::MessageReceived(BMessage* message)
break; break;
} }
case B_MOUSE_WHEEL_CHANGED:
{
float deltaY = 0;
message->FindFloat("be:wheel_delta_y", &deltaY);
if (deltaY == 0)
return;
BMenuScrollView* scrollMenu
= dynamic_cast<BMenuScrollView*>(Parent());
if (scrollMenu == NULL)
return;
float largeStep;
float smallStep;
scrollMenu->GetSteps(&smallStep, &largeStep);
// pressing the option/command/control key scrolls faster
if (modifiers() & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY))
deltaY *= largeStep;
else
deltaY *= smallStep;
scrollMenu->TryScrollBy(deltaY);
break;
}
case kAddTeam: case kAddTeam:
AddTeam(message->FindInt32("team"), message->FindString("sig")); AddTeam(message->FindInt32("team"), message->FindString("sig"));
break; break;
@@ -397,6 +427,14 @@ 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:
@@ -611,10 +649,9 @@ TExpandoMenuBar::AddTeam(BList* team, BBitmap* icon, char* name,
if (fVertical) { if (fVertical) {
if (item && fShowTeamExpander && fExpandNewTeams) if (item && fShowTeamExpander && fExpandNewTeams)
item->ToggleExpandState(false); item->ToggleExpandState(false);
}
fBarView->SizeWindow(BScreen(Window()).Frame()); SizeWindow(1);
} else
CheckItemSizes(1);
Window()->UpdateIfNeeded(); Window()->UpdateIfNeeded();
} }
@@ -656,14 +693,7 @@ TExpandoMenuBar::RemoveTeam(team_id team, bool partial)
RemoveItem(i); RemoveItem(i);
if (fVertical) { SizeWindow(-1);
// 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
// whereever window sizing is done
fBarView->SizeWindow(BScreen(Window()).Frame());
} else
CheckItemSizes(-1);
Window()->UpdateIfNeeded(); Window()->UpdateIfNeeded();
@@ -803,7 +833,7 @@ TExpandoMenuBar::CheckForSizeOverrun()
return; return;
} }
BScrollMenu* scrollMenu = dynamic_cast<BScrollMenu*>(Parent()); BMenuScrollView* scrollMenu = dynamic_cast<BMenuScrollView*>(Parent());
if (scrollMenu == NULL) if (scrollMenu == NULL)
return; return;
@@ -818,12 +848,20 @@ TExpandoMenuBar::CheckForSizeOverrun()
void void
TExpandoMenuBar::SizeWindow() 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
// code the resize method will be centered in one place
// thus, the same behavior (good or bad) will be used
// wherever window sizing is done
if (fVertical) if (fVertical)
fBarView->SizeWindow(BScreen(Window()).Frame()); fBarView->SizeWindow(BScreen(Window()).Frame());
else else
CheckItemSizes(1); CheckItemSizes(delta);
} }
@@ -928,7 +966,7 @@ TExpandoMenuBar::monitor_team_windows(void* arg)
if (itemModified || resize) { if (itemModified || resize) {
teamMenu->Invalidate(); teamMenu->Invalidate();
if (resize) if (resize)
teamMenu->SizeWindow(); teamMenu->SizeWindow(1);
} }
teamMenu->Window()->Unlock(); teamMenu->Window()->Unlock();
+1 -1
View File
@@ -82,7 +82,7 @@ class TExpandoMenuBar : public BMenuBar {
menu_layout MenuLayout() const; menu_layout MenuLayout() const;
void SizeWindow(); void SizeWindow(int32 delta);
void CheckForSizeOverrun(); void CheckForSizeOverrun();
private: private:
+18 -10
View File
@@ -479,7 +479,8 @@ TTeamMenuItem::DrawContentLabel()
if (Submenu() && fVertical) if (Submenu() && fVertical)
cachedWidth += 18; cachedWidth += 18;
BString label(Label()); const char* label = Label();
char* truncLabel = NULL;
float max = 0; float max = 0;
if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando) if (fVertical && static_cast<TBarApp*>(be_app)->Settings()->superExpando)
@@ -491,23 +492,30 @@ TTeamMenuItem::DrawContentLabel()
BPoint penloc = menu->PenLocation(); BPoint penloc = menu->PenLocation();
BRect frame = Frame(); BRect frame = Frame();
float offset = penloc.x - frame.left; float offset = penloc.x - frame.left;
if (cachedWidth + offset > max) if (cachedWidth + offset > max) {
menu->TruncateString(&label, B_TRUNCATE_MIDDLE, max - offset); truncLabel = (char*)malloc(strlen(label) + 4);
if (!truncLabel)
return;
TruncateLabel(max-offset, truncLabel);
label = truncLabel;
}
} }
if (!label) if (!label)
label = BString(Label()); label = Label();
TBarView* barView = (static_cast<TBarApp*>(be_app))->BarView(); TBarView* barview = (static_cast<TBarApp*>(be_app))->BarView();
bool canHandle = !barView->Dragging() bool canHandle = !barview->Dragging()
|| barView->AppCanHandleTypes(Signature()); || barview->AppCanHandleTypes(Signature());
if (_IsSelected() && IsEnabled() && canHandle) if (_IsSelected() && IsEnabled() && canHandle)
menu->SetLowColor(tint_color(menu->LowColor(), menu->SetLowColor(tint_color(menu->LowColor(),
B_HIGHLIGHT_BACKGROUND_TINT)); B_HIGHLIGHT_BACKGROUND_TINT));
else else
menu->SetLowColor(menu->LowColor()); menu->SetLowColor(menu->LowColor());
menu->DrawString(label.String()); menu->DrawString(label);
free(truncLabel);
} }
@@ -551,7 +559,7 @@ TTeamMenuItem::ToggleExpandState(bool resizeWindow)
sub->SetExpanded(true, myindex + childIndex); sub->SetExpanded(true, myindex + childIndex);
if (resizeWindow) if (resizeWindow)
parent->SizeWindow(); parent->SizeWindow(1);
} }
} }
} else { } else {
@@ -573,7 +581,7 @@ TTeamMenuItem::ToggleExpandState(bool resizeWindow)
sub->SetExpanded(false, 0); sub->SetExpanded(false, 0);
if (resizeWindow) if (resizeWindow)
parent->SizeWindow(); parent->SizeWindow(1);
} }
} }
} }
+1 -1
View File
@@ -82,6 +82,7 @@ MergeObject <libbe>interface_kit.o :
MenuField.cpp MenuField.cpp
MenuItem.cpp MenuItem.cpp
MenuPrivate.cpp MenuPrivate.cpp
MenuScrollView.cpp
MenuWindow.cpp MenuWindow.cpp
OptionControl.cpp OptionControl.cpp
OptionPopUp.cpp OptionPopUp.cpp
@@ -101,7 +102,6 @@ MergeObject <libbe>interface_kit.o :
RegionSupport.cpp RegionSupport.cpp
Screen.cpp Screen.cpp
ScrollBar.cpp ScrollBar.cpp
ScrollMenu.cpp
ScrollView.cpp ScrollView.cpp
SeparatorItem.cpp SeparatorItem.cpp
SeparatorView.cpp SeparatorView.cpp
+1 -6
View File
@@ -2812,13 +2812,8 @@ BMenu::_ChooseTrigger(const char* title, int32& index, uint32& trigger,
void void
BMenu::_UpdateWindowViewSize(const bool &move) BMenu::_UpdateWindowViewSize(const bool &move)
{ {
if (dynamic_cast<BMenuBar*>(this) != NULL) { if (dynamic_cast<BMenuBar*>(this) != NULL)
BScrollMenu* scrollMenu = dynamic_cast<BScrollMenu*>(Parent());
if (scrollMenu != NULL)
scrollMenu->ResizeTo(Bounds().Width(), Bounds().Height());
return; return;
}
BMenuWindow* window = static_cast<BMenuWindow*>(Window()); BMenuWindow* window = static_cast<BMenuWindow*>(Window());
if (window == NULL) if (window == NULL)
+2 -31
View File
@@ -18,7 +18,7 @@
#include <ControlLook.h> #include <ControlLook.h>
#include <LayoutUtils.h> #include <LayoutUtils.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <ScrollMenu.h> #include <MenuScrollView.h>
#include <Window.h> #include <Window.h>
#include <AppMisc.h> #include <AppMisc.h>
@@ -329,36 +329,7 @@ BMenuBar::Draw(BRect updateRect)
void void
BMenuBar::MessageReceived(BMessage* msg) BMenuBar::MessageReceived(BMessage* msg)
{ {
switch (msg->what) { BMenu::MessageReceived(msg);
case B_MOUSE_WHEEL_CHANGED:
{
float deltaY = 0;
msg->FindFloat("be:wheel_delta_y", &deltaY);
if (deltaY == 0)
return;
BScrollMenu* scrollMenu = dynamic_cast<BScrollMenu*>(Parent());
if (scrollMenu == NULL)
return;
float largeStep;
float smallStep;
scrollMenu->GetSteps(&smallStep, &largeStep);
// pressing the option/command/control key scrolls faster
if (modifiers() & (B_OPTION_KEY | B_COMMAND_KEY | B_CONTROL_KEY))
deltaY *= largeStep;
else
deltaY *= smallStep;
scrollMenu->TryScrollBy(deltaY);
break;
}
default:
BMenu::MessageReceived(msg);
break;
}
} }
@@ -9,7 +9,7 @@
*/ */
#include <ScrollMenu.h> #include <MenuScrollView.h>
#include <ControlLook.h> #include <ControlLook.h>
#include <Debug.h> #include <Debug.h>
@@ -22,8 +22,7 @@
#include <MenuPrivate.h> #include <MenuPrivate.h>
const char* kEmptyMenuLabel = "<empty>"; const int kDefaultScrollStep = 8;
const int kDefaultScrollStep = 19;
const int kScrollerHeight = 12; const int kScrollerHeight = 12;
@@ -161,7 +160,7 @@ BMenuDownScroller::Draw(BRect updateRect)
// #pragma mark - // #pragma mark -
BScrollMenu::BScrollMenu(BMenu *menu) BMenuScrollView::BMenuScrollView(BMenu *menu)
: :
BView("menu scroll view", B_WILL_DRAW | B_FRAME_EVENTS), BView("menu scroll view", B_WILL_DRAW | B_FRAME_EVENTS),
fMenu(menu), fMenu(menu),
@@ -172,7 +171,7 @@ BScrollMenu::BScrollMenu(BMenu *menu)
} }
BScrollMenu::~BScrollMenu() BMenuScrollView::~BMenuScrollView()
{ {
if (fMenu != NULL) { if (fMenu != NULL) {
fMenu->RemoveSelf(); fMenu->RemoveSelf();
@@ -195,7 +194,7 @@ BScrollMenu::~BScrollMenu()
void void
BScrollMenu::AttachedToWindow() BMenuScrollView::AttachedToWindow()
{ {
BView::AttachedToWindow(); BView::AttachedToWindow();
@@ -204,7 +203,7 @@ BScrollMenu::AttachedToWindow()
AddChild(fMenu); AddChild(fMenu);
// Move the scroll menu into the right position // Move the scroll menu into position
MoveTo(fMenu->Frame().LeftTop()); MoveTo(fMenu->Frame().LeftTop());
BFont font; BFont font;
@@ -214,7 +213,7 @@ BScrollMenu::AttachedToWindow()
void void
BScrollMenu::DetachedFromWindow() BMenuScrollView::DetachedFromWindow()
{ {
BView::DetachedFromWindow(); BView::DetachedFromWindow();
@@ -230,7 +229,7 @@ BScrollMenu::DetachedFromWindow()
void void
BScrollMenu::Draw(BRect updateRect) BMenuScrollView::Draw(BRect updateRect)
{ {
if (be_control_look != NULL) if (be_control_look != NULL)
return; return;
@@ -246,7 +245,7 @@ BScrollMenu::Draw(BRect updateRect)
void void
BScrollMenu::FrameResized(float newWidth, float newHeight) BMenuScrollView::FrameResized(float newWidth, float newHeight)
{ {
BView::FrameResized(newWidth, newHeight); BView::FrameResized(newWidth, newHeight);
@@ -260,7 +259,7 @@ BScrollMenu::FrameResized(float newWidth, float newHeight)
void void
BScrollMenu::AttachScrollers() BMenuScrollView::AttachScrollers()
{ {
if (fMenu == NULL) if (fMenu == NULL)
return; return;
@@ -297,7 +296,7 @@ BScrollMenu::AttachScrollers()
void void
BScrollMenu::DetachScrollers() BMenuScrollView::DetachScrollers()
{ {
if (!HasScrollers()) if (!HasScrollers())
return; return;
@@ -327,21 +326,21 @@ BScrollMenu::DetachScrollers()
bool bool
BScrollMenu::HasScrollers() const BMenuScrollView::HasScrollers() const
{ {
return fMenu != NULL && fUpperScroller != NULL && fLowerScroller != NULL; return fMenu != NULL && fUpperScroller != NULL && fLowerScroller != NULL;
} }
void void
BScrollMenu::SetSmallStep(float step) BMenuScrollView::SetSmallStep(float step)
{ {
fScrollStep = step; fScrollStep = step;
} }
void void
BScrollMenu::GetSteps(float* _smallStep, float* _largeStep) const BMenuScrollView::GetSteps(float* _smallStep, float* _largeStep) const
{ {
if (_smallStep != NULL) if (_smallStep != NULL)
*_smallStep = fScrollStep; *_smallStep = fScrollStep;
@@ -355,7 +354,7 @@ BScrollMenu::GetSteps(float* _smallStep, float* _largeStep) const
bool bool
BScrollMenu::CheckForScrolling(const BPoint &cursor) BMenuScrollView::CheckForScrolling(const BPoint &cursor)
{ {
if (!HasScrollers()) if (!HasScrollers())
return false; return false;
@@ -365,7 +364,7 @@ BScrollMenu::CheckForScrolling(const BPoint &cursor)
bool bool
BScrollMenu::TryScrollBy(const float& step) BMenuScrollView::TryScrollBy(const float& step)
{ {
if (!HasScrollers()) if (!HasScrollers())
return false; return false;
@@ -376,7 +375,7 @@ BScrollMenu::TryScrollBy(const float& step)
bool bool
BScrollMenu::_Scroll(const BPoint& where) BMenuScrollView::_Scroll(const BPoint& where)
{ {
ASSERT((fLowerScroller != NULL)); ASSERT((fLowerScroller != NULL));
ASSERT((fUpperScroller != NULL)); ASSERT((fUpperScroller != NULL));
@@ -405,7 +404,7 @@ BScrollMenu::_Scroll(const BPoint& where)
void void
BScrollMenu::_ScrollBy(const float& step) BMenuScrollView::_ScrollBy(const float& step)
{ {
if (step > 0) { if (step > 0) {
if (fValue == 0) if (fValue == 0)
@@ -420,6 +419,7 @@ BScrollMenu::_ScrollBy(const float& step)
fMenu->ScrollBy(0, step); fMenu->ScrollBy(0, step);
fValue += step; fValue += step;
} }
fMenu->Invalidate();
} else if (step < 0) { } else if (step < 0) {
if (fValue == fLimit) if (fValue == fLimit)
fLowerScroller->SetEnabled(true); fLowerScroller->SetEnabled(true);
@@ -432,5 +432,6 @@ BScrollMenu::_ScrollBy(const float& step)
fMenu->ScrollBy(0, step); fMenu->ScrollBy(0, step);
fValue += step; fValue += step;
} }
fMenu->Invalidate();
} }
} }