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

  1. /*
  2.     File......: GT_Memo.prg
  3.     Author....: Martin Bryant
  4.     BBS.......: The Dark Knight Returns
  5.     Net/Node..: 050/069
  6.     User Name.: Martin Bryant
  7.     Date......: 05/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 05/03/93
  17.     PD Revision.
  18.  
  19.     Rev 1.1 17/03/93
  20.     Leave on screen option.
  21. */
  22.  
  23. /*  $DOC$
  24.  *  $FUNCNAME$
  25.  *       GT_MEMO()
  26.  *  $CATEGORY$
  27.  *       Array
  28.  *  $ONELINER$
  29.  *       Display a Memo in a box on the screen
  30.  *  $SYNTAX$
  31.  *       GT_Memo(<cText>,[<cTitle>],[<cColour>], ;
  32.  *           [<cBoxLines>],[<nTop>],[<nLeft>],[<nBottom>], ;
  33.  *           [<nRight>],[<lEdit>],[<lScreen>]) => cText
  34.  *  $ARGUMENTS$
  35.  *       <cText> is the Memo to display.
  36.  *       <cTitle> is an optional title for the window.
  37.  *       <cColour> is an optional colour string.
  38.  *       <cBoxLines> are the optional box lines to use.
  39.  *       <nTop>,<nLeft>,<nBottom>,<nRight> are the
  40.  *       corners of the box. As many or as few of these may
  41.  *       be used as required. The default is to use most of
  42.  *       the screen.
  43.  *       <lScreen> Restore screen after use ? (Default .T.)
  44.  *  $RETURNS$
  45.  *       cText
  46.  *  $DESCRIPTION$
  47.  *       Display a Memo in a box on the screen. Optionally
  48.  *       allow editing or just viewing.
  49.  *  $EXAMPLES$
  50.  *  $END$
  51.  */
  52.  
  53. #include "GtClippe.ch"
  54. #include "MemoEdit.ch"
  55.  
  56. FUNCTION GT_Memo(cText,cTitle,cColour,cBoxLines,nTop, ;
  57.     nLeft,nBottom,nRight,lEdit,lScreen)
  58.  
  59. EXTERNAL Memo_udf
  60. EXTERNAL Memo_save
  61.  
  62. LOCAL nCursor := 0
  63. LOCAL cOptions := ;
  64.     'Esc∙Exit                                                 ' + ;
  65.     CHR(24) + CHR(25) + CHR(26) + CHR(27) + '∙Cursor Control'
  66.  
  67. LOCAL cScreen := ''
  68.  
  69. Default cText to ''
  70. Default cTitle to ''
  71. Default cColour to SETCOLOR()
  72. Default cBoxLines to ''
  73. Default nTop to 04
  74. Default nLeft to 02
  75. Default nBottom to MAXROW() - 04
  76. Default nRight to MAXCOL() - 02
  77. Default lEdit to .F.
  78. Default lScreen to .T.
  79.  
  80. IF lScreen
  81.     cScreen := SAVESCREEN(00,00,MAXROW(),MAXCOL())
  82. ENDIF
  83.  
  84. //  Box based on edit mode
  85. IF EMPTY(cBoxLines)
  86.     cBoxLines := IF(lEdit,BOX_DD,BOX_SS)
  87. ENDIF
  88.  
  89. //  Set cursor
  90. nCursor := IF(lEdit,GT_ShowCursor(),GT_NoCursor())
  91.  
  92. //  Display
  93. GT_Window(nTop,nLeft,nBottom,nRight,cBoxLines,cColour, ;
  94.     cTitle,.T.)
  95.  
  96. IF nBottom < MAXROW() - 03
  97.  
  98.     IF !lScreen
  99.         cScreen := SAVESCREEN(MAXROW()-02,00,MAXROW(),MAXCOL())
  100.     ENDIF
  101.  
  102.     GT_Message(cOptions,'Options:',cColour,BOX_SS, ;
  103.         MAXROW()-02,00,MAXROW(),MAXCOL())
  104.  
  105. ENDIF
  106.  
  107. //Edit
  108. cText := MEMOEDIT(cText,nTop+01,nLeft+01,nBottom-01, ;
  109.     nRight-01,lEdit,'Memo_udf')
  110.  
  111. //  Reset cursor
  112. SETCURSOR(nCursor)
  113.  
  114. IF lScreen
  115.     RESTSCREEN(00,00,MAXROW(),MAXCOL(),cScreen)
  116. ELSE
  117.     IF nBottom < MAXROW() - 03
  118.         RESTSCREEN(MAXROW()-02,00,MAXROW(),MAXCOL(),cScreen)
  119.     ENDIF
  120. ENDIF
  121.  
  122. /*
  123.     End of GT_Memo()
  124. */
  125. RETURN(cText)
  126.  
  127. /*
  128. ***********************************************************
  129. */
  130.  
  131. FUNCTION Memo_udf(nStatus,nLine,nColumn)
  132.  
  133. LOCAL aKeys := {K_ESC}
  134. LOCAL aBlocks := { ;
  135.     { | nMode | IF(nMode=ME_UNKEYX,Memo_Save(),0) } ;
  136.     }
  137.  
  138. LOCAL nKey := LASTKEY()
  139. LOCAL nReturn := 0
  140. LOCAL nTest := 0
  141.  
  142. Default nStatus to ME_UNKEY
  143. Default nLine to 0
  144. Default nColumn to 0
  145.  
  146. DO CASE
  147.  
  148.     CASE nStatus = ME_IDLE
  149.         // Idle
  150.  
  151.     CASE nStatus = ME_INIT
  152.         // Should be startup status
  153.  
  154.     OTHERWISE
  155.         // Other key
  156.         nTest := ASCAN(aKeys,nKey)
  157.         IF nTest > 0
  158.             nReturn := EVAL(aBlocks[nTest],nStatus)
  159.         ENDIF
  160.  
  161. ENDCASE
  162.  
  163. /*
  164.     End of Memo_udf()
  165. */
  166. RETURN(nReturn)
  167.  
  168. /*
  169. ************************************************************************
  170. */
  171. FUNCTION Memo_Save()
  172.  
  173. LOCAL cScreen := SAVESCREEN(00,00,MAXROW(),MAXCOL())
  174. LOCAL lSave := .T.
  175.  
  176. lSave := (UPPER(CHR(GT_AskUser('Save changes ? (Y/N)', ;
  177.     {ASC('Y'),ASC('y'),ASC('N'),ASC('n')}))) = 'Y')
  178.  
  179. RESTSCREEN(00,00,MAXROW(),MAXCOL(),cScreen)
  180.  
  181. /*
  182.     End of Memo_Save()
  183. */
  184. RETURN(IF(lSave,K_CTRL_W,K_ESC))
  185.