Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | List of all members
BLayoutItem Class Referenceabstract

Abstract class representing things that are positionable and resizable by objects of the BLayout class. More...

Inherits BArchivable.

Inherited by BAbstractLayoutItem, BLayout, and BSpaceLayoutItem.

Public Member Functions

 BLayoutItem (BMessage *from)
 Archive constructor.
 
virtual status_t Archive (BMessage *into, bool deep=true) const
 Archive the object into a BMessage.
 
BLayoutLayout () 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).
 
bool RemoveSelf ()
 Remove this layout item from the BLayout it is a part of.
 
virtual BViewView ()
 Return the BView this item is representing, or NULL if it does not represent any view.
 
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 and Alignment Constraints

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.

Since
Haiku R1
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().
 
void SetExplicitSize (BSize size)
 Set the explicity size to size.
 
virtual void SetExplicitAlignment (BAlignment alignment)=0
 Set this item's explicit alignment, to be used in Alignment().
 
Getting/Setting the Visibility 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/Setting 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.
 
Layout Events and Requests

These methods represent events or requests originating from a BLayout. In some implementations they may be handled directly by this BLayoutItem, but many implementations will forward these events to another object.

virtual void InvalidateLayout (bool children=false)
 Invalidate the layout of this item, or the object it represents.
 
virtual void Relayout (bool immediate=false)
 Relayout any children or onscreen data this item contains. Often this request is forwarded to another object.
 
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.
 
- Public Member Functions inherited from BArchivable
 BArchivable ()
 Constructor. Does nothing.
 
 BArchivable (BMessage *from)
 Constructor. Does important behind-the-scenes work in the unarchiving process.
 
virtual ~BArchivable ()
 Destructor. Does nothing.
 
virtual status_t AllArchived (BMessage *archive) const
 Method relating to the use of BArchiver.
 
virtual status_t AllUnarchived (const BMessage *archive)
 Method relating to the use of BUnarchiver.
 
virtual status_t Archive (BMessage *into, bool deep=true) const
 Archive the object into a BMessage.
 
virtual status_t Perform (perform_code d, void *arg)
 Perform some action (Internal method defined for binary compatibility purposes).
 

Protected Member Functions

virtual status_t AllArchived (BMessage *into) const
 Method relating to the use of BArchiver.
 
virtual status_t AllUnarchived (const BMessage *from)
 Method relating to the use of BUnarchiver.
 
Hook methods
virtual void LayoutInvalidated (bool children)
 Hook called from InvalidateLayout().
 
virtual void AttachedToLayout ()
 Hook called when this object is attached to a BLayout (via BLayout::AddItem())
 
virtual void DetachedFromLayout (BLayout *layout)
 Hook called when this object is attached to a BLayout (via BLayout::RemoveItem())
 
virtual void AncestorVisibilityChanged (bool shown)
 Hook called when this BLayoutItem's ancestors change visibility, effectively hiding or showing this item.
 

Additional Inherited Members

- Static Public Member Functions inherited from BArchivable
static BArchivableInstantiate (BMessage *archive)
 Static member to restore objects from messages.
 

Detailed Description

Abstract class representing things that are positionable and resizable by objects of the BLayout class.

The BLayoutItem class provides an interface that is meant to be used almost exclusively by objects of the BLayout class. Despite this, there are some methods that are provided for other users of the class.

Warning
This class is not yet finalized, if you use it in your software assume that it will break some time in the future.
Since
Haiku R1

Constructor & Destructor Documentation

◆ BLayoutItem()

BLayoutItem::BLayoutItem ( BMessage archive)

Archive constructor.

Creates a BLayoutItem from the archive message.

Since
Haiku R1

Member Function Documentation

◆ AlignInFrame()

void BLayoutItem::AlignInFrame ( BRect  frame)

Position this BLayoutItem within frame, given the value returned by Alignment(), and the size constraints for this item.

Since
Haiku R1

◆ Alignment()

BAlignment BLayoutItem::Alignment ( )
pure virtual

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.

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ AllArchived()

virtual status_t BLayoutItem::AllArchived ( BMessage into) const
protectedvirtual

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.

Warning
To guarantee that your AllArchived() method will be called during archival, you must create a BArchiver object in your Archive() implementation.
You should archive any objects you own in your Archive() method implementation, and NOT your AllArchived() method.
See also
BArchiver BArchiver::Finish()
Since
Haiku R1

Reimplemented from BArchivable.

