home *** CD-ROM | disk | FTP | other *** search
- /*
- Listing 13.36 YN(), a user interface building block function. Calls
- should be made through the YESNO user-defined command
- found in YESNO.CH.
- NOTE: makes external calls to:
-
- ColorInit() and ColorSet(), which are contained in the
- file CHP1313.PRG
-
- SaveEnv() and RestEnv(), which are contained in the file
- CHP1201.PRG (chapter 12)
-
- 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!
-
- // Required for using the YESNO command.
- #include "yesno.ch"
-
- // Required for using the ColorSet() function.
- #include "colors.ch"
-
- // Other handy programming things.
- #include "inkey.ch"
- #include "box.ch"
- #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 YNTest()
- local answer
-
- // Must be called prior to using ColorSet().
- ColorInit()
-
- // Clean up screen so this demo looks nice.
- setcursor(0)
- cls
-
- yesno "Is this a simple YESNO example?" into answer
-
- yesno "You said " +if(answer, "YES", "NO") +"?" ;
- at 8,20 into answer
-
- yesno "Do you like this color?" ;
- color C_WARNING into answer at 16,40
-
- setcursor(1)
- cls
- return nil
-
- #endif // end stub test program
-
-
-
- /*------------------------------------------------------------------*/
-
- function YesNoMenu(r, c, msg, clr)
- /*
- General-purpose Yes/No prompt function.
-
- Parameter Description
- --------- -----------
- r Starting row, default is center of screen.
- c Starting column, default is center of screen.
- msg Message to display as a prompt.
- clr Color number to use, default is current color.
-
- Note: Color selection for this function is handled by
- the ColorSet() function.
- */
-
- local response // User's response
- local r2, c2, offset // Help with box coordinates
- local oldScr, oldCur, oldClr // Original screen, cursor, color.
- local oldR, oldC // Original row and column
- local pYes, pNo // Prompts for "Yes" and "No"
-
- // Make sure all parameters have reasonable default values.
- default r to (maxrow() / 2) -2
- default c to (maxcol() - len(msg)) / 2
- default clr to C_NORMAL
-
- // Prompts to display for choices.
- pYes := "YES"
- pNo := "NO"
-
- /*
- Calculate ending box coordinates. Box width must be able to
- accommodate the longest of either the prompt message or the
- YES and NO selections.
- */
- r2 := r +3
- c2 := c +len(msg) +1
- c2 := max(c2, c +len(pYes) +2 +len(pNo))
-
- // Calculate how far to indent Yes/No prompts within the box.
- offset := ((c2 -c) -(len(pYes) +2 +len(pNo))) /2
-
- // Save existing screen, color etc.
- SaveEnv()
-
- // Clear the area and draw a box
- dispbox(r, c, r2, c2, B_SINGLE + ' ')
-
- // Display message and Yes/No prompts, wait for response.
- @ r +1, c +1 say msg
- @ r +2, c +1 +offset prompt pYes
- @ r +2, col() +2 prompt pNo
- menu to response
-
- // Restore original screen, color etc before returning.
- RestEnv()
-
- return (response == 1)
-
- // end of file CHP1336.PRG
-