Common Desktop Environment: Desktop KornShell User's Guide

Main Script

The remainder of the script is the equivalent of Main() in a C program. It initializes the Xt Intrinsics and creates all the widgets used in the script_find window. The set -f in the first line tells dtksh to suppress expansion of wildcard characters in path names. This is necessary so that the find command can perform this expansion.

The script_find window (see Figure 4-4) consists of a Form widget with four areas. The areas are marked by Separator widgets, and each area has several widgets, all of which are children of the Form.

Figure 4-4 Widgets in script_find Window

Graphic

The widgets are created in sequence by area, from top to bottom.

Initialize

Initialize is accomplished by the Xt Intrinsics function XtInitialize():

XtInitialize TOPLEVEL find Dtksh $0 "${@:-}"

This creates a top-level shell that serves as the parent of a Form widget, which is created next.

Create a Form Widget

A Form widget is used as the main parent widget. Form is a Manager widget that allows you to place constraints on its children. Most of the widgets in the main script_find window are children of the Form. The description of the creation of the rest of the widgets is separated into the four areas of the window (see Figure 4-4).

First Area

The first area consists of two Label widgets, two TextField widgets, and a Separator widget that separates the first and second areas.

Figure 4-5 First Area of script_find Window

Graphic

The following code segment creates and positions the first Label widget and positions it within the Form using the DtkshAnchorTop and DtkshAnchorLeft convenience functions:

XtCreateManagedWidget SDLABEL sdlabel XmLabel $FORM \
     labelString:"Search Directory:" \
     $(DtkshAnchorTop 12) \
     $(DtkshAnchorLeft 10)

The following code segment creates and positions the first TextField widget. Note that it is positioned in relation to both the Form and the Label widget.

XtCreateManagedWidget SD sd XmText $FORM \
     columns:30 \
     value:"." \
     $(DtkshAnchorTop 6) \
     $(DtkshRightOf $SDLABEL 10) \
     $(DtkshAnchorRight 10) \
    navigationType:EXCLUSIVE_TAB_GROUP  
XmTextFieldSetInsertionPosition $SD 1

The remaining Label widget and TextField widget are created in the same manner.

The Separator widget is created as a child of the Form widget and positioned under the second TextField widget.

XtCreateManagedWidget SEP sep XmSeparator $FORM \
     separatorType:SINGLE_DASHED_LINE \
     $(DtkshUnder $FNP 10) \
     $(DtkshSpanWidth)

Second Area

The second area consists of a RowColumn widget, five ToggleButton gadgets, and another Separator widget.

Figure 4-6 Second Area of script_find Window

Graphic

A gadget is a widget that relies on its parent for many of its attributes, thus saving memory resources.

The RowColumn widget is created as a child of the Form widget, and positioned directly under the Separator widget created in the first area.

XtCreateManagedWidget RC
rc XmRowColumn $FORM \
          orientation:HORIZONTAL \
          numColumns:3 \
				 packing:PACK_COLUMN \
		$(DtkshUnder $SEP 10) \
		$(DtkshSpanWidth 10 10) \ 
		navigationType:EXCLUSIVE_TAB_GROUP

The five ToggleButton gadgets are created as children of the RowColumn using the convenience function DtkshAddButtons:

DtkshAddButtons -w $RC XmToggleButtonGadget \
     T1 "Cross Mount Points"           ""\
     T2 "Print Matching Filenames"     ""\
     T3 "Search Hidden Subdirectories" ""\
     T4 "Follow Symbolic Links"        ""\
     T5 "Descend Subdirectories First" ""

Another Separator is then created to separate the second and third areas. Note that this Separator widget ID is called SEP2.

XtCreateManagedWidget SEP2 sep XmSeparator $FORM \
     separatorType:SINGLE_DASHED_LINE \
     $(DtkshUnder $RC 10) \
		$(DtkshSpanWidth)

Third Area

The third area consists of two option menus and another Separator widget.

Figure 4-7 Third Area of script_find Window

Graphic

The Option Menus are pull-down menus. When the user clicks the option menu button, a menu pane with a number of choices appears. The user drags the pointer to the appropriate choice and releases the mouse button. The menu pane disappears and the option menu button label displays the new choice.

The first option menu menu pane consists of a number of push button gadgets, representing various restrictions that can be imposed upon the find command:

XmCreatePulldownMenu PANE $FORM pane  
DtkshAddButtons -w $PANE XmPushButtonGadget \
     NODIR "no restrictions" ""\
     NFS  "nfs"             ""\
     CDFS  "cdfs"           ""\
     HFS   "hfs"             "" 

Next, the Option Menu button itself is created and managed, with the 
menu pane just created ($PANE) identified as a subMenuId:  
XmCreateOptionMenu FSTYPE $FORM fstype \
          labelString:"Restrict Search To File System Type:" \
          menuHistory:$NODIR \
          subMenuId:$PANE \
   $(DtkshUnder $SEP2 20) \
   $(DtkshSpanWidth 10 10) \
   navigationType:EXCLUSIVE_TAB_GROUP  
XtManageChild $FSTYPE

The second option menu button is created in the same manner. It provides further restrictions on the find command.

The third separator is created in the same manner as the other separators.

Fourth Area

The fourth area consists of four push button widgets, all children of the Form widget.

Graphic

The four push buttons are used as follows:

The push buttons are created and positioned in much the same manner as any of the other widgets, although they are each labeled differently. The following code segment shows how the OK push button is created:

XtCreateManagedWidget OK
ok XmPushButton $FORM \
          labelString:"Ok" \
     $(DtkshUnder $SEP3 10) \
     $(DtkshFloatLeft 4) \
     $(DtkshFloatRight 24) \
    $(DtkshAnchorBottom 10)  
XtAddCallback $OK activateCallback "OkCallback"

Set Operating Parameters

XtSetValues is used to set some initial operating parameters:

XtSetValues $FORM \
     initialFocus:$SD \
     defaultButton:$OK \
     cancelButton:$CLOSE \
     navigationType:EXCLUSIVE_TAB_GROUP

The following line configures the TextField widgets so that pressing the return key does not activate the default button within the Form. See the description of EXCLUSIVE_TAB_GROUP in Appendix B for more information on its use.

DtkshSetReturnKeyControls $SD $FNP $FORM $OK

Realize and Loop

The last three lines of the script load the previous values of the script_find window, realize the top-level widget, and then enter a loop waiting for user input.

LoadStickyValues        
         XtRealizeWidget $TOPLEVEL
         XtMainLoop