16ec25bbaSAdrien Destugues/* 2820dca4dSJohn Scipione * Copyright 2011 Haiku Inc. All rights reserved. 3820dca4dSJohn Scipione * Distributed under the terms of the MIT License. 46ec25bbaSAdrien Destugues * 5820dca4dSJohn Scipione * Authors: 66ec25bbaSAdrien Destugues * Clark Gaeble 76ec25bbaSAdrien Destugues * Adrien Destugues <pulkomandy@pulkomandy.ath.cx> 8a33f8fbdSAdrien Destugues * John Scipione <jscipione@gmail.com> 9820dca4dSJohn Scipione * 106ec25bbaSAdrien Destugues * Corresponds to: 11*131261d2SJohn Scipione * headers/os/interface/Box.h rev 42274 12*131261d2SJohn Scipione * src/kits/interface/Box.cpp rev 42274 13a33f8fbdSAdrien Destugues 146ec25bbaSAdrien Destugues 156ec25bbaSAdrien Destugues/*! 166ec25bbaSAdrien Destugues \file Box.h 17820dca4dSJohn Scipione \ingroup interface 18820dca4dSJohn Scipione \ingroup libbe 196ec25bbaSAdrien Destugues \brief Defines the BBox class 206ec25bbaSAdrien Destugues*/ 216ec25bbaSAdrien Destugues 22a33f8fbdSAdrien Destugues 23a33f8fbdSAdrien Destugues/*! 24a33f8fbdSAdrien Destugues \class BBox 256ec25bbaSAdrien Destugues \ingroup interface 26820dca4dSJohn Scipione \ingroup libbe 276ac7032dSJohn Scipione \brief A rectangular view with a border and an optional label to group 286ac7032dSJohn Scipione related subviews visually. 296ec25bbaSAdrien Destugues 306ac7032dSJohn Scipione A basic BBox looks like this: 31a33f8fbdSAdrien Destugues \image html B_FANCY_BORDER.png 32a33f8fbdSAdrien Destugues 336ac7032dSJohn Scipione A box's label can either be composed of text or it can be a view such 34a33f8fbdSAdrien Destugues as a checkbox or dropdown box. See SetLabel() for more details on setting 356ac7032dSJohn Scipione the box's label. 366ec25bbaSAdrien Destugues*/ 376ec25bbaSAdrien Destugues 386ec25bbaSAdrien Destugues 39a33f8fbdSAdrien Destugues/*! 40a33f8fbdSAdrien Destugues \fn BBox::BBox(BRect frame, const char *name = NULL, 41a33f8fbdSAdrien Destugues uint32 resizingMode = B_FOLLOW_LEFT | B_FOLLOW_TOP, 42a33f8fbdSAdrien Destugues uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, 43a33f8fbdSAdrien Destugues border_style border = B_FANCY_BORDER) 446ac7032dSJohn Scipione \brief Constructs a named BBox object from a set of dimensions. 456ec25bbaSAdrien Destugues 466ac7032dSJohn Scipione \note This is the only constructor that can be used if the box is to be 47a33f8fbdSAdrien Destugues inserted in a window that doesn't use the layout system. 48a33f8fbdSAdrien Destugues 496ac7032dSJohn Scipione \param frame The bounds of the box. 506ac7032dSJohn Scipione \param name The name of the box. 516ac7032dSJohn Scipione \param resizingMode Defines the behavior of the box as the parent view 526ac7032dSJohn Scipione resizes. See BView for details. 536ac7032dSJohn Scipione \param flags Behavior flags for the box. See BView for details. 546ac7032dSJohn Scipione \param border The border_style of the box. 556ec25bbaSAdrien Destugues*/ 566ec25bbaSAdrien Destugues 576ec25bbaSAdrien Destugues 58a33f8fbdSAdrien Destugues/*! 59a33f8fbdSAdrien Destugues \fn BBox::BBox(const char* name, 60a33f8fbdSAdrien Destugues uint32 flags = B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP, 61a33f8fbdSAdrien Destugues border_style border = B_FANCY_BORDER, BView* child = NULL) 626ac7032dSJohn Scipione \brief Constructs a named BBox object with its dimensions defined 636ac7032dSJohn Scipione automatically by the Layout API. 646ec25bbaSAdrien Destugues 656ac7032dSJohn Scipione \param name The name of the box. 666ac7032dSJohn Scipione \param flags Behavior flags for the box. See BView for details. 676ac7032dSJohn Scipione \param border The border_style of the box. 686ac7032dSJohn Scipione \param child Adds an initial child to the Box object. See the Layout 696ac7032dSJohn Scipione API for details. 706ec25bbaSAdrien Destugues*/ 716ec25bbaSAdrien Destugues 726ec25bbaSAdrien Destugues 73a33f8fbdSAdrien Destugues/*! 74a33f8fbdSAdrien Destugues \fn BBox::BBox(border_style border, BView* child) 756ac7032dSJohn Scipione \brief Constructs an anonymous BBox object with a defined border style 766ac7032dSJohn Scipione and child view. 776ec25bbaSAdrien Destugues 786ac7032dSJohn Scipione There can only be a single child view. This view can, however, act as a 796ac7032dSJohn Scipione nesting container if you need to show more items inside the box. 806ec25bbaSAdrien Destugues*/ 816ec25bbaSAdrien Destugues 826ec25bbaSAdrien Destugues 83a33f8fbdSAdrien Destugues/*! 84a33f8fbdSAdrien Destugues \fn BBox::BBox(BMessage* archive) 856ac7032dSJohn Scipione \brief Constructs a BBox object from an \a archive message. 866ec25bbaSAdrien Destugues 87a33f8fbdSAdrien Destugues This method is usually not called directly. If you want to build a BBox 886ac7032dSJohn Scipione object from a message you should call Instantiate() which can 896ac7032dSJohn Scipione handle errors properly. 906ec25bbaSAdrien Destugues 916ac7032dSJohn Scipione If the \a archive deep, the BBox object will also unarchive each of its 926ac7032dSJohn Scipione child views recursively. 936ec25bbaSAdrien Destugues 946ac7032dSJohn Scipione \param archive The \a archive message to restore from. 956ec25bbaSAdrien Destugues*/ 966ec25bbaSAdrien Destugues 976ec25bbaSAdrien Destugues 98a33f8fbdSAdrien Destugues/*! 99a33f8fbdSAdrien Destugues \fn BBox::~BBox() 100a33f8fbdSAdrien Destugues \brief Destructor method. 1016ec25bbaSAdrien Destugues 102a33f8fbdSAdrien Destugues Calling the destructor will also free the memory used by the box's label 103a33f8fbdSAdrien Destugues if it has one. 1046ec25bbaSAdrien Destugues*/ 1056ec25bbaSAdrien Destugues 1066ec25bbaSAdrien Destugues 107a33f8fbdSAdrien Destugues/*! 108a33f8fbdSAdrien Destugues \fn static BArchivable* BBox::Instantiate(BMessage* archive) 1096ac7032dSJohn Scipione \brief Creates a new object from an \a archive. 1106ec25bbaSAdrien Destugues 1116ac7032dSJohn Scipione If the message is a valid object then the instance created from the 112a33f8fbdSAdrien Destugues passed in \a archive will be returned. Otherwise this method will 113a33f8fbdSAdrien Destugues return \c NULL. 114a33f8fbdSAdrien Destugues 115a33f8fbdSAdrien Destugues \param archive The \a archive message. 116a33f8fbdSAdrien Destugues 1176ac7032dSJohn Scipione \returns An instance of the object if \a archive is valid or \c NULL. 1186ac7032dSJohn Scipione 1196ac7032dSJohn Scipione \sa BArchivable::Instantiate() 120a33f8fbdSAdrien Destugues*/ 121a33f8fbdSAdrien Destugues 122a33f8fbdSAdrien Destugues 123a33f8fbdSAdrien Destugues/*! 124a33f8fbdSAdrien Destugues \fn virtual status_t BBox::Archive(BMessage* archive, 125a33f8fbdSAdrien Destugues bool deep = true) const; 1266ac7032dSJohn Scipione \brief Archives the object into \a archive. 127a33f8fbdSAdrien Destugues 1286ac7032dSJohn Scipione \param archive The target \a archive that the data will go into. 1296ac7032dSJohn Scipione \param deep Whether or not to recursively archive child views. 130a33f8fbdSAdrien Destugues 131a33f8fbdSAdrien Destugues \retval B_OK The archive operation was successful. 1326ac7032dSJohn Scipione \retval B_BAD_VALUE \c NULL \a archive message. 1336ac7032dSJohn Scipione \retval B_ERROR The archive operation failed. 1346ac7032dSJohn Scipione 1356ac7032dSJohn Scipione \sa BArchivable::Archive() 1366ec25bbaSAdrien Destugues*/ 1376ec25bbaSAdrien Destugues 1386ec25bbaSAdrien Destugues 139a33f8fbdSAdrien Destugues/*! 140a33f8fbdSAdrien Destugues \fn virtual void BBox::SetBorder(border_style border) 1416ac7032dSJohn Scipione \brief Sets the #border_style. 14201c2a7f3SAdrien Destugues 1436ac7032dSJohn Scipione Possible #border_style values include: 1446ac7032dSJohn Scipione - \c B_PLAIN_BORDER A single 1-pixel line border. 1456ac7032dSJohn Scipione - \c B_FANCY_BORDER The default, beveled look. 1466ac7032dSJohn Scipione - \c B_NO_BORDER Used to make a borderless box. 1476ac7032dSJohn Scipione 1486ac7032dSJohn Scipione \param border The #border_style to set. 1496ec25bbaSAdrien Destugues*/ 1506ec25bbaSAdrien Destugues 1516ec25bbaSAdrien Destugues 152a33f8fbdSAdrien Destugues/*! 153a33f8fbdSAdrien Destugues \fn border_style BBox::Border() const 1546ac7032dSJohn Scipione \brief Gets the current #border_style. 155a33f8fbdSAdrien Destugues 1566ac7032dSJohn Scipione Possible #border_style values include: 1576ac7032dSJohn Scipione - \c B_PLAIN_BORDER A single 1-pixel line border. 1586ac7032dSJohn Scipione - \c B_FANCY_BORDER The default, beveled look. 1596ac7032dSJohn Scipione - \c B_NO_BORDER Used to make a borderless box. 1606ac7032dSJohn Scipione 1616ac7032dSJohn Scipione \returns The #border_style of the box. 1626ec25bbaSAdrien Destugues*/ 1636ec25bbaSAdrien Destugues 1646ec25bbaSAdrien Destugues 165a33f8fbdSAdrien Destugues/*! 166a33f8fbdSAdrien Destugues \fn float BBox::TopBorderOffset() 1676ac7032dSJohn Scipione \brief Gets the distance from the very top of the box to the top border 1686ac7032dSJohn Scipione line in pixels. 169a33f8fbdSAdrien Destugues 170a33f8fbdSAdrien Destugues \warning This method is not part of the BeOS R5 API and is not yet 171a33f8fbdSAdrien Destugues finalized. 17201c2a7f3SAdrien Destugues 1736ac7032dSJohn Scipione The distance may vary depending on the text or view used as label and the 1746ac7032dSJohn Scipione font settings. The border is drawn center-aligned with the label. This 1756ac7032dSJohn Scipione method can be used to line up two boxes visually if one has a label and 1766ac7032dSJohn Scipione the other does not. 17701c2a7f3SAdrien Destugues 1786ac7032dSJohn Scipione \returns The distance from the very top of the box to the top border 1796ac7032dSJohn Scipione line in pixels as a \c float. 1806ec25bbaSAdrien Destugues*/ 1816ec25bbaSAdrien Destugues 1826ec25bbaSAdrien Destugues 183a33f8fbdSAdrien Destugues/*! 184a33f8fbdSAdrien Destugues \fn BRect BBox::InnerFrame() 1856ac7032dSJohn Scipione \brief Gets the frame rectangle just inside the border of the box. 186a33f8fbdSAdrien Destugues 187a33f8fbdSAdrien Destugues \warning This method is not part of the BeOS R5 API and is not yet 188a33f8fbdSAdrien Destugues finalized. 189a33f8fbdSAdrien Destugues 1906ac7032dSJohn Scipione \returns A BRect set to the dimensions of the box's inside border. 1916ec25bbaSAdrien Destugues*/ 1926ec25bbaSAdrien Destugues 1936ec25bbaSAdrien Destugues 194a33f8fbdSAdrien Destugues/*! 195a33f8fbdSAdrien Destugues \fn void BBox::SetLabel(const char* string) 196a33f8fbdSAdrien Destugues \brief Sets the box's label text. 1976ec25bbaSAdrien Destugues 1986ac7032dSJohn Scipione Below is an example of a box with some simple text label: 199a33f8fbdSAdrien Destugues 200a33f8fbdSAdrien Destugues \image html BBox_example.png 201a33f8fbdSAdrien Destugues 2026ac7032dSJohn Scipione The code to create a box with a text label looks like this: 203a33f8fbdSAdrien Destugues \code 204a33f8fbdSAdrien DestuguesfIconBox = new BBox("Icon Box"); 205a33f8fbdSAdrien DestuguesfIconBox->SetLabel("Icon"); 206a33f8fbdSAdrien Destugues \endcode 207a33f8fbdSAdrien Destugues 208a33f8fbdSAdrien Destugues \param string The label text string to set as the box's title. 2096ec25bbaSAdrien Destugues*/ 2106ec25bbaSAdrien Destugues 2116ec25bbaSAdrien Destugues 212a33f8fbdSAdrien Destugues/*! 213a33f8fbdSAdrien Destugues \fn status_t BBox::SetLabel(BView* viewLabel) 2146ac7032dSJohn Scipione \brief Sets the label from a BView. 2156ec25bbaSAdrien Destugues 2166ac7032dSJohn Scipione This version of SetLabel() provides for building a BBox object with a 2176ac7032dSJohn Scipione control used in place of the text label. You can pass in any type of 2186ac7032dSJohn Scipione BView derived control for this such as a BPopupMenu or BCheckBox. 219a33f8fbdSAdrien Destugues 2206ac7032dSJohn Scipione An example of a box with a checkbox view is shown below: 221a33f8fbdSAdrien Destugues \image html BBox_with_checkbox.png 222a33f8fbdSAdrien Destugues 2236ac7032dSJohn Scipione The code to create such a box looks like this: 224a33f8fbdSAdrien Destugues \code 225a33f8fbdSAdrien DestuguesfVirtualMemoryEnabledCheckBox = new BCheckBox("Virtual memory check box", 226a33f8fbdSAdrien Destugues "Enable virtual memory", new BMessage(kVirtualMemoryEnabled)); 227a33f8fbdSAdrien Destugues 228a33f8fbdSAdrien DestuguesBBox* fVirtualMemoryBox = new BBox("Virtual memory box"); 229a33f8fbdSAdrien DestuguesfVirtualMemoryBox->SetLabel(fVirtualMemoryEnabledCheckBox); 230a33f8fbdSAdrien Destugues \endcode 231a33f8fbdSAdrien Destugues 232a33f8fbdSAdrien Destugues \param viewLabel A BView. 2336ac7032dSJohn Scipione 234a33f8fbdSAdrien Destugues \returns \c B_OK 2356ec25bbaSAdrien Destugues*/ 2366ec25bbaSAdrien Destugues 2376ec25bbaSAdrien Destugues 238a33f8fbdSAdrien Destugues/*! 239a33f8fbdSAdrien Destugues \fn const char* BBox::Label() const 2406ac7032dSJohn Scipione \brief Gets the text of the box's label. 2416ec25bbaSAdrien Destugues 2426ac7032dSJohn Scipione This only works if the label is set as text. If you set the label to a 2436ac7032dSJohn Scipione BView, you have to get the text by other means, likely starting with 24401c2a7f3SAdrien Destugues LabelView. 245a33f8fbdSAdrien Destugues 2466ac7032dSJohn Scipione \returns The label text of the BBox if the box has a text label or 2476ac7032dSJohn Scipione \c NULL otherwise. 2486ec25bbaSAdrien Destugues*/ 2496ec25bbaSAdrien Destugues 2506ec25bbaSAdrien Destugues 251a33f8fbdSAdrien Destugues/*! 252a33f8fbdSAdrien Destugues \fn BView* BBox::LabelView() const 2536ec25bbaSAdrien Destugues \brief Gets the BView representing the label. 2546ac7032dSJohn Scipione 2556ac7032dSJohn Scipione \returns a pointer to a BView object. 2566ec25bbaSAdrien Destugues*/ 2576ec25bbaSAdrien Destugues 2586ec25bbaSAdrien Destugues 259a33f8fbdSAdrien Destugues/*! 260a33f8fbdSAdrien Destugues \fn virtual void BBox::Draw(BRect updateRect) 2616ac7032dSJohn Scipione \brief Draws the area of the box that intersects \a updateRect. 2626ec25bbaSAdrien Destugues 2636ac7032dSJohn Scipione This is an hook method called by the Interface Kit, you don't have to 2646ac7032dSJohn Scipione call it yourself. If you need to forcefully redraw the view, 2656ac7032dSJohn Scipione consider calling Invalidate() instead. 26601c2a7f3SAdrien Destugues 2676ac7032dSJohn Scipione \param updateRect The rectangular area to be drawn. 2686ec25bbaSAdrien Destugues*/ 2696ec25bbaSAdrien Destugues 2706ec25bbaSAdrien Destugues 271a33f8fbdSAdrien Destugues/*! 272a33f8fbdSAdrien Destugues \fn virtual void BBox::AttachedToWindow() 2736ac7032dSJohn Scipione \brief Hook method that is called when the object is attached to a 2746ac7032dSJohn Scipione window. 2756ec25bbaSAdrien Destugues 2766ac7032dSJohn Scipione This method overrides BView::AttachedToWindow() to set the background 2776ac7032dSJohn Scipione color of the box to the background of its parent view. 2786ec25bbaSAdrien Destugues 279a33f8fbdSAdrien Destugues If you are using the layout system, the BBox is also resized according to 280a33f8fbdSAdrien Destugues the layout of the parent view. 2816ac7032dSJohn Scipione 2826ac7032dSJohn Scipione \sa BView::AttachedToWindow() 2836ec25bbaSAdrien Destugues*/ 2846ec25bbaSAdrien Destugues 2856ec25bbaSAdrien Destugues 286a33f8fbdSAdrien Destugues/*! 287a33f8fbdSAdrien Destugues \fn virtual void BBox::FrameResized(float width, float height) 2886ac7032dSJohn Scipione \brief Hook method that gets called when the BBox object is resized. 2896ec25bbaSAdrien Destugues 2906ac7032dSJohn Scipione This method may be called either because the window in which the BBox 2916ac7032dSJohn Scipione object was resized, or because the window layout was otherwise altered. 2926ec25bbaSAdrien Destugues 2936ac7032dSJohn Scipione This method recomputes the layout of the BBox (including label and 2946ac7032dSJohn Scipione contents) and makes it redraw as necessary. 2956ec25bbaSAdrien Destugues*/ 2966ec25bbaSAdrien Destugues 2976ec25bbaSAdrien Destugues 298a33f8fbdSAdrien Destugues/*! 299a33f8fbdSAdrien Destugues \fn virtual void BBox::ResizeToPreferred() 3006ac7032dSJohn Scipione \brief Resizes the box to its preferred dimensions. 3016ec25bbaSAdrien Destugues 3026ac7032dSJohn Scipione \note This only works in the non-layout mode, as it forces the resizing. 3036ec25bbaSAdrien Destugues*/ 3046ec25bbaSAdrien Destugues 3056ec25bbaSAdrien Destugues 306a33f8fbdSAdrien Destugues/*! 307a33f8fbdSAdrien Destugues \fn virtual void BBox::GetPreferredSize(float* _width, float* _height) 3086ac7032dSJohn Scipione \brief Fill out the preferred width and height of the box 3096ac7032dSJohn Scipione into the \a _width and \a _height parameters. 3106ec25bbaSAdrien Destugues 311a33f8fbdSAdrien Destugues \note Either the \a _width or \a _height parameter may be set to \c NULL 312a33f8fbdSAdrien Destugues if you only want to get the other one. 31301c2a7f3SAdrien Destugues 3146ac7032dSJohn Scipione The size is computed from the child view sizes, unless it was explicitly 3156ac7032dSJohn Scipione set for the BBox (which can be done only if the BBox is configured to 3166ac7032dSJohn Scipione use the Layout API). 3176ac7032dSJohn Scipione 3186ac7032dSJohn Scipione \param[out] _width Pointer to a \c float to store the width of the view. 3196ac7032dSJohn Scipione \param[out] _height Pointer to a \c float to store the height of the view. 3206ec25bbaSAdrien Destugues*/ 3216ec25bbaSAdrien Destugues 3226ec25bbaSAdrien Destugues 323a33f8fbdSAdrien Destugues/*! 324a33f8fbdSAdrien Destugues \fn virtual BSize BBox::MinSize() 3256ac7032dSJohn Scipione \brief Gets the minimum possible size of the BBox object. 3266ec25bbaSAdrien Destugues 3276ac7032dSJohn Scipione Drawing the box at this size ensures the label and the child view are 3286ac7032dSJohn Scipione visible. Reducing the size even more would mean that a view would not 3296ac7032dSJohn Scipione be visible. 3306ec25bbaSAdrien Destugues*/ 3316ec25bbaSAdrien Destugues 3326ec25bbaSAdrien Destugues 333a33f8fbdSAdrien Destugues/*! 334a33f8fbdSAdrien Destugues \fn virtual BSize BBox::MaxSize() 3356ac7032dSJohn Scipione \brief Gets the maximum possible size of the BBox object. 3366ec25bbaSAdrien Destugues 3376ac7032dSJohn Scipione The maximum size depends on the maximize size of the child views. 338a33f8fbdSAdrien Destugues 3396ac7032dSJohn Scipione \returns The maximum possible size of the BBox as a BSize. 3406ec25bbaSAdrien Destugues*/ 3416ec25bbaSAdrien Destugues 3426ec25bbaSAdrien Destugues 343a33f8fbdSAdrien Destugues/*! 344a33f8fbdSAdrien Destugues \fn virtual BSize BBox::PreferredSize() 3456ac7032dSJohn Scipione \brief Returns the preferred size of the box. 3466ec25bbaSAdrien Destugues 3476ac7032dSJohn Scipione This method works the same as GetPreferredSize, but uses the more 3486ac7032dSJohn Scipione convenient BSize object. 349a33f8fbdSAdrien Destugues 3506ac7032dSJohn Scipione \returns The minimum possible size of the BBox as a BSize. 3516ec25bbaSAdrien Destugues*/ 3526ec25bbaSAdrien Destugues 3536ec25bbaSAdrien Destugues 354a33f8fbdSAdrien Destugues/*! 355a33f8fbdSAdrien Destugues \fn virtual void BBox::DoLayout() 3566ac7032dSJohn Scipione \brief Lays out the box moving everything into its appropriate position. 3576ec25bbaSAdrien Destugues 3586ac7032dSJohn Scipione This only works if the BBox object was constructed using the Layout API, 359a33f8fbdSAdrien Destugues i.e. it was created with one of the BRect-less constructors. 36001c2a7f3SAdrien Destugues 3616ac7032dSJohn Scipione Once the size of the box is known from laying out its parent views, 3626ac7032dSJohn Scipione this method is called so the box can adjust the position and size of the 3636ac7032dSJohn Scipione label, eventually truncating the label text if there is not enough space. 3646ac7032dSJohn Scipione The exact border positions are also computed, then the child view is also 3656ac7032dSJohn Scipione laid out if its size constraints change. 3666ec25bbaSAdrien Destugues*/ 367