nsDialogs: the next InstallOptions

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5199 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
kichik 2007-07-14 09:40:06 +00:00
parent edd3c299f7
commit 74bf17be17
15 changed files with 1832 additions and 0 deletions

View file

@ -0,0 +1,28 @@
!include LogicLib.nsh
!include WinMessages.nsh
Name "nsDialogs IO"
OutFile "nsDialogs IO.exe"
Page custom nsDialogsIO
Page instfiles
XPStyle on
ShowInstDetails show
!include nsDialogs.nsh
Function nsDialogsIO
InitPluginsDir
File /oname=$PLUGINSDIR\io.ini "${NSISDIR}\Examples\InstallOptions\test.ini"
StrCpy $0 $PLUGINSDIR\io.ini
Call CreateDialogFromINI
FunctionEnd
Section
SectionEnd

View file

@ -0,0 +1,36 @@
target = 'nsDialogs'
files = Split("""
browse.c
input.c
nsDialogs.c
nsis.c
""")
resources = Split("""
dialog.rc
""")
libs = Split("""
kernel32
user32
gdi32
shell32
comdlg32
ole32
""")
examples = Split("""
example.nsi
InstallOptions.nsi
welcome.nsi
""")
includes = Split("""
nsDialogs.nsh
""")
Import('BuildPlugin env')
BuildPlugin(target, files, libs, examples, res = resources)
env.DistributeInclude(includes)

153
Contrib/nsDialogs/browse.c Normal file
View file

@ -0,0 +1,153 @@
#include <windows.h>
#include <shlobj.h>
#include "defs.h"
#include "nsis.h"
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) {
if (uMsg == BFFM_INITIALIZED)
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
return 0;
}
void __declspec(dllexport) SelectFolderDialog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
BROWSEINFO bi;
char result[MAX_PATH];
char initial[MAX_PATH];
char title[1024];
LPITEMIDLIST resultPIDL;
EXDLL_INIT();
if (popstring(title, sizeof(initial)))
{
pushstring("error");
return;
}
if (popstring(initial, sizeof(title)))
{
pushstring("error");
return;
}
bi.hwndOwner = hwndParent;
bi.pidlRoot = NULL;
bi.pszDisplayName = result;
bi.lpszTitle = title;
#ifndef BIF_NEWDIALOGSTYLE
#define BIF_NEWDIALOGSTYLE 0x0040
#endif
bi.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
bi.lpfn = BrowseCallbackProc;
bi.lParam = (LPARAM) initial;
bi.iImage = 0;
/*if (pField->pszRoot) {
LPSHELLFOLDER sf;
ULONG eaten;
LPITEMIDLIST root;
int ccRoot = (lstrlen(pField->pszRoot) * 2) + 2;
LPWSTR pwszRoot = (LPWSTR) MALLOC(ccRoot);
MultiByteToWideChar(CP_ACP, 0, pField->pszRoot, -1, pwszRoot, ccRoot);
SHGetDesktopFolder(&sf);
sf->ParseDisplayName(hConfigWindow, NULL, pwszRoot, &eaten, &root, NULL);
bi.pidlRoot = root;
sf->Release();
FREE(pwszRoot);
}*/
resultPIDL = SHBrowseForFolder(&bi);
if (!resultPIDL)
{
pushstring("error");
return;
}
if (SHGetPathFromIDList(resultPIDL, result))
{
pushstring(result);
}
else
{
pushstring("error");
}
CoTaskMemFree(resultPIDL);
}
void __declspec(dllexport) SelectFileDialog(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
OPENFILENAME ofn={0,}; // XXX WTF
int save;
char type[5];
char path[1024];
char filter[1024];
char currentDirectory[1024];
EXDLL_INIT();
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = hwndParent;
ofn.lpstrFilter = filter;
ofn.lpstrFile = path;
ofn.nMaxFile = sizeof(path);
//ofn.Flags = pField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER);
ofn.Flags = OFN_CREATEPROMPT | OFN_EXPLORER;
popstring(type, sizeof(type));
popstring(path, sizeof(path));
popstring(filter, sizeof(filter));
save = !lstrcmpi(type, "save");
if (!filter[0])
{
lstrcpy(filter, "All Files|*.*");
}
{
// Convert the filter to the format required by Windows: NULL after each
// item followed by a terminating NULL
char *p = filter;
while (*p) // XXX take care for 1024
{
if (*p == '|')
{
*p++ = 0;
}
else
{
p = CharNext(p);
}
}
p++;
*p = 0;
}
GetCurrentDirectory(sizeof(currentDirectory), currentDirectory); // save working dir
if ((save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn)))
{
pushstring(path);
}
else if (CommDlgExtendedError() == FNERR_INVALIDFILENAME)
{
*path = '\0';
if ((save ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn)))
{
pushstring(path);
}
else
{
pushstring("");
}
}
// restore working dir
// OFN_NOCHANGEDIR doesn't always work (see MSDN)
SetCurrentDirectory(currentDirectory);
}

64
Contrib/nsDialogs/defs.h Normal file
View file

@ -0,0 +1,64 @@
#ifndef __NS_DIALOGS__DEFS_H__
#define __NS_DIALOGS__DEFS_H__
#include <windows.h>
#define NSDFUNC __stdcall
typedef int nsFunction;
enum nsControlType
{
NSCTL_UNKNOWN,
NSCTL_BUTTON,
NSCTL_EDIT,
NSCTL_COMBOBOX,
NSCTL_LISTBOX,
NSCTL_RICHEDIT,
NSCTL_RICHEDIT2,
NSCTL_STATIC
};
struct nsDialogCallbacks
{
nsFunction onBack;
};
#define DLG_CALLBACK_IDX(x) (FIELD_OFFSET(struct nsDialogCallbacks, x)/sizeof(nsFunction))
struct nsControlCallbacks
{
nsFunction onClick;
nsFunction onChange;
nsFunction onNotify;
};
#define CTL_CALLBACK_IDX(x) (FIELD_OFFSET(struct nsControlCallbacks, x)/sizeof(nsFunction))
#define USERDATA_SIZE 1024
struct nsControl
{
HWND window;
enum nsControlType type;
char userData[USERDATA_SIZE];
struct nsControlCallbacks callbacks;
};
struct nsDialog
{
HWND hwDialog;
HWND hwParent;
WNDPROC parentOriginalWndproc;
struct nsDialogCallbacks callbacks;
unsigned controlCount;
struct nsControl* controls;
};
#define NSCONTROL_ID_PROP "NSIS: nsControl pointer property"
#endif//__NS_DIALOGS__DEFS_H__

View file

@ -0,0 +1,91 @@
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <winresrc.h>
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
1 DIALOG DISCARDABLE 0, 0, 57, 41
STYLE DS_FIXEDSYS | DS_CONTROL | WS_CHILD
FONT 8, "MS Shell Dlg"
BEGIN
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_DIALOG1, DIALOG
STYLE DS_CONTROL | WS_CHILD
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 50
TOPMARGIN, 7
BOTTOMMARGIN, 34
END
END
#endif // APSTUDIO_INVOKED
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED

