home *** CD-ROM | disk | FTP | other *** search
- /*
- Program: HELP.PRG
- System: GRUMPFISH LIBRARY
- Author: Greg Lief
- Copyright (c) 1988-90, Greg Lief
- Clipper 5.01 Version
- Compile instructions: clipper help /n/a
-
- Displays user-defined help screens
-
- Procs & Fncts: HELP
- : SHOWHELP()
- : PRINTHELP()
- : HELPHEAD()
- */
-
- //───── begin preprocessor directives
-
- #include "grump.ch"
- #include "inkey.ch"
- #include "achoice.ch"
-
- //───── end preprocessor directives
-
- //───── begin global declarations
-
- static buffer // saved entry screen
- static helpfile := "help" // default help file
-
- //───── end global declarations
-
- function help(mproc, mline, mvar)
- local wk_area := select(), old_f1, hotkey := 0, oldblock
- memvar helpcode // would be declared in calling program if it exists
- GFSaveEnv( , 0) // shut off cursor
- buffer := savescreen(0, 0, maxrow(), maxcol())
-
- /*
- usually if HELPDEV() was called from anything other than GINKEY(),
- MPROC will be a null string. We would then have to use the procedure
- name three levels deep. However, in the event that the procedure
- name passed to HELPDEV() is an internal Clipper function (beginning
- with double underscore "__"), then we must use the procedure name
- four levels deep.
- */
- if empty(mproc)
- mproc := procname(3)
- elseif left(mproc, 2) = '__'
- mproc := procname(4)
- endif
- oldblock := setkey(hotkey := lastkey(), NIL)
-
- /* set F1 key to show help index (function: ShowIndex()) */
- old_f1 := setkey(K_F1, {|p, l, v| showindex(p, l, v)} )
- //───── make sure everything is proper before proceeding
- if ! file(helpfile + '.dbf') .or. ! file(helpfile + '.dbt')
- err_msg('Help files missing')
- else
- use (helpfile) new
- //───── rebuild index if necessary
- if ! file(helpfile + '.ntx')
- if flock()
- waiton("Indexing help database")
- index on _field->theproc + _field->var to (helpfile)
- unlock
- else
- waiton("database is being reindexed... please wait")
- do while ! flock()
- enddo
- endif
- waitoff()
- else
- set index to (helpfile)
- endif
- //───── seek on helpcode first if such a variable is defined
- seek if(type('helpcode') == "U", padr(mproc, 10) + padr(mvar, 10), ;
- padr(helpcode, 20))
- if found()
- showhelp()
- else
- showindex()
- endif
- use
- endif
- GFRestEnv()
- setkey(K_F1, old_F1) // restore F1 hot-key
- setkey(hotkey, oldblock) // restore hot-key
- restscreen(0, 0, maxrow(), maxcol(), buffer)
- select(wk_area)
- return NIL
-
- * end of function Help() (i need somebody...)
- *--------------------------------------------------------------------
-
-
- /*
- Function: ShowHelp() --> display help screen
- */
- static function ShowHelp
- local mid
- shadowbox((helpfile)->toprow, (helpfile)->lt_col, (helpfile)->botrow, ;
- (helpfile)->rt_col, (helpfile)->boxno,,, color_n2s((helpfile)->boxcolor))
- mid := (helpfile)->lt_col + (int((helpfile)->rt_col - (helpfile)->lt_col) / 2)
- @ (helpfile)->botrow, mid - int(len(trim((helpfile)->footer)) / 2) ;
- ssay trim((helpfile)->footer) color color_n2s((helpfile)->ftcolor)
- @ (helpfile)->toprow, mid - int(len(trim((helpfile)->title)) / 2) ;
- ssay trim((helpfile)->title) color color_n2s((helpfile)->titcolor)
- setcolor(color_n2s((helpfile)->txtcolor))
- memoedit((helpfile)->text, (helpfile)->toprow + 1, (helpfile)->lt_col + 1, ;
- (helpfile)->botrow - 1, (helpfile)->rt_col - 1, .f., 'PrintHelp')
- return NIL
-
- * end of static function ShowHelp() (not just anybody...)
- *--------------------------------------------------------------------
-
-
- /*
- Function: ShowIndex() --> display help screen index
- */
- static function ShowIndex(mproc, mline, mvar)
- static helpindex_ := {} // array to hold help screen titles
- local marker := recno(), buffer2, oldcolor, indexscrn, ele := 1
- //───── if we got here from a hot-key, restore the original screen first!
- if mproc != NIL
- setkey(K_F1, NIL) // disable F1 hot-key
- buffer2 := savescreen(0, 0, maxrow(), maxcol())
- restscreen(0, 0, maxrow(), maxcol(), buffer) // original screen
- endif
- go top
- //───── load the help index array if it was not already loaded
- if len(helpindex_) == 0
- dbeval( { || aadd(helpindex_, (helpfile)->title + str(recno(), 4)) } )
- asort(helpindex_)
- endif
- oldcolor := ColorSet(C_APICK_BOXOUTLINE)
- shadowbox(7, 24, 17, 55, 2, 'Help Index')
- CENTER(17,' Select topic or Esc to abort ')
- indexscrn := savescreen(7, 24, 18, 57)
- do while ele > 0
- ele := achoice(8, 25, 16, 54, helpindex_)
- if ele > 0
- go val(substr(helpindex_[ele], 31, 4))
- restscreen(0, 0, maxrow(), maxcol(), buffer) // original screen
- ShowHelp()
- restscreen(0, 0, maxrow(), maxcol(), buffer) // original screen
- ColorSet(C_APICK_BOXOUTLINE)
- restscreen(7, 24, 18, 57, indexscrn)
- endif
- enddo
- go marker
- //───── restore screen and hot key if we got here from a hot key
- if mproc != NIL
- restscreen(0, 0, maxrow(), maxcol(), buffer2)
- setkey(K_F1, {|p, l, v| showindex(p, l, v)} )
- endif
- setcolor(oldcolor)
- return NIL
-
- * end of static function ShowIndex() (ya know I need someone...)
- *--------------------------------------------------------------------*
-
-
- /*
- function: PrintHelp() -- UDF for MEMOEDIT() above
- */
- function PrintHelp(mstat, mline, mcol)
- local mtext, mproc, key := lastkey(), linewidth, lines, currline
- if key == K_ALT_P // print this help screen
- if PrintOK()
- waiton('Now printing help text, press Esc to abort')
- set device to printer
- currline := 1
- linewidth := (helpfile)->rt_col - (helpfile)->lt_col + 1
- lines := mlcount((helpfile)->text, linewidth)
- HelpHead()
- do while currline <= lines .and. inkey() != K_ESC
- @ prow()+1,(helpfile)->lt_col say ;
- trim(memoline((helpfile)->text, linewidth, currline++))
- if prow() >= 59
- HelpHead()
- endif
- enddo
- eject
- set device to screen
- waitoff()
- endif
- endif
- return 0
-
- * end function PrintHelp()
- *--------------------------------------------------------------------*
-
-
- /*
- function: HelpHead() -- heading when printing help text
- */
- static function HelpHead
- static page := 1
- @ 0,0 say ''
- @ 1,1 say upper((helpfile)->title)
- @ 1,72 say 'Page ' + ltrim(str(page++))
- @ 3, 0 say ''
- return NIL
-
- * end static function HelpHead()
- *--------------------------------------------------------------------*
-
-
- /*
- Function: HelpSet() -- change name of help database file (default HELP.DBF)
- Syntax: HelpSet(<cNewfile>)
- Returns: Previous help file name
- */
- function HelpSet(filename)
- local ret_val := helpfile
- helpfile := filename
- return ret_val
-
- * end function HelpSet()
- *--------------------------------------------------------------------*
-
- * end of file HELP.PRG
-