Go to a NSIS page: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
(Created page.)
 
m (Reverted edits by 84.228.86.84 to last version by Kichik)
 
(10 intermediate revisions by 5 users not shown)
Line 1: Line 1:
{{PageAuthor|deguix}}
== Description ==
== Description ==


This function makes NSIS to got to a specified page relatively from the current page. Use it only on normal functions, the ".onUserAbort" callback function (w/o MUI) and the !define MUI_CUSTOMFUNCTION_ABORT "Function" (w/ MUI) (see more information at the bottom of the page).
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 allow InstallOptions and InstallOptionsEx to use its features so you can choose which controls will take the place of the default NSIS buttons.
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 ==
Line 9: Line 11:
''It doesn't use the stack because changing pages makes the code execution to stop. So instead it uses the variable "$R9".''
''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)"'' ;Explained below:
<highlight-nsis>
 
StrCpy $R9 "(number|X)" ;Relative page number. See below.
<ul>
Call RelGotoPage
*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.
</highlight-nsis>


*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.
=== Relative Page Number Values ===


*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 is bigger than 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 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 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.
*If 0: Continues on the same page. Code will still be running after the call.
</ul>
*'''Call''' ''RelGotoPage''


== Function Code ==
== Function Code ==


<highlight-nsis>;----------------------------------------------------------------------------
<highlight-nsis>
;----------------------------------------------------------------------------
; Title            : Go to a NSIS page
; Title            : Go to a NSIS page
; Short Name        : RelGotoPage
; Short Name        : RelGotoPage
Line 34: Line 35:
; Description      : Makes NSIS to go to a specified page relatively from
; Description      : Makes NSIS to go to a specified page relatively from
;                    the current page. See this below for more information:
;                    the current page. See this below for more information:
;   "http://nsis.sourceforge.net/archive/nsisweb.php?page=705&instances=0,11"
;                     "http://nsis.sf.net/wiki/Go to a NSIS page"
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Function Call    : StrCpy $R9 "(number|X)"
; Function Call    : StrCpy $R9 "(number|X)"
Line 68: Line 69:
   Move:
   Move:
   SendMessage $HWNDPARENT "0x408" "$R9" ""
   SendMessage $HWNDPARENT "0x408" "$R9" ""
FunctionEnd</highlight-nsis>
FunctionEnd
</highlight-nsis>


== Special Usage - Cancel Clicks Simulation ==
== Special Usage - Cancel Clicks Simulation ==


The .onUserAbort callback function (w/o MUI) and the function indicated by the !define MUI_CUSTOMFUNCTION_PRE (w/ MUI) 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 skiping the next page, by using the following codes:
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 ===
=== For All Pages ===
Line 80: Line 82:
Use the normal call that I described on the top of this page but on the function ".onUserAbort":
Use the normal call that I described on the top of this page but on the function ".onUserAbort":


<highlight-nsis>Function .onUserAbort
<highlight-nsis>
Function .onUserAbort
   StrCpy $R9 1 ;Goto the next page
   StrCpy $R9 1 ;Goto the next page
   Call RelGotoPage
   Call RelGotoPage
   Abort
   Abort
FunctionEnd</highlight-nsis>
FunctionEnd
</highlight-nsis>


==== Modern UI ====
==== Modern UI ====
Line 90: Line 94:
Use the normal call that I described on the top of this page on the function indicated by the !define MUI_CUSTOMFUNCTION_ABORT:
Use the normal call that I described on the top of this page on the function indicated by the !define MUI_CUSTOMFUNCTION_ABORT:


<highlight-nsis>!insert "MUI.nsh" ;Required by MUI
<highlight-nsis>
!insert "MUI.nsh" ;Required by MUI


!define MUI_CUSTOMFUNCTION_ABORT "FunctionName"
!define MUI_CUSTOMFUNCTION_ABORT "FunctionName"
Line 100: Line 105:
   Call RelGotoPage
   Call RelGotoPage
   Abort
   Abort
FunctionEnd</highlight-nsis>
FunctionEnd
</highlight-nsis>


=== For One Page ===
=== For One Page ===
Line 108: Line 114:
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:
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:


<highlight-nsis>Page custom CustomPage
<highlight-nsis>
Page custom CustomPage
Page components Components_PreFunction
Page components Components_PreFunction
Page directory Directory_PreFunction
Page directory Directory_PreFunction
Line 133: Line 140:
     Abort
     Abort
   End:
   End:
FunctionEnd</highlight-nsis>
FunctionEnd
</highlight-nsis>


==== Modern UI ====
==== Modern UI ====
Line 139: Line 147:
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:
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:


<highlight-nsis>!include "MUI.nsh" ;Required by MUI
<highlight-nsis>
!include "MUI.nsh" ;Required by MUI


Page custom CustomPage
Page custom CustomPage
Line 171: Line 180:
     Abort
     Abort
   End:
   End:
FunctionEnd</highlight-nsis>
FunctionEnd
</highlight-nsis>
 
[[Category:User Interface Functions]]

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