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

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

	IMPORT	D_AlertBox
	IMPORT	D_CloseDialog
	IMPORT	D_DigitsOnly
	IMPORT	D_GetNewModalDialog
	IMPORT	P_BuildUndo
	IMPORT	P_ChangePage
	IMPORT	P_ContentRect
	IMPORT	P_CurrentWin
	IMPORT	P_DblPage
	IMPORT	P_DrawContent
	IMPORT	P_Entry
	IMPORT	P_FirstPOff
	IMPORT	P_FixSpecMenu
	IMPORT	P_Go2PDlog
	IMPORT	P_GrewDoc
	IMPORT	P_HorizGuides
	IMPORT	P_InitPage
	IMPORT	P_KillPage
	IMPORT	P_LoadPage
	IMPORT	P_LockGuides
	IMPORT	P_MagGuides
	IMPORT	P_MergeGuides
	IMPORT	P_ObjList
	IMPORT	P_PIconRect
	IMPORT	P_PNumDlog
	IMPORT	P_Page
	IMPORT	P_PageCount
	IMPORT	P_PageIcons
	IMPORT	P_PageMode
	IMPORT	P_PageStart
	IMPORT	P_PagesPN
	IMPORT	P_PortRect
	IMPORT	P_PrintChanged
	IMPORT	P_SavePage
	IMPORT	P_StoreV
	IMPORT	P_UseTemplate
	IMPORT	P_V
	IMPORT	P_VertGuides
	IMPORT	P_VisGuides
	IMPORT	P_VisPalette
	IMPORT	P_VisRuler
	IMPORT	D_SetCursor
	IMPORT	T_Deactivate
	IMPORT	D_UseStdColors
	IMPORT	P_KillLMasterStr

;		   poptions.s

		include 'pl.equ'


;---------------------------------------------------------------------------
;
; P_ChgView   
;

