Public Member Functions | Static Public Member Functions | List of all members
GridLayout Class Reference

The GridLayout class lays out controls in a table or grid. More...

#include <GridLayout.h>

Inheritance diagram for GridLayout:
LayoutManager LayoutItem RefCounted< IRefCounted > IRefCounted

Public Member Functions

void SetHorizontalSpacing (int spacing)
 Sets the horizontal spacing between items in the layout. More...
 
int GetHorizontalSpacing () const
 Returns the horizontal spacing between items in the layout. More...
 
void SetVerticalSpacing (int spacing)
 Sets the vertical spacing between rows in the layout. More...
 
int GetVerticalSpacing () const
 Returns the vertical spacing between rows in the layout. More...
 
void SetSpacing (int spacing)
 Sets the horizontal and vertical spacing between items in the layout. More...
 
int GetSpacing () const
 Gets the spacing between items in the layout. More...
 
int GetRowStretch (int row) const
 Returns the stretch factor for the given row. More...
 
void SetRowStretch (int row, int stretch)
 Sets the stretch factor for the given row. More...
 
int GetColumnStretch (int column) const
 Returns the stretch factor for the given column. More...
 
void SetColumnStretch (int column, int stretch)
 Sets the stretch factor for the given column. More...
 
int GetRowMinimumHeight (int row) const
 Returns the minimum height for the given row. More...
 
void SetRowMinimumHeight (int row, int minHeight)
 Sets the minimum height for the given row. More...
 
int GetColumnMinimumWidth (int column) const
 Returns the minimum width for the given column. More...
 
void SetColumnMinimumWidth (int column, int minWidth)
 Sets the minimum width for the given column. More...
 
StatusInt SetColumnSharedSizeGroup (int column, WCharCP groupName)
 Sets the SharedSizeGroup name for the given column. More...
 
int GetColumnCount () const
 Returns the number of columns. More...
 
int GetRowCount () const
 Returns the number of rows. More...
 
BRect GetCellRect (int row, int column) const
 Retrieves the bounding rectangle of the cell specified by the given row index and column index. More...
 
void AddControl (LayoutControl *ctl, int row, int column, LayoutAlignment alignment=Align_None)
 Adds a control to the GridLayout Layout Manager. More...
 
void AddControl (LayoutControl *ctl, int row, int column, int rowSpan, int columnSpan, LayoutAlignment alignment=Align_None)
 Adds a control to the GridLayout Layout Manager. More...
 
void AddLayout (LayoutManager *layout, int row, int column, LayoutAlignment alignment=Align_None)
 Adds a child LayoutManager to the GridLayout Layout Manager. More...
 
void AddLayout (LayoutManager *layout, int row, int column, int rowSpan, int columnSpan, LayoutAlignment alignment=Align_None)
 Adds a child LayoutManager to the GridLayout Layout Manager. More...
 
void SetDefaultPositioning (int n, LayoutOrientation orient)
 
void GetItemPosition (int index, int *row, int *column, int *rowSpan, int *columnSpan)
 Returns information about the item at a given index. More...
 
LayoutItemItemAtPosition (int row, int column) const
 Returns the LayoutItem associated with a given row and column. More...
 
virtual void Invalidate () override
 Resets the layout's rectangle then calls Update() More...
 
virtual void SetDirty () override
 Resets the layout's rectangle then calls Update() More...
 
virtual BSize GetDesiredSize () const override
 Returns the desired size for this layout item. More...
 
virtual BSize GetMinimumSize () const override
 Returns the minimum size for this layout item. More...
 
virtual BSize GetMaximumSize () const override
 Returns the maximum size for this layout item. More...
 
virtual bool HasHeightForWidth () const override
 Returns whether this layout's preferred height depends on its width. More...
 
virtual int GetHeightForWidth (int width) const override
 Returns the preferred height for this layout item, given the width. More...
 
virtual int GetMinimumHeightForWidth (int width) const override
 Returns the minimum height for this layout item, given the width. More...
 
virtual void SetGeometry (const BRect &rect) override
 Sets the geometry for this layout item to the given rectangle. More...
 
virtual LayoutOrientations GetExpandingOrientations () const
 Returns whether this layout item can make use of more space than GetDesiredSize(). More...
 
