Archive: Source of !(insert)macro RadioButton


Source of !(insert)macro RadioButton
I'm using RadioButton-kindish features in my component page. I only need to tweak it somewhat.

For example I need the components to be unselectable (currently 1 always must be selected - which is normal with RadioButtons, but I dont want that).

I could program this myself in the "Function .onSelChange", but have no idea on how to start. The .nsi source of the RadioButton macro would help me a lot, but i can't find it (does it exist? or is it only in C++ source).

Can someone post it? Or your "Function .onSelChange" section if you're using some scripts in there?

Thanks!


stupid me.... *slaps self*

Just found it... it's in sections.nsh

If someone would be so graceful to still post his nifty .onSelChange function I'd be thankful. Otherwise sorry for wasting your time ;)


Okay.... Not that easy (or i just cant read this efficient programming.. ;)). I have declared my own RadioButton macros:

!macro StartRadioButtons2 var
!define StartRadioButtons_Var "${var}"
Push $R0
SectionGetFlags "${StartRadioButtons_Var}" $R0
IntOp $R0 $R0 & ${SECTION_OFF}
SectionSetFlags "${StartRadioButtons_Var}" $R0
Push $R1
StrCpy $R1 "${StartRadioButtons_Var}"
!macroend

!macro RadioButton2 SECTION_NAME
SectionGetFlags ${SECTION_NAME} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} 0 +2 +2
StrCpy "${StartRadioButtons_Var}" ${SECTION_NAME}
!macroend

!macro EndRadioButtons2
StrCmp $R1 "${StartRadioButtons_Var}" 0 +4 ; selection hasn't changed
SectionGetFlags "${StartRadioButtons_Var}" $R0
IntOp $R0 $R0 | ${SF_SELECTED}
; SectionSetFlags "${StartRadioButtons_Var}" $R0
Pop $R1
Pop $R0
!undef StartRadioButtons_Var
!macroend

As you can see, this is directly copied from Sections.nsh. All I did was commenting one line in !macro EndRadioButtons2. This gives the desired effect:
- when clicking an unselected option from the radio-group, it gets selected and all others deselected.
- when clicking the selected option, it deselects leaving all options in the radiogroup deselected.
But what not works (when the entire group is deselected):
- when clicking the just deselected (last) option from the radiogroup, nothing happens (it doesn't get selected).
- when clickin on NOT the just deselected option, it gets selected (as it should).

Hope this is a little clear.. ;)

Ofcourse this is because i just left an entire line out and I've tried playing with the IntOp command... but it all doesn't make much sense to me.... Anyone got any suggestions?

Hmmm.. i threw away all the RadioButton code and have this now:

Function .onSelChange
SectionGetFlags ${SEC_Cross1} $0
SectionGetFlags ${SEC_Cross2} $1
IntOp $3 $0 & $1
IntCmp $3 1 0 +3 +3
SectionSetFlags ${SEC_Cross1} 0
SectionSetFlags ${SEC_Cross2} 0
FunctionEnd

This deselects both options if both are selected, allowing the user to re-select one.

I dont know how to "see" what option was last clicked... how is that done?

I basicly want to add a SectionSetFlags ${last_section_clicked} 1 command at the end...

You have to store the last clicked section in a variable.


Originally posted by Joost Verburg
You have to store the last clicked section in a variable.
no really? :rolleyes: :D

I unfortunatly dont know how... I've seen some other sources, but they dont give me what I'm looking for... Or I'm misinterpreting them...

Can't believe I'm the only one wanting this kind of feature...

* Set the default state in a variable
* Unselect the previous selection in .onSelChange (if there is one selected)
* See what's selected right now and store that in the variable


Sorry.. you're not making any sense to me.... $0 contains the result of SectionGetFlags ${SEC_Cross1} as far as I can see.

