Wt::WContainerWidget Class Reference

A widget that holds and manages child widgets. More...

#include <Wt/WContainerWidget>

Inherits Wt::WInteractWidget.

Inherited by Wt::Ext::Splitter, Wt::Impl::MapWidget, Wt::WAnchor, Wt::WFlashObject, Wt::WGroupBox, Wt::WOverlayLoadingIndicator, Wt::WStackedWidget, and Wt::WTableCell.

List of all members.

Public Types

enum  Overflow { OverflowVisible = 0x0, OverflowAuto = 0x1, OverflowHidden = 0x2, OverflowScroll = 0x3 }
 

How to handle overflow of inner content.

More...

Public Member Functions

 WContainerWidget (WContainerWidget *parent=0)
 Creates a container with optional parent.
 ~WContainerWidget ()
 Destructor.
void setLayout (WLayout *layout)
 Sets a layout manager for the container.
void setLayout (WLayout *layout, WFlags< AlignmentFlag > alignment)
 Sets a layout manager for the container.
WLayoutlayout ()
 Returns the layout manager that was set for the container.
virtual void addWidget (WWidget *widget)
 Adds a child widget to this container.
virtual void insertBefore (WWidget *widget, WWidget *before)
 Inserts a child widget in this container, before another widget.
virtual void insertWidget (int index, WWidget *widget)
 Inserts a child widget in this container at given index.
virtual void removeWidget (WWidget *widget)
 Removes a child widget from this container.
virtual void clear ()
 Removes and deletes all child widgets.
virtual int indexOf (WWidget *widget) const
 Returns the index of a widget.
virtual WWidgetwidget (int index) const
 Returns the widget at index
virtual int count () const
 Returns the number of widgets in this container.
void setContentAlignment (WFlags< AlignmentFlag > contentAlignment)
 Specifies how child widgets must be aligned within the container.
void setPadding (const WLength &padding, WFlags< Side > sides=All)
 Sets padding inside the widget.
WLength padding (Side side) const
 Returns the padding set for the widget.
WFlags< AlignmentFlagcontentAlignment () const
 Returns the alignment of children.
void setOverflow (Overflow overflow, WFlags< Orientation > orientation=(Horizontal|Vertical))
 Sets how overflow of contained children must be handled.
void setList (bool list, bool ordered=false)
 Renders the container as an HTML list.
bool isList () const
 Returns if this container is rendered as a List.
bool isUnorderedList () const
 Returns if this container is rendered as an Unordered List.
bool isOrderedList () const
 Returns if this container is rendered as an Ordered List.
EventSignal< WScrollEvent > & scrolled ()
 Event signal emitted when scrolling in the widget.

Detailed Description

A widget that holds and manages child widgets.

A WContainerWidget acts as a container for child widgets. Child widgets may be added directly to the container or using a layout manager.

Use addWidget() or pass the container as constructor argument to a widget to directly add children to the container, without using a layout manager. In that case, CSS-based layout is used, and the resulting display is determined by properties of the children and the container. By default, a WContainerWidget is displayed as a block and manages its children within a rectangle. Inline child widgets are layed out in lines, wrapping around as needed, while block child widgets are stacked vertically. The container may add padding at the container edges using setPadding(), and provide alignment of contents using setContentAlignment(). A container is rendered by default using a HTML div tag, but this may be changed to an HTML ul or ol tag to make use of other CSS layout techniques, using setList(). In addition, specializations of this class as implemented by WAnchor, WGroupBox, WStackedWidget and WTableCell provide other alternative rendering of the container.

When setting the WContainerWidget inline the container only acts as a conceptual container, offering a common style to its children. Inline children are still layed out inline within the flow of the parent container of this container, as if they were inserted directly into that parent container. Block children are then not allowed (according to the HTML specification).

To use a layout manager instead of CSS-based layout, use setLayout() or pass the container as constructor argument to a layout manager. In that case you should not define any padding for the container, and widgets and nested layout managers must be added to the layout manager, instead of to the container directly.

