Buttons Header: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
No edit summary |
mNo edit summary |
||
Line 23: | Line 23: | ||
<highlight-nsis> | <highlight-nsis> | ||
; Defines | ; Defines | ||
!define buttonVisible "!insertMacro buttonVisible" | !define buttonVisible "!insertMacro buttonVisible" | ||
Line 34: | Line 33: | ||
; Interim macros | ; Interim macros | ||
!macro buttonVisible button value | !macro buttonVisible button value | ||
Push ${button} | |||
Push v | Push v | ||
Push ${value} | Push ${value} | ||
Line 40: | Line 39: | ||
!macroend | !macroend | ||
!macro unbuttonVisible button value | !macro unbuttonVisible button value | ||
Push ${button} | |||
Push v | Push v | ||
Push ${value} | Push ${value} | ||
Line 47: | Line 46: | ||
!macro buttonEnabled button value | !macro buttonEnabled button value | ||
Push ${button} | |||
Push e | Push e | ||
Push ${value} | Push ${value} | ||
Line 53: | Line 52: | ||
!macroend | !macroend | ||
!macro unbuttonEnabled button value | !macro unbuttonEnabled button value | ||
Push ${button} | |||
Push e | Push e | ||
Push ${value} | Push ${value} | ||
Line 60: | Line 59: | ||
!macro buttonText button value | !macro buttonText button value | ||
Push ${button} | |||
Push t | Push t | ||
Push ${value} | Push ${value} | ||
Line 66: | Line 65: | ||
!macroend | !macroend | ||
!macro unbuttonText button value | !macro unbuttonText button value | ||
Push ${button} | |||
Push t | Push t | ||
Push ${value} | Push ${value} | ||
Line 86: | Line 85: | ||
; If 't', then <string> will be set as the button's new label text | ; If 't', then <string> will be set as the button's new label text | ||
!macro ButtonsFunc Un | !macro ButtonsFunc Un | ||
Function ${Un}Buttons | |||
; Stack: <value> <mode> <button> | |||
Exch $2 ; value | Exch $2 ; value ; Stack: $2 <mode> <button> | ||
Exch | Exch ; Stack: <mode> $2 <button> | ||
Exch $1 ; mode | Exch $1 ; mode ; Stack: $1 $2 <button> | ||
Exch 2 | Exch 2 ; Stack: <button> $2 $1 | ||
Exch $0 ; button | Exch $0 ; button ; Stack: $0 $2 $1 | ||
Push $3 | Push $3 ; Stack: $3 $0 $2 $1 | ||
StrCmp $0 "Back" 0 +3 | StrCmp $0 "Back" 0 +3 | ||
StrCpy $3 3 | |||
goto _setbutton | |||
StrCmp $0 "Next" 0 +3 | StrCmp $0 "Next" 0 +3 | ||
StrCpy $3 1 | |||
goto _setbutton | |||
StrCmp $0 "Cancel" 0 _end | StrCmp $0 "Cancel" 0 _end | ||
StrCpy $3 2 | |||
_setbutton: | _setbutton: | ||
Line 111: | Line 110: | ||
goto _end | goto _end | ||
StrCmp $1 "e" 0 +3 | StrCmp $1 "e" 0 +3 | ||
EnableWindow $3 $2 | |||
goto _end | goto _end | ||
StrCmp $1 "t" 0 _end | StrCmp $1 "t" 0 _end | ||
Line 119: | Line 118: | ||
; Stack: $3 $0 $2 $1 | ; Stack: $3 $0 $2 $1 | ||
Pop $3 | Pop $3 ; Stack: $0 $2 $1 | ||
Pop $0 | Pop $0 ; Stack: $2 $1 | ||
Pop $2 | Pop $2 ; Stack: $1 | ||
Pop $1 | Pop $1 ; Stack: [clean] | ||
FunctionEnd | |||
!macroend | !macroend | ||
!insertmacro ButtonsFunc "" | !insertmacro ButtonsFunc "" | ||
!insertmacro ButtonsFunc "Un." | !insertmacro ButtonsFunc "Un." | ||
</highlight-nsis> | </highlight-nsis> |
Revision as of 16:10, 28 October 2008
Below is a simple header file for handling common operations on the 3 main installer buttons; Back, Next and Cancel:
- Disabling/Enabled a button
- Hiding/Unhiding a button
- Changing the button's label
Usage examples:
; For installers ; hide the Back button ${buttonVisible} "Back" 0 ; enable the Next button ${buttonEnabled} "Next" 1 ; Change the Cancel button's label to "Exit" ${buttonText} "Cancel" "Exit" ; For uninstallers, the same commands apply, prepended with 'un'. E.g. ${unbuttonVisible} "Back" 0
; Defines !define buttonVisible "!insertMacro buttonVisible" !define buttonEnabled "!insertMacro buttonEnabled" !define buttonText "!insertMacro buttonText" !define unbuttonVisible "!insertMacro unbuttonVisible" !define unbuttonEnabled "!insertMacro unbuttonEnabled" !define unbuttonText "!insertMacro unbuttonText" ; Interim macros !macro buttonVisible button value Push ${button} Push v Push ${value} Call Buttons !macroend !macro unbuttonVisible button value Push ${button} Push v Push ${value} Call Un.Buttons !macroend !macro buttonEnabled button value Push ${button} Push e Push ${value} Call Buttons !macroend !macro unbuttonEnabled button value Push ${button} Push e Push ${value} Call Un.Buttons !macroend !macro buttonText button value Push ${button} Push t Push ${value} Call Buttons !macroend !macro unbuttonText button value Push ${button} Push t Push ${value} Call Un.Buttons !macroend ; Function (inserted via macros for installer vs uninstaller) ; Buttons FUnction ; Used to interact with the three default buttons; Back, Next, Cancel ; Usage : ; Push Back|Next|Cancel ; Push v|e|t ; Push 1|0|<string> ; Call Buttons | Call Un.Buttons ; Result : ; Interacts with the appropriate button ; If 'v', then 1 will set visible and 0 will set invisible ; If 'e', then 1 will set enabled and 0 will set disabled ; If 't', then <string> will be set as the button's new label text !macro ButtonsFunc Un Function ${Un}Buttons ; Stack: <value> <mode> <button> Exch $2 ; value ; Stack: $2 <mode> <button> Exch ; Stack: <mode> $2 <button> Exch $1 ; mode ; Stack: $1 $2 <button> Exch 2 ; Stack: <button> $2 $1 Exch $0 ; button ; Stack: $0 $2 $1 Push $3 ; Stack: $3 $0 $2 $1 StrCmp $0 "Back" 0 +3 StrCpy $3 3 goto _setbutton StrCmp $0 "Next" 0 +3 StrCpy $3 1 goto _setbutton StrCmp $0 "Cancel" 0 _end StrCpy $3 2 _setbutton: GetDlgItem $3 $HWNDPARENT $3 StrCmp $1 "v" 0 +3 ShowWindow $3 $2 goto _end StrCmp $1 "e" 0 +3 EnableWindow $3 $2 goto _end StrCmp $1 "t" 0 _end SendMessage $3 ${WM_SETTEXT} 0 "STR:$2" _end: ; Stack: $3 $0 $2 $1 Pop $3 ; Stack: $0 $2 $1 Pop $0 ; Stack: $2 $1 Pop $2 ; Stack: $1 Pop $1 ; Stack: [clean] FunctionEnd !macroend !insertmacro ButtonsFunc "" !insertmacro ButtonsFunc "Un."