xref: /haiku/headers/os/interface/ScrollBar.h (revision 1d9d47fc72028bb71b5f232a877231e59cfe2438)
1 /*
2  * Copyright (c) 2001-2006, Haiku, Inc.
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, BView *target,
32 								float min, float max, orientation direction);
33 							BScrollBar(BMessage *data);
34 		virtual				~BScrollBar();
35 		static	BArchivable	*Instantiate(BMessage *data);
36 		virtual	status_t	Archive(BMessage *data, bool deep = true) const;
37 
38 		virtual	void		AttachedToWindow();
39 				void		SetValue(float value);
40 				float		Value() const;
41 				void		SetProportion(float);
42 				float		Proportion() const;
43 		virtual	void		ValueChanged(float newValue);
44 
45 				void		SetRange(float min, float max);
46 				void		GetRange(float *min, float *max) const;
47 				void		SetSteps(float smallStep, float largeStep);
48 				void		GetSteps(float *smallStep, float *largeStep) const;
49 				void		SetTarget(BView *target);
50 				void		SetTarget(const char *targetName);
51 				BView		*Target() const;
52 				orientation	Orientation() const;
53 
54 		virtual void		MessageReceived(BMessage *msg);
55 		virtual	void		MouseDown(BPoint pt);
56 		virtual	void		MouseUp(BPoint pt);
57 		virtual	void		MouseMoved(BPoint pt, uint32 code, const BMessage *msg);
58 		virtual	void		DetachedFromWindow();
59 		virtual	void		Draw(BRect updateRect);
60 		virtual	void		FrameMoved(BPoint new_position);
61 		virtual	void		FrameResized(float new_width, float new_height);
62 
63 		virtual BHandler	*ResolveSpecifier(BMessage *msg, int32 index,
64 								BMessage *specifier, int32 form,
65 								const char *property);
66 
67 		virtual void		ResizeToPreferred();
68 		virtual void		GetPreferredSize(float *width, float *height);
69 		virtual void		MakeFocus(bool state = true);
70 		virtual void		AllAttached();
71 		virtual void		AllDetached();
72 		virtual status_t	GetSupportedSuites(BMessage *data);
73 
74 		virtual status_t	Perform(perform_code d, void *arg);
75 
76 #if DISABLES_ON_WINDOW_DEACTIVATION
77 		virtual	void		WindowActivated(bool active);
78 #endif
79 
80 	private:
81 		class Private;
82 		friend class Private;
83 
84 		friend status_t control_scrollbar(scroll_bar_info *info, BScrollBar *bar);
85 			// for use within the preflet
86 
87 		virtual	void		_ReservedScrollBar1();
88 		virtual	void		_ReservedScrollBar2();
89 		virtual	void		_ReservedScrollBar3();
90 		virtual	void		_ReservedScrollBar4();
91 
92 		BScrollBar	&operator=(const BScrollBar &);
93 
94 				bool		_DoubleArrows() const;
95 				void		_UpdateThumbFrame();
96 				float		_ValueFor(BPoint where) const;
97 				int32		_ButtonFor(BPoint where) const;
98 				BRect		_ButtonRectFor(int32 button) const;
99 				void		_UpdateTargetValue(BPoint where);
100 				void		_UpdateArrowButtons();
101 				void		_DrawDisabledBackground(BRect area,
102 								const rgb_color& light, const rgb_color& dark,
103 								const rgb_color& fill);
104 				void		_DrawArrowButton(int32 direction,
105 								bool doubleArrows, BRect frame,
106 								const BRect& updateRect,
107 								bool enabled, bool down);
108 
109 				float		fMin;
110 				float		fMax;
111 				float		fSmallStep;
112 				float		fLargeStep;
113 				float		fValue;
114 				float		fProportion;
115 				BView*		fTarget;
116 				orientation	fOrientation;
117 				char*		fTargetName;
118 
119 				Private*	fPrivateData;
120 
121 				uint32		_reserved[3];
122 };
123 
124 #endif	// _SCROLL_BAR_H
125