home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Spezial / SPEZIAL2_97.zip / SPEZIAL2_97.iso / ANWEND / ONLINE / TE2_134T / te2inst.003 / UserMenu.scr < prev    next >
Text File  |  1997-07-03  |  6KB  |  171 lines

  1. ;; -------------------------------------------------------------------------
  2. ;;
  3. ;; UserMenu.Scr -- Copyright (c) 1992-94, Oberon Software, Mankato Mn
  4. ;;                 Author: Brady Flowers, 07/09/92
  5. ;;                 Updated: 3/16/94
  6. ;;
  7. ;; Note:   Updated 3/16/94 to use the new, TE/2 1.30 PopupMenu() API
  8. ;;         and still maintain backwards compatibility with older scripts
  9. ;;         which call UserMenu.
  10. ;;
  11. ;; Usage:  This script allows the creation of a popup menu with up to
  12. ;;         ten items.  The user may use the up and down arrows and ENTER
  13. ;;         key to select items or may press the letter or number corresponding
  14. ;;         to the first character of an item (these must be unique for this
  15. ;;         to work as expected).  If the user presses ESCape the menu is
  16. ;;         aborted.
  17. ;;
  18. ;;         The calling script must define at least a subset of this file's
  19. ;;         global variables identically to the way they are defined herein.
  20. ;;         These variables are used for input and output parameters.
  21. ;;
  22. ;;         The following variables should be set on entry:
  23. ;;              usrmnuItems  -- total number of menu items (1 .. 10)
  24. ;;              usrmnuSelect -- initially selected item (1 .. usrmnuItems)
  25. ;;                              if this is invalid, 1 is assumed
  26. ;;              usrmnuTop    -- top row of menu dialog
  27. ;;              usrmnuLeft   -- left column of menu dialog
  28. ;;                              note: dialog dimensions are calculated
  29. ;;                              automatically
  30. ;;              usrmnuAttr   -- 'normal' color attribute (defaults to
  31. ;;                              the standard TE/2 dialog normal attribute if
  32. ;;                              not specified
  33. ;;              usrmnuHiAttr -- 'selected' color attribute (defaults to
  34. ;;                              the standard TE/2 dialog highligh attribute if
  35. ;;                              not specified
  36. ;;              usrmnuTitle  -- title string for the menu -- automatically
  37. ;;                              centered on the top row of the menu dialog
  38. ;;              usrmnuItem1 thru
  39. ;;              usrmnuItem10 -- fill in as many of these as you specified
  40. ;;                              in usrmnuItems, extra ones are ignored
  41. ;;                              the first character of each item should
  42. ;;                              be unique if you want mnemonic matching to
  43. ;;                              work well.
  44. ;;
  45. ;;         The return code of this script is in usrmnuSelect.  If the
  46. ;;         user made a selection, the value of usrmnuSelect on exit will
  47. ;;         be the item selected.  If the user pressed ESCape to exit the
  48. ;;         menu, the value will be zero.
  49. ;;
  50. ;;
  51. ;;  Example:
  52. ;;
  53. ;;    ;; MenuTest.scr
  54. ;;    global integer usrmnuItems  = 4
  55. ;;    global integer usrmnuSelect = 1
  56. ;;    global string  usrmnuTitle  = "Please Select One"
  57. ;;    global string  usrmnuItem1  = "Apples           "
  58. ;;    global string  usrmnuItem2  = "Bananas          "
  59. ;;    global string  usrmnuItem3  = "Coconuts         "
  60. ;;    global string  usrmnuItem4  = "Dates            "
  61. ;;    global integer usrmnuTop    = 10
  62. ;;    global integer usrmnuLeft   = 20
  63. ;;    global integer usrmnuAttr   = 0x1f
  64. ;;    global integer usrmnuHiAttr = 0x71
  65. ;;
  66. ;;    program
  67. ;;      run("UserMenu")
  68. ;;      if usrmnuSelect == 0
  69. ;;        message("^M^JMenu choice aborted^M^J")
  70. ;;      else
  71. ;;        message("^M^JYou selected item %d^M^J", usrmnuSelect)
  72. ;;      endif
  73. ;;      end
  74. ;;
  75. ;;
  76. ;; -------------------------------------------------------------------------
  77.  
  78. ;; -------------------------------------------------------------------------
  79. ;; GLOBAL variable
  80. global integer usrmnuSelect
  81. global integer usrmnuTop
  82. global integer usrmnuLeft
  83. global integer usrmnuAttr
  84. global integer usrmnuHiAttr
  85. global integer usrmnuItems
  86. global string  usrmnuTitle
  87. global string  usrmnuItem1
  88. global string  usrmnuItem2
  89. global string  usrmnuItem3
  90. global string  usrmnuItem4
  91. global string  usrmnuItem5
  92. global string  usrmnuItem6
  93. global string  usrmnuItem7
  94. global string  usrmnuItem8
  95. global string  usrmnuItem9
  96. global string  usrmnuItem10
  97.  
  98. ;; -------------------------------------------------------------------------
  99. ;; LOCAL Variables
  100. string  mnuItems
  101.  
  102. ;; -------------------------------------------------------------------------
  103.  
  104. subroutine SetupItems
  105.  
  106.   mnuItems = ""
  107.   if usrmnuItems > 0
  108.     mnuItems = mnuItems + "ß" + usrmnuItem1
  109.   endif
  110.   if usrmnuItems > 1
  111.     mnuItems = mnuItems + "ß" + usrmnuItem2
  112.   endif
  113.   if usrmnuItems > 2
  114.     mnuItems = mnuItems + "ß" + usrmnuItem3
  115.   endif
  116.   if usrmnuItems > 3
  117.     mnuItems = mnuItems + "ß" + usrmnuItem4
  118.   endif
  119.   if usrmnuItems > 4
  120.     mnuItems = mnuItems + "ß" + usrmnuItem5
  121.   endif
  122.   if usrmnuItems > 5
  123.     mnuItems = mnuItems + "ß" + usrmnuItem6
  124.   endif
  125.   if usrmnuItems > 6
  126.     mnuItems = mnuItems + "ß" + usrmnuItem7
  127.   endif
  128.   if usrmnuItems > 7
  129.     mnuItems = mnuItems + "ß" + usrmnuItem8
  130.   endif
  131.   if usrmnuItems > 8
  132.     mnuItems = mnuItems + "ß" + usrmnuItem9
  133.   endif
  134.   if usrmnuItems > 9
  135.     mnuItems = mnuItems + "ß" + usrmnuItem10
  136.   endif
  137.   mnuItems = mnuItems + "ß"
  138.  
  139. endsub
  140.  
  141.     ;; -----------------------------------------------------------------
  142.     ;; Main driver for the menu
  143.     ;; -----------------------------------------------------------------
  144.  
  145. subroutine UserMenu
  146.  
  147.   ;; Make sure defaults are set if they are needed
  148.   if usrmnuAttr == 0
  149.       usrmnuAttr   = DLogNormAttr
  150.   endif
  151.   if usrmnuHiAttr == 0
  152.       usrmnuHiAttr = DLogHiAttr
  153.   endif
  154.  
  155.   gosub SetupItems
  156.   usrmnuSelect = PopupMenu(usrmnuTitle, mnuItems, usrmnuTop, usrmnuLeft, usrmnuAttr, usrmnuHiAttr, usrmnuSelect)
  157.  
  158. endsub
  159.  
  160.  
  161. program
  162.  
  163.   if (usrmnuItems < 1) OR (usrmnuItems > 10)
  164.     errormsg("Invalid number of Menu Items for UserMenu", "Must be from 1 to 10 items")
  165.     usrmnuSelect = 0
  166.   else
  167.     gosub UserMenu
  168.   endif
  169.   end
  170.  
  171.