XmNleftAttachment set to XmATTACH_OPPOSITE_FORM with negative offset
9.4.3 Position Attachments
Form positions provide another way to position widgets within a Form. The concept is similar to the hook and rod
principle described earlier, but in this case the widgets are anchored on at positions that are based on imaginary
longitude and latitude lines that are used to segment the Form into equal pieces. The resource used to partition the
Form into segments is XmNfractionBase. Although the name of this resource may suggest complicated
calculations, you just need to know that the Form is divided horizontally and vertically into the number of partitions
represented by its value. For example, the figure shows how a Form is partitioned if XmNfractionBase is set to 5.
9 Manager Widgets 9.4.3 Position Attachments
Form with XmNfractionBase set to 5
As you can see, there are an equal number of horizontal and vertical partitions, but the size of the horizontal partitions
is not the same as the size of the vertical partitions. It is currently not possible to set the number of horizontal
partitions separately from the number of vertical ones, although it is possible to work around this shortcoming, as we
will describe shortly.
Widgets are placed at the coordinates that represent the partitions by specifying XmATTACH_POSITION for the
attachment resource and by specifying a coordinate value for the corresponding position resource. The position
resources are XmNtopPosition, --XmN-bottomPosition, XmNleftPosition, and
XmNrightPosition. For example, if we wanted to attach the top and left sides of a PushButton to position 1, we
could use the following code fragment:
XtVaCreateManagedWidget ("name",
xmPushButtonWidgetClass, form,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, 1,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, 1,
The right and bottom attachments are left unspecified, so those edges of the widget are not explicitly positioned by the
Form. If attachments had been specified for these edges, the widget would have to be resized by the Form in order to
satisfy all the attachment constraints.
One obvious example of using position attachments is to create a tic−tac−toe board layout, as is done in the source
9 Manager Widgets 9.4.3 Position Attachments
code XtSetLanguageProc() is only available in X11R5; there is no corresponding function in X11R4.
XmStringCreateLocalized() is only available in Motif 1.2; XmStringCreateSimple() is the
corresponding function in Motif 1.1.
/* tictactoe.c −− demonstrate how fractionBase and XmATTACH_POSITIONs
* work in Form widgets.
#include <Xm/PushB.h>
#include <Xm/Form.h>
main(argc, argv)
int argc;
char *argv[];
XtAppContext app;
Widget toplevel, parent, w;
int x, y;
extern void pushed(); /* callback for each PushButton */
XtSetLanguageProc (NULL, NULL, NULL);
toplevel = XtVaAppInitialize (&app, "Demos", NULL, 0,
&argc, argv, NULL, NULL);
parent = XtVaCreateManagedWidget ("form",
xmFormWidgetClass, toplevel,
XmNfractionBase, 3,
for (x = 0; x < 3; x++)
for (y = 0; y < 3; y++) {
w = XtVaCreateManagedWidget (" ",
xmPushButtonWidgetClass, parent,
XmNtopAttachment, XmATTACH_POSITION,
XmNtopPosition, y,
XmNleftAttachment, XmATTACH_POSITION,
XmNleftPosition, x,
XmNrightAttachment, XmATTACH_POSITION,
XmNrightPosition, x+1,
XmNbottomAttachment, XmATTACH_POSITION,
XmNbottomPosition, y+1,
XtAddCallback (w, XmNactivateCallback, pushed, NULL);
XtRealizeWidget (toplevel);
XtAppMainLoop (app);
pushed(w, client_data, call_data)
Widget w; /* The PushButton that got activated */
XtPointer client_data; /* unused −− NULL was passed to XtAddCallback() */
XtPointer call_data;
char buf[2];
XmString str;
XmPushButtonCallbackStruct *cbs =
(XmPushButtonCallbackStruct *) call_data;
/* Shift key gets an O. (xbutton and xkey happen to be similar) */
if (cbs−>event−>xbutton.state & ShiftMask)
9 Manager Widgets 9.4.3 Position Attachments

Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.