	load 'macros.dump'
	include 'driver.equ'
	include 'wp.equ'

;-----------------------------------------------
;
;   Imported addresses
;
;-----------------------------------------------

	IMPORT	W_CRCopied
	IMPORT	W_CalcDocRect
	IMPORT	W_CalcPages
	IMPORT	W_CalcPixels
	IMPORT	W_CalcScrollVals
	IMPORT	CaretOff
	IMPORT	W_ClipRuler
	IMPORT	W_CurDoc
	
	IMPORT	W_DelSelect
	IMPORT	D_DisableMItems
	IMPORT	W_DrawPgBox
	IMPORT	D_EnableMItems
	IMPORT	W_EndLine
	IMPORT	W_EndOffset
	IMPORT	W_EndPar
	IMPORT	D_FastMult
	IMPORT	W_FirstPage
	
	IMPORT	W_GetLRecPtr
	IMPORT	W_GetLastLine
	IMPORT	W_GetNewOffset
	IMPORT	W_GetParRec
	IMPORT	W_GetRgn
	IMPORT	W_GotNewCtlVals
	IMPORT	W_GotoPage
	IMPORT	W_HideItem
	IMPORT	W_InsertKeys
	IMPORT	W_InvSelect
	IMPORT	W_JunkLeft
	IMPORT	W_Key
	IMPORT	W_KillSelect
	IMPORT	W_LastP
	IMPORT	W_LineToTopPixel
	IMPORT	W_MakeCaret
	IMPORT	W_MakeCaretNS
	IMPORT	W_MakeCr
	IMPORT	W_MakeLines
	IMPORT	W_NewNumPgs
	IMPORT	W_NewRuler
	
	IMPORT	W_NumPgs
	IMPORT	W_OverRide
	
	IMPORT	W_PageDialog
	
	IMPORT	W_ParRec
	
	
	IMPORT	W_Ptr
	IMPORT	W_PutOnScreen
	IMPORT	W_RulBytes
	IMPORT	W_ScreenChangedNS
	IMPORT	W_ScrollBar
	IMPORT	W_SelectOff
	IMPORT	W_SelectOn
	IMPORT	W_SetDocRect
	IMPORT	W_SetFullREct
	IMPORT	W_ShowItem
	IMPORT	W_ShowRuler
	IMPORT	W_StartLine
	IMPORT	W_StartOffset
	IMPORT	W_StartPar
	IMPORT	W_SwitchData
	
	
	IMPORT	W_TopPg
	IMPORT	W_TopPgPixel
	IMPORT	W_UnUseRuler
	IMPORT	W_UndoOff
	IMPORT	W_UpdateText
	IMPORT	W_UseRuler
	IMPORT	W_View
	IMPORT	W_HeaderBits
	IMPORT	W_ModFlags
	IMPORT	Q_Rect
	IMPORT	W_Selected

;-----------------------------------------------
;
;   Forward addresses and entries
;
;-----------------------------------------------

	ENTRY	W_ChangeView
	ENTRY	W_UnCheckView

********************************************************************
*
*	Includes...
*
* Monday, May 1, 1989 5:45:52 AM
********************************************************************

		



****************************************************************
* W_ChangeRuler - shows or hides the ruler
W_ChangeRuler	PROC		EXPORT
			;Using wpglobals
			;Using ScreenData
			;Using W_ATTRData

		local Q_Rect:r,SAmt:w,Rgn:l

		begin +b

		jsl CaretOff

		pushlong W_CurDoc
		_SetPort

		jsl CaretOff

		pushlong !Q_Rect
		jsl W_CalcDocRect

		stz Q_Rect		;go to top

		pushword #$504
		_DeleteMItem

		lda W_ShowRuler
		beq ShowIt

		moveword #-W_RulerHt,SAmt

		pushlong #W_HideItem
		pushword #$503
		pushword #5
		_InsertMItem
		bra DoneInvid

