xref: /haiku/headers/os/interface/ScrollBar.h (revision 746cac055adc6ac3308c7bc2d29040fb95689cc9)
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, float *largeStep) const;
52 				void		SetTarget(BView *target);
53 				void		SetTarget(const char *targetName);
54 				BView		*Target() const;
55 				orientation	Orientation() const;
56 
57 		virtual void		MessageReceived(BMessage *msg);
58 		virtual	void		MouseDown(BPoint pt);
59 		virtual	void		MouseUp(BPoint pt);
60 		virtual	void		MouseMoved(BPoint pt, uint32 code, const BMessage *msg);
61 		virtual	void		DetachedFromWindow();
62 		virtual	void		Draw(BRect updateRect);
63 		virtual	void		FrameMoved(BPoint new_position);
64 		virtual	void		FrameResized(float new_width, float new_height);
65 
66 		virtual BHandler	*ResolveSpecifier(BMessage *msg, int32 index,
67 								BMessage *specifier, int32 form,
68 								const char *property);
69 
70 		virtual void		ResizeToPreferred();
71 		virtual void		GetPreferredSize(float *width, float *height);
72 		virtual void		MakeFocus(bool state = true);
73 		virtual void		AllAttached();
74 		virtual void		AllDetached();
75 		virtual status_t	GetSupportedSuites(BMessage *data);
76 
77 		virtual	BSize		MinSize();
78 		virtual	BSize		MaxSize();
79 		virtual	BSize		PreferredSize();
80 
81 		virtual status_t	Perform(perform_code d, void *arg);
82 
83 #if DISABLES_ON_WINDOW_DEACTIVATION
84 		virtual	void		WindowActivated(bool active);
85 #endif
86 
87 	private:
88 		class Private;
89 		friend class Private;
90 
91 		friend status_t control_scrollbar(scroll_bar_info *info, BScrollBar *bar);
92 			// for use within the preflet
93 
94 		virtual	void		_ReservedScrollBar1();
95 		virtual	void		_ReservedScrollBar2();
96 		virtual	void		_ReservedScrollBar3();
97 		virtual	void		_ReservedScrollBar4();
98 
99 		BScrollBar	&operator=(const BScrollBar &);
100 
101 				bool		_DoubleArrows() const;
102 				void		_UpdateThumbFrame();
103 				float		_ValueFor(BPoint where) const;
104 				int32		_ButtonFor(BPoint where) const;
105 				BRect		_ButtonRectFor(int32 button) const;
106 				void		_UpdateTargetValue(BPoint where);
107 				void		_UpdateArrowButtons();
108 				void		_DrawDisabledBackground(BRect area,
109 								const rgb_color& light, const rgb_color& dark,
110 								const rgb_color& fill);
111 				void		_DrawArrowButton(int32 direction,
112 								bool doubleArrows, BRect frame,
113 								const BRect& updateRect,
114 								bool enabled, bool down);
115 
116 				BSize		_MinSize() const;
117 
118 				float		fMin;
119 				float		fMax;
120 				float		fSmallStep;
121 				float		fLargeStep;
122 				float		fValue;
123 				float		fProportion;
124 				BView*		fTarget;
125 				orientation	fOrientation;
126 				char*		fTargetName;
127 
128 				Private*	fPrivateData;
129 
130 				uint32		_reserved[3];
131 };
132 
133 #endif	// _SCROLL_BAR_H
134