Common Desktop Environment: Desktop KornShell User's Guide

Initializing the Xt Intrinsics

A dtksh script must first initialize the Xt Intrinsics before it can call any of the Xlib, Xt, Motif, or libDt commands. You accomplish this by invoking the XtInitialize command, which returns an application shell widget. As is true for all dtksh commands that return a widget ID, XtInitialize returns the widget ID in the environment variable that is the first argument. For example, in:

XtInitialize TOPLEVEL myShellName Dtksh $0 "$@"

the widget ID is returned in the environment variable TOPLEVEL.

dtksh provides a default app-defaults file, which is used if the call to XtInitialize specifies an application class name of Dtksh. This app-defaults file contains the standard set of Dt application default values, so dtksh applications have a consistent look with other Dt applications.

Creating Widgets

There are several commands you can use to create widgets:

XtCreateWidget

Creates an unmanaged widget.

XtCreateManagedWidget

Creates a managed widget.

XtCreateApplicationShell

Creates an application shell.

XtCreatePopupShell

Creates a pop-up shell.

XmCreate<widgettypes>

Creates an unmanaged widget.

There is a specific format for each of these commands that you must follow. For example, suppose you want to create an unmanaged push button widget as a child of the top-level widget. You can use either XtCreateWidget or XmCreatePushButton. The formats for these commands are:

The actual commands to create a push button widget are:

XtCreateWidget BUTTON button XmPushButton $TOPLEVEL 
XmCreatePushButton BUTTON $TOPLEVEL button

Each of the preceding commands do exactly the same thing: create an unmanaged push button. Note that no resource values are set. Suppose that you want the background color of the push button to be red, and the foreground color to be black. You can set the values of these resources this way:

XtCreateWidget BUTTON button XmPushButton $TOPLEVEL \
  background:Red \
  foreground:Black 

XmCreatePushButton BUTTON $TOPLEVEL button\
  background:Red \ 
	  foreground:Black

All of the C functions that create a widget return a widget ID, or ID. The corresponding dtksh commands set an environment variable equal to the widget ID. These are category 3 commands, so the first argument is the name of the environment variable in which to return the widget ID. The widget ID is an ASCII string used by dtksh to access the actual widget pointer. Either of the following commands could be used to create a new form widget; however, in each case the widget ID for the new form widget is returned in the environment variable FORM:

After either of these commands, you can use $FORM to reference the new form widget. For example, you could use this command to create a label widget within the new form widget:

XmCreateLabel LABEL $FORM name\
  labelString:"Hi Mom" \
CH_FORM \ 
leftAttachment:ATTACH_FORM

Note -

There is a special widget ID called NULL, provided for cases where a shell script may need to specify a NULL widget. For example, to disable the defaultButton resource for a form widget, use the command XtSetValues $FORM defaultButton:NULL