WIP: Add support for horizontal scrolling.
This commit is contained in:
@@ -504,7 +504,10 @@ TBarView::PlaceApplicationBar()
|
|||||||
fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar",
|
fExpando = new TExpandoMenuBar(this, expandoFrame, "ExpandoMenuBar",
|
||||||
fVertical, !hideLabels && fState != kFullState);
|
fVertical, !hideLabels && fState != kFullState);
|
||||||
|
|
||||||
fInlineScrollView = new TInlineScrollView(menuScrollFrame, fExpando);
|
fInlineScrollView = new TInlineScrollView(menuScrollFrame, fExpando,
|
||||||
|
fVertical ? expandoFrame.top : expandoFrame.left,
|
||||||
|
fVertical ? screenFrame.bottom : expandoFrame.right,
|
||||||
|
fVertical ? B_VERTICAL : B_HORIZONTAL);
|
||||||
AddChild(fInlineScrollView);
|
AddChild(fInlineScrollView);
|
||||||
|
|
||||||
if (fVertical)
|
if (fVertical)
|
||||||
@@ -575,12 +578,7 @@ TBarView::SizeWindow(BRect screenFrame)
|
|||||||
GetPreferredWindowSize(screenFrame, &windowWidth, &windowHeight);
|
GetPreferredWindowSize(screenFrame, &windowWidth, &windowHeight);
|
||||||
Window()->ResizeTo(windowWidth, windowHeight);
|
Window()->ResizeTo(windowWidth, windowHeight);
|
||||||
|
|
||||||
if (fExpando != NULL) {
|
CheckForScrolling();
|
||||||
if (fExpando->CheckForSizeOverrun())
|
|
||||||
fInlineScrollView->AttachScrollers();
|
|
||||||
else
|
|
||||||
fInlineScrollView->DetachScrollers();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -607,6 +605,18 @@ TBarView::PositionWindow(BRect screenFrame)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TBarView::CheckForScrolling()
|
||||||
|
{
|
||||||
|
if (fExpando != NULL) {
|
||||||
|
if (fExpando->CheckForSizeOverrun())
|
||||||
|
fInlineScrollView->AttachScrollers();
|
||||||
|
else
|
||||||
|
fInlineScrollView->DetachScrollers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TBarView::SaveSettings()
|
TBarView::SaveSettings()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -148,6 +148,8 @@ class TBarView : public BView {
|
|||||||
void PositionWindow(BRect screenFrame);
|
void PositionWindow(BRect screenFrame);
|
||||||
void AddExpandedItem(const char* signature);
|
void AddExpandedItem(const char* signature);
|
||||||
|
|
||||||
|
void CheckForScrolling();
|
||||||
|
|
||||||
TExpandoMenuBar* ExpandoMenuBar() const;
|
TExpandoMenuBar* ExpandoMenuBar() const;
|
||||||
TBarMenuBar* BarMenuBar() const;
|
TBarMenuBar* BarMenuBar() const;
|
||||||
TDragRegion* DragRegion() const { return fDragRegion; }
|
TDragRegion* DragRegion() const { return fDragRegion; }
|
||||||
|
|||||||
@@ -734,6 +734,9 @@ TExpandoMenuBar::CheckItemSizes(int32 delta)
|
|||||||
if (newWidth > maxContentWidth)
|
if (newWidth > maxContentWidth)
|
||||||
newWidth = maxContentWidth;
|
newWidth = maxContentWidth;
|
||||||
|
|
||||||
|
if (newWidth < iconOnlyWidth)
|
||||||
|
newWidth = iconOnlyWidth;
|
||||||
|
|
||||||
if (reset) {
|
if (reset) {
|
||||||
SetMaxContentWidth(newWidth);
|
SetMaxContentWidth(newWidth);
|
||||||
if (newWidth == maxContentWidth)
|
if (newWidth == maxContentWidth)
|
||||||
@@ -755,6 +758,8 @@ TExpandoMenuBar::CheckItemSizes(int32 delta)
|
|||||||
Invalidate();
|
Invalidate();
|
||||||
Window()->UpdateIfNeeded();
|
Window()->UpdateIfNeeded();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fBarView->CheckForScrolling();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -815,11 +820,12 @@ TExpandoMenuBar::DrawBackground(BRect)
|
|||||||
bool
|
bool
|
||||||
TExpandoMenuBar::CheckForSizeOverrun()
|
TExpandoMenuBar::CheckForSizeOverrun()
|
||||||
{
|
{
|
||||||
if (!fVertical)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
BRect screenFrame = (BScreen(Window())).Frame();
|
BRect screenFrame = (BScreen(Window())).Frame();
|
||||||
|
|
||||||
|
if (fVertical)
|
||||||
return Window()->Frame().bottom > screenFrame.bottom;
|
return Window()->Frame().bottom > screenFrame.bottom;
|
||||||
|
else
|
||||||
|
return Frame().right > fBarView->DragRegion()->Frame().left;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -288,9 +288,9 @@ RightScrollArrow::Draw(BRect updateRect)
|
|||||||
FillRect(frame, B_SOLID_LOW);
|
FillRect(frame, B_SOLID_LOW);
|
||||||
|
|
||||||
float middle = Bounds().bottom / 2;
|
float middle = Bounds().bottom / 2;
|
||||||
FillTriangle(BPoint(frame.bottom - (kScrollerDimension / 2) + 3, middle),
|
FillTriangle(BPoint(kScrollerDimension / 2 + 3, middle),
|
||||||
BPoint(frame.bottom - (kScrollerDimension / 2) - 2, middle + 5),
|
BPoint(kScrollerDimension / 2 - 2, middle + 5),
|
||||||
BPoint(frame.bottom - (kScrollerDimension / 2) - 2, middle - 5));
|
BPoint(kScrollerDimension / 2 - 2, middle - 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -314,31 +314,34 @@ RightScrollArrow::MouseDown(BPoint where)
|
|||||||
|
|
||||||
|
|
||||||
TInlineScrollView::TInlineScrollView(BRect frame, BView* target,
|
TInlineScrollView::TInlineScrollView(BRect frame, BView* target,
|
||||||
enum orientation orientation)
|
float beginLimit, float endLimit, enum orientation orientation)
|
||||||
:
|
:
|
||||||
BView(frame, "inline scroll view", B_FOLLOW_NONE, 0),
|
BView(frame, "inline scroll view", B_FOLLOW_NONE, 0),
|
||||||
fTarget(target),
|
fTarget(target),
|
||||||
fUpperScrollArrow(NULL),
|
fBeginScrollArrow(NULL),
|
||||||
fLowerScrollArrow(NULL),
|
fEndScrollArrow(NULL),
|
||||||
fScrollStep(kDefaultScrollStep),
|
fScrollStep(kDefaultScrollStep),
|
||||||
fValue(0),
|
fScrollValue(0),
|
||||||
fLimit(0)
|
fScrollLimit(0),
|
||||||
|
fBeginLimit(beginLimit),
|
||||||
|
fEndLimit(endLimit),
|
||||||
|
fOrientation(orientation)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TInlineScrollView::~TInlineScrollView()
|
TInlineScrollView::~TInlineScrollView()
|
||||||
{
|
{
|
||||||
if (fUpperScrollArrow != NULL) {
|
if (fBeginScrollArrow != NULL) {
|
||||||
fUpperScrollArrow->RemoveSelf();
|
fBeginScrollArrow->RemoveSelf();
|
||||||
delete fUpperScrollArrow;
|
delete fBeginScrollArrow;
|
||||||
fUpperScrollArrow = NULL;
|
fBeginScrollArrow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fLowerScrollArrow != NULL) {
|
if (fEndScrollArrow != NULL) {
|
||||||
fLowerScrollArrow->RemoveSelf();
|
fEndScrollArrow->RemoveSelf();
|
||||||
delete fLowerScrollArrow;
|
delete fEndScrollArrow;
|
||||||
fLowerScrollArrow = NULL;
|
fEndScrollArrow = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -364,11 +367,11 @@ TInlineScrollView::DetachedFromWindow()
|
|||||||
if (fTarget != NULL)
|
if (fTarget != NULL)
|
||||||
fTarget->RemoveSelf();
|
fTarget->RemoveSelf();
|
||||||
|
|
||||||
if (fUpperScrollArrow != NULL)
|
if (fBeginScrollArrow != NULL)
|
||||||
fUpperScrollArrow->RemoveSelf();
|
fBeginScrollArrow->RemoveSelf();
|
||||||
|
|
||||||
if (fLowerScrollArrow != NULL)
|
if (fEndScrollArrow != NULL)
|
||||||
fLowerScrollArrow->RemoveSelf();
|
fEndScrollArrow->RemoveSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -382,37 +385,64 @@ TInlineScrollView::AttachScrollers()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
BRect frame = Bounds();
|
BRect frame = Bounds();
|
||||||
BRect screenFrame = (BScreen(Window())).Frame();
|
|
||||||
|
|
||||||
if (HasScrollers()) {
|
if (HasScrollers()) {
|
||||||
fLimit = fTarget->Frame().bottom + 2 * kScrollerDimension
|
if (fOrientation == B_VERTICAL) {
|
||||||
- screenFrame.bottom;
|
fScrollLimit = Window()->Frame().bottom + 2 * kScrollerDimension
|
||||||
|
- fEndLimit;
|
||||||
|
} else {
|
||||||
|
fScrollLimit = fTarget->Frame().right + 2 * kScrollerDimension
|
||||||
|
- fEndLimit;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fTarget->MakeFocus(true);
|
fTarget->MakeFocus(true);
|
||||||
|
|
||||||
if (fUpperScrollArrow == NULL) {
|
if (fOrientation == B_VERTICAL) {
|
||||||
fUpperScrollArrow = new UpScrollArrow(
|
if (fBeginScrollArrow == NULL) {
|
||||||
BRect(0, 0, frame.right, kScrollerDimension - 1));
|
fBeginScrollArrow = new UpScrollArrow(
|
||||||
AddChild(fUpperScrollArrow);
|
BRect(frame.left, frame.top, frame.right,
|
||||||
|
kScrollerDimension - 1));
|
||||||
|
AddChild(fBeginScrollArrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fLowerScrollArrow == NULL) {
|
if (fEndScrollArrow == NULL) {
|
||||||
fLowerScrollArrow = new DownScrollArrow(
|
fEndScrollArrow = new DownScrollArrow(
|
||||||
BRect(0, frame.bottom - 2 * kScrollerDimension + 1, frame.right,
|
BRect(0, frame.bottom - 2 * kScrollerDimension + 1, frame.right,
|
||||||
frame.bottom - kScrollerDimension));
|
frame.bottom - kScrollerDimension));
|
||||||
fTarget->AddChild(fLowerScrollArrow);
|
fTarget->AddChild(fEndScrollArrow);
|
||||||
}
|
}
|
||||||
|
|
||||||
fTarget->MoveBy(0, kScrollerDimension);
|
fTarget->MoveBy(0, kScrollerDimension);
|
||||||
|
|
||||||
fUpperScrollArrow->SetEnabled(false);
|
fScrollLimit = Window()->Frame().bottom + 2 * kScrollerDimension
|
||||||
fLowerScrollArrow->SetEnabled(true);
|
- fEndLimit;
|
||||||
|
} else {
|
||||||
|
if (fBeginScrollArrow == NULL) {
|
||||||
|
fBeginScrollArrow = new LeftScrollArrow(
|
||||||
|
BRect(frame.left, frame.top,
|
||||||
|
frame.left + kScrollerDimension - 1, frame.bottom));
|
||||||
|
AddChild(fBeginScrollArrow);
|
||||||
|
}
|
||||||
|
|
||||||
fLimit = fTarget->Frame().bottom + 2 * kScrollerDimension
|
if (fEndScrollArrow == NULL) {
|
||||||
- screenFrame.bottom;
|
fEndScrollArrow = new RightScrollArrow(
|
||||||
fValue = 0;
|
BRect(frame.right - 2 * kScrollerDimension + 1, frame.top,
|
||||||
|
frame.right, frame.bottom));
|
||||||
|
fTarget->AddChild(fEndScrollArrow);
|
||||||
|
}
|
||||||
|
|
||||||
|
fTarget->MoveBy(kScrollerDimension, 0);
|
||||||
|
|
||||||
|
fScrollLimit = fTarget->Frame().right + 2 * kScrollerDimension
|
||||||
|
- fEndLimit;
|
||||||
|
}
|
||||||
|
|
||||||
|
fBeginScrollArrow->SetEnabled(false);
|
||||||
|
fEndScrollArrow->SetEnabled(true);
|
||||||
|
|
||||||
|
fScrollValue = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -422,24 +452,28 @@ TInlineScrollView::DetachScrollers()
|
|||||||
if (!HasScrollers())
|
if (!HasScrollers())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (fLowerScrollArrow) {
|
if (fEndScrollArrow) {
|
||||||
fLowerScrollArrow->RemoveSelf();
|
fEndScrollArrow->RemoveSelf();
|
||||||
delete fLowerScrollArrow;
|
delete fEndScrollArrow;
|
||||||
fLowerScrollArrow = NULL;
|
fEndScrollArrow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fUpperScrollArrow) {
|
if (fBeginScrollArrow) {
|
||||||
fUpperScrollArrow->RemoveSelf();
|
fBeginScrollArrow->RemoveSelf();
|
||||||
delete fUpperScrollArrow;
|
delete fBeginScrollArrow;
|
||||||
fUpperScrollArrow = NULL;
|
fBeginScrollArrow = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fTarget) {
|
if (fTarget) {
|
||||||
// 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.
|
||||||
|
if (fOrientation == B_VERTICAL)
|
||||||
fTarget->MoveBy(0, -kScrollerDimension);
|
fTarget->MoveBy(0, -kScrollerDimension);
|
||||||
|
else
|
||||||
|
fTarget->MoveBy(-kScrollerDimension, 0);
|
||||||
|
|
||||||
fTarget->ScrollTo(0, 0);
|
fTarget->ScrollTo(0, 0);
|
||||||
fValue = 0;
|
fScrollValue = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -447,7 +481,7 @@ TInlineScrollView::DetachScrollers()
|
|||||||
bool
|
bool
|
||||||
TInlineScrollView::HasScrollers() const
|
TInlineScrollView::HasScrollers() const
|
||||||
{
|
{
|
||||||
return fTarget != NULL && fUpperScrollArrow != NULL && fLowerScrollArrow != NULL;
|
return fTarget != NULL && fBeginScrollArrow != NULL && fEndScrollArrow != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -479,33 +513,55 @@ TInlineScrollView::ScrollBy(const float& step)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (step > 0) {
|
if (step > 0) {
|
||||||
if (fValue == 0)
|
if (fScrollValue == 0)
|
||||||
fUpperScrollArrow->SetEnabled(true);
|
fBeginScrollArrow->SetEnabled(true);
|
||||||
|
|
||||||
if (fValue + step >= fLimit) {
|
if (fScrollValue + step >= fScrollLimit) {
|
||||||
// If we reached the limit, only scroll to the end
|
// If we reached the limit, only scroll to the end
|
||||||
fTarget->ScrollBy(0, fLimit - fValue);
|
if (fOrientation == B_VERTICAL) {
|
||||||
fLowerScrollArrow->MoveBy(0, fLimit - fValue);
|
fTarget->ScrollBy(0, fScrollLimit - fScrollValue);
|
||||||
fLowerScrollArrow->SetEnabled(false);
|
fEndScrollArrow->MoveBy(0, fScrollLimit - fScrollValue);
|
||||||
fValue = fLimit;
|
|
||||||
} else {
|
} else {
|
||||||
|
fTarget->ScrollBy(fScrollLimit - fScrollValue, 0);
|
||||||
|
fEndScrollArrow->MoveBy(fScrollLimit - fScrollValue, 0);
|
||||||
|
}
|
||||||
|
fEndScrollArrow->SetEnabled(false);
|
||||||
|
fScrollValue = fScrollLimit;
|
||||||
|
} else {
|
||||||
|
if (fOrientation == B_VERTICAL) {
|
||||||
fTarget->ScrollBy(0, step);
|
fTarget->ScrollBy(0, step);
|
||||||
fLowerScrollArrow->MoveBy(0, step);
|
fEndScrollArrow->MoveBy(0, step);
|
||||||
fValue += step;
|
} else {
|
||||||
|
fTarget->ScrollBy(step, 0);
|
||||||
|
fEndScrollArrow->MoveBy(step, 0);
|
||||||
|
}
|
||||||
|
fScrollValue += step;
|
||||||
}
|
}
|
||||||
} else if (step < 0) {
|
} else if (step < 0) {
|
||||||
if (fValue == fLimit)
|
if (fScrollValue == fScrollLimit)
|
||||||
fLowerScrollArrow->SetEnabled(true);
|
fEndScrollArrow->SetEnabled(true);
|
||||||
|
|
||||||
if (fValue + step <= 0) {
|
if (fScrollValue + step <= 0) {
|
||||||
fTarget->ScrollBy(0, -fValue);
|
if (fOrientation == B_VERTICAL) {
|
||||||
fLowerScrollArrow->MoveBy(0, -fValue);
|
fTarget->ScrollBy(0, -fScrollValue);
|
||||||
fUpperScrollArrow->SetEnabled(false);
|
fEndScrollArrow->MoveBy(0, -fScrollValue);
|
||||||
fValue = 0;
|
|
||||||
} else {
|
} else {
|
||||||
|
fTarget->ScrollBy(-fScrollValue, 0);
|
||||||
|
fEndScrollArrow->MoveBy(-fScrollValue, 0);
|
||||||
|
}
|
||||||
|
fBeginScrollArrow->SetEnabled(false);
|
||||||
|
fScrollValue = 0;
|
||||||
|
} else {
|
||||||
|
if (fOrientation == B_VERTICAL) {
|
||||||
fTarget->ScrollBy(0, step);
|
fTarget->ScrollBy(0, step);
|
||||||
fLowerScrollArrow->MoveBy(0, step);
|
fEndScrollArrow->MoveBy(0, step);
|
||||||
fValue += step;
|
} else {
|
||||||
|
fTarget->ScrollBy(step, 0);
|
||||||
|
fEndScrollArrow->MoveBy(step, 0);
|
||||||
|
}
|
||||||
|
fScrollValue += step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//fTarget->Invalidate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ class BPoint;
|
|||||||
class TInlineScrollView : public BView {
|
class TInlineScrollView : public BView {
|
||||||
public:
|
public:
|
||||||
TInlineScrollView(BRect frame, BView* target,
|
TInlineScrollView(BRect frame, BView* target,
|
||||||
|
float beginLimit, float endLimit,
|
||||||
enum orientation orientation = B_VERTICAL);
|
enum orientation orientation = B_VERTICAL);
|
||||||
virtual ~TInlineScrollView();
|
virtual ~TInlineScrollView();
|
||||||
|
|
||||||
@@ -37,12 +38,17 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
BView* fTarget;
|
BView* fTarget;
|
||||||
ScrollArrow* fUpperScrollArrow;
|
ScrollArrow* fBeginScrollArrow;
|
||||||
ScrollArrow* fLowerScrollArrow;
|
ScrollArrow* fEndScrollArrow;
|
||||||
|
|
||||||
float fScrollStep;
|
float fScrollStep;
|
||||||
float fValue;
|
float fScrollValue;
|
||||||
float fLimit;
|
float fScrollLimit;
|
||||||
|
|
||||||
|
float fBeginLimit;
|
||||||
|
float fEndLimit;
|
||||||
|
|
||||||
|
int32 fOrientation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user