Form widgets
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.
XmATTACHNONE
Default. Do not attach this side.
XmATTACHFORM
Attach the left side of the child to the left side of the form.
XmATTACHWIDGET
Attach the left side of the child to the right side of the widget specified in the leftWidget resource.
XmATTACHPOSITION
Attach the left side of the child to a relative position in the form. This position is specified by the leftPosition resource, and is a fractional value of the width of the form, with the default range being from 0 to 100. The position is relative to the left side of the form for left and right attachments, and to the top of the form for top and bottom attachments. A position of 0 places the left side of the child at the left side of the form. A position of 100 places the left side of the child at the right side of the form.
XmATTACHOPPOSITEFORM
Attach the left side of the child to the right side of the form.
XmATTACHOPPOSITEWIDGET
Attach the left side of the child to the left side of the widget specified in the leftWidget resource.
XmATTACHSELF
Attach the left side of the child to its initial position in the form.
Tip:
It is an error for attachments to be recursively defined. For example, if a widget A is attached to a widget B, then widget B. cannot be attached to widget A. More generally, there must not be a cycle in the widget attachments.
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.
Tip:
The results are undefined if an offset setting is used with an attachment type of XmATTACHPOSITION.
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.
Last modified date: 12/22/2017