RadioButtons: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
 
No edit summary
Line 1: Line 1:
{{PageAuthor|Tu Tong}}
{{PageAuthor|Tim Gallagher}}


== Description ==
== Description ==
Line 104: Line 104:
FunctionEnd
FunctionEnd
</highlight-nsis>
== Macro ==
<highlight-nsis>
  ;--------------------------------
 
  ; Macros for mutually exclusive section selection
  ; Written by Tim Gallagher
  ;
  ; See one-section.nsi for an example of usage
  !macro StartRadioButtons _d
    !verbose push
    !verbose ${LOGICLIB_VERBOSITY}
    var /GLOBAL _CheckedButton${_d}
    ${IfThen} $_CheckedButton${_d} == "" ${|} StrCpy $_CheckedButton${_d} `${_d}` ${|}
    !define CheckedButton `$_CheckedButton${_d}`
    Push $0
    Push $1
    SectionGetFlags `${CheckedButton}` $0
    IntOp $0 $0 & ${SECTION_OFF}
    SectionSetFlags `${CheckedButton}` $0
   
    StrCpy $1 `${CheckedButton}`
    !verbose pop
  !macroend
  ; A radio button
  !macro RadioButton _s
    !verbose push
    !verbose ${LOGICLIB_VERBOSITY}
    ${If} ${SectionIsSelected} `${_s}`
      StrCpy `${CheckedButton}` `${_s}`
    ${EndIf}
   
    !verbose pop
  !macroend
  ; Ends the radio button block
  !macro EndRadioButtons
    !verbose push
    !verbose ${LOGICLIB_VERBOSITY}
    ${If} $1 == `${CheckedButton}`                        ; selection hasn't changed
      SectionGetFlags `${CheckedButton}` $0
      IntOp $0 $0 | ${SF_SELECTED}
      SectionSetFlags `${CheckedButton}` $0
    ${EndIf}
    Pop $1
    Pop $0
    !undef CheckedButton
    !verbose pop
  !macroend
 
  !macro SectionRadioButtons _d _e
    Push $2
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
    !insertmacro StartRadioButtons ${_d}
    StrCpy $3 0
    StrLen $5 `${_e}`
    ${For} $2 0 $5
      StrCpy $4 `${_e}` 1 $2
      ${If} $4 == ","
        IntOp $3 $3 + 1
      ${EndIf}
    ${Next}
    StrCpy $7 `${_e}`
    StrCpy $4 0
    ${Do}
      StrLen $5 `$7`
      ${For} $2 0 $5
        StrCpy $6 `$7` 1 $2
        ${If} $6 == ","
          StrCpy $6 `$7` $2
          IntOp $2 $2 + 1
          StrCpy $7 `$7` "" $2
          IntOp $4 $4 + 1
          ${Break}
        ${EndIf}
      ${Next}
      ${If} $4 <= $3
      ${AndIf} $6 != ""
        !insertmacro RadioButton $6
        ${If} $4 == $3
          !insertmacro RadioButton $7
        ${EndIf}
      ${EndIf}
    ${LoopUntil} $4 >= $3
    !insertmacro EndRadioButtons
    Pop $7
    Pop $6
    Pop $5
    Pop $4
    Pop $3
    Pop $2
  !macroend
</highlight-nsis>
</highlight-nsis>


[[Category:Section Management Functions]]
[[Category:Section Management Functions]]

Revision as of 18:50, 28 October 2005

Author: Tim Gallagher (talk, contrib)


Description

Macros for mutually exclusive section selection.

Usage

  !insertmacro SectionRadioButtons "1" "1,2,3"
 
or
 
  !insertmacro StartRadioButtons 1
    !insertmacro RadioButton 1
    !insertmacro RadioButton 2
    !insertmacro RadioButton 3
  !insertmacro EndRadioButtons
 
or
 
  !insertmacro SectionRadioButtons "${g2o1}" "${g2o1},${g2o2},${g2o3}"
 
or
 
  !insertmacro StartRadioButtons ${g2o1}
    !insertmacro RadioButton ${g2o1}
    !insertmacro RadioButton ${g2o2}
    !insertmacro RadioButton ${g2o3}
  !insertmacro EndRadioButtons

Example

; one-section.nsi
;
; This example demonstrates how to control section selection.
; It allows only one of the sections of a group to be selected.
 
;--------------------------------
 
; Section define/macro header file
; See this header file for more info
 
!include ".\Sections.nsh"
 