ShowIt

		moveword #W_RulerHt,SAmt

		pushlong #W_ShowItem
		pushword #$503
		pushword #5
		_InsertMItem

DoneInvid
		pushlong !Q_Rect
		pushword #0
		pushword SAmt
		jsl W_GetRgn
		movelong ax,Rgn
		phx
		pha
		_ScrollRect

		pushlong Rgn
		_InValRgn

		lda W_ShowRuler
		eor #1
		sta W_ShowRuler

		jsl W_ScreenChangedNS

		pha
		pha
		pha
		jsl W_CalcScrollVals
		lda 3,s
		pha
		pushlong W_ScrollBar
		_SetCtlParams
		pla
		pla   ;value not used

		jsl W_MakeCaret

		return

		ENDP



****************************************************************
W_GotoPg	PROC		EXPORT
			;Using wpglobals

		local NewPage:w,UsePage:w,OldPage:l
		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl W_SetDocRect

		jsl CaretOff

		jsl W_UndoOff

		pha
		jsl W_GotoPage
		pullword NewPage
		cmp #-1
		jeq GPExit

		addword W_FirstPage,W_NumPgs,a
		sta UsePage
		cmp NewPage
		bcc GotUse
		lda W_FirstPage
		inc a
		sta UsePage
		cmp NewPage
		bcs GotUse

		moveword NewPage,UsePage

GotUse
		movelong W_TopPg,OldPage
		subword UsePage,W_FirstPage,W_TopPg
		stz W_TopPgPixel

		jsl W_SetFullREct

		pha
		pha
		pha
		jsl W_CalcScrollVals
		pla
		pla
		pushlong W_ScrollBar
		_SetCtlValue

		pushlong OldPage
		jsl W_GotNewCtlVals

		jsl W_MakeCaretNS

GPExit
		jsl W_SetFullREct

		return

		ENDP


****************************************************************
* W_GotoBeg - goes to the beginning of the W_Document
W_GotoBeg	PROC		EXPORT
			;Using wpglobals

		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl W_SetDocRect

		jsl CaretOff

		jsl W_UndoOff

		jsl W_KillSelect

		moveword #1,W_StartPar
		stz W_StartLine
		moveword #W_TextHeader,W_StartOffset

		jsl W_MakeCaret

		jsl W_SetFullREct

		return

		ENDP


****************************************************************
* W_GotoEnd - goes to the end of the W_Document
W_GotoEnd	PROC		EXPORT
			;Using wpglobals

		local ParPtr:l,LinePtr:l
		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl W_SetDocRect

		jsl CaretOff

		jsl W_UndoOff

		jsl W_KillSelect

		moveword W_LastP,W_StartPar
PLoop
		lda W_StartPar
		jsl W_GetParRec
		movelong ax,ParPtr

		moveword [ParPtr]:#W_pAttr,a
		cmp #W_Picture
		beq NextPar
		cmp #W_PgBrk
		bne W_GotPar
NextPar	dec W_StartPar
		bra PLoop

W_GotPar
		moveword [ParPtr]:#W_pLastLine,a
		tay
		dec a
		sta W_StartLine

		spacelong
		pushword W_StartPar
		phy
		jsl W_GetLRecPtr
		pullLong LinePtr

		moveword [LinePtr]:#W_lOffset,W_StartOffset

		jsl W_MakeCaret

		jsl W_SetFullREct

		return

		ENDP


****************************************************************
W_GotApNum	PROC		EXPORT
			;Using wpglobals

		input num:w
		local W_ParRec:l,NewPar:w,NewLine:w,NewOffset:w
		begin

		jsl W_UndoOff

		ldx W_LastP
		dex
		ldy num
		jsl D_FastMult
		pha
		pha
		pha
		pushword #8
		_UDivide
		plx
		pla
		inx
		stx NewPar

		stz NewLine

		lda NewPar
		jsl W_GetParRec
		movelong ax,W_ParRec

		moveword [W_ParRec]:#W_pAttr,a
		beq NoPB

		inc NewPar