View file

@ -0,0 +1,76 @@
!include nsDialogs.nsh
!include LogicLib.nsh
Name "nsDialogs Example"
OutFile "nsDialogs Example.exe"
XPStyle on
Page license
Page custom nsDialogsPage
Var BUTTON
Var EDIT
Var CHECKBOX
Function nsDialogsPage
nsDialogs::Create /NOUNLOAD 1018
Pop $0
GetFunctionAddress $0 OnBack
nsDialogs::OnBack /NOUNLOAD $0
${NSD_CreateButton} 0 0 100% 12u Test
Pop $BUTTON
GetFunctionAddress $0 OnClick
nsDialogs::OnClick /NOUNLOAD $BUTTON $0
${NSD_CreateText} 0 35 100% 12u hello
Pop $EDIT
GetFunctionAddress $0 OnChange
nsDialogs::OnChange /NOUNLOAD $EDIT $0
${NSD_CreateCheckbox} 0 -50 100% 8u Test
Pop $CHECKBOX
GetFunctionAddress $0 OnCheckbox
nsDialogs::OnClick /NOUNLOAD $CHECKBOX $0
${NSD_CreateLabel} 0 40u 75% 40u "* Type `hello there` above.$\n* Click the button.$\n* Check the checkbox.$\n* Hit the Back button."
Pop $0
nsDialogs::Show
FunctionEnd
Function OnClick
MessageBox MB_OK clicky
FunctionEnd
Function OnChange
System::Call user32::GetWindowText(i$EDIT,t.r0,i${NSIS_MAX_STRLEN})
${If} $0 == "hello there"
MessageBox MB_OK "right back at ya"
${EndIf}
FunctionEnd
Function OnBack
MessageBox MB_YESNO "are you sure?" IDYES +2
Abort
FunctionEnd
Function OnCheckbox
MessageBox MB_OK "checkbox clicked"
FunctionEnd
Section
SectionEnd

77
Contrib/nsDialogs/input.c Normal file
View file

@ -0,0 +1,77 @@
#include <windows.h>
#include "input.h"
#include "defs.h"
#include "nsis.h"
extern struct nsDialog g_dialog;
static int NSDFUNC ConvertPlacement(char *str, int total, int height)
{
char unit = *CharPrev(str, str + lstrlen(str));
int x = myatoi(str);
if (unit == '%')
{
if (x < 0)
{
return MulDiv(total, 100 + x, 100);
}
return MulDiv(total, x, 100);
}
else if (unit == 'u')
{
RECT r;
r.left = r.top = x;
MapDialogRect(g_dialog.hwParent, &r);
if (height)
return x >= 0 ? r.top : total + r.top;
else
return x >= 0 ? r.left : total + r.left;
}
if (x < 0)
{
return total + x;
}
return x;
}
int NSDFUNC PopPlacement(int *x, int *y, int *width, int *height)
{
RECT dialogRect;
int dialogWidth;
int dialogHeight;
char buf[1024];
GetClientRect(g_dialog.hwDialog, &dialogRect);
dialogWidth = dialogRect.right;
dialogHeight = dialogRect.bottom;
if (popstring(buf, 1024))
return 1;
*x = ConvertPlacement(buf, dialogWidth, 0);
if (popstring(buf, 1024))
return 1;
*y = ConvertPlacement(buf, dialogHeight, 1);
if (popstring(buf, 1024))
return 1;
*width = ConvertPlacement(buf, dialogWidth, 0);
if (popstring(buf, 1024))
return 1;
*height = ConvertPlacement(buf, dialogHeight, 1);
return 0;
}

View file

@ -0,0 +1,8 @@
#ifndef __NS_DIALOGS__INPUT_H__
#define __NS_DIALOGS__INPUT_H__
#include "defs.h"
int NSDFUNC PopPlacement(int *x, int *y, int *width, int *height);
#endif//__NS_DIALOGS__INPUT_H__

View file

