DtFuncs.sh 23 KB

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