xref: /haiku/headers/os/interface/Control.h (revision cda5b8808fd0262f0fac472f6cfa809f846a83cf)
1 //------------------------------------------------------------------------------
2 //	Copyright (c) 2001-2002, OpenBeOS
3 //
4 //	Permission is hereby granted, free of charge, to any person obtaining a
5 //	copy of this software and associated documentation files (the "Software"),
6 //	to deal in the Software without restriction, including without limitation
7 //	the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 //	and/or sell copies of the Software, and to permit persons to whom the
9 //	Software is furnished to do so, subject to the following conditions:
10 //
11 //	The above copyright notice and this permission notice shall be included in
12 //	all copies or substantial portions of the Software.
13 //
14 //	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 //	IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 //	FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 //	AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 //	LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 //	FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 //	DEALINGS IN THE SOFTWARE.
21 //
22 //	File Name:		Control.h
23 //	Author:			Marc Flerackers (mflerackers@androme.be)
24 //	Description:	BControl is the base class for user-event handling objects.
25 //------------------------------------------------------------------------------
26 
27 #ifndef _CONTROL_H
28 #define _CONTROL_H
29 
30 // Standard Includes -----------------------------------------------------------
31 
32 // System Includes -------------------------------------------------------------
33 #include <BeBuild.h>
34 #include <Invoker.h>
35 #include <Message.h>	/* For convenience */
36 #include <View.h>
37 
38 // Project Includes ------------------------------------------------------------
39 
40 // Local Includes --------------------------------------------------------------
41 
42 // Local Defines ---------------------------------------------------------------
43 enum {
44 	B_CONTROL_OFF = 0,
45 	B_CONTROL_ON = 1
46 };
47 
48 // Globals ---------------------------------------------------------------------
49 
50 
51 class BWindow;
52 
53 // BControl class --------------------------------------------------------------
54 class BControl : public BView, public BInvoker {
55 
56 public:
57 					BControl(BRect frame,
58 						const char *name,
59 						const char *label,
60 						BMessage *message,
61 						uint32 resizingMode,
62 						uint32 flags);
63 					BControl(const char *name,
64 						const char *label,
65 						BMessage *message,
66 						uint32 flags);
67 virtual				~BControl();
68 
69 					BControl(BMessage *archive);
70 static BArchivable	*Instantiate(BMessage *archive);
71 virtual status_t	Archive(BMessage *archive, bool deep = true) const;
72 
73 virtual void		WindowActivated(bool active);
74 virtual void		AttachedToWindow();
75 virtual void		MessageReceived(BMessage *message);
76 virtual void		MakeFocus(bool focused = true);
77 virtual void		KeyDown(const char *bytes, int32 numBytes);
78 virtual	void		MouseDown(BPoint point);
79 virtual	void		MouseUp(BPoint point);
80 virtual	void		MouseMoved(BPoint point, uint32 transit, const BMessage *message);
81 virtual	void		DetachedFromWindow();
82 
83 virtual void		SetLabel(const char *string);
84 		const char	*Label() const;
85 
86 virtual void		SetValue(int32 value);
87 		int32		Value() const;
88 
89 virtual void		SetEnabled(bool enabled);
90 		bool		IsEnabled() const;
91 
92 virtual	void		GetPreferredSize(float *width, float *height);
93 virtual void		ResizeToPreferred();
94 
95 virtual status_t	Invoke(BMessage *message = NULL);
96 virtual BHandler	*ResolveSpecifier(BMessage *message,
97 									int32 index,
98 									BMessage *specifier,
99 									int32 what,
100 									const char *property);
101 virtual status_t	GetSupportedSuites(BMessage *message);
102 
103 virtual void		AllAttached();
104 virtual void		AllDetached();
105 
106 virtual status_t	Perform(perform_code d, void *arg);
107 
108 protected:
109 
110 		bool		IsFocusChanging() const;
111 		bool		IsTracking() const;
112 		void		SetTracking(bool state);
113 
114 		void		SetValueNoUpdate(int32 value);
115 
116 private:
117 
118 virtual	void		_ReservedControl1();
119 virtual	void		_ReservedControl2();
120 virtual	void		_ReservedControl3();
121 virtual	void		_ReservedControl4();
122 
123 		BControl	&operator=(const BControl &);
124 
125 		void		InitData(BMessage *data = NULL);
126 
127 		char		*fLabel;
128 		int32		fValue;
129 		bool		fEnabled;
130 		bool		fFocusChanging;
131 		bool		fTracking;
132 		bool		fWantsNav;
133 		uint32		_reserved[4];
134 };
135 //------------------------------------------------------------------------------
136 
137 #endif // _CONTROL_H
138