Reimplemented in BAbstractLayout, BCardLayout, BLayout, BGridLayout, BGroupLayout, and BTwoDimensionalLayout.

◆ AllUnarchived()

virtual status_t BLayoutItem::AllUnarchived ( const BMessage archive)
protectedvirtual

Method relating to the use of BUnarchiver.

This hook function is called triggered in the BUnarchiver::Finish() method. In this method, you can rebuild references to objects that may be direct children of your object, or may be children of other objects. Implementations of this method should call the implementation of their parent class, the same as for the Archive() method.

Warning
To guarantee that your AllUnarchived() method will be called during unarchival, you must create a BUnarchiver object in your archive constructor.
See also
BUnarchiver, BUnarchiver::Finish()
Since
Haiku R1

Reimplemented from BArchivable.

Reimplemented in BAbstractLayout, BCardLayout, BGridLayout, BGroupLayout, BLayout, and BTwoDimensionalLayout.

◆ AncestorVisibilityChanged()

void BLayoutItem::AncestorVisibilityChanged ( bool  shown)
protectedvirtual

Hook called when this BLayoutItem's ancestors change visibility, effectively hiding or showing this item.

Implementations of this method should alter the onscreen visibility of this item. I.E. if shown is false, nothing should be drawn to represent this item.

Note
This method should not effect the value returned by this object's IsVisible() method.
Parameters
showntrue to show, false to hide.
Since
Haiku R1

Reimplemented in BAbstractLayout, and BLayout.

◆ Archive()

virtual status_t BLayoutItem::Archive ( BMessage into,
bool  deep = true 
) const
virtual

Archive the object into a BMessage.

You should call this method from your derived implementation as it adds the data needed to instantiate your object to the message.

Parameters
intoThe message you store your object in.
deepIf true, all children of this object should be archived as well.
Return values
B_OKThe archive operation was successful.
B_BAD_VALUENULL archive message.
B_ERRORThe archive operation failed.
Since
BeOS R3

Reimplemented from BArchivable.

Reimplemented in BAbstractLayout, BCardLayout, BGridLayout, BGroupLayout, BLayout, BSpaceLayoutItem, and BTwoDimensionalLayout.

◆ AttachedToLayout()

void BLayoutItem::AttachedToLayout ( )
protectedvirtual

Hook called when this object is attached to a BLayout (via BLayout::AddItem())

Note
You can find the BLayout you've been attached to with the Layout() method.
Since
Haiku R1

Reimplemented in BAbstractLayout, and BLayout.

◆ DetachedFromLayout()

void BLayoutItem::DetachedFromLayout ( BLayout layout)
protectedvirtual

Hook called when this object is attached to a BLayout (via BLayout::RemoveItem())

Warning
You should not use this hook to reattach this to BLayout, doing so will cause undefined behaviour (probably a crash).
Parameters
layoutThe BLayout you were previously attached to.
Since
Haiku R1

Reimplemented in BAbstractLayout, and BLayout.

◆ Frame()

BRect BLayoutItem::Frame ( )
pure virtual

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.

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ GetHeightForWidth()

void BLayoutItem::GetHeightForWidth ( float  width,
float *  min,
float *  max,
float *  preferred 
)
virtual

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.

Note
It is prudent to compare min, max, preferred to NULL before dereferencing them.
Since
Haiku R1

Reimplemented in BCardLayout, and BTwoDimensionalLayout.

◆ HasHeightForWidth()

bool BLayoutItem::HasHeightForWidth ( )
virtual

Returns whether or not this BLayoutItem's height constraints are dependent on its width.

Note
By default, this method returns false.
Since
Haiku R1

Reimplemented in BCardLayout, and BTwoDimensionalLayout.

◆ InvalidateLayout()

void BLayoutItem::InvalidateLayout ( bool  children = false)
virtual

Invalidate the layout of this item, or the object it represents.

Although this method is virtual, you should not override it in your classes, override LayoutInvalidated() instead. This method will take care of calling the InvalidateLayout() methods of affected views/layouts/items. However, if there is an object that is somehow connected to this one by means other than the standard mechanisms provided by the Haiku API, you should use the LayoutInvalidated() hook to do this.

Parameters
childrenWhether or not to invalidate children of this object.
Since
Haiku R1

Reimplemented in BLayout.

◆ IsVisible()

bool BLayoutItem::IsVisible ( )
pure virtual

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.

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ Layout()

BLayout * BLayoutItem::Layout ( ) const

