home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / appman / APPMAN.OPL
Text File  |  1995-04-18  |  22KB  |  762 lines

  1. REM You have a royalty free right to use
  2. REM this software in any way that you
  3. REM see fit, provided that you agree that
  4. REM neither Jezar nor Psion will be held
  5. REM responsible for the consequences of your
  6. REM doing so. This software is free and
  7. REM unsupported, so you must treat it as having
  8. REM no warranties whatsoever.
  9. REM
  10. REM That having been said, I have done my utmost
  11. REM to ensure that the supplied code is bug free,
  12. REM but again - no guarantees can be made.
  13. REM
  14. REM This software is for the Psion Series 3a
  15. REM It should also function correctly on the
  16. REM WorkAbout, although I have not tested this.
  17. REM
  18. REM Use "outline" in Program editor to see which
  19. REM procedures you can directly use in this file.
  20. REM
  21. REM This program demonstrates how to launch menus
  22. REM and dialogs asynchronously in OPL. This allows
  23. REM your program to be completely responsive to
  24. REM all messages at all times, so users can
  25. REM close your application from the system screen
  26. REM even when a menu is showing, etc.
  27. REM
  28. REM It also shows how you can have nested
  29. REM dialogs to any level, and how you can use
  30. REM alternative UI elements such as a DONEWN
  31. REM within your dialog boxes.
  32. REM
  33. REM To use this material effectively, you need
  34. REM a strong understanding of how event driven
  35. REM software works. In addition, you must remember
  36. REM that after trapping normal keypresses that
  37. REM are not destined for a dialog or menu, you
  38. REM must return 1 to eat the key, or the wserv
  39. REM object will try to send it to a non-existant
  40. REM client window which will give you "Exit 55"
  41. REM
  42. REM Alternatively, you could create a win instance
  43. REM (or subclass) and poke its handle in like this:
  44. REM POKEW UADD(PEEKW($12),$22),mywin%
  45. REM which is the location of wserv->wserv.cli
  46. REM and that would "soak up" the keypress whilst
  47. REM using only 8 bytes of memory.
  48. REM
  49. REM Other potential errors you may encounter
  50. REM if you try to modify this code are:
  51. REM
  52. REM "Exit 111" - wserv read outstanding.
  53. REM Most likely the console has been turned
  54. REM back on accidently by using normal
  55. REM MENU and DIALOG commands interspersed
  56. REM with these routines.
  57. REM
  58. REM "Exit 48" - invalid method
  59. REM You have probably used a positive number
  60. REM for the exit buttons on a gauge. All
  61. REM buttons on a gauge-equipped dialog must
  62. REM be negative.
  63. REM
  64. REM Further information on these subjects is
  65. REM contained in Volume Four of the Psion C SDK.
  66. REM
  67. REM I hope this will be of use to you!
  68. REM
  69. REM Good luck,
  70. REM Regards,
  71. REM Jezar
  72. REM Tue 18 Apr 1995
  73.  
  74. PROC mpStart%:
  75. REM  Main program starting point
  76.  
  77.         GLOBAL LHwim%,LOlib%
  78.         TRAP CACHE $800,$2000
  79.  
  80.         mpSetup%:
  81.         mpMain%:
  82. ENDP
  83.  
  84. REM ----------------------------------------
  85. REM The hook procs below, are near the
  86. REM front of this source file for speed in OPL
  87.  
  88. PROC hpWserv%:             REM Hook wserv event
  89. REM  Hook point for events read by the window
  90. REM  server. You get these before the relevant
  91. REM  entity (menu/dialog/help) does.
  92. REM  Return 0 to allow the dispatch of the
  93. REM  event, or return/raise any errors instead.
  94.  
  95.         LOCAL type%,handle%,dummy%,keyk%,modk%
  96.  
  97.         REM Copy the details of the event.
  98.         REM We copy 9 bytes because we are
  99.         REM not interested in key repeats
  100.         REM (which would be the upper byte of modk%)
  101.         CALL($a1,0,9,0,UADD(PEEKW($12),12),ADDR(type%))
  102.  
  103.         REM In this example, we allow the user to
  104.         REM turn off all the debugging messages below
  105.         IF PEEKW($30)=0
  106.                 RETURN
  107.         ENDIF
  108.  
  109.         REM Jump according to what type it is.
  110.         REM Tables translate very efficiently in OPL
  111.         VECTOR type%
  112.                 Kpress, Mouse,   Redraw,  Unknown, Backg
  113.                 Foreg,  Rubber,  User,    Active,  Unknown
  114.                 Cancel, Kstate,  RubInit, DeIcon,  Attach
  115.                 Detach, Command, TaskKey, TskUpdt, PowrOn
  116.                 Esc,    NewDate
  117.         ENDV
  118.  
  119.         REM (example code follows)
  120.  
  121. REM Did you know that labels use
  122. REM literally *no* code in OPL?
  123. Unknown::
  124. Rubber::
  125. Active::
  126. Kstate::
  127. RubInit::
  128. DeIcon::
  129. Attach::
  130. Detach::
  131. TskUpdt::
  132. Esc::
  133.         PRINT "Unknown event",type%
  134.         GOTO Common
  135. TaskKey::
  136.         PRINT "An application button was pressed"
  137.         PRINT "(?? normally the system screen traps these)"
  138.         GOTO Common
  139. User::
  140.         PRINT "Custom message"
  141.         PRINT "Who said that?"
  142.         GOTO Common
  143. Redraw::
  144.         PRINT "Redraw message for win (0x";HEX$(handle%);")"
  145.         GOTO Common
  146. Backg::
  147.         PRINT "Application sent to background"
  148.         GOTO Common
  149. Foreg::
  150.         PRINT "Application brought to foreground"
  151.         GOTO Common
  152. Cancel::
  153.         PRINT "Message cancelled"
  154.         PRINT "(sorry to bother you)"
  155.         GOTO Common
  156. Mouse::
  157.         PRINT "You appear to have received"
  158.         PRINT "a mouse event. Most interesting..."
  159.         GOTO Common
  160. Command::
  161.         PRINT "Message from system screen:"
  162.         PRINT GETCMD$
  163.         GOTO Common
  164. PowrOn::
  165.         PRINT "Machine switched on with me visible"
  166.         GOTO Common
  167. NewDate::
  168.         PRINT "The date has changed"
  169.         GOTO Common
  170. Kpress::
  171.         PRINT "Keypress",keyk%,
  172.         IF keyk%>31 AND keyk%<127
  173.                 PRINT "(""";CHR$(keyk%);""")"
  174.         ENDIF
  175.         PRINT "Modifiers 0x";HEX$(modk%)
  176.         GOTO Common
  177. REM End of vectored OPL code
  178.  
  179. Common::
  180.         REM Common stuff would go here.
  181.         PRINT "-----------------------------"
  182.  
  183. ENDP
  184.  
  185. PROC hpRun%:(htask%)       REM Hook task run
  186. REM  Hook point for a task about to run
  187. REM  Return >0 to prevent the object's run
  188. REM  or <0 for errors (or RAISE them)
  189.  
  190.         REM (example code follows)
  191.  
  192.         REM For our example progress gauge:
  193.         IF htask%=PEEKW($34)
  194.                 exPgRun%:(htask%)
  195.         ENDIF
  196. ENDP
  197.  
  198. PROC hpAbRun%:(htask%)     REM Hook task clean
  199. REM  Hook point for a tasks cleanup
  200. REM  (The error code is stored in ERR)
  201. REM  Return zero to allow the objects cleanup
  202.  
  203.         REM (example code follows)
  204.         PRINT "An object is aborting (0x";HEX$(htask%);")"
  205. ENDP
  206.  
  207. REM ----------------------------------------
  208.  
  209.  
  210.  
  211.  
  212. PROC amStart%:             REM Start appman
  213. REM  Start the basic loop to get a message
  214. REM  from the server. May be called recursively
  215. REM  for modal interaction.
  216.  
  217.         LOCAL amclean%,amqnext%,amstop%,amself%
  218.         LOCAL stop%,ret%,abret%,wserv%,menubar%
  219.         LOCAL pt%,aoisact%,donestp%
  220.         LOCAL htask%,waotask%
  221.  
  222.         amself%  = PEEKW($14)
  223.         amclean% = UADD(amself%,4)
  224.         amqnext% = UADD(amself%,14)
  225.         amstop%  = UADD(amself%,18)
  226.         wserv%   = PEEKW($12)
  227.         menubar% = UADD(wserv%,$20)
  228.  
  229.         REM The waotask object eats
  230.         REM OPL signals under XWIM
  231.         REM Seeing as this *is* OPL we
  232.         REM will prevent it from running in
  233.         REM just this OPL version of am_start
  234.         waotask% = PEEKW(UADD(PEEKW($38),4))
  235.  
  236.         REM Increment appman.stop
  237.         POKEW amstop%,PEEKW(amstop%)+1
  238.         stop%=PEEKW(amstop%)
  239.  
  240.         REM Set the cleanup level
  241.         IF PEEKW(amclean%)
  242.                 SEND(PEEKW(amclean%),29,#stop%)
  243.         ENDIF
  244.  
  245.         REM We are about to queue a wserv read
  246.         REM so we *must* turn off the console
  247.         cnOff%:(1)
  248.  
  249.         DO
  250.                 REM Wait for event
  251.                 SEND(amself%,5)
  252.  
  253.                 REM Find a task to run
  254.                 pt%=amqnext% REM Task queue head
  255.                 WHILE 1
  256.                         abret%=0
  257.  
  258.                         REM Find next task
  259.                         pt%=PEEKW(pt%)
  260.                         IF pt%=amqnext%
  261.                                 ALERT("Stray signal death")
  262.                                 STOP
  263.                         ENDIF
  264.  
  265.                         REM See if task is qualified to run
  266.                         REM (remember to ignore waotask)
  267.                         htask%=USUB(pt%,4)
  268.                         aoisact%=UADD(htask%,9)
  269.                         IF PEEKB(aoisact%)=0 OR PEEKW(UADD(