home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / baswiz19.zip / BW$BAS.ZIP / WMENUPU.BAS < prev   
BASIC Source File  |  1993-01-29  |  6KB  |  137 lines

  1. '   +----------------------------------------------------------------------+
  2. '   |                                                                      |
  3. '   |        BASWIZ  Copyright (c) 1990-1993  Thomas G. Hanlin III         |
  4. '   |                                                                      |
  5. '   |                      The BASIC Wizard's Library                      |
  6. '   |                                                                      |
  7. '   +----------------------------------------------------------------------+
  8.  
  9.    DECLARE SUB WColor (BYVAL Handle%, BYVAL Fore%, BYVAL Back%)
  10.    DECLARE SUB WCursor (BYVAL Handle%, BYVAL CSize%)
  11.    DECLARE SUB WGetColor (BYVAL Handle%, Fore%, Back%)
  12.    DECLARE SUB WGetCursor (BYVAL Handle%, CSize%)
  13.    DECLARE SUB WGetScroll (BYVAL Handle%, AutoScroll%)
  14.    DECLARE SUB WGetSize (BYVAL Handle%, Rows%, Columns%)
  15.    DECLARE SUB WLocate (BYVAL Handle%, BYVAL Row%, BYVAL Column%)
  16.    DECLARE SUB WScroll (BYVAL Handle%, BYVAL AutoScroll%)
  17.    DECLARE SUB WUpdate ()
  18.    DECLARE SUB WView (BYVAL Handle%, BYVAL Row%, BYVAL Column%)
  19.    DECLARE SUB WWriteLn (BYVAL Handle%, St$)
  20.  
  21.    DEFINT A-Z
  22.  
  23. FUNCTION WMenuPopUp (Handle, PickList$(), HiFore, HiBack)
  24.  
  25. ' ------ Initialize ---------------------------------------------------------
  26. ' Here we save any information about the window which we're going to change,
  27. ' so we can restore it when we exit.  The location of the window within the
  28. ' virtual screen, the cursor position, and the text of the virtual screen are
  29. ' not saved... the window is left in its final state in case we want to pop
  30. ' up a sub-menu next to it or something of the sort.
  31.  
  32.    WGetColor Handle, Fore, Back
  33.    WGetCursor Handle, Cursor
  34.    WGetScroll Handle, AutoScroll
  35.    WGetSize Handle, Rows, Columns
  36.  
  37. ' After saving the relevant parameters, we set the virtual screen to suit our
  38. ' needs: move the window to the top left corner of the virtual screen, turn
  39. ' off the cursor, and turn off scrolling.  We also initialize some variables.
  40.  
  41.    Highlight = 1             ' row of the highlight bar
  42.    TopRow = 1                ' top row of the window within the virt. screen
  43.    WView Handle, TopRow, 1
  44.    WScroll Handle, 0
  45.    WCursor Handle, 0
  46.    FirstChoice = LBOUND(PickList$)
  47.    LastChoice = UBOUND(PickList$)
  48.  
  49. ' ------ Main Handler -------------------------------------------------------
  50. ' The pick list is written to the virtual screen and displayed.  When a key
  51. ' is pressed, appropriate action is taken.  Unless it was an exit key (abort
  52. ' or select), we'll come right back and do it all over again.
  53. ' ------
  54. ' It may seem sloppy to rewrite the entire pick list every time, but it's by
  55. ' far the easiest way to handle it.  The virtual windowing system is so fast
  56. ' that this inefficiency just doesn't matter, in this particular application
  57. ' at least (most of the time is spent waiting for them to press a key).
  58.  
  59.    DO
  60.       WLocate Handle, 1, 1                     ' write the menu choices
  61.       FOR tmp = FirstChoice TO LastChoice
  62.          St$ = LEFT$(PickList$(tmp) + SPACE$(Columns), Columns)
  63.          WLocate Handle, tmp - FirstChoice + 1, 1
  64.          IF tmp - FirstChoice + 1 = Highlight THEN
  65.             WColor Handle, HiFore, HiBack
  66.             WWriteLn Handle, St$
  67.             WColor Handle, Fore, Back
  68.          ELSE
  69.             WWriteLn Handle, St$
  70.          END IF
  71.       NEXT
  72.       WUpdate
  73.       DO                                       ' wait until we get a key
  74.          ky$ = INKEY$
  75.       LOOP UNTIL LEN(ky$)
  76.       ky = ASC(RIGHT$(ky$, 1))
  77.       IF LEN(ky$) = 1 THEN                     ' process the key
  78.          SELECT CASE ky
  79.             CASE 5: GOSUB LineUp               ' Control E (WordStar move up)
  80.             CASE 9: GOSUB LineDown             ' Tab       (Lotus move forward)
  81.             CASE 24: GOSUB LineDown            ' Control X (WordStar move down)
  82.             CASE 13: Done = -1                 ' Enter     (they've picked one)
  83.             CASE 27: Done = -1: Highlight = 0  ' ESC       (abort menu)
  84.             CASE ELSE
  85.          END SELECT
  86.       ELSE
  87.          SELECT CASE ky
  88.             CASE 72: GOSUB LineUp              ' Up arrow   (keypad move up)
  89.             CASE 15: GOSUB LineUp              ' BackTab    (Lotus move back)
  90.             CASE 80: GOSUB LineDown            ' Down arrow (keypad move down)
  91.             CASE ELSE
  92.          END SELECT
  93.       END IF
  94.    LOOP UNTIL Done                             ' go do it again if need be!
  95.    GOTO Terminate                              ' otherwise, exit
  96.  
  97. ' ------ Move Up a Row ------------------------------------------------------
  98. ' If they want to move up a row, we check to see if it's possible.  If so, we
  99. ' move the highlighted row up.  We also change the window view if need be.
  100.  
  101. LineUp:
  102.    IF Highlight > 1 THEN
  103.       Highlight = Highlight - 1
  104.       IF Highlight < TopRow THEN
  105.          TopRow = TopRow - 1
  106.          WView Handle, TopRow, 1
  107.       END IF
  108.    END IF
  109.    RETURN
  110.  
  111. ' ------ Move Down a Row ----------------------------------------------------
  112. ' If they want to move down a row, we check to see if it's possible.  If so,
  113. ' we move the highlighted row down, changing the window view too, if needed.
  114.  
  115. LineDown:
  116.    IF Highlight < LastChoice - FirstChoice + 1 THEN
  117.       Highlight = Highlight + 1
  118.       IF Highlight > TopRow + Rows - 1 THEN
  119.          TopRow = TopRow + 1
  120.          WView Handle, TopRow, 1
  121.       END IF
  122.    END IF
  123.    RETURN
  124.  
  125. ' ------ Terminate ----------------------------------------------------------
  126. ' They selected an option or aborted the menu, so we're done.  We restore
  127. ' some of the window settings that we changed, on the off chance that the
  128. ' window might later be used for something other than a menu.  The highlight
  129. ' row is returned as the result, which will be 0 if they aborted.
  130.  
  131. Terminate:
  132.    WScroll Handle, AutoScroll
  133.    WCursor Handle, Cursor
  134.    WMenuPopUp = Highlight
  135.  
  136. END FUNCTION
  137.