xref: /haiku/headers/os/interface/ScrollView.h (revision ae0a10cad3999b13cbfa47a3d947a5219d2d90f4)
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 */
15 class BScrollView : public BView {
16 public:
17 								BScrollView(const char* name, BView* target,
18 									uint32 resizingMode = B_FOLLOW_LEFT_TOP,
19 									uint32 flags = 0, bool horizontal = false,
20 									bool vertical = false,
21 									border_style border = B_FANCY_BORDER);
22 								BScrollView(const char* name, BView* target,
23 									uint32 flags, bool horizontal,
24 									bool vertical, border_style border
25 										= B_FANCY_BORDER);
26 								BScrollView(BMessage* archive);
27 	virtual						~BScrollView();
28 
29 	static	BArchivable*		Instantiate(BMessage* archive);
30 	virtual	status_t			Archive(BMessage* archive, bool deep = true) const;
31 	virtual status_t			AllUnarchived(const BMessage* archive);
32 
33 	// Hook methods
34 	virtual	void				AllAttached();
35 	virtual	void				AllDetached();
36 
37 	virtual	void				AttachedToWindow();
38 	virtual	void				DetachedFromWindow();
39 
40 	virtual	void				Draw(BRect updateRect);
41 	virtual	void				FrameMoved(BPoint newPosition);
42 	virtual	void				FrameResized(float newWidth, float newHeight);
43 
44 	virtual	void				MessageReceived(BMessage* message);
45 
46 	virtual	void				MouseDown(BPoint where);
47 	virtual	void				MouseMoved(BPoint where, uint32 code,
48 									const BMessage* dragMessage);
49 	virtual	void				MouseUp(BPoint where);
50 
51 	virtual	void				WindowActivated(bool active);
52 
53 	// Size
54 	virtual	void				GetPreferredSize(float* _width, float* _height);
55 	virtual	void				ResizeToPreferred();
56 
57 	virtual	void				MakeFocus(bool focus = true);
58 
59 	virtual	BSize				MinSize();
60 	virtual	BSize				MaxSize();
61 	virtual	BSize				PreferredSize();
62 
63 	// BScrollBar
64 			BScrollBar*			ScrollBar(orientation direction) const;
65 
66 	virtual	void				SetBorder(border_style border);
67 			border_style		Border() const;
68 			void				SetBorders(uint32 borders);
69 			uint32				Borders() const;
70 
71 	virtual	status_t			SetBorderHighlighted(bool highlight);
72 			bool				IsBorderHighlighted() const;
73 
74 			void				SetTarget(BView* target);
75 			BView*				Target() const;
76 
77 	// Scripting
78 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
79 									int32 index, BMessage* specifier,
80 									int32 what, const char* property);
81 	virtual	status_t			GetSupportedSuites(BMessage* message);
82 
83 	virtual	status_t			Perform(perform_code d, void* arg);
84 
85 protected:
86 	virtual	void				LayoutInvalidated(bool descendants = false);
87 	virtual	void				DoLayout();
88 
89 private:
90 	// FBC padding and forbidden methods
91 	virtual	void				_ReservedScrollView1();
92 	virtual	void				_ReservedScrollView2();
93 	virtual	void				_ReservedScrollView3();
94 	virtual	void				_ReservedScrollView4();
95 
96 			BScrollView&		operator=(const BScrollView& other);
97 
98 private:
99 	friend class BView;
100 
101 			void				_Init(bool horizontal, bool vertical);
102 			float				_BorderSize() const;
103 			BRect				_InnerFrame() const;
104 			BSize				_ComputeSize(BSize targetSize) const;
105 			BRect				_ComputeFrame(BRect targetRect) const;
106 			void				_AlignScrollBars(bool horizontal,
107 									bool vertical, BRect targetFrame);
108 
109 	static	BRect				_ComputeFrame(BRect frame, BScrollBar* horizontal,
110 									BScrollBar* vertical, border_style border,
111 									uint32 borders);
112 	static	BRect				_ComputeFrame(BView* target, BScrollBar* horizontal,
113 									BScrollBar* vertical, border_style border,
114 									uint32 borders);
115 	static	float				_BorderSize(border_style border);
116 	static	uint32				_ModifyFlags(uint32 flags, BView* target,
117 									border_style border);
118 	static	void				_InsetBorders(BRect& frame, border_style border,
119 									uint32 borders, bool expand = false);
120 private:
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