home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / gt_choos.prg < prev    next >
Text File  |  1993-10-14  |  3KB  |  151 lines

  1. /*
  2.     File......: GT_Choose.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Martin Bryant
  7.     Date......: 04/03/93
  8.     Revision..: 1.0
  9.  
  10.     This is an original work by Martin Bryant and is placed
  11.     in the public domain.
  12.  
  13.     Modification history:
  14.     ---------------------
  15.  
  16.     Rev 1.0 04/03/93
  17.     PD Revision.
  18. */
  19.  
  20. /*  $DOC$
  21.  *  $FUNCNAME$
  22.  *      GT_CHOOSE()
  23.  *  $CATEGORY$
  24.  *      General
  25.  *  $ONELINER$
  26.  *      List an array and allow selection.
  27.  *  $SYNTAX$
  28.  *      GT_Choose(<aOptions>,[<cTitle>],[<nTop>], ;
  29.  *          [<nLeft>],[<nBottom>],[<nRight>],[<aValid>], ;
  30.  *          [<nStartItem>],[<nStartRow>])
  31.  *  $ARGUMENTS$
  32.  *      <aOptions> is the array to list.
  33.  *
  34.  *      <cTitle> is an optional title.
  35.  *
  36.  *      <nTop>,<nLeft>,<nBottom>,<nRight> Window Co-ords.
  37.  *
  38.  *      <aValid> an array of logical values matching the
  39.  *      options list.
  40.  *
  41.  *      <nStartItem> is the entry point for the array.
  42.  *
  43.  *      <nStartRow> is the row of the window to start on.
  44.  *  $RETURNS$
  45.  *      nSelected
  46.  *  $DESCRIPTION$
  47.  *      Basically this is a tarted up ACHOICE(). Allowing
  48.  *      a box around it, title and proper key handling.
  49.  *  $EXAMPLES$
  50.  *      nOption := 1
  51.  *      nOption := Gt_Choose({'1. Start','2. End  ','3.Exit '}, ;
  52.  *          'Now what?',02,02,NIL,NIL,NIL,nOption)
  53.  *  $SEEALSO$
  54.  *      GT_BROWSE()
  55.  *  $INCLUDE$
  56.  *
  57.  *  $END$
  58.  */
  59.  
  60. #include "GtClippe.ch"
  61. #include "aChoice.ch"
  62.  
  63. FUNCTION GT_Choose(aOptions,cTitle,nTop,nLeft,nBottom, ;
  64.     nRight,aValid,nStartItem,nStartRow)
  65.  
  66. LOCAL nWidth := 0
  67. LOCAL nReturn := 0
  68.  
  69. Default aOptions to {}
  70. Default cTitle to ''
  71. Default nTop to 04
  72. Default nLeft to 02
  73. Default nBottom to MAXROW()-01
  74. Default nRight to MAXCOL()-02
  75. Default aValid to .T.
  76. Default nStartItem to 1
  77. Default nStartRow to 1
  78.  
  79. //  No list
  80. IF LEN(aOptions) < 1
  81.     RETURN(0)
  82. ENDIF
  83.  
  84. //  Size window
  85. nWidth := nRight - nLeft - 1
  86.  
  87. //  Draw window
  88. GT_Window(nTop,nLeft,nBottom,nRight,BOX_DS,SETCOLOR())
  89. @ nTop + 02, nLeft SAY SUBSTR(BOX_DS,11,1)
  90. @ nTop + 02, nRight SAY SUBSTR(BOX_DS,10,1)
  91. @ nTop + 02, nLeft + 01 SAY REPLICATE(SUBSTR(BOX_DS,2,1), ;
  92.     nWidth)
  93.  
  94. @ nTop + 01, nLeft + 01 SAY cTitle
  95.  
  96. nReturn := ACHOICE(nTop+3,nLeft+1,nBottom-1,nRight-1 ;
  97.                     ,aOptions,aValid,'Key_Control' ;
  98.                     ,nStartItem,nStartRow)
  99.  
  100. /*
  101.     End of GT_Choose()
  102. */
  103. RETURN(nReturn)
  104. /*
  105. ***********************************************************
  106. */
  107. STATIC FUNCTION Key_Control(nMode,nInlist,nInWin)
  108.  
  109. LOCAL nReturn := AC_CONT
  110. LOCAL nKey := LASTKEY()
  111.  
  112. Default nMode to AC_NOITEM
  113. Default nInlist to 0
  114. Default nInWin to 0
  115.  
  116. DO CASE
  117.     CASE nMode = AC_EXCEPT
  118.         // Some key that ACHOICE does not understand
  119.         DO CASE
  120.             CASE nKey = K_ENTER
  121.                 // Select
  122.                 nReturn := AC_SELECT
  123.  
  124.             CASE nKey = K_ESC
  125.                 // Escape
  126.                 nReturn := AC_ABORT
  127.  
  128.             CASE ISALPHA(CHR(nKey))
  129.                 // Letter to search For
  130.                 nReturn := AC_GOTO
  131.  
  132.             OTHERWISE
  133.                 // I dunno ?
  134.  
  135.         ENDCASE
  136.  
  137.     CASE nMode = AC_NOITEM
  138.         // No items to select
  139.         nReturn := AC_ABORT
  140.  
  141.     OTHERWISE
  142.         // AC_IDLE, AC_HITTOP, AC_HITBOT Do nothing special
  143.  
  144. ENDCASE
  145.  
  146. /*
  147.     End of Key_Control()
  148. */
  149. RETURN(nReturn)
  150.  
  151.