xref: /haiku/headers/private/interface/AbstractSpinner.h (revision fce4895d1884da5ae6fb299d23c735c598e690b1)
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 
23 typedef enum {
24 	SPINNER_BUTTON_HORIZONTAL_ARROWS,
25 	SPINNER_BUTTON_VERTICAL_ARROWS,
26 	SPINNER_BUTTON_PLUS_MINUS
27 } spinner_button_style;
28 
29 
30 class BTextView;
31 class SpinnerButton;
32 class 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 */
38 class BAbstractSpinner : public BControl {
39 public:
40 								BAbstractSpinner(BRect frame, const char* name,
41 									const char* label, BMessage* message,
42 									uint32 resizingMode = B_FOLLOW_LEFT_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 	virtual void				MessageReceived(BMessage* message);
63 
64 	virtual	void				Decrement() = 0;
65 	virtual	void				Increment() = 0;
66 	virtual	void				MakeFocus(bool focus = true);
67 	virtual	void				ResizeToPreferred();
68 	virtual	void				SetFlags(uint32 flags);
69 	virtual	void				WindowActivated(bool active);
70 
71 			alignment			Alignment() const { return fAlignment; };
72 	virtual	void				SetAlignment(alignment align);
73 
74 	spinner_button_style		ButtonStyle() const { return fButtonStyle; };
75 	virtual	void				SetButtonStyle(spinner_button_style buttonStyle);
76 
77 			float				Divider() const { return fDivider; };
78 	virtual	void				SetDivider(float position);
79 
80 	virtual	void				SetEnabled(bool enable);
81 
82 	virtual	void				SetLabel(const char* label);
83 
84 	virtual	void				SetValueFromText() = 0;
85 
86 			bool				IsDecrementEnabled() const;
87 	virtual	void				SetDecrementEnabled(bool enable);
88 
89 			bool				IsIncrementEnabled() const;
90 	virtual	void				SetIncrementEnabled(bool enable);
91 
92 	virtual	BSize				MinSize();
93 	virtual	BSize				MaxSize();
94 	virtual	BSize				PreferredSize();
95 	virtual	BAlignment			LayoutAlignment();
96 
97 			BLayoutItem*		CreateLabelLayoutItem();
98 			BLayoutItem*		CreateTextViewLayoutItem();
99 
100 			BTextView*			TextView() const;
101 
102 private:
103 	// FBC padding
104 	virtual	void				_ReservedAbstractSpinner20();
105 	virtual	void				_ReservedAbstractSpinner19();
106 	virtual	void				_ReservedAbstractSpinner18();
107 	virtual	void				_ReservedAbstractSpinner17();
108 	virtual	void				_ReservedAbstractSpinner16();
109 	virtual	void				_ReservedAbstractSpinner15();
110 	virtual	void				_ReservedAbstractSpinner14();
111 	virtual	void				_ReservedAbstractSpinner13();
112 	virtual	void				_ReservedAbstractSpinner12();
113 	virtual	void				_ReservedAbstractSpinner11();
114 	virtual	void				_ReservedAbstractSpinner10();
115 	virtual	void				_ReservedAbstractSpinner9();
116 	virtual	void				_ReservedAbstractSpinner8();
117 	virtual	void				_ReservedAbstractSpinner7();
118 	virtual	void				_ReservedAbstractSpinner6();
119 	virtual	void				_ReservedAbstractSpinner5();
120 	virtual	void				_ReservedAbstractSpinner4();
121 	virtual	void				_ReservedAbstractSpinner3();
122 	virtual	void				_ReservedAbstractSpinner2();
123 	virtual	void				_ReservedAbstractSpinner1();
124 
125 protected:
126 	virtual	status_t			AllArchived(BMessage* into) const;
127 	virtual	status_t			AllUnarchived(const BMessage* from);
128 
129 	virtual	void				LayoutInvalidated(bool descendants);
130 	virtual	void				DoLayout();
131 
132 private:
133 	class LabelLayoutItem;
134 	class TextViewLayoutItem;
135 	struct LayoutData;
136 
137 	friend class SpinnerButton;
138 	friend class SpinnerTextView;
139 
140 	friend class LabelLayoutItem;
141 	friend class TextViewLayoutItem;
142 	friend struct LayoutData;
143 
144 			void				_DrawLabel(BRect updateRect);
145 			void				_DrawTextView(BRect updateRect);
146 			void				_InitObject();
147 			void				_LayoutTextView();
148 			void				_UpdateFrame();
149 			void				_UpdateTextViewColors(bool enable);
150 			void				_ValidateLayoutData();
151 
152 			BAbstractSpinner&	operator=(const BAbstractSpinner& other);
153 
154 			alignment			fAlignment;
155 	spinner_button_style		fButtonStyle;
156 			float				fDivider;
157 
158 			LayoutData*			fLayoutData;
159 
160 			SpinnerTextView*	fTextView;
161 			SpinnerButton*		fIncrement;
162 			SpinnerButton*		fDecrement;
163 
164 	// FBC padding
165 			uint32				_reserved[20];
166 };
167 
168 
169 #endif	// _ABSTRACT_SPINNER_H
170