I'm currently unselecting all sections, but have no way to reselect the clicked section. I'm still looking for the SectionSetFlags ${last_section_clicked} 1 sollution... :(


I'm not sure the solution below is the right thing to do because I don't *really* understand what you mean, but to store that value in a variable I suggest you use a global variable.

Try this (otside of your function):

Var nSectionSelectionValue

Function .onSelChange
SectionGetFlags ${SEC_Cross1} $0
...
SectionSetFlags ${SEC_Cross2} $nSectionSelectionValue
FunctionEnd

Maybe this helps...

Then I also suggest that you try to use the "LogicLib.nsh" and write like this instead of using "IntCmp"

IntCmp $3 1 0 +3 +3
SectionSetFlags ${SEC_Cross1} 0
SectionSetFlags ${SEC_Cross2} 0

could be written as:

${If} $3 = 1
SectionSetFlags ${SEC_Cross1} 0
SectionSetFlags ${SEC_Cross2} 0
${EndIf}

Almost like C :)


Actually, "==" is StrCmp; IntCmp is "=".

Devion, I think I had to do this once. I'll try to dig it out...

edit:
OK, no need :)


AHYES... I finally got it! Here's my sollution:

This is the solution for having 2 sections, who both can be selected or unselected, but not both selected at the same time. E.g. if section 1 is selected, and you select section 2, section 1 will become unselected.

this in .onInit

   StrCpy $8 "true" ; using $8 to store state of section1 (default is on)
StrCpy $9 "false"; using $9 to store state of section2 (default is off)


this in .onSelChange
   SectionGetFlags ${SEC_Cross1} $0 ;get both states
SectionGetFlags ${SEC_Cross2} $1
IntOp $3 $0 & $1
IntCmp $3 1 doscheck sisok sisok ;if both states are ON, go check what to do, else selection is OK
doscheck:
; MessageBox MB_OK "c1:$8 - c2:$9" ;for debugging
SectionSetFlags ${SEC_Cross1} 0 ;deselect both sections
SectionSetFlags ${SEC_Cross2} 0

StrCmp $8 "true" c1wason c2wason ; section1 WAS on, so now section 2 must be on
c1wason:
SectionSetFlags ${SEC_Cross2} 1
StrCpy $8 "false"
StrCpy $9 "true"
goto sisok ; variables are updated and the section has been selected

c2wason:
SectionSetFlags ${SEC_Cross1} 1
StrCpy $8 "true"
StrCpy $9 "false"

sisok:

This is prolly not the best way to do this, but it works! Would also be easily possible to do this for more that 2 sections.

Thanks for your input everyone!

There is an easier method. Use this set of macros in the same way as the orignal Sections.nsh macros and it should work.

!macro StartRadioButtons var

!define StartRadioButtons_Var "${var}"

Push $R0

Push $R1

StrCpy $R1 0

SectionGetFlags "${StartRadioButtons_Var}" $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} 0 +5 +5
SectionGetFlags "${StartRadioButtons_Var}" $R0
IntOp $R0 $R0 & ${SECTION_OFF}
SectionSetFlags "${StartRadioButtons_Var}" $R0
StrCpy $R1 1

Push $R2

StrCpy $R2 "${StartRadioButtons_Var}"

!macroend

; A radio button

!macro RadioButton SECTION_NAME

SectionGetFlags ${SECTION_NAME} $R0
IntOp $R0 $R0 & ${SF_SELECTED}
IntCmp $R0 ${SF_SELECTED} 0 +3 +3
StrCpy "${StartRadioButtons_Var}" ${SECTION_NAME}
StrCpy $R1 1

!macroend

; Ends the radio button block

!macro EndRadioButtons

StrCmp $R1 0 +5
StrCmp $R2 "${StartRadioButtons_Var}" 0 +4 ; selection hasn't changed
SectionGetFlags "${StartRadioButtons_Var}" $R0
IntOp $R0 $R0 | ${SF_SELECTED}
SectionSetFlags "${StartRadioButtons_Var}" $R0

Pop $R2
Pop $R1
Pop $R0

!undef StartRadioButtons_Var

!macroend