crMovesText1.src 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. XCOMM! CDE_INSTALLATION_TOP/bin/dtksh
  2. XCOMM $XConsortium: crMovesText1.src /main/3 1996/04/23 20:19:33 drk $
  3. XCOMM #########################################################################
  4. XCOMM (c) Copyright 1993, 1994 Hewlett-Packard Company
  5. XCOMM (c) Copyright 1993, 1994 International Business Machines Corp.
  6. XCOMM (c) Copyright 1993, 1994 Sun Microsystems, Inc.
  7. XCOMM (c) Copyright 1993, 1994 Unix System Labs, Inc., a subsidiary of
  8. XCOMM Novell, Inc.
  9. XCOMM #########################################################################
  10. XCOMM
  11. XCOMM This advanced shell script demonstrates the code necessary for forcing
  12. XCOMM the Return key to move the focus to the next text field in a dialog,
  13. XCOMM instead of causing the default pushbutton to be activated. When the
  14. XCOMM focus has moved to the last text field, then the Return key will activate
  15. XCOMM the default pushbutton.
  16. XCOMM
  17. XCOMM This function modifies the text field indicated by $1, so that when
  18. XCOMM the text field receives the focus, it clears the default button; when
  19. XCOMM it loses the focus, it will reenable the default button. It also adds
  20. XCOMM some translations for catching the Return key, so that it can force
  21. XCOMM the focus to the next text widget, which is indicated by $2
  22. SetCrControls()
  23. {
  24. XtAddCallback $1 focusCallback "ClearDftButton"
  25. XtAddCallback $1 losingFocusCallback "SetDftButton $OK"
  26. XtOverrideTranslations $1 \
  27. "Ctrl<Key>Return:ksh_eval(\"XmProcessTraversal $2 TRAVERSE_CURRENT\")
  28. <Key>Return:ksh_eval(\"XmProcessTraversal $2 TRAVERSE_CURRENT\")"
  29. }
  30. XCOMM FocusOut Callback: reenables the default button
  31. SetDftButton()
  32. {
  33. XtSetValues $FORM defaultButton:$OK
  34. }
  35. XCOMM FocusIn Callback: disables the default button
  36. ClearDftButton()
  37. {
  38. XtSetValues $FORM defaultButton:NULL
  39. }
  40. XCOMM If the 'Ok' button is activated, but the 'Name' field is empty, then
  41. XCOMM this function will display an error dialog.
  42. EmptyNameError()
  43. {
  44. XmCreateErrorDialog ERROR_DIALOG $TOPLEVEL noName \
  45. okLabelString:Ok \
  46. messageString:"You must supply a name...."
  47. XmMessageBoxGetChild CANCEL_BTN $ERROR_DIALOG DIALOG_CANCEL_BUTTON
  48. XmMessageBoxGetChild HELP_BTN $ERROR_DIALOG DIALOG_HELP_BUTTON
  49. XtUnmanageChildren $CANCEL_BTN $HELP_BTN
  50. XtSetValues $(XtParent "-" $ERROR_DIALOG) title:foo
  51. XtManageChildren $ERROR_DIALOG
  52. }
  53. XCOMM Pushbutton Callback: attached to the 'Cancel' pushbutton
  54. QuitCB()
  55. {
  56. exit 0
  57. }
  58. XCOMM Pushbutton Callback: attached to the default pushbutton. It extracts the
  59. XCOMM fields within the dialog, and does some validation.
  60. CheckActionValues()
  61. {
  62. XtGetValues $LARGEICON value:LARGEICON_VALUE
  63. XtGetValues $SMALLICON value:SMALLICON_VALUE
  64. XtGetValues $DESCRIPTION value:DESCRIPTION_VALUE
  65. XtGetValues $COMMANDLINE value:COMMANDLINE_VALUE
  66. XtGetValues $PROMPT value:PROMPT_VALUE
  67. XtGetValues $COMMANDTYPE menuHistory:COMMANDTYPE_WIDGET
  68. XmTextGetString NAME_VALUE $NAME
  69. if [ "$NAME_VALUE" = "" ]
  70. then
  71. EmptyNameError
  72. else
  73. echo "Name: "$NAME_VALUE
  74. echo "Large Icon: "$LARGEICON_VALUE
  75. echo "Small Icon: "$SMALLICON_VALUE
  76. echo "Description: "$DESCRIPTION_VALUE
  77. echo "Command Line: "$COMMANDLINE_VALUE
  78. echo "Prompt: "$PROMPT_VALUE
  79. echo "Command Type: "$COMMANDTYPE_WIDGET
  80. fi
  81. }
  82. XCOMM ###################### Create the Main UI ###############################
  83. XtInitialize TOPLEVEL createAction CreateAction "$0" "$@"
  84. XtCreateManagedWidget FORM form XmForm $TOPLEVEL
  85. XtCreateManagedWidget NAMELABEL nameLabel XmLabel $FORM \
  86. topAttachment:ATTACH_FORM \
  87. topOffset:20 \
  88. leftAttachment:ATTACH_FORM \
  89. leftOffset:20 \
  90. labelString:"Name:"
  91. XtCreateManagedWidget NAME name XmText $FORM \
  92. topAttachment:ATTACH_OPPOSITE_WIDGET \
  93. topWidget:$NAMELABEL \
  94. topOffset:-7 \
  95. leftAttachment:ATTACH_WIDGET \
  96. leftWidget:$NAMELABEL \
  97. leftOffset:10 \
  98. rightAttachment:ATTACH_FORM \
  99. rightOffset:10 \
  100. navigationType:EXCLUSIVE_TAB_GROUP
  101. XtCreateManagedWidget COMMANDLINELABEL commandLineLabel XmLabel $FORM \
  102. topAttachment:ATTACH_WIDGET \
  103. topWidget:$NAMELABEL \
  104. topOffset:20 \
  105. leftAttachment:ATTACH_FORM \
  106. leftOffset:20 \
  107. labelString:"Command Line:"
  108. XtCreateManagedWidget COMMANDLINE commandLine XmText $FORM \
  109. topAttachment:ATTACH_WIDGET \
  110. topWidget:$COMMANDLINELABEL \
  111. topOffset:5 \
  112. leftAttachment:ATTACH_FORM \
  113. leftOffset:40 \
  114. rightAttachment:ATTACH_FORM \
  115. rightOffset:10 \
  116. navigationType:EXCLUSIVE_TAB_GROUP
  117. XmCreatePulldownMenu PANE $FORM pane
  118. XtCreateManagedWidget XWIN xwin XmPushButton $PANE \
  119. labelString:"X Windows"
  120. XtCreateManagedWidget NOOUT noOut XmPushButton $PANE \
  121. labelString:"No Output"
  122. XtCreateManagedWidget TERM term XmPushButton $PANE \
  123. labelString:"Terminal"
  124. XtCreateManagedWidget TERMCLOSE termClose XmPushButton $PANE \
  125. labelString:"Terminal [auto-close]"
  126. XmCreateOptionMenu COMMANDTYPE $FORM commandType \
  127. topAttachment:ATTACH_WIDGET \
  128. topWidget:$COMMANDLINE \
  129. topOffset:20 \
  130. leftAttachment:ATTACH_FORM \
  131. leftOffset:20 \
  132. rightAttachment:ATTACH_FORM \
  133. rightOffset:10 \
  134. labelString:"Window Type:" \
  135. menuHistory:$TERM \
  136. subMenuId:$PANE \
  137. navigationType:EXCLUSIVE_TAB_GROUP
  138. XtSetValues $COMMANDTYPE spacing:35
  139. XtManageChildren $COMMANDTYPE
  140. XtCreateManagedWidget OPTLABEL optLabel XmLabel $FORM \
  141. topAttachment:ATTACH_WIDGET \
  142. topWidget:$COMMANDTYPE \
  143. topOffset:30 \
  144. leftAttachment:ATTACH_FORM \
  145. leftOffset:100 \
  146. labelString:"Optional Fields"
  147. XtCreateManagedWidget SEP1 sep1 XmSeparator $FORM \
  148. topAttachment:ATTACH_OPPOSITE_WIDGET \
  149. topWidget:$OPTLABEL \
  150. topOffset:10 \
  151. rightAttachment:ATTACH_WIDGET \
  152. rightWidget:$OPTLABEL \
  153. rightOffset:5 \
  154. leftAttachment:ATTACH_FORM \
  155. orientation:HORIZONTAL \
  156. separatorType:SHADOW_ETCHED_OUT
  157. XtCreateManagedWidget SEP2 sep2 XmSeparator $FORM \
  158. topAttachment:ATTACH_OPPOSITE_WIDGET \
  159. topWidget:$OPTLABEL \
  160. topOffset:10 \
  161. leftAttachment:ATTACH_WIDGET \
  162. leftWidget:$OPTLABEL \
  163. leftOffset:5 \
  164. rightAttachment:ATTACH_FORM \
  165. orientation:HORIZONTAL \
  166. separatorType:SHADOW_ETCHED_OUT
  167. XtCreateManagedWidget PROMPTLABEL promptLabel XmLabel $FORM \
  168. topAttachment:ATTACH_WIDGET \
  169. topWidget:$OPTLABEL \
  170. topOffset:20 \
  171. leftAttachment:ATTACH_FORM \
  172. leftOffset:20 \
  173. labelString:"Filename Prompt:"
  174. XtCreateManagedWidget PROMPT prompt XmText $FORM \
  175. topAttachment:ATTACH_WIDGET \
  176. topWidget:$PROMPTLABEL \
  177. topOffset:5 \
  178. leftAttachment:ATTACH_FORM \
  179. leftOffset:40 \
  180. rightAttachment:ATTACH_FORM \
  181. rightOffset:10 \
  182. navigationType:EXCLUSIVE_TAB_GROUP
  183. XtCreateManagedWidget LARGEICONLABEL largeIconLabel XmLabel $FORM \
  184. topAttachment:ATTACH_WIDGET \
  185. topWidget:$PROMPT \
  186. topOffset:30 \
  187. leftAttachment:ATTACH_FORM \
  188. leftOffset:20 \
  189. labelString:"Large Icon:"
  190. XtCreateManagedWidget LARGEICON largeIcon XmText $FORM \
  191. topAttachment:ATTACH_OPPOSITE_WIDGET \
  192. topWidget:$LARGEICONLABEL \
  193. topOffset:-7 \
  194. leftAttachment:ATTACH_WIDGET \
  195. leftWidget:$LARGEICONLABEL \
  196. leftOffset:20 \
  197. rightAttachment:ATTACH_FORM \
  198. rightOffset:10 \
  199. navigationType:EXCLUSIVE_TAB_GROUP
  200. XtCreateManagedWidget SMALLICONLABEL smallIconLabel XmLabel $FORM \
  201. topAttachment:ATTACH_WIDGET \
  202. topWidget:$LARGEICONLABEL \
  203. topOffset:20 \
  204. leftAttachment:ATTACH_FORM \
  205. leftOffset:20 \
  206. labelString:"Small Icon:"
  207. XtCreateManagedWidget SMALLICON smallIcon XmText $FORM \
  208. topAttachment:ATTACH_OPPOSITE_WIDGET \
  209. topWidget:$SMALLICONLABEL \
  210. topOffset:-7 \
  211. leftAttachment:ATTACH_OPPOSITE_WIDGET \
  212. leftWidget:$LARGEICON \
  213. rightAttachment:ATTACH_FORM \
  214. rightOffset:10 \
  215. navigationType:EXCLUSIVE_TAB_GROUP
  216. XtCreateManagedWidget DESCRIPTIONLABEL descriptionLabel XmLabel $FORM \
  217. topAttachment:ATTACH_WIDGET \
  218. topWidget:$SMALLICONLABEL \
  219. topOffset:20 \
  220. leftAttachment:ATTACH_FORM \
  221. leftOffset:20 \
  222. labelString:"Description:"
  223. XmCreateScrolledText DESCRIPTION $FORM description \
  224. topAttachment:ATTACH_WIDGET \
  225. topWidget:$DESCRIPTIONLABEL \
  226. topOffset:5 \
  227. leftAttachment:ATTACH_FORM \
  228. leftOffset:40 \
  229. rightAttachment:ATTACH_FORM \
  230. rightOffset:10 \
  231. editMode:MULTI_LINE_EDIT \
  232. rows:4 \
  233. navigationType:EXCLUSIVE_TAB_GROUP
  234. XtManageChildren $DESCRIPTION
  235. XtCreateManagedWidget SEP sep XmSeparator $FORM \
  236. topAttachment:ATTACH_WIDGET \
  237. topWidget:$DESCRIPTION \
  238. topOffset:20 \
  239. rightAttachment:ATTACH_FORM \
  240. leftAttachment:ATTACH_FORM
  241. XtCreateManagedWidget OK ok XmPushButton $FORM \
  242. labelString:Apply \
  243. leftAttachment:ATTACH_POSITION \
  244. leftPosition:10 \
  245. rightAttachment:ATTACH_POSITION \
  246. rightPosition:30 \
  247. topAttachment:ATTACH_WIDGET \
  248. topWidget:$SEP \
  249. topOffset:20 \
  250. bottomOffset:10 \
  251. bottomAttachment:ATTACH_FORM
  252. XtAddCallback $OK activateCallback CheckActionValues
  253. XtCreateManagedWidget CLOSE close XmPushButton $FORM \
  254. labelString:Close \
  255. leftAttachment:ATTACH_POSITION \
  256. leftPosition:40 \
  257. rightAttachment:ATTACH_POSITION \
  258. rightPosition:60 \
  259. topAttachment:ATTACH_WIDGET \
  260. topWidget:$SEP \
  261. topOffset:20 \
  262. bottomOffset:10 \
  263. bottomAttachment:ATTACH_FORM
  264. XtAddCallback $CLOSE activateCallback QuitCB
  265. XtCreateManagedWidget HELP help XmPushButton $FORM \
  266. labelString:Help \
  267. leftAttachment:ATTACH_POSITION \
  268. leftPosition:70 \
  269. rightAttachment:ATTACH_POSITION \
  270. rightPosition:90 \
  271. topAttachment:ATTACH_WIDGET \
  272. topWidget:$SEP \
  273. topOffset:20 \
  274. bottomOffset:10 \
  275. bottomAttachment:ATTACH_FORM
  276. XtSetValues $FORM \
  277. defaultButton:$OK \
  278. cancelButton:$CLOSE \
  279. navigationType:EXCLUSIVE_TAB_GROUP \
  280. initialFocus:$NAME
  281. XCOMM Set up proper behavior for the Return key
  282. SetCrControls $NAME $COMMANDLINE
  283. SetCrControls $COMMANDLINE $PROMPT
  284. SetCrControls $PROMPT $LARGEICON
  285. SetCrControls $LARGEICON $SMALLICON
  286. XtRealizeWidget $TOPLEVEL
  287. XtMainLoop