Our example is a bit contrived, so it may seem pointless to call XtAddCallback() for each PushButton and
specify an XmNentryCallback as well. The most compelling reason for using an entry callback is that you may
want to provide client data for the RowColumn as a whole, as well as for each child widget.
Remember that the RowColumn widget is also used for a number of objects implemented internally by the Motif
toolkit, such as the Motif menu system, RadioBoxes, and CheckBoxes. Many of the resources for the widget are
specific to these objects, so they are not discussed here. For more information on menus, see Chapter 4, The Main
Window, and Chapter 15, Menus; for information on RadioBoxes and CheckBoxes, see Chapter 11, Labels and
Buttons.
9.6 The Frame Widget
The Frame is a simple manager widget; the purpose of the Frame is to draw a three−dimensional border around its
child. In Motif 1.1, a Frame can contain only one child. With Motif 1.2, the widget can have two children: a work
area child and a title child. The Frame shrink wraps itself around its work area child, adding space for a title if one is
specified. The children are responsible for setting the size of the Frame.
The Frame is useful for grouping related control elements, so that they are separated visually from other elements in a
window. The Frame is commonly used as the parent of RadioBoxes and CheckBoxes, since the RowColumn widget
does not provide a three−dimensional border. the figure shows a portion of a dialog box that uses Frames to segregate
three groups of ToggleButtons.
Frame widgets used to provide borders around RowColumn widgets
To use Frame widgets in an application, you must include the file <Xm/Frame.h>. Creating a Frame widget is just like
creating any other manager widget, as shown in the following code fragment:
Widget frame;
frame = XtVaCreateManagedWidget ("name",
xmFrameWidgetClass, parent,
9 Manager Widgets 9.6 The Frame Widget
233
resource−value−list,
NULL);
Since the Frame performs only simple geometry management, you can create a Frame widget as managed using
XtVaCreateManagedWidget() and not worry about a performance loss. The Frame widget is an exception to
the guidelines about creating manager widgets that we presented earlier in the chapter.
The principal resource used by the Frame widget is XmNshadowType. This resource specifies the style of the
three−dimensional border that is placed around the work area child of the Frame. The value may be any of the
following:
XmSHADOW_IN
XmSHADOW_OUT
XmSHADOW_ETCHED_IN
XmSHADOW_ETCHED_OUT
If the parent of the Frame is a shell widget, the default value for XmNshadowType is set to XmSHADOW_OUT and the
value for XmNshadowThickness is set to 1. Otherwise, the default shadow type is XmSHADOW_ETCHED_IN and
the thickness is 2. Of course, these values may be overridden by the application or the user.
In Motif 1.2, the Frame provides some constraint resources that can be specified for its children. The
XmNchildType resource indicates whether the child is the work area or the title child for the Frame. The default
value is XmFRAME_WORKAREA_CHILD. To specify that a child is the title child, use the value
XmFRAME_TITLE_CHILD.
The XmNchildHorizontalAlignment and XmNchildHorizontalSpacing resources control the
horizontal positioning of the title. The possible values for horizontal alignment are:
XmALIGNMENT_BEGINNING
XmALIGNMENT_END
XmALIGNMENT_CENTER
The XmNchildVerticalAlignment resource specifies the vertical positioning of the title child relative to the
top shadow of the Frame. The possible values for this resource are:
XmALIGNMENT_BASELINE_BOTTOM
XmALIGNMENT_BASELINE_TOP
XmALIGNMENT_CENTER
XmALIGNMENT_WIDGET_TOP
XmALIGNMENT_WIDGET_BOTTOM
the source code demonstrates many of the different shadow and alignment styles that are possible with the Frame
widget. XtSetLanguageProc() is only available in X11R5; there is no corresponding function in X11R4. This
example also uses functionality that is new in Motif 1.2; to take advantage of this functionality, define the symbol
MOTIF_1_2 when you compile the program.
/* frame.c −− demonstrate the Frame widget by creating
* four Labels with Frame widget parents.
*/
#include <Xm/LabelG.h>
#include <Xm/RowColumn.h>
#include <Xm/Frame.h>
main(argc, argv)
int argc;
9 Manager Widgets 9.6 The Frame Widget
234
char *argv[];
{
Widget toplevel, rowcol, frame;
XtAppContext app;
XtSetLanguageProc (NULL, NULL, NULL);
/* Initialize toolkit and create TopLevel shell widget */
toplevel = XtVaAppInitialize (&app, "Demos",
NULL, 0, &argc, argv, NULL, NULL);
/* Make a RowColumn to contain all the Frames */
rowcol = XtVaCreateWidget ("rowcolumn",
xmRowColumnWidgetClass, toplevel,
XmNspacing, 5,
NULL);
/* Create different Frames each containing a unique shadow type */
XtVaCreateManagedWidget ("Frame Types:",
xmLabelGadgetClass, rowcol, NULL);
frame = XtVaCreateManagedWidget ("frame1",
xmFrameWidgetClass, rowcol,
XmNshadowType, XmSHADOW_IN,
NULL);
XtVaCreateManagedWidget ("XmSHADOW_IN",
xmLabelGadgetClass, frame,
NULL);
#ifdef MOTIF_1_2
XtVaCreateManagedWidget ("XmALIGNMENT_CENTER",
xmLabelGadgetClass, frame,
XmNchildType, XmFRAME_TITLE_CHILD,
XmNchildVerticalAlignment, XmALIGNMENT_CENTER,
NULL);
#endif
frame = XtVaCreateManagedWidget ("frame2",
xmFrameWidgetClass, rowcol,
XmNshadowType, XmSHADOW_OUT,
NULL);
XtVaCreateManagedWidget ("XmSHADOW_OUT",
xmLabelGadgetClass, frame,
NULL);
#ifdef MOTIF_1_2
XtVaCreateManagedWidget ("XmALIGNMENT_BASELINE_TOP",
xmLabelGadgetClass, frame,
XmNchildType, XmFRAME_TITLE_CHILD,
XmNchildVerticalAlignment, XmALIGNMENT_BASELINE_TOP,
NULL);
#endif
frame = XtVaCreateManagedWidget ("frame3",
xmFrameWidgetClass, rowcol,
XmNshadowType, XmSHADOW_ETCHED_IN,
NULL);
XtVaCreateManagedWidget ("XmSHADOW_ETCHED_IN",
xmLabelGadgetClass, frame,
NULL);
#ifdef MOTIF_1_2
XtVaCreateManagedWidget ("XmALIGNMENT_WIDGET_TOP",
xmLabelGadgetClass, frame,
XmNchildType, XmFRAME_TITLE_CHILD,
9 Manager Widgets 9.6 The Frame Widget
235

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.