virtual size_t Count () const override
 Returns the number of items in this layout. More...
 
virtual LayoutItemItemAt (int index) const override
 Retrieves the item at index in the layout and returns the item. More...
 
virtual LayoutItemTakeAt (int index) override
 Removes the item at index from the layout, and returns the item. More...
 
- Public Member Functions inherited from LayoutManager
virtual void AddItem (LayoutItem *item)=0
 Adds a LayoutItem to this Layout Manager. More...
 
virtual int IndexOf (LayoutControl *ctl) const
 Searches for the control in this layout (not including child layouts). More...
 
virtual int IndexOf (LayoutItem *item) const
 Searches for the LayoutItem in this layout (not including child layouts). More...
 
void WindowSizeDoLayout (const BSize &size)
 Notifies this LayoutManager that the Window size has changed and all child items should be laid out accordingly. More...
 
void VisibleDoLayout ()
 Notifies this LayoutManager that the layout has changed visibility and all child items should be laid out accordingly. More...
 
void ItemSizeDoLayout ()
 Notifies this LayoutManager that a child has changed size and all child items should be laid out accordingly. More...
 
LayoutManagerGetMainLayout ()
 Retrieves the main LayoutManager associated with this Layout Manager. More...
 
LayoutManagerGetSharedSizeGroupBoundary ()
 Retrieves the next Shared Size Group Boundary associated with this Layout Manager. More...
 
LayoutManagerGetParentLayout () const
 Retrieves the parent LayoutManager associated with this Layout Manager. More...
 
void SetParentLayout (LayoutManager *)
 Sets the parent LayoutManager for this Layout Manager. More...
 
LayoutControlGetParentControl () const
 Retrieves the parent LayoutControl associated with this Layout Manager. More...
 
void SetParentControl (LayoutControl *)
 Sets the parent LayoutControl for this Layout Manager. More...
 
int GetMargin () const
 Retrieves the margin for the LayoutManager, but only if all 4 margins are the same. Otherwise, -1 is returned. More...
 
void SetMargin (int margin)
 Sets the 4 margins for the LayoutManager to the same value. More...
 
void SetLayoutMargins (int left, int top, int right, int bottom)
 Sets the 4 margins for the LayoutManager. More...
 
void SetLayoutMargins (const Margins &margins)
 Sets the margins for the LayoutManager. More...
 
void GetLayoutMargins (int *left, int *top, int *right, int *bottom) const
 Gets the 4 margins for the LayoutManager. More...
 
Margins GetLayoutMargins () const
 Gets the 4 margins for the LayoutManager. More...
 
BRect GetContentsRect () const
 Gets the bounding rectangle for the contents in the LayoutManager. More...
 
bool SetAlignment (LayoutControl *ctl, LayoutAlignment alignment)
 Sets the alignment for a child control. More...
 
bool SetAlignment (LayoutManager *layout, LayoutAlignment alignment)
 Sets the alignment for a child layout. More...
 
bool Activate ()
 Invalidates the layout item then updates it. More...
 
void Update ()
 Invalidates the layout item without updating it. More...
 
void RemoveControl (LayoutControl *ctl)
 Removes a child control. More...
 
void RemoveItem (LayoutItem *item)
 Removes a child item. More...
 
int GetTotalHeightForWidth (int width) const
 Retrieves the required height for a given width. More...
 
BSize GetTotalMinimumSize () const
 Retrieves the total minimum size for the layout. More...
 
BSize GetTotalMaximumSize () const
 Retrieves the total maximum size for the layout. More...
 
BSize GetTotalDesiredSize () const
 Retrieves the total desired size for the layout. More...
 
void SetEnabled (bool)
 Sets whether the layout is enabled. More...
 
bool IsEnabled () const
 Determines whether the layout is enabled. More...
 
void SetTopLevel (bool)
 Sets whether the layout is top-level. More...
 
bool IsTopLevel () const
 Determines whether the layout is top-level. More...
 
void SetSharedSizeGroupBoundary (bool)
 Sets whether the layout is a Shared Group Boundary. More...
 
bool IsSharedSizeGroupBoundary () const
 Determines whether the layout is a Shared Group Boundary. More...
 
