home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a012 / 1.ddi / CHAP14.EXE / CHP1405.PRG < prev    next >
Encoding:
Text File  |  1991-06-12  |  2.0 KB  |  69 lines

  1. /*
  2.    Listing 14.5 Displaying Horizontal Menu with HORIZMENU()
  3.    Author: Greg Lief
  4.    Excerpted from "Clipper 5: A Developer's Guide"
  5.    Copyright (c) 1991 M&T Books
  6.                       501 Galveston Drive
  7.                       Redwood City, CA 94063-4728
  8.                       (415) 366-3600
  9. */
  10.  
  11. //───── NOTE: must compile with the /N option!
  12.  
  13. #define TEST            // remove this if you don't need the test code
  14.  
  15. //───── begin stub test program
  16.  
  17. #ifdef TEST
  18.  
  19. function main 
  20. local sel := 1 
  21. do while sel != 0 .and. sel != 4 
  22.    sel = horizmenu(20, 0, ; 
  23.    { { "Data Entry", "Enter data, naturally", { || dataentry() } } , ; 
  24.      { "Reports", "Share your information"  , { || reports() } }   , ; 
  25.      { "Maintenance", "Reindex files etc"   , { || maint() } }     , ; 
  26.      { "Quit", "Take a siesta" } } ) 
  27. enddo 
  28. return nil 
  29.  
  30. #endif
  31.  
  32. //───── end stub test program
  33.  
  34. /* 
  35.    HORIZMENU() - display horizontal menu 
  36. */ 
  37. #define SPACING  2          // controls spacing between each menu option
  38.  
  39. function horizmenu(nrow, ncol, prompts) 
  40. local choice := 1, x, oldwrap := set(_SET_WRAP, .T.), ; 
  41.       oldmessrow, oldcursor := setcursor(0) // turn off cursor 
  42.  
  43. //───── if no message row has been established, use row beneath menu options
  44. if (oldmessrow := set(_SET_MESSAGE)) == 0 
  45.    set(_SET_MESSAGE, nrow + 1) 
  46. endif 
  47. //───── loop through menu prompts array and display each
  48. for x = 1 to len(prompts) 
  49.    if len(prompts[x]) > 1
  50.       @ nrow, ncol prompt prompts[x, 1] message padr(prompts[x, 2], maxcol()) 
  51.    else 
  52.       @ nrow, ncol prompt prompts[x, 1] 
  53.    endif 
  54.    ncol += len(prompts[x, 1]) + SPACING 
  55. next 
  56. menu to choice 
  57.  
  58. //───── if there is an action block for this menu option, run it now
  59. if choice != 0 .and. len(prompts[choice]) == 3
  60.    eval(prompts[choice, 3]) 
  61. endif 
  62. //───── restore previous message and wrap settings
  63. set(_SET_MESSAGE, oldmessrow) 
  64. set(_SET_WRAP, oldwrap) 
  65. setcursor(oldcursor) 
  66. return(choice)
  67.  
  68. //───── end of file CHP1405.PRG
  69.