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

  1. /*
  2.  * File......: HELP.PRG
  3.  * Author....: Simon Coates
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Simon Coates
  7.  * Date......: 08/07/1993
  8.  * Revision..: 1.0
  9.  *
  10.  * This is an original work by Simon Coates and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *
  18.  *
  19.  */
  20.  
  21. /*  $DOC$
  22.  *  $FUNCNAME$
  23.  *      GT_HELPREQUEST
  24.  *  $CATEGORY$
  25.  *      General
  26.  *  $ONELINER$
  27.  *     Context Sensitive Help Driver
  28.  *  $SYNTAX$
  29.  *      Set Key nn To GT_HelpRequest
  30.  *  $ARGUMENTS$
  31.  *
  32.  *  $RETURNS$
  33.  *      NIL
  34.  *  $DESCRIPTION$
  35.  *      This is a simple 'Help Engine'. It must be simple since I wrote it
  36.  *      <g>. The routine will create the help database automatically if
  37.  *      the file 'HELPFILE', is missing. If the user requests help at any
  38.  *      point where it has not been previously defined, then it will create
  39.  *      a blank entry in the database, with the relevant calling points &
  40.  *      variables.
  41.  *      It also creates and index called
  42.  *      'HelpFil1.NTX' as well.The structure is as follows :-
  43.  *
  44.  *      VARIABLE_   Character   12
  45.  *      ROUTINE_    Character   12
  46.  *      HELPTEXT_   Memo
  47.  *      TITLE_      Character   15
  48.  *
  49.  *      The file should be indexed on Upper(Variable_)+Upper(Routine_)
  50.  *
  51.  *      NB This routine uses the following routines :-
  52.  *      GT_ELEVBAR      by       MartDude
  53.  *      GT_OPEN         by       MortDude
  54.  *      GT_BLOCK        by       Me!
  55.  *
  56.  *  $EXAMPLES$
  57.  *
  58.  *  $SEEALSO$
  59.  *
  60.  *  $INCLUDE$
  61.  *
  62.  *  $END$
  63.  */
  64.  
  65. /****************************************************************************
  66.  Purpose - Displays context sensitive help based on current get variable
  67.  Returns - None
  68.  Author  - Simon Coates
  69.  Created - 08 June 1993
  70. ******************************************************************************
  71. Parameters  - cProc      - Calling Procedure
  72.               nLine      - Current line of procedure
  73.               cVar       - Current variable
  74. Locals      - cOldScreen - Holds old screen
  75.             - cOldColours- Holds existing screen colours
  76.             - cOldArea   - Holds old Alias
  77.             - nBoxT   ─┐
  78.             - nBoxL   ─┤
  79.             - nBoxB   ─┼── Co-ordinates of box
  80.             - nBoxR   ─┘
  81.             - nMaxCol    - Screen Size
  82.             - nMaxRow
  83.             - aStructure - Holds the structure of the DBF file
  84. ****************************************************************************/
  85.  
  86. Function GT_HelpRequest(cProc, nLine, cVar)
  87.  
  88. Local nMaxRow := MaxRow()
  89. Local nMaxCol := MaxCol()
  90.  
  91. Local nBoxT := 03
  92. Local nBoxL := 04
  93. Local nBoxB := nMaxRow - 3
  94. Local nBoxR := nMaxCol - 4
  95.  
  96. Local cOldColours := SetColor()
  97. Local cOldArea := Alias()
  98. Local cOldScreen := ""
  99. Local aStructure := {}
  100.  
  101. LOCAL cTitle := ""
  102. LOCAL cTempMemo := ""
  103.  
  104. //
  105. // Define an array to hold the structure of the
  106. // help database. This allows me to create the
  107. // file if it is missing.
  108. AADD(aStructure, {"Variable_", "C", 12, 0})
  109. AADD(aStructure, {"Routine_", "C", 12, 0})
  110. AADD(aStructure, {"HelpText_", "M", 10, 0})
  111. AADD(aStructure, {"Title_", "C", 15, 0})
  112.  
  113. // Were we called from here??
  114. If Upper(cProc) = Upper(ProcName())
  115.     Return(NIL) //Then go pack from whence we came
  116. EndIf
  117.  
  118. GT_Open("HelpFile", {"Upper(Variable_)+Upper(Routine_)"}, "Help", .F., .F., aStructure)
  119.  
  120. Save Screen To cOldScreen
  121.  
  122. SetColor("W+/R")
  123. Seek Upper(cVar)
  124. IF .Not. Found()
  125.     tone(200, 1)
  126.     Append Blank
  127.     Replace help->Variable_ WITH cVar
  128.     Replace help->routine_ With cProc
  129.     Replace help->Helptext_ With " "
  130. End If
  131. nLine := 1
  132. cTitle := If(Empty(help->Title_), "General Help", help->Title_)
  133. cTitle := AllTrim(cTitle)
  134. //
  135. // Ok, now drawq the box on the screen (using GT_BLOCK for effect)
  136. DispBegin()
  137.     GT_Block(nBoxT, nBoxL, nBoxB, nBoxR, "", .T., "n/b", "b+/b", "╔═╗║╝═╚║ ╣╠")
  138.  
  139.     // Tidy the thing up a bit
  140.     SetColor("b+/b")
  141.     @ nBoxT+2, nBoxL Say "╟"
  142.     SetColor("n/b")
  143.     @ nBoxT+2, nBoxR Say "╢"
  144.     @ nBoxT+2, nBoxL+1 Say Replicate("─", nBoxR-(nBoxL+1))
  145.     SetColor("W+/b")
  146.     // Shadow it
  147.     Shadow(nBoxT, nBoxL, nBoxB, nBoxR)
  148.     Centre(nBoxT+1, cTitle)
  149.     //
  150.     // Now edit the stuff
  151.     //
  152. DispEnd()
  153. cTempMemo := MemoEdit(HELP->HELPTEXT_, nBoxT+3, nBoxL+1, nBoxB-1, nBoxR-1, .F., "helpudf")
  154. USE // nothing (Close the file)
  155. SetColor(cOldColours)
  156. If .NOT. Empty(cOldArea)
  157.     Select cOldArea
  158. End If
  159.  
  160. // Ok, all done, return to calling point
  161.  
  162. Restore Screen From cOldScreen
  163. Keyboard Chr(1)
  164. Return(NIL)
  165.  
  166. /****************************************************************************
  167.  Purpose - UDF called from HelpRequest to display scroll bar thingy
  168.  Returns - None
  169.  Author  - Simon Coates
  170.  Created - 08 June 1993
  171. ******************************************************************************
  172. Parameters  - nJunk                  - Not Required
  173.               nVertPos      - Current line of Memo
  174. Locals      - cOldScreen    - Holds old screen
  175.             - cOldColours   - Holds existing screen colours
  176.             - nLineCount    - Holds total lines in memo
  177.             - nWidth        - Width of memo box
  178.             - nBoxT   ─┐
  179.             - nBoxL   ─┤
  180.             - nBoxB   ─┼── Co-ordinates of box
  181.             - nBoxR   ─┘
  182.             - nMaxCol    - Screen Size
  183.             - nMaxRow
  184. ****************************************************************************/
  185.  
  186. FUNCTION Helpudf( nJunk, nVertPos )
  187. Local cOldScreen, cOldColours
  188. Local nBoxT, nBoxL, nBoxB, nBoxR, nMaxRow, nMaxCol, nWidth, nLinecount
  189.  
  190. nMaxRow := MaxRow()
  191. nMaxCol := MaxCol()
  192.  
  193. nBoxT := 03
  194. nBoxL := 04
  195. nBoxB := nMaxRow - 3
  196. nBoxR := nMaxCol - 4
  197. nWidth:= nBoxR - nBoxL
  198.  
  199. cOldColours := SetColor()
  200.  
  201. nLineCount  := MlCount(HELP->HELPTEXT_, 10)
  202. nVertPos    := IF(nVertPos>MlCount(HELP->HELPTEXT_, nWidth), ;
  203.                + MlCount(HELP->HELPTEXT_, nWidth), nVertPos)
  204. GT_ElevBar(nBoxT+3, nBoxB-1, nBoxR, "▒", "■", 1, nVertPos, MlCount(HELP->HELPTEXT_, nWidth))
  205. SetColor(cOldColours)
  206. Return(0)
  207.  
  208.  
  209. /****************************************************************************
  210.  Purpose - Displays a text string on a specified row
  211.  Returns - None
  212.  Author  - Simon Coates
  213.  Created - 08 June 1993
  214. ******************************************************************************
  215. Parameters  - nLine         - Row for message
  216.               cText         - Text string to be displayed
  217. Locals      - nMid          - Used to calculate the middle column
  218. ****************************************************************************/
  219.  
  220. Function Centre(nLine, cText)
  221. Local nMid
  222. nMid := (MaxCol()/2)-(Len(cText)/2)
  223. @ nLine, nMid Say cText
  224. Return(NIL)
  225.