home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 14.5 Displaying Horizontal Menu with HORIZMENU()
- 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!
-
- #define TEST // remove this if you don't need the test code
-
- //───── begin stub test program
-
- #ifdef TEST
-
- function main
- local sel := 1
- do while sel != 0 .and. sel != 4
- sel = horizmenu(20, 0, ;
- { { "Data Entry", "Enter data, naturally", { || dataentry() } } , ;
- { "Reports", "Share your information" , { || reports() } } , ;
- { "Maintenance", "Reindex files etc" , { || maint() } } , ;
- { "Quit", "Take a siesta" } } )
- enddo
- return nil
-
- #endif
-
- //───── end stub test program
-
- /*
- HORIZMENU() - display horizontal menu
- */
- #define SPACING 2 // controls spacing between each menu option
-
- function horizmenu(nrow, ncol, prompts)
- local choice := 1, x, oldwrap := set(_SET_WRAP, .T.), ;
- oldmessrow, oldcursor := setcursor(0) // turn off cursor
-
- //───── if no message row has been established, use row beneath menu options
- if (oldmessrow := set(_SET_MESSAGE)) == 0
- set(_SET_MESSAGE, nrow + 1)
- endif
- //───── loop through menu prompts array and display each
- for x = 1 to len(prompts)
- if len(prompts[x]) > 1
- @ nrow, ncol prompt prompts[x, 1] message padr(prompts[x, 2], maxcol())
- else
- @ nrow, ncol prompt prompts[x, 1]
- endif
- ncol += len(prompts[x, 1]) + SPACING
- next
- menu to choice
-
- //───── if there is an action block for this menu option, run it now
- if choice != 0 .and. len(prompts[choice]) == 3
- eval(prompts[choice, 3])
- endif
- //───── restore previous message and wrap settings
- set(_SET_MESSAGE, oldmessrow)
- set(_SET_WRAP, oldwrap)
- setcursor(oldcursor)
- return(choice)
-
- //───── end of file CHP1405.PRG
-