@ -0,0 +1,396 @@
#include <windows.h>
#include "defs.h"
#include "nsis.h"
#include "input.h"
HINSTANCE g_hInstance;
struct nsDialog g_dialog;
extra_parameters* g_pluginParms;
struct nsControl* NSDFUNC GetControl(HWND hwCtl)
{
unsigned id = (unsigned) GetProp(hwCtl, NSCONTROL_ID_PROP);
if (id == 0 || id > g_dialog.controlCount)
{
return NULL;
}
return &g_dialog.controls[id - 1];
}
BOOL CALLBACK ParentProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
BOOL res;
if (message == WM_NOTIFY_OUTER_NEXT)
{
if (wParam == (WPARAM)-1)
{
if (g_pluginParms->ExecuteCodeSegment(g_dialog.callbacks.onBack - 1, 0))
{
return 0;
}
}
}
res = CallWindowProc(g_dialog.parentOriginalWndproc, hwnd, message, wParam, lParam);
if (message == WM_NOTIFY_OUTER_NEXT && !res)
{
DestroyWindow(g_dialog.hwDialog);
HeapFree(GetProcessHeap(), 0, g_dialog.controls);
g_dialog.hwDialog = NULL;
g_dialog.controls = NULL;
}
return res;
}
BOOL CALLBACK DialogProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
// handle notifications
case WM_COMMAND:
{
HWND hwCtl = GetDlgItem(hwndDlg, LOWORD(wParam));
struct nsControl* ctl = GetControl(hwCtl);
if (ctl == NULL)
break;
if (HIWORD(wParam) == BN_CLICKED && ctl->type == NSCTL_BUTTON)
{
pushint((int) hwCtl);
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onClick - 1, 0);
}
else if (HIWORD(wParam) == EN_CHANGE && ctl->type == NSCTL_EDIT)
{
pushint((int) hwCtl);
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0);
}
else if (HIWORD(wParam) == LBN_SELCHANGE && ctl->type == NSCTL_LISTBOX)
{
pushint((int) hwCtl);
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0);
}
else if (HIWORD(wParam) == CBN_SELCHANGE && ctl->type == NSCTL_COMBOBOX)
{
pushint((int) hwCtl);
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onChange - 1, 0);
}
break;
}
case WM_NOTIFY:
{
LPNMHDR nmhdr = (LPNMHDR) lParam;
struct nsControl* ctl = GetControl(nmhdr->hwndFrom);
if (ctl == NULL)
break;
if (!ctl->callbacks.onNotify)
break;
pushint((int) nmhdr);
pushint(nmhdr->code);
pushint((int) nmhdr->hwndFrom);
g_pluginParms->ExecuteCodeSegment(ctl->callbacks.onNotify - 1, 0);
}
// handle colors
case WM_CTLCOLORSTATIC:
case WM_CTLCOLOREDIT:
case WM_CTLCOLORDLG:
case WM_CTLCOLORBTN:
case WM_CTLCOLORLISTBOX:
// let the NSIS window handle colors, it knows best
return SendMessage(g_dialog.hwParent, uMsg, wParam, lParam);
}
return FALSE;
}
void __declspec(dllexport) Create(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
HWND hwPlacementRect;
RECT rcPlacement;
EXDLL_INIT();
g_dialog.hwParent = hwndParent;
g_pluginParms = extra;
hwPlacementRect = GetDlgItem(hwndParent, popint());
GetWindowRect(hwPlacementRect, &rcPlacement);
MapWindowPoints(NULL, hwndParent, (LPPOINT) &rcPlacement, 2);
g_dialog.hwDialog = CreateDialog(g_hInstance, MAKEINTRESOURCE(1), hwndParent, DialogProc);
SetWindowPos(
g_dialog.hwDialog,
0,
rcPlacement.left,
rcPlacement.top,
rcPlacement.right - rcPlacement.left,
rcPlacement.bottom - rcPlacement.top,
SWP_NOZORDER | SWP_NOACTIVATE
);
g_dialog.parentOriginalWndproc = (WNDPROC) SetWindowLong(hwndParent, DWL_DLGPROC, (long) ParentProc);
g_dialog.controlCount = 0;
g_dialog.controls = (struct nsControl*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 0);
pushint((int) g_dialog.hwDialog);
}
void __declspec(dllexport) CreateItem(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
char *className;
char *text;
HWND hwItem;
int x, y, width, height;
DWORD style, exStyle;
size_t id;
// get info from stack
className = (char *) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, g_stringsize * 2);
text = &className[g_stringsize];
if (!className)
return;
if (popstring(className, 0))
{
HeapFree(GetProcessHeap(), 0, className);
return;
}
style = (DWORD) popint();
exStyle = (DWORD) popint();
PopPlacement(&x, &y, &width, &height);
if (popstring(text, 0))
{
HeapFree(GetProcessHeap(), 0, className);
return;
}
// create item descriptor
id = g_dialog.controlCount;
g_dialog.controlCount++;
g_dialog.controls = (struct nsControl*) HeapReAlloc(
GetProcessHeap(),
HEAP_ZERO_MEMORY,
g_dialog.controls,
g_dialog.controlCount * sizeof(struct nsControl));
if (!lstrcmpi(className, "BUTTON"))
g_dialog.controls[id].type = NSCTL_BUTTON;
else if (!lstrcmpi(className, "EDIT"))
g_dialog.controls[id].type = NSCTL_EDIT;
else if (!lstrcmpi(className, "COMBOBOX"))
g_dialog.controls[id].type = NSCTL_COMBOBOX;
else if (!lstrcmpi(className, "LISTBOX"))
g_dialog.controls[id].type = NSCTL_LISTBOX;
else if (!lstrcmpi(className, "RichEdit"))
g_dialog.controls[id].type = NSCTL_RICHEDIT;
else if (!lstrcmpi(className, "RICHEDIT_CLASS"))
g_dialog.controls[id].type = NSCTL_RICHEDIT2;
else if (!lstrcmpi(className, "STATIC"))
g_dialog.controls[id].type = NSCTL_STATIC;
else
g_dialog.controls[id].type = NSCTL_UNKNOWN;
// create item's window
hwItem = CreateWindowEx(
exStyle,
className,
text,
style,
x, y, width, height,
g_dialog.hwDialog,
(HMENU) (1200 + id),
g_hInstance,
NULL);
g_dialog.controls[id].window = hwItem;
// remember id
SetProp(hwItem, NSCONTROL_ID_PROP, (HANDLE) (id + 1));
// set font
SendMessage(hwItem, WM_SETFONT, SendMessage(g_dialog.hwParent, WM_GETFONT, 0, 0), TRUE);
// push back result
pushint((int) hwItem);
// done
HeapFree(GetProcessHeap(), 0, className);
}
void __declspec(dllexport) SetUserData(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
HWND hwCtl;
struct nsControl* ctl;
// get info from stack
hwCtl = (HWND) popint();
if (!IsWindow(hwCtl))
{
popint(); // remove user data from stack
return;
}
// get descriptor
ctl = GetControl(hwCtl);
if (ctl == NULL)
return;
// set user data
popstring(ctl->userData, USERDATA_SIZE);
}
void __declspec(dllexport) GetUserData(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
HWND hwCtl;
struct nsControl* ctl;
// get info from stack
hwCtl = (HWND) popint();
if (!IsWindow(hwCtl))
{
pushstring("");
return;
}
// get descriptor
ctl = GetControl(hwCtl);
if (ctl == NULL)
{
pushstring("");
return;
}
// return user data
pushstring(ctl->userData);
}
void NSDFUNC SetControlCallback(size_t callbackIdx)
{
HWND hwCtl;
nsFunction callback;
nsFunction* callbacks;
struct nsControl* ctl;
// get info from stack
hwCtl = (HWND) popint();
callback = (nsFunction) popint();
if (!IsWindow(hwCtl))
return;
// get descriptor
ctl = GetControl(hwCtl);
if (ctl == NULL)
return;
// set callback
callbacks = (nsFunction*) &ctl->callbacks;
callbacks[callbackIdx] = callback;
}
void NSDFUNC SetDialogCallback(size_t callbackIdx)
{
nsFunction callback;
nsFunction* callbacks;
// get info from stack
callback = (nsFunction) popint();
// set callback
callbacks = (nsFunction*) &g_dialog.callbacks;
callbacks[callbackIdx] = callback;
}
void __declspec(dllexport) OnClick(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
SetControlCallback(CTL_CALLBACK_IDX(onClick));
}
void __declspec(dllexport) OnChange(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
SetControlCallback(CTL_CALLBACK_IDX(onChange));
}
void __declspec(dllexport) OnNotify(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
SetControlCallback(CTL_CALLBACK_IDX(onNotify));
}
void __declspec(dllexport) OnBack(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
SetDialogCallback(DLG_CALLBACK_IDX(onBack));
}
void __declspec(dllexport) Show(HWND hwndParent, int string_size, char *variables, stack_t **stacktop, extra_parameters *extra)
{
// tell NSIS to remove old inner dialog and pass handle of the new inner dialog
SendMessage(hwndParent, WM_NOTIFY_CUSTOM_READY, (WPARAM) g_dialog.hwDialog, 0);
ShowWindow(g_dialog.hwDialog, SW_SHOWNA);
// message loop
while (g_dialog.hwDialog)
{
MSG msg;
GetMessage(&msg, NULL, 0, 0);
if (!IsDialogMessage(g_dialog.hwDialog, &msg) && !IsDialogMessage(g_dialog.hwParent, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// reset wndproc
SetWindowLong(hwndParent, DWL_DLGPROC, (long) g_dialog.parentOriginalWndproc);
}
BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
{
g_hInstance = (HINSTANCE) hInst;
return TRUE;
}

View file

@ -0,0 +1,413 @@
!include LogicLib.nsh
!include WinMessages.nsh
!define WS_EX_DLGMODALFRAME 0x00000001
!define WS_EX_NOPARENTNOTIFY 0x00000004
!define WS_EX_TOPMOST 0x00000008
!define WS_EX_ACCEPTFILES 0x00000010
!define WS_EX_TRANSPARENT 0x00000020
!define WS_EX_MDICHILD 0x00000040
!define WS_EX_TOOLWINDOW 0x00000080
!define WS_EX_WINDOWEDGE 0x00000100
!define WS_EX_CLIENTEDGE 0x00000200
!define WS_EX_CONTEXTHELP 0x00000400
!define WS_EX_RIGHT 0x00001000
!define WS_EX_LEFT 0x00000000
!define WS_EX_RTLREADING 0x00002000
!define WS_EX_LTRREADING 0x00000000
!define WS_EX_LEFTSCROLLBAR 0x00004000
!define WS_EX_RIGHTSCROLLBAR 0x00000000
!define WS_EX_CONTROLPARENT 0x00010000
!define WS_EX_STATICEDGE 0x00020000
!define WS_EX_APPWINDOW 0x00040000
!define WS_CHILD 0x40000000
!define WS_VISIBLE 0x10000000
!define WS_DISABLED 0x08000000
!define WS_CLIPSIBLINGS 0x04000000
!define WS_CLIPCHILDREN 0x02000000
!define WS_MAXIMIZE 0x01000000
!define WS_VSCROLL 0x00200000
!define WS_HSCROLL 0x00100000
!define WS_GROUP 0x00020000
!define WS_TABSTOP 0x00010000
!define ES_LEFT 0x00000000
!define ES_CENTER 0x00000001
!define ES_RIGHT 0x00000002
!define ES_MULTILINE 0x00000004
!define ES_UPPERCASE 0x00000008
!define ES_LOWERCASE 0x00000010
!define ES_PASSWORD 0x00000020
!define ES_AUTOVSCROLL 0x00000040
!define ES_AUTOHSCROLL 0x00000080
!define ES_NOHIDESEL 0x00000100
!define ES_OEMCONVERT 0x00000400
!define ES_READONLY 0x00000800
!define ES_WANTRETURN 0x00001000
!define ES_NUMBER 0x00002000
!define SS_LEFT 0x00000000
!define SS_CENTER 0x00000001
!define SS_RIGHT 0x00000002
!define SS_ICON 0x00000003
!define SS_BLACKRECT 0x00000004
!define SS_GRAYRECT 0x00000005
!define SS_WHITERECT 0x00000006
!define SS_BLACKFRAME 0x00000007
!define SS_GRAYFRAME 0x00000008
!define SS_WHITEFRAME 0x00000009
!define SS_USERITEM 0x0000000A
!define SS_SIMPLE 0x0000000B
!define SS_LEFTNOWORDWRAP 0x0000000C
!define SS_OWNERDRAW 0x0000000D
!define SS_BITMAP 0x0000000E
!define SS_ENHMETAFILE 0x0000000F
!define SS_ETCHEDHORZ 0x00000010
!define SS_ETCHEDVERT 0x00000011
!define SS_ETCHEDFRAME 0x00000012
!define SS_TYPEMASK 0x0000001F
!define SS_REALSIZECONTROL 0x00000040
!define SS_NOPREFIX 0x00000080
!define SS_NOTIFY 0x00000100
!define SS_CENTERIMAGE 0x00000200
!define SS_RIGHTJUST 0x00000400
!define SS_REALSIZEIMAGE 0x00000800
!define SS_SUNKEN 0x00001000
!define SS_EDITCONTROL 0x00002000
!define SS_ENDELLIPSIS 0x00004000
!define SS_PATHELLIPSIS 0x00008000
!define SS_WORDELLIPSIS 0x0000C000
!define SS_ELLIPSISMASK 0x0000C000
!define BS_PUSHBUTTON 0x00000000
!define BS_DEFPUSHBUTTON 0x00000001
!define BS_CHECKBOX 0x00000002
!define BS_AUTOCHECKBOX 0x00000003
!define BS_RADIOBUTTON 0x00000004
!define BS_3STATE 0x00000005
!define BS_AUTO3STATE 0x00000006
!define BS_GROUPBOX 0x00000007
!define BS_USERBUTTON 0x00000008
!define BS_AUTORADIOBUTTON 0x00000009
!define BS_PUSHBOX 0x0000000A
!define BS_OWNERDRAW 0x0000000B
!define BS_TYPEMASK 0x0000000F
!define BS_LEFTTEXT 0x00000020
!define BS_TEXT 0x00000000
!define BS_ICON 0x00000040
!define BS_BITMAP 0x00000080
!define BS_LEFT 0x00000100
!define BS_RIGHT 0x00000200
!define BS_CENTER 0x00000300
!define BS_TOP 0x00000400
!define BS_BOTTOM 0x00000800
!define BS_VCENTER 0x00000C00
!define BS_PUSHLIKE 0x00001000
!define BS_MULTILINE 0x00002000
!define BS_NOTIFY 0x00004000
!define BS_FLAT 0x00008000
!define BS_RIGHTBUTTON ${BS_LEFTTEXT}
!define CBS_SIMPLE 0x0001
!define CBS_DROPDOWN 0x0002
!define CBS_DROPDOWNLIST 0x0003
!define CBS_OWNERDRAWFIXED 0x0010
!define CBS_OWNERDRAWVARIABLE 0x0020
!define CBS_AUTOHSCROLL 0x0040
!define CBS_OEMCONVERT 0x0080
!define CBS_SORT 0x0100
!define CBS_HASSTRINGS 0x0200
!define CBS_NOINTEGRALHEIGHT 0x0400
!define CBS_DISABLENOSCROLL 0x0800
!define CBS_UPPERCASE 0x2000
!define CBS_LOWERCASE 0x4000
!define LBS_NOTIFY 0x0001
!define LBS_SORT 0x0002
!define LBS_NOREDRAW 0x0004
!define LBS_MULTIPLESEL 0x0008
!define LBS_OWNERDRAWFIXED 0x0010
!define LBS_OWNERDRAWVARIABLE 0x0020
!define LBS_HASSTRINGS 0x0040
!define LBS_USETABSTOPS 0x0080
!define LBS_NOINTEGRALHEIGHT 0x0100
!define LBS_MULTICOLUMN 0x0200
!define LBS_WANTKEYBOARDINPUT 0x0400
!define LBS_EXTENDEDSEL 0x0800
!define LBS_DISABLENOSCROLL 0x1000
!define LBS_NODATA 0x2000
!define LBS_NOSEL 0x4000
!define LBS_COMBOBOX 0x8000
!define LR_DEFAULTCOLOR 0x0000
!define LR_MONOCHROME 0x0001
!define LR_COLOR 0x0002
!define LR_COPYRETURNORG 0x0004
!define LR_COPYDELETEORG 0x0008
!define LR_LOADFROMFILE 0x0010
!define LR_LOADTRANSPARENT 0x0020
!define LR_DEFAULTSIZE 0x0040
!define LR_VGACOLOR 0x0080
!define LR_LOADMAP3DCOLORS 0x1000
!define LR_CREATEDIBSECTION 0x2000
!define LR_COPYFROMRESOURCE 0x4000
!define LR_SHARED 0x8000
!define IMAGE_BITMAP 0
!define IMAGE_ICON 1
!define IMAGE_CURSOR 2
!define IMAGE_ENHMETAFILE 3
!define DEFAULT_STYLES ${WS_CHILD}|${WS_VISIBLE}|${WS_CLIPSIBLINGS}
!define __NSD_HLine_CLASS STATIC
!define __NSD_HLine_STYLE ${DEFAULT_STYLES}|${SS_ETCHEDHORZ}|${SS_SUNKEN}
!define __NSD_HLine_EXSTYLE ${WS_EX_TRANSPARENT}
!define __NSD_VLine_CLASS STATIC
!define __NSD_VLine_STYLE ${DEFAULT_STYLES}|${SS_ETCHEDVERT}|${SS_SUNKEN}
!define __NSD_VLine_EXSTYLE ${WS_EX_TRANSPARENT}
!define __NSD_Label_CLASS STATIC
!define __NSD_Label_STYLE ${DEFAULT_STYLES}
!define __NSD_Label_EXSTYLE ${WS_EX_TRANSPARENT}
!define __NSD_Icon_CLASS STATIC
!define __NSD_Icon_STYLE ${DEFAULT_STYLES}|${SS_ICON}
!define __NSD_Icon_EXSTYLE 0
!define __NSD_Bitmap_CLASS STATIC
!define __NSD_Bitmap_STYLE ${DEFAULT_STYLES}|${SS_BITMAP}
!define __NSD_Bitmap_EXSTYLE 0
!define __NSD_BrowseButton_CLASS BUTTON
!define __NSD_BrowseButton_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}
!define __NSD_BrowseButton_EXSTYLE 0
!define __NSD_Link_CLASS BUTTON
!define __NSD_Link_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${BS_OWNERDRAW}
!define __NSD_Link_EXSTYLE 0
!define __NSD_Button_CLASS BUTTON
!define __NSD_Button_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}
!define __NSD_Button_EXSTYLE 0
!define __NSD_GroupBox_CLASS BUTTON
!define __NSD_GroupBox_STYLE ${DEFAULT_STYLES}|${BS_GROUPBOX}
!define __NSD_GroupBox_EXSTYLE ${WS_EX_TRANSPARENT}
!define __NSD_CheckBox_CLASS BUTTON
!define __NSD_CheckBox_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${BS_TEXT}|${BS_VCENTER}|${BS_AUTOCHECKBOX}|${BS_MULTILINE}
!define __NSD_CheckBox_EXSTYLE 0
!define __NSD_RadioButton_CLASS BUTTON
!define __NSD_RadioButton_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${BS_TEXT}|${BS_VCENTER}|${BS_AUTORADIOBUTTON}|${BS_MULTILINE}
!define __NSD_RadioButton_EXSTYLE 0
!define __NSD_Text_CLASS EDIT
!define __NSD_Text_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${ES_AUTOHSCROLL}
!define __NSD_Text_EXSTYLE ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}
!define __NSD_FileRequest_CLASS EDIT
!define __NSD_FileRequest_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${ES_AUTOHSCROLL}
!define __NSD_FileRequest_EXSTYLE ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}
!define __NSD_DirRequest_CLASS EDIT
!define __NSD_DirRequest_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${ES_AUTOHSCROLL}
!define __NSD_DirRequest_EXSTYLE ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}
!define __NSD_ComboBox_CLASS COMBOBOX
!define __NSD_ComboBox_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${WS_CLIPCHILDREN}|${CBS_AUTOHSCROLL}|${CBS_HASSTRINGS}
!define __NSD_ComboBox_EXSTYLE ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}
!define __NSD_ListBox_CLASS LISTBOX
!define __NSD_ListBox_STYLE ${DEFAULT_STYLES}|${WS_TABSTOP}|${WS_VSCROLL}|${LBS_DISABLENOSCROLL}|${LBS_HASSTRINGS}|${LBS_NOINTEGRALHEIGHT}
!define __NSD_ListBox_EXSTYLE ${WS_EX_WINDOWEDGE}|${WS_EX_CLIENTEDGE}
!macro __NSD_DefineControl NAME
!define NSD_Create${NAME} "nsDialogs::CreateItem /NOUNLOAD ${__NSD_${Name}_CLASS} ${__NSD_${Name}_STYLE} ${__NSD_${Name}_EXSTYLE}"
!macroend
!insertmacro __NSD_DefineControl HLine
!insertmacro __NSD_DefineControl VLine
!insertmacro __NSD_DefineControl Label
!insertmacro __NSD_DefineControl Icon
!insertmacro __NSD_DefineControl Bitmap
!insertmacro __NSD_DefineControl BrowseButton
!insertmacro __NSD_DefineControl Link
!insertmacro __NSD_DefineControl Button
!insertmacro __NSD_DefineControl GroupBox
!insertmacro __NSD_DefineControl CheckBox
!insertmacro __NSD_DefineControl RadioButton
!insertmacro __NSD_DefineControl Text
!insertmacro __NSD_DefineControl FileRequest
!insertmacro __NSD_DefineControl DirRequest
!insertmacro __NSD_DefineControl ComboBox
!insertmacro __NSD_DefineControl ListBox
!define DEBUG `System::Call kernel32::OutputDebugString(ts)`
!macro __NSD_ControlCase TYPE
${Case} ${TYPE}
${NSD_Create${TYPE}} $R3u $R4u $R5u $R6u $R7
Pop $R9
${Break}
!macroend
!macro __NSD_ControlCaseEx TYPE
${Case} ${TYPE}
Call ${TYPE}
${Break}
!macroend
Function CreateDialogFromINI
# $0 = ini
ReadINIStr $R0 $0 Settings RECT
${If} $R0 == ""
StrCpy $R0 1018
${EndIf}
nsDialogs::Create /NOUNLOAD $R0
Pop $R9
ReadINIStr $R0 $0 Settings NumFields
${DEBUG} "NumFields = $R0"
${For} $R1 1 $R0
${DEBUG} "Creating field $R1"
ReadINIStr $R2 $0 "Field $R1" Type
${DEBUG} " Type = $R2"
ReadINIStr $R3 $0 "Field $R1" Left
${DEBUG} " Left = $R3"
ReadINIStr $R4 $0 "Field $R1" Top
${DEBUG} " Top = $R4"
ReadINIStr $R5 $0 "Field $R1" Right
${DEBUG} " Right = $R5"
ReadINIStr $R6 $0 "Field $R1" Bottom
${DEBUG} " Bottom = $R6"
IntOp $R5 $R5 - $R3
${DEBUG} " Width = $R5"
IntOp $R6 $R6 - $R4
${DEBUG} " Height = $R6"
ReadINIStr $R7 $0 "Field $R1" Text
${DEBUG} " Text = $R7"
${Switch} $R2
!insertmacro __NSD_ControlCase HLine
!insertmacro __NSD_ControlCase VLine
!insertmacro __NSD_ControlCase Label
!insertmacro __NSD_ControlCase Icon
!insertmacro __NSD_ControlCase Bitmap
!insertmacro __NSD_ControlCase Link
!insertmacro __NSD_ControlCase Button
!insertmacro __NSD_ControlCase GroupBox
!insertmacro __NSD_ControlCase CheckBox
!insertmacro __NSD_ControlCase RadioButton
!insertmacro __NSD_ControlCase Text
!insertmacro __NSD_ControlCaseEx FileRequest
!insertmacro __NSD_ControlCaseEx DirRequest
!insertmacro __NSD_ControlCase ComboBox
!insertmacro __NSD_ControlCase ListBox
${EndSwitch}
WriteINIStr $0 "Field $R1" HWND $R9
${Next}
nsDialogs::Show
FunctionEnd
Function FileRequest
IntOp $R5 $R5 - 15
IntOp $R8 $R3 + $R5
${NSD_CreateBrowseButton} $R8u $R4u 15u $R6u ...
Pop $R8
nsDialogs::SetUserData /NOUNLOAD $R8 $R1 # remember field id
WriteINIStr $0 "Field $R1" HWND2 $R8
GetFunctionAddress $R9 OnFileBrowseButton
nsDialogs::OnClick /NOUNLOAD $R8 $R9
ReadINIStr $R9 $0 "Field $R1" State
${NSD_CreateFileRequest} $R3u $R4u $R5u $R6u $R9
Pop $R9
FunctionEnd
Function DirRequest
IntOp $R5 $R5 - 15
IntOp $R8 $R3 + $R5
${NSD_CreateBrowseButton} $R8u $R4u 15u $R6u ...
Pop $R8
nsDialogs::SetUserData /NOUNLOAD $R8 $R1 # remember field id
WriteINIStr $0 "Field $R1" HWND2 $R8
GetFunctionAddress $R9 OnDirBrowseButton
nsDialogs::OnClick /NOUNLOAD $R8 $R9
ReadINIStr $R9 $0 "Field $R1" State
${NSD_CreateFileRequest} $R3u $R4u $R5u $R6u $R9
Pop $R9
FunctionEnd
Function OnFileBrowseButton
Pop $R0
nsDialogs::GetUserData /NOUNLOAD $R0
Pop $R1
ReadINIStr $R2 $0 "Field $R1" HWND
ReadINIStr $R4 $0 "Field $R1" Filter
System::Call user32::GetWindowText(iR2,t.R3,i${NSIS_MAX_STRLEN})
nsDialogs::SelectFileDialog /NOUNLOAD save $R3 $R4
Pop $R3
${If} $R3 != ""
SendMessage $R2 ${WM_SETTEXT} 0 STR:$R3
${EndIf}
FunctionEnd
Function OnDirBrowseButton
Pop $R0
nsDialogs::GetUserData /NOUNLOAD $R0
Pop $R1
ReadINIStr $R2 $0 "Field $R1" HWND
ReadINIStr $R3 $0 "Field $R1" Text
System::Call user32::GetWindowText(iR2,t.R4,i${NSIS_MAX_STRLEN})
nsDialogs::SelectFolderDialog /NOUNLOAD $R3 $R4
Pop $R3
${If} $R3 != error
SendMessage $R2 ${WM_SETTEXT} 0 STR:$R3
${EndIf}
FunctionEnd

