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