home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / DISPMSG.PRG < prev    next >
Text File  |  1991-08-16  |  8KB  |  223 lines

  1. /*
  2.  * File......: DISPMSG.PRG
  3.  * Author....: Paul Ferrara
  4.  * CIS ID....: 76702,556
  5.  * Date......: $Date:   15 Aug 1991 23:05:14  $
  6.  * Revision..: $Revision:   1.2  $
  7.  * Log file..: $Logfile:   E:/nanfor/src/dispmsg.prv  $
  8.  *
  9.  * This function is an original work by Paul Ferrar and is placed in the
  10.  * public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   E:/nanfor/src/dispmsg.prv  $
  16.  * 
  17.  *    Rev 1.2   15 Aug 1991 23:05:14   GLENN
  18.  * Forest Belt proofread/edited/cleaned up doc
  19.  * 
  20.  *    Rev 1.1   14 Jun 1991 19:51:36   GLENN
  21.  * Minor edit to file header
  22.  * 
  23.  *    Rev 1.0   01 Apr 1991 01:01:12   GLENN
  24.  * Nanforum Toolkit
  25.  *
  26.  */
  27.  
  28.  
  29. /*  $DOC$
  30.  *  $FUNCNAME$
  31.  *     FT_DISPMSG()
  32.  *  $CATEGORY$
  33.  *     Menus/Prompts
  34.  *  $ONELINER$
  35.  *     Display a message and optionally waits for a keypress
  36.  *  $SYNTAX$
  37.  *     FT_DISPMSG( <aMessageArray>, [ <cKey2Check> ],
  38.  *                 [ <nTopBoxRow> ], [ <nLeftBoxColumn> ],
  39.  *                 [ <cBoxType> ], [ <lShadow> ] ) -> lKeyMatch
  40.  *  $ARGUMENTS$
  41.  *     <aMessageArray> is a multidimensional array of messages to be
  42.  *     displayed and the color attributes for each message.
  43.  *
  44.  *     The first dimension of the array contains one or more elements,
  45.  *     each representing one line in the message box, up to the maximum
  46.  *     number of rows on the screen.
  47.  *
  48.  *     The second dimension of the array contains a color attribute for
  49.  *     the corresponding element in dimension one, plus one additional
  50.  *     element for the color of the box border.  Dimension two will
  51.  *     always contain one more element than dimension one.  If an
  52.  *     attribute is omitted, the last color selected will be used.
  53.  *
  54.  *     <Key2Check> is a character string of one or more keys to check
  55.  *     for.  If omitted, the message is displayed and control is returned
  56.  *     to the calling procedure.  If one character is specified,
  57.  *     FT_DISPMSG() waits for one keypress, restores the screen and
  58.  *     returns.  If multiple characters are specified, FT_DISPMSG()
  59.  *     remains in a loop until one of the specified keys has been
  60.  *     pressed, then restores the screen and returns.
  61.  *
  62.  *     <nTopBoxRow> is the upper row for the message box.  If omitted, the
  63.  *     box is centered vertically.
  64.  *
  65.  *     <nLeftBoxColumn> is the leftmost column for the box.  If omitted, the
  66.  *     box is centered horizontally.
  67.  *
  68.  *     <cBoxType> is a string of characters or a variable for the box
  69.  *     border.  See the @...BOX command.  If omitted, a double box is
  70.  *     drawn.
  71.  *
  72.  *     <lShadow> is a logical variable.  If true (.T.) or omitted, it
  73.  *     uses FT_SHADOW() to add a transparent shadow to the box.  If
  74.  *     false (.F.), the box is drawn without the shadow.
  75.  *  $RETURNS$
  76.  *     If <Key2Check> is not specified, FT_DISPMSG() will return false
  77.  *     (.F.).
  78.  *
  79.  *     If <Key2Check> is a one-character string, FT_DISPMSG() will return
  80.  *     true (.T.) if the user presses that key, or false (.F.) if any
  81.  *     other key is pressed.
  82.  *
  83.  *     If <Key2Check> consists of multiple characters, it will lock the
  84.  *     user in a loop until one of those keys are pressed and return the
  85.  *     INKEY() value of the keypress.
  86.  *  $DESCRIPTION$
  87.  *     FT_DISPMSG() is a multi-purpose pop-up for user messages.
  88.  *     Multiple lines may be displayed, each with a different attribute.
  89.  *     The box will be automatically centered on the screen, or the row
  90.  *     and/or column can be specified by the programmer.  It also centers
  91.  *     each line of the message within the box.
  92.  *  $EXAMPLES$
  93.  *     The following example displays a simple two-line message
  94.  *     and returns immediately to the calling routine.
  95.  *
  96.  *        FT_DISPMSG( { { "Printing Report"                    , ;
  97.  *                        "Press [ESC] To Interrupt" }         , ;
  98.  *                      { "W+/B*", "W/B", "GR+/B" } } )
  99.  *
  100.  *     The next example displays a message and waits for a key press.
  101.  *
  102.  *        FT_DISPMSG( { { "Press [D] To Confirm Deletion"      , ;
  103.  *                        "Or Any Other Key To Abort" }        , ;
  104.  *                      { "W+/B", "W+/B", "GR+/B" } }          , ;
  105.  *                      "D" )
  106.  *
  107.  *     The next example displays a one-line message centered on row 5
  108.  *     and returns to the calling procedure.
  109.  *
  110.  *        FT_DISPMSG( { { "Please Do Not Interrupt" }   , ;
  111.  *                      { "W+/B", "GR+/B" } }          , ;
  112.  *                      , 5, )
  113.  *  $END$
  114.  */
  115.  
  116.  
  117. #ifdef FT_TEST
  118.  
  119.    PROCEDURE DUMMY
  120.    LOCAL X
  121.  
  122.    // EXAMPLE #1 - DISPLAYS BOX AND RETURNS
  123.    SETCOLOR( "W/N" )
  124.    CLS
  125.    FT_DISPMSG( { { "This is message #1"                 , ;
  126.                    "This is another message - line 2"   , ;
  127.                    "This is the third line, etc" }      , ;
  128.                  { "W+/B", "W/B", "R/BG*", "GR+/B" } } )
  129.  
  130.    FT_DISPMSG( { { "Press Any Key To Continue" }, { "W/B", "W+/B" } }," ",20,0 )
  131.  
  132.    // example #2 - displays box and waits for input
  133.    // then restores the screen and returns
  134.    IF FT_DISPMSG( { { "Press [D] To Delete"                , ;
  135.                       "Or Any Other Key To Abort" }        , ;
  136.                     { "W+/R*", "W/R", "W+/R" } }           , ;
  137.                       "D", 5 , 5 )
  138.       FT_DISPMSG( { { 'You Pressed "D"', "Press Any Key To Continue" }, { "W+/B*", "W/B", "W+/B" } }," ",19,0 )
  139.    ELSE
  140.       FT_DISPMSG( { { 'You Did NOT Press "D"', "Press Any Key To Continue" }, { "W+/B*", "W/B", "W+/B" } }," ",19,0 )
  141.    ENDIF
  142.  
  143.    // example #3 - displays box and waits for input / multiple keys
  144.    // then restores the screen and returns
  145.    x= FT_DISPMSG( { { "Press [D] To Delete"                   , ;
  146.                       "[A] To Add New Record"                 , ;
  147.                       "[F] To Find A Record"                  , ;
  148.                       "Or [ESCape] To Abort"  }               , ;
  149.                     { "N/G",,,, "W+/G" } }                    , ;
  150.                       "DAF"+CHR(27) )
  151.    IF x == 27
  152.       FT_DISPMSG( { { 'You Pressed ESCAPE', "Press Any Key To Continue" }, { "W+/B*", "W/B", "W+/B" } }," ",19,0 )
  153.    ELSE
  154.       FT_DISPMSG( { { 'You Pressed '+ CHR(x), "Press Any Key To Continue" }, { "W+/B*", "W/B", "W+/B" } }," ",19,0 )
  155.    ENDIF
  156.  
  157.    QUIT
  158.  
  159. #endif
  160.  
  161.  
  162.  
  163. FUNCTION FT_DISPMSG( aInfo, cKey, nTop, nLeft, cBoxType, lShadow )
  164.  
  165.    LOCAL lRtnVal := .f., nWidest := 0, nRight, nBottom
  166.    LOCAL cOldScreen, cOldCursor, cOldColor, i, nOption
  167.  
  168.    AEVAL( aInfo[1], {|x| nWidest := MAX( nWidest, LEN( x ) ) } )
  169.  
  170.    IF nLeft == NIL
  171.       nLeft := (MAXCOL() - nWidest - 4) / 2
  172.    ENDIF
  173.    nRight := nLeft + nWidest + 5
  174.  
  175.    IF nTop == NIL
  176.       nTop := (MAXROW() - LEN( aInfo[1] ) - 2) / 2 + 1
  177.    ENDIF
  178.    nBottom := nTop + LEN( aInfo[1] ) + 1
  179.  
  180.    cBoxType := IF( cBoxType == NIL, "╔═╗║╝═╚║ ", cBoxType )
  181.  
  182.    cOldScreen := SAVESCREEN( nTop, nLeft, nBottom+1, nRight+2 )
  183.  
  184.    cOldCursor := SETCURSOR( 0 )
  185.  
  186.    IF lShadow == NIL .OR. lShadow
  187.       FT_SHADOW( nTop, nLeft, nBottom, nRight )
  188.    ENDIF
  189.  
  190.    // draw box
  191.    cOldColor := SETCOLOR( aInfo[ 2, LEN( aInfo[2] ) ] )
  192.    @ nTop, nLeft, nBottom, nRight BOX cBoxType
  193.  
  194.    // display messages
  195.    FOR i := 1 TO LEN( aInfo[1] )
  196.       IF aInfo[ 2, i ] != NIL
  197.          SETCOLOR( aInfo[ 2, i ] )
  198.       ENDIF
  199.       @ nTop+i,                                       ;
  200.         nLeft+( ( nWidest-LEN(aInfo[1,i]) ) / 2 ) + 3 ;
  201.         SAY aInfo[1,i]
  202.    NEXT
  203.  
  204.    IF cKey != NIL
  205.       IF LEN( cKey ) == 1
  206.          nOption := INKEY(0)
  207.          IF UPPER( CHR( nOption) ) == cKey
  208.             lRtnVal := .t.
  209.          ENDIF
  210.       ELSE
  211.          nOption := 0
  212.          DO WHILE AT( UPPER( CHR( nOption ) ), UPPER( cKey ) ) == 0
  213.             nOption := INKEY(0)
  214.          ENDDO
  215.          lRtnVal := nOption  //TGFWT! (Thank God For Weak Typing)
  216.       ENDIF
  217.       RESTSCREEN( nTop, nLeft, nBottom+1, nRight+2, cOldScreen )
  218.    ENDIF
  219.  
  220.    SETCOLOR( cOldColor )
  221.    SETCURSOR( cOldCursor )
  222.    RETURN lRtnVal
  223.