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

	IMPORT	D_CopyStrings
	IMPORT	X_DiScrap
	IMPORT	X_FSScratch
	IMPORT	FieldRecSize
	IMPORT	X_FormatMask
	IMPORT	X_InitFieldScanner
	IMPORT	X_NextField
	IMPORT	X_FormatValue
	import	X_AlertFlag

	ENTRY	X_ShortFormatText

;*********************************************************************
;
;   short - routines to get the first field out of the scrap
;	for interfacing with LineEdit.  All of these routines
;	leave the result in X_DiScrap
;
;*********************************************************************

X_ShortAsciiText	PROC	EXPORT
	;Using X_ClipData
	;Using X_FieldScannerData

	input Src:l

	begin

	inc	X_AlertFlag
	Call X_InitFieldScanner,in=(Src:l,#0:w,#0:w)
	Call X_NextField,out=(a:w)
	dec	X_AlertFlag

	Call D_CopyStrings,in=(#X_FSScratch:l,#X_DiScrap:l)

	return
	ENDP

X_ShortPLText	PROC	EXPORT

	input Src:l

	local Sptr:l

	begin

	MoveLong [Src],Sptr
	Call X_ShortFormatText,in=(Sptr:l)

	return

	ENDP

X_ShortWPText	PROC	EXPORT

	input Src:l

	local Sptr:l,Block:l,Bptr:l

	begin

	AddLong [Src],#2,Sptr
	MoveLong [Sptr],Block
	AddLong [Block],#4,Bptr
	Call X_ShortFormatText,in=(Bptr:l)

	return

	ENDP

X_ShortDBScrap	PROC	EXPORT
	;Using X_ClipData
	;Using X_DBScrapData

	input Src:l

	local Sptr:l,DataPointer:l,Type:w

	begin

	MoveLong [Src],Sptr
	Cmpw [Sptr],#X_DBFieldType
	jeq dofieldname
	AddLong Sptr,[Sptr]:#X_DBDataOffset,DataPointer
	lda [DataPointer]
	beq notempty

	stz X_DiScrap
	brl exit

notempty
	Addwl #2,DataPointer
	Addwl #X_DBScHeaderSize,Sptr
	MoveWord [Sptr]:#X_DBFType,a
	asl a
	tax
	jmp (TypeTable,x)

TypeTable
	DC.W	Q_Text
	DC.W	numeric
	DC.W	date
	DC.W	time
	DC.W	picture
	DC.W	pltext2

Q_Text
	Call D_CopyStrings,in=(DataPointer:l,#X_DiScrap:l)
	brl exit

numeric	Addwl #10,DataPointer
	brl Q_Text

time
date
	Addwl #4,DataPointer
	brl Q_Text

picture
	stz X_DiScrap
	brl exit

pltext2	Addwl #4,DataPointer
	Call X_ShortFormatText,in=(DataPointer:l)
	brl exit

dofieldname
	AddLong Sptr,#X_DBScHeaderSize,Sptr
	MoveWord [Sptr]:#X_DBFType,a
	cmp #9
	bge label
	AddLong Sptr,#FieldRecSize,Sptr
	Call D_CopyStrings,in=(Sptr:l,#X_DiScrap:l)

label
	stz X_DiScrap

exit	return

	ENDP

X_ShortSSScrap	PROC	EXPORT
	;Using X_ClipData
	;Using X_SSScrapData

	Input Src:l

	Local Sptr:l

	Begin

	AddLong [Src],#X_SSScrapCells,Sptr
	Cmpl [Sptr],#$10001
	jne empty

	MoveWord [Sptr]:#X_SSScrapFormat,a
	and #X_SSCellType
	xba
	clc
	lsr a
	lsr a
	lsr a
	lsr a
	tax
	jmp (TypeTable,x)

TypeTable
	DC.W	Q_Text
	DC.W	value
	DC.W	calctext
	DC.W	formula
	DC.W	leftpad
	DC.W	rightpad
	DC.W	empty
	DC.W	empty

Q_Text
	Addwl #X_SSScrapValue,Sptr
	Call D_CopyStrings,in=(Sptr:l,#X_DiScrap:l)
	brl exit

value
formula
	movelong #(-1-X_SSCellParenNeg),X_FormatMask

	SpaceLong
	SpaceLong
	PushWord #256
	PushLong [Sptr]:#X_SSScrapFormat
	Addwls #X_SSScrapValue,Sptr
	Call X_FormatValue
	ply
	PullLong Sptr
	ply

	Call D_CopyStrings,in=(Sptr:l,#X_DiScrap:l)
	MoveLong #-1,X_FormatMask
	brl exit

calctext
	Addwl #X_SSScrapValueSize,Sptr
	Call D_CopyStrings,in=(Sptr:l,#X_DiScrap:l)
	brl exit

empty
leftpad
rightpad
	stz X_DiScrap

exit	Return

	ENDP

X_ShortFormatText	PROC	EXPORT
	;Using X_ClipData

	Input Sptr:l

	Begin

	Addwl #6,Sptr

	Short
	stz X_DiScrap
	ldy #1

loop	lda [Sptr],y
docomp	cmp #TAB
	beq end
	cmp #CR
	beq end
	cmp #1
	bne notfont
	jsr FontChange
	bra docomp

notfont
	cmp #5
	bge notstyle
	jsr StyleChange
	bra docomp

notstyle
	tyx
	sta X_DiScrap,x
	sty X_DiScrap
	iny
	bne loop

end	Long

	Return

FontChange
	phy
	Long
	Addwl #3,Sptr
	Short
	ply
	lda [Sptr],y
	rts

StyleChange
	phy
	Long
	Addwl #2,Sptr
	Short
	ply
	lda [Sptr],y
	rts

	ENDP

X_ShortIgnore	PROC	EXPORT
	;Using X_ClipData

	input Src:l

	begin

	stz X_DiScrap

	return
	ENDP
	END

