home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 3
/
PDCD_3.iso
/
pocketbk
/
developmen
/
appman
/
APPMAN.OPL
Wrap
Text File
|
1995-04-18
|
22KB
|
762 lines
REM You have a royalty free right to use
REM this software in any way that you
REM see fit, provided that you agree that
REM neither Jezar nor Psion will be held
REM responsible for the consequences of your
REM doing so. This software is free and
REM unsupported, so you must treat it as having
REM no warranties whatsoever.
REM
REM That having been said, I have done my utmost
REM to ensure that the supplied code is bug free,
REM but again - no guarantees can be made.
REM
REM This software is for the Psion Series 3a
REM It should also function correctly on the
REM WorkAbout, although I have not tested this.
REM
REM Use "outline" in Program editor to see which
REM procedures you can directly use in this file.
REM
REM This program demonstrates how to launch menus
REM and dialogs asynchronously in OPL. This allows
REM your program to be completely responsive to
REM all messages at all times, so users can
REM close your application from the system screen
REM even when a menu is showing, etc.
REM
REM It also shows how you can have nested
REM dialogs to any level, and how you can use
REM alternative UI elements such as a DONEWN
REM within your dialog boxes.
REM
REM To use this material effectively, you need
REM a strong understanding of how event driven
REM software works. In addition, you must remember
REM that after trapping normal keypresses that
REM are not destined for a dialog or menu, you
REM must return 1 to eat the key, or the wserv
REM object will try to send it to a non-existant
REM client window which will give you "Exit 55"
REM
REM Alternatively, you could create a win instance
REM (or subclass) and poke its handle in like this:
REM POKEW UADD(PEEKW($12),$22),mywin%
REM which is the location of wserv->wserv.cli
REM and that would "soak up" the keypress whilst
REM using only 8 bytes of memory.
REM
REM Other potential errors you may encounter
REM if you try to modify this code are:
REM
REM "Exit 111" - wserv read outstanding.
REM Most likely the console has been turned
REM back on accidently by using normal
REM MENU and DIALOG commands interspersed
REM with these routines.
REM
REM "Exit 48" - invalid method
REM You have probably used a positive number
REM for the exit buttons on a gauge. All
REM buttons on a gauge-equipped dialog must
REM be negative.
REM
REM Further information on these subjects is
REM contained in Volume Four of the Psion C SDK.
REM
REM I hope this will be of use to you!
REM
REM Good luck,
REM Regards,
REM Jezar
REM Tue 18 Apr 1995
PROC mpStart%:
REM Main program starting point
GLOBAL LHwim%,LOlib%
TRAP CACHE $800,$2000
mpSetup%:
mpMain%:
ENDP
REM ----------------------------------------
REM The hook procs below, are near the
REM front of this source file for speed in OPL
PROC hpWserv%: REM Hook wserv event
REM Hook point for events read by the window
REM server. You get these before the relevant
REM entity (menu/dialog/help) does.
REM Return 0 to allow the dispatch of the
REM event, or return/raise any errors instead.
LOCAL type%,handle%,dummy%,keyk%,modk%
REM Copy the details of the event.
REM We copy 9 bytes because we are
REM not interested in key repeats
REM (which would be the upper byte of modk%)
CALL($a1,0,9,0,UADD(PEEKW($12),12),ADDR(type%))
REM In this example, we allow the user to
REM turn off all the debugging messages below
IF PEEKW($30)=0
RETURN
ENDIF
REM Jump according to what type it is.
REM Tables translate very efficiently in OPL
VECTOR type%
Kpress, Mouse, Redraw, Unknown, Backg
Foreg, Rubber, User, Active, Unknown
Cancel, Kstate, RubInit, DeIcon, Attach
Detach, Command, TaskKey, TskUpdt, PowrOn
Esc, NewDate
ENDV
REM (example code follows)
REM Did you know that labels use
REM literally *no* code in OPL?
Unknown::
Rubber::
Active::
Kstate::
RubInit::
DeIcon::
Attach::
Detach::
TskUpdt::
Esc::
PRINT "Unknown event",type%
GOTO Common
TaskKey::
PRINT "An application button was pressed"
PRINT "(?? normally the system screen traps these)"
GOTO Common
User::
PRINT "Custom message"
PRINT "Who said that?"
GOTO Common
Redraw::
PRINT "Redraw message for win (0x";HEX$(handle%);")"
GOTO Common
Backg::
PRINT "Application sent to background"
GOTO Common
Foreg::
PRINT "Application brought to foreground"
GOTO Common
Cancel::
PRINT "Message cancelled"
PRINT "(sorry to bother you)"
GOTO Common
Mouse::
PRINT "You appear to have received"
PRINT "a mouse event. Most interesting..."
GOTO Common
Command::
PRINT "Message from system screen:"
PRINT GETCMD$
GOTO Common
PowrOn::
PRINT "Machine switched on with me visible"
GOTO Common
NewDate::
PRINT "The date has changed"
GOTO Common
Kpress::
PRINT "Keypress",keyk%,
IF keyk%>31 AND keyk%<127
PRINT "(""";CHR$(keyk%);""")"
ENDIF
PRINT "Modifiers 0x";HEX$(modk%)
GOTO Common
REM End of vectored OPL code
Common::
REM Common stuff would go here.
PRINT "-----------------------------"
ENDP
PROC hpRun%:(htask%) REM Hook task run
REM Hook point for a task about to run
REM Return >0 to prevent the object's run
REM or <0 for errors (or RAISE them)
REM (example code follows)
REM For our example progress gauge:
IF htask%=PEEKW($34)
exPgRun%:(htask%)
ENDIF
ENDP
PROC hpAbRun%:(htask%) REM Hook task clean
REM Hook point for a tasks cleanup
REM (The error code is stored in ERR)
REM Return zero to allow the objects cleanup
REM (example code follows)
PRINT "An object is aborting (0x";HEX$(htask%);")"
ENDP
REM ----------------------------------------
PROC amStart%: REM Start appman
REM Start the basic loop to get a message
REM from the server. May be called recursively
REM for modal interaction.
LOCAL amclean%,amqnext%,amstop%,amself%
LOCAL stop%,ret%,abret%,wserv%,menubar%
LOCAL pt%,aoisact%,donestp%
LOCAL htask%,waotask%
amself% = PEEKW($14)
amclean% = UADD(amself%,4)
amqnext% = UADD(amself%,14)
amstop% = UADD(amself%,18)
wserv% = PEEKW($12)
menubar% = UADD(wserv%,$20)
REM The waotask object eats
REM OPL signals under XWIM
REM Seeing as this *is* OPL we
REM will prevent it from running in
REM just this OPL version of am_start
waotask% = PEEKW(UADD(PEEKW($38),4))
REM Increment appman.stop
POKEW amstop%,PEEKW(amstop%)+1
stop%=PEEKW(amstop%)
REM Set the cleanup level
IF PEEKW(amclean%)
SEND(PEEKW(amclean%),29,#stop%)
ENDIF
REM We are about to queue a wserv read
REM so we *must* turn off the console
cnOff%:(1)
DO
REM Wait for event
SEND(amself%,5)
REM Find a task to run
pt%=amqnext% REM Task queue head
WHILE 1
abret%=0
REM Find next task
pt%=PEEKW(pt%)
IF pt%=amqnext%
ALERT("Stray signal death")
STOP
ENDIF
REM See if task is qualified to run
REM (remember to ignore waotask)
htask%=USUB(pt%,4)
aoisact%=UADD(htask%,9)
IF PEEKB(aoisact%)=0 OR PEEKW(UADD(