NoPB
		pha
		pushword W_StartPar
		pushword W_StartLine
		pushword W_StartOffset
		moveword NewPar,W_StartPar				;was pushword NewPar
		pha										;sta W_StartPar SFS 5/24/89
		moveword NewLine,W_StartLine
		pha
		jsl W_GetNewOffset
		pullword W_StartOffset

		jsl W_MakeCaret

		return

		ENDP



****************************************************************
W_WpSelectAll	PROC		EXPORT
			;Using wpglobals

		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl CaretOff

		jsl W_UndoOff

		jsl W_SelectOff

		moveword W_LastP,W_EndPar
		jsl W_GetLastLine
		stx W_EndOffset
		sta W_EndLine

		cmpw #1,W_EndPar
		bne IsDiff
		lda W_EndLine
		bne IsDiff

		pha
		pushword #1
		pushword #0
		pushword W_EndOffset
		jsl W_JunkLeft
		pla
		cmp #W_TextHeader
		beq Nothing

IsDiff
		moveword #1,W_StartPar
		stz W_StartLine
		moveword #W_TextHeader,W_StartOffset

		jsl W_InvSelect

		jsl W_SelectOn

		jsl W_SetDocRect

		jsl W_InvSelect

		jsl W_SetFullREct

Nothing
		return

		ENDP



****************************************************************
W_WpSelectPar	PROC		EXPORT
			;Using wpglobals

		local W_ParRec:l
		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl CaretOff

		jsl W_UndoOff

		jsl W_SetDocRect

		jsl W_SelectOff

		stz W_StartLine
		moveword #W_TextHeader,W_StartOffset
		moveword W_StartPar,W_EndPar
		jsl W_GetLastLine
		stx W_EndOffset
		sta W_EndLine
		cpx #W_TextHeader
		beq NoPar

		lda W_StartPar
		cmp W_LastP
		bcs NotNext

		inc W_EndPar
		stz W_EndLine
		moveword #W_TextHeader,W_EndOffset

NotNext
		jsl W_SelectOn

		jsl W_SetDocRect

		jsl W_InvSelect

NoPar
		jsl W_SetFullREct

		return

		ENDP



****************************************************************
* W_CopyRuler
W_CopyRuler	PROC		EXPORT
			;Using wpglobals

		local W_ParRec:l
		begin +b

		jsl W_UndoOff

		pushlong W_CurDoc
		_SetPort

		moveword #1,W_CRCopied

		lda W_StartPar
		jsl W_GetParRec
		movelong ax,W_ParRec

		pushlong [W_ParRec]:#W_pRulerHand
		pushlong #W_ClipRuler
		pushlong #W_RulBytes
		_HandToPtr

		return

		ENDP



****************************************************************
W_PasteRuler	PROC		EXPORT
			;Using wpglobals

		local W_ParRec:l,Ruler:l,W_Ptr:l,Q_Rect:r,CurPar:w,temp:w
		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl W_SetDocRect

		jsl CaretOff

		jsl W_UndoOff

		lda W_CRCopied
		jeq PRExit

		pushword W_StartPar
		pushword W_StartLine
		pushlong #0
		jsl W_PutOnScreen

		pha
		pha
		jsl W_NewRuler
		pullLong Ruler

		pushlong #W_ClipRuler
		pushlong Ruler
		pushlong #W_RulBytes
		_PtrToHand

		movelong [Ruler],W_Ptr

		moveword #0,[W_Ptr]

		lda W_StartPar
		sta CurPar

