xref: /haiku/docs/user/interface/Control.dox (revision 323b65468e5836bb27a5e373b14027d902349437)
1/*
2 * Copyright 2011, Haiku inc.
3 * Distributed under the terms of the MIT License.
4 *
5 * Documentation by:
6 *		John Scipione, jscipione@gmail.com
7 * Corresponds to:
8 *		/trunk/headers/os/interface/Control.h	 rev 42794
9 *		/trunk/src/kits/interface/Control.cpp	 rev 42794
10 */
11
12/*!
13	\file Control.h
14	\brief BControl class definition and support enums.
15*/
16
17
18/*!
19	\var B_CONTROL_ON
20	Control on
21*/
22
23
24/*!
25	\var B_CONTROL_OFF
26	Control off
27*/
28
29
30/*!
31	\class BControl
32	\ingroup interface
33	\ingroup libbe
34	\brief BControl is the base class for user-event handling objects.
35
36	Simple controls such as BCheckBox and BButton deviate only a bit from
37	BControl, whereas more complicated controls such as BColorControl and
38	BSlider re-implement much more functionality. Whether you are building
39	a simple control or something more complicated you should inherit from
40	BControl as it provides a common set of methods for intercepting
41	received messages from mouse and keyboard events.
42
43	Controls have state which they keep in their value. The value of a
44	control, stored as an int32, is read and set by the virtual Value() and
45	SetValue() methods. BControl defines \c B_CONTROL_ON and \c B_CONTROL_OFF
46	values that you can use as a convenience if your control has a simple
47	on/off state. If your BControl derived class stores a larger set of
48	states then you should define your own integer values instead.
49*/
50
51
52/*!
53	\fn BControl::BControl(BRect frame, const char *name, const char *label,
54						   BMessage *message, uint32 resizingMode,
55						   uint32 flags)
56	\brief Construct a control in the \a frame with a \a name, \a label,
57		model \a message, \a resizingMode, and creation \a flags.
58
59	The initial value of the control is set to 0 (\c B_CONTROL_OFF).
60	The \a label and the \a message parameters can be set to \c NULL.
61
62	\param frame The \a frame to draw the control in.
63	\param name The \a name of the control.
64	\param label The \a label displayed along with the control.
65	\param message The \a message to send when the control is activated.
66	\param resizingMode Defines the behavior of the control as the parent
67		view resizes.
68	\param flags Behavior \a flags for the control. See BView for details.
69*/
70
71
72/*!
73	\fn BControl::BControl(const char *name, const char *label,
74						   BMessage *message, uint32 flags)
75	\brief Construct a control with a \a name, \a label, model \a message,
76		and creation \a flags suitable for use with the Layout API.
77
78	The initial value of the control is set to 0 (\c B_CONTROL_OFF).
79	The \a label and the \a message parameters can be set to \c NULL.
80
81	\param name The \a name of the control.
82	\param label The \a label displayed along with the control.
83	\param message The \a message to send when the control is activated.
84	\param flags Behavior \a flags for the control. See BView for details.
85*/
86
87
88/*!
89	\fn BControl::~BControl()
90	\brief Frees all memory used by the BControl object including the memory
91		used by the model message.
92*/
93
94
95/*!
96	\fn BControl::BControl(BMessage *archive)
97	\brief Constructs a BControl object from an \a archive message.
98
99	This method is usually not called directly. If you want to build a
100	control from a message you should call Instantiate() which can
101	handle errors properly.
102
103	If the \a archive deep, the BControl object will also unarchive each
104	of its child views recursively.
105
106	\param archive The \a archive message to restore from.
107*/
108
109
110/*!
111	\fn BArchivable* BControl::Instantiate(BMessage *archive)
112	\brief Creates a new object from an \a archive.
113
114	If the message is a valid object then the instance created from the
115	passed in \a archive will be returned. Otherwise this method will
116	return \c NULL.
117
118	\param archive The \a archive message.
119
120	\returns An instance of the object if \a archive is valid or \c NULL.
121
122	\sa BArchivable::Instantiate()
123*/
124
125
126/*!
127	\fn status_t BControl::Archive(BMessage *archive, bool deep) const
128	\brief Archives the object into \a archive.
129
130	\param archive The target \a archive that the data will go into.
131	\param deep Whether or not to recursively archive child views.
132
133	\retval B_OK The archive operation was successful.
134	\retval B_BAD_VALUE \c NULL \a archive message.
135	\retval B_ERROR The archive operation failed.
136
137	\sa BArchivable::Archive()
138*/
139
140
141/*!
142	\fn void BControl::WindowActivated(bool active)
143	\brief Hook method that is called when the attached window becomes
144		activated or deactivated.
145
146	The BControl is redrawn if it is a child of the focused view.
147
148	\param active \c true if the window becomes activated, \c false if the
149		window becomes deactivated.
150
151	\sa BView::WindowActivated()
152*/
153
154
155/*!
156	\fn void BControl::AttachedToWindow()
157	\brief Hook method that is called when the object is attached to a
158		window.
159
160	This method overrides BView::AttachedToWindow() setting the low color
161	and view color of the BControl so that it matches the view color of the
162	control's parent view. It also makes the attached window the default
163	target for Invoke() as long as another target has not already been set.
164
165	\sa BView::AttachedToWindow()
166	\sa Invoke()
167	\sa BInvoker::SetTarget()
168*/
169
170
171/*!
172	\fn void BControl::DetachedFromWindow()
173	\brief Hook method that is called when the object is detached from a
174		window.
175
176	\sa BView::DetachedFromWindow()
177*/
178
179
180/*!
181	\fn void BControl::AllAttached()
182	\brief Similar to AttachedToWindow() but this method is triggered after
183		all child views have already been attached to a window.
184
185	\sa BView::AllAttached()
186*/
187
188
189/*!
190	\fn void BControl::AllDetached()
191	\brief Similar to AttachedToWindow() but this method is triggered after
192		all child views have already been detached from a window.
193
194	\sa BView::AllDetached()
195*/
196
197
198/*!
199	\fn void BControl::MakeFocus(bool focused)
200	\brief Gives or removes focus from the control.
201
202	BControl::MakeFocus() overrides BView::MakeFocus() to call Draw() when
203	the focus changes. Derived classes generally don't have to re-implement
204	MakeFocus().
205
206	IsFocusChanging() returns \c true when Draw() is called from this method.
207
208	\param focused \a true to set focus, \a false to remove it.
209
210	\sa BView::MakeFocus()
211	\sa IsFocusChanging()
212*/
213
214
215/*!
216	\fn void BControl::KeyDown(const char *bytes, int32 numBytes)
217	\brief Hook method that is called when a keyboard key is pressed.
218
219	Overrides BView::KeyDown() to toggle the control value and then
220	calls Invoke() for \c B_SPACE or \c B_ENTER. If this is not desired
221	you should override this method in derived classes.
222
223	The KeyDown() method is only called if the BControl is the focus view
224	in the active window. If the window has a default button, \c B_ENTER
225	will be passed to that object instead of the focus view.
226
227	\param bytes The bytes of the key combination pressed.
228	\param numBytes The number of bytes in \a bytes.
229
230	\sa BView::KeyDown()
231	\sa MakeFocus()
232*/
233
234
235/*!
236	\fn void BControl::MouseDown(BPoint point)
237	\brief Hook method that is called when a mouse button is pressed.
238
239	\param point The point on the screen where to mouse pointer is when
240		the mouse button is pressed.
241
242	\sa BView::MouseDown()
243*/
244
245
246/*!
247	\fn void BControl::MouseUp(BPoint point)
248	\brief Hook method that is called when a mouse button is released.
249
250	\param point The point on the screen where to mouse pointer is when
251		the mouse button is released.
252
253	\sa BView::MouseUp()
254*/
255
256
257/*!
258	\fn void BControl::MouseMoved(BPoint point, uint32 transit,
259								  const BMessage *message)
260	\brief Hook method that is called when the mouse is moved.
261
262	\sa BView::MouseMoved()
263*/
264
265
266/*!
267	\fn void BControl::SetLabel(const char *label)
268	\brief Sets the \a label of the control.
269
270	If the \a label changes the control is redrawn.
271
272	\param label The \a label to set, can be \c NULL.
273*/
274
275
276/*!
277	\fn const char* BControl::Label() const
278	\brief Gets the label of the control.
279
280	returns The control's label.
281*/
282
283
284/*!
285	\fn void BControl::SetValue(int32 value)
286	\brief Sets the value of the control.
287
288	If the \a value changes the control is redrawn.
289
290	\param value The \a value to set.
291
292	\sa SetValueNoUpdate()
293*/
294
295
296/*!
297	\fn void BControl::SetValueNoUpdate(int32 value)
298	\brief Sets the value of the control without redrawing.
299
300	\param value The \a value to set.
301
302	\sa SetValue()
303*/
304
305
306/*!
307	\fn int32 BControl::Value() const
308	\brief Gets the value of the control.
309
310	\returns The control's value.
311*/
312
313
314/*!
315	\fn void BControl::SetEnabled(bool enabled)
316	\brief Enables or disables the control.
317
318	BControl objects are enabled by default. If the control changes enabled
319	state then it is redrawn.
320
321	Disabled controls generally won't allow the user to focus on them
322	(The \c B_NAVIGABLE flag is turned off), and don't post any messages.
323
324	Disabled controls in derived classes should be drawn in subdued colors
325	to visually indicate that they are disabled and should not respond to
326	keyboard or mouse events.
327
328	\param enabled If \c true enables the control, if \c false, disables it.
329*/
330
331
332/*!
333	\fn bool BControl::IsEnabled() const
334	\brief Gets whether or not the control is currently enabled.
335
336	\returns \c true if the control is enabled, \c false if it is disabled.
337*/
338
339
340/*!
341	\fn void BControl::GetPreferredSize(float *_width, float *_height)
342	\brief Fill out the preferred width and height of the control
343		into the \a _width and \a _height parameters.
344
345	Derived classes can override this method to set the preferred
346	width and height of the control.
347
348	\param _width Pointer to a \c float to hold the width of the control.
349	\param _height Pointer to a \c float to hold the height of the control.
350
351	\sa BView::GetPreferredSize()
352*/
353
354
355/*!
356	\fn void BControl::ResizeToPreferred()
357	\brief Resize the control to its preferred size.
358
359	\sa BView::ResizeToPreferred()
360*/
361
362
363/*!
364	\fn status_t BControl::Invoke(BMessage *message)
365	\brief Sends a copy of the model \a message to the designated target.
366
367	BControl::Invoke() overrides BInvoker::Invoke(). Derived classes
368	should use this method in their MouseDown() and KeyDown() methods
369	and should call IsEnabled() to check if the control is enabled
370	before calling Invoke().
371
372	The following fields added to the BMessage:
373		- "when"	\c B_INT64_TYPE	system_time()
374		- "source"	\c B_POINTER_TYPE	A pointer to the BControl object.
375
376	\param message The \a message to send.
377
378	\sa BInvoker::Invoke()
379	\sa IsEnabled()
380*/
381
382
383/*!
384	\fn BHandler* BControl::ResolveSpecifier(BMessage *message, int32 index,
385											 BMessage *specifier, int32 what,
386											 const char *property)
387	\brief Determine the proper specifier for scripting messages.
388
389	\sa BHandler::ResolveSpecifier()
390*/
391
392
393/*!
394	\fn status_t BControl::GetSupportedSuites(BMessage *message)
395	\brief Report the suites of understood messages.
396
397	\sa BHandler::GetSupportedSuites();
398*/
399
400
401/*!
402	\fn status_t BControl::Perform(perform_code code, void* _data)
403	\brief Perform some action. (Internal Method)
404
405	The following perform codes are recognized:
406		- \c PERFORM_CODE_MIN_SIZE
407		- \c PERFORM_CODE_MAX_SIZE
408		- \c PERFORM_CODE_PREFERRED_SIZE
409		- \c PERFORM_CODE_LAYOUT_ALIGNMENT
410		- \c PERFORM_CODE_HAS_HEIGHT_FOR_WIDTH
411		- \c PERFORM_CODE_GET_HEIGHT_FOR_WIDTH
412		- \c PERFORM_CODE_SET_LAYOUT
413		- \c PERFORM_CODE_INVALIDATE_LAYOUT
414		- \c PERFORM_CODE_DO_LAYOUT
415
416	\param code The perform code.
417	\param _data A pointer to store some data.
418
419	\returns A status code.
420
421	\sa BHandler::Perform()
422*/
423