Create form widgets using the createForm:argBlock: convenience method. Position form widget children by attaching their sides to other objects. Specify attachments by setting each child's leftAttachment, rightAttachment, topAttachment and bottomAttachment resources. A side can be attached either to a given position, to another widget, or to the edge of the form. The attachment types are listed below. The first four types are the most commonly used. All are described in terms of the leftAttachment, but the same attachment types apply to the other sides, with corresponding behavior.
If the attachment is XmATTACHFORM or XmATTACHWIDGET, an offset can also be specified that adds space between the side of the widget and the object to which it is attached. Offsets are specified by the leftOffset, rightOffset, topOffset, and bottomOffset resources. Offsets are specified in units of pixels.
If attachments have been set on all sides of a widget, the size of the widget is completely determined by the form and the other child widgets. However, if a side is left unattached, the widget will use its preferred size in the corresponding dimension. This is useful for allowing widgets to size themselves automatically based on their font size, contents, and other attributes.
Some convenience methods, such as those used to create a scrolled list or a scrolled text, actually create a widget subtree, but instead of returning the root of the subtree, the child is returned. In these cases, the form attachments must be set on the returned widget's parent, rather than on the widget itself. For an example, see "Scrolled lists".
The following diagram illustrates a form containing a drawing area and a
text widget. The right side of the drawing area is attached to a
position two-thirds (67 per cent) of the way from left to right. The
left side of the text widget is attached to the right side of the drawing
area. The remaining sides of the text and drawing area widgets are
attached to the form. The widgets are offset from each other by two
pixels. (Offsets in the diagram have been exaggerated to show the
attachments.)
The following code example creates the widget tree illustrated above:
| shell form drawing text | shell := CwTopLevelShell createApplicationShell: 'shell' argBlock: [:w | w title: 'Form Example']. form := shell createForm: 'form' argBlock: nil. form manageChild.
drawing := form createDrawingArea: 'drawing' argBlock: [:w | w borderWidth: 1; width: 200; height: 200; leftAttachment: XmATTACHFORM; leftOffset: 2;
rightAttachment: XmATTACHPOSITION; rightPosition: 67; topAttachment: XmATTACHFORM; topOffset: 2; bottomAttachment: XmATTACHFORM; bottomOffset: 2]. drawing manageChild.
text := form createText: 'text' argBlock: [:w | w leftAttachment: XmATTACHWIDGET; leftWidget: drawing; leftOffset: 2; rightAttachment: XmATTACHFORM; rightOffset: 2; topAttachment: XmATTACHFORM; topOffset: 2; bottomAttachment: XmATTACHFORM; bottomOffset: 2]. text manageChild. shell realizeWidget.