;--------------------------------
 
Name "One Section"
OutFile "one-section.exe"
 
;--------------------------------
 
; Pages
 
Page components
Page instfiles
 
;--------------------------------
 
; Sections
 
Section !Required
  SectionIn RO
SectionEnd
 
Section "Group 1 - Option 1" g1o1
SectionEnd
 
Section /o "Group 1 - Option 2" g1o2
SectionEnd
 
Section /o "Group 1 - Option 3" g1o3
SectionEnd
 
Section "Group 2 - Option 1" g2o1
SectionEnd
 
Section /o "Group 2 - Option 2" g2o2
SectionEnd
 
Section /o "Group 2 - Option 3" g2o3
SectionEnd
 
;--------------------------------
 
; Functions
 
Function .onSelChange
 
  !insertmacro SectionRadioButtons "1" "1,2,3"
;  !insertmacro StartRadioButtons 1
;    !insertmacro RadioButton 1
;    !insertmacro RadioButton 2
;    !insertmacro RadioButton 3
;  !insertmacro EndRadioButtons
 
;  !insertmacro SectionRadioButtons "${g2o1}" "${g2o1},${g2o2},${g2o3}"
  !insertmacro StartRadioButtons ${g2o1}
    !insertmacro RadioButton ${g2o1}
    !insertmacro RadioButton ${g2o2}
    !insertmacro RadioButton ${g2o3}
  !insertmacro EndRadioButtons
 
FunctionEnd

Macro

  ;--------------------------------
 
  ; Macros for mutually exclusive section selection
  ; Written by Tim Gallagher
  ;
  ; See one-section.nsi for an example of usage
 
  !macro StartRadioButtons _d
    !verbose push
    !verbose ${LOGICLIB_VERBOSITY}
 
    var /GLOBAL _CheckedButton${_d}
    ${IfThen} $_CheckedButton${_d} == "" ${|} StrCpy $_CheckedButton${_d} `${_d}` ${|}
    !define CheckedButton `$_CheckedButton${_d}`
 
    Push $0
    Push $1
 
    SectionGetFlags `${CheckedButton}` $0
    IntOp $0 $0 & ${SECTION_OFF}
    SectionSetFlags `${CheckedButton}` $0
 
    StrCpy $1 `${CheckedButton}`
 
    !verbose pop
  !macroend
 
  ; A radio button
  !macro RadioButton _s
    !verbose push
    !verbose ${LOGICLIB_VERBOSITY}
 
    ${If} ${SectionIsSelected} `${_s}`
      StrCpy `${CheckedButton}` `${_s}`
    ${EndIf}
 
    !verbose pop
  !macroend
 
  ; Ends the radio button block
  !macro EndRadioButtons
    !verbose push
    !verbose ${LOGICLIB_VERBOSITY}
 
    ${If} $1 == `${CheckedButton}`                        ; selection hasn't changed
      SectionGetFlags `${CheckedButton}` $0
      IntOp $0 $0 | ${SF_SELECTED}
      SectionSetFlags `${CheckedButton}` $0
    ${EndIf}
 
    Pop $1
    Pop $0
 
    !undef CheckedButton
    !verbose pop
  !macroend
 
  !macro SectionRadioButtons _d _e
    Push $2
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
 
    !insertmacro StartRadioButtons ${_d}
 
    StrCpy $3 0
    StrLen $5 `${_e}`
    ${For} $2 0 $5
      StrCpy $4 `${_e}` 1 $2
      ${If} $4 == ","
        IntOp $3 $3 + 1
      ${EndIf}
    ${Next}
 
    StrCpy $7 `${_e}`
    StrCpy $4 0
    ${Do}
 
      StrLen $5 `$7`
      ${For} $2 0 $5
        StrCpy $6 `$7` 1 $2
        ${If} $6 == ","
          StrCpy $6 `$7` $2
          IntOp $2 $2 + 1
          StrCpy $7 `$7` "" $2
          IntOp $4 $4 + 1
          ${Break}
        ${EndIf}
      ${Next}
 
      ${If} $4 <= $3
      ${AndIf} $6 != ""
        !insertmacro RadioButton $6
        ${If} $4 == $3
          !insertmacro RadioButton $7
        ${EndIf}
      ${EndIf}
 
    ${LoopUntil} $4 >= $3
 
    !insertmacro EndRadioButtons
 
    Pop $7
    Pop $6
    Pop $5
    Pop $4
    Pop $3
    Pop $2
  !macroend