
		LOAD		'Macros.dump'

		INCLUDE	'SS.equ'

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

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

		IMPORT	D_AlertBox
		IMPORT	D_MemoryError

		IMPORT	S_ActiveWindow
		IMPORT	S_CurBRSelect
		IMPORT	S_CurBScrl
		IMPORT	S_CurContRect
		IMPORT	S_CurEditFlag
		IMPORT	S_CurMaxTLCell
		IMPORT	S_CurRScrl
		IMPORT	S_CurTLSelect
		IMPORT	S_CurWindow
		IMPORT	S_DoModifyChart
		IMPORT	S_DoNewChart
		IMPORT	S_DrawLocation
		IMPORT	S_EndEdit
		IMPORT	S_FixLE
		IMPORT	S_GetCellDlog
		IMPORT	S_HiliteCells
		IMPORT	S_InvalidCellStr
		IMPORT	S_SwapIn
		IMPORT	S_Thumb
		IMPORT	S_UpdateDoc

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

		ENTRY	S_RefreshUpdateRgn

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

S_Goto		PROC		EXPORT
			;Using	S_CurrentData
			;Using	S_ErrorData

			local	Cell:l,Value:w,OldClipRgn:l
			error	ErrFlag
			BEGIN	+b

			stz		ErrFlag

			Call		S_SwapIn,in=(S_ActiveWindow:l)

	;	newcell: 0 == Cancelled, 0 w/carry set == error

			Call		S_GetCellDlog,in=(#0:w,S_CurTLSelect:l),out=(Cell:l)

			bcc		doOK

			Call		D_AlertBox,in=(#OKBox:w,#S_InvalidCellStr:l),out=(a:w)

doOK
			lda		Cell
			ora		Cell+2
			jeq		Exit

			lda		S_CurEditFlag
			and		#S_KeysInactive
			jne		Exit

			Call		S_RefreshUpdateRgn

			lda		S_CurEditFlag
			and		#S_EditingBit
			beq		ChkBump

			Call		S_EndEdit,in=(#-1:w),err=ErrFlag
			jcs		memError

			lda		S_CurEditFlag
			and		#-1-S_EditingBit
			sta		S_CurEditFlag

	;	Bump the window until the New cell at the top left	;

ChkBump

	;	Bump Horizontally	;

			CmpWord	Cell+2,S_CurMaxTLCell+2
			blt		setBValue

			lda		S_CurMaxTLCell+2

setBValue
			dec		a
			sta		Value

			Tool		_SetCtlValue,in=(Value:w,S_CurBScrl:l)
			Call		S_Thumb,in=(S_CurBScrl:l)

	;	Bump Vertically	;

			CmpWord	Cell,S_CurMaxTLCell
			blt		setRValue

			lda		S_CurMaxTLCell

setRValue
			dec		a
			sta		Value

			Tool		_SetCtlValue,in=(Value:w,S_CurRScrl:l)
			Call		S_Thumb,in=(S_CurRScrl:l)

	;	The Cell is completely in view	;

			Tool		_NewRgn,out=(:l)
			MoveLong	1:s,OldClipRgn
			Tool		_GetClip,in=(:l)
			Tool		_ClipRect,in=(#S_CurContRect:l)

			Call		S_HiliteCells

			MoveWord	Cell,S_CurTLSelect
			sta		S_CurBRSelect

			MoveWord	Cell+2,S_CurTLSelect+2
			sta		S_CurBRSelect+2

			Call		S_HiliteCells

			Tool		_SetClip,in=(OldClipRgn:l)
			Tool		_DisposeRgn,in=(OldClipRgn:l)
			bra		doLE

memError
			Call		D_MemoryError

	;	The New cell needs to be displayed in the LE field.	;

doLE
			Call		S_FixLE
			Call		S_DrawLocation

Exit
			RETURN
			ENDP

;---------------------------------------------------------------------------
;
; S_NewChart	
;

S_NewChart	PROC		EXPORT
			BEGIN	+b

			Call		S_SwapIn,in=(S_ActiveWindow:l)
			Call		S_DoNewChart

			RETURN
			ENDP

;---------------------------------------------------------------------------
;
; S_ModifyChart 
;

S_ModifyChart	PROC		EXPORT
			BEGIN	+b

			Call		S_SwapIn,in=(S_ActiveWindow:l)
			Call		S_DoModifyChart

			RETURN
			ENDP

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

S_RefreshUpdateRgn	PROC		EXPORT
				;Using	S_CurrentData

			BEGIN

			Tool		_BeginUpdate,in=(S_CurWindow:l)
			Call		S_UpdateDoc,in=(S_CurWindow:l)
			Tool		_EndUpdate,in=(S_CurWindow:l)

			RETURN
			ENDP
			END

