1/*
2 * Copyright 2006-2009, Haiku.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Stephan Aßmus <superstippi@gmx.de>
7 *		Ingo Weinhold <bonefish@cs.tu-berlin.de>
8 */
9
10#ifndef SCROLL_VIEW_H
11#define SCROLL_VIEW_H
12
13#include <View.h>
14
15#include "Scroller.h"
16
17class Scrollable;
18class InternalScrollBar;
19class ScrollCorner;
20
21enum {
22	SCROLL_HORIZONTAL						= 0x01,
23	SCROLL_VERTICAL							= 0x02,
24	SCROLL_HORIZONTAL_MAGIC					= 0x04,
25	SCROLL_VERTICAL_MAGIC					= 0x08,
26	SCROLL_VISIBLE_RECT_IS_CHILD_BOUNDS		= 0x10,
27	SCROLL_NO_FRAME							= 0x20,
28	SCROLL_LIST_FRAME						= 0x40,
29};
30
31enum {
32	BORDER_LEFT		= 0x01,
33	BORDER_TOP		= 0x02,
34	BORDER_RIGHT	= 0x04,
35	BORDER_BOTTOM	= 0x08,
36	BORDER_ALL		= BORDER_LEFT | BORDER_TOP | BORDER_RIGHT | BORDER_BOTTOM
37};
38
39
40class ScrollView : public BView, public Scroller {
41public:
42								ScrollView(BView* child, uint32 scrollingFlags,
43									BRect frame, const char *name,
44									uint32 resizingMode, uint32 viewFlags,
45									uint32 borderStyle = B_FANCY_BORDER,
46									uint32 borderFlags = BORDER_ALL);
47#ifdef __HAIKU__
48								ScrollView(BView* child, uint32 scrollingFlags,
49									const char *name, uint32 viewFlags,
50									uint32 borderStyle = B_FANCY_BORDER,
51									uint32 borderFlags = BORDER_ALL);
52#endif // __HAIKU__
53	virtual						~ScrollView();
54
55	virtual	void				AllAttached();
56	virtual	void				Draw(BRect updateRect);
57	virtual	void				FrameResized(float width, float height);
58	virtual	void				WindowActivated(bool activated);
59
60#ifdef __HAIKU__
61
62	virtual	BSize				MinSize();
63	virtual	BSize				PreferredSize();
64
65#endif // __HAIKU__
66
67			uint32				ScrollingFlags() const;
68			void				SetVisibleRectIsChildBounds(bool flag);
69			bool				VisibleRectIsChildBounds() const;
70
71			BView*				Child() const;
72			void				ChildFocusChanged(bool focused);
73
74			BScrollBar*			HScrollBar() const;
75			BScrollBar*			VScrollBar() const;
76			BView*				HVScrollCorner() const;
77
78			void				SetHSmallStep(float hStep);
79			void				SetVSmallStep(float vStep);
80			void				SetSmallSteps(float hStep, float vStep);
81			void				GetSmallSteps(float* hStep,
82											  float* vStep) const;
83			float				HSmallStep() const;
84			float				VSmallStep() const;
85
86	virtual	bool				IsScrolling() const;
87	virtual	void				SetScrollingEnabled(bool enabled);
88
89 protected:
90	virtual	void				DataRectChanged(BRect oldDataRect,
91												BRect newDataRect);
92	virtual	void				ScrollOffsetChanged(BPoint oldOffset,
93													BPoint newOffset);
94	virtual	void				VisibleSizeChanged(float oldWidth,
95												   float oldHeight,
96												   float newWidth,
97												   float newHeight);
98	virtual	void				ScrollTargetChanged(Scrollable* oldTarget,
99													Scrollable* newTarget);
100
101 private:
102			BView*				fChild;			// child view
103			uint32				fScrollingFlags;
104			InternalScrollBar*	fHScrollBar;	// horizontal scroll bar
105			InternalScrollBar*	fVScrollBar;	// vertical scroll bar
106			ScrollCorner*		fScrollCorner;	// scroll corner
107			bool				fHVisible;		// horizontal/vertical scroll
108			bool				fVVisible;		// bar visible flag
109			bool				fCornerVisible;	// scroll corner visible flag
110			bool				fWindowActive;
111			bool				fChildFocused;
112			bool				fScrolling;
113			float				fHSmallStep;
114			float				fVSmallStep;
115
116			uint32				fBorderStyle;
117			uint32				fBorderFlags;
118
119			void				_Init(BView* child, uint32 scrollingFlags,
120									uint32 borderStyle, uint32 borderFlags);
121
122			void				_ScrollValueChanged(
123										InternalScrollBar* scrollBar,
124										float value);
125			void				_ScrollCornerValueChanged(BPoint offset);
126
127protected:
128	virtual	void				_Layout(uint32 flags);
129
130private:
131			void				_UpdateScrollBars();
132			uint32				_UpdateScrollBarVisibility();
133
134			BRect				_InnerRect() const;
135			BRect				_ChildRect() const;
136			BRect				_ChildRect(bool hbar, bool vbar) const;
137			BRect				_GuessVisibleRect(bool hbar, bool vbar) const;
138			BRect				_MaxVisibleRect() const;
139#ifdef __HAIKU__
140	virtual	BSize				_Size(BSize childSize);
141#endif
142
143			void				_SetScrolling(bool scrolling);
144
145	friend class InternalScrollBar;
146	friend class ScrollCorner;
147};
148
149
150
151#endif	// SCROLL_VIEW_H
152