95
Contrib/nsDialogs/nsis.c Normal file
View file

@ -0,0 +1,95 @@
#include <windows.h>
#include "nsis.h"
int g_stringsize;
stack_t **g_stacktop;
char *g_variables;
int NSDFUNC myatoi(const char *s)
{
int v=0;
if (*s == '0' && (s[1] == 'x' || s[1] == 'X'))
{
s++;
for (;;)
{
int c=*(++s);
if (c >= '0' && c <= '9') c-='0';
else if (c >= 'a' && c <= 'f') c-='a'-10;
else if (c >= 'A' && c <= 'F') c-='A'-10;
else break;
v<<=4;
v+=c;
}
}
else if (*s == '0' && s[1] <= '7' && s[1] >= '0')
{
for (;;)
{
int c=*(++s);
if (c >= '0' && c <= '7') c-='0';
else break;
v<<=3;
v+=c;
}
}
else
{
int sign=0;
if (*s == '-') sign++; else s--;
for (;;)
{
int c=*(++s) - '0';
if (c < 0 || c > 9) break;
v*=10;
v+=c;
}
if (sign) v = -v;
}
// Support for simple ORed expressions
if (*s == '|')
{
v |= myatoi(s+1);
}
return v;
}
int NSDFUNC popstring(char *str, int size)
{
stack_t *th;
if (!g_stacktop || !*g_stacktop) return 1;
th=(*g_stacktop);
lstrcpyn(str,th->text,size?size:g_stringsize);
*g_stacktop = th->next;
GlobalFree((HGLOBAL)th);
return 0;
}
void NSDFUNC pushstring(const char *str)
{
stack_t *th;
if (!g_stacktop) return;
th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize);
lstrcpyn(th->text,str,g_stringsize);
th->next=*g_stacktop;
*g_stacktop=th;
}
int NSDFUNC popint()
{
char buf[1024];
if (popstring(buf,sizeof(buf)))
return 0;
return myatoi(buf);
}
void NSDFUNC pushint(int value)
{
char buffer[1024];
wsprintf(buffer, "%d", value);
pushstring(buffer);
}

