The BLayout class provides an interface, and some basic implementation to manage the positioning and sizing of BLayoutItem s. More...
Public Member Functions | |
| BLayout () | |
| Default constructor. | |
| BLayout (BMessage *archive) | |
| Archive constructor. | |
| virtual | ~BLayout () |
| Destructor, deletes all BLayoutItem's that this layout manages, and detaches from this BLayout's owner view if there is one. | |
| BLayout * | Layout () const |
| Returns the BLayout this BLayoutItem resides in. | |
| virtual status_t | Perform (perform_code d, void *arg) |
| Perform some action (Internal method defined for binary compatibility purposes). | |
BView targeting and attachment information. | |
| BView * | Owner () const |
| Returns the Owner of this layout, i.e. the view this layout manages. | |
| BView * | TargetView () const |
| Returns the target view of this layout. | |
| virtual BView * | View () |
| Returns the same BView* as BLayout::Owner(), this method is inherited from BLayoutItem. | |
Adding, removing, counting and accessing BLayout children | |
| virtual BLayoutItem * | AddView (BView *child) |
| Creates a BLayoutItem to represent a BView, and adds that item to this layout. | |
| virtual BLayoutItem * | AddView (int32 index, BView *child) |
| Creates a BLayoutItem to represent child, and adds that item at index to this layout. child is added to this BLayout's target view. | |
| virtual bool | AddItem (BLayoutItem *item) |
| Adds a BLayoutItem to this layout, and adds the BView it represents to this BLayout's target view. | |
| virtual bool | AddItem (int32 index, BLayoutItem *item) |
| Adds item to this layout, and adds the BView item represents to this BLayout's target view. | |
| virtual bool | RemoveView (BView *child) |
| Removes and deletes all BLayoutItem representing a BView from this layout. | |
| virtual bool | RemoveItem (BLayoutItem *item) |
| Removes a BLayoutItem from this layout, and also removes the view it represents from this BLayout's target view. | |
| virtual BLayoutItem * | RemoveItem (int32 index) |
| Remove the BLayoutItem at index. | |
| BLayoutItem * | ItemAt (int32 index) const |
Get the BLayoutItem at index. Returns NULL if index is out of bounds. | |
| int32 | CountItems () const |
| Get the number of BLayoutItem s in this layout. | |
| int32 | IndexOfItem (const BLayoutItem *item) const |
| Get the index of a BLayoutItem in this layout. | |
| int32 | IndexOfView (BView *child) const |
| Get the index of child in this layout. | |
Methods triggering or related to laying out this BLayout. | |
| virtual void | Relayout (bool immediate=false) |
| Request this BLayout to reposition and resize its items as required. | |
| void | LayoutItems (bool force=false) |
If there is no layout currently ongoing, and force is false, creates a new BLayoutContext and calls the DoLayout() method of this BLayout and any BLayout s nested in this BLayout. | |
Reporting size and alignment constraints to a BLayout | |
| virtual BSize | MinSize ()=0 |
| Returns the minimum desirable size for this item. | |
| virtual BSize | MaxSize ()=0 |
| Returns the maximum desirable size for this item. | |
| virtual BSize | PreferredSize ()=0 |
| Returns the preferred size for this item. | |
| virtual BAlignment | Alignment ()=0 |
| Returns the requested alignment for this item. | |
| virtual bool | HasHeightForWidth () |
| Returns whether or not this BLayoutItem's height constraints are dependent on its width. | |
| virtual void | GetHeightForWidth (float width, float *min, float *max, float *preferred) |
| Get this BLayoutItem's height constraints for a given width. | |
Overriding size constraints and alignment. | |
Although the explicit constraints placed on an item are not enforced by the BLayoutItem class, all Haiku BLayoutItem subclasses will use the BLayoutUtils::ComposeSize() or BLayoutUtils::ComposeAlignment() functions in when reporting these constraints. It is recommended that all subclasses do this as well, the BAbstractLayoutItem class provides any easy way to include this behaviour in your class. | |
| virtual void | SetExplicitMinSize (BSize size)=0 |
| Set this item's explicit min size, to be used in MinSize(). | |
| virtual void | SetExplicitMaxSize (BSize size)=0 |
| Set this item's explicit max size, to be used in MaxSize(). | |
| virtual void | SetExplicitPreferredSize (BSize size)=0 |
| Set this item's explicit preferred size, to be used in PreferredSize(). | |
| virtual void | SetExplicitAlignment (BAlignment alignment)=0 |
| Set this item's explicit alignment, to be used in Alignment(). | |
Getting and setting the visiblity of a BLayoutItem. | |
These methods take into account only the local visibility of this item, not the visibility of its ancestors. | |
| virtual bool | IsVisible ()=0 |
| Return the current local visibility of this item. If an item is not visible, it will not be given space by the BLayout it resides in. | |
| virtual void | SetVisible (bool visible)=0 |
| Set the local visibility of this item. | |
Getting and setting the current on-screen positioning of a BLayoutItem. | |
| virtual BRect | Frame ()=0 |
| Return the bounding frame of this item. | |
| virtual void | SetFrame (BRect frame)=0 |
| Set the bounding frame of this item. | |
| void | AlignInFrame (BRect frame) |
| Position this BLayoutItem within frame, given the value returned by Alignment(), and the size constraints for this item. | |
Utility methods for BLayout subclasses | |
Utility methods for the BLayout class to attach and retrieve arbitrary data for a BLayoutItem. | |
| void * | LayoutData () const |
| Retrieve arbitrary data attached to this BLayoutItem. | |
| void | SetLayoutData (void *data) |
| Attach arbitrary data to this BLayoutItem. | |
Static Public Member Functions | |
| static BArchivable * | Instantiate (BMessage *archive) |
| Static member to restore objects from messages. | |
Protected Member Functions | |
| virtual status_t | AllArchived (BMessage *archive) const |
Method relating to the use of BArchiver. | |
| virtual void | LayoutInvalidated (bool children) |
| Hook called from InvalidateLayout(). | |
BLayout Hook methods | |
| virtual bool | ItemAdded (BLayoutItem *item, int32 atIndex) |
| Hook method called when item is added to this layout. | |
| virtual void | ItemRemoved (BLayoutItem *item, int32 fromIndex) |
| Hook method called when item is removed from this layout. | |
| virtual void | DoLayout ()=0 |
| Implemented by derived classes to position and resize the items in this layout. | |
| virtual void | OwnerChanged (BView *was) |
| Hook method called when this layout is attached to a BView. | |
| virtual void | AttachedToLayout () |
| Hook method inherited from BLayoutItem, classes derived from BLayout must include the BLayout version of this method in their implementation. | |
| virtual void | DetachedFromLayout (BLayout *layout) |
| Hook method inherited from BLayoutItem, classes derived from BLayout must include the BLayout version of this method in their implementation. | |
| virtual void | AncestorVisibilityChanged (bool shown) |
| Hook method inherited from BLayoutItem, classes derived from BLayout must include the BLayout version of this method in their implementation. | |
Subclass helpers. | |
These methods are meant to ease the development of BLayout subclasses. | |
| bool | AncestorsVisible () const |
| Get the visibility of the ancestors of this layout. | |
| BRect | LayoutArea () |
| Returns the on-screen area this layout has received to lay out its items in. | |
| void | VisibilityChanged (bool show) |
| Method to be called by derived classes in their SetVisible() implementation. Calls AncestorVisibilityChanged() on the items in this BLayout. | |
Invalidation and state mutators and accessors. | |
| virtual void | InvalidateLayout (bool children=false) |
| Invalidate this layout and any cached data this layout has relating to positioning and sizing of its items. | |
| void | RequireLayout () |
| Flag this layout as stale, i.e. any cached data may still be valid, but the items need to be repositioned or resized. | |
| bool | IsValid () |
| Returns whether this layout has been invalidated (via BLayout::InvalidateLayout()) and has not yet been validated (by doing a layout, or by its ResetLayoutInvalidation() method. | |
| void | EnableLayoutInvalidation () |
| Re-enable layout invalidation after a call to DisableLayoutInvalidation(). | |
| void | DisableLayoutInvalidation () |
| Disable layout invalidation notifications, i.e. calls to this object's InvalidateLayout() method. | |
| void | ResetLayoutInvalidation () |
| Reset layout invalidation, causing InvalidateLayout calls to proceed again. This method should be called once any cached data has been validated, or updated to valid values. | |
Archiving methods | |
These methods relate to the archiving or unarchiving of this object and the BLayoutItem's it contains | |
| virtual status_t | Archive (BMessage *into, bool deep=true) const |
| Archives this layout into archive. If deep is true, also archives the items in this layout, calling ItemArchived() for each one. | |
| virtual status_t | AllUnarchived (const BMessage *from) |
| Unarchives the BLayoutItem's for this layout, calling ItemUnarchived() for each one. | |
| virtual status_t | ItemArchived (BMessage *into, BLayoutItem *item, int32 index) const |
| Hook for derived classes to add data specific to item to the into BMessage. item resides at index. | |
| virtual status_t | ItemUnarchived (const BMessage *from, BLayoutItem *item, int32 index) |
| Hook for derived classes to retrieve data specific to item from the from BMessage. item resides at index. | |
The BLayout class provides an interface, and some basic implementation to manage the positioning and sizing of BLayoutItem s.
BLayouts can be attached to a BView, managing the BLayoutItem's and BView's that reside in that view, or can be nested within another BLayout as a BLayoutItem.
Before adding a BLayoutItem to a BLayout, that layout must have a target view. When a BLayout is attached directly to a BView via BView::SetLayout() then that BView becomes the target of the layout. When a BLayout is nested in another BLayout (via BLayout::AddItem()) the nested BLayout inherits the target of the layout it's nested in, if it does not have a target already. You can retrieve the target view for a layout with the TargetView() method. When adding a BLayoutItem to a BLayout, the item's view (as returned by BLayoutItem::View()) is added to the BLayout's target view.
BView* topView = new BGroupView(); BLayout* topLayout = topView->GetLayout(); BLayout* nestedLayout = new BGroupLayout(B_HORIZONTAL); topLayout->AddItem(nestedLayout); BLayout* veryNestedLayout = new BGroupLayout(B_VERTICAL); nestedLayout->AddItem(veryNestedLayout);
After executing this code, veryNestedLayout, nestedLayout, and topLayout all have the same target view: topView.
Continuing with the same objects...
BLayout* nestedLayoutWithView = (new BGroupView())->GetLayout(); topLayout->AddItem(nestedLayoutWithView);
nestedLayoutWithView does have a target view of topView. This is because nestedLayoutWithView is attached directly to a BView.
| BLayout::BLayout | ( | ) |
| BLayout::BLayout | ( | BMessage * | archive | ) |
Archive constructor.
| archive | The archive message. |
| BLayout::~BLayout | ( | ) | [virtual] |
Destructor, deletes all BLayoutItem's that this layout manages, and detaches from this BLayout's owner view if there is one.
Destructor method.
Each BLayoutItem's BView (as returned by BLayoutItem::View()) is also removed from their parent.
Standard Destructor.
| bool BLayout::AddItem | ( | BLayoutItem * | item | ) | [virtual] |
Adds a BLayoutItem to this layout, and adds the BView it represents to this BLayout's target view.
| item | The BLayoutItem to be added. |
| true | success |
| false | failure |
Reimplemented in BGridLayout, and BGroupLayout.
| bool BLayout::AddItem | ( | int32 | index, |
| BLayoutItem * | item | ||
| ) | [virtual] |
Adds item to this layout, and adds the BView item represents to this BLayout's target view.
| item | The BLayoutItem to be added. |
| index | The index at which to add item. |
If index is out of bounds, item will be added at the end. If index is somewhere between the first and last indices, then items from index to the end will be shuffled over by one.
| true | success |
| false | failure |
Reimplemented in BGridLayout, and BGroupLayout.
| BLayoutItem * BLayout::AddView | ( | BView * | child | ) | [virtual] |
Creates a BLayoutItem to represent a BView, and adds that item to this layout.
child is added to this BLayout's target view.
NULL if there was an error.Reimplemented in BGridLayout, and BGroupLayout.
| BAlignment BLayoutItem::Alignment | ( | ) | [pure virtual, inherited] |
Returns the requested alignment for this item.
The value returned from this method is used in BLayoutItem::AlignInFrame(), which BLayouts use to position and resize items. In a vertical BGroupLayout, for example, although each item recieves the same horizontal area, each item can use that area differently, aligning to the left, right or center for example.
Implemented in BAbstractLayout.
Method relating to the use of BArchiver.
This hook function is called once the first BArchiver that was created in an archiving session is either destroyed, or has its Finish() method called. Implementations of this method can be used, in conjunction with BArchiver::IsArchived(), to reference objects in your archive that you do not own, depending on whether or not those objects were archived by their owners. Implementations of this method should call the implementation of their parent class, the same as for the Archive() method.
Reimplemented from BLayoutItem.
Reimplemented in BGridLayout, BTwoDimensionalLayout, BAbstractLayout, and BGroupLayout.
| bool BLayout::AncestorsVisible | ( | ) | const |
Get the visibility of the ancestors of this layout.
If a BLayout is connected to a BView, this will always return true. If a BLayout is nested in another layout (it was passed to AddItem()), then this will reflect the visibility of this BLayout's parent layout. If any layout is hidden (by BLayout::SetVisible()) between this layout and its target BView's layout, then this method will return false.
| void BLayout::DetachedFromLayout | ( | BLayout * | layout | ) | [protected, virtual] |
Hook method inherited from BLayoutItem, classes derived from BLayout must include the BLayout version of this method in their implementation.
Reimplemented from BLayoutItem.
Reimplemented in BAbstractLayout.
| BRect BLayoutItem::Frame | ( | ) | [pure virtual, inherited] |
Return the bounding frame of this item.
The returned BRect is in the coordinate system of the target view of the BLayout this item belongs to.
Implemented in BAbstractLayout.
| void BLayoutItem::GetHeightForWidth | ( | float | width, |
| float * | min, | ||
| float * | max, | ||
| float * | preferred | ||
| ) | [virtual, inherited] |
Get this BLayoutItem's height constraints for a given width.
If a BLayoutItem does not have height for width constraints (HasHeightForWidth() returns false) it does not need to implement this method.
NULL before dereferencing them. Reimplemented in BTwoDimensionalLayout.
| bool BLayoutItem::HasHeightForWidth | ( | ) | [virtual, inherited] |
Returns whether or not this BLayoutItem's height constraints are dependent on its width.
false. Reimplemented in BTwoDimensionalLayout.
| int32 BLayout::IndexOfItem | ( | const BLayoutItem * | item | ) | const |
Get the index of a BLayoutItem in this layout.
| item | The BLayoutItem whose index you want. |
| -1 | item was not found in this BLayout. |
| int32 BLayout::IndexOfView | ( | BView * | child | ) | const |
Get the index of child in this layout.
| static BArchivable * BArchivable::Instantiate | ( | BMessage * | archive | ) | [static, inherited] |
Static member to restore objects from messages.
You should always check that the archive argument actually corresponds to your class. The automatic functions, such as instantiate_object() and BUnarchiver::InstantiateObject() will not choose the wrong class but manual calls to this member might be faulty. You can verify that archive stores an object of your calss with the validate_instantiation() function.
| archive | The message with the data of the object to restore. |
| You | should return a pointer to the object you create with archive, or NULL if unarchival fails. |
NULL. Even though it is possible to store plain BArchivable objects, it is impossible to restore them.Reimplemented in BView, BCollator, BDirectWindow, BTextView, BBitmap, BGridLayout, BCursor, BAlert, BListView, BApplication, BLooper, BGroupLayout, BHandler, BColorControl, BDragger, BControl, BBox, BButton, BScrollView, and BCheckBox.
| void BLayout::InvalidateLayout | ( | bool | children = false | ) | [virtual] |
Invalidate this layout and any cached data this layout has relating to positioning and sizing of its items.
Invalidating a BLayout also invalidates the view it is connected to (if there is one) and the BLayout this layout (or this BLayout's view) resides in.
Although this method is virtual, you should not override it, override the BLayout::LayoutInvalidated() hook instead.
This method should be called whenever the layout becomes invalid. This might happen if the size constraints of an item in this layout change, this layout is given more or less space than it previously had, or an object in this layout has had its InvalidateLayout() method called.
Reimplemented from BLayoutItem.
| bool BLayoutItem::IsVisible | ( | ) | [pure virtual, inherited] |
Return the current local visibility of this item. If an item is not visible, it will not be given space by the BLayout it resides in.
A simple implementation would return the last thing passed to SetVisible(). A more complex implementation may deal with a BView that could be hidden in any number of ways.
Implemented in BAbstractLayout.
| bool BLayout::ItemAdded | ( | BLayoutItem * | item, |
| int32 | atIndex | ||
| ) | [protected, virtual] |
Hook method called when item is added to this layout.
| item | The BLayoutItem that is being added. |
| atIndex | The index of the BLayoutItem. |
| true | success |
| false | failure, item will not be added. |
Reimplemented in BGridLayout, BAbstractLayout, and BGroupLayout.
| status_t BLayout::ItemArchived | ( | BMessage * | into, |
| BLayoutItem * | item, | ||
| int32 | index | ||
| ) | const [protected, virtual] |
Hook for derived classes to add data specific to item to the into BMessage. item resides at index.
Reimplemented in BGridLayout, BTwoDimensionalLayout, BAbstractLayout, and BGroupLayout.
| void BLayout::ItemRemoved | ( | BLayoutItem * | item, |
| int32 | fromIndex | ||
| ) | [protected, virtual] |
Hook method called when item is removed from this layout.
| item | The BLayoutItem being removed. |
| fromIndex | The index where item used to reside. |
When this hook is called, item is not yet completely removed. It can no longer be accessed with LayoutItemAt(), nor does it contribute to the value of CountItems(), but the item has not yet had its ItemDetached() hook called.
Reimplemented in BGridLayout, BAbstractLayout, and BGroupLayout.
| status_t BLayout::ItemUnarchived | ( | const BMessage * | from, |
| BLayoutItem * | item, | ||
| int32 | index | ||
| ) | [protected, virtual] |
Hook for derived classes to retrieve data specific to item from the from BMessage. item resides at index.
Reimplemented in BGridLayout, BTwoDimensionalLayout, BAbstractLayout, and BGroupLayout.
| BRect BLayout::LayoutArea | ( | ) |
Returns the on-screen area this layout has received to lay out its items in.
The return value is in the coordinate space of this BLayout's target view. If this BLayout is attached directly to a BView, then LayoutArea().LeftTop() == B_ORIGIN .
| void * BLayoutItem::LayoutData | ( | ) | const [inherited] |
Retrieve arbitrary data attached to this BLayoutItem.
| virtual void BLayout::LayoutInvalidated | ( | bool | children | ) | [protected, virtual] |
Hook called from InvalidateLayout().
Override this method to clean out an cached layout info. It is good practice to recreate such info only on demand, eg when MinSize() or friends are called.
If children is true, then you should invalidate any information on child objects as well, and propagate the invalidation to them.
Reimplemented from BLayoutItem.
Reimplemented in BTwoDimensionalLayout, and BAbstractLayout.
| void BLayout::LayoutItems | ( | bool | force = false | ) |
If there is no layout currently ongoing, and force is false, creates a new BLayoutContext and calls the DoLayout() method of this BLayout and any BLayout s nested in this BLayout.
This method also guarantees that the owner view of this layout (as returned by BLayout::Owner()) performs a layout as well (if it is suitable to do so).
| force | Force the LayoutItems. |
| void BLayout::OwnerChanged | ( | BView * | was | ) | [protected, virtual] |
Hook method called when this layout is attached to a BView.
Reimplemented in BAbstractLayout.
| void BLayout::Relayout | ( | bool | immediate = false | ) | [virtual] |
Request this BLayout to reposition and resize its items as required.
If immediate is false, and there is already a request to have the window this layout resides in re-laid-out, then the layout will happen at that time. If immediate is true, and there is no such pending request, nor is this BLayout's parent layout in the process of laying out its items, then this BLayout will now layout its items.
| immediate | Whether or not to Relayout immediately or wait for pending requests first. |
Reimplemented from BLayoutItem.
| bool BLayout::RemoveItem | ( | BLayoutItem * | item | ) | [virtual] |
Removes a BLayoutItem from this layout, and also removes the view it represents from this BLayout's target view.
| item | The BLayoutItem to be removed |
| true | success |
| false | failure |
| BLayoutItem * BLayout::RemoveItem | ( | int32 | index | ) | [virtual] |
Remove the BLayoutItem at index.
| bool BLayout::RemoveView | ( | BView * | child | ) | [virtual] |
Removes and deletes all BLayoutItem representing a BView from this layout.
| child | The BView to be removed. |
| true | success |
| false | failure |
| void BLayoutItem::SetFrame | ( | BRect | frame | ) | [pure virtual, inherited] |
Set the bounding frame of this item.
frame is in the coordinate system of the target view of the BLayout that this item belongs to.
Implemented in BTwoDimensionalLayout, and BAbstractLayout.
| void BLayoutItem::SetLayoutData | ( | void * | data | ) | [inherited] |
Attach arbitrary data to this BLayoutItem.
| BView * BLayout::TargetView | ( | ) | const |
Returns the target view of this layout.
The target view of a layout becomes the parent of any BView's in this layout, as well as the BView's returned by BLayoutItem::View() for each BLayoutItem in this layout.
| void BLayout::VisibilityChanged | ( | bool | show | ) | [protected] |
Method to be called by derived classes in their SetVisible() implementation. Calls AncestorVisibilityChanged() on the items in this BLayout.
| show | true to show, false to hide. |