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

  1. /*
  2.    Listing 14.6 Displaying Vertical Menu with VERTMENU()
  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. #include "error.ch"
  14. #include "box.ch"
  15.  
  16. #define TEST            // remove this if you don't need the test code
  17.  
  18. //───── begin stub test program
  19.  
  20. #ifdef TEST
  21.  
  22. function main 
  23. local mainmenu := ; 
  24.     { { "Data Entry", "Enter data",         { || vertmenu(datamenu)  } }, ; 
  25.       { "Reports",    "Hard copy",          { || vertmenu(repmenu)   } }, ; 
  26.       { "Maintenance","Reindex files, etc.",{ || vertmenu(maintmenu) } }, ; 
  27.       { "Quit", "See ya later" } } 
  28.  
  29. local datamenu := { { "Customers", , { || cust()    } }, ; 
  30.                     { "Invoices",  , { || inv()     } }, ; 
  31.                     { "Vendors",   , { || vendors() } }, ; 
  32.                     { "Exit", "Return to Main Menu" } } 
  33.  
  34. local repmenu :=  { { "Customer List", , { || custrep()   } }, ; 
  35.                     { "Past Due",      , { || pastdue()   } }, ; 
  36.                     { "Weekly Sales",  , { || weeksales() } }, ; 
  37.                     { "Monthly P&L",   , { || monthpl()   } }, ; 
  38.                     { "Vendor List",   , { || vendorrep() } }, ; 
  39.                     { "Exit", "Return to Main Menu" } } 
  40.  
  41. local maintmenu := { { "Reindex",  "Rebuild index files", { || re_ntx()   } }, ; 
  42.                      { "Backup",   "Backup data files"  , { || backup()   } }, ; 
  43.                      { "Compress", "Compress data files", { || compress() } }, ; 
  44.                      { "Exit", "Return to Main Menu" } } 
  45. local newhandler, oldhandler
  46. /*
  47.    establish custom error handler to handle calls to functions
  48.    that do not exist
  49. */
  50. newhandler := { | e | bogusfunc(e, oldhandler) }
  51. oldhandler := errorblock(newhandler)
  52. vertmenu(mainmenu) 
  53. return nil 
  54.  
  55.  
  56. /*
  57.    BogusFunc(): custom error handler for bogus function calls
  58. */
  59. static function bogusfunc(e, oldhandler)
  60. if e:gencode() == EG_NOFUNC
  61.    return .t.
  62. endif
  63. return eval(oldhandler, e)
  64.  
  65.  
  66. #endif
  67.  
  68. //───── end stub test program
  69.  
  70.  
  71. /* 
  72.    VERTMENU(): display vertical menu 
  73. */ 
  74. static function vertmenu(menuinfo) 
  75. local choice := 1, num_opts := len(menuinfo), maxwidth := 0, nleft, x, oldscrn 
  76. local ntop, oldwrap := set(_SET_WRAP, .T.), oldctr := set(_SET_MCENTER, .T.) 
  77. local oldmessrow := set(_SET_MESSAGE) 
  78.  
  79. //───── if no message row has been established, use bottom row
  80. if oldmessrow == 0
  81.    set(_SET_MESSAGE, maxrow() ) 
  82. endif 
  83.  
  84. //───── determine longest menu option
  85. aeval(menuinfo, { | ele | maxwidth := max(maxwidth, len(ele[1])) } ) 
  86.  
  87. //───── establish top and left box coordinates
  88. nleft := int( maxcol() - maxwidth ) / 2
  89. ntop  := 12 - int(num_opts / 2)
  90. do while choice != 0 .and. choice != num_opts 
  91.    oldscrn := savescreen(ntop, nleft - 1, ntop + num_opts + 1, maxcol() - nleft)
  92.    @ ntop, nleft - 1, ntop + num_opts + 1, maxcol() - nleft box B_SINGLE + ' ' 
  93.    setpos(ntop, nleft)
  94.    for x = 1 to len(menuinfo) 
  95.       if len(menuinfo[x]) > 1 .and. menuinfo[x, 2] != NIL
  96.          @ row() + 1, nleft prompt padr(menuinfo[x, 1], maxwidth) ; 
  97.                             message menuinfo[x, 2] 
  98.       else 
  99.          @ row() + 1, nleft prompt padr(menuinfo[x, 1], maxwidth) 
  100.       endif 
  101.    next 
  102.    menu to choice 
  103.    restscreen(ntop, nleft - 1, ntop + num_opts + 1, maxcol() - nleft, oldscrn) 
  104.    //───── execute action block attached to this option if there is one
  105.    if choice > 0 .and. len( menuinfo[ choice ] ) = 3
  106.       eval( menuinfo[choice, 3] ) 
  107.    endif 
  108. enddo 
  109. //───── restore previous message and wrap settings
  110. set(_SET_MESSAGE, oldmessrow) 
  111. set(_SET_MCENTER, oldctr) 
  112. set(_SET_WRAP, oldwrap) 
  113. return nil
  114.  
  115. //───── end of file CHP1406.PRG
  116.