xref: /haiku/src/apps/icon-o-matic/generic/gui/scrollview/ScrollView.h (revision b30304acc8c37e678a1bf66976d15bdab103f931)
1 /*
2  * Copyright 2006, 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 
17 class Scrollable;
18 class InternalScrollBar;
19 class ScrollCorner;
20 
21 enum {
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 };
28 
29 enum {
30 	BORDER_LEFT		= 0x01,
31 	BORDER_TOP		= 0x02,
32 	BORDER_RIGHT	= 0x04,
33 	BORDER_BOTTOM	= 0x08,
34 	BORDER_ALL		= BORDER_LEFT | BORDER_TOP | BORDER_RIGHT | BORDER_BOTTOM
35 };
36 
37 
38 class ScrollView : public BView, public Scroller {
39  public:
40 								ScrollView(BView* child, uint32 scrollingFlags,
41 									BRect frame, const char *name,
42 									uint32 resizingMode, uint32 viewFlags,
43 									uint32 borderStyle = B_FANCY_BORDER,
44 									uint32 borderFlags = BORDER_ALL);
45 	virtual						~ScrollView();
46 
47 	virtual	void				AllAttached();
48 	virtual	void				Draw(BRect updateRect);
49 	virtual	void				FrameResized(float width, float height);
50 	virtual	void				WindowActivated(bool activated);
51 
52 #ifdef __HAIKU__
53 	virtual	BSize				MinSize();
54 	virtual	BSize				PreferredSize();
55 #endif
56 
57 
58 			uint32				ScrollingFlags() const;
59 			void				SetVisibleRectIsChildBounds(bool flag);
60 			bool				VisibleRectIsChildBounds() const;
61 
62 			BView*				Child() const;
63 			void				ChildFocusChanged(bool focused);
64 
65 			BScrollBar*			HScrollBar() const;
66 			BScrollBar*			VScrollBar() const;
67 			BView*				HVScrollCorner() const;
68 
69 			void				SetHSmallStep(float hStep);
70 			void				SetVSmallStep(float vStep);
71 			void				SetSmallSteps(float hStep, float vStep);
72 			void				GetSmallSteps(float* hStep,
73 											  float* vStep) const;
74 			float				HSmallStep() const;
75 			float				VSmallStep() const;
76 
77  protected:
78 	virtual	void				DataRectChanged(BRect oldDataRect,
79 												BRect newDataRect);
80 	virtual	void				ScrollOffsetChanged(BPoint oldOffset,
81 													BPoint newOffset);
82 	virtual	void				VisibleSizeChanged(float oldWidth,
83 												   float oldHeight,
84 												   float newWidth,
85 												   float newHeight);
86 	virtual	void				ScrollTargetChanged(Scrollable* oldTarget,
87 													Scrollable* newTarget);
88 
89  private:
90 			BView*				fChild;			// child view
91 			uint32				fScrollingFlags;
92 			InternalScrollBar*	fHScrollBar;	// horizontal scroll bar
93 			InternalScrollBar*	fVScrollBar;	// vertical scroll bar
94 			ScrollCorner*		fScrollCorner;	// scroll corner
95 			bool				fHVisible;		// horizontal/vertical scroll
96 			bool				fVVisible;		// bar visible flag
97 			bool				fCornerVisible;	// scroll corner visible flag
98 			bool				fWindowActive;
99 			bool				fChildFocused;
100 			float				fHSmallStep;
101 			float				fVSmallStep;
102 
103 			uint32				fBorderStyle;
104 			uint32				fBorderFlags;
105 
106 			void				_ScrollValueChanged(
107 										InternalScrollBar* scrollBar,
108 										float value);
109 			void				_ScrollCornerValueChanged(BPoint offset);
110 
111 protected:
112 	virtual	void				_Layout(uint32 flags);
113 
114 private:
115 			void				_UpdateScrollBars();
116 			uint32				_UpdateScrollBarVisibility();
117 
118 			BRect				_InnerRect() const;
119 			BRect				_ChildRect() const;
120 			BRect				_ChildRect(bool hbar, bool vbar) const;
121 			BRect				_GuessVisibleRect(bool hbar, bool vbar) const;
122 			BRect				_MaxVisibleRect() const;
123 #ifdef __HAIKU__
124 	virtual	BSize				_Size(BSize childSize);
125 #endif
126 
127 	friend class InternalScrollBar;
128 	friend class ScrollCorner;
129 };
130 
131 
132 
133 #endif	// SCROLL_VIEW_H
134