Usage example:

 // Example 1:
 // Instantiate a container widget and add some children whose layout 
 // is governed based on HTML/CSS rules.
 Wt::WContainerWidget *container1 = new Wt::WContainerWidget();
 container1->addWidget(new Wt::WText("Some text"));
 container1->addWidget(new Wt::WImage("images/img.png"));
 Wt::WContainerWidget *child3 = new Wt::WContainerWidget(container1);

 // Example 2:
 // Instantiate a container widget which uses a layout manager
 Wt::WContainerWidget *container2 = new Wt::WContainerWidget();
 container2->resize(WLength::Auto, 600); // give the container a fixed height.

 Wt::WVBoxLayout *layout = new Wt::WVBoxLayout();
 layout->addWidget(new Wt::WText("Some text"));
 layout->addWidget(new Wt::WImage("images/img.png"));

 container2->setLayout(layout);      // set the layout to the container.

When using a layout manager, you need to carefully consider the alignment of the layout manager with respect to the container: when the container's height is unconstrained (not specified explicitly using resize() or a style class, and the container is not included in a layout manager), you should pass AlignTop to setLayout().

CSS

Depending on its configuration and usage, the widget corresponds to the following HTML tags:

This widget does not provide styling, and can be styled using inline or external CSS as appropriate.


Member Enumeration Documentation

How to handle overflow of inner content.

Enumerator:
OverflowVisible 

Show content that overflows.

OverflowAuto 

Show scrollbars when needed.

OverflowHidden 

Hide content that overflows.

OverflowScroll 

Always show scroll bars.


Member Function Documentation

void Wt::WContainerWidget::addWidget ( WWidget widget  )  [virtual]

Adds a child widget to this container.

This is equivalent to passing this container as the parent when constructing the child. The widget is appended to the list of children, and thus also layed-out at the end.

Reimplemented in Wt::Ext::Splitter, and Wt::WStackedWidget.

void Wt::WContainerWidget::clear (  )  [virtual]

Removes and deletes all child widgets.

This deletes all children that have been added to this container.

If a layout was set, also the layout manager is deleted.

WFlags<AlignmentFlag> Wt::WContainerWidget::contentAlignment (  )  const [inline]

Returns the alignment of children.

See also:
setContentAlignment(WFlags<AlignmentFlag>)
void Wt::WContainerWidget::insertBefore ( WWidget widget,
WWidget before 
) [virtual]

Inserts a child widget in this container, before another widget.

The widget is inserted at the place of the before widget, and subsequent widgets are shifted.

See also:
insertWidget(int index, WWidget *widget);

Reimplemented in Wt::Ext::Splitter.

void Wt::WContainerWidget::insertWidget ( int  index,
WWidget widget 
) [virtual]

Inserts a child widget in this container at given index.

The widget is inserted at the given index, and subsequent widgets are shifted.

See also:
insertBefore(WWidget *widget, WWidget *before);

Reimplemented in Wt::Ext::Splitter, and Wt::WStackedWidget.

bool Wt::WContainerWidget::isList (  )  const

Returns if this container is rendered as a List.

See also:
setList(), isOrderedList(), isUnorderedList()
bool Wt::WContainerWidget::isOrderedList (  )  const

Returns if this container is rendered as an Ordered List.

See also:
setList(), isList(), isUnorderedList()
bool Wt::WContainerWidget::isUnorderedList (  )  const

Returns if this container is rendered as an Unordered List.

See also:
setList(), isList(), isOrderedList()
WLayout* Wt::WContainerWidget::layout (  )  [inline, virtual]

Returns the layout manager that was set for the container.

If no layout manager was previously set using setLayout(WLayout *), 0 is returned.

See also:
setLayout(WLayout *)

Reimplemented from Wt::WWidget.

WLength Wt::WContainerWidget::padding ( Side  side  )  const

Returns the padding set for the widget.

See also:
setPadding(const WLength&, WFlags<Side>)
void Wt::WContainerWidget::removeWidget ( WWidget widget  )  [virtual]

Removes a child widget from this container.

This removes the widget from this container, but does not delete the widget !

Reimplemented in Wt::WStackedWidget.

EventSignal< WScrollEvent > & Wt::WContainerWidget::scrolled (  ) 

