xref: /haiku/headers/os/interface/ScrollBar.h (revision bc3955fea5b07e2e94a27fc05e4bb58fe6f0319b)
1 /*
2  * Copyright (c) 2001-2008, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT license.
4  *
5  * Authors:
6  *		Marc Flerackers (mflerackers@androme.be)
7  *		DarkWyrm (bpmagic@columbus.rr.com)
8  *		Stefano Ceccherini (burton666@libero.it)
9  *		Stephan Aßmus <superstippi@gmx.de>
10  */
11 #ifndef	_SCROLL_BAR_H
12 #define	_SCROLL_BAR_H
13 
14 
15 #include <BeBuild.h>
16 #include <View.h>
17 
18 
19 #define B_V_SCROLL_BAR_WIDTH	14.0f
20 #define B_H_SCROLL_BAR_HEIGHT	14.0f
21 
22 // TODO: shouldn't these be moved into the implementation?
23 #define SCROLL_BAR_MAXIMUM_KNOB_SIZE	50
24 #define SCROLL_BAR_MINIMUM_KNOB_SIZE	9
25 
26 #define DISABLES_ON_WINDOW_DEACTIVATION 1
27 
28 
29 class BScrollBar : public BView {
30 public:
31 								BScrollBar(BRect frame, const char* name,
32 									BView* target, float min, float max,
33 									orientation direction);
34 								BScrollBar(const char* name, BView* target,
35 									float min, float max, orientation direction);
36 								BScrollBar(BMessage* data);
37 	virtual						~BScrollBar();
38 	static	BArchivable*		Instantiate(BMessage* data);
39 	virtual	status_t			Archive(BMessage *data, bool deep = true) const;
40 
41 	virtual	void				AttachedToWindow();
42 			void				SetValue(float value);
43 			float				Value() const;
44 			void				SetProportion(float);
45 			float				Proportion() const;
46 	virtual	void				ValueChanged(float newValue);
47 
48 			void				SetRange(float min, float max);
49 			void				GetRange(float* _min, float* _max) const;
50 			void				SetSteps(float smallStep, float largeStep);
51 			void				GetSteps(float* _smallStep,
52 									float* _largeStep) const;
53 			void				SetTarget(BView *target);
54 			void				SetTarget(const char* targetName);
55 			BView*				Target() const;
56 			void				SetOrientation(enum orientation orientation);
57 			orientation			Orientation() const;
58 
59 	virtual void				MessageReceived(BMessage* message);
60 	virtual	void				MouseDown(BPoint pt);
61 	virtual	void				MouseUp(BPoint pt);
62 	virtual	void				MouseMoved(BPoint pt, uint32 code,
63 									const BMessage* dragMessage);
64 	virtual	void				DetachedFromWindow();
65 	virtual	void				Draw(BRect updateRect);
66 	virtual	void				FrameMoved(BPoint new_position);
67 	virtual	void				FrameResized(float newWidth, float newHeight);
68 
69 	virtual BHandler*			ResolveSpecifier(BMessage* message,
70 									int32 index, BMessage* specifier,
71 									int32 form, const char* property);
72 
73 	virtual void				ResizeToPreferred();
74 	virtual void				GetPreferredSize(float* _width, float* _height);
75 	virtual void				MakeFocus(bool state = true);
76 	virtual void				AllAttached();
77 	virtual void				AllDetached();
78 	virtual status_t			GetSupportedSuites(BMessage* data);
79 
80 	virtual	BSize				MinSize();
81 	virtual	BSize				MaxSize();
82 	virtual	BSize				PreferredSize();
83 
84 	virtual status_t			Perform(perform_code d, void* arg);
85 
86 #if DISABLES_ON_WINDOW_DEACTIVATION
87 	virtual	void				WindowActivated(bool active);
88 #endif
89 
90 private:
91 	class Private;
92 	friend class Private;
93 
94 	friend status_t control_scrollbar(scroll_bar_info* info,
95 		BScrollBar *bar);
96 		// for use within the preflet
97 
98 	virtual	void				_ReservedScrollBar1();
99 	virtual	void				_ReservedScrollBar2();
100 	virtual	void				_ReservedScrollBar3();
101 	virtual	void				_ReservedScrollBar4();
102 
103 	// disabled
104 			BScrollBar&			operator=(const BScrollBar& other);
105 
106 			bool				_DoubleArrows() const;
107 			void				_UpdateThumbFrame();
108 			float				_ValueFor(BPoint where) const;
109 			int32				_ButtonFor(BPoint where) const;
110 			BRect				_ButtonRectFor(int32 button) const;
111 			void				_UpdateTargetValue(BPoint where);
112 			void				_UpdateArrowButtons();
113 			void				_DrawDisabledBackground(BRect area,
114 									const rgb_color& light,
115 									const rgb_color& dark,
116 									const rgb_color& fill);
117 			void				_DrawArrowButton(int32 direction,
118 									bool doubleArrows, BRect frame,
119 									const BRect& updateRect,
120 									bool enabled, bool down);
121 
122 			BSize				_MinSize() const;
123 
124 			float				fMin;
125 			float				fMax;
126 			float				fSmallStep;
127 			float				fLargeStep;
128 			float				fValue;
129 			float				fProportion;
130 			BView*				fTarget;
131 			orientation			fOrientation;
132 			char*				fTargetName;
133 
134 			Private*			fPrivateData;
135 
136 			uint32				_reserved[3];
137 };
138 
139 #endif	// _SCROLL_BAR_H
140