P_ChgView	PROC		EXPORT
			;Using P_AttrData
			;Using P_DATA
			;Using P_ObjData
			;Using T_Data

		begin +b

		jsl P_Entry
		call D_SetCursor,in=(#WatchCursor:w)

		lda P_PageMode
		beq GoFull

		stz P_PageMode
		movelong P_StoreV,P_V
		bra Done


GoFull	inc P_PageMode
		movelong P_V,P_StoreV
		stzl P_V
		call T_Deactivate,in=(#0:w,#0:w)

Done	call P_FixSpecMenu
		call P_PrintChanged,in=(P_CurrentWin:l)

		return
		ENDP





;---------------------------------------------------------------------------
;
; P_ChgTemplate
;
;

P_ChgTemplate	PROC		EXPORT
			;Using P_AttrData
			;Using P_Data

		begin +b

		jsl P_Entry
		Not P_UseTemplate
		jsl P_FixSpecMenu
		call P_MergeGuides

		tool _EraseRect,in=(#P_ContentRect:l)
		call P_DrawContent,in=(#P_ContentRect:l,#0:w)

		return
		ENDP




;---------------------------------------------------------------------------
;
; P_ChgTmplCount () 
;

P_ChgTmplCount	PROC		EXPORT
			;Using P_AttrData
			;Using P_Data

		local oldpage:w
		begin +b

		jsl P_Entry
		moveword P_Page,oldpage
		call P_SavePage,in=(a:w)

		lda P_DblPage
		beq GoDbl

		call P_LoadPage,in=(#0:w)
		IsNil P_VertGuides
		bne DoAlert
		IsNil P_HorizGuides
		bne DoAlert
		IsNil P_ObjList
		beq GoSingle

DoAlert	
		jsl	D_UseStdColors
		call D_AlertBox,in=(#2:w,#P_KillLMasterStr:l),out=(a:w)
		cmp #Cancel
		jeq exit

GoSingle	call P_BuildUndo,in=(#P_NoUndo:w)
		lda oldpage
		bne DoKill
		call T_Deactivate,in=(#0:w,#0:w)

DoKill	call P_KillPage,in=(#0:w,#0:w)
		call P_InitPage,in=(#0:w)
		stz P_DblPage

		lda oldpage
		bne done
		inc oldpage

		bra done

GoDbl	inc P_DblPage

done	call P_LoadPage,in=(oldpage:w)
		jsl P_FixSpecMenu
		call P_GrewDoc,in=(P_CurrentWin:l)

		tool _EraseRect,in=(#P_ContentRect:l)
		call P_DrawContent,in=(#P_ContentRect:l,#0:w)
		bra quit

exit	call P_LoadPage,in=(oldpage:w)
quit	return

		ENDP



;---------------------------------------------------------------------------
;
; P_ChgGuideVis 
;

P_ChgGuideVis	PROC		EXPORT
			;Using P_AttrData
			;Using P_Data

		begin +b

		jsl P_Entry
		lda P_VisGuides
		beq MakeVis
		stz P_VisGuides
		bra exit

MakeVis	inc P_VisGuides

exit	call P_FixSpecMenu
		tool _EraseRect,in=(#P_ContentRect:l)
		tool _InvalRect,in=(#P_ContentRect:l)   ; generate an D_Update
		return

		ENDP



;---------------------------------------------------------------------------
;
; P_ChgGuideLock 
;

P_ChgGuideLock	PROC		EXPORT
			;Using P_AttrData
			;Using P_Data

		begin +b

		lda P_LockGuides
		beq Lockit
		stz P_LockGuides

		bra exit

Lockit	inc P_LockGuides

exit	call P_FixSpecMenu

		return
		ENDP



;---------------------------------------------------------------------------
;
; P_ChgGuideMag 
;

P_ChgGuideMag	PROC		EXPORT
			;Using P_AttrData
			;Using P_Data

		begin +b

		lda P_MagGuides
		beq MakeMag
		stz P_MagGuides
		bra exit

MakeMag	inc P_MagGuides

exit	call P_FixSpecMenu
		return

		ENDP



;---------------------------------------------------------------------------
;
; P_ChgRulerVis
;

P_ChgRulerVis	PROC		EXPORT
			;Using P_AttrData
			;Using P_RulerDATA
			;Using P_DATA

		local tmprect:r
		begin +b

		jsl P_Entry
		lda P_VisRuler
		beq MakeVis
		stz P_VisRuler

		tool _ClipRect,in=(#P_PortRect:l)   ; GrewDoc will fix this...

		stz P_contentRect				   ; top
		lda P_VisPalette
		bne DontErase
		stz  P_ContentRect+2
		bra DidErase
DontErase	moveword #P_TabWLeft,P_ContentRect+2

DidErase	tool _EraseRect,in=(#P_ContentRect:l)
		tool _InvalRect,in=(#P_ContentRect:l)

		stz  P_ContentRect+2
		stzl P_ContentRect+4
		bra exit

MakeVis	inc P_VisRuler

		stzl P_ContentRect
		tool _EraseRect,in=(#P_ContentRect:l)
		tool _InvalRect,in=(#P_ContentRect:l)   ; generate an D_Update

		stzl P_ContentRect+4

exit
		call P_GrewDoc,in=(P_CurrentWin:l)
		call P_FixSpecMenu
		return

		ENDP





;---------------------------------------------------------------------------
;
; P_ChgPalVis 
;

P_ChgPalVis	PROC		EXPORT
			;Using P_AttrData
			;Using P_RulerDATA
			;Using P_DATA

		local tmprect:r
		begin +b

		jsl P_Entry

		lda P_VisPalette
		beq MakeVis
		stz P_VisPalette

		tool _ClipRect,in=(#P_PortRect:l)   ; GrewDoc will fix this...


;		   fix consts...

		stz P_contentRect   ; top
		stz P_contentRect+2 ; left

		tool _EraseRect,in=(#P_ContentRect:l)
		tool _InvalRect,in=(#P_ContentRect:l)

		stzl P_ContentRect+4
		bra exit

MakeVis	inc P_VisPalette

		stzl P_ContentRect
		tool _EraseRect,in=(#P_ContentRect:l)
		tool _InvalRect,in=(#P_ContentRect:l)

		stzl P_ContentRect+4


exit
		call P_GrewDoc,in=(P_CurrentWin:l)
		call P_FixSpecMenu

		return
		ENDP




;---------------------------------------------------------------------------
;
; P_GotoPage  
;

P_GotoPage	PROC		EXPORT
			;Using P_Data

		local TheDlog:l,result:w,page:w
		local pagetext:r

		begin +b

		jsl P_Entry
		jsl	D_UseStdColors

		call D_GetNewModalDialog,in=(#P_Go2PDlog:l),out=(TheDlog:l)

DlogLoop	tool _ModalDialog,in=(#D_DigitsOnly+$80000000:l),out=(result:w)
		cmp #Cancel
		beq QuitDlog
		cmp #OK
		bne DlogLoop

DoneDlog	tool _GetIText,in=(TheDlog:l,#4:w,!pagetext:l)
		lda pagetext
		and #$00FF
		bne CkValid
		moveword #2,result
		bra QuitDlog

CkValid	tax
		spaceword
		pushlong !pagetext+1
		pushword x
		pushword #0
		_Dec2Int
		pullword page
		bcs QuitDlog

QuitDlog	call D_CloseDialog,in=(TheDlog:l)

		cmpw result,#Cancel
		jeq exit

		subword page,P_FirstPOff,a
		bpl NotNeg
		addword P_FirstPOff,#2,page
		bra DidCk

NotNeg	cmp #1
		bgt CkGtr

		addword P_FirstPOff,#2,page
		bra DidCk

CkGtr	subword page,P_FirstPOff,a
		subword a,#2,a
		cmp P_PageCount
		blt DidCk

		lda P_PageCount
		ina
		addword a,P_FirstPOff,page

DidCk	subword page,P_FirstPOff,page
DoGo	cmpw Page,P_Page
		beq Exit
		call P_ChangePage,in=(Page:w,#1:w)

Exit	return
		ENDP




;---------------------------------------------------------------------------
;
; P_SetPageNo 
;

P_SetPageNo	PROC		EXPORT
			;Using P_Data
		local TheDlog:l,result:w,page:w,length:w
		local pagetext:r

		begin +b

		jsl P_Entry
		addword #2,P_FirstPOff,a
		tool _Int2Dec,in=(a:w,#P_PagesPN:l,#3:w,#0:w)
		jsl	D_UseStdColors

		call D_GetNewModalDialog,in=(#P_PNumDlog:l),out=(TheDlog:l)

DlogLoop	tool _ModalDialog,in=(#D_DigitsOnly+$80000000:l),out=(result:w)
		cmp #Cancel
		beq QuitDlog
		cmp #OK
		bne DlogLoop

DoneDlog	tool _GetIText,in=(TheDlog:l,#4:w,!pagetext:l)
		lda pagetext
		and #$00FF
		bne CkValid
		moveword #2,result
		bra QuitDlog

CkValid

QuitDlog	call D_CloseDialog,in=(TheDlog:l)
		cmpw result,#Cancel
		jeq exit

		lda pagetext
		and #$FF
		sta length

		tool _Dec2Int,in=(!pagetext+1:l,length:w,#0:w),out=(page:w)

		addword #2,P_FirstPOff,a
		cmp page										; Same 1st page
		beq exit										; already.

		call P_BuildUndo,in=(#P_NoUndo:w)

		subword P_PageStart,P_FirstPOff,x
		subword page,#2,P_FirstPOff
		addword x,P_FirstPOff,P_PageStart

		tool _ClipRect,in=(#P_PortRect:l)
		tool _EraseRect,in=(#P_PIconRect:l)
		call P_PageIcons

		call P_MergeGuides
		tool _ClipRect,in=(P_ContentRect:l)
		tool _InvalRect,in=(#P_ContentRect:l)   ; generate an D_Update

exit	return
		ENDP
		END