55
Contrib/nsDialogs/nsis.h Normal file
View file

@ -0,0 +1,55 @@
#ifndef __NS_DIALOGS__NSIS_H__
#define __NS_DIALOGS__NSIS_H__
#include <windows.h>
#include "defs.h"
#define EXDLL_INIT() { \
g_stringsize=string_size; \
g_stacktop=stacktop; \
g_variables=variables; }
// For page showing plug-ins
#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8)
#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd)
#define NOTIFY_BYE_BYE 'x'
typedef struct _stack_t {
struct _stack_t *next;
char text[1]; // this should be the length of string_size
} stack_t;
extern int g_stringsize;
extern stack_t **g_stacktop;
extern char *g_variables;
int NSDFUNC myatoi(const char *s);
int NSDFUNC popstring(char *str, int size);
void NSDFUNC pushstring(const char *str);
int NSDFUNC popint();
void NSDFUNC pushint(int value);
typedef struct {
int autoclose;
int all_user_var;
int exec_error;
int abort;
int exec_reboot;
int reboot_called;
int XXX_cur_insttype; // deprecated
int XXX_insttype_changed; // deprecated
int silent;
int instdir_error;
int rtl;
int errlvl;
int alter_reg_view;
} exec_flags_type;
typedef struct {
exec_flags_type *exec_flags;
int (__stdcall *ExecuteCodeSegment)(int, HWND);
void (__stdcall *validate_filename)(char *);
} extra_parameters;
#endif//__NS_DIALOGS__NSIS_H__

