Initial import of the CDE 2.1.30 sources from the Open Group.
[oweals/cde.git] / cde / programs / dtksh / DtFuncs.sh.src
1 # $XConsortium: DtFuncs.sh.src /main/1 1995/11/01 15:49:09 rswiston $
2 #
3 #   COMPONENT_NAME: desktop
4 #
5 #   FUNCTIONS: DtkshAddButtons
6 #               DtkshFloatBottom
7 #               DtkshFloatLeft
8 #               DtkshFloatRight
9 #               DtkshFloatTop
10 #               DtkshLeftOf
11 #               DtkshOver
12 #               DtkshRightOf
13 #               DtkshSetReturnKeyControls
14 #               DtkshUnder
15 #
16 #   ORIGINS: 27,118,119,120,121
17 #
18 #   This module contains IBM CONFIDENTIAL code. -- (IBM
19 #   Confidential Restricted when combined with the aggregated
20 #   modules for this product)
21 #   OBJECT CODE ONLY SOURCE MATERIALS
22 #
23 #   (C) COPYRIGHT International Business Machines Corp. 1995
24 #   All Rights Reserved
25 #   US Government Users Restricted Rights - Use, duplication or
26 #   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
27 #
28 ###############################################################################
29 #  (c) Copyright 1993, 1994 Hewlett-Packard Company     
30 #  (c) Copyright 1993, 1994 International Business Machines Corp.
31 #  (c) Copyright 1993, 1994 Sun Microsystems, Inc.
32 #  (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
33 #      Novell, Inc.
34 ###############################################################################
35
36 ###############################################################################
37 #
38 # DtkshAddButtons - Convenience function for adding 1 or more buttons of the
39 #                same kind into a composite widget.  Most frequently
40 #                used to add a collection of buttons into a menupane.
41 #
42 # Usages: 
43 #
44 #   DtkshAddButtons parent widgetClass label1 callback1 [label2 callback2 ...]
45 #
46 #   DtkshAddButtons [-w] parent widgetClass variable1 label1 callback1 \
47 #                   [variable2 label2 callback2 ...]
48 #
49 # The "-w" option indicates that the convenience function should return
50 # the widget handle for each of the created buttons.  The widget handle
51 # is returned in the specified environment variable.
52 #
53 # The widgetClass can be one of the following, and will default to the
54 # XmPushButtonGadget class, if not specified:
55 #
56 #          XmPushButton
57 #          XmPushButtonGadget
58 #          XmToggleButton
59 #          XmToggleButtonGadget
60 #          XmCascadeButton
61 #          XmCascadeButtonGadget
62 #
63 # Examples: 
64 #
65 #   DtkshAddButtons $MENU XmPushButtonGadget Open do_Open Save do_Save Quit exit
66 #
67 #   DtkshAddButtons -w $MENU XmPushButtonGadget B1 Open do_Open B2 Save do_Save
68 #
69
70 DtkshAddButtons() 
71 {
72    typeset parent widgetClass callback returnWidget="false" TMP=""
73    typeset -i paramCount=2
74
75    if [ $# -ge 1 ] && [ x"$1" = "x-w" ]; then 
76       returnWidget=true
77       paramCount=3
78       shift
79    fi
80
81    if [ $# -lt 2 ]; then
82       return 1
83    fi
84
85    parent=$1
86    shift
87
88    widgetClass=${1:-XmPushButtonGadget}
89    shift
90    case $widgetClass in
91      XmPushButtonGadget)      callback=activateCallback;;
92      XmPushButton)            callback=activateCallback;;
93      XmToggleButtonGadget)    callback=valueChangedCallback;;
94      XmToggleButton)          callback=valueChangedCallback;;
95      XmCascadeButtonGadget)   callback=activateCallback;;
96      XmCascadeButton)         callback=activateCallback;;
97      *)                       return 1
98    esac
99
100    while [ $# -ge $paramCount ]
101    do
102       if [ "$returnWidget" = true ]; then 
103          if [ ! "$3" = "" ]; then
104             XtCreateManagedWidget "$1" "$1" $widgetClass "$parent" \
105                       labelString:"$2" ${callback}:"$3"
106          else
107             XtCreateManagedWidget "$1" "$1" $widgetClass "$parent" \
108                       labelString:"$2"
109          fi
110          shift 3
111       else 
112          if [ ! "$2" = "" ]; then
113             XtCreateManagedWidget Id "btn" $widgetClass "$parent" \
114                       labelString:"$1" ${callback}:"$2"
115          else
116             XtCreateManagedWidget Id "btn" $widgetClass "$parent" \
117                       labelString:"$1"
118          fi
119          shift 2
120       fi
121    done
122    return 0
123 }
124
125
126
127 ###############################################################################
128 #
129 # DtkshSetReturnKeyControls - Convenience function for configuring a text
130 #            widget (within a form!) so that the Return key does not
131 #            activate the default button within the form, but instead
132 #            moves the focus to the next text widget within the form.
133 #            This is useful if you have a window which contains a
134 #            series of text fields, and the default button should not
135 #            be activated until the user presses the Return key in the
136 #            last text field.
137 #
138 # Usage: 
139 #
140 #   DtkshSetReturnKeyControls textWidgetId nextTextWidgetId formWidgetId \
141 #                          defaultButtonId
142 #
143 # The textWidgetId parameter specifies the widget which is to be configured
144 # to catch the 'Return' key, and force the focus to move to the next text
145 # widget (as indicated by the nextTextWidgetId parameter).  The formWidgetId
146 # parameter specifies the form which contains the default button, and should
147 # be the parent of the two text widgets.  The defaultButtonId indicates which
148 # component is to be treated as the default button within the form.
149 #
150 # Examples: 
151 #
152 #   DtkshSetReturnKeyControls $TEXT1 $TEXT2 $FORM $OK
153 #   DtkshSetReturnKeyControls $TEXT2 $TEXT3 $FORM $OK
154 #
155
156 DtkshSetReturnKeyControls()
157 {
158    if [ $# -ne 4 ]; then
159       return 1
160    fi
161
162    XtAddCallback $1 focusCallback "XtSetValues $3 defaultButton:NULL"
163    XtAddCallback $1 losingFocusCallback "XtSetValues $3 defaultButton:$4"
164
165    XtOverrideTranslations $1 \
166        "Ctrl<Key>Return:ksh_eval(\"XmProcessTraversal $2 TRAVERSE_CURRENT\")
167         <Key>Return:ksh_eval(\"XmProcessTraversal $2 TRAVERSE_CURRENT\")"
168    return 0
169 }
170
171
172
173 ###############################################################################
174 #
175 # DtkshUnder
176 # DtkshOver
177 # DtkshRightOf
178 # DtkshLeftOf - Convenience functions for specifying form constraints.
179 #            This set of functions allow a component to be attached
180 #            to one of the edges of another component.
181 #
182 # Usages: 
183 #
184 #   DtkshUnder   widgetId [offset]
185 #   DtkshOver    widgetId [offset]
186 #   DtkshRightOf widgetId [offset]
187 #   DtkshLeftOf  widgetId [offset]
188 #
189 # The widgetId parameter specifies the widget to which the current
190 # component is to be attached.  The offset value is optional, and
191 # defaults to 0 if not specified.
192 #
193 # Examples: 
194 #
195 #   XtCreateManagedWidget BUTTON2 button2 XmPushButton $FORM \
196 #                         labelString:"Exit" \
197 #                         $(DtkshUnder $BUTTON1)
198 #
199
200 DtkshUnder() 
201 {
202    if [ $# -lt 1 ]; then
203       return 1
204    fi
205
206    echo "topWidget:$1 topAttachment:ATTACH_WIDGET topOffset:${2:-0}"
207 }
208
209 DtkshOver() 
210 {
211    if [ $# -lt 1 ]; then
212       return 1
213    fi
214
215    echo "bottomWidget:$1 bottomAttachment:ATTACH_WIDGET bottomOffset:${2:-0}"
216 }
217
218 DtkshRightOf() 
219 {
220    if [ $# -lt 1 ]; then
221       return 1
222    fi
223
224    echo "leftWidget:$1 leftAttachment:ATTACH_WIDGET leftOffset:${2:-0}"
225 }
226
227 DtkshLeftOf() 
228 {
229    if [ $# -lt 1 ]; then
230       return 1
231    fi
232
233    echo "rightWidget:$1 rightAttachment:ATTACH_WIDGET rightOffset:${2:-0}"
234 }
235
236
237
238 ###############################################################################
239 #
240 # DtkshFloatRight
241 # DtkshFloatLeft
242 # DtkshFloatTop
243 # DtkshFloatBottom - Convenience functions for specifying form constraints.
244 #                 This set of functions allow a component to be positioned
245 #                 independent of the other components within the form.
246 #                 As the form grows or shrinks, the component maintains
247 #                 its relative position within the form.  The component
248 #                 may still grow or shrink, depending upon the other form
249 #                 constraints which have been specified for the component.
250 #
251 # Usages: 
252 #
253 #   DtkshFloatRight  [position]
254 #   DtkshFloatLeft   [position]
255 #   DtkshFloatTop    [position]
256 #   DtkshFloatBottom [position]
257 #
258 # The optional position parameter specifies the relative position
259 # to which the indicated edge of the component will be positioned.
260 # A default position is used, if not specified.
261 #
262 # Examples: 
263 #
264 #   XtCreateManagedWidget BUTTON1 button1 XmPushButton $FORM \
265 #                         labelString:"Ok" \
266 #                         $(DtkshUnder $SEPARATOR) \
267 #                         $(DtkshFloatLeft 10) \
268 #                         $(DtkshFloatRight 40)
269 #
270
271 DtkshFloatRight() 
272 {
273    echo "rightAttachment:ATTACH_POSITION rightPosition:${1:-0}"
274 }
275
276 DtkshFloatLeft() 
277 {
278    echo "leftAttachment:ATTACH_POSITION leftPosition:${1:-0}"
279 }
280
281 DtkshFloatTop() 
282 {
283    echo "topAttachment:ATTACH_POSITION topPosition:${1:-0}"
284 }
285
286 DtkshFloatBottom() 
287 {
288    echo "bottomAttachment:ATTACH_POSITION bottomPosition:${1:-0}"
289 }
290
291
292
293 ###############################################################################
294 #
295 # DtkshAnchorRight
296 # DtkshAnchorLeft
297 # DtkshAnchorTop
298 # DtkshAnchorBottom - Convenience functions for specifying form constraints.
299 #                  This set of functions allow a component to be attached
300 #                  to one of the edges of the form in such a fashion that
301 #                  as the form grows or shrinks, the component's position
302 #                  does not change.  However, depending upon the other
303 #                  form constaints set on this component, the component
304 #                  may still grow or shrink in size.
305 #
306 # Usages: 
307 #
308 #   DtkshAnchorRight  [offset]
309 #   DtkshAnchorLeft   [offset]
310 #   DtkshAnchorTop    [offset]
311 #   DtkshAnchorBottom [offset]
312 #
313 # The optional offset parameter specifies how far from the edge
314 # of the form the component should be positioned.  If an offset
315 # is not specified, then 0 is user.
316 #
317 # Examples: 
318 #
319 #   XtCreateManagedWidget BUTTON1 button1 XmPushButton $FORM \
320 #                         labelString:"Ok" \
321 #                         $(DtkshUnder $SEPARATOR) \
322 #                         $(DtkshAnchorLeft 10) \
323 #                         $(DtkshAnchorBottom 10)
324 #
325
326 DtkshAnchorRight() 
327 {
328    echo "rightAttachment:ATTACH_FORM rightOffset:${1:-0}"
329 }
330
331 DtkshAnchorLeft() 
332 {
333    echo "leftAttachment:ATTACH_FORM leftOffset:${1:-0}"
334 }
335
336 DtkshAnchorTop() 
337 {
338    echo "topAttachment:ATTACH_FORM topOffset:${1:-0}"
339 }
340
341 DtkshAnchorBottom() 
342 {
343    echo "bottomAttachment:ATTACH_FORM bottomOffset:${1:-0}"
344 }
345
346
347
348 ###############################################################################
349 #
350 # DtkshSpanWidth
351 # DtkshSpanHeight - Convenience functions for specifying form constraints.
352 #                This set of functions allow a component to be configured
353 #                such that it spans either the full height or width of
354 #                the form widget.  This effect is accomplished by attaching
355 #                two edges of the component (top & bottom for DtkshSpanHeight,
356 #                and left and right for DtkshSpanWidth) to the form.  The
357 #                component will typically resize whenever the form is
358 #                resized.
359 #
360 # Usages: 
361 #
362 #   DtkshSpanWidth  [offset]
363 #   DtkshSpanHeight   [offset]
364 #
365 # The optional offset parameter specifies how far from the edge
366 # of the form the component should be positioned.  If an offset
367 # is not specified, then 0 is user.
368 #
369 # Examples: 
370 #
371 #   XtCreateManagedWidget SEPARATOR $FORM XmSeparator \
372 #                         $(DtkshSpanWidth 1 1)
373 #
374
375 DtkshSpanWidth() 
376 {
377    echo "leftAttachment:ATTACH_FORM leftOffset:${1:-0} \
378          rightAttachment:ATTACH_FORM rightOffset:${2:-0}"
379 }
380
381 DtkshSpanHeight() 
382 {
383    echo "topAttachment:ATTACH_FORM topOffset:${1:-0} \
384          bottomAttachment:ATTACH_FORM bottomOffset:${2:-0}"
385 }
386
387
388
389 ###############################################################################
390 #
391 # DtkshDisplayInformationDialog
392 # DtkshDisplayQuestionDialog
393 # DtkshDisplayWarningDialog
394 # DtkshDisplayWorkingDialog
395 # DtkshDisplayErrorDialog - Convenience functions for creating a single 
396 #                        instance of each of the flavors of the Motif 
397 #                        feedback dialog.  If an instance of the requested
398 #                        type of dialog already exists, then it will be
399 #                        reused.  The parent of the dialog is obtained
400 #                        from the environment variable $TOPLEVEL, which
401 #                        should be set by the calling shell script.  The 
402 #                        handle for the requested dialog is returned in 
403 #                        one of the following environment variables:
404 #
405 #                               _DT_ERROR_DIALOG_HANDLE
406 #                               _DT_QUESTION_DIALOG_HANDLE
407 #                               _DT_WORKING_DIALOG_HANDLE
408 #                               _DT_WARNING_DIALOG_HANDLE
409 #                               _DT_INFORMATION_DIALOG_HANDLE
410 #
411 # WARNING:  IF ATTACHING YOUR OWN CALLBACKS TO THE DIALOG
412 #           BUTTONS, DO NOT DESTROY THE DIALOG WHEN YOU
413 #           ARE DONE WITH IT; SIMPLY UNMANAGE THE DIALOG,
414 #           SO THAT IT CAN BE USED AT A LATER TIME.
415 #
416 # Usages: 
417 #
418 #   DtDisplay*Dialog title message okCallback closeCallback helpCallback \
419 #                    dialogStyle
420 #
421 # The "Ok" button is always managed, and by default will simply unmanage
422 # the dialog.  The "Cancel" and "Help" buttons are only managed when a
423 # callback is supplied for them.
424 #
425 # The "dialogStyle" parameter accepts any of the standard resource settings
426 # supported by the bulletin board widget.
427 #
428 # Examples: 
429 #
430 #   DtkshDisplayErrorDialog "Read Error" "Unable to read the file" \
431 #                         "OkCallback" "CancelCallback" "" \
432 #                         DIALOG_PRIMARY_APPLICATION_MODAL
433 #
434
435
436 # Global feedback dialog handles
437 _DT_ERROR_DIALOG_HANDLE=""
438 _DT_QUESTION_DIALOG_HANDLE=""
439 _DT_WORKING_DIALOG_HANDLE=""
440 _DT_WARNING_DIALOG_HANDLE=""
441 _DT_INFORMATION_DIALOG_HANDLE=""
442 _DT_TMP_DIALOG_HANDLE=""
443
444
445 DtkshDisplayErrorDialog() 
446 {
447    _DtDisplayFeedbackDialog "$_DT_ERROR_DIALOG_HANDLE" "Error" "${@:-}"
448    if [ "$_DT_ERROR_DIALOG_HANDLE" = "" ] ; then
449       _DT_ERROR_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
450    fi
451    return 0
452 }
453
454 DtkshDisplayQuestionDialog() 
455 {
456    _DtDisplayFeedbackDialog "$_DT_QUESTION_DIALOG_HANDLE" "Question" "${@:-}"
457    if [ "$_DT_QUESTION_DIALOG_HANDLE" = "" ] ; then
458       _DT_QUESTION_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
459    fi
460    return 0
461 }
462
463 DtkshDisplayWorkingDialog() 
464 {
465    _DtDisplayFeedbackDialog "$_DT_WORKING_DIALOG_HANDLE" "Working" "${@:-}"
466    if [ "$_DT_WORKING_DIALOG_HANDLE" = "" ] ; then
467       _DT_WORKING_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
468    fi
469    return 0
470 }
471
472 DtkshDisplayWarningDialog() 
473 {
474    _DtDisplayFeedbackDialog "$_DT_WARNING_DIALOG_HANDLE" "Warning" "${@:-}"
475    if [ "$_DT_WARNING_DIALOG_HANDLE" = "" ] ; then
476       _DT_WARNING_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
477    fi
478    return 0
479 }
480
481 DtkshDisplayInformationDialog() 
482 {
483    _DtDisplayFeedbackDialog "$_DT_INFORMATION_DIALOG_HANDLE" "Information" \
484                             "${@:-}"
485    if [ "$_DT_INFORMATION_DIALOG_HANDLE" = "" ] ; then
486       _DT_INFORMATION_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
487    fi
488    return 0
489 }
490
491
492
493 ###############################################################################
494 #
495 # DtkshDisplayQuickHelpDialog
496 # DtkshDisplayHelpDialog - Convenience functions for creating a single 
497 #                       instance of a help dialog and a quick help
498 #                       dialog.  If an instance of the requested type
499 #                       of help dialog already exists, then it will be
500 #                       reused.  The parent of the dialog is obtained
501 #                       from the environment variable $TOPLEVEL, which
502 #                       should be set by the calling shell script.  The 
503 #                       handle for the requested dialog is returned in 
504 #                       one of the following environment variables:
505 #
506 #                               _DT_HELP_DIALOG_HANDLE
507 #                               _DT_QUICK_HELP_DIALOG_HANDLE
508 #
509 # WARNING:  DO NOT DESTROY THIS DIALOG, UNLESS YOU ALSO CLEAR THE
510 #           CORRESPONDING ENVIRONMENT VARIABLE, SO THAT THIS CODE
511 #           WILL NOT ATTEMPT TO REUSE THE DIALOG AGAIN.
512 #
513 # Usages: 
514 #
515 #   DtDisplay*HelpDialog title helpType helpInformation [locationId]
516 #
517 # The meaning of the parameters is dependent upon the value specified
518 # for the 'helpType' parameter.  There meanings are explained below:
519 #
520 #      helpType = HELP_TYPE_TOPIC
521 #           helpInformation = help volume name
522 #           locationId      = help topic location id
523 #
524 #      helpType = HELP_TYPE_STRING
525 #           helpInformation = help string
526 #           locationId      = <not used>
527 #
528 #      helpType = HELP_TYPE_DYNAMIC_STRING
529 #           helpInformation = help string
530 #           locationId      = <not used>
531 #
532 #      helpType = HELP_TYPE_MAN_PAGE
533 #           helpInformation = man page name
534 #           locationId      = <not used>
535 #
536 #      helpType = HELP_TYPE_FILE
537 #           helpInformation = help file name
538 #           locationId      = <not used>
539 #
540 # Examples: 
541 #
542 #   DtkshDisplayHelpDialog "Help On Dtksh" HELP_TYPE_FILE "HelpFileName"
543 #
544
545
546 # Global help dialog handles
547 _DT_HELP_DIALOG_HANDLE=""
548 _DT_QUICK_HELP_DIALOG_HANDLE=""
549
550
551 DtkshDisplayQuickHelpDialog() 
552 {
553    _DtkshDisplayHelpDialog "$_DT_QUICK_HELP_DIALOG_HANDLE" "Quick" "${@:-}"
554    if [ "$_DT_QUICK_HELP_DIALOG_HANDLE" = "" ] ; then
555       _DT_QUICK_HELP_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
556    fi
557 }
558
559
560 DtkshDisplayHelpDialog() 
561 {
562    _DtkshDisplayHelpDialog "$_DT_HELP_DIALOG_HANDLE" "" "${@:-}"
563    if [ "$_DT_HELP_DIALOG_HANDLE" = "" ] ; then
564       _DT_HELP_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
565    fi
566 }
567
568
569 ##############################################################################
570 #
571 # This internal shell function performs most of the work required to
572 # create an instance of a feedback dialog (error, warning, information,
573 # working and question).  It will reuse an existing instance of the
574 # requested type of feedback dialog, if one has already been created;
575 # otherwise, it will create a new one.
576 #
577 # The "Ok" button is always managed, and by default will simply unpost
578 # the dialog.  The "Cancel" and "Help" buttons are only managed if the
579 # callers specifies a callback for the butttons.  Both the "Ok" and
580 # "Cancel" buttons rely on the fact that the 'autoUnpost' resource for
581 # the dialog is 'True'.
582 #
583 # The implied parent of the dialog is identified by the environment
584 # variable '$TOPLEVEL'.
585 #
586 # The incoming parameters are defined as follows (note that $1 and $2 are
587 # defined by the convenience function which is calling us, while $3 - $8
588 # are the parameters which were passed by the caller to the convenience
589 # function:
590 #
591 #      $1 = existing dialog handle, or "" if first time
592 #      $2 = type of feedback dialog (Information, Question, Working, ... )
593 #      $3 = dialog title
594 #      $4 = message string
595 #      $5 = okCallback
596 #      $6 = cancelCallback
597 #      $7 = helpCallback
598 #      $8 = dialogStyle
599 #
600
601 _DtDisplayFeedbackDialog()
602 {
603    if [ "$1" = "" ]; then
604       XmCreate${2}Dialog _DT_TMP_DIALOG_HANDLE $TOPLEVEL "$2"
605    else
606       _DT_TMP_DIALOG_HANDLE=$1
607    fi
608
609    XtSetValues $_DT_TMP_DIALOG_HANDLE \
610         dialogTitle:"${3:-$2}" \
611         messageString:"${4:- }" \
612         dialogStyle:"${8:-DIALOG_MODELESS}"
613
614    if [ $# -ge 5 ] && [ "$5" != "" ]; then
615       XtSetValues $_DT_TMP_DIALOG_HANDLE okCallback:"$5"
616    fi
617
618    if [ $# -lt 6 ] || [ "$6" = "" ]; then
619       XtUnmanageChild $(XmMessageBoxGetChild "-" $_DT_TMP_DIALOG_HANDLE \
620                         DIALOG_CANCEL_BUTTON)
621    else 
622       XtSetValues $_DT_TMP_DIALOG_HANDLE cancelCallback:"$6"
623    fi
624
625    if [ $# -lt 7 ] || [ "$7" = "" ]; then
626       XtUnmanageChild $(XmMessageBoxGetChild "-" $_DT_TMP_DIALOG_HANDLE \
627                         DIALOG_HELP_BUTTON)
628    else 
629       XtSetValues $_DT_TMP_DIALOG_HANDLE helpCallback:"$7"
630    fi
631
632    _DtkshPositionDialog "$1"
633    XtManageChild $_DT_TMP_DIALOG_HANDLE
634    return 0
635 }
636
637
638 ##############################################################################
639 #
640 # This internal shell function performs most of the work required to
641 # create an instance of a help dialog (regular help or quick help)
642 # It will reuse an existing instance of the requested type of help 
643 # dialog, if one has already been created; otherwise, it will create 
644 # a new one.
645 #
646 # The implied parent of the dialog is identified by the environment
647 # variable '$TOPLEVEL'.
648 #
649 # The incoming parameters are defined as follows (note that $1 and $2 are
650 # defined by the convenience function which is calling us, while $3 - $6
651 # are the parameters which were passed by the caller to the convenience
652 # function:
653 #
654 #      $1 = existing dialog handle, or "" if first time
655 #      $2 = type of help dialog (Quick or "")
656 #      $3 = dialog title
657 #      $4 = help type 
658 #      $5 = help information:
659 #              help volume (if help type = HELP_TYPE_TOPIC)
660 #              help string (if help type = HELP_TYPE_STRING)
661 #              help string (if help type = HELP_TYPE_DYNAMIC_STRING)
662 #              man page name (if help type = HELP_TYPE_MAN_PAGE)
663 #              help file name (if help type = HELP_TYPE_FILE)
664 #      $6 = help location Id (if help type = HELP_TYPE_TOPIC)
665 #
666
667 _DtkshDisplayHelpDialog()
668 {
669    typeset helpType ARG1="" ARG2="" ARG3=""
670    typeset helpType VAL1="" VAL2="" VAL3=""
671
672    helpType="${4:-HELP_TYPE_TOPIC}"
673    ARG1="helpType:"
674    VAL1="$helpType"
675
676    case $helpType in
677       HELP_TYPE_TOPIC)          ARG2="helpVolume:"
678                                 VAL2="${5:-}"
679                                 ARG3="locationId:"
680                                 VAL3="${6:-_HOMETOPIC}";;
681       HELP_TYPE_STRING)         ARG2="stringData:"
682                                 VAL2="${5:-}";;
683       HELP_TYPE_DYNAMIC_STRING) ARG2="stringData:"
684                                 VAL2="${5:-}";;
685       HELP_TYPE_MAN_PAGE)       ARG2="manPage:"
686                                 VAL2="${5:-}";;
687       HELP_TYPE_FILE)           ARG2="helpFile:"
688                                 VAL2="${5:-}";;
689       *)  return 1;;
690    esac
691
692    if [ "$1" = "" ]; then
693       if [ "$ARG3" != "" ]; then
694          DtCreateHelp${2}Dialog _DT_TMP_DIALOG_HANDLE $TOPLEVEL "$2" \
695                    "${ARG1}${VAL1}" "${ARG2}${VAL2}" "${ARG3}${VAL3}"
696       else
697          DtCreateHelp${2}Dialog _DT_TMP_DIALOG_HANDLE $TOPLEVEL "$2" \
698                    "${ARG1}${VAL1}" "${ARG2}${VAL2}"
699       fi
700    else
701       _DT_TMP_DIALOG_HANDLE=$1
702       if [ "$ARG3" != "" ]; then
703          XtSetValues $_DT_TMP_DIALOG_HANDLE \
704                    "${ARG1}${VAL1}" "${ARG2}${VAL2}" "${ARG3}${VAL3}"
705       else
706          XtSetValues $_DT_TMP_DIALOG_HANDLE \
707                    "${ARG1}${VAL1}" "${ARG2}${VAL2}"
708       fi
709    fi
710
711    if [ "$2" = "Quick" ]; then
712       XtSetSensitive $(DtHelpQuickDialogGetChild "-" $_DT_TMP_DIALOG_HANDLE \
713                     HELP_QUICK_HELP_BUTTON) false
714    fi
715    XtSetValues $(XtParent "-" $_DT_TMP_DIALOG_HANDLE) title:"${3:-Help}"
716    _DtkshPositionDialog "$1"
717    XtManageChild $_DT_TMP_DIALOG_HANDLE
718    return 0
719 }
720
721
722 ##############################################################################
723 #
724 # This internal shell function takes care of positioning the dialog so
725 # that it is centered over the window for which it is transient; if the
726 # window it is transient for is not currently managed, then the window
727 # will be positioned over in the center of the screen.
728 #
729 # Positioning does not occur that first time the dialog is posted; that
730 # is taken care of automatically by Motif and the window manager.  It
731 # only needs to happen for subsequent postings.
732 #
733
734 _DtkshPositionDialog()
735 {
736    typeset -i WIDTH HEIGHT X_P Y_P WIDTH_P HEIGHT_P 
737    typeset -i finalX finalY
738
739    if [ "$1" != "" ] && ! XtIsManaged $1 && XtIsShell $TOPLEVEL ; then
740       XtGetValues $1 width:WIDTH height:HEIGHT
741       if XtIsRealized $TOPLEVEL; then
742          XtGetValues $TOPLEVEL x:X_P y:Y_P width:WIDTH_P height:HEIGHT_P
743          (( finalX=$X_P+($WIDTH_P-$WIDTH)/2 ))
744          (( finalY=$Y_P+($HEIGHT_P-$HEIGHT)/2 ))
745       else
746          (( finalX=($(XWidthOfScreen "-" $(XtScreen "-" $1) )-$WIDTH)/2 ))
747          (( finalY=($(XHeightOfScreen "-" $(XtScreen "-" $1) )-$HEIGHT)/2 ))
748       fi
749       XtSetValues $(XtParent "-" $1) x:$finalX y:$finalY
750    fi
751 }