antoine-source/appleworksgs/PL/Src/PEDIT.S

1 line
17 KiB
ArmAsm
Executable File

load 'macros.dump'
include 'driver.equ'
include 'pl.equ'
include 'scrap.equ'
;-----------------------------------------------
;
; Imported addresses
;
;-----------------------------------------------
IMPORT D_ClosePicture
IMPORT D_CheckPurge
IMPORT X_CopyOneHandle
IMPORT X_CopyThread
IMPORT D_Deref
IMPORT X_DisposeScrap
IMPORT X_DisposeThread
IMPORT D_KillFont
IMPORT D_MemoryError
IMPORT P_BoundsRect
IMPORT P_BuildUndo
IMPORT P_CheckHand
IMPORT P_ContentRect
IMPORT P_CurrentWin
IMPORT P_DefFont
IMPORT P_DefSize
IMPORT P_DefStyle
IMPORT P_DelObjList
IMPORT P_DelObjects
IMPORT P_DeselectAll
IMPORT P_DrawObject
IMPORT P_DrawRgn
IMPORT P_Entry
IMPORT P_errorAlert
IMPORT P_FixMenus
IMPORT P_FixRect
IMPORT P_GetPictSize
IMPORT P_HotRect
IMPORT P_ImportHdl
IMPORT P_ImportType
IMPORT P_LastObj
IMPORT P_ListOp
IMPORT P_LoadWindowStuff
IMPORT P_local2PL
IMPORT P_NewObj
IMPORT P_NewTool
IMPORT P_NotActive
IMPORT P_ObjList
IMPORT P_PL2local
IMPORT P_Page
IMPORT P_PageMode
IMPORT P_PastePt
IMPORT P_Placing
IMPORT P_ThreadDir
IMPORT P_ThreadHdl
IMPORT X_PostScrap
IMPORT D_ScreenPort
IMPORT X_SwitchFont
IMPORT T_Clear
IMPORT T_Copy
IMPORT T_CpyOrClrObj
IMPORT T_CurParHdl
IMPORT T_Deactivate
IMPORT T_Dot
IMPORT T_DotLine
IMPORT T_DotObj
IMPORT T_DotOffset
IMPORT T_DotParag
IMPORT T_DrawRuler
IMPORT T_Editing
IMPORT T_GetParSize
IMPORT T_InvSelect
IMPORT T_Mark
IMPORT T_MarkLine
IMPORT T_MarkObj
IMPORT T_MarkOffset
IMPORT T_MarkParag
IMPORT T_Offset2Line
IMPORT T_PL2WPText
IMPORT T_Paste
IMPORT T_ReThread
IMPORT T_TextSelect
IMPORT T_WP2PLText
;-----------------------------------------------
;
; Forward addresses and entries
;
;-----------------------------------------------
ENTRY P_AddObjList
ENTRY P_ClearPrim
ENTRY P_Copy
ENTRY P_CopyObjList
ENTRY P_CopyPrim
ENTRY P_DrawImage
ENTRY P_GetCenter
ENTRY P_KillImport
;------------------------------------------------------------------------------
;
; P_Cut (Window:l) : ImageRoutine:l
;
P_Cut PROC EXPORT
;Using P_Data
;Using T_Data
;Using X_ClipData
input Window:l
output ImageRoutine:l
local SType:w,ScrapHdl:l
error Err
begin +b
in Window:l
out ImageRoutine:l,SType:w,ScrapHdl:l
xerr Err
xcall P_Copy
bcs Exit
call X_PostScrap,in=(SType:w,ScrapHdl:l)
call P_ClearPrim,in=(#1:w)
Exit return
ENDP
;------------------------------------------------------------------------------
;
; P_Copy (Window:l) : ImageRoutine:l,SType:w,ScrapHdl:l
;
P_Copy PROC EXPORT
;Using P_Data
;Using P_ObjData
;Using T_Data
;Using X_ClipData
input Window:l
output ImageRoutine:l,SType:w,ScrapHdl:l
error Err
begin +b
jsl P_Entry
stz Err
stz SType
stzl ImageRoutine
call P_BuildUndo,in=(#P_NoUndo:w)
lda T_Editing
beq NotText
lda T_TextSelect
beq Exit
call T_Copy,out=(ScrapHdl:l),err=(Err)
bcs Exit
call T_PL2WPText,in=(ScrapHdl:l)
moveword #WPText,SType
bra Exit
NotText
call P_CopyPrim,out=(ScrapHdl:l),err=(Err)
bcs Exit
cpzl ScrapHdl
beq Exit
moveword #PLPict,SType
movelong #P_DrawImage,ImageRoutine
Exit
return
ENDP
;------------------------------------------------------------------------------
;
; P_Paste (Window:l,ScrapHdl:l,X_ScrapType:w,PasteType:w,Where:l)
;
; Window - Window to paste into
; ScrapHdl - Handle to the scrap
; X_ScrapType - The type of scrap
; PasteType - 0:from menu; 1:directional; 2:import
; Where - Used if paste is directional
P_Paste PROC EXPORT
;Using P_Data
;Using P_ObjData
;Using T_Data
;Using X_ClipData
input Window:l,ScrapHdl:l,X_ScrapType:w,PasteType:w,Where:l
local ObjRect:r,Vert:w,Horiz:w,MidPt:w,Pt:l
local Hdl:l,Ptr:l,PCount:w,OldWindow:l,OldEditing:w
error Err
begin +b
stz Err
movelong P_CurrentWin,OldWindow
cmpl Window,P_CurrentWin
beq Active
inc P_NotActive
call P_LoadWindowStuff,in=(Window:l)
moveword T_Editing,OldEditing
stz T_Editing
Active
jsl P_Entry
call P_BuildUndo,in=(#P_NoUndo:w)
jsl P_KillImport
cmpw PasteType,#1
bne NotDir
rcall P_local2PL,in=(Where:ax),out=(Where:ax)
bra WhereSet
NotDir rcall P_GetCenter,out=(Where:ax)
WhereSet
cmpw X_ScrapType,#WPTEXT
jeq PasteText
call T_Deactivate,in=(#1:w,#1:w)
lda X_ScrapType
cmp #PICT
beq PastePict
cmp #PLPICT
jeq PasteObj
brl Done
PastePict
lda PasteType
cmp #2
jeq ImportPict
call P_GetPictSize,in=(ScrapHdl:l),out=(Pt:l)
lsr Pt
lsr Pt+2
subword Where,Pt,ObjRect
subword Where+2,Pt+2,ObjRect+2
lda P_PageMode
bne MakePictObj
lda ObjRect
bpl TryLeft
stz ObjRect
TryLeft lda ObjRect+2
bpl MakePictObj
stz ObjRect+2
; Make D_New object code set the obj bounds from the picture
MakePictObj
movelong ObjRect,ObjRect+4
call P_NewTool,in=(#P_ARROW:w,#1:w)
call P_NewObj,in=(#P_PICTURE:w,!ObjRect:l,ScrapHdl:l),out=(a:l)
brl Done
ImportPict
inc P_Placing
moveword #1,P_ImportType
movelong ScrapHdl,P_ImportHdl
stzl P_ThreadHdl
brl Done
PasteObj
cmpw PasteType,#1
bne NotDir2
movelong Where,P_PastePt
NotDir2
call P_NewTool,in=(#P_ARROW:w,#1:w)
call P_AddObjList,in=(ScrapHdl:l)
brl Done
PasteText
movelong [ScrapHdl],Ptr
moveword [Ptr],PCount
cmp #2500
blt Okay
call P_errorAlert,in=(#0:w)
brl KillScrap
Okay
; Convert the scrap type
in P_DefSize:b,P_DefStyle:b,P_DefFont:w,#0:w,ScrapHdl:l
xcall X_SwitchFont
call T_WP2PLText,in=(ScrapHdl:l),err=(Err)
jcs KillScrap
lda T_Editing
bne InsertText
cmpw PasteType,#2
beq ImportText
; Make a D_New Q_Text object and thread
NewTextObj
subword Where,#30,ObjRect
addword Where,#30,ObjRect+4
subword Where+2,#100,ObjRect+2
addword Where+2,#100,ObjRect+6
call P_NewTool,in=(#P_ARROW:w,#1:w)
call P_NewObj,in=(#P_ALPHA:w,!ObjRect:l,ScrapHdl:l),out=(a:l)
brl Done
ImportText
inc P_Placing
stz P_ImportType
stzl P_ThreadHdl
stz P_ThreadDir
movelong ScrapHdl,P_ImportHdl
bra Done
InsertText
call P_CheckHand,in=(#$8000:l),err=(Err)
bcc Okay2
call P_errorAlert,in=(#1:w)
call X_DisposeThread,in=(ScrapHdl:l,#1:w)
bra Done
Okay2
movelong T_CurParHdl,Hdl
movelong [Hdl],Ptr
addword [Ptr],PCount,a
cmp #2500
blt Okay3
call P_errorAlert,in=(#0:w)
call X_DisposeThread,in=(ScrapHdl:l,#1:w)
bra Done
Okay3
call T_Paste,in=(ScrapHdl:l,#1:w)
bra Done
KillScrap
call X_DisposeScrap,in=(X_ScrapType:w,ScrapHdl:l)
Done
jsl P_FixMenus
lda P_NotActive
beq Exit
moveword OldEditing,T_Editing
call P_LoadWindowStuff,in=(OldWindow:l)
stz P_NotActive
Exit return
ENDP
;------------------------------------------------------------------------------
;
; P_Clear ()
;
P_Clear PROC EXPORT
begin +b
jsl P_Entry
call P_ClearPrim,in=(#0:w)
return
ENDP
;------------------------------------------------------------------------------
;
; P_ClearPrim (D_DoCut:w)
;
P_ClearPrim PROC EXPORT
;Using P_Data
;Using T_Data
input D_DoCut:w
begin
lda T_Editing
beq DoObj
lda D_DoCut
bne @Cut
pushword #P_ClearTextUndo
bra Build
@Cut pushword #P_CutTextUndo
Build jsl P_BuildUndo
jsl T_Clear
bra Exit
DoObj
lda D_DoCut
bne Cut2
pushword #P_ClearObjUndo
bra Build2
Cut2 pushword #P_CutObjUndo
Build2 jsl P_BuildUndo
call P_DelObjects,in=(#0:w)
Exit jsl P_FixMenus
return
ENDP
;------------------------------------------------------------------------------
;
; P_SelectAll ()
;
P_SelectAll PROC EXPORT
;Using P_DATA
;Using P_OBJDATA
;Using T_Data
local ParagHdl:l,ParagPtr:l
begin +b
jsl P_Entry
lda T_Editing
jeq SelObject
call P_BuildUndo,in=(#0:w)
jsl T_InvSelect
stz T_DotParag
moveword #7,T_DotOffset
movelong T_CurParHdl,ParagHdl
movelong [ParagHdl],ParagPtr
lda [ParagPtr]
dec a
sta T_MarkParag
rcall T_GetParSize,in=(a:a),out=(a:a)
dec a ; No CR
sta T_MarkOffset
in T_DotParag:w,T_DotOffset:w
out T_DotObj:l,T_DotLine:w
xcall T_Offset2Line
in T_MarkParag:w,T_MarkOffset:w
out T_MarkObj:l,T_MarkLine:w
xcall T_Offset2Line
call T_DrawRuler
cmpl T_Dot,T_Mark
beq Exit
moveword #1,T_TextSelect
jsl T_InvSelect
bra Exit
SelObject call P_NewTool,in=(#P_Arrow:w,#1:w)
call P_ListOp,in=(P_ObjList:l,#PL_SelectAll:w,#0:l,#0:l)
Exit jsl P_FixMenus
return
ENDP
;------------------------------------------------------------------------------
;
; P_Duplicate ()
;
P_Duplicate PROC EXPORT
;Using P_Data
;Using P_ObjData
local ObjList:l
begin +b
jsl P_Entry
call P_BuildUndo,in=(#P_NoUndo:w)
call P_CopyPrim,out=(ObjList:l)
bcs _MemErr
call P_AddObjList,in=(ObjList:l)
Exit return
_MemErr
jsl D_MemoryError
bra Exit
ENDP
;------------------------------------------------------------------------------
;
; P_CopyPrim (): ObjList:l
;
P_CopyPrim PROC EXPORT
;Using P_Data
;Using P_ObjData
output ObjList:l
error Err
begin
call P_CopyObjList,in=(P_ObjList:l,#1:w),out=(ObjList:l),err=(Err)
bcs Exit
call P_BoundsRect,in=(ObjList:l,#P_HotRect:l),out=(a:w)
; Set P_PastePt to middle of the bounds rectangle plus an offset
addword P_HotRect,P_HotRect+4,a
lsr a
addword a,#6,P_PastePt
addword P_HotRect+2,P_HotRect+6,a
lsr a
addword a,#12,P_PastePt+2
; Offset object list to start at (0,0)
pushlong ObjList
pushword #PL_OffsetObj
subword #0,P_HotRect+2,s
subword #0,P_HotRect,s
pushlong #0
jsl P_ListOp
lda P_PageMode
beq Exit
call P_FixRect,in=(#P_HotRect:l,#P_RECTANGLE:w,#1:w,#0:w)
Exit return
ENDP
;-----------------------------------------------------------------------------
;
; P_CopyObjList (ObjHdl:l,CopyData:w) : CopyList:l
;
; If CopyData is true, any handles hanging off the object are also copied.
P_CopyObjList PROC EXPORT
;Using P_Data
;Using P_ObjData
;Using T_Data
;Using T_TextEqu
input ObjHdl:l,CopyData:w
output CopyList:l
error Err
local ObjPtr:l,NewObj:l,NewPtr:l,LastObj:l,LastPtr:l
local ObjNo:w,Size:l,ParagHdl:l,PictHdl:l,PictSize:l
local SPar:w,EPar:w,SOffset:w,EOffset:w,Q_Line:w,LinePtr:l
begin +b
stz Err
stzl CopyList
stzl LastObj
stz ObjNo
WhileLoop cpzl ObjHdl
jeq EndLoop
rcall D_Deref,in=(ObjHdl:ax),out=(ObjPtr:ax)
moveword [ObjPtr]:#P_Selected,a
jeq NextObject
call X_CopyOneHandle,in=(ObjHdl:l),out=(NewObj:l),err=(err)
jcs CleanUp
lda CopyData
jeq DidObject
; If its a Q_Text object, call X_CopyWPScrap
; If its a picture, copy the PictHdl
moveword [ObjPtr]:#P_Type,a
cmp #P_ALPHA
jne TryPict
; If this is the only object in the thread, I can copy it all.
; Otherwise I need to call T_Copy with the proper Dot and D_Mark.
movelong [ObjPtr]:#P_ParagHdl,ParagHdl
cpzl [ObjPtr]:#P_PThread
bne PartCopy
cpzl [ObjPtr]:#P_NThread
bne PartCopy
call X_CopyThread,in=(ParagHdl:l,#1:w),out=(ParagHdl:l),err=(Err)
jcs PreCleanUp
bra SetParHdl
PartCopy
call T_CpyOrClrObj,in=(ObjPtr:l,#1:w),out=(ParagHdl:l)
SetParHdl
movelong [NewObj],NewPtr
movelong ParagHdl,[NewPtr]:#P_ParagHdl
lda #0
moveword a,[NewPtr]:#P_PThread
moveword a,[NewPtr]:#P_PThread+2
moveword a,[NewPtr]:#P_NThread
moveword a,[NewPtr]:#P_NThread+2
bra DidObject
TryPict
cmp #P_PICTURE
bne DidObject
in [ObjPtr]:#P_PictHandle:l
out PictHdl:l
xerr Err
xcall X_CopyOneHandle
jcs PreCleanUp
movelong [NewObj],NewPtr
movelong PictHdl,[NewPtr]:#P_PictHandle
DidObject
; Set CopyList if its the first object
cpzl CopyList
bne Set
movelong NewObj,CopyList
Set
; Maintain the links
movelong [NewObj],NewPtr
movelong LastObj,[NewPtr]:#P_Prev
movelong #0,[NewPtr]:#P_Next
cpzl LastObj
beq First
movelong [LastObj],LastPtr
movelong NewObj,[LastPtr]:#P_Next
First
moveword ObjNo,[NewPtr]:#P_UndoData
movelong NewObj,LastObj
NextObject
tool _HUnlock,in=(ObjHdl:l)
inc ObjNo
movelong [ObjPtr],ObjHdl
brl WhileLoop
EndLoop
Exit return
PreCleanUp tool _DisposeHandle,in=(NewObj:l)
CleanUp call P_DelObjList,in=(CopyList:l,CopyData:w,#1:w)
stzl CopyList
bra Exit
ENDP
;------------------------------------------------------------------------------
;
; P_AddObjList (ObjList:l)
P_AddObjList PROC EXPORT
;Using P_Data
;Using P_ObjData
;Using T_Data
input ObjList:l
local CurObj:l,CurPtr:l,NextObj:l,ObjHdl:l,ObjPtr:l
local RgnHdl:l,ScreenRect:r,BRect:r,Pt:l
begin
jsl P_DeselectAll
cpzl ObjList
jeq Exit
; Make sure PastePt is on screen
rcall P_PL2local,in=(P_PastePt:ax),out=(Pt:ax)
tool _PtInRect,in=(!Pt:l,#P_ContentRect:l),out=(a:w)
bne OnScreen
rcall P_GetCenter,out=(P_PastePt:ax)
OnScreen
; Set Pt to offset each object to
call P_BoundsRect,in=(ObjList:l,!BRect:l),out=(a:w)
lsr BRect+4
subword P_PastePt,BRect+4,Pt
lsr BRect+6
subword P_PastePt+2,BRect+6,Pt+2
; Offset object list
call P_ListOp,in=(ObjList:l,#PL_OffsetObj:w,Pt:l,#0:l)
tool _NewRgn,out=(RgnHdl:l)
call P_ListOp,in=(ObjList:l,#PL_AddUpdate:w,RgnHdl:l,#0:l)
movelong ObjList,CurObj
Loop
movelong [CurObj],CurPtr
movelong [CurPtr],NextObj
cmpw [CurPtr]:#P_Type,#P_ALPHA
bne Next
lda #0
moveword a,[CurPtr]:#P_PThread
moveword a,[CurPtr]:#P_PThread+2
moveword a,[CurPtr]:#P_NThread
moveword a,[CurPtr]:#P_NThread+2
moveword a,[CurPtr]:#P_StartParag
moveword a,[CurPtr]:#P_StartLine
moveword P_Page,[CurPtr]:#P_PageNo
call T_ReThread,in=(CurObj:l)
Next cpzl NextObj
beq EndLoop
movelong NextObj,CurObj
bra Loop
EndLoop
movelong [CurObj],CurPtr
movelong P_ObjList,[CurPtr]:#P_Next
cpzl P_ObjList
beq NoObjects
movelong P_ObjList,ObjHdl
movelong [ObjHdl],ObjPtr
movelong CurObj,[ObjPtr]:#P_Prev
bra SetList
NoObjects movelong CurObj,P_LastObj
SetList movelong ObjList,P_ObjList
call P_DrawRgn,in=(RgnHdl:l)
addword P_PastePt,#6,P_PastePt
addword P_PastePt+2,#12,P_PastePt+2
Exit
return
ENDP
;-------------------------------------------------------------------------------
;
; P_GetCenter () : Q_center:ax
;
; Gets the Q_center of the screen and returns it in D_PL Coordinates.
P_GetCenter PROC EXPORT
;Using P_Data
addword P_ContentRect+2,P_ContentRect+6,a
lsr a
tax
addword P_ContentRect,P_ContentRect+4,a
lsr a
rcall P_local2PL,in=(ax:ax),out=(ax:ax)
rtl
ENDP
;------------------------------------------------------------------------------
;
; P_DrawImage (Where:l)
;
P_DrawImage PROC EXPORT
;Using P_Data
input Where:l
local Q_Rect:r,Tmp:w
begin +b
subword P_HotRect+4,P_HotRect,a
lsr a
sta Tmp
subword Where,Tmp,Q_Rect
addword Where,Tmp,Q_Rect+4
subword P_HotRect+6,P_HotRect+2,a
lsr a
sta Tmp
subword Where+2,Tmp,Q_Rect+2
addword Where+2,Tmp,Q_Rect+6
cmpw Q_Rect,Q_Rect+4
beq Q_Line
cmpw Q_Rect+2,Q_Rect+6
beq Q_Line
tool _FrameRect,in=(!Q_Rect:l)
bra Exit
Q_Line
tool _MoveTo,in=(Q_Rect:l)
tool _LineTo,in=(Q_Rect+4:l)
Exit return
ENDP
;------------------------------------------------------------------------------
;
; P_MakePict (ObjHdl:l) : PictHdl:l
;
; This routine makes a picture out of an object list.
; It can be called when I get a convert scrap message routine from the
; driver or when I get unloaded.
P_MakePict PROC EXPORT
;Using D_GlobalData
;Using P_ObjData
;Using P_Data
;Using T_Data
input ObjHdl:l
output PictHdl:l
error Err
local PicFrame:r,ObjPtr:l,LastObj:l,OldPort:l,ClipRgn:l
begin +b
stz Err
pushword P_PageMode
stz P_PageMode
; Get the bounding Q_Rect
call P_BoundsRect,in=(ObjHdl:l,!PicFrame:l),out=(a:w)
call P_FixRect,in=(!PicFrame:l,#P_RECTANGLE:w,#0:w,#1:w)
; Get the last object, so I can draw them back to front.
Loop
movelong ObjHdl,LastObj
movelong [ObjHdl],ObjPtr
movelong [ObjPtr],ObjHdl
cpzl ObjHdl
bne Loop
tool _GetPort,out=(OldPort:l)
tool _SetPort,in=(>D_ScreenPort:l)
jsl D_KillFont
tool _NewRgn,out=(ClipRgn:l)
tool _GetClip,in=(ClipRgn:l)
tool _ClipRect,in=(!PicFrame:l)
tool _OpenPicture,in=(!PicFrame:l),out=(PictHdl:l),err=(Err)
bcs RestorePort
tool _SetFontFlags,in=(#4:w)
tool _SetTextMode,in=(#modeForeCopy:w)
; Draw the objects
movelong LastObj,ObjHdl
WhileLoop
cpzl ObjHdl
beq EndLoop
call P_DrawObject,in=(ObjHdl:l,#1:w),err=err
bcs endloop
movelong [ObjHdl],ObjPtr
movelong [ObjPtr]:#P_Prev,ObjHdl
bra WhileLoop
EndLoop
jsl D_ClosePicture
bcc @ok
@picErr lda #$201
bra @bad
@ok lda err
bne @bad
jsl D_CheckPurge
bcc RestorePort
@bad sta Err
tool _KillPicture,in=(PictHdl:l)
jsl D_CheckPurge
RestorePort
tool _PenNormal
tool _SetClip,in=(ClipRgn:l)
tool _SetPort,in=(OldPort:l)
pullword P_PageMode
return
ENDP
;------------------------------------------------------------------------------
;
; P_KillImport ()
;
; Kills a pending import or thread operation.
P_KillImport PROC EXPORT
;Using P_Data
begin
lda P_Placing
beq Exit
stz P_Placing
cpzl P_ThreadHdl
bne ZeroStuff
lda P_ImportType
beq Q_Text
tool _DisposeHandle,in=(P_ImportHdl:l)
bra ZeroStuff
Q_Text
call X_DisposeThread,in=(P_ImportHdl:l,#1:w)
ZeroStuff
stzl P_ThreadHdl
stzl P_ImportHdl
Exit return
ENDP
END