home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 5 / 05.iso / a / a013 / 1.ddi / SOURCE.EXE / F_SYSHLP.PRG < prev    next >
Encoding:
Text File  |  1991-01-25  |  6.9 KB  |  269 lines

  1. *****************************************************************
  2. FUNCTION SYSHELP
  3. *****************************************************************
  4. *
  5. * Displays help or other messages contained in a database
  6. *
  7. * Copyright(c) 1991 -- James Occhiogrosso
  8. *
  9. * Three arguments are passed if SYSHELP is called from a hotkey.
  10. * If called though a special Developer's Library function,
  11. * keypress is also passed.  All arguments can be used in the
  12. * help condition statement.
  13.  
  14. # include "setcurs.ch"
  15.  
  16. LOCAL old_area   := SELECT(),  old_color := SETCOLOR(),         ;
  17.       old_cursor := SETCURSOR(SC_NONE),                         ;
  18.       old_help := IF(TYPE('helpcode')!= 'C' .OR. LASTKEY() =-1, ;
  19.                      '', TRIM(UPPER(helpcode))),                ;
  20.       old_col := COL(), old_row := ROW(),                       ;
  21.       old_screen := SCRNSAVE( 0, 0, MAXROW(), MAXCOL() ),       ;
  22.       open_flag := .F.
  23.  
  24.  
  25.  
  26. PARAMETERS callproc, linenum, inputvar, keypress
  27.  
  28. PRIVATE help_col, help_row
  29.  
  30. * Prevent recursive entry
  31. IF TYPE('help__on') = 'L'
  32.     * Help is already active
  33.     RETURN .F.
  34. ELSE
  35.     * Initialize help variable
  36.     help__on = .T.
  37. ENDIF
  38.  
  39. * Set defaults for undefined variables
  40. IF TYPE('helpfile') != 'C'
  41.    PRIVATE helpfile := 'SYSHELP'
  42. ENDIF
  43. IF TYPE('helpcode') != 'C'
  44.    PRIVATE helpcode := ''
  45. ENDIF
  46.  
  47. IF TYPE('keypress') != 'N'
  48.     * Call may not be from a Developer's Library function.
  49.     * Initialize keypress to prevent runtime error.
  50.     keypress = 0
  51. ENDIF
  52.  
  53. * Check for direct call. If fewer than 3 arguments, SYSHELP was
  54. * called directly. Initialize arguments to prevent error.
  55. IF PCOUNT() < 3
  56.     callproc = ''
  57.     linenum  = 0
  58.     inputvar = ''
  59. ENDIF
  60.  
  61. * Select helpfile or open it if necessary. Note that help
  62. * is addressed only by its alias dl_syshelp.  The help database
  63. * can have any name.
  64.  
  65. IF SELECT('dl_syshelp') = 0
  66.  
  67.     IF FILE((helpfile) + '.DBF') .AND. FILE((helpfile) + '.DBT');
  68.             .AND. FILE((helpfile) + INDEXEXT())
  69.  
  70.         * Help file exists, open it and set flag
  71.         USE &helpfile ALIAS dl_syshelp INDEX ((helpfile)) NEW
  72.         open_flag := .T.
  73.     ELSE
  74.         * Help file not found
  75.         old_screen = SCRNSAVE(MAXROW(), 0, MAXROW(), MAXCOL())
  76.         CENTERON(MAXROW(),'Helpfile not available. ' + hitanykey)
  77.         ERRORBEEP()
  78.         INKEY(0)
  79.         SCRNREST(old_screen)
  80.         RETURN .F.
  81.     ENDIF
  82.  
  83. ELSE
  84.     * Help file already open, select it
  85.     SELECT dl_syshelp
  86. ENDIF
  87.  
  88. * Set up maximum row and column for SYSHELP messages. Look for
  89. * special system record with maximum screen coordinates. If not
  90. * found, default to entire screen.
  91.  
  92. SEEK '~~HG_SYS~~'
  93. IF .NOT. FOUND()
  94.     help_row = MAXROW()
  95.     help_col = MAXCOL()
  96. ELSE
  97.     help_row = dl_syshelp->hlpbott
  98.     help_col = dl_syshelp->hlprgt
  99. ENDIF
  100.  
  101. * Locate the message
  102. GO TOP
  103. IF .NOT. EMPTY(helpcode)
  104.     SEEK helpcode
  105.  
  106.     IF FOUND() .AND. TRIM(helpcode) == TRIM(dl_syshelp->hlpcode)
  107.  
  108.         * Display message if condition is empty or true
  109.         IF EMPTY(dl_syshelp->hlpcond)
  110.             HELPMSG()
  111.         ELSEIF CHKCOND()
  112.             HELPMSG()
  113.         ELSE
  114.             * Otherwise, no help is available
  115.             NOHELP()
  116.         ENDIF
  117.     ELSE
  118.         * Help code not in file, display message
  119.         NOHELP()
  120.     ENDIF
  121.  
  122. ELSE
  123.     * No helpcode passed, evaluate condition field only
  124.  
  125.     IF CHKCOND() .AND. EMPTY(dl_syshelp->hlpcode)
  126.         * We found one, display it
  127.         HELPMSG()
  128.     ELSE
  129.         * No help available
  130.         NOHELP()
  131.     ENDIF
  132.  
  133. ENDIF
  134.  
  135. * Restore entry conditions and return
  136.  
  137. IF open_flag
  138.     * We opened help file, close it
  139.     USE
  140. ENDIF
  141.  
  142. * Restore everything and return
  143. SCRNREST(old_screen)
  144. SELECT(old_area)
  145. SETCOLOR(old_color)
  146. helpcode := old_help
  147. SETCURSOR(old_cursor)
  148. DEVPOS(old_row, old_col)
  149. RETURN NIL
  150.  
  151.  
  152. *****************************************************************
  153. STATIC FUNCTION NOHELP
  154. *****************************************************************
  155.  
  156. * Display no help available message
  157.  
  158. LOCAL keypress, old_screen
  159.  
  160. * Clear message row and display error message
  161. ERRORBEEP()
  162. @ help_row, 0 CLEAR TO help_row, help_col
  163. SETCOLOR(colwindow)
  164. @ help_row, INT((help_col - 52) / 2) SAY ;
  165.       ' No help is available. ' + hitanykey
  166.  
  167. keypress = INKEY(0)
  168.  
  169. * The code below is for development. If the "^" key (key 94)
  170. * is pressed when no help is available, calling conditions
  171. * appear in a window.
  172.  
  173. IF keypress = 94 .AND. TYPE('callproc') = 'C'
  174.  
  175.    old_screen = SCRNSAVE(10, 17, 15, 60)
  176.    @ 10, 17, 15, 59 BOX '┌─┐│┘─└│ '
  177.    @ 11, 20 SAY ' Calling Procedure ...... '+ callproc
  178.    @ 12, 20 SAY ' Line Number ............ '+ LTRIM(STR(linenum))
  179.    @ 13, 20 SAY ' Input Variable ......... '+ inputvar
  180.    @ 14, 20 SAY ' Help Code .............. '+ helpcode
  181.  
  182.    @ help_row, 0 SAY PADC('Test key pressed!' +  ;
  183.                      hitanykey, help_col)
  184.    INKEY(0)
  185.    SCRNREST(old_screen)
  186.  
  187. ENDIF
  188.  
  189. RETURN NIL
  190.  
  191.  
  192. *****************************************************************
  193. STATIC FUNCTION CHKCOND
  194. *****************************************************************
  195.  
  196. * Check condition field of help file. If it is false or
  197. * empty, return false. Otherwise, return true.
  198.  
  199. LOCAL checkit
  200.  
  201. DO WHILE helpcode == TRIM(dl_syshelp->hlpcode) .AND. .NOT. EOF()
  202.  
  203.     IF EMPTY(dl_syshelp->hlpcond)
  204.         * No condition is specified
  205.         SKIP
  206.     ELSE
  207.         checkit = UPPER(dl_syshelp->hlpcond)
  208.         IF &checkit
  209.             * Condition evaluates true
  210.             RETURN(.T.)
  211.         ENDIF
  212.         SKIP
  213.     ENDIF
  214.  
  215. ENDDO
  216.  
  217. RETURN .F.
  218.  
  219.  
  220. *****************************************************************
  221. STATIC FUNCTION HELPMSG
  222. *****************************************************************
  223.  
  224. * Display help message at specified position
  225.  
  226. @ help_row, 0 CLEAR TO help_row, help_col
  227.  
  228. SETCOLOR(colwindow)
  229. @ help_row, INT((help_col - 52) / 2) SAY ;
  230.       ' Use up/down, pgup/pgdn to view. Press ESC to EXIT. '
  231.  
  232. * Set help color. If no entry, default to colhelp1
  233. IF .NOT. EMPTY(dl_syshelp->hlpcolr)
  234.     SETCOLOR(&(dl_syshelp->(hlpcolr)))
  235. ELSE
  236.     SETCOLOR(colhelp1)
  237. ENDIF
  238.  
  239. IF dl_syshelp->hlpclr
  240.     @ 0, 0 CLEAR TO help_row - 1, help_col
  241. ENDIF
  242.  
  243. IF dl_syshelp->hlpbox
  244.  
  245.    * Load selected box type
  246.    boxdef = IF(dl_syshelp->hlpbx = 'S', '┌─┐│┘─└│ ', '╔═╗║╝═╚║ ')
  247.  
  248.    * Draw box at defined position
  249.    @ dl_syshelp->hlptop, dl_syshelp->hlpleft, ;
  250.      dl_syshelp->hlpbott, dl_syshelp->hlprgt BOX boxdef
  251.  
  252.    * And display message inside box
  253.  
  254.    MEMOEDIT(dl_syshelp->hlpmsg, dl_syshelp->hlptop+1,     ;
  255.             dl_syshelp->hlpleft+2, dl_syshelp->hlpbott-1, ;
  256.             dl_syshelp->hlprgt-2, .F.)
  257.  
  258. ELSE
  259.    * Display message without boxing
  260.  
  261.    MEMOEDIT(dl_syshelp->hlpmsg, dl_syshelp->hlptop,       ;
  262.             dl_syshelp->hlpleft, dl_syshelp->hlpbott,     ;
  263.             dl_syshelp->hlprgt, .F.)
  264.  
  265. ENDIF
  266.  
  267. RETURN NIL
  268.  
  269.