Spinner.h revision a9385e8e
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				MakeFocus(bool focus = true);
58	virtual	void				ResizeToPreferred();
59	virtual	void				SetFlags(uint32 flags);
60	virtual	void				WindowActivated(bool active);
61
62			alignment			Alignment() const { return fAlignment; };
63	virtual	void				SetAlignment(alignment align);
64
65			float				Divider() const { return fDivider; };
66	virtual	void				SetDivider(float position);
67
68			bool				IsEnabled() const { return fIsEnabled; };
69	virtual	void				SetEnabled(bool enable);
70
71			const char*			Label() const { return fLabel; };
72	virtual	void				SetLabel(const char* text);
73
74			uint32				Precision() const { return fPrecision; };
75	virtual	void				SetPrecision(uint32 precision) { fPrecision = precision; };
76
77			double				MaxValue() const { return fMaxValue; }
78	virtual	void				SetMaxValue(double max);
79
80			double				MinValue() const { return fMinValue; }
81	virtual	void				SetMinValue(double min);
82
83			void				Range(double* min, double* max);
84	virtual	void				SetRange(double min, double max);
85
86			double				Step() const { return fStep; }
87	virtual	void				SetStep(double step) { fStep = step; };
88
89			double				Value() const { return fValue; };
90	virtual	void				SetValue(double value);
91
92			bool				IsDecrementEnabled() const;
93	virtual	void				SetDecrementEnabled(bool enable);
94
95			bool				IsIncrementEnabled() const;
96	virtual	void				SetIncrementEnabled(bool enable);
97
98	virtual	BSize				MinSize();
99	virtual	BSize				MaxSize();
100	virtual	BSize				PreferredSize();
101	virtual	BAlignment			LayoutAlignment();
102
103			BLayoutItem*		CreateLabelLayoutItem();
104			BLayoutItem*		CreateTextViewLayoutItem();
105
106			BTextView*			TextView() const;
107
108private:
109	// FBC padding
110	virtual	void				_ReservedSpinner20();
111	virtual	void				_ReservedSpinner19();
112	virtual	void				_ReservedSpinner18();
113	virtual	void				_ReservedSpinner17();
114	virtual	void				_ReservedSpinner16();
115	virtual	void				_ReservedSpinner15();
116	virtual	void				_ReservedSpinner14();
117	virtual	void				_ReservedSpinner13();
118	virtual	void				_ReservedSpinner12();
119	virtual	void				_ReservedSpinner11();
120	virtual	void				_ReservedSpinner10();
121	virtual	void				_ReservedSpinner9();
122	virtual	void				_ReservedSpinner8();
123	virtual	void				_ReservedSpinner7();
124	virtual	void				_ReservedSpinner6();
125	virtual	void				_ReservedSpinner5();
126	virtual	void				_ReservedSpinner4();
127	virtual	void				_ReservedSpinner3();
128	virtual	void				_ReservedSpinner2();
129	virtual	void				_ReservedSpinner1();
130
131protected:
132	virtual	status_t			AllArchived(BMessage* into) const;
133	virtual	status_t			AllUnarchived(const BMessage* from);
134
135	virtual	void				LayoutInvalidated(bool descendants);
136	virtual	void				DoLayout();
137
138private:
139	class LabelLayoutItem;
140	class TextViewLayoutItem;
141	struct LayoutData;
142
143	friend class SpinnerArrow;
144	friend class SpinnerTextView;
145
146	friend class LabelLayoutItem;
147	friend class TextViewLayoutItem;
148	friend struct LayoutData;
149
150			void				_DrawLabel(BRect updateRect);
151			void				_DrawTextView(BRect updateRect);
152			void				_InitObject();
153			void				_LayoutTextView();
154			void				_UpdateFrame();
155			void				_UpdateTextViewColors(bool enable);
156			void				_ValidateLayoutData();
157
158			BSpinner&			operator=(const BSpinner& other);
159
160			alignment			fAlignment;
161			float				fDivider;
162			bool				fIsEnabled;
163			const char*			fLabel;
164			double				fMinValue;
165			double				fMaxValue;
166			double				fStep;
167			double				fValue;
168			uint32				fPrecision;
169
170			LayoutData*			fLayoutData;
171
172			SpinnerTextView*	fTextView;
173			SpinnerArrow*		fIncrement;
174			SpinnerArrow*		fDecrement;
175
176	// FBC padding
177			uint32				_reserved[20];
178};
179
180
181#endif	// SPINNER_H
182