Event signal emitted when scrolling in the widget.

This event is emitted when the user scrolls in the widget (for setting the scroll bar policy, see setOverflow()). The event conveys details such as the new scroll bar position, the total contents height and the current widget height.

See also:
setOverflow()
void Wt::WContainerWidget::setContentAlignment ( WFlags< AlignmentFlag contentAlignment  ) 

Specifies how child widgets must be aligned within the container.

For a WContainerWidget, only specifes the horizontal alignment of child widgets. Note that there is no way to specify vertical alignment: children are always pushed to the top of the container.

For a WTableCell, this may also specify the vertical alignment. The default alignment is (AlignTop | AlignLeft ).

void Wt::WContainerWidget::setLayout ( WLayout layout,
WFlags< AlignmentFlag alignment 
)

Sets a layout manager for the container.

The alignment argument determines how the layout is aligned inside the container. By default, the layout manager arranges children over the entire width and height of the container, corresponding to a value of AlignJustify. This requires that the container has a specified height (either because it is managed by another layout manager, is the root container widget, or has a height set).

In general, alignment is the logical OR of a horizontal and a vertical flag:

When using a horizontal alingment different from Wt::AlignJustify, and a vertical alignment different from '0', the widget is sized in that direction to fit the contents, instead of the contents being adjusted to the widget size. This is useful when the container does not have a specific size in that direction and when the layout manager does not contain any widgets that wish to consume all remaining space in that direction.

Only a single layout manager may be set. If you want to replace the current layout manager, you have to erase all contents first using clear(), which also deletes the layout manager.

Note that you can nest layout managers inside each other, to create a complex layout hierarchy.

The widget will take ownership of layout.

See also:
layout()
void Wt::WContainerWidget::setLayout ( WLayout layout  )  [virtual]

Sets a layout manager for the container.

Note that you can nest layout managers inside each other, to create a complex layout hierarchy.

If a previous layout manager was already set, it is first deleted. In that case, you will need to make sure that you either readd all widgets that were part of the previous layout to the new layout, or delete them, to avoid memory leaks.

The layout manager arranges children in the entire width and height of the container. This is equivalent to setLayout(layout, AlignJustify)

See also:
layout(), setLayout(WLayout *, WFlags<AlignmentFlag>)

Reimplemented from Wt::WWidget.

void Wt::WContainerWidget::setList ( bool  list,
bool  ordered = false 
)

Renders the container as an HTML list.

Setting renderList to true will cause the container to be using an HTML <ul> or <ol> type, depending on the value of orderedList. This must be set before the initial render of the container. When set, any contained WContainerWidget will be rendered as an HTML <li>. Adding non-WContainerWidget children results in unspecified behaviour.

Note that CSS default layout rules for <ul> and <ol> add margin and padding to the container, which may look odd if you do not use bullets.

By default, a container is rendered using a <div> element.

See also:
isList(), isOrderedList(), isUnorderedList()
void Wt::WContainerWidget::setOverflow ( Overflow  overflow,
WFlags< Orientation orientation = (Horizontal | Vertical) 
)

Sets how overflow of contained children must be handled.

This is an alternative (CSS-ish) way to provide scroll bars on a container widget, compared to wrapping inside a WScrollArea.

Note that currently, you cannot separately specify vertical and horizontal scroll behaviour, since this is not supported on Opera. Therefore, settings will apply automatically to both orientations.

Note:
For Internet Explorer, setting overflow to OverflowAuto or OverflowScroll may cause problems with content that uses absolutely positioned DOM elements (such as WPaintedWidget or several Ext widgets): due to a bug in IE, these elements will not scroll along, but stay 'fixed' at their initial position. This problem can (usually) be circumvented by using a relative position scheme relative (using setPositionScheme(Relative)) for the same container widget which provides the scroll bars.
See also:
WScrollArea
void Wt::WContainerWidget::setPadding ( const WLength padding,
WFlags< Side sides = All 
)

Sets padding inside the widget.

Setting padding has the effect of adding distance between the widget children and the border.


Generated on Thu May 13 05:16:16 2010 for Wt by doxygen 1.6.3