View file

@ -0,0 +1,320 @@
!include MUI.nsh
!include LogicLib.nsh
!include WinMessages.nsh
!include FileFunc.nsh
!insertmacro GetRoot
Name "nsDialogs Welcome"
OutFile "nsDialogs Welcome.exe"
Page custom nsDialogsWelcome
Page custom nsDialogsDirectory
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
!define WS_EX_CLIENTEDGE 0x00000200
!define WS_CHILD 0x40000000
!define WS_VISIBLE 0x10000000
!define WS_DISABLED 0x08000000
!define WS_CLIPSIBLINGS 0x04000000
!define WS_MAXIMIZE 0x01000000
!define WS_VSCROLL 0x00200000
!define WS_HSCROLL 0x00100000
!define WS_GROUP 0x00020000
!define WS_TABSTOP 0x00010000
!define ES_LEFT 0x00000000
!define ES_CENTER 0x00000001
!define ES_RIGHT 0x00000002
!define ES_MULTILINE 0x00000004
!define ES_UPPERCASE 0x00000008
!define ES_LOWERCASE 0x00000010
!define ES_PASSWORD 0x00000020
!define ES_AUTOVSCROLL 0x00000040
!define ES_AUTOHSCROLL 0x00000080
!define ES_NOHIDESEL 0x00000100
!define ES_OEMCONVERT 0x00000400
!define ES_READONLY 0x00000800
!define ES_WANTRETURN 0x00001000
!define ES_NUMBER 0x00002000
!define SS_LEFT 0x00000000
!define SS_CENTER 0x00000001
!define SS_RIGHT 0x00000002
!define SS_ICON 0x00000003
!define SS_BLACKRECT 0x00000004
!define SS_GRAYRECT 0x00000005
!define SS_WHITERECT 0x00000006
!define SS_BLACKFRAME 0x00000007
!define SS_GRAYFRAME 0x00000008
!define SS_WHITEFRAME 0x00000009
!define SS_USERITEM 0x0000000A
!define SS_SIMPLE 0x0000000B
!define SS_LEFTNOWORDWRAP 0x0000000C
!define SS_OWNERDRAW 0x0000000D
!define SS_BITMAP 0x0000000E
!define SS_ENHMETAFILE 0x0000000F
!define SS_ETCHEDHORZ 0x00000010
!define SS_ETCHEDVERT 0x00000011
!define SS_ETCHEDFRAME 0x00000012
!define SS_TYPEMASK 0x0000001F
!define SS_REALSIZECONTROL 0x00000040
!define SS_NOPREFIX 0x00000080
!define SS_NOTIFY 0x00000100
!define SS_CENTERIMAGE 0x00000200
!define SS_RIGHTJUST 0x00000400
!define SS_REALSIZEIMAGE 0x00000800
!define SS_SUNKEN 0x00001000
!define SS_EDITCONTROL 0x00002000
!define SS_ENDELLIPSIS 0x00004000
!define SS_PATHELLIPSIS 0x00008000
!define SS_WORDELLIPSIS 0x0000C000
!define SS_ELLIPSISMASK 0x0000C000
!define BS_PUSHBUTTON 0x00000000
!define BS_DEFPUSHBUTTON 0x00000001
!define BS_CHECKBOX 0x00000002
!define BS_AUTOCHECKBOX 0x00000003
!define BS_RADIOBUTTON 0x00000004
!define BS_3STATE 0x00000005
!define BS_AUTO3STATE 0x00000006
!define BS_GROUPBOX 0x00000007
!define BS_USERBUTTON 0x00000008
!define BS_AUTORADIOBUTTON 0x00000009
!define BS_PUSHBOX 0x0000000A
!define BS_OWNERDRAW 0x0000000B
!define BS_TYPEMASK 0x0000000F
!define BS_LEFTTEXT 0x00000020
!define BS_TEXT 0x00000000
!define BS_ICON 0x00000040
!define BS_BITMAP 0x00000080
!define BS_LEFT 0x00000100
!define BS_RIGHT 0x00000200
!define BS_CENTER 0x00000300
!define BS_TOP 0x00000400
!define BS_BOTTOM 0x00000800
!define BS_VCENTER 0x00000C00
!define BS_PUSHLIKE 0x00001000
!define BS_MULTILINE 0x00002000
!define BS_NOTIFY 0x00004000
!define BS_FLAT 0x00008000
!define BS_RIGHTBUTTON ${BS_LEFTTEXT}
!define LR_DEFAULTCOLOR 0x0000
!define LR_MONOCHROME 0x0001
!define LR_COLOR 0x0002
!define LR_COPYRETURNORG 0x0004
!define LR_COPYDELETEORG 0x0008
!define LR_LOADFROMFILE 0x0010
!define LR_LOADTRANSPARENT 0x0020
!define LR_DEFAULTSIZE 0x0040
!define LR_VGACOLOR 0x0080
!define LR_LOADMAP3DCOLORS 0x1000
!define LR_CREATEDIBSECTION 0x2000
!define LR_COPYFROMRESOURCE 0x4000
!define LR_SHARED 0x8000
!define IMAGE_BITMAP 0
!define IMAGE_ICON 1
!define IMAGE_CURSOR 2
!define IMAGE_ENHMETAFILE 3
Var DIALOG
Var HEADLINE
Var TEXT
Var IMAGECTL
Var IMAGE
Var DIRECTORY
Var FREESPACE
Var HEADLINE_FONT
Function .onInit
CreateFont $HEADLINE_FONT "$(^Font)" "14" "700"
InitPluginsDir
File /oname=$PLUGINSDIR\welcome.bmp "${NSISDIR}\Contrib\Graphics\Wizard\orange-nsis.bmp"
FunctionEnd
Function HideControls
LockWindow on
GetDlgItem $0 $HWNDPARENT 1028
ShowWindow $0 ${SW_HIDE}
GetDlgItem $0 $HWNDPARENT 1256
ShowWindow $0 ${SW_HIDE}
GetDlgItem $0 $HWNDPARENT 1035
ShowWindow $0 ${SW_HIDE}
GetDlgItem $0 $HWNDPARENT 1037
ShowWindow $0 ${SW_HIDE}
GetDlgItem $0 $HWNDPARENT 1038
ShowWindow $0 ${SW_HIDE}
GetDlgItem $0 $HWNDPARENT 1039
ShowWindow $0 ${SW_HIDE}
GetDlgItem $0 $HWNDPARENT 1045
ShowWindow $0 ${SW_NORMAL}
LockWindow off
FunctionEnd
Function ShowControls
LockWindow on
GetDlgItem $0 $HWNDPARENT 1028
ShowWindow $0 ${SW_NORMAL}
GetDlgItem $0 $HWNDPARENT 1256
ShowWindow $0 ${SW_NORMAL}
GetDlgItem $0 $HWNDPARENT 1035
ShowWindow $0 ${SW_NORMAL}
GetDlgItem $0 $HWNDPARENT 1037
ShowWindow $0 ${SW_NORMAL}
GetDlgItem $0 $HWNDPARENT 1038
ShowWindow $0 ${SW_NORMAL}
GetDlgItem $0 $HWNDPARENT 1039
ShowWindow $0 ${SW_NORMAL}
GetDlgItem $0 $HWNDPARENT 1045
ShowWindow $0 ${SW_HIDE}
LockWindow off
FunctionEnd
Function nsDialogsWelcome
nsDialogs::Create /NOUNLOAD 1044
Pop $DIALOG
nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${SS_BITMAP} 0 0 0 109u 193u ""
Pop $IMAGECTL
StrCpy $0 $PLUGINSDIR\welcome.bmp
System::Call 'user32::LoadImage(i 0, t r0, i ${IMAGE_BITMAP}, i 0, i 0, i ${LR_LOADFROMFILE}) i.s'
Pop $IMAGE
SendMessage $IMAGECTL ${STM_SETIMAGE} ${IMAGE_BITMAP} $IMAGE
nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 120u 10u -130u 20u "Welcome to nsDialogs!"
Pop $HEADLINE
SendMessage $HEADLINE ${WM_SETFONT} $HEADLINE_FONT 0
nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 120u 32u -130u -32u "nsDialogs is the next generation of user interfaces in NSIS. It gives the developer full control over custom pages. Some of the features include control text containing variables, callbacks directly into script functions and creation of any type of control. Create boring old edit boxes or load some external library and create custom controls with no need of creating your own plug-in.$\r$\n$\r$\nUnlike InstallOptions, nsDialogs doesn't use INI files to communicate with the script. By interacting directly with the script, nsDialogs can perform much faster without the need of costly, old and inefficient INI operations. Direct interaction also allows direct calls to functions defined in the script and removes the need of conversion functions like Io2Nsis.$\r$\n$\r$\nHit the Next button to see how it all fits into a mock directory page."
Pop $TEXT
SetCtlColors $DIALOG "" 0xffffff
SetCtlColors $HEADLINE "" 0xffffff
SetCtlColors $TEXT "" 0xffffff
Call HideControls
nsDialogs::Show
Call ShowControls
System::Call gdi32::DeleteObject(i$IMAGE)
FunctionEnd
!define SHACF_FILESYSTEM 1
Function nsDialogsDirectory
!insertmacro MUI_HEADER_TEXT "Choose Install Location" "Choose the folder in which to install $(^NameDA)."
GetDlgItem $0 $HWNDPARENT 1
EnableWindow $0 0
nsDialogs::Create /NOUNLOAD 1018
Pop $DIALOG
nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${SS_CENTER} 0 0 0 100% 30 "Directory page"
Pop $HEADLINE
SendMessage $HEADLINE ${WM_SETFONT} $HEADLINE_FONT 0
nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 0 30 100% 40 "Select the installation directory of NSIS to continue. $_CLICK"
Pop $TEXT
nsDialogs::CreateItem /NOUNLOAD EDIT ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS}|${ES_AUTOHSCROLL}|${WS_TABSTOP} ${WS_EX_CLIENTEDGE} 0 75 100% 12u ""
Pop $DIRECTORY
SendMessage $HWNDPARENT ${WM_NEXTDLGCTL} $DIRECTORY 1
GetFunctionAddress $0 DirChange
nsDialogs::OnChange /NOUNLOAD $DIRECTORY $0
System::Call shlwapi::SHAutoComplete(i$DIRECTORY,i${SHACF_FILESYSTEM})
nsDialogs::CreateItem /NOUNLOAD STATIC ${WS_VISIBLE}|${WS_CHILD}|${WS_CLIPSIBLINGS} 0 0 -10u 100% 10u ""
Pop $FREESPACE
Call UpdateFreeSpace
nsDialogs::Show
FunctionEnd
Function UpdateFreeSpace
${GetRoot} $INSTDIR $0
StrCpy $1 " bytes"
System::Call kernel32::GetDiskFreeSpaceEx(tr0,*l,*l,*l.r0)
${If} $0 > 1024
${OrIf} $0 < 0
System::Int64Op $0 / 1024
Pop $0
StrCpy $1 "kb"
${If} $0 > 1024
${OrIf} $0 < 0
System::Int64Op $0 / 1024
Pop $0
StrCpy $1 "mb"
${If} $0 > 1024
${OrIf} $0 < 0
System::Int64Op $0 / 1024
Pop $0
StrCpy $1 "gb"
${EndIf}
${EndIf}
${EndIf}
SendMessage $FREESPACE ${WM_SETTEXT} 0 "STR:Free space: $0$1"
FunctionEnd
Function DirChange
GetDlgItem $0 $HWNDPARENT 1
System::Call user32::GetWindowText(i$DIRECTORY,t.d,i${NSIS_MAX_STRLEN})
${If} ${FileExists} $INSTDIR\makensis.exe
EnableWindow $0 1
${Else}
EnableWindow $0 0
${EndIf}
Call UpdateFreeSpace
FunctionEnd
Section
SectionEnd

