ScrollView.h revision 1f424632
1/*
2 * Copyright 2004-2009, Axel D��rfler, axeld@pinc-software.de.
3 * Copyright 2014 Haiku, Inc. All rights reserved.
4 * Distributed under the terms of the MIT License.
5 *
6 * Authors:
7 *		Axel D��rfler, axeld@pinc-software.de
8 *		John Scipione, jscpione@gmail.com
9 */
10#ifndef _SCROLL_VIEW_H
11#define _SCROLL_VIEW_H
12
13
14#include <ScrollBar.h>
15
16
17/*!	The BScrollView is a convenience class to add a scrolling
18	mechanism to the target view.
19*/
20class BScrollView : public BView {
21public:
22								BScrollView(const char* name, BView* target,
23									uint32 resizingMode
24										= B_FOLLOW_LEFT | B_FOLLOW_TOP,
25									uint32 flags = 0, bool horizontal = false,
26									bool vertical = false,
27									border_style border = B_FANCY_BORDER);
28								BScrollView(const char* name, BView* target,
29									uint32 flags, bool horizontal,
30									bool vertical, border_style border
31										= B_FANCY_BORDER);
32								BScrollView(BMessage* archive);
33	virtual						~BScrollView();
34
35	static	BArchivable*		Instantiate(BMessage* archive);
36	virtual	status_t			Archive(BMessage* archive, bool deep = true) const;
37
38	// Hook methods
39	virtual	void				AllAttached();
40	virtual	void				AllDetached();
41
42	virtual	void				AttachedToWindow();
43	virtual	void				DetachedFromWindow();
44
45	virtual	void				Draw(BRect updateRect);
46	virtual	void				FrameMoved(BPoint newPosition);
47	virtual	void				FrameResized(float newWidth, float newHeight);
48
49	virtual	void				MessageReceived(BMessage* message);
50
51	virtual	void				MouseDown(BPoint where);
52	virtual	void				MouseMoved(BPoint where, uint32 code,
53									const BMessage* dragMessage);
54	virtual	void				MouseUp(BPoint where);
55
56	virtual	void				WindowActivated(bool active);
57
58	// Size
59	virtual	void				GetPreferredSize(float* _width, float* _height);
60	virtual	void				ResizeToPreferred();
61
62	virtual	void				MakeFocus(bool focus = true);
63
64	virtual	BSize				MinSize();
65	virtual	BSize				MaxSize();
66	virtual	BSize				PreferredSize();
67
68	// BScrollBar
69			BScrollBar*			ScrollBar(orientation posture) const;
70
71	virtual	void				SetBorder(border_style border);
72			border_style		Border() const;
73
74	virtual	status_t			SetBorderHighlighted(bool highlight);
75			bool				IsBorderHighlighted() const;
76
77			void				SetTarget(BView* target);
78			BView*				Target() const;
79
80	// Scripting
81	virtual	BHandler*			ResolveSpecifier(BMessage* message,
82									int32 index, BMessage* specifier,
83									int32 what, const char* property);
84	virtual	status_t			GetSupportedSuites(BMessage* message);
85
86	virtual	status_t			Perform(perform_code d, void* arg);
87
88protected:
89	virtual	void				LayoutInvalidated(bool descendants = false);
90	virtual	void				DoLayout();
91
92private:
93	// FBC padding and forbidden methods
94	virtual	void				_ReservedScrollView1();
95	virtual	void				_ReservedScrollView2();
96	virtual	void				_ReservedScrollView3();
97	virtual	void				_ReservedScrollView4();
98
99			BScrollView&		operator=(const BScrollView& other);
100
101private:
102	friend class BView;
103
104			void				_Init(bool horizontal, bool vertical);
105			float				_BorderSize() const;
106			BRect				_InnerFrame() const;
107			BSize				_ComputeSize(BSize targetSize) const;
108			BRect				_ComputeFrame(BRect targetRect) const;
109			void				_AlignScrollBars(bool horizontal,
110									bool vertical, BRect targetFrame);
111
112	static	BRect				_ComputeFrame(BRect frame, bool horizontal,
113									bool vertical, border_style border);
114	static	BRect				_ComputeFrame(BView* target, bool horizontal,
115									bool vertical, border_style border);
116	static	float				_BorderSize(border_style border);
117	static	int32				_ModifyFlags(int32 flags, border_style border);
118
119private:
120			BView*				fTarget;
121			BScrollBar*			fHorizontalScrollBar;
122			BScrollBar*			fVerticalScrollBar;
123			border_style		fBorder;
124			uint16				fPreviousWidth;
125			uint16				fPreviousHeight;
126			bool				fHighlighted;
127
128			uint32				_reserved[3];
129};
130
131#endif // _SCROLL_VIEW_H
132