ScrollView.h revision c466b4da
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	virtual status_t			AllUnarchived(const BMessage* archive);
38
39	// Hook methods
40	virtual	void				AllAttached();
41	virtual	void				AllDetached();
42
43	virtual	void				AttachedToWindow();
44	virtual	void				DetachedFromWindow();
45
46	virtual	void				Draw(BRect updateRect);
47	virtual	void				FrameMoved(BPoint newPosition);
48	virtual	void				FrameResized(float newWidth, float newHeight);
49
50	virtual	void				MessageReceived(BMessage* message);
51
52	virtual	void				MouseDown(BPoint where);
53	virtual	void				MouseMoved(BPoint where, uint32 code,
54									const BMessage* dragMessage);
55	virtual	void				MouseUp(BPoint where);
56
57	virtual	void				WindowActivated(bool active);
58
59	// Size
60	virtual	void				GetPreferredSize(float* _width, float* _height);
61	virtual	void				ResizeToPreferred();
62
63	virtual	void				MakeFocus(bool focus = true);
64
65	virtual	BSize				MinSize();
66	virtual	BSize				MaxSize();
67	virtual	BSize				PreferredSize();
68
69	// BScrollBar
70			BScrollBar*			ScrollBar(orientation direction) const;
71
72	virtual	void				SetBorder(border_style border);
73			border_style		Border() const;
74
75	virtual	status_t			SetBorderHighlighted(bool highlight);
76			bool				IsBorderHighlighted() const;
77
78			void				SetTarget(BView* target);
79			BView*				Target() const;
80
81	// Scripting
82	virtual	BHandler*			ResolveSpecifier(BMessage* message,
83									int32 index, BMessage* specifier,
84									int32 what, const char* property);
85	virtual	status_t			GetSupportedSuites(BMessage* message);
86
87	virtual	status_t			Perform(perform_code d, void* arg);
88
89protected:
90	virtual	void				LayoutInvalidated(bool descendants = false);
91	virtual	void				DoLayout();
92
93private:
94	// FBC padding and forbidden methods
95	virtual	void				_ReservedScrollView1();
96	virtual	void				_ReservedScrollView2();
97	virtual	void				_ReservedScrollView3();
98	virtual	void				_ReservedScrollView4();
99
100			BScrollView&		operator=(const BScrollView& other);
101
102private:
103	friend class BView;
104
105			void				_Init(bool horizontal, bool vertical);
106			float				_BorderSize() const;
107			BRect				_InnerFrame() const;
108			BSize				_ComputeSize(BSize targetSize) const;
109			BRect				_ComputeFrame(BRect targetRect) const;
110			void				_AlignScrollBars(bool horizontal,
111									bool vertical, BRect targetFrame);
112
113	static	BRect				_ComputeFrame(BRect frame, bool horizontal,
114									bool vertical, border_style border);
115	static	BRect				_ComputeFrame(BView* target, bool horizontal,
116									bool vertical, border_style border);
117	static	float				_BorderSize(border_style border);
118	static	int32				_ModifyFlags(int32 flags, border_style border);
119
120private:
121			BView*				fTarget;
122			BScrollBar*			fHorizontalScrollBar;
123			BScrollBar*			fVerticalScrollBar;
124			border_style		fBorder;
125			uint16				fPreviousWidth;
126			uint16				fPreviousHeight;
127			bool				fHighlighted;
128
129			uint32				_reserved[3];
130};
131
132#endif // _SCROLL_VIEW_H
133