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