1/*
2 * Copyright 2001-2016 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _SLIDER_H
6#define _SLIDER_H
7
8
9#include <Control.h>
10
11
12enum hash_mark_location {
13	B_HASH_MARKS_NONE = 0,
14	B_HASH_MARKS_TOP = 1,
15	B_HASH_MARKS_LEFT = 1,
16	B_HASH_MARKS_BOTTOM = 2,
17	B_HASH_MARKS_RIGHT = 2,
18	B_HASH_MARKS_BOTH = 3
19};
20
21enum thumb_style {
22	B_BLOCK_THUMB,
23	B_TRIANGLE_THUMB
24};
25
26
27class BSlider : public BControl {
28public:
29								BSlider(BRect frame, const char* name,
30									const char* label, BMessage* message,
31									int32 minValue, int32 maxValue,
32									thumb_style thumbType = B_BLOCK_THUMB,
33									uint32 resizingMode = B_FOLLOW_LEFT_TOP,
34									uint32 flags = B_NAVIGABLE | B_WILL_DRAW
35										| B_FRAME_EVENTS);
36
37								BSlider(BRect frame, const char* name,
38									const char* label, BMessage* message,
39									int32 minValue, int32 maxValue,
40									orientation posture,
41									thumb_style thumbType = B_BLOCK_THUMB,
42									uint32 resizingMode = B_FOLLOW_LEFT_TOP,
43									uint32 flags = B_NAVIGABLE | B_WILL_DRAW
44										| B_FRAME_EVENTS);
45
46								BSlider(const char* name, const char* label,
47									BMessage* message, int32 minValue,
48									int32 maxValue, orientation posture,
49									thumb_style thumbType = B_BLOCK_THUMB,
50									uint32 flags = B_NAVIGABLE | B_WILL_DRAW
51										| B_FRAME_EVENTS);
52
53								BSlider(BMessage* archive);
54	virtual						~BSlider();
55
56	static 	BArchivable*		Instantiate(BMessage* archive);
57	virtual	status_t 			Archive(BMessage* archive,
58									bool deep = true) const;
59	virtual status_t			Perform(perform_code code, void* data);
60
61	virtual void				WindowActivated(bool state);
62	virtual	void				AttachedToWindow();
63	virtual	void				AllAttached();
64	virtual	void				AllDetached();
65	virtual	void				DetachedFromWindow();
66
67	virtual	void				MessageReceived(BMessage* message);
68	virtual void				FrameMoved(BPoint newPosition);
69	virtual void				FrameResized(float width, float height);
70	virtual void				KeyDown(const char* bytes, int32 numBytes);
71	virtual void				KeyUp(const char* bytes, int32 numBytes);
72	virtual void				MouseDown(BPoint point);
73	virtual void				MouseUp(BPoint point);
74	virtual void				MouseMoved(BPoint point, uint32 transit,
75									const BMessage* dragMessage);
76	virtual	void				Pulse();
77
78	virtual void				SetLabel(const char* label);
79	virtual	void				SetLimitLabels(const char* minLabel,
80									const char* maxLabel);
81			const char*			MinLimitLabel() const;
82			const char*			MaxLimitLabel() const;
83	virtual	void				SetValue(int32 value);
84	virtual int32				ValueForPoint(BPoint point) const;
85	virtual void				SetPosition(float);
86			float				Position() const;
87	virtual void				SetEnabled(bool on);
88			void				GetLimits(int32* minimum, int32* maximum) const;
89
90	virtual	void				Draw(BRect updateRect);
91	virtual void				DrawSlider();
92	virtual void				DrawBar();
93	virtual void				DrawHashMarks();
94	virtual void				DrawThumb();
95	virtual void				DrawFocusMark();
96	virtual	void				DrawText();
97	virtual const char*			UpdateText() const;
98			void				UpdateTextChanged();
99
100	virtual BRect				BarFrame() const;
101	virtual BRect				HashMarksFrame() const;
102	virtual BRect				ThumbFrame() const;
103
104	virtual	void				SetFlags(uint32 flags);
105	virtual	void				SetResizingMode(uint32 mode);
106
107	virtual void				GetPreferredSize(float* _width,
108									float* _height);
109	virtual void				ResizeToPreferred();
110
111	virtual status_t			Invoke(BMessage* message = NULL);
112	virtual BHandler*			ResolveSpecifier(BMessage* message,
113									int32 index, BMessage* specifier,
114									int32 form, const char* property);
115	virtual	status_t			GetSupportedSuites(BMessage* data);
116
117	virtual	void				SetModificationMessage(BMessage* message);
118			BMessage*			ModificationMessage() const;
119
120	virtual void				SetSnoozeAmount(int32 microSeconds);
121			int32				SnoozeAmount() const;
122
123	virtual	void				SetKeyIncrementValue(int32 value);
124			int32				KeyIncrementValue()	const;
125
126	virtual	void				SetHashMarkCount(int32 count);
127			int32				HashMarkCount() const;
128
129	virtual	void				SetHashMarks(hash_mark_location where);
130			hash_mark_location	HashMarks() const;
131
132	virtual	void				SetStyle(thumb_style style);
133			thumb_style			Style() const;
134
135	virtual	void				SetBarColor(rgb_color color);
136			rgb_color			BarColor() const;
137	virtual	void				UseFillColor(bool useFill,
138									const rgb_color* color = NULL);
139			bool				FillColor(rgb_color* color) const;
140
141			BView*				OffscreenView() const;
142
143			orientation			Orientation() const;
144	virtual void				SetOrientation(orientation);
145
146			float				BarThickness() const;
147	virtual void				SetBarThickness(float thickness);
148
149	virtual void				SetFont(const BFont* font,
150									uint32 properties = B_FONT_ALL);
151
152	virtual void				SetLimits(int32 minimum, int32 maximum);
153
154	virtual	float				MaxUpdateTextWidth();
155
156	virtual	BSize				MinSize();
157	virtual	BSize				MaxSize();
158	virtual	BSize				PreferredSize();
159
160	virtual	status_t			SetIcon(const BBitmap* icon, uint32 flags = 0);
161
162protected:
163	virtual	void				LayoutInvalidated(bool descendants);
164
165private:
166			void				_DrawBlockThumb();
167			void				_DrawTriangleThumb();
168
169			BPoint				_Location() const;
170			void				_SetLocationForValue(int32 value);
171
172			float				_MinPosition() const;
173			float				_MaxPosition() const;
174			bool				_ConstrainPoint(BPoint& point,
175									BPoint compare) const;
176
177			BSize				_ValidateMinSize();
178
179			void				_InitBarColor();
180			void				_InitObject();
181
182private:
183	// FBC padding and forbidden methods
184	virtual	void				_ReservedSlider6();
185	virtual	void				_ReservedSlider7();
186	virtual	void				_ReservedSlider8();
187	virtual	void				_ReservedSlider9();
188	virtual	void				_ReservedSlider10();
189	virtual	void				_ReservedSlider11();
190	virtual	void				_ReservedSlider12();
191
192			BSlider&			operator=(const BSlider& other);
193
194private:
195			BMessage*			fModificationMessage;
196			int32				fSnoozeAmount;
197
198			rgb_color 			fBarColor;
199			rgb_color 			fFillColor;
200			bool				fUseFillColor;
201
202			char*				fMinLimitLabel;
203			char*				fMaxLimitLabel;
204			const char*			fUpdateText;
205
206			int32 				fMinValue;
207			int32 				fMaxValue;
208			int32 				fKeyIncrementValue;
209
210			int32 				fHashMarkCount;
211			hash_mark_location 	fHashMarks;
212
213			BBitmap*			fOffScreenBits;
214			BView*				fOffScreenView;
215
216			thumb_style			fStyle;
217
218			BPoint 				fLocation;
219			BPoint				fInitialLocation;
220
221			orientation			fOrientation;
222			float				fBarThickness;
223
224			BSize				fMinSize;
225
226			float				fMaxUpdateTextWidth;
227
228			uint32				_reserved[4];
229};
230
231
232#endif	// _SLIDER_H
233