xref: /haiku/headers/os/interface/Slider.h (revision 4b3b81da9e459443d75329cfd08bc9a57ad02653)
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(BMessage *data);
49 		virtual	~BSlider();
50 
51 		static 	BArchivable	*Instantiate(BMessage *data);
52 		virtual	status_t 	Archive(BMessage *data, bool deep = true) const;
53 		virtual status_t	Perform(perform_code d, void *arg);
54 
55 		virtual void		WindowActivated(bool state);
56 		virtual	void		AttachedToWindow();
57 		virtual	void		AllAttached();
58 		virtual	void		AllDetached();
59 		virtual	void		DetachedFromWindow();
60 
61 		virtual	void		MessageReceived(BMessage *msg);
62 		virtual void		FrameMoved(BPoint new_position);
63 		virtual void		FrameResized(float w,float h);
64 		virtual void		KeyDown(const char * bytes, int32 n);
65 		virtual void		MouseDown(BPoint);
66 		virtual void		MouseUp(BPoint pt);
67 		virtual void		MouseMoved(BPoint pt, uint32 c, const BMessage *m);
68 		virtual	void		Pulse();
69 
70 		virtual void		SetLabel(const char *label);
71 		virtual	void		SetLimitLabels(const char *minLabel,
72 								const char *maxLabel);
73 		const char*			MinLimitLabel() const;
74 		const char*			MaxLimitLabel() const;
75 		virtual	void		SetValue(int32);
76 		virtual int32		ValueForPoint(BPoint) const;
77 		virtual void		SetPosition(float);
78 				float		Position() const;
79 		virtual void		SetEnabled(bool on);
80 				void		GetLimits(int32 * minimum, int32 * maximum);
81 
82 		virtual	void		Draw(BRect);
83 		virtual void		DrawSlider();
84 		virtual void		DrawBar();
85 		virtual void		DrawHashMarks();
86 		virtual void		DrawThumb();
87 		virtual void		DrawFocusMark();
88 		virtual	void		DrawText();
89 		virtual char*		UpdateText() const;
90 
91 		virtual BRect		BarFrame() const;
92 		virtual BRect		HashMarksFrame() const;
93 		virtual BRect		ThumbFrame() const;
94 
95 		virtual	void		SetFlags(uint32 flags);
96 		virtual	void		SetResizingMode(uint32 mode);
97 
98 		virtual void		GetPreferredSize( float *width, float *height);
99 		virtual void		ResizeToPreferred();
100 
101 		virtual status_t	Invoke(BMessage *msg=NULL);
102 		virtual BHandler*	ResolveSpecifier(BMessage *msg, int32 index,
103 								BMessage *specifier, int32 form,
104 								const char *property);
105 		virtual	status_t	GetSupportedSuites(BMessage* data);
106 
107 		virtual	void		SetModificationMessage(BMessage *message);
108 				BMessage*	ModificationMessage() const;
109 
110 		virtual void		SetSnoozeAmount(int32);
111 				int32		SnoozeAmount() const;
112 
113 		virtual	void		SetKeyIncrementValue(int32 value);
114 				int32		KeyIncrementValue()	const;
115 
116 		virtual	void		SetHashMarkCount(int32 count);
117 				int32		HashMarkCount() const;
118 
119 		virtual	void		SetHashMarks(hash_mark_location where);
120 		hash_mark_location	HashMarks() const;
121 
122 		virtual	void		SetStyle(thumb_style s);
123 				thumb_style	Style() const;
124 
125 		virtual	void		SetBarColor(rgb_color);
126 				rgb_color	BarColor() const;
127 		virtual	void		UseFillColor(bool, const rgb_color* c=NULL);
128 				bool		FillColor(rgb_color*) const;
129 
130 				BView*		OffscreenView() const;
131 
132 				orientation	Orientation() const;
133 		virtual void		SetOrientation(orientation);
134 
135 				float		BarThickness() const;
136 		virtual void		SetBarThickness(float thickness);
137 
138 		virtual void		SetFont(const BFont *font, uint32 properties = B_FONT_ALL);
139 
140 		virtual void		SetLimits(int32 minimum, int32 maximum);
141 
142 	private:
143 				void		_DrawBlockThumb();
144 				void		_DrawTriangleThumb();
145 
146 				BPoint		_Location() const;
147 				void		_SetLocation(BPoint p);
148 
149 				float		_MinPosition() const;
150 				float		_MaxPosition() const;
151 				bool		_ConstrainPoint(BPoint& point, BPoint compare) const;
152 
153 		virtual	void		_ReservedSlider5();
154 		virtual	void		_ReservedSlider6();
155 		virtual	void		_ReservedSlider7();
156 		virtual	void		_ReservedSlider8();
157 		virtual	void		_ReservedSlider9();
158 		virtual	void		_ReservedSlider10();
159 		virtual	void		_ReservedSlider11();
160 		virtual	void		_ReservedSlider12();
161 
162 				BSlider&	operator=(const BSlider &);
163 
164 				void		_InitObject();
165 
166 	private:
167 		BMessage*			fModificationMessage;
168 		int32				fSnoozeAmount;
169 
170 		rgb_color 			fBarColor;
171 		rgb_color 			fFillColor;
172 		bool				fUseFillColor;
173 
174 		char*				fMinLimitLabel;
175 		char*				fMaxLimitLabel;
176 		char*				fUpdateText;
177 
178 		int32 				fMinValue;
179 		int32 				fMaxValue;
180 		int32 				fKeyIncrementValue;
181 
182 		int32 				fHashMarkCount;
183 		hash_mark_location 	fHashMarks;
184 
185 #if USE_OFF_SCREEN_VIEW
186 		BBitmap*			fOffScreenBits;
187 		BView*				fOffScreenView;
188 #endif
189 
190 		thumb_style			fStyle;
191 
192 		BPoint 				fLocation;
193 		BPoint				fInitialLocation;
194 
195 		orientation			fOrientation;
196 		float				fBarThickness;
197 
198 #if USE_OFF_SCREEN_VIEW
199 		uint32				_reserved[7];
200 #else
201 		uint32				_reserved[9];
202 #endif
203 };
204 
205 #endif	// _SLIDER_H
206