Loop	lda CurPar
		jsl W_GetParRec
		movelong ax,W_ParRec

		pushword #1
		pushlong Ruler
		jsl W_UseRuler

		pushword #1
		pushlong [W_ParRec]:#W_pRulerHand
		jsl W_UnUseRuler

		movelong Ruler,[W_ParRec]:#W_pRulerHand
		pushword CurPar
		jsl W_MakeLines

		lda W_Selected
		beq DoneLoop
		inc CurPar
		cmpw W_EndPar,CurPar
		bcs Loop

DoneLoop
		pushlong !Q_Rect
		jsl W_CalcDocRect

		pha
		pha
		pushword W_StartPar
		pushword #0
		jsl W_LineToTopPixel
		pla
		pla
		sta temp
		scmpw temp,Q_Rect
		bcc GotR
		lda temp
		sta Q_Rect
GotR

		pushlong !Q_Rect
		_ClipRect

		pushlong !Q_Rect
		_EraseRect

		jsl W_UpdateText

		jsl W_CalcPages

		jsl W_SetFullREct

		jsl W_MakeCaret

PRExit
		return

		ENDP



****************************************************************
W_DoSetPg	PROC		EXPORT
			;Using wpglobals
			;Using ScreenData

		local NewPage:w,Q_Rect:r
		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl W_SetDocRect

		jsl CaretOff

		jsl W_UndoOff

		pha
		pha
		lda W_FirstPage
		inc a
		pha
		pushword W_HeaderBits
		jsl W_PageDialog
		pla
		plx
		cpx #-1
		jeq GPExit

		sta W_HeaderBits
		dex
		stx W_FirstPage

		jsl W_SetFullREct

		jsl CaretOff

		jsl W_CalcPages

		pushword W_NumPgs
		jsl W_NewNumPgs

		moveword #1,W_OverRide

		jsl W_MakeCaret

		pushlong !Q_Rect			 ;first erase the old value
		_getPortRect

		lda Q_Rect+6
		sec
		sbc #W_SideWidth-2
		sta Q_Rect+2
		lda Q_Rect
		clc
		adc #W_PNumBoxHt
		sta Q_Rect+4

		pushlong !Q_Rect
		_InvalRect

GPExit

		return

		ENDP


****************************************************************
*
W_DoNormal	PROC		EXPORT
			;Using wpglobals
			;Using W_ATTRData

		begin +b

		lda W_View
		beq DNExit

		pushword #W_NormalOn
		jsl W_SwitchData

		pushword W_View
		jsl W_CalcPixels

		jsl W_UnCheckView

		pushword #W_IPNBit+W_ITBit+W_IDBit
		pushword #5
		jsl D_DisableMItems

		pushword #W_IPBBit+W_PageDBit
		pushword #5
		jsl D_EnableMItems

		stz W_View

		pushword #1
		pushword #W_NVItem
		_CheckMItem

		pushword #W_NormalOn
		jsl W_ChangeView

DNExit
		return

		ENDP


****************************************************************
*
W_DoHead	PROC		EXPORT
			;Using wpglobals
			;Using W_ATTRData

		begin +b

		lda W_View
		cmp #W_HeaderOn
		beq DHExit

		pushword #W_HeaderOn
		jsl W_SwitchData

		pushword W_View
		jsl W_CalcPixels

		jsl W_UnCheckView

		pushword #W_IPBBit+W_PageDBit
		pushword #5
		jsl D_DisableMItems

		pushword #W_IPNBit+W_ITBit+W_IDBit
		pushword #5
		jsl D_EnableMItems

		lda #1
		sta W_View

		pushword #1
		pushword #W_VHItem
		_CheckMItem

		pushword #W_HeaderOn
		jsl W_ChangeView

DHExit
		return

		ENDP



****************************************************************
*
W_DoFoot	PROC		EXPORT
			;Using wpglobals
			;Using W_ATTRData

		begin +b

		lda W_View
		bmi DFExit

		pushword #W_FooterOn
		jsl W_SwitchData

		pushword W_View
		jsl W_CalcPixels

		jsl W_UnCheckView

		pushword #W_IPBBit+W_PageDBit
		pushword #5
		jsl D_DisableMItems

		pushword #W_IPNBit+W_ITBit+W_IDBit
		pushword #5
		jsl D_EnableMItems

		lda #-1
		sta W_View

		pushword #1
		pushword #W_VFItem
		_CheckMItem

		pushword #W_FooterOn
		jsl W_ChangeView

