Extended the ScrollView API a bit.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31357 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
cd170ddc34
commit
007ea5873a
@ -37,6 +37,9 @@ class InternalScrollBar : public BScrollBar {
|
||||
|
||||
virtual void ValueChanged(float value);
|
||||
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void MouseUp(BPoint where);
|
||||
|
||||
private:
|
||||
ScrollView* fScrollView;
|
||||
};
|
||||
@ -64,6 +67,26 @@ InternalScrollBar::ValueChanged(float value)
|
||||
fScrollView->_ScrollValueChanged(this, value);
|
||||
}
|
||||
|
||||
// MouseDown
|
||||
void
|
||||
InternalScrollBar::MouseDown(BPoint where)
|
||||
{
|
||||
if (fScrollView)
|
||||
fScrollView->_SetScrolling(true);
|
||||
BScrollBar::MouseDown(where);
|
||||
}
|
||||
|
||||
// MouseUp
|
||||
void
|
||||
InternalScrollBar::MouseUp(BPoint where)
|
||||
{
|
||||
BScrollBar::MouseUp(where);
|
||||
if (fScrollView)
|
||||
fScrollView->_SetScrolling(false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// #pragma mark -ScrollCorner
|
||||
|
||||
class ScrollCorner : public BView {
|
||||
@ -124,7 +147,7 @@ ScrollCorner::ScrollCorner(ScrollView* scrollView)
|
||||
int32 bpr = fBitmaps[0]->BytesPerRow();
|
||||
for (int i = 0; i <= sBitmapHeight; i++, bits += bpr)
|
||||
memcpy(bits, &sScrollCornerNormalBits[i * sBitmapHeight * 4], sBitmapWidth * 4);
|
||||
|
||||
|
||||
//printf("setting up bitmap 1\n");
|
||||
fBitmaps[1] = new BBitmap(BRect(0.0f, 0.0f, sBitmapWidth, sBitmapHeight), sColorSpace);
|
||||
// fBitmaps[1]->SetBits((void *)sScrollCornerPushedBits, fBitmaps[1]->BitsLength(), 0L, sColorSpace);
|
||||
@ -257,63 +280,35 @@ ScrollCorner::SetDragging(bool dragging)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - ScrollView
|
||||
|
||||
|
||||
// constructor
|
||||
ScrollView::ScrollView(BView* child, uint32 scrollingFlags, BRect frame,
|
||||
const char *name, uint32 resizingMode, uint32 viewFlags,
|
||||
uint32 borderStyle, uint32 borderFlags)
|
||||
: BView(frame, name, resizingMode, viewFlags | B_FRAME_EVENTS | B_WILL_DRAW
|
||||
| B_FULL_UPDATE_ON_RESIZE),
|
||||
Scroller(),
|
||||
fChild(NULL),
|
||||
fScrollingFlags(scrollingFlags),
|
||||
|
||||
fHScrollBar(NULL),
|
||||
fVScrollBar(NULL),
|
||||
fScrollCorner(NULL),
|
||||
|
||||
fHVisible(true),
|
||||
fVVisible(true),
|
||||
fCornerVisible(true),
|
||||
|
||||
fWindowActive(false),
|
||||
fChildFocused(false),
|
||||
|
||||
fHSmallStep(1),
|
||||
fVSmallStep(1),
|
||||
|
||||
fBorderStyle(borderStyle),
|
||||
fBorderFlags(borderFlags)
|
||||
const char* name, uint32 resizingMode, uint32 viewFlags,
|
||||
uint32 borderStyle, uint32 borderFlags)
|
||||
: BView(frame, name, resizingMode,
|
||||
viewFlags | B_FRAME_EVENTS | B_WILL_DRAW | B_FULL_UPDATE_ON_RESIZE),
|
||||
Scroller()
|
||||
{
|
||||
// Set transparent view color -- our area is completely covered by
|
||||
// our children.
|
||||
SetViewColor(B_TRANSPARENT_32_BIT);
|
||||
// create scroll bars
|
||||
if (fScrollingFlags & (SCROLL_HORIZONTAL | SCROLL_HORIZONTAL_MAGIC)) {
|
||||
fHScrollBar = new InternalScrollBar(this,
|
||||
BRect(0.0, 0.0, 100.0, B_H_SCROLL_BAR_HEIGHT), B_HORIZONTAL);
|
||||
AddChild(fHScrollBar);
|
||||
}
|
||||
if (fScrollingFlags & (SCROLL_VERTICAL | SCROLL_VERTICAL_MAGIC)) {
|
||||
fVScrollBar = new InternalScrollBar(this,
|
||||
BRect(0.0, 0.0, B_V_SCROLL_BAR_WIDTH, 100.0), B_VERTICAL);
|
||||
AddChild(fVScrollBar);
|
||||
}
|
||||
// Create a scroll corner, if we can scroll into both direction.
|
||||
if (fHScrollBar && fVScrollBar) {
|
||||
fScrollCorner = new ScrollCorner(this);
|
||||
AddChild(fScrollCorner);
|
||||
}
|
||||
// add child
|
||||
if (child) {
|
||||
fChild = child;
|
||||
AddChild(child);
|
||||
if (Scrollable* scrollable = dynamic_cast<Scrollable*>(child))
|
||||
SetScrollTarget(scrollable);
|
||||
}
|
||||
_Init(child, scrollingFlags, borderStyle, borderFlags);
|
||||
}
|
||||
|
||||
#ifdef __HAIKU__
|
||||
|
||||
// constructor
|
||||
ScrollView::ScrollView(BView* child, uint32 scrollingFlags, const char* name,
|
||||
uint32 viewFlags, uint32 borderStyle, uint32 borderFlags)
|
||||
: BView(name, viewFlags | B_FRAME_EVENTS | B_WILL_DRAW
|
||||
| B_FULL_UPDATE_ON_RESIZE),
|
||||
Scroller()
|
||||
{
|
||||
_Init(child, scrollingFlags, borderStyle, borderFlags);
|
||||
}
|
||||
|
||||
#endif // __HAIKU__
|
||||
|
||||
// destructor
|
||||
ScrollView::~ScrollView()
|
||||
{
|
||||
@ -528,6 +523,21 @@ ScrollView::VSmallStep() const
|
||||
return fVSmallStep;
|
||||
}
|
||||
|
||||
// IsScrolling
|
||||
bool
|
||||
ScrollView::IsScrolling() const
|
||||
{
|
||||
return fScrolling;
|
||||
}
|
||||
|
||||
void
|
||||
ScrollView::SetScrollingEnabled(bool enabled)
|
||||
{
|
||||
Scroller::SetScrollingEnabled(enabled);
|
||||
if (IsScrollingEnabled())
|
||||
SetScrollOffset(ScrollOffset());
|
||||
}
|
||||
|
||||
// #pragma mark -
|
||||
|
||||
// DataRectChanged
|
||||
@ -583,10 +593,69 @@ ScrollView::ScrollTargetChanged(Scrollable* /*oldTarget*/,
|
||||
*/
|
||||
}
|
||||
|
||||
// _Init
|
||||
void
|
||||
ScrollView::_Init(BView* child, uint32 scrollingFlags, uint32 borderStyle,
|
||||
uint32 borderFlags)
|
||||
{
|
||||
fChild = NULL;
|
||||
fScrollingFlags = scrollingFlags;
|
||||
|
||||
fHScrollBar = NULL;
|
||||
fVScrollBar = NULL;
|
||||
fScrollCorner = NULL;
|
||||
|
||||
fHVisible = true;
|
||||
fVVisible = true;
|
||||
fCornerVisible = true;
|
||||
|
||||
fWindowActive = false;
|
||||
fChildFocused = false;
|
||||
|
||||
fScrolling = false;
|
||||
|
||||
fHSmallStep = 1;
|
||||
fVSmallStep = 1;
|
||||
|
||||
fBorderStyle = borderStyle;
|
||||
fBorderFlags = borderFlags;
|
||||
|
||||
// Set transparent view color -- our area is completely covered by
|
||||
// our children.
|
||||
SetViewColor(B_TRANSPARENT_32_BIT);
|
||||
// create scroll bars
|
||||
if (fScrollingFlags & (SCROLL_HORIZONTAL | SCROLL_HORIZONTAL_MAGIC)) {
|
||||
fHScrollBar = new InternalScrollBar(this,
|
||||
BRect(0.0, 0.0, 100.0, B_H_SCROLL_BAR_HEIGHT), B_HORIZONTAL);
|
||||
AddChild(fHScrollBar);
|
||||
}
|
||||
if (fScrollingFlags & (SCROLL_VERTICAL | SCROLL_VERTICAL_MAGIC)) {
|
||||
fVScrollBar = new InternalScrollBar(this,
|
||||
BRect(0.0, 0.0, B_V_SCROLL_BAR_WIDTH, 100.0), B_VERTICAL);
|
||||
AddChild(fVScrollBar);
|
||||
}
|
||||
// Create a scroll corner, if we can scroll into both direction.
|
||||
if (fHScrollBar && fVScrollBar) {
|
||||
fScrollCorner = new ScrollCorner(this);
|
||||
AddChild(fScrollCorner);
|
||||
}
|
||||
// add child
|
||||
if (child) {
|
||||
fChild = child;
|
||||
AddChild(child);
|
||||
if (Scrollable* scrollable = dynamic_cast<Scrollable*>(child))
|
||||
SetScrollTarget(scrollable);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// _ScrollValueChanged
|
||||
void
|
||||
ScrollView::_ScrollValueChanged(InternalScrollBar* scrollBar, float value)
|
||||
{
|
||||
if (!IsScrollingEnabled())
|
||||
return;
|
||||
|
||||
switch (scrollBar->Orientation()) {
|
||||
case B_HORIZONTAL:
|
||||
if (fHScrollBar)
|
||||
@ -682,14 +751,14 @@ ScrollView::_UpdateScrollBars()
|
||||
dataRect.Set(0.0, 0.0, 0.0, 0.0);
|
||||
visibleBounds.Set(0.0, 0.0, 0.0, 0.0);
|
||||
}
|
||||
float hProportion = min(1.0f, (visibleBounds.Width() + 1.0f) /
|
||||
(dataRect.Width() + 1.0f));
|
||||
float hMaxValue = max(dataRect.left,
|
||||
dataRect.right - visibleBounds.Width());
|
||||
float vProportion = min(1.0f, (visibleBounds.Height() + 1.0f) /
|
||||
(dataRect.Height() + 1.0f));
|
||||
float vMaxValue = max(dataRect.top,
|
||||
dataRect.bottom - visibleBounds.Height());
|
||||
float hProportion = min_c(1.0f, (visibleBounds.Width() + 1.0f)
|
||||
/ (dataRect.Width() + 1.0f));
|
||||
float hMaxValue = max_c(dataRect.left,
|
||||
dataRect.right - visibleBounds.Width());
|
||||
float vProportion = min_c(1.0f, (visibleBounds.Height() + 1.0f)
|
||||
/ (dataRect.Height() + 1.0f));
|
||||
float vMaxValue = max_c(dataRect.top,
|
||||
dataRect.bottom - visibleBounds.Height());
|
||||
// update horizontal scroll bar
|
||||
if (fHScrollBar) {
|
||||
fHScrollBar->SetProportion(hProportion);
|
||||
@ -894,6 +963,7 @@ ScrollView::_MaxVisibleRect() const
|
||||
}
|
||||
|
||||
#ifdef __HAIKU__
|
||||
|
||||
BSize
|
||||
ScrollView::_Size(BSize size)
|
||||
{
|
||||
@ -939,5 +1009,12 @@ ScrollView::_Size(BSize size)
|
||||
|
||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||
}
|
||||
|
||||
#endif // __HAIKU__
|
||||
|
||||
// _SetScrolling
|
||||
void
|
||||
ScrollView::_SetScrolling(bool scrolling)
|
||||
{
|
||||
fScrolling = scrolling;
|
||||
}
|
||||
|
@ -1,11 +1,4 @@
|
||||
/*
|
||||
* Copyright 2006, Haiku.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*
|
||||
* Authors:
|
||||
* Stephan Aßmus <superstippi@gmx.de>
|
||||
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
|
||||
*/
|
||||
// ScrollView.h
|
||||
|
||||
#ifndef SCROLL_VIEW_H
|
||||
#define SCROLL_VIEW_H
|
||||
@ -23,7 +16,9 @@ enum {
|
||||
SCROLL_VERTICAL = 0x02,
|
||||
SCROLL_HORIZONTAL_MAGIC = 0x04,
|
||||
SCROLL_VERTICAL_MAGIC = 0x08,
|
||||
SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS = 0x10
|
||||
SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS = 0x10,
|
||||
SCROLL_NO_FRAME = 0x20,
|
||||
SCROLL_LIST_FRAME = 0x40,
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -36,12 +31,18 @@ enum {
|
||||
|
||||
|
||||
class ScrollView : public BView, public Scroller {
|
||||
public:
|
||||
public:
|
||||
ScrollView(BView* child, uint32 scrollingFlags,
|
||||
BRect frame, const char *name,
|
||||
uint32 resizingMode, uint32 viewFlags,
|
||||
uint32 borderStyle = B_FANCY_BORDER,
|
||||
uint32 borderFlags = BORDER_ALL);
|
||||
#ifdef __HAIKU__
|
||||
ScrollView(BView* child, uint32 scrollingFlags,
|
||||
const char *name, uint32 viewFlags,
|
||||
uint32 borderStyle = B_FANCY_BORDER,
|
||||
uint32 borderFlags = BORDER_ALL);
|
||||
#endif // __HAIKU__
|
||||
virtual ~ScrollView();
|
||||
|
||||
virtual void AllAttached();
|
||||
@ -50,10 +51,11 @@ class ScrollView : public BView, public Scroller {
|
||||
virtual void WindowActivated(bool activated);
|
||||
|
||||
#ifdef __HAIKU__
|
||||
|
||||
virtual BSize MinSize();
|
||||
virtual BSize PreferredSize();
|
||||
#endif
|
||||
|
||||
#endif // __HAIKU__
|
||||
|
||||
uint32 ScrollingFlags() const;
|
||||
void SetVisibleRectIsChildBounds(bool flag);
|
||||
@ -74,6 +76,9 @@ class ScrollView : public BView, public Scroller {
|
||||
float HSmallStep() const;
|
||||
float VSmallStep() const;
|
||||
|
||||
virtual bool IsScrolling() const;
|
||||
virtual void SetScrollingEnabled(bool enabled);
|
||||
|
||||
protected:
|
||||
virtual void DataRectChanged(BRect oldDataRect,
|
||||
BRect newDataRect);
|
||||
@ -97,12 +102,16 @@ class ScrollView : public BView, public Scroller {
|
||||
bool fCornerVisible; // scroll corner visible flag
|
||||
bool fWindowActive;
|
||||
bool fChildFocused;
|
||||
bool fScrolling;
|
||||
float fHSmallStep;
|
||||
float fVSmallStep;
|
||||
|
||||
uint32 fBorderStyle;
|
||||
uint32 fBorderFlags;
|
||||
|
||||
void _Init(BView* child, uint32 scrollingFlags,
|
||||
uint32 borderStyle, uint32 borderFlags);
|
||||
|
||||
void _ScrollValueChanged(
|
||||
InternalScrollBar* scrollBar,
|
||||
float value);
|
||||
@ -124,6 +133,8 @@ private:
|
||||
virtual BSize _Size(BSize childSize);
|
||||
#endif
|
||||
|
||||
void _SetScrolling(bool scrolling);
|
||||
|
||||
friend class InternalScrollBar;
|
||||
friend class ScrollCorner;
|
||||
};
|
||||
|
@ -17,7 +17,8 @@
|
||||
|
||||
// constructor
|
||||
Scroller::Scroller()
|
||||
: fScrollTarget(NULL)
|
||||
: fScrollTarget(NULL),
|
||||
fScrollingEnabled(true)
|
||||
{
|
||||
}
|
||||
|
||||
@ -135,6 +136,19 @@ Scroller::VisibleRect() const
|
||||
return BRect();
|
||||
}
|
||||
|
||||
// SetScrollingEnabled
|
||||
void
|
||||
Scroller::SetScrollingEnabled(bool enabled)
|
||||
{
|
||||
fScrollingEnabled = enabled;
|
||||
}
|
||||
|
||||
// IsScrolling
|
||||
bool
|
||||
Scroller::IsScrolling() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// hooks
|
||||
|
||||
|
@ -5,7 +5,6 @@
|
||||
* Authors:
|
||||
* Ingo Weinhold <bonefish@cs.tu-berlin.de>
|
||||
*/
|
||||
|
||||
#ifndef SCROLLER_H
|
||||
#define SCROLLER_H
|
||||
|
||||
@ -31,6 +30,12 @@ class Scroller {
|
||||
BRect VisibleBounds() const;
|
||||
BRect VisibleRect() const;
|
||||
|
||||
virtual void SetScrollingEnabled(bool enabled);
|
||||
bool IsScrollingEnabled() const
|
||||
{ return fScrollingEnabled; }
|
||||
|
||||
virtual bool IsScrolling() const;
|
||||
|
||||
protected:
|
||||
virtual void DataRectChanged(BRect oldDataRect,
|
||||
BRect newDataRect);
|
||||
@ -45,6 +50,7 @@ protected:
|
||||
|
||||
protected:
|
||||
Scrollable* fScrollTarget;
|
||||
bool fScrollingEnabled;
|
||||
|
||||
friend class Scrollable;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user