xref: /haiku/headers/os/interface/ScrollView.h (revision 508f54795f39c3e7552d87c95aae9dd8ec6f505b)
1 /*
2  * Copyright 2004-2009, 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 */
15 class BScrollView : public BView {
16 public:
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,
32 									bool deep = true) const;
33 
34 	virtual void				AttachedToWindow();
35 	virtual	void				DetachedFromWindow();
36 	virtual	void				AllAttached();
37 	virtual	void				AllDetached();
38 
39 	virtual void				Draw(BRect updateRect);
40 
41 	virtual void				WindowActivated(bool active);
42 	virtual void				MakeFocus(bool state = true);
43 
44 	virtual void				GetPreferredSize(float* _width,
45 									float* _height);
46 	virtual	BSize				MinSize();
47 	virtual	BSize				MaxSize();
48 	virtual	BSize				PreferredSize();
49 	virtual void				ResizeToPreferred();
50 
51 	virtual	void				InvalidateLayout(bool descendants = false);
52 	virtual	void				DoLayout();
53 	virtual	void				FrameMoved(BPoint position);
54 	virtual	void				FrameResized(float width, float height);
55 
56 	virtual void				MessageReceived(BMessage* message);
57 
58 	virtual void				MouseDown(BPoint point);
59 	virtual	void				MouseUp(BPoint point);
60 	virtual	void				MouseMoved(BPoint point, uint32 code,
61 									const BMessage* dragMessage);
62 
63 	// BScrollView
64 			BScrollBar*			ScrollBar(orientation posture) const;
65 
66 	virtual void				SetBorder(border_style border);
67 			border_style		Border() const;
68 
69 	virtual status_t			SetBorderHighlighted(bool state);
70 			bool				IsBorderHighlighted() const;
71 
72 			void				SetTarget(BView* target);
73 			BView*				Target() const;
74 
75 	// Scripting
76 	virtual BHandler*			ResolveSpecifier(BMessage* message,
77 									int32 index, BMessage* specifier,
78 									int32 form, const char* property);
79 	virtual status_t			GetSupportedSuites(BMessage* data);
80 
81 	virtual status_t			Perform(perform_code d, void* arg);
82 
83 private:
84 	// FBC padding and forbidden methods
85 	virtual	void				_ReservedScrollView1();
86 	virtual	void				_ReservedScrollView2();
87 	virtual	void				_ReservedScrollView3();
88 	virtual	void				_ReservedScrollView4();
89 
90 			BScrollView&		operator=(const BScrollView& other);
91 
92 private:
93 	friend class BView;
94 
95 			void				_Init(bool horizontal, bool vertical);
96 			float				_BorderSize() const;
97 			BRect				_InnerFrame() const;
98 			BSize				_ComputeSize(BSize targetSize) const;
99 			BRect				_ComputeFrame(BRect targetRect) const;
100 			void				_AlignScrollBars(bool horizontal,
101 									bool vertical, BRect targetFrame);
102 
103 	static	BRect				_ComputeFrame(BRect frame, bool horizontal,
104 									bool vertical, border_style border);
105 	static	BRect				_ComputeFrame(BView* target, bool horizontal,
106 									bool vertical, border_style border);
107 	static	float				_BorderSize(border_style border);
108 	static	int32				_ModifyFlags(int32 flags, border_style border);
109 
110 private:
111 			BView*				fTarget;
112 			BScrollBar*			fHorizontalScrollBar;
113 			BScrollBar*			fVerticalScrollBar;
114 			border_style		fBorder;
115 			uint16				fPreviousWidth;
116 			uint16				fPreviousHeight;
117 			bool				fHighlighted;
118 
119 			uint32				_reserved[3];
120 };
121 
122 #endif // _SCROLL_VIEW_H
123