home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 13.51 HowTo(), a user interface building block function.
- Author: Craig Yellick
- 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!
-
- #command DEFAULT <a> to <b> => <a> := if(<a> = nil, <b>, <a>)
-
- /*
- This #define will cause the testing/demo routine to be included in
- the compile. Delete the line and recompile to get rid of the test
- code and produce a smaller OBJ file. However-- leave the source
- code here so you can more easily test changes and additions in the
- future.
- */
- #define TESTING
-
- #ifdef TESTING
- function HowToTest()
- local answer
-
- // Clean up screen so this demo looks nice.
- setcursor(0)
- cls
-
- HowTo({"If you want to continue, select CONTINUE.", ;
- "If you do not want to continue, select DON'T.", ;
- "If you're not sure, select DON'T."}, .t.)
-
- @ 9, 11 to 12,22 double
- @ 10,12 prompt " CONTINUE "
- @ 11,12 prompt " DON'T "
- menu to answer
-
- HowTo("This is another set of instructions...")
-
- scroll(9, 11, 12, 22, 0)
- @ 10,12 say "Press a key..."
- inkey(0)
-
- HowTo()
-
- setcursor(1)
- cls
- return nil
-
- #endif
-
- /*------------------------------------------------------------------*/
-
- function HowTo(msg_, hasHelp)
- /*
- General-purpose "How To Do It" function, displays specified lines of
- text at bottom of screen that describe what's happening on the screen
- and what the user is expected to do next.
-
- Parameter Description
- --------- -----------
- msg_ Array of message lines. (If single line, a string is ok.)
- hasHelp Logical flag, .t. indicates a help screen is available.
-
- HowTo() called with no parameters removes the last set of messages
- and resets the low row variable so future calls do not mess up the
- screen.
- */
-
- #define HELP_KEY_MSG " [ F1-Help ]"
-
- local i
-
- // Remember the lowest row number the previous messages occupied.
- static previous
-
- // Clear previous message lines (if any).
- if previous <> nil
- scroll(previous, 0)
- endif
-
- // No message, reset
- if msg_ = nil
- previous := nil
-
- // Displaying message lines.
- else
- // As a convenience feature if there's only one line in the
- // message it can be passed as a single string instead of
- // and array.
- if valtype(msg_) = "C"
- msg_ := {msg_}
- endif
-
-
- // Display lines to bottom of screen.
- for i := 0 to (len(msg_) -1)
- @ maxrow() - i, 0 say padr(msg_[ len(msg_) -i ], maxcol())
- next i
- @ row() -1, 0 say replicate(chr(196), maxcol())
- previous := row()
-
- /*
- Display message regarding the help key, if applicable. Clipper's
- "short circuit logic" allows us to check for a valid type on the
- same line as we need the actual value, it won't even consider
- ".and. hasHelp" unless the valtype() function returns true.
- */
- if (valtype(hasHelp) = "L") .and. hasHelp
- setpos(maxrow(), maxcol() -len(HELP_KEY_MSG))
- dispout(HELP_KEY_MSG)
- endif
- endif
-
- return nil
-
- // end of file CHP1351.PRG
-