xref: /haiku/headers/os/interface/Control.h (revision d5cd5d63ff0ad395989db6cf4841a64d5b545d1d)
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 virtual				~BControl();
64 
65 					BControl(BMessage *archive);
66 static BArchivable	*Instantiate(BMessage *archive);
67 virtual status_t	Archive(BMessage *archive, bool deep = true) const;
68 
69 virtual void		WindowActivated(bool active);
70 virtual void		AttachedToWindow();
71 virtual void		MessageReceived(BMessage *message);
72 virtual void		MakeFocus(bool focused = true);
73 virtual void		KeyDown(const char *bytes, int32 numBytes);
74 virtual	void		MouseDown(BPoint point);
75 virtual	void		MouseUp(BPoint point);
76 virtual	void		MouseMoved(BPoint point, uint32 transit, const BMessage *message);
77 virtual	void		DetachedFromWindow();
78 
79 virtual void		SetLabel(const char *string);
80 		const char	*Label() const;
81 
82 virtual void		SetValue(int32 value);
83 		int32		Value() const;
84 
85 virtual void		SetEnabled(bool enabled);
86 		bool		IsEnabled() const;
87 
88 virtual	void		GetPreferredSize(float *width, float *height);
89 virtual void		ResizeToPreferred();
90 
91 virtual status_t	Invoke(BMessage *message = NULL);
92 virtual BHandler	*ResolveSpecifier(BMessage *message,
93 									int32 index,
94 									BMessage *specifier,
95 									int32 what,
96 									const char *property);
97 virtual status_t	GetSupportedSuites(BMessage *message);
98 
99 virtual void		AllAttached();
100 virtual void		AllDetached();
101 
102 virtual status_t	Perform(perform_code d, void *arg);
103 
104 protected:
105 
106 		bool		IsFocusChanging() const;
107 		bool		IsTracking() const;
108 		void		SetTracking(bool state);
109 
110 		void		SetValueNoUpdate(int32 value);
111 
112 private:
113 
114 virtual	void		_ReservedControl1();
115 virtual	void		_ReservedControl2();
116 virtual	void		_ReservedControl3();
117 virtual	void		_ReservedControl4();
118 
119 		BControl	&operator=(const BControl &);
120 
121 		void		InitData(BMessage *data = NULL);
122 
123 		char		*fLabel;
124 		int32		fValue;
125 		bool		fEnabled;
126 		bool		fFocusChanging;
127 		bool		fTracking;
128 		bool		fWantsNav;
129 		uint32		_reserved[4];
130 };
131 //------------------------------------------------------------------------------
132 
133 #endif // _CONTROL_H
134 
135 /*
136  * $Log $
137  *
138  * $Id  $
139  *
140  */
141