home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_AEDBAR.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  5.3 KB  |  196 lines

  1. *****************************************************************
  2. FUNCTION AEDBAR (aed_item)
  3. *****************************************************************
  4.  
  5. * Single line  -- Quit, Add, Edit, Find, Delete -- bar menu
  6.  
  7. * Copyright(c) 1991 - James Occhiogrosso
  8.  
  9. #include "inkey.ch"
  10. #include "set.ch"
  11. #include "setcurs.ch"
  12.  
  13. LOCAL  aed_col :=1, init_col := 1, keypress := 0, prev_item :=1,;
  14.        old_col :=1, old_color := '', old_cursor := '',          ;
  15.        spacing := 9, txtnorm := '',  txthigh := ''
  16.  
  17. * Menubar prompt messages
  18. PRIVATE prompt1 := ' Quit ',   prompt2 := ' Add ' ,  ;
  19.         prompt3 := ' Edit ',   prompt4 := ' Find ',  ;
  20.         prompt5 := ' Delete '
  21.  
  22. old_cursor = SET(_SET_CURSOR,SC_NONE)
  23. old_color  = SETCOLOR(colbarlo)
  24.  
  25. * If AEDBAR variable is undefined, define it.
  26. IF TYPE('aedbar') = 'U'
  27.     * Set aedbar public for use by AEDMSG
  28.     PUBLIC aedbar
  29.     aedbar = .T.
  30. ENDIF
  31.  
  32. * If starting row is not defined, default to bottom screen row
  33. IF TYPE('aed_row') != 'N'
  34.     * Set aed_row public for use by AEDMSG
  35.     PUBLIC aed_row
  36.     aed_row = MAXROW()
  37. ENDIF
  38.  
  39. * If starting item is not defined, default to item 1
  40. aed_item = IF(aed_item = NIL, 1, aed_item)
  41.  
  42. * Display the menubar.
  43. SETCOLOR(colbarlo)
  44. @ aed_row, init_col                SAY  prompt1
  45. @ aed_row, init_col  + (spacing)   SAY  prompt2
  46. @ aed_row, init_col  + (spacing*2) SAY  prompt3
  47. @ aed_row, init_col  + (spacing*3) SAY  prompt4
  48. @ aed_row, init_col  + (spacing*4) SAY  prompt5
  49.  
  50. * If the message window update variable is undefined, define it.
  51. IF TYPE('mw_update') = 'U'
  52.     PUBLIC mw_update
  53.     mw_update = .T.
  54. ENDIF
  55.  
  56. * Update the message window unless mw_update is false.
  57. * BOF or EOF set it .F. so that messages remain on view.
  58. IF mw_update
  59.     AEDMSG('mw_init')
  60. ENDIF
  61.  
  62. * Set the loop exit for first letter of each prompt,
  63. * or the Return or Esc keys.
  64.  
  65. DO WHILE .NOT. CHR(keypress) $ 'QAEFDqaefd' .AND. ;
  66.                keypress != K_RETURN .AND. keypress != K_ESC
  67.  
  68.     * Highlight the current menubar option
  69.     SETCOLOR(colbarhi)
  70.     aed_col = init_col + (spacing * (aed_item - 1))
  71.     txthigh = "prompt" + STR(aed_item,1)
  72.     @ aed_row , aed_col  SAY &txthigh
  73.  
  74.     * Position a normal size cursor at end of current prompt
  75.     SETCURSOR(SC_NORMAL)
  76.     IF aed_item = 5
  77.         @ aed_row, aed_col + 7 say ''
  78.     ELSEIF aed_item = 2
  79.         @ aed_row, aed_col + 4 say ''
  80.     ELSE
  81.         @ aed_row, aed_col + 5 say ''
  82.     ENDIF
  83.  
  84.     * Save the current settings
  85.     prev_item = aed_item
  86.     old_col = aed_col
  87.  
  88.     * Wait for the operator to press a key.
  89.     keypress = INKEY(0)
  90.     SETCURSOR(SC_NONE)
  91.  
  92.     IF keypress = K_RIGHT
  93.  
  94.         * Move prompt 1 position to right
  95.         aed_item++
  96.         old_col = aed_col
  97.         aed_col = aed_col + spacing
  98.  
  99.         IF aed_item > 5
  100.             * Wrap around back to item 1
  101.             aed_item = 1
  102.             aed_col = init_col
  103.         ENDIF
  104.  
  105.     ELSEIF keypress = K_LEFT
  106.  
  107.         * Move prompt 1 position to left
  108.         aed_item--
  109.         old_col = aed_col
  110.         aed_col = aed_col - spacing
  111.         IF aed_item < 1
  112.            aed_item = 5
  113.            aed_col = init_col +(spacing * 4)
  114.         ENDIF
  115.  
  116.     ELSEIF keypress = K_UP
  117.  
  118.           * Move data base pointer up 1 and exit
  119.           SKIP -1
  120.           IF .NOT. BOF()
  121.               mw_update = .T.
  122.           ELSE
  123.               * Display "Top of file" message
  124.               mw_update = .F.
  125.               GO TOP
  126.               AEDMSG('mw_bof', colblink)
  127.           ENDIF
  128.           browsing = .T.
  129.           EXIT
  130.  
  131.     ELSEIF keypress = K_DOWN
  132.  
  133.           * Move data base pointer down 1 and exit
  134.           SKIP
  135.           IF .NOT. EOF()
  136.               mw_update = .T.
  137.           ELSE
  138.               * Display "Bottom of file" message
  139.               mw_update = .F.
  140.               GO BOTTOM
  141.               AEDMSG('mw_eof', colblink)
  142.           ENDIF
  143.           browsing = .T.
  144.           EXIT
  145.  
  146.     * Reset menubar position if an option letter key was pressed.
  147.  
  148.     ELSEIF CHR(keypress) $ 'Aa'     // Add mode
  149.         aed_item = 2
  150.     ELSEIF CHR(keypress) $ 'Ee'     // Edit mode
  151.         aed_item = 3
  152.     ELSEIF CHR(keypress) $ 'Ff'     // Find mode
  153.         aed_item = 4
  154.     ELSEIF CHR(keypress) $ 'Dd'     // Delete mode
  155.         aed_item = 5
  156.     ELSEIF CHR(keypress) $ 'Qq' .OR. keypress = K_ESC   // Quit
  157.         aed_item = 1
  158.  
  159.     ELSEIF (keypress <= K_F2 .OR. keypress > 256 ;
  160.            .OR. keypress = K_F1) .AND. TYPE('fkeyset') != 'U'
  161.  
  162.         * Call special keys procedure if any function key or
  163.         * alternate key combination is pressed. The variable,
  164.         * "fkeyset" must contain the procedure name.
  165.  
  166.         IF .NOT. EMPTY(fkeyset)
  167.             SETCOLOR(old_color)
  168.             DO &fkeyset WITH 'AEDBAR', 0, '', keypress
  169.         ENDIF
  170.  
  171.     ELSE
  172.         LOOP
  173.  
  174.     ENDIF
  175.  
  176.     * Key is a left or right arrow. Reposition menu bar.
  177.  
  178.     txtnorm = "prompt" + STR(prev_item,1)
  179.     txthigh = "prompt" + STR(aed_item,1)
  180.     SETCOLOR(colbarlo)
  181.     @ aed_row, old_col SAY &txtnorm
  182.     SETCOLOR(colbarhi)
  183.     aed_col = init_col + (spacing * (aed_item-1))
  184.     @ aed_row , aed_col  SAY &txthigh
  185.     old_col = aed_col
  186.  
  187. ENDDO
  188.  
  189. * Reset entry conditions and return the key pressed
  190.  
  191. SETCURSOR(old_cursor)
  192. SETCOLOR(old_color)
  193. RETURN(keypress)
  194.  
  195.  
  196.