antoine-source/appleworksgs/WP/Src/WpFileIO.aii

1 line
12 KiB
Plaintext
Raw Normal View History

2023-03-04 02:45:20 +00:00
***************************************************************************************************** * WPFileIO Routines * * This file contains the WP open and save routines. * ***************************************************************************************************** load 'macros.dump' include 'driver.equ' include 'wp.equ' IMPORT D_AlertBox IMPORT D_BeachBall IMPORT D_BitMapChanged IMPORT D_BitMapPtr IMPORT D_ClearFileChanged IMPORT D_Deref IMPORT D_GrowHandle IMPORT D_KillFont IMPORT D_MemoryError IMPORT D_NeedHandle IMPORT D_SystemHandle IMPORT D_StringBuffer IMPORT D_Read2 IMPORT D_Write2 IMPORT W_CollapseRulers IMPORT W_CurDoc IMPORT W_FillDateTime IMPORT W_GetAddr IMPORT W_GetDoc IMPORT W_GetParRec IMPORT W_LastP IMPORT W_MakeScrollBar IMPORT W_MaxP IMPORT W_NewWinComin IMPORT W_PHandle IMPORT W_PPtr IMPORT W_PutDoc IMPORT W_ScrollBar IMPORT W_SetFullREct IMPORT D_SetRefCon IMPORT W_ShowRuler IMPORT W_SizeWinGlobals IMPORT W_StartPar IMPORT W_StartRuler IMPORT W_StartWinGlobals IMPORT W_SwitchData IMPORT W_View IMPORT X_DisposeWPScrap IMPORT X_ReadWPScrap IMPORT X_WriteThread ***************************************************************************************************** ; W_OpenDoc ( FileRef:word, WindowPtr:long ) ; ; This routine will handle reading in a word processing document with the given file reference. ; The file has already been opened by the driver and the file mark moved to the start of the document ; data. Memory or file I/O errors are returned to the driver which will handle closing the file and ; alerting the user. W_OpenDoc PROC EXPORT ;Using WpGlobals ;Using D_IOData ;Using W_SampleData ;Using W_ATTRData ;Using W_WPFileIOData EXPORT W_FVersion input FileRef:w,window:l local Scrap:l,ScrapPtr:l,ScrapSize:l,OldShowRul:w local Version:w,CurView:w,RefHand:l,Ptr:l,SaveDoc:l local bodyscrap:l,footerscrap:l,headerscrap:l error err begin +b ; Clear error status, save current document's data to its refcon, save the document so it can be ; restored before exiting, and make the input window the current document. Remember the old port ; on the stack and setport to new window. stz err jsl W_PutDoc movelong W_CurDoc,SaveDoc movelong window,W_CurDoc tool _GetPort,out=(:l) tool _SetPort,in=(window:l) ; Create the refcon handle that will hold this windows globals. If we get a memory err then exit. call D_NeedHandle,in=(#W_SizeWinGlobals:l,#attrfixed:w),out=(RefHand:l),err=err jcs exit ; Set window refcon to the handle we created. movelong [RefHand],Ptr call D_SetRefCon,in=(Ptr:l,Window:l) ; Get version number from file. If error reading then exit after disposing of refcon. Check if valid ; version if not warn user and exit. call D_Read2,in=(FileRef:w,!Version:l,#2:l),out=(ax:l),err=err jcs killref cmpw Version,W_FVersion jlt laterversion cmp #1 jeq earlyversion ; Read in the globals for the document. If error then dispose of refcon and exit. call D_Read2,in=(FileRef:w,#W_StartWinGlobals:l,#W_SizeWinGlobals:l),out=(ax:l),err=err jcs killref ; Save ruler status and view status brought in from file. moveword W_ShowRuler,OldShowRul moveword W_View,CurView ; Read in the document body, header, and footer. If any memory errors occurs dispose of the scraps ; we have read so far and the document refcon we created. call X_ReadWPScrap,in=(FileRef:w,#0:w),out=(bodyscrap:l),err=err jcs killref call X_ReadWPScrap,in=(FileRef:w,#0:w),out=(headerscrap:l),err=err jcs killbody call X_ReadWPScrap,in=(FileRef:w,#0:w),out=(footerscrap:l),err=err jcs killheader ; Successfully read in all three document parts as WP scraps. Now managle each scrap into a document ; thread and switch it into its correct globals location. Finally switch to the document part that ; was being edited when the document was saved. call W_SwitchData,in=(#W_NormalOn:w) movelong bodyscrap,scrap jsr manglescrap call W_SwitchData,in=(#W_HeaderOn:w) movelong headerscrap,scrap jsr manglescrap call W_SwitchD