virtual bool IsEmpty () const override
 Returns whether the layout item is empty. More...
 
virtual bool IsVisible () const override
 Returns whether the layout item is visible. More...
 
virtual BRect GetGeometry () const override
 Retrieves the geometry for this layout item. More...
 
virtual LayoutManagerGetLayout () override
 If the concrete item is a LayoutManager, it can be retrieved using GetLayout(). More...
 
- Public Member Functions inherited from LayoutItem
virtual BSize GetSize () const
 Returns the geometry's size for this layout item. More...
 
virtual LayoutControlGetControl ()
 If the concrete item is a LayoutControl, it can be retrieved using GetControl(). More...
 
LayoutAlignment GetAlignment () const
 Returns the alignment within the layout for this layout item. More...
 
void SetAlignment (LayoutAlignment alignment)
 Sets the alignment within the layout for this layout item. More...
 
- Public Member Functions inherited from RefCounted< IRefCounted >
void * operator new (size_t size)
 
void operator delete (void *rawMemory, size_t size)
 
UInt32 AddRef () const
 
UInt32 Release () const
 
 RefCounted ()
 
 RefCounted (RefCounted const &rhs)
 
RefCountedoperator= (RefCounted const &rhs)
 
UInt32 GetRefCount () const
 

Static Public Member Functions

static GridLayoutCreate (LayoutControl *parent=0)
 Creates a GridLayout Layout Manager. More...
 

Additional Inherited Members

- Protected Member Functions inherited from RefCounted< IRefCounted >
virtual ~RefCounted ()
 
- Protected Member Functions inherited from IRefCounted
virtual ~IRefCounted ()
 
void * operator new (size_t size)
 
void operator delete (void *rawMemory, size_t size)
 

Detailed Description

The GridLayout class lays out controls in a table or grid.

GridLayout takes the space made available to it (by its parent layout or by the parent control), divides it up into rows and columns, and puts each control it manages into the correct cell.

Columns and rows behave identically and there are equivalent functions columns and rows.

Each column has a minimum width and a stretch factor. The minimum width is the greatest of that set using SetColumnMinimumWidth() and the minimum width of each control in that column. The stretch factor is set using SetColumnStretch() and determines how much of the available space the column will get over and above its necessary minimum.

Normally, each managed control or layout is put into a cell of its own using AddControl(). It is also possible for a control to occupy multiple cells using the row and column spanning overloads of AddItem() and AddControl(). If you do this, GridLayout will guess how to distribute the size over the columns/rows (based on the stretch factors).

To remove a control from a layout, call RemoveControl(). Calling LayoutControl::Hide() on a control also effectively removes the control from the layout until LayoutControl::Show() is called.

If you want two or more columns to have the same width, you must set their minimum widths and stretch factors to be the same yourself. You do this using SetColumnMinimumWidth() and SetColumnStretch().

