1/* 2 * Copyright 2010, Haiku, Inc. All Rights Reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Documentation by: 6 * Alex Wilson <yourpalal2@gmail.com> 7 * Corresponds to: 8 * /trunk/headers/os/interface/LayoutItem.h rev 38207 9 * /trunk/src/kits/interface/LayoutItem.cpp rev 38207 10 */ 11 12 13/*! 14 \file LayoutItem.h 15 Describes the BLayoutItem class 16*/ 17 18 19/*! 20 \class BLayoutItem 21 \ingroup interface 22 \ingroup layout 23 \ingroup libbe 24 25 \brief Abstract class representing things that are positionable and 26 resizable by objects of the BLayout class. 27 28 The BLayoutItem class provides an interface that is meant to be used almost 29 exclusively by objects of the BLayout class. Despite this, there are some 30 methods that are provided for other users of the class. 31 32 \warning This class is not yet finalized, if you use it in your software 33 assume that it will break some time in the future. 34*/ 35 36 37/*! 38 \fn BLayoutItem::BLayoutItem(BMessage* archive) 39 \brief Archive constructor. 40 41 Creates a BLayoutItem from the \a archive message. 42*/ 43 44 45/*! 46 \fn BLayout* BLayoutItem::Layout() const 47 \brief Returns the BLayout this BLayoutItem resides in. 48*/ 49 50 51/*! 52 \fn BLayout::~BLayout() 53 \brief Destructor method. 54 55 Standard Destructor. 56*/ 57 58 59/*! 60 \name Reporting size and alignment constraints to a BLayout 61*/ 62 63 64//! @{ 65 66 67/*! 68 \fn BSize BLayoutItem::MinSize() = 0 69 \brief Returns the minimum desirable size for this item. 70*/ 71 72 73/*! 74 \fn BSize BLayoutItem::MaxSize() = 0 75 \brief Returns the maximum desirable size for this item. 76*/ 77 78 79/*! 80 \fn BSize BLayoutItem::PreferredSize() = 0 81 \brief Returns the preferred size for this item. 82*/ 83 84 85/*! 86 \fn BAlignment BLayoutItem::Alignment() = 0 87 \brief Returns the requested alignment for this item. 88 89 The value returned from this method is used in BLayoutItem::AlignInFrame(), 90 which BLayouts use to position and resize items. In a vertical BGroupLayout, 91 for example, although each item recieves the same horizontal area, each item 92 can use that area differently, aligning to the left, right or center for 93 example. 94*/ 95 96 97/*! 98 \fn bool BLayoutItem::HasHeightForWidth() 99 \brief Returns whether or not this BLayoutItem's height constraints are 100 dependent on its width. 101 102 \note By default, this method returns \c false. 103*/ 104 105 106/*! 107 \fn void BLayoutItem::GetHeightForWidth(float width, float* min, 108 float* max, float* preferred) 109 \brief Get this BLayoutItem's height constraints for a given \a width. 110 111 If a BLayoutItem does not have height for width constraints 112 (HasHeightForWidth() returns \c false) it does not need to implement this 113 method. 114 115 \note It is prudent to compare \a min, \a max, \a preferred to \c NULL 116 before dereferencing them. 117*/ 118 119 120//! @} 121 122 123/*! 124 \name Overriding size constraints and alignment. 125 126 Although the explicit constraints placed on an item are not enforced by the 127 BLayoutItem class, all Haiku BLayoutItem subclasses will use the 128 BLayoutUtils::ComposeSize() or BLayoutUtils::ComposeAlignment() functions 129 in when reporting these constraints. It is recommended that all subclasses 130 do this as well, the BAbstractLayoutItem class provides any easy way to 131 include this behaviour in your class. 132*/ 133 134 135//! @{ 136 137 138/*! 139 \fn void BLayoutItem::SetExplicitMinSize(BSize size) = 0 140 \brief Set this item's explicit min size, to be used in MinSize(). 141*/ 142 143 144/*! 145 \fn void BLayoutItem::SetExplicitMaxSize(BSize size) = 0 146 \brief Set this item's explicit max size, to be used in MaxSize(). 147*/ 148 149 150/*! 151 \fn void BLayoutItem::SetExplicitPreferredSize(BSize size) = 0 152 \brief Set this item's explicit preferred size, to be used in 153 PreferredSize(). 154*/ 155 156 157/*! 158 \fn void BLayoutItem::SetExplicitAlignment(BAlignment alignment) = 0 159 \brief Set this item's explicit alignment, to be used in Alignment(). 160*/ 161 162 163//! @} 164 165 166/*! 167 \name Getting and setting the visiblity of a BLayoutItem. 168 169 These methods take into account only the local visibility of this 170 item, not the visibility of its ancestors. \n 171*/ 172 173 174//! @{ 175 176 177/*! 178 \fn bool BLayoutItem::IsVisible() = 0 179 \brief Return the current local visibility of this item. If an item is not 180 visible, it will not be given space by the BLayout it resides in. 181 182 A simple implementation would return the last thing passed to SetVisible(). 183 A more complex implementation may deal with a BView that could 184 be hidden in any number of ways. 185*/ 186 187 188/*! 189 \fn void BLayoutItem::SetVisible(bool visible) = 0 190 \brief Set the local visibility of this item. 191*/ 192 193 194//! @} 195 196 197/*! 198 \name Getting and setting the current on-screen positioning of a BLayoutItem. 199*/ 200 201 202//! @{ 203 204 205/*! 206 \fn void BLayoutItem::AlignInFrame(BRect frame) 207 \brief Position this BLayoutItem within \a frame, given the value returned 208 by Alignment(), and the size constraints for this item. 209*/ 210 211 212/*! 213 \fn BRect BLayoutItem::Frame() = 0 214 \brief Return the bounding frame of this item. 215 216 The returned BRect is in the coordinate system of the target view of the 217 BLayout this item belongs to. 218*/ 219 220 221/*! 222 \fn void BLayoutItem::SetFrame(BRect frame) = 0 223 \brief Set the bounding frame of this item. 224 225 \a frame is in the coordinate system of the target view of the BLayout 226 that this item belongs to. 227*/ 228 229 230//! @} 231 232 233/*! 234 \fn BView* BLayoutItem::View() 235 \brief Return the BView this item is representing, or \c NULL if it does not 236 represent any view. 237 238 When a BLayoutItem is added to a BLayout, this method is called, and the 239 returned BView will be added to the BLayout's target view. 240*/ 241 242 243/*! 244 \name Layout events and requests. 245 246 \brief These methods represent events or requests originating from a 247 BLayout. In some implementations they may be handled directly by this 248 BLayoutItem, but many implementations will forward these events to 249 another object. 250*/ 251 252 253//! @{ 254 255 256/*! 257 \fn void BLayoutItem::InvalidateLayout(bool children = false) 258 \brief Invalidate the layout of this item, or the object it represents. 259 260 If \a children is \c true, then you should also invalidate any child 261 objects. 262*/ 263 264 265/*! 266 \fn void BLayoutItem::Relayout(bool immediate = false) 267 \brief Relayout any children or onscreen data this item contains. Often 268 this request is forwarded to another object. 269*/ 270 271 272//! @} 273 274 275/*! 276 \name Utility methods for BLayout subclasses 277 \brief Utility methods for the BLayout class to attach and retrieve 278 arbitrary data for a BLayoutItem. 279*/ 280 281 282//! @{ 283 284 285/*! 286 \fn void* BLayoutItem::LayoutData() const 287 \brief Retrieve arbitrary data attached to this BLayoutItem. 288 289 \note This method should only be called by a BLayout subclass. 290*/ 291 292 293/*! 294 \fn void BLayoutItem::SetLayoutData(void* data) 295 \brief Attach arbitrary data to this BLayoutItem. 296 297 \note This method should only be called by a BLayout subclass. 298*/ 299 300 301//! @} 302 303 304/*! 305 \name Hook methods 306*/ 307 308 309//! @{ 310 311 312/*! 313 \fn void BLayoutItem::AttachedToLayout() 314 \brief Hook called when this object is attached to a BLayout (via 315 BLayout::AddItem()) 316 317 \note You can find the BLayout you've been attached to with the Layout() 318 method. 319*/ 320 321 322/*! 323 \fn void BLayoutItem::DetachedFromLayout(BLayout* layout) 324 \brief Hook called when this object is attached to a BLayout (via 325 BLayout::RemoveItem()) 326 327 \warning You should not use this hook to reattach \c this to \a BLayout, 328 doing so will cause undefined behaviour (probably a crash). 329 330 \param layout The BLayout you were previously attached to. 331*/ 332 333 334/*! 335 \fn void BLayoutItem::AncestorVisibilityChanged(bool shown) 336 \brief Hook called when this BLayoutItem's ancestors change visibility, 337 effectively hiding or showing this item. 338 339 Implementations of this method should alter the onscreen visibility of this 340 item. I.E. if \a shown is \c false, nothing should be drawn to represent 341 this item. 342 343 \note This method should not effect the value returned by this object's 344 IsVisible() method. 345 346 \param shown \c true to show, \c false to hide. 347*/ 348 349 350//! @} 351