xref: /haiku/headers/os/interface/ScrollBar.h (revision 58481f0f6ef1a61ba07283f012cafbc2ed874ead)
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,
52 									float* _largeStep) const;
53 			void				SetTarget(BView *target);
54 			void				SetTarget(const char* targetName);
55 			BView*				Target() const;
56 			void				SetOrientation(enum orientation orientation);
57 			orientation			Orientation() const;
58 
59 			// TODO: make this a virtual method, it should be one,
60 			// but it's not important right now. This is supposed
61 			// to be used in case the BScrollBar should draw part of
62 			// the focus indication of the target view for aesthetical
63 			// reasons. BScrollView will forward this method.
64 			status_t			SetBorderHighlighted(bool state);
65 
66 	virtual void				MessageReceived(BMessage* message);
67 	virtual	void				MouseDown(BPoint pt);
68 	virtual	void				MouseUp(BPoint pt);
69 	virtual	void				MouseMoved(BPoint pt, uint32 code,
70 									const BMessage* dragMessage);
71 	virtual	void				DetachedFromWindow();
72 	virtual	void				Draw(BRect updateRect);
73 	virtual	void				FrameMoved(BPoint new_position);
74 	virtual	void				FrameResized(float newWidth, float newHeight);
75 
76 	virtual BHandler*			ResolveSpecifier(BMessage* message,
77 									int32 index, BMessage* specifier,
78 									int32 form, const char* property);
79 
80 	virtual void				ResizeToPreferred();
81 	virtual void				GetPreferredSize(float* _width, float* _height);
82 	virtual void				MakeFocus(bool state = true);
83 	virtual void				AllAttached();
84 	virtual void				AllDetached();
85 	virtual status_t			GetSupportedSuites(BMessage* data);
86 
87 	virtual	BSize				MinSize();
88 	virtual	BSize				MaxSize();
89 	virtual	BSize				PreferredSize();
90 
91 	virtual status_t			Perform(perform_code d, void* arg);
92 
93 #if DISABLES_ON_WINDOW_DEACTIVATION
94 	virtual	void				WindowActivated(bool active);
95 #endif
96 
97 private:
98 	class Private;
99 	friend class Private;
100 
101 	friend status_t control_scrollbar(scroll_bar_info* info,
102 		BScrollBar *bar);
103 		// for use within the preflet
104 
105 	virtual	void				_ReservedScrollBar1();
106 	virtual	void				_ReservedScrollBar2();
107 	virtual	void				_ReservedScrollBar3();
108 	virtual	void				_ReservedScrollBar4();
109 
110 	// disabled
111 			BScrollBar&			operator=(const BScrollBar& other);
112 
113 			bool				_DoubleArrows() const;
114 			void				_UpdateThumbFrame();
115 			float				_ValueFor(BPoint where) const;
116 			int32				_ButtonFor(BPoint where) const;
117 			BRect				_ButtonRectFor(int32 button) const;
118 			void				_UpdateTargetValue(BPoint where);
119 			void				_UpdateArrowButtons();
120 			void				_DrawDisabledBackground(BRect area,
121 									const rgb_color& light,
122 									const rgb_color& dark,
123 									const rgb_color& fill);
124 			void				_DrawArrowButton(int32 direction,
125 									bool doubleArrows, BRect frame,
126 									const BRect& updateRect,
127 									bool enabled, bool down);
128 
129 			BSize				_MinSize() const;
130 
131 			float				fMin;
132 			float				fMax;
133 			float				fSmallStep;
134 			float				fLargeStep;
135 			float				fValue;
136 			float				fProportion;
137 			BView*				fTarget;
138 			orientation			fOrientation;
139 			char*				fTargetName;
140 
141 			Private*			fPrivateData;
142 
143 			uint32				_reserved[3];
144 };
145 
146 #endif	// _SCROLL_BAR_H
147