Go to a NSIS page: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Reverted edits by 84.228.86.84 to last version by Kichik)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{PageAuthor|deguix}}
{{PageAuthor|deguix}}


web hosting
== Description ==
[http://web-hosting.viprape.com/ web-hosting]
 
web hosting
This function makes NSIS to go to a specified page relatively from the current page. Use it only on normal functions, the ".onUserAbort" callback function (w/o MUI) or the !define MUI_CUSTOMFUNCTION_ABORT "Function" (w/ MUI) (see more information at the bottom of the page).
tatu
 
This function also allows InstallOptions and InstallOptionsEx to use its features so you can choose which controls will take the place of the default NSIS buttons.


== Function Call ==
== Function Call ==

Latest revision as of 22:11, 8 November 2005

Author: deguix (talk, contrib)


Description

This function makes NSIS to go to a specified page relatively from the current page. Use it only on normal functions, the ".onUserAbort" callback function (w/o MUI) or the !define MUI_CUSTOMFUNCTION_ABORT "Function" (w/ MUI) (see more information at the bottom of the page).

This function also allows InstallOptions and InstallOptionsEx to use its features so you can choose which controls will take the place of the default NSIS buttons.

Function Call

It doesn't use the stack because changing pages makes the code execution to stop. So instead it uses the variable "$R9".

StrCpy $R9 "(number|X)" ;Relative page number. See below.
Call RelGotoPage

Relative Page Number Values

  • If a number > 0: Goes foward that number of pages. Code of that page will be executed, not returning to this point. If it is bigger than the number of pages that are after that page, it simulates a "Cancel" click.
  • If a number < 0: Goes back that number of pages. Code of that page will be executed, not returning to this point. If it is bigger than the number of pages that are before that page, it simulates a "Cancel" click.
  • If X: Simulates a "Cancel" click. Code will go to callback functions, not returning to this point.
  • If 0: Continues on the same page. Code will still be running after the call.

Function Code

;----------------------------------------------------------------------------
; Title             : Go to a NSIS page
; Short Name        : RelGotoPage
; Last Changed      : 22/Feb/2005
; Code Type         : Function
; Code Sub-Type     : Special Restricted Call, One-way StrCpy Input
;----------------------------------------------------------------------------
; Description       : Makes NSIS to go to a specified page relatively from
;                     the current page. See this below for more information:
;                     "http://nsis.sf.net/wiki/Go to a NSIS page"
;----------------------------------------------------------------------------
; Function Call     : StrCpy $R9 "(number|X)"
;
;                     - If a number &gt; 0: Goes foward that number of
;                       pages. Code of that page will be executed, not
;                       returning to this point. If it excess the number of
;                       pages that are after that page, it simulates a
;                       "Cancel" click.
;
;                     - If a number &lt; 0: Goes back that number of pages.
;                       Code of that page will be executed, not returning to
;                       this point. If it excess the number of pages that
;                       are before that page, it simulates a "Cancel" click.
;
;                     - If X: Simulates a "Cancel" click. Code will go to
;                       callback functions, not returning to this point.
;
;                     - If 0: Continues on the same page. Code will still
;                        be running after the call.
;
;                     Call RelGotoPage
;----------------------------------------------------------------------------
; Author            : Diego Pedroso
; Author Reg. Name  : deguix
;----------------------------------------------------------------------------
 
Function RelGotoPage
  IntCmp $R9 0 0 Move Move
    StrCmp $R9 "X" 0 Move
      StrCpy $R9 "120"
 
  Move:
  SendMessage $HWNDPARENT "0x408" "$R9" ""
FunctionEnd

Special Usage - Cancel Clicks Simulation

The .onUserAbort callback function (w/o MUI) and the function indicated by the !define MUI_CUSTOMFUNCTION_PRE (w/ MUI) are totally special in fact that they handle all "Cancel" and "X" clicks the user does, and secondly, that the code still runs if you run the RelGotoPage function, but goes to the page specified after the function is aborted. We can make this "Cancel" and "X" buttons to have a different effect like skipping to the next page, by using the following codes:

For All Pages

Default UI

Use the normal call that I described on the top of this page but on the function ".onUserAbort":

Function .onUserAbort
  StrCpy $R9 1 ;Goto the next page
  Call RelGotoPage
  Abort
FunctionEnd

Modern UI

Use the normal call that I described on the top of this page on the function indicated by the !define MUI_CUSTOMFUNCTION_ABORT:

!insert "MUI.nsh" ;Required by MUI
 
!define MUI_CUSTOMFUNCTION_ABORT "FunctionName"
 
!insertmacro MUI_LANGUAGE "English" ;Required by MUI
 
Function FunctionName
  StrCpy $R9 1 ;Goto the next page
  Call RelGotoPage
  Abort
FunctionEnd

For One Page

Default UI

Use a variable to hold the page index inside the PreFunction of every page and before InstallOptions plugin first call inside every custom page main function, and compare this variable inside the ".onUserAbort" callback function. An example:

Page custom CustomPage
Page components Components_PreFunction
Page directory Directory_PreFunction
 
Function CustomPage
  StrCpy $R8 1 ;This is the first page
  InstallOptions::dialog "C:\MyDir\MyIOPage.ini"
  Pop $0
FunctionEnd
 
Function Components_PreFunction
  StrCpy $R8 2 ;This is the second page
FunctionEnd
 
Function Directory_PreFunction
  StrCpy $R8 3 ;This is the third page
FunctionEnd
 
Function .onUserAbort
  StrCmp $R8 1 0 End ;Compare the variable with the
                     ;page index of your choice
    StrCpy $R9 1
    Call RelGotoPage
    Abort
  End:
FunctionEnd

Modern UI

Use a variable to hold the page index inside the function indicated by each !define MUI_PAGE_CUSTOMFUNCTION_PRE of every page and before MUI_INSTALLOPTIONS_* macro first call inside every custom page main function (except for MUI_INSTALLOPTIONS_READ and MUI_INSTALLOPTIONS_WRITE macros), and compare this variable inside the function indicated by the !define MUI_CUSTOMFUNCTION_ABORT. An example:

!include "MUI.nsh" ;Required by MUI
 
Page custom CustomPage
!define MUI_PAGE_CUSTOMFUNCTION_PRE Components_PreFunction
  !insertmacro MUI_PAGE_COMPONENTS
!define MUI_PAGE_CUSTOMFUNCTION_PRE Directory_PreFunction
  !insertmacro MUI_PAGE_DIRECTORY
 
!define MUI_CUSTOMFUNCTION_ABORT "FunctionName"
!insertmacro MUI_LANGUAGE "English" ;Required by MUI
 
Function CustomPage
  StrCpy $R8 1 ;This is the first page
  InstallOptions::dialog "C:\MyDir\MyIOPage.ini"
  Pop $0
FunctionEnd
 
Function Components_PreFunction
  StrCpy $R8 2 ;This is the second page
FunctionEnd
 
Function Directory_PreFunction
  StrCpy $R8 3 ;This is the third page
FunctionEnd
 
Function FunctionName
  StrCmp $R8 1 0 End ;Compare the variable with the
                     ;page index of your choice
    StrCpy $R9 1
    Call RelGotoPage
    Abort
  End:
FunctionEnd