nsDialogs::OnNotify can now return values back to Windows, also fixes bug #1216
git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@7054 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
4f695dbd30
commit
a523c05626
6 changed files with 54 additions and 18 deletions
|
@ -500,7 +500,7 @@ SectionEnd</pre></blockquote>
|
|||
|
||||
<h3><a name="ref-onnotify"></a>OnNotify</h3>
|
||||
<p><code>nsDialogs::OnNotify <i>control_HWND</i> <i>function_address</i></code></p>
|
||||
<p>Sets a notification callback function for the given control. Whenever the control receives the WM_NOTIFY message, the function will be called and the control's HWND, notification code and a pointer to the NMHDR structure will be waiting on its stack.</p>
|
||||
<p>Sets a notification callback function for the given control. Whenever the control receives the WM_NOTIFY message, the function will be called and the control's HWND, notification code and a pointer to the NMHDR structure will be waiting on its stack. Use ${NSD_Return} to return a value.</p>
|
||||
<p>Use GetFunctionAddress to get the address of the desired callback function.</p>
|
||||
<p>Returns nothing.</p>
|
||||
|
||||
|
@ -559,8 +559,6 @@ SectionEnd</pre></blockquote>
|
|||
<p><code>${NSD_OnBack} <i>function_name</i></code></p>
|
||||
<p>See <a href="#ref-onback">OnBack</a> for more details.</p>
|
||||
|
||||
<p></p>
|
||||
|
||||
<h3><a name="mref-onchange"></a>NSD_OnChange</h3>
|
||||
<p><code>${NSD_OnChange} <i>control_HWND</i> <i>function_name</i></code></p>
|
||||
<p>See <a href="#ref-onchange">OnChange</a> for more details.</p>
|
||||
|
@ -574,6 +572,10 @@ SectionEnd</pre></blockquote>
|
|||
<p><code>${NSD_OnNotify} <i>control_HWND</i> <i>function_name</i></code></p>
|
||||
<p>See <a href="#ref-onnotify">OnNotify</a> for more details.</p>
|
||||
|
||||
<h3><a name="mref-return"></a>NSD_Return</h3>
|
||||
<p><code>${NSD_Return} <i>value</i></code></p>
|
||||
<p>Used to return a value back to Windows from a OnNotify callback.</p>
|
||||
|
||||
<h3><a name="mref-setfocus"></a>NSD_SetFocus</h3>
|
||||
<p><code>${NSD_SetFocus} <i>control_HWND</i></code></p>
|
||||
<p>Sets focus to a control.</p>
|
||||
|
|
|
@ -5,7 +5,11 @@
|
|||
|
||||
#include <windows.h>
|
||||
|
||||
#define NSDFUNC __stdcall
|
||||
#define NSDFUNC WINAPI
|
||||
|
||||
#define DlgRet(hDlg, val) ( SetWindowLongPtr((hDlg), DWLP_MSGRESULT, (val)) | TRUE )
|
||||
#define StrToIntPtr nsishelper_str_to_ptr
|
||||
|
||||
|
||||
typedef int nsFunction;
|
||||
|
||||
|
|
|
@ -178,9 +178,10 @@ Function NotifyPage
|
|||
${NSD_CreateRichEdit} 1 1 -2 -2 ""
|
||||
Pop $9
|
||||
${NSD_OnNotify} $9 OnNotify
|
||||
${NSD_RichEd_SetEventMask} $9 ${ENM_LINK}
|
||||
IntOp $8 ${ENM_LINK} | ${ENM_KEYEVENTS}
|
||||
${NSD_RichEd_SetEventMask} $9 $8
|
||||
SendMessage $9 ${EM_AUTOURLDETECT} 1 0
|
||||
${NSD_SetText} $9 "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard http://nsis.sf.net\par {\b Click the link}...} "
|
||||
${NSD_SetText} $9 "{\rtf1\ansi{\fonttbl\f0\fswiss Helvetica;}\f0\pard http://nsis.sf.net\par {\b Click the link!}\par\par Type something and I will block every other character...}"
|
||||
|
||||
nsDialogs::Show
|
||||
FunctionEnd
|
||||
|
@ -189,19 +190,29 @@ Function OnNotify
|
|||
Pop $1 ; HWND
|
||||
Pop $2 ; Code
|
||||
Pop $3 ; NMHDR*
|
||||
${IfThen} $2 <> ${EN_LINK} ${|} Return ${|}
|
||||
System::Call '*$3(p,p,p,p.r2,p,p,i.r4,i.r5)' ; Extract from ENLINK*
|
||||
${IfThen} $2 <> ${WM_LBUTTONDOWN} ${|} Return ${|}
|
||||
IntOp $2 $5 - $4
|
||||
System::Call '*(ir4,ir5,l,&t$2,i)p.r2' ; Create TEXTRANGE and a text buffer
|
||||
${If} $2 P<> 0
|
||||
IntPtrOp $3 $2 + 16 ; Find buffer
|
||||
System::Call '*$2(i,i,p$3)' ; Set buffer in TEXTRANGE
|
||||
SendMessage $1 ${EM_GETTEXTRANGE} "" $2 $4
|
||||
${If} $4 <> 0
|
||||
System::Call 'SHELL32::ShellExecute(p$hWndParent, p0, pr3, p0, p0, i 1)'
|
||||
${If} $2 = ${EN_LINK}
|
||||
System::Call '*$3(p,p,p,p.r2,p,p,i.r4,i.r5)' ; Extract from ENLINK*
|
||||
${IfThen} $2 <> ${WM_LBUTTONDOWN} ${|} Return ${|}
|
||||
IntOp $2 $5 - $4
|
||||
System::Call '*(ir4,ir5,l,&t$2,i)p.r2' ; Create TEXTRANGE and a text buffer
|
||||
${If} $2 P<> 0
|
||||
IntPtrOp $3 $2 + 16 ; Find buffer
|
||||
System::Call '*$2(i,i,p$3)' ; Set buffer in TEXTRANGE
|
||||
SendMessage $1 ${EM_GETTEXTRANGE} "" $2 $4
|
||||
${If} $4 <> 0
|
||||
System::Call 'SHELL32::ShellExecute(p$hWndParent, p0, pr3, p0, p0, i 1)'
|
||||
${EndIf}
|
||||
System::Free $2
|
||||
${EndIf}
|
||||
${ElseIf} $2 = ${EN_MSGFILTER}
|
||||
Var /Global Toggle
|
||||
System::Call '*$3(p,i,i,i.r4)' ; MSGFILTER->msg
|
||||
${If} $4 = ${WM_CHAR}
|
||||
IntOp $Toggle $Toggle ^ 1
|
||||
${If} $Toggle & 1
|
||||
${NSD_Return} 1
|
||||
${EndIf}
|
||||
${EndIf}
|
||||
System::Free $2
|
||||
${EndIf}
|
||||
FunctionEnd
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
HINSTANCE g_hInstance;
|
||||
struct nsDialog g_dialog;
|
||||
extra_parameters* g_pluginParms;
|
||||
LPTSTR g_var0;
|
||||
|
||||
static COLORREF GetLinkColor()
|
||||
{
|
||||
|
@ -149,6 +150,7 @@ INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
|
|||
{
|
||||
LPNMHDR nmhdr = (LPNMHDR) lParam;
|
||||
struct nsControl* ctl = GetControl(nmhdr->hwndFrom);
|
||||
int *pFlag = &g_pluginParms->exec_flags->silent, orgFlag, ret; // The silent flag can only be changed in .onInit and custom pages will not be displayed in silent mode so we can use this flag in the callback
|
||||
|
||||
if (ctl == NULL)
|
||||
break;
|
||||
|
@ -156,11 +158,16 @@ INT_PTR CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPara
|
|||
if (!ctl->callbacks.onNotify)
|
||||
break;
|
||||
|
||||
orgFlag = *pFlag, *pFlag = 0;
|
||||
pushintptr((INT_PTR) nmhdr);
|
||||
pushintptr(nmhdr->code);
|
||||
pushintptr((INT_PTR) nmhdr->hwndFrom);
|
||||
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onNotify - 1, 0);
|
||||
ret = *pFlag, *pFlag = orgFlag;
|
||||
if (ret)
|
||||
return DlgRet(hwndDlg, StrToIntPtr(g_var0));
|
||||
}
|
||||
break;
|
||||
|
||||
// handle links
|
||||
case WM_DRAWITEM:
|
||||
|
@ -266,6 +273,7 @@ void __declspec(dllexport) Create(HWND hwndParent, int string_size, TCHAR *varia
|
|||
|
||||
g_dialog.hwParent = hwndParent;
|
||||
g_pluginParms = extra;
|
||||
g_var0 = variables;
|
||||
|
||||
hwPlacementRect = GetDlgItem(hwndParent, popint());
|
||||
GetWindowRect(hwPlacementRect, &rcPlacement);
|
||||
|
|
|
@ -413,6 +413,15 @@ Header file for creating custom installer pages with nsDialogs
|
|||
!insertmacro __NSD_DefineControlCallback Notify
|
||||
!insertmacro __NSD_DefineDialogCallback Back
|
||||
|
||||
!define NSD_Return "!insertmacro NSD_Return "
|
||||
!macro NSD_Return val
|
||||
!if "${val}" != "$0"
|
||||
StrCpy $0 ${val}
|
||||
!endif
|
||||
SetSilent silent
|
||||
Return
|
||||
!macroend
|
||||
|
||||
|
||||
!define __NSD_MkCtlCmd "!insertmacro __NSD_MkCtlCmd "
|
||||
!macro __NSD_MkCtlCmd msg wp lp hCtl
|
||||
|
|
|
@ -16,6 +16,8 @@ Released on ??? ??th, 20??
|
|||
|
||||
\b Added MUI_TEXTCOLOR setting
|
||||
|
||||
\b nsDialogs::OnNotify can now return values back to Windows
|
||||
|
||||
\b Added LIBRARY_INSTALL_EQUAL_VERSION \R{library_install}{InstallLib} option
|
||||
|
||||
\b Added NTMARTA to preload list to fix rare Windows 7 security issue (\W{http://sf.net/p/nsis/bugs/1204}{bug #1204})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue