home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / ohs20 / SYS$HELP.OPL < prev    next >
Text File  |  1994-03-10  |  8KB  |  441 lines

  1. rem OPL Help System 2.0
  2. rem Copyright © Tom Dolbilin 1994
  3.  
  4.  
  5. PROC hstub:
  6. local fname$(128), scr%, pos%
  7. local n$(10), ret%
  8. fname$ = "\help.hlp" : scr% = 0 : pos% = 1
  9. n$ = "OplHelp"
  10. call( $c88, call( $88, 0, 0, 0, 0, 0 ), 0, 0, 0, addr( n$ ) + 1 )
  11.  
  12. while 1
  13.     dinit
  14.     dtext "", " "
  15.     dtext "", "OPL Help System for Psion S3a", $102
  16.     dtext "", "Version 2.0", 2
  17.     dtext "", "© Tom Dolbilin 1994", 2
  18.     dtext "", " ", $200
  19.     dfile fname$, "Help file:", 16
  20.     if dialog = 0
  21.         stop
  22.     endif
  23.     ret% = help%:( addr( fname$ ) )
  24.     if ret% < 0
  25.         giprint err$( ret% )
  26.     endif
  27. endwh
  28. ENDP
  29.  
  30.  
  31. PROC help%:( ptr% )
  32. local fname$(128), scr%, pos%
  33. local num%, ret%
  34. onerr uhoh
  35.  
  36. fname$ = peek$( ptr% )
  37. scr% = max( 0, peekw( ptr% + 129 ) )
  38. pos% = max( 0, peekw( ptr% + 131 ) )
  39. if pos% = 0
  40.     poke$ ptr%, "2.0"
  41.     return
  42. endif
  43.  
  44. openr fname$, a, n%, str$
  45.  
  46. ret% = hdowin%:( scr%, pos% )
  47. trap close
  48. return min( ret%, 0 )
  49.  
  50. uhoh::
  51. trap close
  52. return err
  53. ENDP
  54.  
  55.  
  56. PROC hdowin%:( s%, p% )
  57. global pstr%(128)
  58. global type%, hid%, grey%
  59. global num%, scr%, pos%, oldpos%, first%, last%, lines%, w%, redraw%
  60. local i%, event%(6), ret%
  61.  
  62. scr% = s%
  63. pos% = p%
  64. grey% = 1
  65. ret% = hwininit:
  66. if ret% = -10
  67.     if type% = 1
  68.         hdialog:
  69.         return
  70.     else
  71.         grey% = 0
  72.         ret% = hwininit:
  73.         if ret% = -10
  74.             hdialog:
  75.             return
  76.         elseif ret%
  77.         return
  78.         endif
  79.     endif
  80. elseif ret%
  81.     return
  82. endif
  83.  
  84. rem ---------- Main Event Loop
  85. while 1
  86.     getevent event%()
  87.     if ( event%(1) and $400 )
  88.         rem ----- the event is a system message
  89.         if event%(1) = $404 and left$( getcmd$, 1 ) = "X"
  90.             hcleanup:
  91.             trap close
  92.             return $404
  93.         endif
  94.      else
  95.         rem ----- the event is a key-press
  96.         ret% =  hdokey%:( event%(1), event%(2) and $ff, event%(2) / 256 )
  97.         if ret%
  98.             hcleanup:
  99.             return ret%
  100.         endif
  101.     endif
  102.  
  103. endwh
  104.  
  105. uhoh::
  106. ret% = err
  107. hcleanup:
  108. return ret%
  109. ENDP
  110.  
  111.  
  112. PROC hdokey%:( k%, kmod%, arep% )
  113. local ret%
  114. if k% = 9
  115.     rem ---------- Tab
  116. elseif k% = 13
  117.     rem ---------- Enter
  118.     if type% = 1
  119.         hselect:( pos% )
  120.         gxborder grey%, $104
  121.         ret% = hdowin%:( pos%, 1 )
  122.         guse hid%
  123.         hselect:( pos% )
  124.         gxborder grey%, $103
  125.         return ret% + ( ret% > 0 )
  126.     endif
  127. elseif k% = 27
  128.     rem ---------- Esc
  129.     if kmod% and 4
  130.         return type%
  131.     else
  132.         return 1
  133.     endif
  134. elseif k% < 264
  135.     rem ---------- Arrow and printable keys
  136.     oldpos% = pos%
  137.     vector k% - 255
  138.         Up, Down, Right, Left
  139.         PgUp, PgDn, Home, End
  140.     endv
  141.     goto Z
  142. Up::
  143. Left::
  144.     pos% = max( pos% - arep%, 1 )
  145.     goto Z
  146. Down::
  147. Right::
  148.     pos% = min( pos% + arep%, num% )
  149.     goto Z
  150. PgUp::
  151.     pos% = max( pos% - lines% + 1, 1 )
  152.     if kmod% and 4
  153.         pos% = 1
  154.     endif
  155.     goto Z
  156. PgDn::
  157.     pos% = min( pos% + lines% - 1, num% )
  158.     if kmod% and 4
  159.         pos% = num%
  160.     endif
  161.     goto Z
  162. Home::
  163.     goto Z
  164. End::
  165. Z::
  166.     hredraw:
  167. elseif k% = 291
  168.     rem ---------- Help key
  169.     if type% = 1
  170.         hselect:( pos% )
  171.         gxborder grey%, $104
  172.         ret% = hdowin%:( num%, 1 )
  173.         guse hid%
  174.         hselect:( pos% )
  175.         gxborder grey%, $103
  176.         return ret% + ( ret% > 0 )
  177.     endif
  178. endif
  179. ENDP
  180.  
  181.  
  182. PROC hwininit:
  183. local w%, h%, top$(100), about%, ret%
  184. onerr uhoh
  185.  
  186. first
  187. num% = a.n% / $200 + 1
  188. scr% = min( abs( scr% ), num%  )
  189. type% = ( scr% = 0 ) + 2
  190.  
  191. if scr% = 0
  192.     first
  193.     top$ = a.str$
  194.     w% = a.n% and $1ff
  195.     next
  196. else
  197.     if scr% = num%
  198.         about% = 1
  199.         top$ = "About Help"
  200.         num% = 4
  201.         w% = 234
  202.     else
  203.         position scr% + 1
  204.         top$ = a.str$
  205.         position a.n%
  206.         num% = a.n% / $200
  207.         w% = a.n% and $1ff
  208.     endif
  209. endif
  210. lines% = min( num%, 8 )
  211. w% = w% + 27 - 7 * ( num% > 8 )
  212. h% = lines% * 15 + 36
  213. hid% = gcreate( 240 - w% / 2, 80 - h% / 2, w%, h%, 0, grey% )
  214. gxborder grey%, $103
  215. gat 9, 25 : glineby gwidth - 18, 0
  216. gfont 11 : gstyle 1 : gat 10, 21
  217. gprintb "Help: " + top$ , w% - 18 + 7 * ( num% > 8 ), 3
  218. gstyle 2 - type%
  219.  
  220. hlist:( about% )
  221. pos% = 1
  222. first% = 1
  223. last% = min( first% + lines% - 1, num% )
  224. oldpos% = pos%
  225. redraw% = 1
  226. hredraw:
  227. gvisible on
  228. hselect:( pos% )
  229. if ( last% < num% )
  230.     gat gwidth - 15, gheight - 12 : gprint chr$(13)
  231. endif
  232. return
  233.  
  234. uhoh::
  235. ret% = err
  236. giprint err$( ret% )
  237. hcleanup:
  238. return ret%
  239. ENDP
  240.  
  241.  
  242. PROC hredraw:
  243. local i%, oldf%, oldl%, dy%, to%, entry$(100)
  244. oldf% = first%
  245. oldl% = last%
  246. pos% = min( pos%, num% )
  247. if pos% <> oldpos%
  248.     hselect:( oldpos% )
  249. endif
  250. last% = min( first% + lines% - 1, num% )
  251. first% = max( last% - lines% + 1, 1 )
  252. if pos% < first%
  253.     first% = pos%
  254.     last% = min( first% + lines% - 1, num% )
  255. elseif pos% > last%
  256.     last% = pos%
  257.     first% = max( last% - lines% + 1, 1 )
  258. endif
  259. if ( last% <> oldl% ) or ( first% <> oldf% )
  260.     gtmode 1 + ( first% > 1 )
  261.     gat gwidth - 15, 39 : gprint chr$(30)
  262.     gtmode 1 + ( last% < num% )
  263.     gat gwidth - 15, gheight - 12 : gprint chr$(13)
  264.     gtmode 0
  265.     dy% = ( max( -8, min( 8, oldf% - first% ) ) ) * 15
  266.     gscroll 0, dy%, 9, 27 - min( 0, dy% ), gwidth - 18 + 7 * ( num% > 8 ), gheight - 36 - abs( dy% )
  267.     redraw% = 1
  268. else
  269.     dy% = lines% * 15
  270. endif
  271. if redraw%
  272.     redraw% = 0
  273.     if dy% >= 0
  274.         i% = first% - 1
  275.         to% = first% + dy% / 15 - 1
  276.     else
  277.         i% = last% + dy% / 15
  278.         to% =  last%
  279.     endif
  280.     while i% < to%
  281.         i% = i% + 1
  282.         gat 15 + 6 * ( type% = 1 ), ( i% - first% ) * 15 + 39
  283.         entry$ = peek$( pstr%( i% ) )
  284.         if type% = 1
  285.             entry$ = "ÿ" + entry$
  286.         endif
  287.         gprintb entry$, gwidth - 24 - 6 * ( type% = 1 ) + 7 * ( num% > 8 ), 2, 1, 1, 2
  288.     endwh
  289. endif
  290. if pos% <> oldpos%
  291.     hselect:( pos% )
  292. endif
  293. gupdate
  294. ENDP
  295.  
  296.  
  297. PROC hselect:( i% )
  298. if type% = 1
  299.     gat 9, ( i% - first% ) * 15 + 27
  300.     ginvert gtwidth( "ÿ" + peek$( pstr%( i% ) ) ) + 3, 15
  301. else
  302.     gtmode 2
  303.     gat 11, ( i% - first% ) * 15 + 39
  304.     gprint chr$(28)
  305. endif
  306. ENDP
  307.  
  308.  
  309. PROC hlist:( about% )
  310. local i%, oldp%, about$(4,36)
  311. if about%
  312.     about$(1) = "To choose a topic:  " + chr$(24) + chr$(25) + "  then Enter"
  313.     about$(2) = ""
  314.     about$(3) = "Esc returns to previous Help screen"
  315.     about$(4) = "Control-Esc exits Help"
  316.     while i% < 4
  317.         i% = i% + 1
  318.         pstr%( i% ) = alloc( len( about$( i% ) ) + 1 )
  319.         if pstr%( i% ) = 0 : raise -10 : endif
  320.         poke$ pstr%( i% ), about$( i% )
  321.     endwh
  322.     return
  323. endif
  324.  
  325. i% = 0
  326. while i% < num% + ( type% = 1 )
  327.     i% = i% + 1
  328.     pstr%( i% ) = alloc( len( a.str$ ) + 1 )
  329.     if pstr%( i% ) = 0 : raise -10 : endif
  330.     poke$ pstr%( i% ), a.str$
  331.     next
  332. endwh
  333.  
  334. if type% = 1
  335.     rem Add About Help to list of topics
  336.     i% = i% + 1
  337.     about$(1) = "About Help"
  338.     pstr%( i% ) = alloc(11)
  339.     if pstr%( i% ) = 0 : raise -10 : endif
  340.     poke$ pstr%( i% ), about$(1)
  341. endif
  342. ENDP
  343.  
  344.  
  345. PROC hcleanup:
  346. local i%
  347. while i% < num%
  348.     i% = i% + 1
  349.     freealloc pstr%( i% )
  350. endwh
  351. trap gclose hid%
  352. ENDP
  353.  
  354.  
  355. PROC hdialog:
  356. global title$(100), num%, lines%, level%, pos%, start%
  357. local d%, screen%
  358. onerr uhoh
  359.  
  360. first
  361. screen% = min( abs( scr% ), a.n% / $200 )
  362. level% = ( screen% = 0 ) + 2
  363. type% = 2
  364. position screen% + 1
  365. title$ = a.str$
  366. pos% = 1
  367.  
  368. if screen% = 0
  369.     num% = a.n% / $200
  370.     start% = 2
  371.     position start%
  372. else
  373.     start% = a.n%
  374.     position start%
  375.     num% = a.n% / $200
  376. endif
  377. hlist:(0)
  378.  
  379. while 1
  380.     d% = hmakedlg:
  381.     if d% = -1
  382.         break
  383.     elseif d%
  384.         if level% = 1
  385.             scr% = pos% + d% - 2
  386.             hcleanup:
  387.             hdialog:
  388.             position start%
  389.             hlist:(0)
  390.         endif
  391.     endif
  392. endwh
  393. uhoh::
  394. hcleanup:
  395. ENDP
  396.  
  397.  
  398. PROC hmakedlg:
  399. local i%, up%, down%, d%, entry$(100)
  400.  
  401. dinit "Help: " + title$
  402.  
  403. if pos% > 1
  404.     up% = 1
  405.     dtext "", chr$(24), $401
  406. endif
  407.  
  408. if pos% + 7 < num%
  409.     down% = 1
  410. endif
  411.  
  412. lines% = min( 8 - up% - down%, num% - pos% + 1 )
  413.  
  414. while i% < lines%
  415.     entry$ = peek$( pstr%( pos% + i% ) )
  416.     if entry$ = ""
  417.         entry$ = " "
  418.     endif
  419.     if level% = 1
  420.         dtext "", "ÿ" + entry$, $500
  421.     else
  422.         dtext "", entry$
  423.     endif
  424.     i% = i% + 1
  425. endwh
  426.  
  427. if down% : dtext "", chr$(25), $401 : endif
  428. d% = dialog
  429. if d%
  430.     if ( d% = 2 ) and ( up% = 1 )
  431.         pos% = pos% - 6 + ( pos% = 8 )
  432.     elseif ( d% = 9 ) and ( down% = 1 )
  433.         pos% = pos% + lines%
  434.     else
  435.         return d% - up%
  436.     endif
  437. else
  438.     return -1
  439. endif
  440. ENDP
  441.