xref: /haiku/headers/os/interface/Control.h (revision d06cbe081b7ea043aea2012359744091de6d604d)
1 /*
2  * Copyright 2001-2013, Haiku, Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef _CONTROL_H
6 #define _CONTROL_H
7 
8 #include <Invoker.h>
9 #include <Message.h>	// For convenience
10 #include <View.h>
11 
12 
13 enum {
14 	B_CONTROL_OFF = 0,
15 	B_CONTROL_ON = 1,
16 	B_CONTROL_PARTIALLY_ON = 2
17 };
18 
19 class BBitmap;
20 class BWindow;
21 
22 namespace BPrivate {
23 	class BIcon;
24 };
25 
26 
27 class BControl : public BView, public BInvoker {
28 public:
29 								BControl(BRect frame, const char* name,
30 									const char* label, BMessage* message,
31 									uint32 resizingMode, uint32 flags);
32 								BControl(const char* name, const char* label,
33 									BMessage* message, uint32 flags);
34 	virtual						~BControl();
35 
36 								BControl(BMessage* data);
37 	static	BArchivable*		Instantiate(BMessage* data);
38 	virtual	status_t			Archive(BMessage* data, bool deep = true) const;
39 
40 	virtual	void				WindowActivated(bool active);
41 
42 	virtual	void				AttachedToWindow();
43 	virtual	void				DetachedFromWindow();
44 	virtual	void				AllAttached();
45 	virtual	void				AllDetached();
46 
47 	virtual	void				MessageReceived(BMessage* message);
48 	virtual	void				MakeFocus(bool focus = true);
49 
50 	virtual	void				KeyDown(const char* bytes, int32 numBytes);
51 	virtual	void				MouseDown(BPoint where);
52 	virtual	void				MouseUp(BPoint where);
53 	virtual	void				MouseMoved(BPoint where, uint32 code,
54 									const BMessage* dragMessage);
55 
56 	virtual	void				SetLabel(const char* string);
57 			const char*			Label() const;
58 
59 	virtual	void				SetValue(int32 value);
60 			int32				Value() const;
61 
62 	virtual	void				SetEnabled(bool enabled);
63 			bool				IsEnabled() const;
64 
65 	virtual	void				GetPreferredSize(float* _width,
66 									float* _height);
67 	virtual	void				ResizeToPreferred();
68 
69 	virtual	status_t			Invoke(BMessage* message = NULL);
70 	virtual	BHandler*			ResolveSpecifier(BMessage* message,
71 									int32 index, BMessage* specifier,
72 									int32 what, const char* property);
73 	virtual	status_t			GetSupportedSuites(BMessage* message);
74 
75 	virtual	status_t			Perform(perform_code d, void* arg);
76 
77 	virtual	status_t			SetIcon(const BBitmap* bitmap,
78 									uint32 flags = 0);
79 			status_t			SetIconBitmap(const BBitmap* bitmap,
80 									uint32 which, uint32 flags = 0);
81 			const BBitmap*		IconBitmap(uint32 which) const;
82 
83 protected:
84 			bool				IsFocusChanging() const;
85 			bool				IsTracking() const;
86 			void				SetTracking(bool state);
87 
88 			void				SetValueNoUpdate(int32 value);
89 
90 private:
91 			struct IconData;
92 
93 private:
94 	virtual	void				_ReservedControl2();
95 	virtual	void				_ReservedControl3();
96 	virtual	void				_ReservedControl4();
97 
98 			BControl&			operator=(const BControl&);
99 
100 			void				InitData(BMessage* data = NULL);
101 
102 private:
103 			char*				fLabel;
104 			int32				fValue;
105 			bool				fEnabled;
106 			bool				fFocusChanging;
107 			bool				fTracking;
108 			bool				fWantsNav;
109 			BPrivate::BIcon*	fIcon;
110 
111 #ifdef B_HAIKU_64_BIT
112 			uint32				_reserved[2];
113 #else
114 			uint32				_reserved[3];
115 #endif
116 };
117 
118 #endif // _CONTROL_H
119