xref: /haiku/headers/os/interface/ScrollBar.h (revision 9fe3529f3eadd7f63c3185589caa341b79402251)
1 /*
2  * Copyright 2001-2020 Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef	_SCROLL_BAR_H
6 #define	_SCROLL_BAR_H
7 
8 
9 #include <View.h>
10 
11 
12 #define B_V_SCROLL_BAR_WIDTH	14.0f
13 #define B_H_SCROLL_BAR_HEIGHT	14.0f
14 
15 
16 class BScrollBar : public BView {
17 public:
18 								BScrollBar(BRect frame, const char* name,
19 									BView* target, float min, float max,
20 									orientation direction);
21 								BScrollBar(const char* name, BView* target,
22 									float min, float max,
23 									orientation orientation);
24 								BScrollBar(BMessage* archive);
25 	virtual						~BScrollBar();
26 	static	BArchivable*		Instantiate(BMessage* archive);
27 	virtual	status_t			Archive(BMessage* archive,
28 									bool deep = true) const;
29 
30 	virtual void				AllAttached();
31 	virtual void				AllDetached();
32 
33 	virtual	void				AttachedToWindow();
34 	virtual	void				DetachedFromWindow();
35 
36 	virtual	void				Draw(BRect updateRect);
37 	virtual	void				FrameMoved(BPoint new_position);
38 	virtual	void				FrameResized(float newWidth, float newHeight);
39 
40 	virtual void				MessageReceived(BMessage* message);
41 
42 	virtual	void				MouseDown(BPoint where);
43 	virtual	void				MouseUp(BPoint where);
44 	virtual	void				MouseMoved(BPoint where, uint32 code,
45 									const BMessage* dragMessage);
46 
47 	virtual	void				WindowActivated(bool active);
48 
49 			void				SetValue(float value);
50 			float				Value() const;
51 
52 			void				SetProportion(float);
53 			float				Proportion() const;
54 
55 	virtual	void				ValueChanged(float newValue);
56 
57 			void				SetRange(float min, float max);
58 			void				GetRange(float* _min, float* _max) const;
59 			void				SetSteps(float smallStep, float largeStep);
60 			void				GetSteps(float* _smallStep,
61 									float* _largeStep) const;
62 
63 			void				SetTarget(BView *target);
64 			void				SetTarget(const char* targetName);
65 			BView*				Target() const;
66 
67 			void				SetOrientation(orientation direction);
68 			orientation			Orientation() const;
69 
70 			// TODO: Make this a virtual method, it should be one,
71 			// but it's not important right now. This is supposed
72 			// to be used in case the BScrollBar should draw part of
73 			// the focus indication of the target view for aesthetical
74 			// reasons. BScrollView will forward this method.
75 			status_t			SetBorderHighlighted(bool highlight);
76 
77 	virtual void				GetPreferredSize(float* _width,
78 									float* _height);
79 	virtual void				ResizeToPreferred();
80 	virtual void				MakeFocus(bool focus = true);
81 
82 	virtual	BSize				MinSize();
83 	virtual	BSize				MaxSize();
84 	virtual	BSize				PreferredSize();
85 
86 	virtual status_t			GetSupportedSuites(BMessage* message);
87 	virtual BHandler*			ResolveSpecifier(BMessage* message,
88 									int32 index, BMessage* specifier,
89 									int32 what, const char* property);
90 
91 	virtual status_t			Perform(perform_code d, void* arg);
92 
93 private:
94 	class Private;
95 	friend class Private;
96 
97 	friend status_t control_scrollbar(scroll_bar_info* info,
98 		BScrollBar *bar);
99 		// for use within the preflet
100 
101 	virtual	void				_ReservedScrollBar1();
102 	virtual	void				_ReservedScrollBar2();
103 	virtual	void				_ReservedScrollBar3();
104 	virtual	void				_ReservedScrollBar4();
105 
106 	// disabled
107 			BScrollBar&			operator=(const BScrollBar& other);
108 
109 			bool				_DoubleArrows() const;
110 			void				_UpdateThumbFrame();
111 			float				_ValueFor(BPoint where) const;
112 			int32				_ButtonFor(BPoint where) const;
113 			BRect				_ButtonRectFor(int32 button) const;
114 			void				_UpdateTargetValue(BPoint where);
115 			void				_UpdateArrowButtons();
116 
117 			BSize				_MinSize() const;
118 
119 private:
120 			float				fMin;
121 			float				fMax;
122 			float				fSmallStep;
123 			float				fLargeStep;
124 			float				fValue;
125 			float				fProportion;
126 			BView*				fTarget;
127 			orientation			fOrientation;
128 
129 			Private*			fPrivateData;
130 
131 			uint32				_reserved[4];
132 };
133 
134 #endif	// _SCROLL_BAR_H
135