If the GridLayout is not the top-level layout (i.e. does not manage all of the control's area and children), you must add it to its parent layout when you create it, but before you do anything with it. The normal way to add a layout is by calling AddLayout() on the parent layout.

Once you have added your layout you can start putting controls and other layouts into the cells of your grid layout using AddControl(), AddItem(), and AddLayout().

GridLayout includes two margin width functions: the GetLayoutMargins() and the GetSpacing(). The contents margin is the width of the reserved space along each of the GridLayout's four sides. The spacing is the width of the automatically allocated spacing between neighboring boxes.

The default contents margin values are 0. The spacing defaults to the same as the margin width for a top-level layout, or to the same as the parent layout.

Member Function Documentation

void AddControl ( LayoutControl ctl,
int  row,
int  column,
LayoutAlignment  alignment = Align_None 
)

Adds a control to the GridLayout Layout Manager.

Parameters
[in]ctlThe LayoutControl being added to the layout.
[in]rowThe index of the row being added.
[in]columnThe index of the column being added.
[in]alignmentThe alignment to use for the control being added.
void AddControl ( LayoutControl ctl,
int  row,
int  column,
int  rowSpan,
int  columnSpan,
LayoutAlignment  alignment = Align_None 
)

Adds a control to the GridLayout Layout Manager.

Parameters
[in]ctlThe LayoutControl being added to the layout.
[in]rowThe beginning index of the row being added.
[in]columnThe beginning index of the column being added.
[in]rowSpanThe number of rows the control will span.
[in]columnSpanThe number of columns the control will span.
[in]alignmentThe alignment to use for the control being added.
void AddLayout ( LayoutManager layout,
int  row,
int  column,
LayoutAlignment  alignment = Align_None 
)

Adds a child LayoutManager to the GridLayout Layout Manager.

Parameters
[in]layoutThe LayoutManager being added as a child to the layout.
[in]rowThe index of the row being added.
[in]columnThe index of the column being added.
[in]alignmentThe alignment to use for the layout being added.
void AddLayout ( LayoutManager layout,
int  row,
int  column,
int  rowSpan,
int  columnSpan,
LayoutAlignment  alignment = Align_None 
)

Adds a child LayoutManager to the GridLayout Layout Manager.

Parameters
[in]layoutThe LayoutManager being added as a child to the layout.
[in]rowThe beginning index of the row being added.
[in]columnThe beginning index of the column being added.
[in]rowSpanThe number of rows the control will span.
[in]columnSpanThe number of columns the control will span.
[in]alignmentThe alignment to use for the layout being added.
virtual size_t Count ( ) const
overridevirtual

Returns the number of items in this layout.

Implements LayoutManager.

static GridLayout* Create ( LayoutControl parent = 0)
static

Creates a GridLayout Layout Manager.

Parameters
[in]parentThe parent LayoutControl
Returns
A pointer to the new GridLayout object.
BRect GetCellRect ( int  row,
int  column 
) const

Retrieves the bounding rectangle of the cell specified by the given row index and column index.

Parameters
[in]rowThe index of the row for which to get the cell rectangle.
[in]columnThe index of the column for which to get the cell rectangle.
int GetColumnCount ( ) const

Returns the number of columns.

int GetColumnMinimumWidth ( int  column) const

Returns the minimum width for the given column.

Parameters
[in]columnThe index of the column for which to get the minimum width.
int GetColumnStretch ( int  column) const

Returns the stretch factor for the given column.

Parameters
[in]columnThe index of the column for which to get the stretch factor.
virtual BSize GetDesiredSize ( ) const
overridevirtual

Returns the desired size for this layout item.

Implements LayoutItem.

virtual LayoutOrientations GetExpandingOrientations ( ) const
virtual

Returns whether this layout item can make use of more space than GetDesiredSize().

A value of LO_Vertical or LO_Horizontal means that it wants to grow in only one dimension, whereas LO_Vertical | LO_Horizontal means that it wants to grow in both dimensions.

Reimplemented from LayoutManager.

virtual int GetHeightForWidth ( int  width) const
overridevirtual

Returns the preferred height for this layout item, given the width.

Parameters
[in]widthThe width for which to retrieve the preferred height.

Reimplemented from LayoutItem.

int GetHorizontalSpacing ( ) const

Returns the horizontal spacing between items in the layout.

void GetItemPosition ( int  index,
int *  row,
int *  column,
int *  rowSpan,
int *  columnSpan 
)

Returns information about the item at a given index.

Parameters
[in]indexThe index of the item for which to get the information
[out]rowThe initial row occupied by the item
[out]columnThe initial column occupied by the item
[out]rowSpanThe number of rows spanned by the item
[out]columnSpanThe number of columns spanned by the item
virtual BSize GetMaximumSize ( ) const
overridevirtual

Returns the maximum size for this layout item.

Reimplemented from LayoutManager.

virtual int GetMinimumHeightForWidth ( int  width) const
overridevirtual

Returns the minimum height for this layout item, given the width.

Parameters
[in]widthThe width for which to retrieve the minimum height.

Reimplemented from LayoutItem.

virtual BSize GetMinimumSize ( ) const
overridevirtual

Returns the minimum size for this layout item.

Reimplemented from LayoutManager.

int GetRowCount ( ) const

Returns the number of rows.

int GetRowMinimumHeight ( int  row) const

Returns the minimum height for the given row.

Parameters
[in]rowThe index of the row for which to get the minimum height.
int GetRowStretch ( int  row) const

Returns the stretch factor for the given row.

Parameters
[in]rowThe index of the row for which to get the stretch factor.
int GetSpacing ( ) const
virtual

Gets the spacing between items in the layout.

If the vertical spacing is equal to the horizontal spacing, this function returns that value; otherwise it return -1.

Reimplemented from LayoutManager.

int GetVerticalSpacing ( ) const

Returns the vertical spacing between rows in the layout.

virtual bool HasHeightForWidth ( ) const
overridevirtual

Returns whether this layout's preferred height depends on its width.

For GridLayout, it depends on whether the layout items in the rows and columns have a height for width.

Reimplemented from LayoutItem.

virtual void Invalidate ( )
overridevirtual

Resets the layout's rectangle then calls Update()

Reimplemented from LayoutManager.

virtual LayoutItem* ItemAt ( int  index) const
overridevirtual

Retrieves the item at index in the layout and returns the item.

If there is no such item, the function returns NULL.

Parameters
[in]indexThe index of the item to retrieve. Items are numbered consecutively from 0.

Implements LayoutManager.

LayoutItem* ItemAtPosition ( int  row,
int  column 
) const

Returns the LayoutItem associated with a given row and column.

Parameters
[out]rowThe row for which to retrieve the LayoutItem
[out]columnThe column for which to retrieve the LayoutItem
void SetColumnMinimumWidth ( int  column,
int  minWidth 
)

Sets the minimum width for the given column.

Parameters
[in]columnThe index of the column for which to set the minimum width
[in]minWidthThe new minimum width for the given row
StatusInt SetColumnSharedSizeGroup ( int  column,
WCharCP  groupName 
)

Sets the SharedSizeGroup name for the given column.

Parameters
[in]columnThe index of the column for which to set the SharedSizeGroup name
[in]groupNameThe name of the SharedSizeGroup
Remarks
A SharedSizeGroup allows columns to automatically have the same size across multiple GridLayouts on a dialog. When defining the columns for a GridLayout, a Shared Size Group name can be specified for each column. When multiple GridLayouts in a dialog contain columns that have the same Shared Size Group name, those columns will share sizing properties. The widest minimum and desired column sizes from the multiple GridLayouts will be used for each column in the group, resulting in consistent column widths across GridLayout boundaries.
void SetColumnStretch ( int  column,
int  stretch 
)

Sets the stretch factor for the given column.

Parameters
[in]columnThe index of the column for which to set the stretch factor
[in]stretchThe new stretch factor for the given column
void SetDefaultPositioning ( int  n,
LayoutOrientation  orient 
)
virtual void SetDirty ( )
overridevirtual

Resets the layout's rectangle then calls Update()

Reimplemented from LayoutManager.

virtual void SetGeometry ( const BRect rect)
overridevirtual

Sets the geometry for this layout item to the given rectangle.

Parameters
[in]rectThe rectangle of the new geometry for the layout item.

Reimplemented from LayoutManager.

void SetHorizontalSpacing ( int  spacing)

Sets the horizontal spacing between items in the layout.

Parameters
[in]spacingThe amount of space between items in the layout.
void SetRowMinimumHeight ( int  row,
int  minHeight 
)

Sets the minimum height for the given row.

Parameters
[in]rowThe index of the row for which to set the minimum height
[in]minHeightThe new minimum height for the given row
void SetRowStretch ( int  row,
int  stretch 
)

Sets the stretch factor for the given row.

Parameters
[in]rowThe index of the row for which to set the stretch factor
[in]stretchThe new stretch factor for the given row
void SetSpacing ( int  spacing)
virtual

Sets the horizontal and vertical spacing between items in the layout.

Parameters
[in]spacingThe amount of space between items in the layout.

Reimplemented from LayoutManager.

void SetVerticalSpacing ( int  spacing)

Sets the vertical spacing between rows in the layout.

Parameters
[in]spacingThe amount of space between rows in the layout.
virtual LayoutItem* TakeAt ( int  index)
overridevirtual

Removes the item at index from the layout, and returns the item.

If there is no such item, the function does nothing and returns NULL.

Parameters
[in]indexThe index of the item to remove. Items are numbered consecutively from 0.

Implements LayoutManager.


The documentation for this class was generated from the following file:

Copyright © 2017 Bentley Systems, Incorporated. All rights reserved.