View file

@ -548,6 +548,24 @@ ${MementoSection} "InstallOptions" SecPluginsIO
File ..\Examples\InstallOptions\testnotify.nsi
${MementoSectionEnd}
${MementoSection} "nsDialogs" SecPluginsDialogs
SetDetailsPrint textonly
DetailPrint "Installing Plug-ins | nsDialogs..."
SetDetailsPrint listonly
SectionIn 1
SetOutPath $INSTDIR\Plugins
File ..\Plugins\nsDialogs.dll
SetOutPath $INSTDIR\Examples\nsDialogs
File ..\Examples\nsDialogs\example.nsi
File ..\Examples\nsDialogs\InstallOptions.nsi
File ..\Examples\nsDialogs\welcome.nsi
SetOutPath $INSTDIR\Include
File ..\Include\nsDialogs.nsh
${MementoSectionEnd}
${MementoSection} "Math" SecPluginsMath
SetDetailsPrint textonly
@ -849,6 +867,7 @@ SectionEnd
!insertmacro MUI_DESCRIPTION_TEXT ${SecPluginsMath} "Plugin that lets you evaluate complicated mathematical expressions"
!insertmacro MUI_DESCRIPTION_TEXT ${SecPluginsDialer} "Plugin that provides internet connection functions"
!insertmacro MUI_DESCRIPTION_TEXT ${SecPluginsIO} "Plugin that lets you add custom pages to an installer"
!insertmacro MUI_DESCRIPTION_TEXT ${SecPluginsDialogs} "Plugin that lets you add custom pages to an installer"
!insertmacro MUI_DESCRIPTION_TEXT ${SecPluginsStartMenu} "Plugin that lets the user select the start menu folder"
!insertmacro MUI_DESCRIPTION_TEXT ${SecPluginsBgImage} "Plugin that lets you show a persistent background image plugin and play sounds"
!insertmacro MUI_DESCRIPTION_TEXT ${SecPluginsUserInfo} "Plugin that that gives you the user name and the user account type"

View file

@ -21,6 +21,7 @@ plugins = [
'LangDLL',
'Library/TypeLib',
'Math',
'nsDialogs',
'nsExec',
'NSISdl',
'Splash',