AbstractSpinner.h revision a0ba79fb
1/*
2 * Copyright 2004 DarkWyrm <darkwyrm@earthlink.net>
3 * Copyright 2013 FeemanLou
4 * Copyright 2014-2015 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 _ABSTRACT_SPINNER_H
17#define _ABSTRACT_SPINNER_H
18
19
20#include <Control.h>
21
22
23typedef enum {
24	SPINNER_BUTTON_HORIZONTAL_ARROWS,
25	SPINNER_BUTTON_VERTICAL_ARROWS,
26	SPINNER_BUTTON_PLUS_MINUS
27} spinner_button_style;
28
29
30class BTextView;
31class SpinnerButton;
32class SpinnerTextView;
33
34
35/*!	BAbstractSpinner provides an input whose value can be nudged up or down
36	by way of two small buttons on the right.
37*/
38class BAbstractSpinner : public BControl {
39public:
40								BAbstractSpinner(BRect frame, const char* name,
41									const char* label, BMessage* message,
42									uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP,
43									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
44								BAbstractSpinner(const char* name, const char* label,
45									BMessage* message,
46									uint32 flags = B_WILL_DRAW | B_NAVIGABLE);
47								BAbstractSpinner(BMessage* data);
48	virtual						~BAbstractSpinner();
49
50	static	BArchivable*		Instantiate(BMessage* data);
51	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
52
53	virtual	status_t			GetSupportedSuites(BMessage* message);
54	virtual	BHandler*			ResolveSpecifier(BMessage* message, int32 index,
55									BMessage* specifier, int32 form,
56									const char* property);
57
58	virtual	void				AttachedToWindow();
59	virtual	void				Draw(BRect updateRect);
60	virtual	void				FrameResized(float width, float height);
61	virtual	void				ValueChanged();
62
63	virtual	void				Decrement() = 0;
64	virtual	void				Increment() = 0;
65	virtual	void				MakeFocus(bool focus = true);
66	virtual	void				ResizeToPreferred();
67	virtual	void				SetFlags(uint32 flags);
68	virtual	void				WindowActivated(bool active);
69
70			alignment			Alignment() const { return fAlignment; };
71	virtual	void				SetAlignment(alignment align);
72
73	spinner_button_style		ButtonStyle() const { return fButtonStyle; };
74	virtual	void				SetButtonStyle(spinner_button_style buttonStyle);
75
76			float				Divider() const { return fDivider; };
77	virtual	void				SetDivider(float position);
78
79	virtual	void				SetEnabled(bool enable);
80
81	virtual	void				SetLabel(const char* label);
82
83	virtual	void				SetValueFromText() = 0;
84
85			bool				IsDecrementEnabled() const;
86	virtual	void				SetDecrementEnabled(bool enable);
87
88			bool				IsIncrementEnabled() const;
89	virtual	void				SetIncrementEnabled(bool enable);
90
91	virtual	BSize				MinSize();
92	virtual	BSize				MaxSize();
93	virtual	BSize				PreferredSize();
94	virtual	BAlignment			LayoutAlignment();
95
96			BLayoutItem*		CreateLabelLayoutItem();
97			BLayoutItem*		CreateTextViewLayoutItem();
98
99			BTextView*			TextView() const;
100
101private:
102	// FBC padding
103	virtual	void				_ReservedAbstractSpinner20();
104	virtual	void				_ReservedAbstractSpinner19();
105	virtual	void				_ReservedAbstractSpinner18();
106	virtual	void				_ReservedAbstractSpinner17();
107	virtual	void				_ReservedAbstractSpinner16();
108	virtual	void				_ReservedAbstractSpinner15();
109	virtual	void				_ReservedAbstractSpinner14();
110	virtual	void				_ReservedAbstractSpinner13();
111	virtual	void				_ReservedAbstractSpinner12();
112	virtual	void				_ReservedAbstractSpinner11();
113	virtual	void				_ReservedAbstractSpinner10();
114	virtual	void				_ReservedAbstractSpinner9();
115	virtual	void				_ReservedAbstractSpinner8();
116	virtual	void				_ReservedAbstractSpinner7();
117	virtual	void				_ReservedAbstractSpinner6();
118	virtual	void				_ReservedAbstractSpinner5();
119	virtual	void				_ReservedAbstractSpinner4();
120	virtual	void				_ReservedAbstractSpinner3();
121	virtual	void				_ReservedAbstractSpinner2();
122	virtual	void				_ReservedAbstractSpinner1();
123
124protected:
125	virtual	status_t			AllArchived(BMessage* into) const;
126	virtual	status_t			AllUnarchived(const BMessage* from);
127
128	virtual	void				LayoutInvalidated(bool descendants);
129	virtual	void				DoLayout();
130
131private:
132	class LabelLayoutItem;
133	class TextViewLayoutItem;
134	struct LayoutData;
135
136	friend class SpinnerButton;
137	friend class SpinnerTextView;
138
139	friend class LabelLayoutItem;
140	friend class TextViewLayoutItem;
141	friend struct LayoutData;
142
143			void				_DrawLabel(BRect updateRect);
144			void				_DrawTextView(BRect updateRect);
145			void				_InitObject();
146			void				_LayoutTextView();
147			void				_UpdateFrame();
148			void				_UpdateTextViewColors(bool enable);
149			void				_ValidateLayoutData();
150
151			BAbstractSpinner&	operator=(const BAbstractSpinner& other);
152
153			alignment			fAlignment;
154	spinner_button_style		fButtonStyle;
155			float				fDivider;
156
157			LayoutData*			fLayoutData;
158
159			SpinnerTextView*	fTextView;
160			SpinnerButton*		fIncrement;
161			SpinnerButton*		fDecrement;
162
163	// FBC padding
164			uint32				_reserved[20];
165};
166
167
168#endif	// _ABSTRACT_SPINNER_H
169