
; Subroutines to deal with gadget selections in the examples. Below is a list
;of what ID corresponds to which gadget:

;GD_PaletteGadg                         EQU    0
;GD_SelColTxtGadg                       EQU    1
;GD_QuitGadg                            EQU    2
;GD_CheckPalGadg                        EQU    3
;GD_NameGadg                            EQU    4
;GD_AgeGadg                             EQU    5
;GD_SexGadg                             EQU    6
;GD_CreditGadg                          EQU    7
;GD_CompLVGadg                          EQU    8
;GD_ScrollGadg                          EQU    9
;GD_SlideGadg                           EQU    10
;GD_Gadget110                           EQU    11


*****************************************************************************

; Palette gadget sends colour selected in im_Code.

; We get the colour number and update the text gadget accordingly!

DoPalette	moveq.l		#0,d0			clear d0
		move.w		im_Code(a4),d0		get colour number
		
; Convert colour number into a long word offset for string table and get
;address of string. Write address of string into the Tag List

		asl.l		#2,d0			x4 for long offset
		lea		StrTab(pc),a0		->string table
		add.l		d0,a0
		move.l		(a0),NewColour		set colour text

; Now update the text gadget to reflect the colour selected. The address of
;the gadget to update is obtained from the array of pointer generated by
;GadToolsBox. If we multiply the gadgets ID by 4 we get the offset into the
;array at which the gadgets pointer has been stored :-)

		lea		Project0Gadgets,a0	->Gadget pointer array
		move.l		GD_SelColTxtGadg*4(a0),a0	->Gadget
		move.l		win.ptr(a5),a1		->Window
		suba.l		a2,a2			no requester
		lea		ColNumTags(pc),a3	->Tag List
		CALLGAD		GT_SetGadgetAttrsA


		rts

StrTab		dc.l		Grey
		dc.l		Black
		dc.l		White
		dc.l		Blue

Grey		dc.b		'Grey',0
		even
Black		dc.b		'Black',0
		even
White		dc.b		'White',0
		even
Blue		dc.b		'Blue',0
		even

ColNumTags	dc.l		GTTX_Text	this Tag item has been split
NewColour	dc.l		0		over two lines
		dc.l		TAG_DONE

*****************************************************************************

; Palette Check Box gadget has been hit. A CheckBox gadget returns a 0 in
;im_Code if deselected ( no tick ) or a 1 if selected ( ticked ). This is
;the opposite to the values we require so it must first be reversed:

DoPalEnable	moveq.l		#0,d0			clear
		move.w		im_Code(a4),d0
		bne.s		.IsSet
		moveq.l		#2,d0

.IsSet		subq.w		#1,d0
		move.l		d0,PalEnable

; Can now enable/disable palette gadget according to the state of the Check
;box gadget ... very tidy:-)

		lea		Project0Gadgets,a0	->Gadget pointer array
		move.l		GD_PaletteGadg*4(a0),a0	->Gadget
		move.l		win.ptr(a5),a1		->Window
		suba.l		a2,a2			no requester
		lea		PalEnableTags(pc),a3	->Tag List
		CALLGAD		GT_SetGadgetAttrsA

		rts

PalEnableTags	dc.l		GA_Disabled
PalEnable	dc.l		0
		dc.l		TAG_DONE
		
*****************************************************************************

; Name entry gadget. Just get address of string and echo it using the OKReq
;subroutine.

DoName		move.l		im_IAddress(a4),a0	->Gadget
		move.l		gg_SpecialInfo(a0),a0	->StringInfo
		move.l		si_Buffer(a0),a0	->Entered string

		move.l		a0,OKDStream
		
		lea		NameText(pc),a0
		bsr		OKReq
		rts

NameText	dc.b		'Hi there %s.',0
		even

*****************************************************************************

; Age entry gadget. We must get the integer value entered from the gadgets
;special info structure.

DoAge		move.l		im_IAddress(a4),a0	->Gadget
		move.l		gg_SpecialInfo(a0),a0	->StringInfo
		move.l		si_LongInt(a0),d0	->Entered string
		

		move.w		d0,OKDStream

		lea		AgeText(pc),a0
		bsr		OKReq
		rts

AgeText		dc.b		'So your are %d years young!',0
		even

*****************************************************************************

; Sex MX gadget. The ordinal number of the selection can be obtained from
;the im_Code field. We already know that the selections are Male, Female and
;Other:

; Again I am using the ordinal number to obtain an offset into an array of 
;string pointers.

DoSex		moveq.l		#0,d0
		move.w		im_Code(a4),d0

		asl.l		#2,d0			x4 for long offset
		lea		SexStrTab(pc),a0	->string table
		add.l		d0,a0
		move.l		(a0),a0			get a response
		bsr		OKReq
		rts

SexStrTab	dc.l		Male
		dc.l		Female
		dc.l		Other

Male		dc.b		'Alright mate!',0
		even

Female		dc.b		'Simulated wolf whistle',0
		even

Other		dc.b		' Arrggghhhhhh ',0
		even

*****************************************************************************

; Credits cycle gadget. Again ordinal number of selected text is returned
;in im_Code.

DoCycle		move.w		im_Code(a4),OKDStream

		lea		CycleText(pc),a0
		bsr		OKReq
		
		rts

CycleText	dc.b		'Cycle gadget item %d selected.',0
		even

*****************************************************************************

; ListView. We only get a message when user has made a selection. The im_Code
;field will contain the ordinal number of node selected, we can step through
;the nodes until we arrive at the one selected and pull the name of the node
;from this ... not always necessary, but useful for demonstration.

DoLV		moveq.l		#0,d0
		move.w		im_Code(a4),d0		get ordinal number

; get address of the list header being used by ListView .. created by
;GadToolsBox

		lea		CompLVGadgList,a0	a0->list header

; Now step through the list using ordinal number as a counter

LVloop		move.l		(a0),a0			a0->next node
		dbra		d0,LVloop

; We can now pull the name of the node ready for use:

		move.l		LN_NAME(a0),OKDStream

; Now time to print what we have discovered :-)

		lea		LVText,a0
		bsr		OKReq
		
		rts

LVText		dc.b		'So you are the proud owner',$0a
		dc.b		'of a CBM %s',0
		even

*****************************************************************************

; A scroller is used to display sections of the whole. The upper limit, lower
;limit and visible amount are set at initialisation time. The scroller
;returns the value of the top most visible portion of the whole.

DoScroll	move.w		im_Code(a4),OKDStream

		lea		ScrollText,a0
		bsr		OKReq

		rts

ScrollText	dc.b		'Scroller returned value %d.',0
		even

*****************************************************************************

; A slider will return a value between it's upper and lower values as
;specified at initialisation time. These limits can be changed at any time
;by calling GT_SetGadgetAttrsA(), but this is not covered here :-)

DoSlide		move.w		im_Code(a4),OKDStream

		lea		SlideText,a0
		bsr		OKReq

		rts

SlideText	dc.b		'Slider returned value %d.',0
		even

*****************************************************************************

*****************************************************************************

*****************************************************************************

*****************************************************************************



