home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a067 / 1.img / GRUMP501.EXE / HELP.PRG < prev    next >
Encoding:
Text File  |  1991-09-02  |  6.8 KB  |  223 lines

  1. /*
  2.    Program: HELP.PRG
  3.    System: GRUMPFISH LIBRARY
  4.    Author: Greg Lief
  5.    Copyright (c) 1988-90, Greg Lief
  6.    Clipper 5.01 Version
  7.    Compile instructions: clipper help /n/a
  8.  
  9.    Displays user-defined help screens
  10.  
  11.    Procs & Fncts: HELP
  12.                 : SHOWHELP()
  13.                 : PRINTHELP()
  14.                 : HELPHEAD()
  15. */
  16.  
  17. //───── begin preprocessor directives
  18.  
  19. #include "grump.ch"
  20. #include "inkey.ch"
  21. #include "achoice.ch"
  22.  
  23. //───── end preprocessor directives
  24.  
  25. //───── begin global declarations
  26.  
  27. static buffer                 // saved entry screen
  28. static helpfile := "help"     // default help file
  29.  
  30. //───── end global declarations
  31.  
  32. function help(mproc, mline, mvar)
  33. local wk_area := select(), old_f1, hotkey := 0, oldblock
  34. memvar helpcode        // would be declared in calling program if it exists
  35. GFSaveEnv( , 0)        // shut off cursor
  36. buffer := savescreen(0, 0, maxrow(), maxcol())
  37.  
  38. /*
  39.    usually if HELPDEV() was called from anything other than GINKEY(),
  40.    MPROC will be a null string.  We would then have to use the procedure
  41.    name three levels deep.  However, in the event that the procedure
  42.    name passed to HELPDEV() is an internal Clipper function (beginning
  43.    with double underscore "__"), then we must use the procedure name
  44.    four levels deep.
  45. */
  46. if empty(mproc)
  47.    mproc := procname(3)
  48. elseif left(mproc, 2) = '__'
  49.    mproc := procname(4)
  50. endif
  51. oldblock := setkey(hotkey := lastkey(), NIL)
  52.  
  53. /* set F1 key to show help index (function: ShowIndex()) */
  54. old_f1 := setkey(K_F1, {|p, l, v| showindex(p, l, v)} )
  55. //───── make sure everything is proper before proceeding
  56. if ! file(helpfile + '.dbf') .or. ! file(helpfile + '.dbt')
  57.    err_msg('Help files missing')
  58. else
  59.    use (helpfile) new
  60.    //───── rebuild index if necessary
  61.    if ! file(helpfile + '.ntx')
  62.       if flock()
  63.          waiton("Indexing help database")
  64.          index on _field->theproc + _field->var to (helpfile)
  65.          unlock
  66.       else
  67.          waiton("database is being reindexed... please wait")
  68.          do while ! flock()
  69.          enddo
  70.       endif
  71.       waitoff()
  72.    else
  73.       set index to (helpfile)
  74.    endif
  75.    //───── seek on helpcode first if such a variable is defined
  76.    seek if(type('helpcode') == "U", padr(mproc, 10) + padr(mvar, 10), ;
  77.         padr(helpcode, 20))
  78.    if found()
  79.       showhelp()
  80.    else
  81.       showindex()
  82.    endif
  83.    use
  84. endif
  85. GFRestEnv()
  86. setkey(K_F1, old_F1)        // restore F1 hot-key
  87. setkey(hotkey, oldblock)    // restore hot-key
  88. restscreen(0, 0, maxrow(), maxcol(), buffer)
  89. select(wk_area)
  90. return NIL
  91.  
  92. * end of function Help() (i need somebody...)
  93. *--------------------------------------------------------------------
  94.  
  95.  
  96. /*
  97.    Function: ShowHelp()  --> display help screen
  98. */
  99. static function ShowHelp
  100. local mid
  101. shadowbox((helpfile)->toprow, (helpfile)->lt_col, (helpfile)->botrow, ;
  102.      (helpfile)->rt_col, (helpfile)->boxno,,, color_n2s((helpfile)->boxcolor))
  103. mid := (helpfile)->lt_col + (int((helpfile)->rt_col - (helpfile)->lt_col) / 2)
  104. @ (helpfile)->botrow, mid - int(len(trim((helpfile)->footer)) / 2) ;
  105.        ssay trim((helpfile)->footer) color color_n2s((helpfile)->ftcolor)
  106. @ (helpfile)->toprow, mid - int(len(trim((helpfile)->title)) / 2) ;
  107.        ssay trim((helpfile)->title) color color_n2s((helpfile)->titcolor)
  108. setcolor(color_n2s((helpfile)->txtcolor))
  109. memoedit((helpfile)->text, (helpfile)->toprow + 1, (helpfile)->lt_col + 1, ;
  110.          (helpfile)->botrow - 1, (helpfile)->rt_col - 1, .f., 'PrintHelp')
  111. return NIL
  112.  
  113. * end of static function ShowHelp() (not just anybody...)
  114. *--------------------------------------------------------------------
  115.  
  116.  
  117. /*
  118.    Function: ShowIndex()  --> display help screen index
  119. */
  120. static function ShowIndex(mproc, mline, mvar)
  121. static helpindex_ := {}    // array to hold help screen titles
  122. local marker := recno(), buffer2, oldcolor, indexscrn, ele := 1
  123. //───── if we got here from a hot-key, restore the original screen first!
  124. if mproc != NIL
  125.    setkey(K_F1, NIL)       // disable F1 hot-key
  126.    buffer2 := savescreen(0, 0, maxrow(), maxcol())
  127.    restscreen(0, 0, maxrow(), maxcol(), buffer)    // original screen
  128. endif
  129. go top
  130. //───── load the help index array if it was not already loaded
  131. if len(helpindex_) == 0
  132.    dbeval( { || aadd(helpindex_, (helpfile)->title + str(recno(), 4)) } )
  133.    asort(helpindex_)
  134. endif
  135. oldcolor := ColorSet(C_APICK_BOXOUTLINE)
  136. shadowbox(7, 24, 17, 55, 2, 'Help Index')
  137. CENTER(17,' Select topic or Esc to abort ')
  138. indexscrn := savescreen(7, 24, 18, 57)
  139. do while ele > 0
  140.    ele := achoice(8, 25, 16, 54, helpindex_)
  141.    if ele > 0
  142.       go val(substr(helpindex_[ele], 31, 4))
  143.       restscreen(0, 0, maxrow(), maxcol(), buffer)    // original screen
  144.       ShowHelp()
  145.       restscreen(0, 0, maxrow(), maxcol(), buffer)    // original screen
  146.       ColorSet(C_APICK_BOXOUTLINE)
  147.       restscreen(7, 24, 18, 57, indexscrn)
  148.    endif
  149. enddo
  150. go marker
  151. //───── restore screen and hot key if we got here from a hot key
  152. if mproc != NIL
  153.    restscreen(0, 0, maxrow(), maxcol(), buffer2)
  154.    setkey(K_F1, {|p, l, v| showindex(p, l, v)} )
  155. endif
  156. setcolor(oldcolor)
  157. return NIL
  158.  
  159. * end of static function ShowIndex() (ya know I need someone...)
  160. *--------------------------------------------------------------------*
  161.  
  162.  
  163. /*
  164.   function: PrintHelp() -- UDF for MEMOEDIT() above
  165. */
  166. function PrintHelp(mstat, mline, mcol)
  167. local mtext, mproc, key := lastkey(), linewidth, lines, currline
  168. if key == K_ALT_P    // print this help screen
  169.    if PrintOK()
  170.       waiton('Now printing help text, press Esc to abort')
  171.       set device to printer
  172.       currline := 1
  173.       linewidth := (helpfile)->rt_col - (helpfile)->lt_col + 1
  174.       lines := mlcount((helpfile)->text, linewidth)
  175.       HelpHead()
  176.       do while currline <= lines .and. inkey() != K_ESC
  177.          @ prow()+1,(helpfile)->lt_col say ;
  178.                      trim(memoline((helpfile)->text, linewidth, currline++))
  179.          if prow() >= 59
  180.             HelpHead()
  181.          endif
  182.       enddo
  183.       eject
  184.       set device to screen
  185.       waitoff()
  186.    endif
  187. endif
  188. return 0
  189.  
  190. * end function PrintHelp()
  191. *--------------------------------------------------------------------*
  192.  
  193.  
  194. /*
  195.   function: HelpHead() -- heading when printing help text
  196. */
  197. static function HelpHead
  198. static page := 1
  199. @ 0,0 say ''
  200. @ 1,1 say upper((helpfile)->title)
  201. @ 1,72 say 'Page ' + ltrim(str(page++))
  202. @ 3, 0 say ''
  203. return NIL
  204.  
  205. * end static function HelpHead()
  206. *--------------------------------------------------------------------*
  207.  
  208.  
  209. /*
  210.   Function: HelpSet() -- change name of help database file (default HELP.DBF)
  211.   Syntax:   HelpSet(<cNewfile>)
  212.   Returns:  Previous help file name
  213. */
  214. function HelpSet(filename)
  215. local ret_val := helpfile
  216. helpfile := filename
  217. return ret_val
  218.  
  219. * end function HelpSet()
  220. *--------------------------------------------------------------------*
  221.  
  222. * end of file HELP.PRG
  223.