DFExit
		return

		ENDP


****************************************************************
W_ChangeView	PROC		EXPORT
			;Using wpglobals

		input NewMode:w
		local Q_Rect:r
		begin

		jsl CaretOff

		jsl W_UndoOff

		pushword NewMode
		jsl W_SwitchData

		lda W_HeaderBits
		bne NoInit
		moveword #W_HonEven+W_HonOdd+W_FonEven+W_FonOdd,W_HeaderBits
NoInit

		jsl W_CalcPages

		jsl W_MakeCaret

		jsl W_SetFullREct

		pushword W_NumPgs
		jsl W_NewNumPgs

		pha
		pha
		pha
		jsl W_CalcScrollVals
		pla
		pla
		pushlong W_ScrollBar
		_SetCtlValue

		jsl W_DrawPgBox

		pushlong !Q_Rect
		jsl W_CalcDocRect

		stz Q_Rect
		pushlong !Q_Rect
		_InvalRect

		return

		ENDP



****************************************************************
*
W_UnCheckView	PROC		EXPORT
			;Using wpglobals

		begin

		lda W_View
		bne NotNorm

		pushword #0
		pushword #W_NVItem
		_CheckMItem
		bra W_DoneCheck

NotNorm	cmp #1
		bne isFoot

		pushword #0
		pushword #W_VHItem
		_CheckMItem
		bra W_DoneCheck

IsFoot

		pushword #0
		pushword #W_VFItem
		_CheckMItem

W_DoneCheck
		return

		ENDP


****************************************************************
W_InsertPageBrk	PROC		EXPORT
			;Using wpglobals

		local W_ParRec:l
		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl W_SetDocRect

		jsl CaretOff

		jsl W_UndoOff

		jsl W_DelSelect

		pushword W_StartPar
		pushword W_StartLine
		pushword W_StartOffset
		jsl W_MakeCr

		pushword W_StartPar
		pushword W_StartLine
		pushword W_StartOffset
		jsl W_MakeCr

		lda W_StartPar
		inc a
		jsl W_GetParRec
		movelong ax,W_ParRec

		pushword #1
		pushlong [W_ParRec]:#W_pRulerHand
		jsl W_UnUseRuler

		movelong #0,[W_ParRec]:#W_pLineHand
		moveword #W_PgBrk,[W_ParRec]:#W_pAttr
		movelong #0,[W_ParRec]:#W_pRulerHand

		addword #2,W_StartPar,W_StartPar
		moveword #W_TextHeader,W_StartOffset
		stz W_StartLine

		jsl W_CalcPages

		moveword #1,W_OverRide

		jsl W_MakeCaret

		jsl W_SetFullREct

		return

		ENDP



****************************************************************
W_DoPageNum	PROC		EXPORT
			;Using W_EditData
			;Using wpglobals

		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl CaretOff

		moveword #W_PageNumber,W_Key
		stz W_ModFlags

		jsl W_InsertKeys

		return
		ENDP


****************************************************************
W_DoDate	PROC		EXPORT
			;Using W_EditData
			;Using wpglobals

		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl CaretOff

		moveword #W_Date,W_Key
		stz W_ModFlags

		jsl W_InsertKeys

		return
		ENDP


****************************************************************
W_DoTime	PROC		EXPORT
			;Using W_EditData
			;Using wpglobals

		begin +b

		pushlong W_CurDoc
		_SetPort

		jsl CaretOff

		moveword #W_Time,W_Key
		stz W_ModFlags

		jsl W_InsertKeys

		return
		ENDP
		END

