Name "test"
OutFile "test.exe"

!define SF_SELECTED   1
!define SF_SUBSEC     2
!define SF_SUBSECEND  4
!define SF_BOLD       8
!define SF_RO         16
!define SF_EXPAND     32

!define SECTION_OFF   0xFFFFFFFE

ComponentText "blah, blah"


SubSection /e "xx_1"
Section option_11 sec11
SectionEnd
Section option_12 sec12
SectionEnd
SubSectionEnd

SubSection /e "xx_2"
Section option_21 sec21
SectionEnd
Section option_22 sec22
SectionEnd
SubSectionEnd


Function .onInit

	Push $0

	SectionGetFlags ${sec11} $0
		IntOp $0 $0 | ${SF_SELECTED}
	SectionSetFlags ${sec11} $0
	SectionGetFlags ${sec12} $0
		IntOp $0 $0 & ${SECTION_OFF}
	SectionSetFlags ${sec12} $0

	; remember which section (1)
	StrCpy $1 ${sec11}

	SectionGetFlags ${sec21} $0
		IntOp $0 $0 | ${SF_SELECTED}
	SectionSetFlags ${sec21} $0
	SectionGetFlags ${sec22} $0
		IntOp $0 $0 & ${SECTION_OFF}
	SectionSetFlags ${sec22} $0

	; remember which section (2)
	StrCpy $3 $(sec21)

	Pop $0
	
FunctionEnd

Function .onSelChange

	Push $0

	; turn off old selected section (1)
	SectionGetFlags $1 $0
		IntOp $0 $0 & ${SECTION_OFF}
	SectionSetFlags $1 $0

	; remember the current selection (1)
	Push $2
	StrCpy $2 $1

	SectionGetFlags ${sec11} $0
		IntOp $0 $0 & ${SF_SELECTED}
		IntCmp $0 ${SF_SELECTED} 0 +2 +2
		StrCpy $1 ${sec11}
	SectionGetFlags ${sec12} $0
		IntOp $0 $0 & ${SF_SELECTED}
		IntCmp $0 ${SF_SELECTED} 0 +2 +2
		StrCpy $1 ${sec12}

	; selection hasn't changed (1)
	StrCmp $2 $1 0 +4
	SectionGetFlags $1 $0
		IntOp $0 $0 | ${SF_SELECTED}
	SectionSetFlags $1 $0
	Pop $2

	; turn off old selected section (2)
	SectionGetFlags $3 $0
		IntOp $0 $0 & ${SECTION_OFF}
	SectionSetFlags $3 $0

	; remember the current selection (2)
	Push $4
	StrCpy $4 $3

	SectionGetFlags ${sec21} $0
		IntOp $0 $0 & ${SF_SELECTED}
		IntCmp $0 ${SF_SELECTED} 0 +2 +2
		StrCpy $3 ${sec21}
	SectionGetFlags ${sec22} $0
		IntOp $0 $0 & ${SF_SELECTED}
		IntCmp $0 ${SF_SELECTED} 0 +2 +2
		StrCpy $3 ${sec22}

	; selection hasn't changed (2)
	StrCmp $4 $3 0 +4
	SectionGetFlags $3 $0
		IntOp $0 $0 | ${SF_SELECTED}
	SectionSetFlags $3 $0
	Pop $4

	Pop $0

FunctionEnd