Returns the BLayout this BLayoutItem resides in.

Since
Haiku R1

◆ LayoutData()

void * BLayoutItem::LayoutData ( ) const

Retrieve arbitrary data attached to this BLayoutItem.

Note
This method should only be called by a BLayout subclass.
Since
Haiku R1

◆ LayoutInvalidated()

void BLayoutItem::LayoutInvalidated ( bool  children)
protectedvirtual

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.

Since
Haiku R1

Reimplemented in BAbstractLayout, BLayout, BCardLayout, and BTwoDimensionalLayout.

◆ MaxSize()

BSize BLayoutItem::MaxSize ( )
pure virtual

Returns the maximum desirable size for this item.

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ MinSize()

BSize BLayoutItem::MinSize ( )
pure virtual

Returns the minimum desirable size for this item.

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ Perform()

virtual status_t BLayoutItem::Perform ( perform_code  d,
void *  arg 
)
virtual

Perform some action (Internal method defined for binary compatibility purposes).

Reimplemented from BArchivable.

Reimplemented in BAbstractLayout, BCardLayout, BGridLayout, BGroupLayout, BLayout, and BTwoDimensionalLayout.

◆ PreferredSize()

BSize BLayoutItem::PreferredSize ( )
pure virtual

Returns the preferred size for this item.

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ Relayout()

void BLayoutItem::Relayout ( bool  immediate = false)
virtual

Relayout any children or onscreen data this item contains. Often this request is forwarded to another object.

The default implementation of this method will likely be sufficient in most cases. Assuming this->View() doesn't return NULL, the default implementation calls Relayout() or Layout() on the value returned by View().

Since
Haiku R1

Reimplemented in BLayout.

◆ RemoveSelf()

bool BLayoutItem::RemoveSelf ( )

Remove this layout item from the BLayout it is a part of.

This method works analoguous to BView::RemoveSelf(), that is it removes itself from the parent layout and returns whether or not this was succesful.

Returns
true if the item was removed from the layout, or false if item was not part of a layout, or removal was succesful.
Since
Haiku R1

◆ SetExplicitAlignment()

void BLayoutItem::SetExplicitAlignment ( BAlignment  alignment)
pure virtual

Set this item's explicit alignment, to be used in Alignment().

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

Referenced by BLayoutBuilder::Grid< ParentBuilder >::AddMenuField(), and BLayoutBuilder::Grid< ParentBuilder >::AddTextControl().

◆ SetExplicitMaxSize()

void BLayoutItem::SetExplicitMaxSize ( BSize  size)
pure virtual

Set this item's explicit max size, to be used in MaxSize().

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ SetExplicitMinSize()

void BLayoutItem::SetExplicitMinSize ( BSize  size)
pure virtual

Set this item's explicit min size, to be used in MinSize().

This forces the minimal size for the item and overrides any constraints that would normally be used to compute it. Most importantly, the minimal size of children is ignored, so setting this can lead to the children not fitting the view.

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ SetExplicitPreferredSize()

void BLayoutItem::SetExplicitPreferredSize ( BSize  size)
pure virtual

Set this item's explicit preferred size, to be used in PreferredSize().

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ SetExplicitSize()

void BLayoutItem::SetExplicitSize ( BSize  size)

Set the explicity size to size.

This method is a convenience method that sets the minimum size, maximum size and preferred size to size, as to force this layout item to have a specific size.

Parameters
sizeThe specific (non-zero) size for this layout item.
Since
Haiku R1

◆ SetFrame()

void BLayoutItem::SetFrame ( BRect  frame)
pure virtual

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.

Since
Haiku R1

Implemented in BAbstractLayout, BSpaceLayoutItem, and BTwoDimensionalLayout.

◆ SetLayoutData()

void BLayoutItem::SetLayoutData ( void *  data)

Attach arbitrary data to this BLayoutItem.

Note
This method should only be called by a BLayout subclass.
Since
Haiku R1

◆ SetVisible()

void BLayoutItem::SetVisible ( bool  visible)
pure virtual

Set the local visibility of this item.

Since
Haiku R1

Implemented in BAbstractLayout, and BSpaceLayoutItem.

◆ View()

BView * BLayoutItem::View ( )
virtual

Return the BView this item is representing, or NULL if it does not represent any view.

When a BLayoutItem is added to a BLayout, this method is called, and the returned BView will be added to the BLayout's target view.

Since
Haiku R1

Reimplemented in BLayout.