home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 14.12 LITE_MENU() Example
- 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
- */
-
- #include "inkey.ch"
- #include "mymenu.ch" // contains modified @..PROMPT and MENU TO
-
-
- #define TEST // remove this if you don't need the test code
-
- //───── begin stub test program
-
- #ifdef TEST
-
- function main
- local menulist, sel
- cls
- setcolor('w/b, n/bg')
- @ 0, 0 say "Press F1 to see where you are"
- set key K_F1 to helpme
- do while sel != 0 .and. sel != 7
- @ 9,33 prompt padr('Customers', 14) message 'Add/edit customer data' ;
- action custfile()
- @ 10,33 prompt padr('Invoices ', 14) message 'Add/edit invoice data' ;
- action invfile()
- @ 11,33 prompt padr('Vendors', 14) message 'Add/edit vendor data' ;
- action vendorfile()
- @ 12,33 prompt padr('Reports', 14) action reports()
- @ 13,33 prompt 'reconci~Liation' action reconcile()
- @ 14,33 prompt 'Maintenance ' message "Rebuild indices, backup, etc." ;
- action maint()
- @ 15,33 prompt padr('Quit', 14)
- menu to sel
- enddo
- return nil
-
-
- static function helpme(p, l, v)
- output("Proc: " + p + space(5) + "Var: " + v + space(5) + ;
- "Current option: " + substr(v, at('[', v) + 1, 1))
- output("Grumpfish Library features excellent context-specific help development!")
- return nil
-
- static function custfile
- output("You selected the Customers option")
- return nil
-
-
- static function invfile
- output("You selected the Invoices option")
- return nil
-
-
- static function vendorfile
- output("You selected the Vendors option")
- return nil
-
-
- static function reports
- output("You selected the Reports option")
- return nil
-
-
- static function reconcile
- output("You selected the Reconciliation option")
- return nil
-
-
- static function maint
- output("You selected the Maintenance option")
- return nil
-
-
- static function output(msg)
- @ maxrow(), 0 say padc(msg, maxcol() + 1) color '+gr/r'
- inkey(0)
- scroll(maxrow(), 0, maxrow(), maxcol(), 0)
- return nil
-
- #endif
-
- //───── end stub test program
-
-
-
- //───── these manifest constants are for easy identification
- //───── of levels in the multi-dimensional array
- #define ROW 1
- #define COL 2
- #define PROMPT 3
- #define MESSAGE 4
- #define ACTION 5
-
- /*
- LITE_MENU() -- alternate menu system
- */
- function lite_menu(marray, selection, varname)
- local num_elem := len(marray), xx, nkey := 0, triggerltr := [], ;
- fallout := .f., oldmsgctr := set(_SET_MCENTER, .T.), ptr, ;
- mess_row := set(_SET_MESSAGE), oldcursor := setcursor(0), ;
- oldcolor := setcolor(), plaincolor, hilitcolor
-
- //───── if MESSAGE row was never set, use the bottom row of screen
- if mess_row == 0
- mess_row := maxrow()
- endif
-
- //───── set default colors for unselected and selected options
- xx = at(',', oldcolor)
- plaincolor = substr(oldcolor, 1, xx - 1)
- hilitcolor = substr(oldcolor, xx + 1)
-
- /*
- determine initial highlighted item default to 1 -- also perform
- error-checking to ensure they didn't specify an invalid selection
- */
- if selection == NIL .or. (selection < 1 .or. selection > num_elem)
- selection = 1
- endif
-
- // build the string containing available letters for selection
- for xx = 1 to num_elem
- /*
- the default is to add the first non-space character.
- However, if there is a tilde embedded in this menu
- option, use the letter directly following it.
- */
- if (ptr := at("~", marray[xx, PROMPT]) ) > 0
- triggerltr += upper(substr(marray[xx, PROMPT], ptr + 1, 1))
- else
- triggerltr += upper(left(marray[xx, PROMPT], 1))
- endif
- ShowOption(marray[xx], plaincolor)
- next
- //───── commence main key-grabbing loop
- do while nkey != K_ENTER .and. nkey != K_ESC
- // display current option
- @ marray[selection, ROW], marray[selection, COL] say ;
- strtran(marray[selection, PROMPT], "~", "") color hilitcolor
- /* display corresponding message if there is one */
- setcolor(plaincolor)
- if marray[selection, MESSAGE] == NIL
- scroll(mess_row, 0, mess_row, maxcol(), 0)
- else
- @ mess_row, 0 say padc(marray[selection, MESSAGE], maxcol() + 1)
- endif
- if fallout
- exit
- else
- nkey := inkey(0)
- do case
-
- /*
- use SETKEY() to see if an action block attached to the last
- keypress -- if it returns anything other than NIL, then you
- know that the answer is a resounding YES!
- */
- case setkey(nkey) != NIL
- /*
- pass action block the name of the previous procedure,
- along with the name of the variable referenced in the
- MENU TO statement and the current highlighted menu
- option (this means that you can tie a help screen to
- each individual menu option; try that with MENU TO)
- */
- eval(setkey(nkey), procname(1), procline(1), varname + ;
- "[" + ltrim(str(selection)) + "]")
-
- /* go down one line, observing wrap-around conventions */
- case nkey == K_DOWN
- ShowOption(marray[selection], plaincolor)
- if selection == num_elem
- selection := 1
- else
- selection++
- endif
-
- /* go up one line, observing wrap-around conventions */
- case nkey == K_UP
- ShowOption(marray[selection], plaincolor)
- if selection == 1
- selection := num_elem
- else
- selection--
- endif
-
- /* jump to top option */
- case nkey == K_HOME
- /* no point in changing color if we're already there */
- if selection != 1
- ShowOption(marray[selection], plaincolor)
- selection := 1
- endif
-
- /* jump to bottom option */
- case nkey == K_END
- /* no point in changing color if we're already there */
- if selection != num_elem
- ShowOption(marray[selection], plaincolor)
- selection := num_elem
- endif
-
- /* first letter - jump to appropriate option */
- case upper(chr(nkey)) $ triggerltr
- ShowOption(marray[selection], plaincolor)
- selection := at(upper(chr(nkey)), triggerltr)
- fallout := .t.
-
- endcase
- endif
- enddo
- //───── if there is an action block attached to this selection, run it
- if lastkey() != K_ESC
- if marray[selection, ACTION] != NIL
- eval(marray[selection, ACTION])
- endif
- else
- selection := 0 // since they Esc'd out, return a zero
- endif
- setcursor(oldcursor)
- set(_SET_MCENTER, oldmsgctr) // reset SET MESSAGE CENTER
- setcolor(oldcolor)
- return nil
-
-
- /*
- Function: ShowOption()
- Purpose: Display current prompt in mixed colors
- */
- static function ShowOption(item, plaincolor)
- local ptr := at("~", item[PROMPT])
- if ptr > 0
- @ item[ROW], item[COL] say strtran(item[PROMPT], "~", "") color plaincolor
- @ item[ROW], item[COL] + ptr - 1 say ;
- substr(item[PROMPT], ptr + 1, 1) color '+' + plaincolor
- else
- @ item[ROW], item[COL] say left(item[PROMPT], 1) color '+' + plaincolor
- dispout(substr(item[PROMPT], 2), plaincolor)
- endif
- return nil
-
- //───── end of file CHP1412.PRG
-