1 # $XConsortium: DtFuncs.sh.src /main/1 1995/11/01 15:49:09 rswiston $
3 # COMPONENT_NAME: desktop
5 # FUNCTIONS: DtkshAddButtons
13 # DtkshSetReturnKeyControls
16 # ORIGINS: 27,118,119,120,121
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
23 # (C) COPYRIGHT International Business Machines Corp. 1995
25 # US Government Users Restricted Rights - Use, duplication or
26 # disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
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
34 ###############################################################################
36 ###############################################################################
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.
44 # DtkshAddButtons parent widgetClass label1 callback1 [label2 callback2 ...]
46 # DtkshAddButtons [-w] parent widgetClass variable1 label1 callback1 \
47 # [variable2 label2 callback2 ...]
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.
53 # The widgetClass can be one of the following, and will default to the
54 # XmPushButtonGadget class, if not specified:
59 # XmToggleButtonGadget
61 # XmCascadeButtonGadget
65 # DtkshAddButtons $MENU XmPushButtonGadget Open do_Open Save do_Save Quit exit
67 # DtkshAddButtons -w $MENU XmPushButtonGadget B1 Open do_Open B2 Save do_Save
72 typeset parent widgetClass callback returnWidget="false" TMP=""
73 typeset -i paramCount=2
75 if [ $# -ge 1 ] && [ x"$1" = "x-w" ]; then
88 widgetClass=${1:-XmPushButtonGadget}
91 XmPushButtonGadget) callback=activateCallback;;
92 XmPushButton) callback=activateCallback;;
93 XmToggleButtonGadget) callback=valueChangedCallback;;
94 XmToggleButton) callback=valueChangedCallback;;
95 XmCascadeButtonGadget) callback=activateCallback;;
96 XmCascadeButton) callback=activateCallback;;
100 while [ $# -ge $paramCount ]
102 if [ "$returnWidget" = true ]; then
103 if [ ! "$3" = "" ]; then
104 XtCreateManagedWidget "$1" "$1" $widgetClass "$parent" \
105 labelString:"$2" ${callback}:"$3"
107 XtCreateManagedWidget "$1" "$1" $widgetClass "$parent" \
112 if [ ! "$2" = "" ]; then
113 XtCreateManagedWidget Id "btn" $widgetClass "$parent" \
114 labelString:"$1" ${callback}:"$2"
116 XtCreateManagedWidget Id "btn" $widgetClass "$parent" \
127 ###############################################################################
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
140 # DtkshSetReturnKeyControls textWidgetId nextTextWidgetId formWidgetId \
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.
152 # DtkshSetReturnKeyControls $TEXT1 $TEXT2 $FORM $OK
153 # DtkshSetReturnKeyControls $TEXT2 $TEXT3 $FORM $OK
156 DtkshSetReturnKeyControls()
158 if [ $# -ne 4 ]; then
162 XtAddCallback $1 focusCallback "XtSetValues $3 defaultButton:NULL"
163 XtAddCallback $1 losingFocusCallback "XtSetValues $3 defaultButton:$4"
165 XtOverrideTranslations $1 \
166 "Ctrl<Key>Return:ksh_eval(\"XmProcessTraversal $2 TRAVERSE_CURRENT\")
167 <Key>Return:ksh_eval(\"XmProcessTraversal $2 TRAVERSE_CURRENT\")"
173 ###############################################################################
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.
184 # DtkshUnder widgetId [offset]
185 # DtkshOver widgetId [offset]
186 # DtkshRightOf widgetId [offset]
187 # DtkshLeftOf widgetId [offset]
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.
195 # XtCreateManagedWidget BUTTON2 button2 XmPushButton $FORM \
196 # labelString:"Exit" \
197 # $(DtkshUnder $BUTTON1)
202 if [ $# -lt 1 ]; then
206 echo "topWidget:$1 topAttachment:ATTACH_WIDGET topOffset:${2:-0}"
211 if [ $# -lt 1 ]; then
215 echo "bottomWidget:$1 bottomAttachment:ATTACH_WIDGET bottomOffset:${2:-0}"
220 if [ $# -lt 1 ]; then
224 echo "leftWidget:$1 leftAttachment:ATTACH_WIDGET leftOffset:${2:-0}"
229 if [ $# -lt 1 ]; then
233 echo "rightWidget:$1 rightAttachment:ATTACH_WIDGET rightOffset:${2:-0}"
238 ###############################################################################
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.
253 # DtkshFloatRight [position]
254 # DtkshFloatLeft [position]
255 # DtkshFloatTop [position]
256 # DtkshFloatBottom [position]
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.
264 # XtCreateManagedWidget BUTTON1 button1 XmPushButton $FORM \
266 # $(DtkshUnder $SEPARATOR) \
267 # $(DtkshFloatLeft 10) \
268 # $(DtkshFloatRight 40)
273 echo "rightAttachment:ATTACH_POSITION rightPosition:${1:-0}"
278 echo "leftAttachment:ATTACH_POSITION leftPosition:${1:-0}"
283 echo "topAttachment:ATTACH_POSITION topPosition:${1:-0}"
288 echo "bottomAttachment:ATTACH_POSITION bottomPosition:${1:-0}"
293 ###############################################################################
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.
308 # DtkshAnchorRight [offset]
309 # DtkshAnchorLeft [offset]
310 # DtkshAnchorTop [offset]
311 # DtkshAnchorBottom [offset]
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.
319 # XtCreateManagedWidget BUTTON1 button1 XmPushButton $FORM \
321 # $(DtkshUnder $SEPARATOR) \
322 # $(DtkshAnchorLeft 10) \
323 # $(DtkshAnchorBottom 10)
328 echo "rightAttachment:ATTACH_FORM rightOffset:${1:-0}"
333 echo "leftAttachment:ATTACH_FORM leftOffset:${1:-0}"
338 echo "topAttachment:ATTACH_FORM topOffset:${1:-0}"
343 echo "bottomAttachment:ATTACH_FORM bottomOffset:${1:-0}"
348 ###############################################################################
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
362 # DtkshSpanWidth [offset]
363 # DtkshSpanHeight [offset]
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.
371 # XtCreateManagedWidget SEPARATOR $FORM XmSeparator \
372 # $(DtkshSpanWidth 1 1)
377 echo "leftAttachment:ATTACH_FORM leftOffset:${1:-0} \
378 rightAttachment:ATTACH_FORM rightOffset:${2:-0}"
383 echo "topAttachment:ATTACH_FORM topOffset:${1:-0} \
384 bottomAttachment:ATTACH_FORM bottomOffset:${2:-0}"
389 ###############################################################################
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:
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
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.
418 # DtDisplay*Dialog title message okCallback closeCallback helpCallback \
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.
425 # The "dialogStyle" parameter accepts any of the standard resource settings
426 # supported by the bulletin board widget.
430 # DtkshDisplayErrorDialog "Read Error" "Unable to read the file" \
431 # "OkCallback" "CancelCallback" "" \
432 # DIALOG_PRIMARY_APPLICATION_MODAL
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=""
445 DtkshDisplayErrorDialog()
447 _DtDisplayFeedbackDialog "$_DT_ERROR_DIALOG_HANDLE" "Error" "${@:-}"
448 if [ "$_DT_ERROR_DIALOG_HANDLE" = "" ] ; then
449 _DT_ERROR_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
454 DtkshDisplayQuestionDialog()
456 _DtDisplayFeedbackDialog "$_DT_QUESTION_DIALOG_HANDLE" "Question" "${@:-}"
457 if [ "$_DT_QUESTION_DIALOG_HANDLE" = "" ] ; then
458 _DT_QUESTION_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
463 DtkshDisplayWorkingDialog()
465 _DtDisplayFeedbackDialog "$_DT_WORKING_DIALOG_HANDLE" "Working" "${@:-}"
466 if [ "$_DT_WORKING_DIALOG_HANDLE" = "" ] ; then
467 _DT_WORKING_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
472 DtkshDisplayWarningDialog()
474 _DtDisplayFeedbackDialog "$_DT_WARNING_DIALOG_HANDLE" "Warning" "${@:-}"
475 if [ "$_DT_WARNING_DIALOG_HANDLE" = "" ] ; then
476 _DT_WARNING_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
481 DtkshDisplayInformationDialog()
483 _DtDisplayFeedbackDialog "$_DT_INFORMATION_DIALOG_HANDLE" "Information" \
485 if [ "$_DT_INFORMATION_DIALOG_HANDLE" = "" ] ; then
486 _DT_INFORMATION_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
493 ###############################################################################
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:
506 # _DT_HELP_DIALOG_HANDLE
507 # _DT_QUICK_HELP_DIALOG_HANDLE
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.
515 # DtDisplay*HelpDialog title helpType helpInformation [locationId]
517 # The meaning of the parameters is dependent upon the value specified
518 # for the 'helpType' parameter. There meanings are explained below:
520 # helpType = HELP_TYPE_TOPIC
521 # helpInformation = help volume name
522 # locationId = help topic location id
524 # helpType = HELP_TYPE_STRING
525 # helpInformation = help string
526 # locationId = <not used>
528 # helpType = HELP_TYPE_DYNAMIC_STRING
529 # helpInformation = help string
530 # locationId = <not used>
532 # helpType = HELP_TYPE_MAN_PAGE
533 # helpInformation = man page name
534 # locationId = <not used>
536 # helpType = HELP_TYPE_FILE
537 # helpInformation = help file name
538 # locationId = <not used>
542 # DtkshDisplayHelpDialog "Help On Dtksh" HELP_TYPE_FILE "HelpFileName"
546 # Global help dialog handles
547 _DT_HELP_DIALOG_HANDLE=""
548 _DT_QUICK_HELP_DIALOG_HANDLE=""
551 DtkshDisplayQuickHelpDialog()
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
560 DtkshDisplayHelpDialog()
562 _DtkshDisplayHelpDialog "$_DT_HELP_DIALOG_HANDLE" "" "${@:-}"
563 if [ "$_DT_HELP_DIALOG_HANDLE" = "" ] ; then
564 _DT_HELP_DIALOG_HANDLE=$_DT_TMP_DIALOG_HANDLE
569 ##############################################################################
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.
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'.
583 # The implied parent of the dialog is identified by the environment
584 # variable '$TOPLEVEL'.
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
591 # $1 = existing dialog handle, or "" if first time
592 # $2 = type of feedback dialog (Information, Question, Working, ... )
594 # $4 = message string
596 # $6 = cancelCallback
601 _DtDisplayFeedbackDialog()
603 if [ "$1" = "" ]; then
604 XmCreate${2}Dialog _DT_TMP_DIALOG_HANDLE $TOPLEVEL "$2"
606 _DT_TMP_DIALOG_HANDLE=$1
609 XtSetValues $_DT_TMP_DIALOG_HANDLE \
610 dialogTitle:"${3:-$2}" \
611 messageString:"${4:- }" \
612 dialogStyle:"${8:-DIALOG_MODELESS}"
614 if [ $# -ge 5 ] && [ "$5" != "" ]; then
615 XtSetValues $_DT_TMP_DIALOG_HANDLE okCallback:"$5"
618 if [ $# -lt 6 ] || [ "$6" = "" ]; then
619 XtUnmanageChild $(XmMessageBoxGetChild "-" $_DT_TMP_DIALOG_HANDLE \
620 DIALOG_CANCEL_BUTTON)
622 XtSetValues $_DT_TMP_DIALOG_HANDLE cancelCallback:"$6"
625 if [ $# -lt 7 ] || [ "$7" = "" ]; then
626 XtUnmanageChild $(XmMessageBoxGetChild "-" $_DT_TMP_DIALOG_HANDLE \
629 XtSetValues $_DT_TMP_DIALOG_HANDLE helpCallback:"$7"
632 _DtkshPositionDialog "$1"
633 XtManageChild $_DT_TMP_DIALOG_HANDLE
638 ##############################################################################
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
646 # The implied parent of the dialog is identified by the environment
647 # variable '$TOPLEVEL'.
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
654 # $1 = existing dialog handle, or "" if first time
655 # $2 = type of help dialog (Quick or "")
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)
667 _DtkshDisplayHelpDialog()
669 typeset helpType ARG1="" ARG2="" ARG3=""
670 typeset helpType VAL1="" VAL2="" VAL3=""
672 helpType="${4:-HELP_TYPE_TOPIC}"
677 HELP_TYPE_TOPIC) ARG2="helpVolume:"
680 VAL3="${6:-_HOMETOPIC}";;
681 HELP_TYPE_STRING) ARG2="stringData:"
683 HELP_TYPE_DYNAMIC_STRING) ARG2="stringData:"
685 HELP_TYPE_MAN_PAGE) ARG2="manPage:"
687 HELP_TYPE_FILE) ARG2="helpFile:"
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}"
697 DtCreateHelp${2}Dialog _DT_TMP_DIALOG_HANDLE $TOPLEVEL "$2" \
698 "${ARG1}${VAL1}" "${ARG2}${VAL2}"
701 _DT_TMP_DIALOG_HANDLE=$1
702 if [ "$ARG3" != "" ]; then
703 XtSetValues $_DT_TMP_DIALOG_HANDLE \
704 "${ARG1}${VAL1}" "${ARG2}${VAL2}" "${ARG3}${VAL3}"
706 XtSetValues $_DT_TMP_DIALOG_HANDLE \
707 "${ARG1}${VAL1}" "${ARG2}${VAL2}"
711 if [ "$2" = "Quick" ]; then
712 XtSetSensitive $(DtHelpQuickDialogGetChild "-" $_DT_TMP_DIALOG_HANDLE \
713 HELP_QUICK_HELP_BUTTON) false
715 XtSetValues $(XtParent "-" $_DT_TMP_DIALOG_HANDLE) title:"${3:-Help}"
716 _DtkshPositionDialog "$1"
717 XtManageChild $_DT_TMP_DIALOG_HANDLE
722 ##############################################################################
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.
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.
734 _DtkshPositionDialog()
736 typeset -i WIDTH HEIGHT X_P Y_P WIDTH_P HEIGHT_P
737 typeset -i finalX finalY
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 ))
746 (( finalX=($(XWidthOfScreen "-" $(XtScreen "-" $1) )-$WIDTH)/2 ))
747 (( finalY=($(XHeightOfScreen "-" $(XtScreen "-" $1) )-$HEIGHT)/2 ))
749 XtSetValues $(XtParent "-" $1) x:$finalX y:$finalY