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

	IMPORT	D_BeachBall
	IMPORT	D_CurCursor
	IMPORT	X_DefHeader
	IMPORT	X_DrawPLText
	IMPORT	D_DrawPicture
	IMPORT	X_GetScrap
	IMPORT	D_GrowLHandle
	IMPORT	D_KillFont
	IMPORT	D_NeedHandle
	IMPORT	X_OldCursor
	IMPORT	X_ParBlockSize
	IMPORT	X_ScrapType
	IMPORT	D_SelectFont
	IMPORT	D_SetCursor
	IMPORT	X_SwitchFont

X_DrawClipboard	PROC	EXPORT

	local PortRect:r,X_ScrapType:w,ScrapHand:l,Pptr:l

	error err

	begin +b

	SpaceWord
	SpaceLong
	PushLong #DrawList
	jsl X_GetScrap
	sta err
	PullLong ScrapHand
	PullWord X_ScrapType
	jcs mem_err

	Cmpw X_ScrapType,#0
	jeq exit

	PushLong !PortRect
	_GetPortRect

	PushLong !PortRect
	_EraseRect

	Cmpw X_ScrapType,#StaticText
	jne picttest

	PushLong !PortRect
	PushWord #0
	PushWord #2
	_OffsetRect

	PushLong !PortRect
	PushWord #4
	PushWord #0
	_InsetRect

	PushLong ScrapHand
	PushLong !PortRect
	jsl X_DrawPLText

	PushLong ScrapHand
	_DisposeHandle

	brl exit

picttest	Cmpw X_ScrapType,#PICT
	jne exit

	MoveLong [Scraphand],Pptr

	MoveLong [Pptr]:#2,PortRect
	MoveLong [Pptr]:#6,PortRect+4

	lda PortRect
	beq alreadytop

	lda PortRect+4
	sec
	sbc PortRect
	sta PortRect+4
	stz PortRect

alreadytop
	lda PortRect+2
	beq alreadydone

	lda PortRect+6
	sec
	sbc PortRect+2
	sta PortRect+6
	stz PortRect+2

alreadydone
	PushLong !PortRect
	PushWord #4
	PushWord #2
	_OffsetRect

	PushLong ScrapHand
	PushLong !PortRect
	jsl D_DrawPicture

	PushLong ScrapHand
	_DisposeHandle
	brl exit

mem_err	PushLong !PortRect
	_GetPortRect

	PushLong !PortRect
	_EraseRect

	jsl D_KillFont

	ldy #0
	MoveLong #0,ax
	jsl D_SelectFont

	PushWord #10
	PushWord #10
	_MoveTo

	PushLong #MemErrorStr
	PushWord #EndMemError-MemErrorStr
	_DrawText

exit	return

DrawList	DC.W	StaticText,PICT,0
MemErrorStr	DC.B	'Not enough memory to draw clipboard.'
EndMemError

	ENDP

	END

