home *** CD-ROM | disk | FTP | other *** search
- /*
- Program: MENUV()
- System: GRUMPFISH LIBRARY
- Author: Greg Lief
- Copyright (c) 1988, Greg Lief
- Clipper 5.x version
- Compile instructions: clipper menuv /n/w/a
-
- Creates vertical bounce-bar menu
-
- 5.0 NOTES: MenuV() now expects a multi-dimensional array rather
- than a messy delimited character string. The old
- (primitive) format was:
-
- mainmenu[1] = 'Data Entry$Edit info^DATA_ENTRY()'
- mainmenu[2] = 'Reports$Hard copies^REPORTS()'
- mainmenu[3] = 'Utilities$Misc.^UTILITIES()'
- mainmenu[4] = 'Mastermind$Waste time^POPMM()'
- mainmenu[5] = 'Quit$Exit to DOS'
-
- Out with the crud, and in with the new:
-
- mainmenu := { { 'Data Entry', 'Edit info', 'DATA_ENTRY()'} , ;
- { 'Reports', 'Hard copies', 'REPORTS()' } , ;
- { 'Utilities', 'Miscellaneous', 'UTILITIES()' } , ;
- { 'Mastermind', 'Waste time', 'POPMM()' } , ;
- { 'Quit', 'Exit to DOS'} }
-
- To skip anything, just leave it NIL. For example:
-
- { 'Reports', , } , ;
-
- will display Reports as a menu option, but will not display
- an accompaying message nor execute any function upon selection.
- */
-
- //───── begin preprocessor directives
-
- #include "grump.ch"
-
- //───── end preprocessor directives
-
- function Menuv(marray, ctitle, nboxtype, boxcolor, titlecolor)
- local choice, use_proc, num_ele := len(marray), max_len, ntop, nleft, ;
- nbottom, nright, gfmenuscrn, oldcol, xx, cproc, oldmessc, ;
- oldmessrow, oldwrap
-
- GFSaveEnv()
- //───── establish MESSAGE and WRAP settings
- oldmessc := set(_SET_MCENTER, .T.) // set message to be centered
- //───── if no message row has been established already, set it to 24
- if (oldmessrow := set(_SET_MESSAGE)) == 0
- set(_SET_MESSAGE, 24)
- endif
- oldwrap := set(_SET_WRAP, .T.) // SET WRAP ON
-
- //───── establish defaults if parameters were not passed
- default ctitle to 'Menu'
- default nboxtype to 1
- default boxcolor to ColorSet(C_MENU_UNSELECTED, .T.) + ',' + ;
- ColorSet(C_MENU_SELECTED, .T.)
- default titlecolor to ColorSet(C_MENU_SELECTED, .T.)
-
- //───── we can only accommodate a maximum of 20 menu items
- if num_ele < 21
- //───── determine maximum length for menu selections and draw box accordingly
- max_len := len(ctitle) + 4 // must be at least as wide as the menu title!
- use_proc := .f. // set true if user passed procedures to do
- aeval(marray, { | a | max_len := max(max_len, len(a[1])) } )
- //───── if any procedure names were passed, set USE_PROC true
- use_proc := ( ascan( marray, { | a | a[3] != NIL } ) > 0)
-
- //───── assign left and right column coordinates
- nleft := int((maxcol() + 1 - max_len) / 2)
- nright := nleft + max_len
-
- //───── calculate top and bottom rows for box based on # of options
- nbottom := ( ntop := 12 - int((num_ele + 3) / 2) ) + num_ele + 2
-
- //───── draw the box and any necessary shadows
- if nboxtype > 5 // 3-D effect
- if nboxtype > 10 // super-duper 3-D
- setcolor('W/W')
- scroll(ntop - 2, nleft + 3, nbottom - 2, nright + 4, 0)
- endif
- setcolor('W/N')
- scroll(ntop - 1, nleft + 1, nbottom - 1, nright + 2, 0)
- endif
- @ ntop, nleft-1, nbottom, nright box ;
- BOXFRAMES[if(nboxtype%5 = 0, 5, nboxtype%5)] color boxcolor
- @ ntop, int((maxcol() - 1 - len(ctitle)) / 2) ssay ' ' + ctitle + ' ' ;
- color titlecolor
-
- //───── main loop
- do while .t.
- setcolor(boxcolor)
- //───── first -- display all prompts centered on the screen
- setpos(ntop + 1, nleft)
- for xx = 1 to num_ele
- @ row()+1, int( (80 - len(marray[xx][1])) / 2) ;
- prompt marray[xx][1] message marray[xx][2]
- next
- menu to choice
- //───── exit the loop if they selected the last choice, escaped, or
- //───── no procedures were passed to be done
- if choice == len(marray) .or. choice == 0 .or. ! use_proc
- exit
- else
- //───── execute the function tied to this option if there is one
- if marray[choice][3] != NIL
- cproc := &( "{ | | " + marray[choice][3] + "}" )
- gfmenuscrn := savescreen(0, 0, maxrow(), maxcol())
- eval(cproc)
- restscreen(0, 0, maxrow(), maxcol(), gfmenuscrn)
- endif
- endif
- enddo
- endif
- //───── restore previous message and wrap settings
- set(_SET_MCENTER, oldmessc)
- set(_SET_MESSAGE, oldmessrow)
- set(_SET_WRAP, oldwrap)
- GFRestEnv()
- return choice
-
- * end function MenuV()
- *--------------------------------------------------------------------*
-
- * eof menuv.prg
-