RadioButtons: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (correct user name)
No edit summary
Line 86: Line 86:


; Functions
; Functions
Function .onInit
  !insertmacro RadioGetChecked "1" "1,2,3"
  !insertmacro RadioGetChecked "${g2o1}" "${g2o1},${g2o2},${g2o3}"
FunctionEnd


Function .onSelChange
Function .onSelChange
Line 118: Line 123:
     !verbose push
     !verbose push
     !verbose ${LOGICLIB_VERBOSITY}
     !verbose ${LOGICLIB_VERBOSITY}
   
    !ifndef _CheckedButton${_d}
      var /GLOBAL _CheckedButton${_d}
      !define _CheckedButton${_d}
    !endif


    var /GLOBAL _CheckedButton${_d}
     ${IfThen} $_CheckedButton${_d} == "" ${|} StrCpy $_CheckedButton${_d} `${_d}` ${|}
     ${IfThen} $_CheckedButton${_d} == "" ${|} StrCpy $_CheckedButton${_d} `${_d}` ${|}
     !define CheckedButton `$_CheckedButton${_d}`
     !define CheckedButton `$_CheckedButton${_d}`
Line 219: Line 228:
     Pop $2
     Pop $2
   !macroend
   !macroend
  !macro RadioGetChecked _d _e
    Push $2
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
    !ifndef _CheckedButton${_d}
      var /GLOBAL _CheckedButton${_d}
      !define _CheckedButton${_d}
    !endif
    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 != ""
        ${If} ${SectionIsSelected} $6
          StrCpy $_CheckedButton${_d} "$6"
          ${ExitDo}
        ${EndIf}
        ${If} $4 == $3
        ${AndIf} ${SectionIsSelected} $7
          StrCpy $_CheckedButton${_d} "$7"
        ${EndIf}
      ${EndIf}
    ${LoopUntil} $4 >= $3
    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 15:58, 31 October 2005

Author: NHOCSUNG (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 "${g1o1}" "${g1o1},${g1o2},${g1o3}"
 
or
 
  !insertmacro StartRadioButtons ${g1o1}
    !insertmacro RadioButton ${g1o1}
    !insertmacro RadioButton ${g1o2}
    !insertmacro RadioButton ${g1o3}
  !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 .onInit
  !insertmacro RadioGetChecked "1" "1,2,3"
  !insertmacro RadioGetChecked "${g2o1}" "${g2o1},${g2o2},${g2o3}"
FunctionEnd
 
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

Macros

  ;--------------------------------
 
  ; 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}
 
    !ifndef _CheckedButton${_d}
      var /GLOBAL _CheckedButton${_d}
      !define _CheckedButton${_d}
    !endif
 
    ${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
 
  !macro RadioGetChecked _d _e
    Push $2
    Push $3
    Push $4
    Push $5
    Push $6
    Push $7
 
    !ifndef _CheckedButton${_d}
      var /GLOBAL _CheckedButton${_d}
      !define _CheckedButton${_d}
    !endif
 
    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 != ""
 
        ${If} ${SectionIsSelected} $6
          StrCpy $_CheckedButton${_d} "$6"
          ${ExitDo}
        ${EndIf}
 
        ${If} $4 == $3
        ${AndIf} ${SectionIsSelected} $7
          StrCpy $_CheckedButton${_d} "$7"
        ${EndIf}
      ${EndIf}
 
    ${LoopUntil} $4 >= $3
 
    Pop $7
    Pop $6
    Pop $5
    Pop $4
    Pop $3
    Pop $2
  !macroend