home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 14.6 Displaying Vertical Menu with VERTMENU()
- Author: Greg Lief
- Excerpted from "Clipper 5: A Developer's Guide"
- Copyright (c) 1991 M&T Books
- 501 Galveston Drive
- Redwood City, CA 94063-4728
- (415) 366-3600
- */
-
- //───── NOTE: must compile with the /N option!
-
- #include "error.ch"
- #include "box.ch"
-
- #define TEST // remove this if you don't need the test code
-
- //───── begin stub test program
-
- #ifdef TEST
-
- function main
- local mainmenu := ;
- { { "Data Entry", "Enter data", { || vertmenu(datamenu) } }, ;
- { "Reports", "Hard copy", { || vertmenu(repmenu) } }, ;
- { "Maintenance","Reindex files, etc.",{ || vertmenu(maintmenu) } }, ;
- { "Quit", "See ya later" } }
-
- local datamenu := { { "Customers", , { || cust() } }, ;
- { "Invoices", , { || inv() } }, ;
- { "Vendors", , { || vendors() } }, ;
- { "Exit", "Return to Main Menu" } }
-
- local repmenu := { { "Customer List", , { || custrep() } }, ;
- { "Past Due", , { || pastdue() } }, ;
- { "Weekly Sales", , { || weeksales() } }, ;
- { "Monthly P&L", , { || monthpl() } }, ;
- { "Vendor List", , { || vendorrep() } }, ;
- { "Exit", "Return to Main Menu" } }
-
- local maintmenu := { { "Reindex", "Rebuild index files", { || re_ntx() } }, ;
- { "Backup", "Backup data files" , { || backup() } }, ;
- { "Compress", "Compress data files", { || compress() } }, ;
- { "Exit", "Return to Main Menu" } }
- local newhandler, oldhandler
- /*
- establish custom error handler to handle calls to functions
- that do not exist
- */
- newhandler := { | e | bogusfunc(e, oldhandler) }
- oldhandler := errorblock(newhandler)
- vertmenu(mainmenu)
- return nil
-
-
- /*
- BogusFunc(): custom error handler for bogus function calls
- */
- static function bogusfunc(e, oldhandler)
- if e:gencode() == EG_NOFUNC
- return .t.
- endif
- return eval(oldhandler, e)
-
-
- #endif
-
- //───── end stub test program
-
-
- /*
- VERTMENU(): display vertical menu
- */
- static function vertmenu(menuinfo)
- local choice := 1, num_opts := len(menuinfo), maxwidth := 0, nleft, x, oldscrn
- local ntop, oldwrap := set(_SET_WRAP, .T.), oldctr := set(_SET_MCENTER, .T.)
- local oldmessrow := set(_SET_MESSAGE)
-
- //───── if no message row has been established, use bottom row
- if oldmessrow == 0
- set(_SET_MESSAGE, maxrow() )
- endif
-
- //───── determine longest menu option
- aeval(menuinfo, { | ele | maxwidth := max(maxwidth, len(ele[1])) } )
-
- //───── establish top and left box coordinates
- nleft := int( maxcol() - maxwidth ) / 2
- ntop := 12 - int(num_opts / 2)
- do while choice != 0 .and. choice != num_opts
- oldscrn := savescreen(ntop, nleft - 1, ntop + num_opts + 1, maxcol() - nleft)
- @ ntop, nleft - 1, ntop + num_opts + 1, maxcol() - nleft box B_SINGLE + ' '
- setpos(ntop, nleft)
- for x = 1 to len(menuinfo)
- if len(menuinfo[x]) > 1 .and. menuinfo[x, 2] != NIL
- @ row() + 1, nleft prompt padr(menuinfo[x, 1], maxwidth) ;
- message menuinfo[x, 2]
- else
- @ row() + 1, nleft prompt padr(menuinfo[x, 1], maxwidth)
- endif
- next
- menu to choice
- restscreen(ntop, nleft - 1, ntop + num_opts + 1, maxcol() - nleft, oldscrn)
- //───── execute action block attached to this option if there is one
- if choice > 0 .and. len( menuinfo[ choice ] ) = 3
- eval( menuinfo[choice, 3] )
- endif
- enddo
- //───── restore previous message and wrap settings
- set(_SET_MESSAGE, oldmessrow)
- set(_SET_MCENTER, oldctr)
- set(_SET_WRAP, oldwrap)
- return nil
-
- //───── end of file CHP1406.PRG
-