home *** CD-ROM | disk | FTP | other *** search
EPOC OPL Source | 1999-02-20 | 14.1 KB | 612 lines |
-
-
- APP RMREvent,42
- ICON "RMREvent.icn"
- FLAGS 1
- ENDA
-
- INCLUDE "CONST.OPH"
- INCLUDE "PRINTER.OXH"
- INCLUDE "SYSTEM.OXH"
- INCLUDE "DBASE.OXH"
- INCLUDE "RMREVENT.OSG"
-
- CONST RMREvent_UID&=4
- CONST Key_Pressed=&400
- CONST Program_To_Foreground=&401
- CONST Program_To_Background=&402
- CONST Open_or_Close_Document=$404
- CONST Key_Down=&406
- CONST Key_Up=&407
- CONST Pointer_Used=&408
- CONST Pointer_Enter=&409
- CONST Pointer_Exit=&40A
- CONST KCmdLetterExit$="X"
- CONST Forever=0
-
- PROC Start:
- LOADM "Z:\SYSTEM\OPL\TOOLBAR.OPO"
- TBarLink:("Main")
- ENDP
-
- PROC Main:
- GLOBAL Key&,A&(20),DocumentName$(255),SystemCommandLetter$(3),Toolbar%,A%,Dev$(3)
- GLOBAL Mod%,Control%,Shift%,ScreenWidth%,off%(6),RID&
- GLOBAL One&,Two&,Three&,Four&,Minit%,Mainscn%,Screen2%,Buffer&(65),TextString$(255)
- GLOBAL Icon$(50),RSC$(50),Path$(255),Data$(255),LastUsed$(255),Thread&,Program$(20),Version$(5)
- GLOBAL Scrollscn%,Upid&,Downid&,Sliderid&,Findid&,Scrollpos%,Screenheight%,RMRId&
-
- DocumentName$=CMD$(2)
- SystemCommandLetter$=CMD$(3)
-
- Program$="RMREvent"
- Version$="1.8"
-
- Init:
- ActionSystemEvent:
- DO
- Run:
- UNTIL Forever
- ENDP
-
- PROC Run:
- ONERR Handler::
- DO
- GETEVENT32 A&()
- IF A&(1)=Open_or_Close_Document
- DocumentName$=GETCMD$
- SystemCommandLetter$=LEFT$(DocumentName$,1) : DocumentName$=MID$(DocumentName$,2,255)
- ActionSystemEvent:
- A&(1)=Program_To_Foreground
- ELSEIF A&(1)=Program_To_Background
- Background:
- ELSEIF A&(1)=Program_To_Foreground
- Foreground:
- ELSE
- REM Determine status of modifier keys
- Mod%=A&(4) AND 255
- IF Mod% AND 2
- Shift%=KTrue%
- ELSE
- Shift%=KFalse%
- ENDIF
- IF Mod% AND 4
- Control%=KTrue%
- ELSE
- Control%=KFalse%
- ENDIF
- Key&=A&(1)
- Action_Pen_or_Keypress:
- ENDIF
- UNTIL Forever
- Handler::
- ONERR OFF
- Error_Handler:(Program$)
- ENDP
-
- PROC Action_Pen_or_Keypress:
- IF Key&=Key_Up OR Key&=Key_Down
- RETURN
- ELSEIF Key&=Pointer_Used
- IF TBarOffer%:(A&(3),A&(4),A&(6),A&(7))
- RETURN
- ELSEIF A&(4)=1
- Pointer_Event:(A&(3),A&(6),A&(7))
- ENDIF
- ELSEIF Key&=10001
- giPRINT "Cut/Copy/Paste"
- ELSEIF Key&=10002
- giPRINT "InfraRed"
- ELSEIF Key&=10003
- giPRINT "Zoom in"
- ELSEIF Key&=10004
- giPRINT "Zoom out"
- ELSEIF Key&=4101 : giPRINT "Page Down"
- ELSEIF Key&=4100 : giPRINT "Page Up"
- ELSEIF Key&=4099 : giPRINT "End"
- ELSEIF Key&=4098 : giPRINT "Home"
- ELSEIF Key&=4106 : giPRINT "Cursor Down"
- ELSEIF Key&=4105 : giPRINT "Cursor Up"
- ELSEIF Key&=4104 : giPRINT "Cursor Right"
- ELSEIF Key&=4103 : giPRINT "Cursor Left"
- ELSEIF Key&=4150 OR Key&=10000
- Display_Menu:
- ENDIF
- IF Shift%
- Key&=Key&-32
- ENDIF
- IF Key&<=300
- Action_Key:
- ENDIF
- Shift%=0 : Control%=0
- ENDP
-
- PROC Display_Menu:
- mINIT
- mCASC "Printing","Page setup…",%U,"Print setup…",%P,"Print preview…",%V,"Print…",%p
- mCARD "File","Create new document…",%n,"Open existing document…",-%o,"Printing>",-16,"Close",%e
- mCARD "Edit","Text",%u
- mCARD "View","Zoom in",%m,"Zoom out",-%M,"Show toolbar",%t OR -$2800*Toolbar%
- mCARD "Tools","Help on RMREvent…",%H,"About RMREvent…",%A
- Key&=MENU(Minit%)-96
- Control%=KTrue%
- ENDP
-
- PROC Action_Key:
- LOCAL G$(20)
- Printkey:
- IF Key&=ASC("n")-96 : Newfile:
- ELSEIF Key&=ASC("o")-96 : Open_Existing_file:
- ELSEIF Key&=ASC("t")-96 : ToolSwitch:
- ELSEIF Key&=ASC("e")-96 : Exit:
- ELSEIF Key&=ASC("H")-96 : Help:
- ELSEIF Key&=ASC("A")-96 : About:
- ELSEIF Key&=ASC("u")-96 : TextEditor:
- ELSEIF Key&=ASC("m")-96 AND Control%=KTrue% : giPRINT "Zoom in" : Key&=0
- ELSEIF Key&=ASC("M")-96 AND Control%=KTrue% : giPRINT "Zoom out" : Key&=0
-
- ELSE
-
- REM Add your application specific keys here
- REM The following code just displays the keypress
-
- IF Shift% : G$="Shift+" : Key&=Key&+32 : ENDIF
- IF Key&=13
- giPRINT "Enter"
- ELSEIF Key&=9
- giPRINT "Tab"
- ELSEIF Key&=8
- giPRINT "Delete"
- ELSEIF Key&=27
- giPRINT "Escape"
- ELSEIF Key&=32
- giPRINT "Space Bar"
- ELSEIF Key&>96
- giPRINT G$+CHR$(Key&-32)
- ELSEIF Control%
- giPrINT G$+"Ctrl+"+CHR$(Key&+64)
- ELSE
- giPrINT G$+CHR$(Key&)
- ENDIF
-
- ENDIF
- ENDP
-
- PROC Printkey:
- ResetPrinting:
- IF Key&=ASC("U")-96 : PageSetupDialog:
- ELSEIF Key&=ASC("P")-96 : PrintRangeDialog:
- ELSEIF Key&=ASC("V")-96
- ONERR Printquit::
- Print: : PrintPreviewDialog:
- ELSEIF Key&=ASC("p")-96
- ONERR Printquit::
- Print: : PrintDialog:
- ENDIF
- ONERR OFF : RETURN
- Printquit::
- ONERR OFF
- giPRINT "Problem with Printer"
- ENDP
-
- PROC ActionSystemEvent:
- IF SystemCommandLetter$=KCmdLetterCreate$
- Create:(DocumentName$)
- ELSEIF SystemCommandLetter$=KCmdLetterOpen$
- Openfile:
- ELSEIF SystemCommandLetter$=KCmdLetterRun$
- Resumefile:
- ELSEIF SystemCommandLetter$=KCmdLetterExit$
- STOP
- ENDIF
- ENDP
-
- PROC Init:
- Screenheight%=gHEIGHT
- Path$="\System\Apps\RMREvent\"
- Data$="C:\System\Apps\RMREvent\"
- Toolbar%=KTrue%
- TRAP MKDIR Data$
- Load_INI_File:
- Setup_Toolbar:
- RSC$=Path$+"RMREvent.rsc"
- IF Device:(RSC$)
- rId&=LoadRsc&:(Dev$+RSC$)
- ELSE
- dINIT "File not found"
- dTEXT "","RMREvent.RSC not found",2
- dBUTTONS "OK",($300 or 13)
- DIALOG
- STOP
- ENDIF
- Icon$=Path$+"RMREvent.mbm"
- IF Device:(Icon$)
- Icon$=Dev$+Icon$
- Upid&=gLOADBIT(Icon$,0,0)
- Downid&=gLOADBIT(Icon$,0,1)
- Sliderid&=gLOADBIT(Icon$,0,2)
- FindId&=gLOADBIT(Icon$,0,3)
- RMRId&=gLOADBIT(Icon$,0,7)
- ELSE
- ALERT ("MBM file not found")
- STOP
- ENDIF
- MainScn%=gCREATE (0,0,Screenwidth%-23,Screenheight%,1,1)
- gBORDER 0
- Screen2%=gCREATE (200,145,300,60,1,1)
- gBORDER 0
- ScrollScn%=gCREATE (Screenwidth%-23,0,23,Screenheight%,0,1)
- gBORDER 0
- Scrollpos%=100
- Setup_Scroll:
- TBarButt:("a",1,"",0,One&,One&,0)
- TBarButt:("b",2,"Find",0,FindId&,FindId&,0)
- TBarButt:("c",3,"No\Yes",0,Three&,Three&,0)
- TBarButt:("d",4,"Raise"+CHR$(10)+"Error",0,Four&,Four&,0)
- Instructions:
- ENDP
-
- PROC Setup_Scroll:
- gUSE Scrollscn%
- gAT 1,1 : gFILL 21,Screenheight%-2,1
- gAT 0,Screenheight%-44
- gCOPY Upid&,0,0,24,24,0
- gAT 0,Screenheight%-22
- gCOPY Downid&,0,0,24,24,0
- gAT 0,Scrollpos%
- gCOPY SliderId&,0,0,24,24,0
- gVISIBLE ON
- ENDP
-
- PROC Setup_Toolbar:
- TBarInit:("Demo",gWidth,gHeight)
- IF Toolbar%=KTrue%
- TBarShow: : Screenwidth%=568
- ELSE
- TBarHide: : Screenwidth%=640
- ENDIF
- ENDP
-
- PROC Load_INI_File:
- IF EXIST (Data$+"RMREvent.ini")
- OPEN Data$+"RMREvent.ini",A,F1$
- LastUsed$=A.F1$
- NEXT
- TextString$=A.F1$
- CLOSE
- ENDIF
- ENDP
-
- PROC Save_INI_File:
- TRAP DELETE Data$+"RMREvent.ini"
- CREATE Data$+"RMREvent.ini",A,F1$
- A.F1$=LastUsed$
- APPEND
- A.F1$=TextString$
- APPEND
- CLOSE
- ENDP
-
- PROC Cmda%:
- giPRINT "Button 1 on Toolbar pressed"
- ENDP
-
- PROC Cmdb%:
- giPRINT "'Find' Button on Toolbar pressed"
- ENDP
-
- PROC Cmdc%:
- dINIT "Example"
- dTEXT "","A simple No/Yes dialog"
- dBUTTONS "No",%n OR KDButtonNoLabel% OR KDButtonPlainKey%,"Yes",%y OR KDButtonNoLabel% OR KDButtonPlainKey%
- IF DIALOG=%y
- giPRINT "Yes"
- ELSE
- giPRINT "No"
- ENDIF
- ENDP
-
- PROC Cmdd%:
- giPRINT "Button 4 on Toolbar pressed"
- REM Raise an example error
- RAISE -78
- ENDP
-
- PROC Pointer_Event:(Window&,X_Position&,Y_Position&)
- IF Window&=MainScn%
- giPRINT "Pen/Pointer is on the main window at X - "+FIX$(X_Position&,0,9)+" Y - "+FIX$(Y_Position&,0,9)
- ELSEIF Window&=Screen2%
- giPRINT "Pen/Pointer is on the secondary window at X - "+FIX$(X_Position&,0,9)+" Y - "+FIX$(Y_Position&,0,9)
- ELSEIF Window&=Scrollscn%
- IF Y_Position&<Scrollpos%
- giPRINT "Pen/Pointer is on the scroll window above the slider",1
- Scrollmove:(-30)
- ELSEIF Y_Position&<Screenheight%-44
- giPRINT "Pen/Pointer is on the scroll window below the slider",1
- Scrollmove:(30)
- ELSEIF Y_Position&<Screenheight%-22
- giPRINT "Cursor Up",1
- Scrollmove:(-10)
- ELSE
- giPRINT "Cursor Down",1
- Scrollmove:(10)
- ENDIF
- ENDIF
- ENDP
-
- PROC ScrollMove:(D%)
- Scrollpos%=Scrollpos%+D%
- IF Scrollpos%>Screenheight%-60
- Scrollpos%=Screenheight%-60
- ELSEIF Scrollpos%<0
- Scrollpos%=0
- ENDIF
- Setup_scroll:
- ENDP
-
- PROC Toolswitch:
- gCLOSE MainScn% : gCLOSE Scrollscn%
- IF Toolbar%
- Toolbar%=KFalse% : TBarHide: : Screenwidth%=640
- ELSE
- Toolbar%=KTrue% : TBarShow: : Screenwidth%=568
- ENDIF
- MainScn%=gCREATE (0,0,Screenwidth%,Screenheight%,1,1)
- ScrollScn%=gCREATE (Screenwidth%-23,0,23,Screenheight%,0,1)
- gBORDER 0
- Setup_Scroll:
- gORDER Screen2%,1
- Instructions:
- ENDP
-
- PROC ToolBarTitle:(A$)
- REM 'Trim Filename to 7 characters to fit ToolBar
- TBarSetTitle:(LEFT$(MID$(PARSE$(A$,DocumentName$,off%()),Off%(4),Off%(5)-Off%(4)),7))
- ENDP
-
- PROC NewFile:
- LOCAL File$(255),Ok%
- DO
- Ok%=KTrue%
- dINIT "New data file"
- dFILE File$,"File,Folder,Disk",1
- dBUTTONS "Cancel",KDButtonEsc% OR KDButtonNoLabel% OR KDButtonPlainKey%,"OK",KDButtonEnter% OR KDButtonNoLabel% OR KDButtonPlainKey%
- IF DIALOG=KDButtonEnter%
- IF NOT EXIST (File$)
- Create:(File$)
- ELSE
- giPRINT "Document already exists"
- Ok%=KFalse%
- ENDIF
- ENDIF
- UNTIL Ok%=KTrue%
- ENDP
-
- PROC Create:(File$)
- LOCAL Key1&
- SETDOC File$
- CREATE """"+File$+""" FIELDS Date,Number,Details TO Entries",A,F1&,F2%,F3$
- USE A : CLOSE
- Key1&=DbNewKey&:
- DbAddField:(Key1&,"Date",1)
- DbSetComparison:(Key1&,1)
- DbCreateIndex:("Date",Key1&,File$,"Entries")
- DbDeleteKey:(Key1&)
- DocumentName$=File$
- LastUsed$=File$
- ToolBarTitle:(File$)
- giPRINT "File created"
- ENDP
-
- PROC Open_Existing_File:
- LOCAL File$(255),Ret%
- File$=DocumentName$
- DO
- dINIT "Open existing file"
- dFILE File$,"File,Folder,Disk",2,0,KUidOplDoc&,RMREvent_UID&
- dBUTTONS "Cancel",KDButtonEsc% OR KDButtonNoLabel% OR KDButtonPlainKey%,"OK",KDButtonEnter% OR KDButtonNoLabel% OR KDButtonPlainKey%
- IF DIALOG=KDButtonEnter%
- DocumentName$=File$ : Ret%=Openfile:
- ELSE : Ret%=KTrue%
- ENDIF
- UNTIL Ret%=KTrue%
- ENDP
-
- PROC OpenFile:
- LOCAL Order$(20),Filter$(20),Ok%
- dINIT "Message"
- dTEXT "","The program has been asked to open the"
- dTEXT "","the file : "+DocumentName$
- dBUTTONS "Close",KDButtonEnter% OR KDButtonNoLabel% OR KDButtonPlainKey%
- IF DIALOG
- SETDOC DocumentName$
- Order$=" ORDER BY Date"
- Filter$=" WHERE Number>4"
- TRAP OPEN """"+DocumentName$+""" FOLDED SELECT Date,Number,Details FROM Entries"+Filter$+Order$,A,F1&,F2%,F3$
- IF ERR
- giPRINT "Not a valid RMREvent file"
- RETURN KFalse%
- ELSE
- USE A : CLOSE
- LastUsed$=DocumentName$
- ToolBarTitle:(DocumentName$)
- giPRINT "File Opened"
- RETURN KTrue%
- ENDIF
- ENDIF
- ENDP
-
- PROC ResumeFile:
- IF LastUsed$="" OR EXIST (LastUsed$)=0
- dINIT "Message"
- dTEXT "","The program has been asked to open"
- dTEXT "","the last used file, but it doesn't"
- dTEXT "","exist. You will therefore be asked"
- dTEXT "","to create a new one."
- dBUTTONS "Close",KDButtonEnter% OR KDButtonNoLabel% OR KDButtonPlainKey%
- DIALOG
- NewFile:
- ELSE
- DocumentName$=LastUsed$
- SETDOC DocumentName$
- Openfile:
- ToolBarTitle:(DocumentName$)
- ENDIF
- ENDP
-
- PROC Background:
- LOCAL E&(16),Keytosend&,Modtosend&,Caped&
- giPRINT "Program has moved to background",2
- Keytosend&=5 REM <Ctrl+Fn+E> (A=1,B=2..., but avoid "S")
- Modtosend&=KModifierCtrl&+KModifierFunc&
- Caped&=CaptureKey&:(Keytosend&,Modtosend&,Modtosend&)
- DO
- GETEVENT32 E&()
- IF E&(1)=Open_or_Close_Document
- DocumentName$=GETCMD$
- SystemCommandLetter$=LEFT$(DocumentName$,1)
- DocumentName$=MID$(DocumentName$,2,255)
- E&(1)=Program_To_Foreground
- ActionSystemEvent:
- ENDIF
- UNTIL E&(1)<&60 OR E&(1)=Program_To_Foreground
- CancelCaptureKey:(Caped&)
- IF E&(1)<&60
- SetForeground:
- ENDIF
- ENDP
-
- PROC Foreground:
- giPRINT "Program has moved to foreground",2
- ENDP
-
- PROC Print:
- ResetPrinting:
- SetFontName:("Courier")
- SetFontHeight:(200)
- SendStringToPrinter:("Printer Demonstration")
- SendNewParaToPrinter:
- SendBitmapToPrinter:(RMRId&)
- ENDP
-
- PROC About:
- dINIT "Event Driven Core"
- dTEXT "","Version "+Version$
- dTEXT "","Produced by Al Richey"
- dTEXT "","feel free to use it as a"
- dTEXT "","basis for your programs"
- dBUTTONS "OK",KDButtonEnter% OR KDButtonNoLabel% OR KDButtonPlainKey%
- DIALOG
- ENDP
-
- PROC Help:
- LOCAL HelpFile$(255)
- IF Device:(Path$+"RMREvent.hlp")
- Helpfile$=Dev$+Path$+"RMREvent.hlp"
- IF Thread&<>0
- ONERR Notopen::
- SetForegroundByThread&:(Thread&,0)
- ELSE
- Notopen::
- ONERR OFF
- Thread&=RunApp&:("Data",Helpfile$,"",0)
- ENDIF
- ELSE
- giPRINT "Help file not found"
- ENDIF
- ENDP
-
- PROC Exit:
- Save_INI_File:
- IF Thread&<>0
- ONERR Exitanyway::
- EndTask&:(Thread&,0)
- ENDIF
- Exitanyway::
- STOP
- ENDP
-
- PROC Instructions:
- gUSE MainScn%
- gAT 1,1 : gBUTTON "",1,60,60,0,RMRId&,RMRId&
- gFONT KFontArialNormal18&
- gAT 70,20 : gPRINT "OPL Event-Driven Core (© Al Richey)"
- gAT 70,22 : gLINEBY 300,0
- gFONT KFontArialNormal13&
- gSTYLE KgStyleItalic%
- gAT 80,40 : gPRINT "(provided to help programmers)"
- gFONT KFontArialNormal15&
- gAT 360,50 : gPRINT ReadRsc$:(Version_&)
- gAT 10,80 : gPRINT ReadRsc$:(Instructions1_&)
- gAT 10,100 : gPRINT ReadRsc$:(Instructions2_&)
- gAT 10,120 : gPRINT ReadRsc$:(Instructions3_&)
- gAT 10,140 : gPRINT ReadRsc$:(Instructions4_&)
- gAT 10,160 : gPRINT ReadRsc$:(Instructions5_&)
- gAT 10,180 : gPRINT ReadRsc$:(Instructions6_&)
- gAT 10,200 : gPRINT ReadRsc$:(Instructions7_&)
- gSTYLE 0
- gAT 10,225 : gPRINT ReadRsc$:(Instructions8_&)
- REM gAT 10,225 : gPRINT ReadRsc$:(Blank_&)
- gUSE Screen2%
- gFONT KFontArialNormal27&
- gAT 20,40 : gPRINT "Secondary Window"
- ENDP
-
- PROC Error_Handler:(P$)
- DINIT "",2
- dTEXT "","Sorry. it seems an unexpected error has occured"
- dTEXT "","Please E-mail me at : xxxxxxxx.xxxx@xxxx.com"
- dTEXT "","and tell me the EXACT circumstances and the key"
- dTEXT "","presses that led to this error. I will also need"
- dTEXT "","the following additional information :"
- dTEXT "","",$800
- dTEXT "",P$+" Version "+Version$
- dTEXT "","There has been an "+ERRX$
- dTEXT "","The error was : "+ERR$(ERR)
- dBUTTONS "Continue",13 OR $300
- DIALOG
- ENDP
-
- PROC Device:(F$)
- Dev$="C:"
- IF EXIST (Dev$+F$) : RETURN KTrue%
- ELSE
- Dev$="D:"
- IF EXIST (Dev$+F$)
- RETURN KTrue%
- ELSE
- RETURN KFalse%
- ENDIF
- ENDIF
- ENDP
-
- PROC TextEditor:
- Buffer:(TextString$)
- dINIT "Text Editor"
- dEDITMULTI ADDR(buffer&(1)),"",30,5,240
- dBUTTONS "Cancel",KDButtonEsc% OR KDButtonNoLabel% OR KDButtonPlainKey%,"Save",%s
- IF DIALOG=%s
- TextString$=Buffer$:
- ENDIF
- ENDP
-
- PROC Buffer$:
- LOCAL C4&,A$(255)
- C4&=ADDR(Buffer&(1))
- POKEB C4&+3,PEEKB (C4&)
- A$=PEEK$(C4&+3)
- POKEB C4&+3,0
- RETURN A$
- ENDP
-
- PROC Buffer:(A$)
- LOCAL C4&
- C4&=ADDR(Buffer&(1))
- POKE$ C4&+3,A$
- POKEB C4&,PEEKB (C4&+3)
- POKEB C4&+3,0
- ENDP
-
-
-
-