
		LOAD		'Macros.dump'

		INCLUDE	'SS.equ'

		INCLUDE	'Driver.equ'
		INCLUDE	'Heap.aii.i'
		INCLUDE	'Eval.aii.i'

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

		IMPORT	D_AlertBox
		IMPORT	D_BLForgetLists
		IMPORT	D_BLGetSel
		IMPORT	D_BLMakeList
		IMPORT	D_BLModalDialog
		IMPORT	D_BLSelect
		IMPORT	D_BlinkButton
		IMPORT	D_CloseDialog
		IMPORT	D_DigitsOnly
		IMPORT	D_EscFilter
		IMPORT	D_GetNewModalDialog
		IMPORT	D_HeartBeatIdle
		IMPORT	D_IsDigit
		IMPORT	D_IsLetter
		IMPORT	D_Set4Pat

		IMPORT	S_Cell2Str
		IMPORT	S_CopyIn
		IMPORT	S_CopyOut
		IMPORT	S_Cur2EditFlag
		IMPORT	S_Cur2LEHandle
		IMPORT	S_CurrentData2
		IMPORT	S_SetEdittingMenus
		IMPORT	S_Text2Cell
		IMPORT	S_TrackVertLine

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

		ENTRY	S_ALeftRadio
		ENTRY	S_AddButton
		ENTRY	S_AddFuncStr
		ENTRY	S_AlStr
		ENTRY	S_AscRadio
		ENTRY	S_AscStr
		ENTRY	S_BoldBox
		ENTRY	S_BoldStr
		ENTRY	S_CellDlog
		ENTRY	S_CellStrPtr
		ENTRY	S_CloseFuncStr
		ENTRY	S_ColRowStr
		ENTRY	S_Column1Box
		ENTRY	S_Column1Str
		ENTRY	S_Column1ValStr
		ENTRY	S_Column2Box
		ENTRY	S_Column2Str
		ENTRY	S_Column2ValStr
		ENTRY	S_CommaStr
		ENTRY	S_CtrStr
		ENTRY	S_DRStr
		ENTRY	S_DefOK
		ENTRY	S_DefaultWidthBlurb
		ENTRY	S_DefaultWidthStr
		ENTRY	S_DeleteStr
		ENTRY	S_DescStr
		ENTRY	S_DirDlog
		ENTRY	S_DirOK
		ENTRY	S_DirStrPtr
		ENTRY	S_DisplayStr
		ENTRY	S_DollarStr
		ENTRY	S_DownRadio
		ENTRY	S_DownStr
		ENTRY	S_FillStr
		ENTRY	S_FixedStr
		ENTRY	S_FmtStr
		ENTRY	S_GenRadio
		ENTRY	S_GenStr
		ENTRY	S_GotoStr
		ENTRY	S_KeyStr
		ENTRY	S_LEText
		ENTRY	S_LFCloseButton
		ENTRY	S_LeftBox
		ENTRY	S_LeftBoxVal
		ENTRY	S_LeftStr
		ENTRY	S_LeftTitleStr
		ENTRY	S_ListFuncBlurb
		ENTRY	S_ListFuncStr
		ENTRY	S_MoveStr
		ENTRY	S_MyFuckingCancelStr
		ENTRY	S_OKStr
		ENTRY	S_OptRect
		ENTRY	S_OptText
		ENTRY	S_ParenNegStr
		ENTRY	S_PercentStr
		ENTRY	S_PlaceLE
		ENTRY	S_PlaceStr
		ENTRY	S_RRStr
		ENTRY	S_RedNegStr
		ENTRY	S_RightStr
		ENTRY	S_Row1Box
		ENTRY	S_Row1Str
		ENTRY	S_Row1ValStr
		ENTRY	S_Row2Box
		ENTRY	S_Row2Str
		ENTRY	S_Row2ValStr
		ENTRY	S_RowColStr
		ENTRY	S_SciNotStr
		ENTRY	S_SortCell
		ENTRY	S_SortDlog
		ENTRY	S_SortOK
		ENTRY	S_SortStr
		ENTRY	S_StyStr
		ENTRY	S_ThruStr
		ENTRY	S_TitleBlurb
		ENTRY	S_TitleBlurbStr
		ENTRY	S_TitleCancel
		ENTRY	S_TitleCol1Str
		ENTRY	S_TitleDlog
		ENTRY	S_TitleOK
		ENTRY	S_TitleRow1Str
		ENTRY	S_TopBox
		ENTRY	S_TopBoxVal
		ENTRY	S_TopTitleStr
		ENTRY	S_ULineStr
		ENTRY	S_UpStr
		ENTRY	S_WhichLE
		ENTRY	S_WidthCancel
		ENTRY	S_WidthOK
		ENTRY	S_WidthThing

		ENTRY	S_CellNumberFromLetters
		ENTRY	S_CellNumberFromNumbers
		ENTRY	S_ColLetterFromNumber
		ENTRY	S_DlogRect
		ENTRY	S_DrawLFMember
		ENTRY	S_InsertStr
		ENTRY	S_LFFilter
		ENTRY	S_RowNumberFromNumber
		ENTRY	S_SelectLFMember
		ENTRY	S_ThingDef
		ENTRY	S_TitleFilter
		ENTRY	S_WidthFilter

;---------------------------------------------------------------------------
;
; S_DlogRect	
;
;	action proc for drawing a rectangle in a dialog

