xref: /haiku/src/apps/cortex/support/ScrollHelpers.h (revision 3e216965baa8d58a67bf7372e2bfa13d999f5a9d)
1 // ScrollHelpers.h
2 // e.moon 9mar99
3 //
4 // An interface/driver view combination to simplify the task
5 // of redirecting a scroll bar: an invisible proxy view
6 // forwards scroll requests back to a scroll-handler.
7 
8 #ifndef __EMOON_ScrollHelpers_H__
9 #define __EMOON_ScrollHelpers_H__
10 
11 #include <View.h>
12 #include "debug_tools.h"
13 
14 class IScrollTarget {
15 public:			// interface
16 	virtual void handleScrollBy(float xDelta, float yDelta)=0;
17 };
18 
19 class ScrollProxyView : public BView {
20 	typedef BView _inherited;
21 public:
22 	ScrollProxyView(IScrollTarget* pTarget, BRect frame) :
23 		m_pTarget(pTarget),
24 		BView(frame, "scrollProxy", B_FOLLOW_LEFT|B_FOLLOW_TOP, 0) {}
25 	virtual ~ScrollProxyView() {}
26 
27 	virtual void ScrollTo(BPoint where) {
28 		float xDelta = where.x - Bounds().left;
29 		float yDelta = where.y - Bounds().top;
30 		_inherited::ScrollTo(where);
31 		ASSERT(m_pTarget);
32 		m_pTarget->handleScrollBy(xDelta, yDelta);
33 	}
34 
35 protected:
36 	IScrollTarget*		m_pTarget;
37 };
38 
39 #endif /* __EMOON_ScrollHelpers_H__ */