Spinner.h revision d1229383
1/*
2 * Copyright 2004 DarkWyrm <darkwyrm@earthlink.net>
3 * Copyright 2013 FeemanLou
4 * Copyright 2014 Haiku, Inc. All rights reserved.
5 *
6 * Distributed under the terms of the MIT license.
7 *
8 * Originally written by DarkWyrm <darkwyrm@earthlink.net>
9 * Updated by FreemanLou as part of Google GCI 2013
10 *
11 * Authors:
12 *		DarkWyrm, darkwyrm@earthlink.net
13 *		FeemanLou
14 *		John Scipione, jscipione@gmail.com
15 */
16#ifndef SPINNER_H
17#define SPINNER_H
18
19
20#include <Invoker.h>
21#include <View.h>
22
23
24class BTextView;
25class SpinnerArrow;
26class SpinnerTextView;
27
28
29/*!	BSpinner provides a numeric input whose value can be nudged up or down
30	by way of two small buttons on the right.
31*/
32class BSpinner : public BView, public BInvoker {
33public:
34								BSpinner(BRect frame, const char* name,
35									const char* label, BMessage* message,
36									uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
37									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
38								BSpinner(const char* name, const char* label,
39									BMessage* message,
40									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
41								BSpinner(BMessage* data);
42	virtual						~BSpinner();
43
44	static	BArchivable*		Instantiate(BMessage* data);
45	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
46
47	virtual	status_t			GetSupportedSuites(BMessage* message);
48	virtual	BHandler*			ResolveSpecifier(BMessage* message, int32 index,
49									BMessage* specifier, int32 form,
50									const char* property);
51
52	virtual	void				AttachedToWindow();
53	virtual	void				Draw(BRect updateRect);
54	virtual	void				FrameResized(float width, float height);
55	virtual	void				ValueChanged();
56
57	virtual	void				Decrement();
58	virtual	void				Increment();
59	virtual	void				MakeFocus(bool focus = true);
60	virtual	void				ResizeToPreferred();
61	virtual	void				SetFlags(uint32 flags);
62	virtual	void				SetValueFromText();
63	virtual	void				WindowActivated(bool active);
64
65			alignment			Alignment() const { return fAlignment; };
66	virtual	void				SetAlignment(alignment align);
67
68			float				Divider() const { return fDivider; };
69	virtual	void				SetDivider(float position);
70
71			bool				IsEnabled() const { return fIsEnabled; };
72	virtual	void				SetEnabled(bool enable);
73
74			const char*			Label() const { return fLabel; };
75	virtual	void				SetLabel(const char* text);
76
77			uint32				Precision() const { return fPrecision; };
78	virtual	void				SetPrecision(uint32 precision) { fPrecision = precision; };
79
80			double				MaxValue() const { return fMaxValue; }
81	virtual	void				SetMaxValue(double max);
82
83			double				MinValue() const { return fMinValue; }
84	virtual	void				SetMinValue(double min);
85
86			void				Range(double* min, double* max);
87	virtual	void				SetRange(double min, double max);
88
89			double				Step() const { return fStep; }
90	virtual	void				SetStep(double step) { fStep = step; };
91
92			double				Value() const { return fValue; };
93	virtual	void				SetValue(double value);
94
95			bool				IsDecrementEnabled() const;
96	virtual	void				SetDecrementEnabled(bool enable);
97
98			bool				IsIncrementEnabled() const;
99	virtual	void				SetIncrementEnabled(bool enable);
100
101	virtual	BSize				MinSize();
102	virtual	BSize				MaxSize();
103	virtual	BSize				PreferredSize();
104	virtual	BAlignment			LayoutAlignment();
105
106			BLayoutItem*		CreateLabelLayoutItem();
107			BLayoutItem*		CreateTextViewLayoutItem();
108
109			BTextView*			TextView() const;
110
111private:
112	// FBC padding
113	virtual	void				_ReservedSpinner20();
114	virtual	void				_ReservedSpinner19();
115	virtual	void				_ReservedSpinner18();
116	virtual	void				_ReservedSpinner17();
117	virtual	void				_ReservedSpinner16();
118	virtual	void				_ReservedSpinner15();
119	virtual	void				_ReservedSpinner14();
120	virtual	void				_ReservedSpinner13();
121	virtual	void				_ReservedSpinner12();
122	virtual	void				_ReservedSpinner11();
123	virtual	void				_ReservedSpinner10();
124	virtual	void				_ReservedSpinner9();
125	virtual	void				_ReservedSpinner8();
126	virtual	void				_ReservedSpinner7();
127	virtual	void				_ReservedSpinner6();
128	virtual	void				_ReservedSpinner5();
129	virtual	void				_ReservedSpinner4();
130	virtual	void				_ReservedSpinner3();
131	virtual	void				_ReservedSpinner2();
132	virtual	void				_ReservedSpinner1();
133
134protected:
135	virtual	status_t			AllArchived(BMessage* into) const;
136	virtual	status_t			AllUnarchived(const BMessage* from);
137
138	virtual	void				LayoutInvalidated(bool descendants);
139	virtual	void				DoLayout();
140
141private:
142	class LabelLayoutItem;
143	class TextViewLayoutItem;
144	struct LayoutData;
145
146	friend class SpinnerArrow;
147	friend class SpinnerTextView;
148
149	friend class LabelLayoutItem;
150	friend class TextViewLayoutItem;
151	friend struct LayoutData;
152
153			void				_DrawLabel(BRect updateRect);
154			void				_DrawTextView(BRect updateRect);
155			void				_InitObject();
156			void				_LayoutTextView();
157			void				_UpdateFrame();
158			void				_UpdateTextViewColors(bool enable);
159			void				_ValidateLayoutData();
160
161			BSpinner&			operator=(const BSpinner& other);
162
163			alignment			fAlignment;
164			float				fDivider;
165			bool				fIsEnabled;
166			const char*			fLabel;
167			double				fMinValue;
168			double				fMaxValue;
169			double				fStep;
170			double				fValue;
171			uint32				fPrecision;
172
173			LayoutData*			fLayoutData;
174
175			SpinnerTextView*	fTextView;
176			SpinnerArrow*		fIncrement;
177			SpinnerArrow*		fDecrement;
178
179	// FBC padding
180			uint32				_reserved[20];
181};
182
183
184#endif	// SPINNER_H
185