S_DlogRect	PROC		EXPORT
			;USING	S_ChartData

			input	TheDlog:l,item:w
			local	ptr:l,tmprect:r,rectptr:l
			BEGIN

			MoveLong	!tmprect,rectptr
			Tool		_GetDItemBox,in=(TheDlog:l,item:w,rectptr:l)

			_PenNormal
			Tool 	_SetPenSize,in=(#2:w,#1:w)
			Tool 	_FrameRect,in=(rectptr:l)
			_PenNormal

			RETURN
			ENDP

;---------------------------------------------------------------------------
;
; S_GetDirDlog(all:w):w
;
;	all:	0==Fill in what direction?	D,R
;		1==Insert in what direction?	D,R
;		2==Delete in what direction?	U,L
;
;	direction:	0==Cancel,1==Left,	2==Right,	3==Up,4==Down
;	Button:		4		5		6		7

S_GetDirDlog	PROC		EXPORT
			;Using	S_DlogData

			input	all:w
			output	direction:w
			local	TheDlog:l,result:w,CtlHdl:l
			BEGIN	+b

			moveword	#4,direction

			lda		all
			bne		DoAll

			movelong	#S_FillStr,S_DirStrPtr
			MoveLong	#S_DownStr,S_DRStr
			MoveLong	#S_RightStr,S_RRStr
			bra		dodlog

doall
			cmp		#1
			bne		dodelete

			MoveLong	#S_InsertStr,S_DirStrPtr
			MoveLong	#S_DownStr,S_DRStr
			MoveLong	#S_RightStr,S_RRStr
			bra		dodlog

dodelete
			MoveLong	#S_DeleteStr,S_DirStrPtr
			MoveLong	#S_UpStr,S_DRStr
			MoveLong	#S_LeftStr,S_RRStr

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

DlogLoop
			tool		_ModalDialog,in=(#D_EscFilter+$80000000:l),out=(result:w)
			cmp		#3
			blt		Done
			beq		DlogLoop

			subword	a,#3,direction

			tool		_GetControlDItem,in=(TheDlog:l,result:w),out=(CtlHdl:l)
			tool		_SetCtlValue,in=(#1:w,CtlHdl:l)

			bra		DlogLoop


Done
			call		D_CloseDialog,in=(TheDlog:l)
			cmpw		result,#OK
			bne		cancelout

			lda		all
			cmp		#2
			bne		exit

			SubWord	Direction,#1,Direction
			bra		exit

cancelout
			stz		direction

exit
			RETURN
			ENDP

;---------------------------------------------------------------------------
;
; S_GetCellDlog(move:w,cell:l):l
;
;	move:	0==Goto cell
;			1==Move cell
;
;	cell: 	0==No default
;
;	newcell: 0 == Cancelled, 0 w/carry set == error

S_GetCellDlog	PROC		EXPORT
			;Using	S_DlogData

			input	move:w,cell:l
			output	newcell:l
			local	TheDlog:l,result:w,tmpstr:r,tmp:l
			error	err
			BEGIN	+b

			stz		err
			stzl		newcell

			IsNil	cell
			bne		DoConvert

			stz		S_LEText
			bra		Cont

DoConvert
			call		S_Cell2Str,in=(#S_LEText:l,cell:l)


Cont
			lda		move
			beq		Goto
			movelong	#S_MoveStr,S_CellStrPtr
			bra		DoDlog

Goto
			movelong	#S_GotoStr,S_CellStrPtr

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

DlogLoop
			tool		_ModalDialog,in=(#D_EscFilter+$80000000:l),out=(result:w)

			cmp		#3
			bge		DlogLoop

Done
			tool		_GetIText,in=(TheDlog:l,#4:w,!tmpstr:l)
			call		D_CloseDialog,in=(TheDlog:l)

			lda		result
			cmp		#Cancel
			beq		exit

			lda		tmpstr
			and		#$FF
			bne		Do2Cell

			inc		err
			bra		exit

Do2Cell
			sta		tmp
			call		S_Text2Cell,in=(!tmpstr+1:l,tmp:w),out=(newcell:l)
			bcc		exit

			stzl		newcell
			inc		err

exit
			RETURN
			ENDP

;---------------------------------------------------------------------------
;
; S_DoSortDlog(default:l):(ascend:w,rowcol:w,cell:l)
;
;	ascend:	0==ascending,	1==decending
;	rowcol:	0==col by row,	1==row by col
;	cell:	0 == Cancelled,0 w/carry set == error
;

S_DoSortDlog	PROC		EXPORT
			;Using	S_DlogData

			input	default:l
			output	ascend:w,rowcol:w,newcell:l
			local	TheDlog:l,result:w,CtlHdl:l,tmpstr:r,tmp:w
			error	err
			BEGIN	+b

			stz		err
			stzl		newcell

			moveword	#1,rowcol
			stz		ascend

			IsNil	default
			bne		DoConvert

			stz		S_LEText
			bra		DoDlog

DoConvert
			call		S_Cell2Str,in=(#S_LEText:l,default:l)

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

DlogLoop
			tool		_ModalDialog,in=(#D_EscFilter+$80000000:l),out=(result:w)

			cmp		#7
			bge		DlogLoop

			cmp		#3
			blt		Done

			bne		chk4

			stz		ascend
			bra		setItem

chk4
			cmp		#4
			bne		chk5

			moveword	#1,ascend
			bra		setItem

chk5
			cmp		#5
			bne		do6

			moveword	#1,rowcol
			bra		setItem

do6
			stz		rowcol

setItem
			tool		_GetControlDItem,in=(TheDlog:l,result:w),out=(CtlHdl:l)
			tool		_SetCtlValue,in=(#1:w,CtlHdl:l)
			bra		DLogLoop

Done
			tool		_GetIText,in=(TheDlog:l,#9:w,!tmpstr:l)
			call		D_CloseDialog,in=(TheDlog:l)

			lda		result
			cmp		#Cancel
			beq		exit

			lda		tmpstr
			and		#$FF
			bne		Do2Cell

			inc		err
			bra		exit

Do2Cell
			sta		tmp
			call		S_Text2Cell,in=(!tmpstr+1:l,tmp:w),out=(newcell:l)
			bcc		exit

			stzl		newcell
			inc		err

exit
			RETURN
			ENDP


;*********************************************************************
;
;	S_TitleDialog
;
;*********************************************************************
S_TitleDialog	PROC		EXPORT
			;Using	S_DlogData

			input	OldColLeft:w,OldRowTop:w,OldColRight:w,OldRowBottom:w
			input	LeftThere:w,TopThere:w
			local	Item:w,Dialog:l,Left:w,Right:w
			output	ColLeft:w,RowTop:w,ColRight:w,RowBottom:w
			error	err
			BEGIN	+b

			stz		err
			stz		S_WhichLE

			lda		OldColLeft
			bne		S_LeftStr

			stz		S_Column1ValStr
			bra		next1

S_LeftStr
			in		OldColLeft:w,#S_Column1ValStr:l
			XCall	S_ColLetterFromNumber

next1
			lda		OldColRight
			bne		S_RightStr

			stz		S_Column2ValStr
			bra		next2

S_RightStr
			in		OldColRight:w,#S_Column2ValStr:l
			XCall	S_ColLetterFromNumber

next2
			lda		OldRowTop
			bne		topstr

			stz		S_Row1ValStr
			bra		next3

topstr
			in		OldRowTop:w,#S_Row1ValStr:l
			XCall	S_RowNumberFromNumber

next3
			lda		OldRowBottom
			bne		bottomstr

			stz		S_Row2ValStr
			bra		next4

bottomstr
			in		OldRowBottom:w,#S_Row2ValStr:l
			XCall	S_RowNumberFromNumber

next4
			MoveWord	LeftThere,S_LeftBoxVal
			MoveWord	TopThere,S_TopBoxVal

			in		#S_TitleDlog:l
			out		Dialog:l
			XCall	D_GetNewModalDialog

dLoop
			in		#S_TitleFilter+$80000000:l
			out		Item:w
			XTool	_ModalDialog

			cmp		#1
			beq		getValues

			cmp		#2
			jeq		doCancel

			cmp		#5
			beq		doCheckBox

			cmp		#4
			bne		dLoop

doCheckBox
			in		Dialog:l,Item:w
			out		a:w
			XTool	_GetDItemValue

			eor		#1

			in		a:w,Dialog:l,Item:w
			XTool	_SetDItemValue
			bra		dLoop

getValues
			in		Dialog:l,S_LeftBox:w
			out		a:w
			XTool	_GetDItemValue

			bne		doLeft

			stz		ColLeft
			stz		ColRight
			bra		checkTop

doLeft
			in		Dialog:l,S_Column1Box:w,#CellScratch:l
			XTool	_GetIText

			in		#CellScratch:l
			out		ColLeft:w
			XCall	S_CellNumberFromLetters


			in		Dialog:l,S_Column2Box:w,#CellScratch:l
			XTool	_GetIText

			in		#CellScratch:l
			out		ColRight:w
			XCall	S_CellNumberFromLetters

			lda		ColLeft
			jeq		notGood

			lda		ColRight
			bne		ChkColOrder

			MoveWord	ColLeft,ColRight
			bra		checkTop

chkColOrder
			cmp		ColLeft
			jlt		notGood

checkTop
			in		Dialog:l,S_TopBox:w
			out		a:w
			XTool	_GetDItemValue

			bne		dotop

			stz		RowTop
			stz		RowBottom
			brl		doClose

doTop
			in		Dialog:l,S_Row1Box:w,#CellScratch:l
			XTool	_GetIText

			in		#CellScratch:l
			out		RowTop:w
			XCall	S_CellNumberFromNumbers

			in		Dialog:l,S_Row2Box:w,#CellScratch:l
			XTool	_GetIText

			in		#CellScratch:l
			out		RowBottom:w
			XCall	S_CellNumberFromNumbers

			lda		RowTop
			beq		notGood

			lda		RowBottom
			bne		chkRowOrder

			MoveWord	RowTop,RowBottom
			bra		doClose

chkRowOrder
			cmp		RowTop
			bge		doClose

notGood
			Call		D_AlertBox,in=(#OKBox:w,#S_BadTitleMsg:l),out=(a:w)
			brl		DLoop

doCancel
			MoveWord	#-1,err
			MoveWord	OldRowTop,RowTop
			MoveWord	OldRowBottom,RowBottom
			MoveWord	OldColLeft,ColLeft
			MoveWord	OldColRight,ColRight

doClose
			PushLong	Dialog
			Call		D_CloseDialog

Exit
			RETURN

CellScratch	DS.B 	8
S_BadTitleMsg	str		'Invalid range specified for titles.'

			ENDP

;***********************************************************************
;
;	S_CellNumberFromLetters
;
;***********************************************************************
S_CellNumberFromLetters	PROC		EXPORT

			input	Ptr:l
			output	Number:w
			BEGIN

			lda		[Ptr]
			and		#$ff
			beq		noText

			dec		a
			beq		onedigit

			SpaceLong
			ldy		#1
			lda		[Ptr],y
			and		#$ff
			sec
			sbc		#'@'
			pha
			PushWord	#26
			_Multiply
			PullWord	Number
			pla

			ldy		#2
			lda		[Ptr],y
			and		#$ff
			sec
			sbc		#'@'
			clc
			adc		Number
			sta		Number
			bra		exit

onedigit		ldy		#1
			lda		[Ptr],y
			and		#$ff
			sec
			sbc		#'@'

noText
			sta	Number

exit
			RETURN
			ENDP

;***********************************************************************
;
;	S_CellNumberFromNumbers
;
;***********************************************************************
S_CellNumberFromNumbers	PROC		EXPORT

			input	Ptr:l
			local	StrSize:w
			output	Number:w
			BEGIN

			lda		[Ptr]
			and		#$ff
			beq		noText

			dec		a
			beq		onedigit
			dec		a
			beq		twodigit
			dec		a
			beq		threedigit

			MoveWord	#4,StrSize
			bra		docall

threedigit
			MoveWord	#3,StrSize
			bra		docall

onedigit
			MoveWord	#1,StrSize
			bra		docall

twodigit
			MoveWord	#2,StrSize

docall		SpaceWord
			Addwls	#1,Ptr
			PushWord	StrSize
			PushWord	#0
			_Dec2Int
			PullWord	Number
			bra		exit

noText		sta		Number

exit
			RETURN
			ENDP


;***********************************************************************
;
;	S_RowNumberFromNumber
;
;***********************************************************************
S_RowNumberFromNumber	PROC		EXPORT

			input	Number:w,Ptr:l
			local	StrLength:w
			BEGIN

			lda		Number
			cmp		#10
			bge		notone

			MoveWord	#1,StrLength
			MoveWord	#1,[Ptr]
			brl		docall

notone		cmp		#100
			bge		nottwo

			MoveWord	#2,StrLength
			MoveWord	#2,[Ptr]
			bra		docall

nottwo		cmp		#1000
			bge		notthree

			MoveWord	#3,StrLength
			MoveWord	#3,[Ptr]
			bra		docall

notthree		MoveWord	#4,StrLength
			MoveWord	#4,[Ptr]

docall		PushWord	Number
			Addwls	#1,Ptr
			PushWord	StrLength
			PushWord	#0
			_Int2Dec

			RETURN
			ENDP

;***********************************************************************
;
;	S_ColLetterFromNumber(Number:w,ptr:l)
;
;***********************************************************************
S_ColLetterFromNumber	PROC		EXPORT

			input	Number:w,Ptr:l
			local	HighLetter:w,LowLetter:w
			BEGIN

			SpaceLong
			lda		Number
			dec		a
			pha
			PushWord	#26
			_UDivide
			PullWord	HighLetter
			pla
			inc		a
			sta		LowLetter

			lda		HighLetter
			beq		oneletter

			clc
			adc		#'@'
			short
			ldy		#1
			sta		[Ptr],y
			lda		LowLetter
			clc
			adc		#'@'
			iny
			sta		[Ptr],y
			lda		#2
			sta		[Ptr]
			long
			bra		exit

oneletter
			MoveWord	#1,[Ptr]
			lda		LowLetter
			clc
			adc		#'@'
			ldy		#1
			sta		[Ptr],y

exit
			RETURN
			ENDP

;************************************************************************
;
;	S_TitleFilter
;
;************************************************************************

S_TitleFilter	PROC		EXPORT
			;Using	S_DlogData

			input	Dialog:l,Event:l,ItemPtr:l
			output	Result:w
			BEGIN	+b

			stz		Result

			jsl		D_HeartBeatIdle

			lda		[Event]
			asl		a
			tax
			jmp		(EventTable,x)

EventTable
			DC.W		exit
			DC.W		mouseDown
			DC.W		exit
			DC.W		keyDown
			DC.W		exit
			DC.W		keyDown
			DC.W		exit
			DC.W		exit
			DC.W		exit

mouseDown
			SpaceWord
			PushLong	Dialog
			PushLong	[Event]:#oWhere
			_FindDItem
			pla

			cmp		#10
			jlt		exit
			sec
			sbc		#10
			sta		S_WhichLE
			brl		exit

keyDown
			Cmpw		[Event]:#oMessage,#$7f
			jeq		exit
			cmp		#ESC
			jeq		doesc
			cmp		#TAB
			jeq		dotab
			cmp		#' '
			jlt		exit

	;	See if it's a letter or digit

			lda		S_WhichLE
			asl		a
			tax
			jmp		(leitemtable,x)

leitemtable
			DC.W		checknumber,checknumber,checkletter,checkletter

checkletter
			MoveWord	[Event]:#oMessage,a
			jsl		D_IsLetter
			bcc		letter

			MoveWord	#0,[Event]:#oWhat
			brl		exit

letter
			MoveWord	[Event]:#oMessage,a
			cmp		#'a'
			jlt		exit
			sec
			sbc		#$20
			sta		[Event],y
			brl		exit

checknumber
			MoveWord	[Event]:#oMessage,a

			jsl		D_IsDigit
			jcc		exit

nogoaway		MoveWord	#0,[Event]:#oWhat
			brl		exit

doesc		MoveWord	#2,[ItemPtr]

			PushLong	Dialog
			PushWord	#2
			jsl		D_BlinkButton

			inc		Result
			brl		exit

dotab		inc		S_WhichLE
			lda		S_WhichLE
			cmp		#4
			jlt		exit
			sec
			sbc		#4
			sta		S_WhichLE

exit
			RETURN
			ENDP

;---------------------------------------------------------------------------
;
; S_DlogData	
;

S_DlogData	PROC		EXPORT
			;Using	D_GlobalData

		EXPORT	S_DirDlog
		EXPORT	S_DirOK
		EXPORT	S_DirCancel
		EXPORT	S_DirText
		EXPORT	S_DirStrPtr
		EXPORT	S_RightRadio
		EXPORT	S_RRStr
		EXPORT	S_DownRadio
		EXPORT	S_DRStr

		EXPORT	S_CellDlog
;		EXPORT	S_CellText
		EXPORT	S_CellStrPtr
;		EXPORT	S_CellLE
		EXPORT	S_LEText

		EXPORT	S_SortDlog
		EXPORT	S_SortOK
;		EXPORT	S_SortCancel
		EXPORT	S_AscRadio
;		EXPORT	S_DescRadio
;		EXPORT	S_RowColRadio
;		EXPORT	S_ColRowRadio
;		EXPORT	S_SortText
;		EXPORT	S_KeyText
		EXPORT	S_SortCell

		EXPORT	S_DefaultDlog
		EXPORT	S_DefOK
;		EXPORT	S_DefCancel
		EXPORT	S_ALeftRadio
		EXPORT	S_ALeftVal
;		EXPORT	S_ACtrRadio
		EXPORT	S_ACtrVal
;		EXPORT	S_ARightRadio
		EXPORT	S_ARightVal
		EXPORT	S_GenRadio
		EXPORT	S_GenVal
;		EXPORT	S_FixedRadio
		EXPORT	S_FixedVal
;		EXPORT	S_DollarRadio
		EXPORT	S_DollarVal
;		EXPORT	S_PercentRadio
		EXPORT	S_PercentVal
;		EXPORT	S_SciNotRadio
		EXPORT	S_SciNotVal
		EXPORT	S_BoldBox
		EXPORT	S_BoldVal
;		EXPORT	S_UlineBox
		EXPORT	S_UlineVal
;		EXPORT	S_CommaBox
		EXPORT	S_CommaVal
;		EXPORT	S_RedNegBox
		EXPORT	S_RedNegVal
;		EXPORT	S_ParenBox
		EXPORT	S_ParenVal
		EXPORT	S_OptText
;		EXPORT	S_AlText
;		EXPORT	S_StyText
		EXPORT	S_OptRect
;		EXPORT	S_AlRect
;		EXPORT	S_StyRect
;		EXPORT	S_DecText
		EXPORT	S_PlaceLE
		EXPORT	S_PlaceStr

		EXPORT	S_TitleDlog
		EXPORT	S_TitleOK
		EXPORT	S_TitleCancel
		EXPORT	S_TitleBlurb
		EXPORT	S_LeftBox
		EXPORT	S_LeftBoxVal
		EXPORT	S_TopBox
		EXPORT	S_TopBoxVal
		EXPORT	S_Column1Str
		EXPORT	S_Column2Str
		EXPORT	S_Row1Str
		EXPORT	S_Row2Str
		EXPORT	S_Column1Box
		EXPORT	S_Column2Box
		EXPORT	S_Row1Box
		EXPORT	S_Row2Box

		EXPORT	S_WidthDialog
		EXPORT	S_WidthOK
		EXPORT	S_WidthCancel
		EXPORT	S_WidthThing
		EXPORT	S_ThingRect
		EXPORT	S_DefaultWidthBlurb
;		EXPORT	S_InThing

		EXPORT	S_ListFunctionsDialog
		EXPORT	S_AddButton
		EXPORT	S_LFCloseButton
		EXPORT	S_ListFuncBlurb
		EXPORT	S_ListFuncBL
		EXPORT	S_LFDialog
		EXPORT	S_LFSize

		EXPORT	S_DownStr
		EXPORT	S_UpStr
		EXPORT	S_LeftStr
		EXPORT	S_RightStr
		EXPORT	S_FillStr
		EXPORT	S_DeleteStr
		EXPORT	S_InsertStr
		EXPORT	S_OKStr
		EXPORT	S_MyFuckingCancelStr
		EXPORT	S_KeyStr
		EXPORT	S_SortStr
		EXPORT	S_RowColStr
		EXPORT	S_ColRowStr
		EXPORT	S_AscStr
		EXPORT	S_DescStr
		EXPORT	S_GotoStr
		EXPORT	S_MoveStr
		EXPORT	S_BoldStr
		EXPORT	S_ULineStr
		EXPORT	S_CommaStr
		EXPORT	S_RedNegStr
		EXPORT	S_ParenNegStr
		EXPORT	S_CtrStr
		EXPORT	S_GenStr
		EXPORT	S_FixedStr
		EXPORT	S_DollarStr
		EXPORT	S_PercentStr
		EXPORT	S_SciNotStr
		EXPORT	S_DisplayStr
		EXPORT	S_FmtStr
		EXPORT	S_AlStr
		EXPORT	S_StyStr
		EXPORT	S_TitleBlurbStr
		EXPORT	S_LeftTitleStr
		EXPORT	S_TopTitleStr
		EXPORT	S_TitleCol1Str
		EXPORT	S_ThruStr
		EXPORT	S_TitleRow1Str
		EXPORT	S_Column1ValStr
		EXPORT	S_Column2ValStr
		EXPORT	S_Row1ValStr
		EXPORT	S_Row2ValStr
		EXPORT	S_DefaultWidthStr
		EXPORT	S_AddFuncStr
		EXPORT	S_CloseFuncStr
		EXPORT	S_ListFuncStr

		EXPORT	S_WhichLE

;_________________________________
;			Direction	Dialog
;_________________________________
S_DirDlog		DC.W		48,185,112,462
			DC.W		1
			DC.L		0
			DC.L		S_DirOK,S_DirCancel,S_DirText
			DC.L		S_DownRadio,S_RightRadio
			DC.L		0

S_DirOK		DC.W		1
			DC.W		45,155,58,230
			DC.W		buttonItem
			DC.L		S_OKStr
			DC.W		0
			DC.W		0
			DC.L		0

S_DirCancel	DC.W		2
			DC.W		45,40,58,115
			DC.W		buttonItem
			DC.L		S_MyFuckingCancelStr
			DC.W		0
			DC.W		0
			DC.L		0

S_DirText		DC.W		3
			DC.W		4,20,14,210
			DC.W		statText
S_DirStrPtr	DC.L		0
			DC.W		0
			DC.W		0
			DC.L		0

S_RightRadio	DC.W		5
			DC.W		29,40,39,115
			DC.W		radioItem
S_RRStr		DC.L		S_RightStr
			DC.W		0
			DC.W		1
			DC.L		0

S_DownRadio	DC.W		7
			DC.W		29,155,39,230
			DC.W		radioItem
S_DRStr		DC.L		S_DownStr
			DC.W		1
			DC.W		1
			DC.L		0


;_________________________________
;			Cell	Dialog
;_________________________________
S_CellDlog	DC.W		48,185,112,462
			DC.W		1
			DC.L		0
			DC.L		S_DirOK,S_DirCancel,S_CellText,S_CellLE
			DC.L		0

S_CellText	DC.W		3
			DC.W		16,40,29,140
			DC.W		statText
S_CellStrPtr	DC.L		0
			DC.W		0
			DC.W		0
			DC.L		0

S_CellLE		DC.W		4
			DC.W		14,155,27,215
			DC.W		editLine
			DC.L		S_LEText
			DC.W		6					; 6 char LE width
			DC.W		0
			DC.W		0
S_LEText		DS.B		7

;_________________________________
;			Sort Dialog
;_________________________________
S_SortDlog	DC.W		40,155,130,510
			DC.W		1
			DC.L		0
			DC.L		S_SortOK,S_SortCancel,S_SortText
			DC.L		S_AscRadio,S_DescRadio,S_RowColRadio,S_ColRowRadio
			DC.L		S_SortCell,S_KeyText
			DC.L		0

S_SortOK		DC.W		1
			DC.W		69,187,82,262
			DC.W		buttonItem
			DC.L		S_OKStr
			DC.W		0
			DC.W		0
			DC.L		0

S_SortCancel	DC.W		2
			DC.W		69,92,82,167
			DC.W		buttonItem
			DC.L		S_MyFuckingCancelStr
			DC.W		0
			DC.W		0
			DC.L		0

S_AscRadio	DC.W		3
			DC.W		19,50,29,155
			DC.W		radioItem
			DC.L		S_AscStr
			DC.W		1
			DC.W		1
			DC.L		0

S_DescRadio	DC.W		4
			DC.W		31,50,41,155
			DC.W		radioItem
			DC.L		S_DescStr
			DC.W		0
			DC.W		1
			DC.L		0

S_RowColRadio	DC.W		5
			DC.W		19,185,29,330
			DC.W		radioItem
			DC.L		S_RowColStr
			DC.W		1
			DC.W		2
			DC.L		0

S_ColRowRadio	DC.W		6
			DC.W		31,185,41,330
			DC.W		radioItem
			DC.L		S_ColRowStr
			DC.W		0
			DC.W		2
			DC.L		0

S_SortText	DC.W		7
			DC.W		4,50,14,300
			DC.W		statText
			DC.L		S_SortStr
			DC.W		0
			DC.W		0
			DC.L		0

S_KeyText		DC.W		8
			DC.W		52,117,62,167
			DC.W		statText
			DC.L		S_KeyStr
			DC.W		0
			DC.W		0
			DC.L		0

S_SortCell	DC.W		9
			DC.W		50,177,63,237
			DC.W		editLine
			DC.L		S_LEText
			DC.W		6					; 6 char LE width
			DC.W		0
			DC.W		0


;_________________________________
;			Set	Defaults Dialog
;_________________________________
S_DefaultDlog	DC.W		20,85,150,562
			DC.W		1
			DC.L		0
			DC.L		S_DefOK,S_DefCancel
			DC.L		S_ALeftRadio,S_ACtrRadio,S_ARightRadio
			DC.L		S_GenRadio,S_FixedRadio,S_DollarRadio,S_PercentRadio,S_SciNotRadio
			DC.L		S_BoldBox,S_UlineBox,S_CommaBox,S_RedNegBox,S_ParenBox
			DC.L		S_OptText,S_AlText,S_StyText
			DC.L		S_OptRect,S_AlRect,S_StyRect
			DC.L		S_PlaceLE,S_DecText
			DC.L		0

S_DefOK		DC.W		1
			DC.W		108,375,121,450
			DC.W		buttonItem
			DC.L		S_OKStr
			DC.W		0
			DC.W		0
			DC.L		0

S_DefCancel	DC.W		2
			DC.W		108,260,121,335
			DC.W		buttonItem
			DC.L		S_MyFuckingCancelStr
			DC.W		0
			DC.W		0
			DC.L		0

S_ALeftRadio	DC.W		3
			DC.W		86,30,96,135
			DC.W		radioItem
			DC.L		S_LeftStr
S_ALeftVal	DC.W		1
			DC.W		1
			DC.L		0

S_ACtrRadio	DC.W		4
			DC.W		96,30,106,135
			DC.W		radioItem
			DC.L		S_CtrStr
S_ACtrVal		DC.W		0
			DC.W		1
			DC.L		0

S_ARightRadio	DC.W		5
			DC.W		106,30,116,135
			DC.W		radioItem
			DC.L		S_RightStr
S_ARightVal	DC.W		0
			DC.W		1
			DC.L		0

S_GenRadio	DC.W		6
			DC.W		16,270,26,515
			DC.W		radioItem
			DC.L		S_GenStr
S_GenVal		DC.W		1
			DC.W		2
			DC.L		0

S_FixedRadio	DC.W		7
			DC.W		26,270,36,515
			DC.W		radioItem
			DC.L		S_FixedStr
S_FixedVal	DC.W		0
			DC.W		2
			DC.L		0

S_DollarRadio	DC.W		8
			DC.W		36,270,46,515
			DC.W		radioItem
			DC.L		S_DollarStr
S_DollarVal	DC.W		0
			DC.W		2
			DC.L		0

S_PercentRadio	DC.W		9
			DC.W		46,270,56,515
			DC.W		radioItem
			DC.L		S_PercentStr
S_PercentVal	DC.W		0
			DC.W		2
			DC.L		0

S_SciNotRadio	DC.W		10
			DC.W		56,270,66,515
			DC.W		radioItem
			DC.L		S_SciNotStr
S_SciNotVal	DC.W		0
			DC.W		2
			DC.L		0

S_BoldBox		DC.W		11
			DC.W		16,30,26,135
			DC.W		checkItem
			DC.L		S_BoldStr
S_BoldVal		DC.W		1
			DC.B		0,0
			DC.L		0

S_UlineBox	DC.W		12
			DC.W		26,30,36,135
			DC.W		checkItem
			DC.L		S_ULineStr
S_UlineVal	DC.W		1
			DC.B		0,0
			DC.L		0

S_CommaBox	DC.W		13
			DC.W		36,30,46,135
			DC.W		checkItem
			DC.L		S_CommaStr
S_CommaVal	DC.W		1
			DC.B		0,0
			DC.L		0

S_RedNegBox	DC.W		14
			DC.W		46,30,56,135
			DC.W		checkItem
			DC.L		S_RedNegStr
S_RedNegVal	DC.W		1
			DC.B		0,0
			DC.L		0

S_ParenBox	DC.W		15
			DC.W		56,30,66,135
			DC.W		checkItem
			DC.L		S_ParenNegStr
S_ParenVal	DC.W		1
			DC.B		0,0
			DC.L		0


S_OptText		DC.W		16
			DC.W		6,30,16,140
			DC.W		statText
			DC.L		S_FmtStr
			DC.W		0
			DC.W		0
			DC.L		0

S_AlText		DC.W		17
			DC.W		76,30,86,111
			DC.W		statText
			DC.L		S_AlStr
			DC.W		0
			DC.W		0
			DC.L		0

S_StyText		DC.W		18
			DC.W		6,270,16,370
			DC.W		statText
			DC.L		S_StyStr
			DC.W		0
			DC.W		0
			DC.L		0

S_OptRect		DC.W		19
			DC.W		10,20,70,218
			DC.W		userItem+itemDisable
			DC.L		S_DlogRect
			DC.W		0
			DC.W		0
			DC.L		0

S_AlRect		DC.W		20
			DC.W		81,20,121,218
			DC.W		userItem+itemDisable
			DC.L		S_DlogRect
			DC.W		0
			DC.W		0
			DC.L		0

S_StyRect		DC.W		21
			DC.W		10,260,72,450
			DC.W		userItem+itemDisable
			DC.L		S_DlogRect
			DC.W		0
			DC.W		0
			DC.L		0

S_DecText		DC.W		22
			DC.W		82,260,92,460
			DC.W		statText
			DC.L		S_DisplayStr
			DC.W		0
			DC.W		0
			DC.L		0

S_PlaceLE		DC.W		23
			DC.W		80,317,93,337
			DC.W		editLine
			DC.L		S_PlaceStr
			DC.W		1					; 1 char LE width
			DC.W		0
			DC.W		0

S_PlaceStr	DS.B 	2

;******************************************************************
;
;			Titles	dialog
;
;******************************************************************
S_TitleDlog
			DC.W		50,120,125,520
			DC.W		1
			DC.L		0
			DC.L		S_TitleOK
			DC.L		S_TitleCancel
			DC.L		S_TitleBlurb
			DC.L		S_LeftBox
			DC.L		S_TopBox
			DC.L		S_Column1Str
			DC.L		S_Column2Str
			DC.L		S_Row1Str
			DC.L		S_Row2Str
			DC.L		S_Row1Box
			DC.L		S_Column2Box
			DC.L		S_Column1Box
			DC.L		S_Row2Box
			DC.L		0

S_TitleOK
			DC.W		1
			DC.W		55,240,70,350
			DC.W		ButtonItem
			DC.L		S_OKStr
			DC.W		0
			DC.W		0
			DC.L		0

S_TitleCancel
			DC.W		2
			DC.W		55,30,70,170
			DC.W		ButtonItem
			DC.L		S_MyFuckingCancelStr
			DC.W		0
			DC.W		0
			DC.L		0

S_TitleBlurb
			DC.W		3
			DC.W		5,30,18,150
			DC.W		StatText+ItemDisable
			DC.L		S_TitleBlurbStr
			DC.W		0
			DC.W		0
			DC.L		0

S_LeftBox
			DC.W		4
			DC.W		36,30,49,150
			DC.W		CheckItem
			DC.L		S_LeftTitleStr
S_LeftBoxVal	DC.W		0
			DC.W		0
			DC.L		0

S_TopBox		DC.W		5
			DC.W		18,30,31,150
			DC.W		CheckItem
			DC.L		S_TopTitleStr
S_TopBoxVal	DC.W		0
			DC.W		0
			DC.L		0

S_Column1Str
			DC.W		6
			DC.W		38,170,50,238
			DC.W		StatText+ItemDisable
			DC.L		S_TitleCol1Str
			DC.W		0
			DC.W		0
			DC.L		0

S_Column2Str
			DC.W		7
			DC.W		39,270,51,338
			DC.W		StatText+ItemDisable
			DC.L		S_ThruStr
			DC.W		0
			DC.W		0
			DC.L		0

S_Row1Str		DC.W		8
			DC.W		20,170,33,208
			DC.W		StatText+ItemDisable
			DC.L		S_TitleRow1Str
			DC.W		0
			DC.W		0
			DC.L		0

S_Row2Str		DC.W		9
			DC.W		20,270,33,338
			DC.W		StatText+ItemDisable
			DC.L		S_ThruStr
			DC.W		0
			DC.W		0
			DC.L		0

S_Column1Box
			DC.W		12
			DC.W		36,240,49,268
			DC.W		EditLine+ItemDisable
			DC.L		S_Column1ValStr
			DC.W		2
			DC.W		0
			DC.L		0

S_Column2Box
			DC.W		13
			DC.W		36,342,49,370
			DC.W		EditLine+ItemDisable
			DC.L		S_Column2ValStr
			DC.W		2
			DC.W		0
			DC.L		0

S_Row1Box		DC.W		10
			DC.W		18,228,31,268
			DC.W		EditLine+ItemDisable
			DC.L		S_Row1ValStr
			DC.W		4
			DC.W		0
			DC.L		0

S_Row2Box		DC.W		11
			DC.W		18,338,31,378
			DC.W		EditLine+ItemDisable
			DC.L		S_Row2ValStr
			DC.W		4
			DC.W		0
			DC.L		0

;******************************************************************
;
;	WidthDialog
;
;******************************************************************
S_WidthDialog
			DC.W		60,320-(S_MaxCellWidth/2+20),125,320+(S_MaxCellWidth/2+20)
			DC.W		1
			DC.L		0
			DC.L		S_WidthOK
			DC.L		S_WidthCancel
			DC.L		S_WidthThing
			DC.L		S_DefaultWidthBlurb
			DC.L		0

S_WidthOK
			DC.W		1
			DC.W		45,(S_MaxCellWidth+40)/2+20,58,(S_MaxCellWidth+40)/2+100
			DC.W		ButtonItem
			DC.L		S_OKStr
			DC.W		0
			DC.W		0
			DC.L		0

S_WidthCancel
			DC.W		2
			DC.W		45,(S_MaxCellWidth+40)/2-100,58,(S_MaxCellWidth+40)/2-20
			DC.W		ButtonItem
			DC.L		S_MyFuckingCancelStr
			DC.W		0
			DC.W		0
			DC.L		0

S_WidthThing
			DC.W		3
S_ThingRect	DC.W		20,20,20+S_ColLabelHeight,S_MaxCellWidth+20
			DC.W		UserItem+ItemDisable
			DC.L		S_ThingDef
			DC.W		0
			DC.W		0
			DC.L		0

S_DefaultWidthBlurb
			DC.W		4
			DC.W		5,20,15,370
			DC.W		StatText+ItemDisable
			DC.L		S_DefaultWidthStr
			DC.W		0
			DC.W		0
			DC.L		0

; S_InThing	DS.B 	2

;**********************************************************************
;
;			List	Formula Dialog
;
;***********************************************************************

S_ListFunctionsDialog
			DC.W		50,170,151,470
			DC.W		1
			DC.L		0
			DC.L		S_ListFuncBlurb
			DC.L		S_LFCloseButton
			DC.L		S_AddButton
			DC.L		0


S_AddButton
			DC.W		1
			DC.W		85,170,97,230
			DC.W		ButtonItem
			DC.L		S_AddFuncStr
			DC.W		0
			DC.W		0
			DC.L		0

S_LFCloseButton
			DC.W		2
			DC.W		85,70,97,130
			DC.W		ButtonItem
			DC.L		S_CloseFuncStr
			DC.W		0
			DC.W		0
			DC.L		0

S_ListFuncBlurb
			DC.W		3
			DC.W		5,20,17,200
			DC.W		StatText+ItemDisable
			DC.L		S_ListFuncStr
			DC.W		0
			DC.W		0
			DC.L		0

S_ListFuncBL
S_LFDialog	DS.B 	4
			DC.W		20,20,82,258
			DC.W		20,260,82,280
S_LFSize		DS.B 	2
			DC.W		10
			DC.W		1
			DC.L		S_DrawLFMember
			DC.L		S_SelectLFMember
			DS.B 	28


;******************************************************************
;
;Strings used in dialogs
;
;******************************************************************

S_DownStr			STR		'Down'
S_UpStr			STR		'Up'
S_LeftStr			STR		'Left'
S_RightStr		STR		'Right'
S_FillStr			STR		'Fill in which direction?'
S_DeleteStr		STR		'Delete in which direction?'
S_InsertStr		STR		'Insert in which direction?'
S_OKStr			STR		'OK'
S_MyFuckingCancelStr STR		'Cancel'
S_KeyStr			STR		'Key:'
S_SortStr			STR		'Sort using which method?'
S_RowColStr		STR		'Rows by column'
S_ColRowStr		STR		'Columns by row'
S_AscStr			STR		'Ascending'
S_DescStr			STR		'Descending'
S_GotoStr			STR		'Go to cell'
S_MoveStr			STR		'   Move to'
S_BoldStr			STR		'Bold'
S_ULineStr		STR		'Underline'
S_CommaStr		STR		'Commas'
S_RedNegStr		STR		'Red negative numbers'
S_ParenNegStr		DC.B		S_CtrStr-S_ParenNegStr-1
				DC.B		'Parenthesize neg. #''s'
S_CtrStr			STR		'Center'
S_GenStr			STR		'General'
S_FixedStr		STR		'Fixed'
S_DollarStr		STR		'Dollars'
S_PercentStr		STR		'Percentage'
S_SciNotStr		STR		'Scientific notation'
S_DisplayStr		STR		'Display      decimal place(s).'
S_FmtStr			STR		' Format Options'
S_AlStr			STR		' Alignment'
S_StyStr			STR		' Format Style'
S_TitleBlurbStr	STR		'Set title area:'
S_LeftTitleStr		STR		' Left titles'
S_TopTitleStr		STR		' Top titles'
S_TitleCol1Str		STR		'Columns:'
S_ThruStr			STR		' through '
S_TitleRow1Str		STR		'Rows:'
S_Column1ValStr	DS.B		3
S_Column2ValStr	DS.B		3
S_Row1ValStr		DS.B		5
S_Row2ValStr		DS.B		5
S_DefaultWidthStr 	STR		'Click in bar to set Default Column Width'
S_AddFuncStr		STR		'Add'
S_CloseFuncStr		STR 		'Close'
S_ListFuncStr		STR		'Select function to add:'


S_WhichLE			DS.B 	2

			ENDP

;--------------------------------------------------------------------------
; S_DoDefaultWidthDlog
;
;	The pixel width is used at the New default column width unless the carry
; is set.	(i.e. set the carry if 'CANCEL' is selected.)

S_DoDefaultWidthDlog	PROC		EXPORT
					;Using	S_DlogData

			input	StartWidth:w
			local	Dialog:l
			output	NewWidth:w
			error	err
			BEGIN	+b

			stz		err

			SpaceLong
			PushLong	#S_WidthDialog
			call		D_GetNewModalDialog
			PullLong	Dialog

			PushWord	StartWidth
			PushLong	Dialog
			PushWord	S_WidthThing
			_SetDItemValue

dloop
			SpaceWord
			PushLong	#S_WidthFilter+$80000000
			_ModalDialog
			pla
			cmp		#2
			beq		docancel
			cmp		#1
			beq		dook
			bra		dloop

dook	SpaceWord
			PushLong	Dialog
			PushWord	#3
			_GetDItemValue
			PullWord	NewWidth
			bra		exit

docancel
			inc		err

exit
			PushLong	Dialog
			call		D_CloseDialog

			RETURN
			ENDP


;***************************************************************
;
;			S_ThingDef	- WidthThing definition procedure
;
;***************************************************************
S_ThingDef	PROC		EXPORT
			;Using	S_DlogData

			input	Dialog:l,ItemID:w
			local	Value:w,Pixels:w,Point:l
			BEGIN	+b

			MoveRect	S_ThingRect,ScratchRect

			SpaceWord
			PushLong	Dialog
			PushWord	ItemId
			_GetDItemValue
			PullWord	Value

			clc
			adc		#20
			sta		Pixels

			MoveWord	Pixels,ScratchRect+6

			PushWord	#LightYellow
			jsl		D_Set4Pat

			PushLong	#ScratchRect
			_PaintRect

			PushWord	#Black
			jsl		D_Set4Pat

			_PenNormal

			PushWord	#2
			PushWord	#1
			_SetPenSize

			MoveWord	S_ThingRect,Point
			MoveWord	Pixels,Point+2

			PushLong	Point
			_MoveTo

			PushWord	#0
			PushWord	#S_ColLabelHeight-1
			_Line

			_PenNormal

			MoveWord	Point,ScratchRect
			AddWord	Point+2,#2,ScratchRect+2
			AddWord	Point,#S_ColLabelHeight,ScratchRect+4
			MoveWord	S_ThingRect+6,ScratchRect+6

			PushLong	#S_BackPat2
			_SetPenPat

			PushLong	#ScratchRect
			_PaintRect

			_PenNormal

			MoveRect	S_ThingRect,ScratchRect

			PushLong	#ScratchRect
			_FrameRect

			RETURN

ScratchRect	DS.B		8

S_BackPat2
			DC.W		$F3F3,$3F3F,$F3F3,$3F3F
			DC.W		$F3F3,$3F3F,$F3F3,$3F3F
			DC.W		$F3F3,$3F3F,$F3F3,$3F3F
			DC.W		$F3F3,$3F3F,$F3F3,$3F3F

			ENDP

;***************************************************************
;
;			S_WidthFilter	- Filter to take care of the width thing
;
;***************************************************************
S_WidthFilter	PROC		EXPORT
			;Using	S_DlogData

			input	Dialog:l,EventPtr:l,ItemPtr:l
			local	LocPoint:l,Value:w,Pixels:w
			output	Result:w
			BEGIN	+b

			jsl		D_HeartBeatIdle

			stz		Result

			MoveWord	[EventPtr]:#oWhat,a
			cmp		#MouseDownEvt
			jne		Exit

	;	Mouse down event	;

			MoveLong	[EventPtr]:#oWhere,LocPoint

			PushLong	!LocPoint
			_GlobalToLocal

			SpaceWord
			PushLong	!LocPoint
			PushLong	#S_ThingRect
			_PtInRect
			pla
			beq		Exit

			SpaceWord
			PushLong	Dialog
			PushWord	S_WidthThing
			_GetDItemValue
			PullWord	Value
			clc
			adc		#20
			sta		Pixels

			SpaceWord
			PushWord	Pixels
			PushWord	#S_MinCellWidth+20
			PushWord	#S_MaxCellWidth+20
			PushWord	S_WidthThing+2
			SubWord	S_WidthThing+6,#1,s
			Call		S_TrackVertLine,in=(:w,:w,:w,:w,:w)	; out = :w

			SubWord	1:s,#20,1:s
			PushLong	Dialog
			PushWord	S_WidthThing
			_SetDItemValue

			inc	Result

Exit
			RETURN
			ENDP


;***************************************************************
;
;			List	formulas dialog
;
;**************************************************************
S_ListFormulasDlog	PROC		EXPORT
				;Using	S_DlogData
				;Using	S_CurrentData2

			local	Item:w,FunctionNo:w,FuncStr:l,StrSize:w
			BEGIN	+b

			Call		S_CopyIn,in=(#S_CurrentData2:l)

			SpaceLong
			PushLong	#S_ListFunctionsDialog
			call		D_GetNewModalDialog
			PullLong	S_LFDialog

			SpaceWord
			jsl		E_GetNFuncs
			PullWord	S_LFSize

			PushLong	#S_ListFuncBL
			jsl		D_BLMakeList

			Call		D_BLSelect,in=(#S_ListFuncBL:l,#0:w)

dloop
			SpaceWord
			PushLong	#S_LFFilter+$80000000
			jsl		D_BLModalDialog
			PullWord	Item
			cmp		#2
			jeq		exit
			cmp		#1
			bne		dloop

			lda		S_Cur2EditFlag
			and		#S_EditingBit
			bne		addFunc

			lda		S_Cur2EditFlag
			ora		#S_EditingBit
			sta		S_Cur2EditFlag

			Tool		_LEActivate,in=(S_Cur2LEHandle:l)
			Tool		_LEGetTextLen,in=(S_Cur2LEHandle:l),out=(x:w)
			Tool		_LESetSelect,in=(#0:w,x:w,S_Cur2LEHandle:l)
			Tool		_LEKey,in=(#$3D:w,#0:w,S_Cur2LEHandle:l)

			Call		S_SetEdittingMenus

addFunc
			SpaceWord
			PushLong	#S_ListFuncBL
			jsl		D_BLGetSel
			PullWord	FunctionNo

			SpaceLong
			PushWord	FunctionNo
			jsl		E_GetFuncName
			PullLong	FuncStr

			lda		[FuncStr]
			and		#$ff
			sta		StrSize

			PushLong	S_Cur2LEHandle
			_LEDelete

			Addwls	#1,FuncStr
			PushWord	StrSize
			PushLong	S_Cur2LEHandle
			_LEInsert
			brl		dloop

exit
			jsl		D_BLForgetLists

			PushLong	S_LFDialog
			call		D_CloseDialog

			Call		S_CopyOut,in=(#S_CurrentData2:l)

			RETURN
			ENDP

;--------------------------------------------------------------------

S_LFFilter	PROC		EXPORT
			;Using	S_DlogData
			;Using	S_CurrentData2

			input	Dialog:l,EventPtr:l,ItemPtr:l
			output	Result:w
			BEGIN	+b

			stz		result

			Cmpw		[EventPtr]:#oWhat,#KeyDownEvt
			jeq		dokey

			cmp		#AutoKeyEvt
			jne		notthisfilter

dokey
			MoveWord	[EventPtr]:#oMessage,a

			cmp		#ESC
			jeq		notthisfilter

			cmp		#CR
			jeq		notthisfilter

			sta		theChar

			lda		S_Cur2EditFlag
			and		#S_EditingBit
			bne		addChar

			lda		S_Cur2EditFlag
			ora		#S_EditingBit
			sta		S_Cur2EditFlag

			Tool		_LEActivate,in=(S_Cur2LEHandle:l)
			Tool		_LEGetTextLen,in=(S_Cur2LEHandle:l),out=(x:w)
			Tool		_LESetSelect,in=(#0:w,x:w,S_Cur2LEHandle:l)

			Call		S_SetEdittingMenus

addChar
			PushWord	theChar
			PushWord	[EventPtr]:#oModifiers
			PushLong	S_Cur2LEHandle
			_LEKey

			bra		exit

notthisfilter
			SpaceWord
			PushLong	Dialog
			PushLong	EventPtr
			PushLong	ItemPtr
			jsl		D_EscFilter
			PullWord	Result

exit
			RETURN

theChar		DS.B 	2

			ENDP

;--------------------------------------------------------------------

S_DrawLFMember	PROC		EXPORT

			input	ListRecPtr:l,ItemNo:w
			local	String:l
			BEGIN

			SpaceLong
			PushWord	ItemNo
			jsl		E_GetFuncName
			PullLong	String

			PushWord	#2
			PushWord	#8
			_Move

			PushLong	String
			_DrawString

			RETURN
			ENDP

;--------------------------------------------------------------------

S_SelectLFMember	PROC		EXPORT
				;Using	S_DlogData

			input	ListPtr:l,Item:w
			BEGIN	+b

			Cmpw		Item,#-1
			bne		activebutton

			lda		LFBActiveFlag
			jeq		exit

			SpaceLong
			PushLong	S_LFDialog
			PushWord	S_AddButton
			_GetControlDItem
			plx
			ply

			PushWord	#255
			phy
			phx
			_HiliteControl

			stz		LFBActiveFlag
			bra		exit

activebutton
			lda		LFBActiveFlag
			bne		exit

			SpaceLong
			PushLong	S_LFDialog
			PushWord	S_AddButton
			_GetControlDItem
			plx
			ply

			PushWord	#0
			phy
			phx
			_HiliteControl

			inc		LFBActiveFlag

exit
			RETURN

LFBActiveFlag	DS.B 	2

			ENDP


;---------------------------------------------------------------------------
;
; S_DoDefaultDlog
;

S_DoDefaultDlog	PROC		EXPORT
				;Using	S_DlogData

			input	oldformat:l
			output	newformat:l

			local	TheDlog:l,result:w,CtlHdl:l
			local	bold:w,uline:w,comma:w,redneg:w,paren:w
			local	left:w,ctr:w,right:w
			local	gen:w,fixed:w,dollar:w,percent:w,scinot:w
			local	decimals:w
			BEGIN	+b

			movelong	oldformat,newformat

			lda		oldformat+2
			and		#S_CellDecPlace
			addword	a,#$30,a
			xba
			ora		#1
			sta		S_PlaceStr

			lda		oldformat
			and		#S_CellPercent
			jsr		MakeBool
			sta		S_PercentVal

			lda		oldformat
			and		#S_CellDollar
			jsr		MakeBool
			sta		S_DollarVal

			lda		oldformat
			and		#S_CellSciNote
			jsr		MakeBool
			sta		S_SciNotVal

			lda		oldformat
			and		#S_CellFixed
			jsr		MakeBool
			sta		S_FixedVal

			ora		S_SciNotVal
			ora		S_DollarVal
			ora		S_PercentVal
			eor		#1
			sta		S_GenVal


			lda		oldformat
			and		#S_CellBold
			jsr		MakeBool
			sta		S_BoldVal

			lda		oldformat
			and		#S_CellULine
			jsr		MakeBool
			sta		S_UlineVal

			lda		oldformat
			and		#S_CellComma
			jsr		MakeBool
			sta		S_CommaVal

			lda		oldformat
			and		#S_CellRedNeg
			jsr		MakeBool
			sta		S_RedNegVal

			lda		oldformat
			and		#S_CellParenNeg
			jsr		MakeBool
			sta		S_ParenVal

			stz		S_ALeftVal
			stz		S_ACtrVal
			stz		S_ARightVal

			lda		oldformat
			and		#S_CellJustify
			cmp		#S_CellLeftJustify
			beq		DoLeft
			cmp		#S_CellRightJustify
			beq		DoRight
DoCtr		inc		S_ACtrVal
			bra		DidJust
DoLeft		inc		S_ALeftVal
			bra		DidJust
DoRight		inc		S_ARightVal
DidJust


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

DlogLoop
			tool		_ModalDialog,in=(#D_DigitsOnly+$80000000:l),out=(result:w)

			beq		DlogLoop

			cmp		#3
			blt		Done

			cmp		#11
			blt		DoRadio

			cmp		#16
			bge		DlogLoop

DoBox		tool		_GetControlDItem,in=(TheDlog:l,result:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(a:w)
			eor		#1
			tool		_SetCtlValue,in=(a:w,CtlHdl:l)
			bra		DlogLoop

DoRadio		tool		_GetControlDItem,in=(TheDlog:l,result:w),out=(CtlHdl:l)
			tool		_SetCtlValue,in=(#1:w,CtlHdl:l)
			brl		DlogLoop

Done			cmpw		result,#Cancel
			jeq		DoClose

			stzl		newformat

			tool		_GetControlDItem,in=(TheDlog:l,#3:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(left:w)
			tool		_GetControlDItem,in=(TheDlog:l,#4:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(ctr:w)
			tool		_GetControlDItem,in=(TheDlog:l,#5:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(right:w)

			tool		_GetControlDItem,in=(TheDlog:l,#6:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(gen:w)
			tool		_GetControlDItem,in=(TheDlog:l,#7:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(fixed:w)
			tool		_GetControlDItem,in=(TheDlog:l,#8:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(dollar:w)
			tool		_GetControlDItem,in=(TheDlog:l,#9:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(percent:w)
			tool		_GetControlDItem,in=(TheDlog:l,#10:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(scinot:w)

			tool		_GetControlDItem,in=(TheDlog:l,#11:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(bold:w)
			tool		_GetControlDItem,in=(TheDlog:l,#12:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(uline:w)
			tool		_GetControlDItem,in=(TheDlog:l,#13:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(comma:w)
			tool		_GetControlDItem,in=(TheDlog:l,#14:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(redneg:w)
			tool		_GetControlDItem,in=(TheDlog:l,#15:w),out=(CtlHdl:l)
			tool		_GetCtlValue,in=(CtlHdl:l),out=(paren:w)


	; Decimal places

			tool		_GetIText,in=(TheDlog:l,#23:w,!decimals:l)

			lda		decimals
			and		#$00FF
			beq		setPlaces				; a = 0 on branch

			lda		decimals+1
			and		#$000F

setPlaces
			ora		newformat+2
			sta		newformat+2

			lda		bold
			beq		TryUline
			lda		#S_CellBold
			ora		newformat
			sta		newformat

TryUline		lda		uline
			beq		TryCommas
			lda		#S_CellUline
			ora		newformat
			sta		newformat

Trycommas		lda		comma
			beq		TryRed
			lda		#S_CellComma
			ora		newformat
			sta		newformat

TryRed		lda		redneg
			beq		TryParen
			lda		#S_CellRedNeg
			ora		newformat
			sta		newformat

TryParen		lda		paren
			beq		DidBoxes
			lda		#S_CellParenNeg
			ora		newformat
			sta		newformat

DidBoxes		lda		gen
			beq		TryFixed
			lda		#0
			bra		DidRadio

TryFixed		lda		fixed
			beq		TryDollar
			lda		#S_CellFixed
			bra		DidRadio

TryDollar		lda		dollar
			beq		TryPercent
			lda		#S_CellDollar
			bra		DidRadio

TryPercent	lda		percent
			beq		TrySciNot
			lda		#S_CellPercent
			bra		DidRadio

TrySciNot		lda		scinot
			beq		DidRadio
			lda		#S_CellSciNote

DidRadio		ora		newformat
			sta		newformat

			lda		right
			beq		TryCtr
			lda		#S_CellRightJustify
			bra		DidRadio2

TryCtr		lda		ctr
			beq		ItsLeft
			lda		#S_CellCenterJustify
			bra		DidRadio2

ItsLeft		lda		#S_CellLeftJustify

DidRadio2		ora		newformat
			sta		newformat

DoClose		call		D_CloseDialog,in=(TheDlog:l)

exit
			RETURN

MakeBool
			beq		GotBool
			lda		#1
GotBool
			rts

			ENDP
			END

