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