2003-03-11 13:29:38 +00:00
|
|
|
/*********************************************************
|
2002-09-05 22:22:26 +00:00
|
|
|
*
|
2003-03-11 13:29:38 +00:00
|
|
|
* InstallOptions version 2.0 - Plugin for custom pages
|
2002-08-02 10:01:35 +00:00
|
|
|
*
|
2003-03-11 13:29:38 +00:00
|
|
|
* See Readme.html for documentation and license
|
2002-08-02 10:01:35 +00:00
|
|
|
*
|
2003-03-11 13:29:38 +00:00
|
|
|
*********************************************************/
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <windowsx.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
#include <commdlg.h>
|
2003-06-02 14:26:15 +00:00
|
|
|
#include <cderr.h>
|
2002-08-02 10:01:35 +00:00
|
|
|
#include "resource.h"
|
2003-06-16 18:49:23 +00:00
|
|
|
#include "Shellapi.h"
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-06-07 10:59:11 +00:00
|
|
|
#define popstring dontuseme
|
2002-09-21 18:31:08 +00:00
|
|
|
#include "../exdll/exdll.h"
|
2003-06-07 10:59:11 +00:00
|
|
|
#undef popstring
|
|
|
|
|
|
|
|
static int popstring(char *str)
|
|
|
|
{
|
|
|
|
stack_t *th;
|
|
|
|
if (!g_stacktop || !*g_stacktop) return 1;
|
|
|
|
th=(*g_stacktop);
|
|
|
|
if (str) lstrcpy(str,th->text);
|
|
|
|
*g_stacktop = th->next;
|
|
|
|
GlobalFree((HGLOBAL)th);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
#define strcpy(x,y) lstrcpy(x,y)
|
|
|
|
#define strncpy(x,y,z) lstrcpyn(x,y,z)
|
|
|
|
#define strdup(x) STRDUP(x)
|
|
|
|
#define stricmp(x,y) lstrcmpi(x,y)
|
|
|
|
//#define abs(x) ((x) < 0 ? -(x) : (x))
|
|
|
|
|
|
|
|
void *MALLOC(int len) { return (void*)GlobalAlloc(GPTR,len); }
|
|
|
|
void FREE(void *d) { if (d) GlobalFree((HGLOBAL)d); }
|
|
|
|
|
|
|
|
char *STRDUP(const char *c)
|
|
|
|
{
|
|
|
|
char *t=(char*)MALLOC(lstrlen(c)+1);
|
2003-06-02 14:26:15 +00:00
|
|
|
return lstrcpy(t,c);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
2002-09-10 20:04:54 +00:00
|
|
|
#define FIELD_LABEL (1)
|
|
|
|
#define FIELD_ICON (2)
|
|
|
|
#define FIELD_BITMAP (3)
|
|
|
|
#define FIELD_BROWSEBUTTON (4)
|
|
|
|
#define FIELD_CHECKBOX (5)
|
|
|
|
#define FIELD_RADIOBUTTON (6)
|
|
|
|
#define FIELD_TEXT (7)
|
|
|
|
#define FIELD_FILEREQUEST (8)
|
|
|
|
#define FIELD_DIRREQUEST (9)
|
|
|
|
#define FIELD_COMBOBOX (10)
|
|
|
|
#define FIELD_LISTBOX (11)
|
2002-12-21 11:24:42 +00:00
|
|
|
#define FIELD_GROUPBOX (12)
|
2003-06-16 18:49:23 +00:00
|
|
|
#define FIELD_LINK (13)
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-07-07 21:08:26 +00:00
|
|
|
//---------------------------------------------------------------------
|
2003-07-05 16:55:54 +00:00
|
|
|
// settings
|
|
|
|
// crashes on windows 98 - #define IO_ENABLE_LINK
|
2003-07-07 21:08:26 +00:00
|
|
|
#define IO_ENABLE_LINK
|
|
|
|
|
|
|
|
//#define IO_LINK_UNDERLINED // Uncomment to show links text underlined
|
|
|
|
//---------------------------------------------------------------------
|
2003-07-05 16:55:54 +00:00
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
// general flags
|
2003-05-30 13:35:47 +00:00
|
|
|
#define FLAG_RIGHT 0x00000001
|
|
|
|
|
|
|
|
// OFN_OVERWRITEPROMPT 0x00000002
|
|
|
|
// OFN_HIDEREADONLY 0x00000004
|
|
|
|
|
|
|
|
#define FLAG_DISABLED 0x00000008
|
|
|
|
#define FLAG_GROUP 0x00000010
|
|
|
|
#define FLAG_NOTABSTOP 0x00000020
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
// text box flags
|
2003-05-30 13:35:47 +00:00
|
|
|
#define FLAG_PASSWORD 0x00000040
|
|
|
|
#define FLAG_ONLYNUMBERS 0x00000080
|
2003-06-10 13:18:07 +00:00
|
|
|
#define FLAG_MULTILINE 0x00000100
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
// listbox flags
|
2003-05-30 13:35:47 +00:00
|
|
|
#define FLAG_MULTISELECT 0x00000200
|
|
|
|
#define FLAG_EXTENDEDSEL 0x00000400
|
|
|
|
|
|
|
|
// OFN_PATHMUSTEXIST 0x00000800
|
|
|
|
// OFN_FILEMUSTEXIST 0x00001000
|
|
|
|
// OFN_CREATEPROMPT 0x00002000
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
// combobox flags
|
2003-05-30 13:35:47 +00:00
|
|
|
#define FLAG_DROPLIST 0x00004000
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-12-12 20:36:28 +00:00
|
|
|
// bitmap flags
|
2003-05-30 13:35:47 +00:00
|
|
|
#define FLAG_RESIZETOFIT 0x00008000
|
|
|
|
|
|
|
|
// OFN_EXPLORER 0x00080000
|
2002-12-12 20:36:28 +00:00
|
|
|
|
2003-06-10 13:18:07 +00:00
|
|
|
// more text box flags
|
|
|
|
#define FLAG_WANTRETURN 0x00100000
|
|
|
|
#define FLAG_VSCROLL 0x00200000
|
|
|
|
#define FLAG_HSCROLL 0x00400000
|
2003-06-11 23:57:24 +00:00
|
|
|
#define FLAG_READONLY 0x00800000
|
2003-06-10 13:18:07 +00:00
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
struct TableEntry {
|
|
|
|
char *pszName;
|
2002-09-05 22:22:26 +00:00
|
|
|
int nValue;
|
2002-08-02 10:01:35 +00:00
|
|
|
};
|
|
|
|
|
2002-09-05 22:22:26 +00:00
|
|
|
int LookupToken(TableEntry*, char*);
|
2002-09-30 22:22:16 +00:00
|
|
|
int LookupTokens(TableEntry*, char*);
|
2002-09-05 22:22:26 +00:00
|
|
|
|
2003-03-17 13:46:13 +00:00
|
|
|
void ConvertNewLines(char *str);
|
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
struct FieldType {
|
2003-03-23 17:12:14 +00:00
|
|
|
char *pszText;
|
|
|
|
char *pszState;
|
|
|
|
char *pszRoot;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-03-23 17:12:14 +00:00
|
|
|
char *pszListItems;
|
|
|
|
char *pszFilter;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-03-23 17:12:14 +00:00
|
|
|
int nType;
|
|
|
|
RECT rect;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-03-23 17:12:14 +00:00
|
|
|
int nMinLength;
|
|
|
|
int nMaxLength;
|
|
|
|
char *pszValidateText;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-03-23 17:12:14 +00:00
|
|
|
int nFlags;
|
|
|
|
bool bSaveDlg;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-03-23 17:12:14 +00:00
|
|
|
HWND hwnd;
|
|
|
|
UINT nControlID;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-06-16 18:49:23 +00:00
|
|
|
int nParentIdx; // this is used by the filerequest and dirrequest controls, used to store original windowproc for LINK
|
2003-07-21 19:48:48 +00:00
|
|
|
HANDLE hImage; // this is used by image/icon field to save the handle to the image
|
2002-08-02 10:01:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// initial buffer size. buffers will grow as required.
|
|
|
|
// use a value larger than MAX_PATH to prevent need for excessive growing.
|
2002-09-05 22:22:26 +00:00
|
|
|
#define MAX_BUFFER_LENGTH (300)
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
char szBrowseButtonCaption[] = "...";
|
|
|
|
|
|
|
|
HWND hConfigWindow = NULL;
|
|
|
|
HWND hMainWindow = NULL;
|
2002-11-08 16:51:26 +00:00
|
|
|
HWND hCancelButton = NULL;
|
|
|
|
HWND hNextButton = NULL;
|
|
|
|
HWND hBackButton = NULL;
|
2002-11-15 15:07:09 +00:00
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
HINSTANCE m_hInstance = NULL;
|
|
|
|
|
2003-06-08 13:41:48 +00:00
|
|
|
struct _stack_t *pFilenameStackEntry = NULL;
|
|
|
|
|
2002-11-10 18:13:35 +00:00
|
|
|
char *pszFilename = NULL;
|
|
|
|
char *pszTitle = NULL;
|
2002-08-02 10:01:35 +00:00
|
|
|
char *pszCancelButtonText = NULL;
|
2002-11-10 18:13:35 +00:00
|
|
|
char *pszNextButtonText = NULL;
|
|
|
|
char *pszBackButtonText = NULL;
|
2002-08-26 13:27:51 +00:00
|
|
|
|
2002-11-15 12:53:08 +00:00
|
|
|
int bBackEnabled = FALSE;
|
|
|
|
int bCancelEnabled = FALSE; // by ORTIM: 13-August-2002
|
|
|
|
int bCancelShow = FALSE; // by ORTIM: 13-August-2002
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
FieldType *pFields = NULL;
|
2002-12-06 15:43:35 +00:00
|
|
|
#define DEFAULT_RECT 1018
|
2002-11-15 15:07:09 +00:00
|
|
|
int nRectId = 0;
|
2002-08-02 10:01:35 +00:00
|
|
|
int nNumFields = 0;
|
|
|
|
int g_done;
|
|
|
|
|
2003-07-10 00:28:05 +00:00
|
|
|
int FindControlIdx(UINT id)
|
|
|
|
{
|
|
|
|
for (int nIdx = 0; nIdx < nNumFields; nIdx++)
|
|
|
|
if (id == pFields[nIdx].nControlID)
|
|
|
|
return nIdx;
|
|
|
|
return -1;
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
// array of HWNDs and window styles used to make the main NSIS controls invisible while this program runs.
|
|
|
|
|
|
|
|
bool BrowseForFile(int nControlIdx) {
|
|
|
|
OPENFILENAME ofn={0,};
|
|
|
|
HWND hControl;
|
|
|
|
BOOL bResult;
|
|
|
|
FieldType *pThisField = &pFields[nControlIdx];
|
|
|
|
|
|
|
|
hControl = pThisField->hwnd;
|
|
|
|
|
2003-05-30 13:35:47 +00:00
|
|
|
ofn.Flags = pThisField->nFlags & (OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_CREATEPROMPT | OFN_EXPLORER);
|
2002-09-05 22:22:26 +00:00
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
// ofn.hInstance = m_hInstance; // no templates so we can leave this at NULL;
|
|
|
|
ofn.hwndOwner = hConfigWindow;
|
|
|
|
// ofn.lCustData = NULL;
|
|
|
|
// ofn.lpfnHook = NULL;
|
|
|
|
// ofn.lpstrCustomFilter = NULL;
|
|
|
|
// ofn.lpstrDefExt = NULL;
|
|
|
|
ofn.nMaxFile = MAX_PATH;
|
2002-12-21 11:24:42 +00:00
|
|
|
ofn.lpstrFile = (char*)MALLOC(MAX_PATH);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
// ofn.nMaxFileTitle = MAX_PATH; // we ignore this for simplicity, leave lpstrFileTitle at NULL
|
|
|
|
// ofn.lpstrFileTitle = new char [ofn.nMaxFileTitle];
|
|
|
|
|
2002-09-05 22:22:26 +00:00
|
|
|
ofn.lpstrFilter = pThisField->pszFilter; // TODO: implement this
|
2002-08-02 10:01:35 +00:00
|
|
|
// ofn.lpstrInitialDir = NULL; // for now, just use the default initial directory.
|
2002-09-05 22:22:26 +00:00
|
|
|
// ofn.lpstrTitle = NULL; // TODO: implement this
|
2002-08-02 10:01:35 +00:00
|
|
|
// ofn.lpTemplateName = NULL;
|
|
|
|
ofn.lStructSize = sizeof(ofn);
|
|
|
|
// ofn.nFileExtension // this is output variable, leave it to 0 for now.
|
|
|
|
// ofn.nFileOffset // this is output variable, leave it to 0 for now.
|
|
|
|
// ofn.nFilterIndex = 1; // since we use no custom filters, leaving it at 0 means use the first.
|
|
|
|
// ofn.nMaxCustFilter = 0;
|
|
|
|
|
2002-12-21 11:24:42 +00:00
|
|
|
GetWindowText(hControl, ofn.lpstrFile, MAX_PATH);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-06-02 14:26:15 +00:00
|
|
|
tryagain:
|
|
|
|
if (pThisField->bSaveDlg) {
|
|
|
|
bResult = GetSaveFileName(&ofn);
|
|
|
|
} else {
|
|
|
|
bResult = GetOpenFileName(&ofn);
|
|
|
|
}
|
|
|
|
if (bResult) {
|
|
|
|
SetWindowText(hControl, ofn.lpstrFile);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (ofn.lpstrFile[0] && CommDlgExtendedError() == FNERR_INVALIDFILENAME) {
|
|
|
|
ofn.lpstrFile[0] = '\0';
|
|
|
|
goto tryagain;
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) {
|
|
|
|
TCHAR szDir[MAX_PATH];
|
|
|
|
|
2002-09-05 22:22:26 +00:00
|
|
|
if (uMsg == BFFM_INITIALIZED) {
|
2002-08-02 10:01:35 +00:00
|
|
|
if (GetWindowText(pFields[(int)pData].hwnd, szDir, MAX_PATH) > 0) {
|
|
|
|
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, (LPARAM)szDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool BrowseForFolder(int nControlIdx) {
|
2002-12-12 20:36:28 +00:00
|
|
|
BROWSEINFO bi;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-09-05 22:22:26 +00:00
|
|
|
bi.hwndOwner = hConfigWindow;
|
2002-12-12 20:36:28 +00:00
|
|
|
bi.pidlRoot = NULL;
|
2002-09-05 22:22:26 +00:00
|
|
|
bi.pszDisplayName = (char*)MALLOC(MAX_PATH);
|
2002-12-21 11:24:42 +00:00
|
|
|
bi.lpszTitle = pFields[nControlIdx].pszText;
|
2003-01-27 16:15:00 +00:00
|
|
|
#ifndef BIF_NEWDIALOGSTYLE
|
|
|
|
#define BIF_NEWDIALOGSTYLE 0x0040
|
|
|
|
#endif
|
|
|
|
bi.ulFlags = BIF_STATUSTEXT | BIF_RETURNONLYFSDIRS| BIF_NEWDIALOGSTYLE;
|
2002-09-05 22:22:26 +00:00
|
|
|
bi.lpfn = BrowseCallbackProc;
|
2002-08-02 10:01:35 +00:00
|
|
|
bi.lParam = nControlIdx;
|
2002-12-12 20:36:28 +00:00
|
|
|
bi.iImage = 0;
|
2002-09-05 22:22:26 +00:00
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
if (pFields[nControlIdx].pszRoot) {
|
|
|
|
LPSHELLFOLDER sf;
|
|
|
|
ULONG eaten;
|
|
|
|
LPITEMIDLIST root;
|
2003-07-18 13:05:53 +00:00
|
|
|
int ccRoot = (lstrlen(pFields[nControlIdx].pszRoot) * 2) + 2;
|
|
|
|
LPWSTR pwszRoot = (LPWSTR) MALLOC(ccRoot);
|
|
|
|
MultiByteToWideChar(CP_ACP, 0, pFields[nControlIdx].pszRoot, -1, pwszRoot, ccRoot);
|
2002-08-02 10:01:35 +00:00
|
|
|
SHGetDesktopFolder(&sf);
|
2003-07-18 13:05:53 +00:00
|
|
|
sf->ParseDisplayName(hConfigWindow, NULL, pwszRoot, &eaten, &root, NULL);
|
2002-08-02 10:01:35 +00:00
|
|
|
bi.pidlRoot = root;
|
|
|
|
sf->Release();
|
2003-07-18 13:05:53 +00:00
|
|
|
FREE(pwszRoot);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
// CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
|
|
|
|
LPITEMIDLIST pResult = SHBrowseForFolder(&bi);
|
|
|
|
if (!pResult) {
|
|
|
|
FREE(bi.pszDisplayName);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *pszFolder = (char*)MALLOC(MAX_PATH);
|
|
|
|
if (SHGetPathFromIDList(pResult, pszFolder)) {
|
2002-12-21 11:24:42 +00:00
|
|
|
SetWindowText(pFields[nControlIdx].hwnd, pszFolder);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
LPMALLOC pMalloc;
|
|
|
|
if (!SHGetMalloc(&pMalloc)) {
|
|
|
|
pMalloc->Free(pResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE(bi.pszDisplayName);
|
|
|
|
FREE(pszFolder);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ValidateFields() {
|
2002-09-05 22:22:26 +00:00
|
|
|
int nIdx;
|
2002-08-02 10:01:35 +00:00
|
|
|
int nLength;
|
|
|
|
|
|
|
|
// In the unlikely event we can't allocate memory, go ahead and return true so we can get out of here.
|
|
|
|
// May cause problems for the install script, but no memory is problems for us.
|
|
|
|
for (nIdx = 0; nIdx < nNumFields; nIdx++) {
|
2002-09-05 22:22:26 +00:00
|
|
|
// this if statement prevents a stupid bug where a min/max length is assigned to a label control
|
2003-03-16 09:56:33 +00:00
|
|
|
// where the user obviously has no way of changing what is displayed. (can you say, "infinite loop"?)
|
2002-09-10 20:04:54 +00:00
|
|
|
if (pFields[nIdx].nType >= FIELD_TEXT) {
|
2002-11-01 20:34:55 +00:00
|
|
|
nLength = SendMessage(pFields[nIdx].hwnd, WM_GETTEXTLENGTH, 0, 0);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
if (((pFields[nIdx].nMaxLength > 0) && (nLength > pFields[nIdx].nMaxLength)) ||
|
|
|
|
((pFields[nIdx].nMinLength > 0) && (nLength < pFields[nIdx].nMinLength))) {
|
|
|
|
if (pFields[nIdx].pszValidateText) {
|
2003-03-16 09:56:33 +00:00
|
|
|
MessageBox(hConfigWindow, pFields[nIdx].pszValidateText, NULL, MB_OK|MB_ICONWARNING);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
SetFocus(pFields[nIdx].hwnd);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2002-09-26 22:47:21 +00:00
|
|
|
bool SaveSettings(void) {
|
2002-09-10 20:04:54 +00:00
|
|
|
static char szField[25];
|
2002-08-02 10:01:35 +00:00
|
|
|
int nIdx;
|
|
|
|
HWND hwnd;
|
2002-09-10 20:04:54 +00:00
|
|
|
int nBufLen = MAX_BUFFER_LENGTH;
|
2002-08-02 10:01:35 +00:00
|
|
|
char *pszBuffer = (char*)MALLOC(nBufLen);
|
|
|
|
if (!pszBuffer) return false;
|
2003-04-18 20:01:23 +00:00
|
|
|
|
2003-06-10 13:18:07 +00:00
|
|
|
int CurrField = 1;
|
2002-08-02 10:01:35 +00:00
|
|
|
for(nIdx = 0; nIdx < nNumFields; nIdx++) {
|
2003-06-10 13:18:07 +00:00
|
|
|
if ( pFields[nIdx].nType == FIELD_BROWSEBUTTON )
|
|
|
|
continue;
|
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
hwnd = pFields[nIdx].hwnd;
|
2003-06-10 13:18:07 +00:00
|
|
|
wsprintf(szField, "Field %d", CurrField);
|
2002-08-02 10:01:35 +00:00
|
|
|
switch(pFields[nIdx].nType) {
|
|
|
|
case FIELD_CHECKBOX:
|
|
|
|
case FIELD_RADIOBUTTON:
|
|
|
|
{
|
|
|
|
wsprintf(pszBuffer, "%d", !!SendMessage(hwnd, BM_GETCHECK, 0, 0));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case FIELD_LISTBOX:
|
|
|
|
{
|
|
|
|
// Ok, this one requires a bit of work.
|
|
|
|
// First, we allocate a buffer long enough to hold every item.
|
|
|
|
// Then, we loop through every item and if it's selected we add it to our buffer.
|
|
|
|
// If there is already an item in the list, then we prepend a | character before the new item.
|
|
|
|
// We could simplify for single-select boxes, but using one piece of code saves some space.
|
|
|
|
int nLength = lstrlen(pFields[nIdx].pszListItems) + 10;
|
|
|
|
if (nLength > nBufLen) {
|
|
|
|
FREE(pszBuffer);
|
|
|
|
nBufLen = nLength;
|
|
|
|
pszBuffer = (char*)MALLOC(nBufLen);
|
|
|
|
if (!pszBuffer) return false;
|
|
|
|
}
|
2003-04-18 21:46:11 +00:00
|
|
|
char *pszItem = (char*)MALLOC(nBufLen);
|
2003-04-18 20:01:23 +00:00
|
|
|
if (!pszItem) return false;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
*pszBuffer = '\0';
|
|
|
|
int nNumItems = SendMessage(hwnd, LB_GETCOUNT, 0, 0);
|
|
|
|
for(int nIdx2 = 0; nIdx2 < nNumItems; nIdx2++) {
|
|
|
|
if (SendMessage(hwnd, LB_GETSEL, nIdx2, 0) > 0) {
|
|
|
|
if (*pszBuffer) lstrcat(pszBuffer, "|");
|
|
|
|
SendMessage(hwnd, LB_GETTEXT, (WPARAM)nIdx2, (LPARAM)pszItem);
|
|
|
|
lstrcat(pszBuffer, pszItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FREE(pszItem);
|
|
|
|
break;
|
|
|
|
}
|
2003-02-07 11:58:06 +00:00
|
|
|
case FIELD_LABEL:
|
|
|
|
*pszBuffer=0;
|
|
|
|
break;
|
2002-08-02 10:01:35 +00:00
|
|
|
default:
|
|
|
|
{
|
2002-11-01 20:34:55 +00:00
|
|
|
int nLength = SendMessage(pFields[nIdx].hwnd, WM_GETTEXTLENGTH, 0, 0);
|
2002-08-02 10:01:35 +00:00
|
|
|
if (nLength > nBufLen) {
|
|
|
|
FREE(pszBuffer);
|
|
|
|
// add a bit extra so we do this less often
|
|
|
|
nBufLen = nLength + 20;
|
|
|
|
pszBuffer = (char*)MALLOC(nBufLen);
|
|
|
|
if (!pszBuffer) return false;
|
|
|
|
}
|
2003-06-10 13:18:07 +00:00
|
|
|
*pszBuffer='"';
|
|
|
|
GetWindowText(hwnd, pszBuffer+1, nBufLen-1);
|
|
|
|
pszBuffer[nLength+1]='"';
|
|
|
|
pszBuffer[nLength+2]='\0';
|
2003-06-16 18:49:23 +00:00
|
|
|
|
2003-06-10 13:18:07 +00:00
|
|
|
if ( pFields[nIdx].nType == FIELD_TEXT && pFields[nIdx].nFlags & FLAG_MULTILINE )
|
|
|
|
{
|
|
|
|
char *pszBuf2 = (char*)MALLOC(nBufLen*2); // double the size, consider the worst case, all chars are \r\n
|
|
|
|
char *p1, *p2;
|
|
|
|
for (p1=pszBuffer,p2=pszBuf2; *p1; p1++, p2++) {
|
|
|
|
if (*p1 == '\r') {
|
|
|
|
*p2++ = '\\';
|
|
|
|
*p2 = 'r';
|
|
|
|
}
|
|
|
|
else if (*p1 == '\n') {
|
|
|
|
*p2++ = '\\';
|
|
|
|
*p2 = 'n';
|
|
|
|
}
|
|
|
|
else if (*p1 == '\t') {
|
|
|
|
*p2++ = '\\';
|
|
|
|
*p2 = 't';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*p2=*p1;
|
|
|
|
}
|
|
|
|
*p2 = 0;
|
|
|
|
nBufLen = nBufLen*2;
|
|
|
|
FREE(pszBuffer);
|
|
|
|
pszBuffer=pszBuf2;
|
|
|
|
}
|
2003-06-16 18:49:23 +00:00
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-09-05 22:22:26 +00:00
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
WritePrivateProfileString(szField, "STATE", pszBuffer, pszFilename);
|
2003-06-10 13:18:07 +00:00
|
|
|
CurrField++;
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FREE(pszBuffer);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2003-03-17 13:46:13 +00:00
|
|
|
#define BROWSE_WIDTH 15
|
2003-07-29 20:25:42 +00:00
|
|
|
|
|
|
|
#define BUFFER_SIZE 8192 // 8kb of mem is max char count in multiedit
|
|
|
|
static char szResult[BUFFER_SIZE];
|
2002-09-26 22:47:21 +00:00
|
|
|
|
|
|
|
DWORD WINAPI myGetProfileString(LPCTSTR lpAppName, LPCTSTR lpKeyName)
|
|
|
|
{
|
|
|
|
*szResult = '\0';
|
2003-07-29 20:25:42 +00:00
|
|
|
return GetPrivateProfileString(lpAppName, lpKeyName, "", szResult, BUFFER_SIZE, pszFilename);
|
2002-09-26 22:47:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char * WINAPI myGetProfileStringDup(LPCTSTR lpAppName, LPCTSTR lpKeyName)
|
|
|
|
{
|
2003-07-29 20:25:42 +00:00
|
|
|
int nSize = myGetProfileString(lpAppName, lpKeyName);
|
|
|
|
if ( nSize )
|
2002-09-26 22:47:21 +00:00
|
|
|
return strdup(szResult);
|
|
|
|
else
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-08-05 15:05:49 +00:00
|
|
|
int ReadSettings(void) {
|
2002-09-10 20:04:54 +00:00
|
|
|
static char szField[25];
|
2003-07-21 19:48:48 +00:00
|
|
|
int nIdx, nCtrlIdx;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-09-26 22:47:21 +00:00
|
|
|
pszTitle = myGetProfileStringDup("Settings", "Title");
|
|
|
|
pszCancelButtonText = myGetProfileStringDup("Settings", "CancelButtonText");
|
|
|
|
pszNextButtonText = myGetProfileStringDup("Settings", "NextButtonText");
|
|
|
|
pszBackButtonText = myGetProfileStringDup("Settings", "BackButtonText");
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
nNumFields = GetPrivateProfileInt("Settings", "NumFields", 0, pszFilename);
|
2002-08-26 13:27:51 +00:00
|
|
|
|
2002-12-06 15:43:35 +00:00
|
|
|
nRectId = GetPrivateProfileInt("Settings", "Rect", DEFAULT_RECT, pszFilename);
|
2002-11-15 15:07:09 +00:00
|
|
|
|
2002-11-15 12:53:08 +00:00
|
|
|
bBackEnabled = GetPrivateProfileInt("Settings", "BackEnabled", 0xFFFF0000, pszFilename);
|
|
|
|
// by ORTIM: 13-August-2002
|
|
|
|
bCancelEnabled = GetPrivateProfileInt("Settings", "CancelEnabled", 0xFFFF0000, pszFilename);
|
|
|
|
bCancelShow = GetPrivateProfileInt("Settings", "CancelShow", 0xFFFF0000, pszFilename);
|
2002-09-05 22:22:26 +00:00
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
if (nNumFields > 0) {
|
|
|
|
// make this twice as large for the worst case that every control is a browse button.
|
|
|
|
// the structure is small enough that this won't waste much memory.
|
|
|
|
// if the structure gets much larger, we should switch to a linked list.
|
|
|
|
pFields = (FieldType *)MALLOC(sizeof(FieldType)*2*nNumFields);
|
|
|
|
}
|
|
|
|
|
2003-07-21 19:48:48 +00:00
|
|
|
for(nIdx = 0, nCtrlIdx = 0; nCtrlIdx < nNumFields; nCtrlIdx++, nIdx++) {
|
2002-09-05 22:22:26 +00:00
|
|
|
// Control types
|
|
|
|
static TableEntry TypeTable[] = {
|
|
|
|
{ "LABEL", FIELD_LABEL },
|
|
|
|
{ "TEXT", FIELD_TEXT },
|
|
|
|
{ "PASSWORD", FIELD_TEXT },
|
|
|
|
{ "LISTBOX", FIELD_LISTBOX },
|
|
|
|
{ "COMBOBOX", FIELD_COMBOBOX },
|
|
|
|
{ "DROPLIST", FIELD_COMBOBOX },
|
|
|
|
{ "FILEREQUEST", FIELD_FILEREQUEST },
|
|
|
|
{ "DIRREQUEST", FIELD_DIRREQUEST },
|
|
|
|
{ "CHECKBOX", FIELD_CHECKBOX },
|
|
|
|
{ "RADIOBUTTON", FIELD_RADIOBUTTON },
|
|
|
|
{ "ICON", FIELD_ICON },
|
|
|
|
{ "BITMAP", FIELD_BITMAP },
|
2002-12-21 11:24:42 +00:00
|
|
|
{ "GROUPBOX", FIELD_GROUPBOX },
|
2003-07-05 16:55:54 +00:00
|
|
|
#ifdef IO_ENABLE_LINK
|
2003-06-16 18:49:23 +00:00
|
|
|
{ "LINK", FIELD_LINK },
|
2003-07-05 16:55:54 +00:00
|
|
|
#else
|
|
|
|
{ "LINK", FIELD_LABEL },
|
|
|
|
#endif
|
2002-09-05 22:22:26 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
|
|
|
// Control flags
|
|
|
|
static TableEntry FlagTable[] = {
|
|
|
|
{ "FILE_MUST_EXIST", OFN_FILEMUSTEXIST },
|
|
|
|
{ "PATH_MUST_EXIST", OFN_PATHMUSTEXIST },
|
|
|
|
{ "WARN_IF_EXIST", OFN_OVERWRITEPROMPT },
|
|
|
|
{ "PROMPT_CREATE", OFN_CREATEPROMPT },
|
|
|
|
{ "RIGHT", FLAG_RIGHT },
|
|
|
|
{ "PASSWORD", FLAG_PASSWORD },
|
|
|
|
{ "DROPLIST", FLAG_DROPLIST },
|
|
|
|
{ "MULTISELECT", FLAG_MULTISELECT },
|
2003-04-03 13:17:54 +00:00
|
|
|
{ "EXTENDEDSELCT", FLAG_EXTENDEDSEL },
|
2002-09-05 22:22:26 +00:00
|
|
|
{ "FILE_EXPLORER", OFN_EXPLORER },
|
|
|
|
{ "FILE_HIDEREADONLY", OFN_HIDEREADONLY },
|
2002-12-12 20:36:28 +00:00
|
|
|
{ "RESIZETOFIT", FLAG_RESIZETOFIT },
|
2002-12-29 20:16:35 +00:00
|
|
|
{ "GROUP", FLAG_GROUP },
|
2003-01-03 22:26:08 +00:00
|
|
|
{ "DISABLED", FLAG_DISABLED },
|
2003-01-04 13:02:17 +00:00
|
|
|
{ "NOTABSTOP", FLAG_NOTABSTOP },
|
2003-05-30 13:35:47 +00:00
|
|
|
{ "ONLY_NUMBERS", FLAG_ONLYNUMBERS },
|
2003-06-10 13:18:07 +00:00
|
|
|
{ "MULTILINE", FLAG_MULTILINE },
|
|
|
|
{ "VSCROLL", FLAG_VSCROLL },
|
|
|
|
{ "HSCROLL", FLAG_HSCROLL },
|
2003-06-11 23:57:24 +00:00
|
|
|
{ "WANTRETURN", FLAG_WANTRETURN },
|
|
|
|
{ "READONLY", FLAG_READONLY },
|
2002-09-05 22:22:26 +00:00
|
|
|
{ NULL, 0 }
|
|
|
|
};
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-07-21 19:48:48 +00:00
|
|
|
wsprintf(szField, "Field %d", nCtrlIdx + 1);
|
2002-09-26 22:47:21 +00:00
|
|
|
myGetProfileString(szField, "TYPE");
|
2002-09-05 22:22:26 +00:00
|
|
|
|
|
|
|
// Get the control type
|
2002-09-10 20:04:54 +00:00
|
|
|
pFields[nIdx].nType = LookupToken(TypeTable, szResult);
|
2002-09-05 22:22:26 +00:00
|
|
|
if (!pFields[nIdx].nType)
|
2002-08-02 10:01:35 +00:00
|
|
|
continue;
|
2002-09-05 22:22:26 +00:00
|
|
|
|
|
|
|
// Lookup flags associated with the control type
|
2002-09-10 20:04:54 +00:00
|
|
|
pFields[nIdx].nFlags |= LookupToken(FlagTable, szResult);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-09-26 22:47:21 +00:00
|
|
|
pFields[nIdx].pszText = myGetProfileStringDup(szField, "TEXT");
|
2003-03-15 12:55:31 +00:00
|
|
|
|
|
|
|
// Label Text - convert newline
|
|
|
|
|
2003-03-17 13:46:13 +00:00
|
|
|
if (pFields[nIdx].nType == FIELD_LABEL) {
|
2003-03-15 12:55:31 +00:00
|
|
|
ConvertNewLines(pFields[nIdx].pszText);
|
2002-11-15 15:07:09 +00:00
|
|
|
}
|
2002-09-26 22:47:21 +00:00
|
|
|
|
|
|
|
// pszState cannot be NULL (?)
|
|
|
|
myGetProfileString(szField, "STATE");
|
2003-07-29 20:25:42 +00:00
|
|
|
pFields[nIdx].pszState = myGetProfileStringDup(szField, "STATE");
|
2003-08-03 22:04:31 +00:00
|
|
|
if (!pFields[nIdx].pszState)
|
|
|
|
pFields[nIdx].pszState = STRDUP(szResult);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-09-26 22:47:21 +00:00
|
|
|
pFields[nIdx].pszRoot = myGetProfileStringDup(szField, "ROOT");
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-09-26 22:47:21 +00:00
|
|
|
{
|
|
|
|
int nResult = myGetProfileString(szField, "ListItems");
|
|
|
|
if (nResult) {
|
|
|
|
// add an extra | character to the end to simplify the loop where we add the items.
|
|
|
|
pFields[nIdx].pszListItems = (char*)MALLOC(nResult + 2);
|
2003-01-11 19:23:49 +00:00
|
|
|
strcpy(pFields[nIdx].pszListItems, szResult);
|
|
|
|
pFields[nIdx].pszListItems[nResult] = '|';
|
2003-04-18 20:01:23 +00:00
|
|
|
pFields[nIdx].pszListItems[nResult + 1] = '\0';
|
2002-09-26 22:47:21 +00:00
|
|
|
}
|
2002-09-05 22:22:26 +00:00
|
|
|
}
|
2002-09-10 20:04:54 +00:00
|
|
|
pFields[nIdx].nMaxLength = GetPrivateProfileInt(szField, "MaxLen", 0, pszFilename);
|
|
|
|
pFields[nIdx].nMinLength = GetPrivateProfileInt(szField, "MinLen", 0, pszFilename);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-09-26 22:47:21 +00:00
|
|
|
pFields[nIdx].pszValidateText = myGetProfileStringDup(szField, "ValidateText");
|
2003-03-15 12:55:31 +00:00
|
|
|
|
|
|
|
// ValidateText - convert newline
|
|
|
|
|
2002-09-26 22:47:21 +00:00
|
|
|
if (pFields[nIdx].pszValidateText) {
|
2003-03-15 12:55:31 +00:00
|
|
|
ConvertNewLines(pFields[nIdx].pszValidateText);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
2002-09-26 22:47:21 +00:00
|
|
|
{
|
|
|
|
int nResult = GetPrivateProfileString(szField, "Filter", "All Files|*.*", szResult, sizeof(szResult), pszFilename);
|
|
|
|
if (nResult) {
|
|
|
|
// add an extra | character to the end to simplify the loop where we add the items.
|
|
|
|
pFields[nIdx].pszFilter = (char*)MALLOC(nResult + 2);
|
|
|
|
strcpy(pFields[nIdx].pszFilter, szResult);
|
|
|
|
char *pszPos = pFields[nIdx].pszFilter;
|
|
|
|
while (*pszPos) {
|
|
|
|
if (*pszPos == '|') *pszPos = '\0';
|
|
|
|
pszPos++;
|
|
|
|
}
|
2002-09-05 22:22:26 +00:00
|
|
|
}
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-09-10 20:04:54 +00:00
|
|
|
pFields[nIdx].rect.left = GetPrivateProfileInt(szField, "LEFT", 0, pszFilename);
|
|
|
|
pFields[nIdx].rect.right = GetPrivateProfileInt(szField, "RIGHT", 0, pszFilename);
|
|
|
|
pFields[nIdx].rect.top = GetPrivateProfileInt(szField, "TOP", 0, pszFilename);
|
|
|
|
pFields[nIdx].rect.bottom = GetPrivateProfileInt(szField, "BOTTOM", 0, pszFilename);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-09-26 22:47:21 +00:00
|
|
|
if (myGetProfileString(szField, "Flags")) {
|
2002-08-02 10:01:35 +00:00
|
|
|
// append the | to make parsing a bit easier
|
2002-09-10 20:04:54 +00:00
|
|
|
if (lstrlen(szResult)<sizeof(szResult)-1) lstrcat(szResult, "|");
|
2002-08-02 10:01:35 +00:00
|
|
|
// parse the flags text
|
|
|
|
char *pszStart, *pszEnd;
|
2002-09-10 20:04:54 +00:00
|
|
|
pszStart = pszEnd = szResult;
|
2002-08-02 10:01:35 +00:00
|
|
|
while ((*pszEnd) && (*pszStart)) {
|
|
|
|
if (*pszEnd == '|') {
|
|
|
|
*pszEnd = '\0';
|
|
|
|
if (pszEnd > pszStart) {
|
|
|
|
if (!stricmp("REQ_SAVE", pszStart)) {
|
|
|
|
pFields[nIdx].bSaveDlg = true;
|
|
|
|
} else {
|
|
|
|
// v1.3 converted this to a table lookup.
|
|
|
|
// I think it's a bit larger now, but we can
|
|
|
|
// add new flags with very little overhead.
|
2002-09-05 22:22:26 +00:00
|
|
|
pFields[nIdx].nFlags |= LookupToken(FlagTable, pszStart);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// jump to the next item, skip any redundant | characters
|
|
|
|
do { pszEnd++; } while (*pszEnd == '|');
|
|
|
|
pszStart = pszEnd;
|
|
|
|
}
|
|
|
|
pszEnd++;
|
2002-09-05 22:22:26 +00:00
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
2003-07-19 00:42:13 +00:00
|
|
|
// Text color for LINK control, default is pure blue
|
|
|
|
//if (pFields[nIdx].nType == FIELD_LINK)
|
|
|
|
pFields[nIdx].hImage = (HANDLE)GetPrivateProfileInt(szField, "TxtColor", RGB(0,0,255), pszFilename);
|
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
pFields[nIdx].nControlID = 1200 + nIdx;
|
2003-07-21 19:48:48 +00:00
|
|
|
if ( pFields[nIdx].nType == FIELD_FILEREQUEST || pFields[nIdx].nType == FIELD_DIRREQUEST )
|
|
|
|
{
|
|
|
|
FieldType *pNewField = &pFields[nIdx+1];
|
|
|
|
pNewField->nControlID = 1200 + nIdx + 1;
|
|
|
|
pNewField->nParentIdx = nIdx;
|
|
|
|
pNewField->nType = FIELD_BROWSEBUTTON;
|
|
|
|
pNewField->nFlags = pFields[nIdx].nFlags & (FLAG_DISABLED | FLAG_NOTABSTOP);
|
|
|
|
pNewField->pszText = STRDUP(szBrowseButtonCaption); // needed for generic FREE
|
|
|
|
pNewField->rect.right = pFields[nIdx].rect.right;
|
|
|
|
pNewField->rect.left = pNewField->rect.right - BROWSE_WIDTH;
|
|
|
|
pNewField->rect.bottom = pFields[nIdx].rect.bottom;
|
|
|
|
pNewField->rect.top = pFields[nIdx].rect.top;
|
|
|
|
pFields[nIdx].rect.right = pNewField->rect.left - 3;
|
|
|
|
nNumFields++;
|
|
|
|
nIdx++;
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
2003-08-05 15:05:49 +00:00
|
|
|
return nNumFields;
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LRESULT WMCommandProc(HWND hWnd, UINT id, HWND hwndCtl, UINT codeNotify) {
|
|
|
|
switch (codeNotify) {
|
|
|
|
case BN_CLICKED:
|
|
|
|
{
|
2003-07-10 00:28:05 +00:00
|
|
|
int nIdx = FindControlIdx(id);
|
|
|
|
if (pFields[nIdx].nType == FIELD_BROWSEBUTTON) {
|
|
|
|
int nParentIdx = pFields[nIdx].nParentIdx;
|
|
|
|
switch(pFields[nParentIdx].nType) {
|
|
|
|
case FIELD_FILEREQUEST:
|
|
|
|
BrowseForFile(nParentIdx);
|
|
|
|
break;
|
|
|
|
case FIELD_DIRREQUEST:
|
|
|
|
BrowseForFolder(nParentIdx);
|
|
|
|
break;
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
2003-07-10 00:28:05 +00:00
|
|
|
break;
|
|
|
|
} else if (pFields[nIdx].nType == FIELD_LINK) {
|
2003-07-21 19:48:48 +00:00
|
|
|
ShellExecute(hMainWindow, NULL, pFields[nIdx].pszState, NULL, NULL, SW_SHOWDEFAULT);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void *lpWndProcOld;
|
|
|
|
|
2003-03-18 15:45:25 +00:00
|
|
|
int g_is_cancel,g_is_back;
|
|
|
|
|
|
|
|
BOOL CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
|
2002-08-02 10:01:35 +00:00
|
|
|
{
|
2003-03-18 15:45:25 +00:00
|
|
|
BOOL bRes;
|
|
|
|
if (message == WM_NOTIFY_OUTER_NEXT && wParam == 1)
|
2003-04-18 20:01:23 +00:00
|
|
|
{
|
2003-03-18 15:45:25 +00:00
|
|
|
// Get the settings ready for the leave function verification
|
|
|
|
SaveSettings();
|
2003-04-18 20:01:23 +00:00
|
|
|
}
|
2003-03-18 15:45:25 +00:00
|
|
|
bRes = CallWindowProc((long (__stdcall *)(struct HWND__ *,unsigned int,unsigned int,long))lpWndProcOld,hwnd,message,wParam,lParam);
|
|
|
|
if (message == WM_NOTIFY_OUTER_NEXT && !bRes)
|
2002-09-26 22:47:21 +00:00
|
|
|
{
|
2003-03-18 15:45:25 +00:00
|
|
|
// if leave function didn't abort (lRes != 0 in that case)
|
|
|
|
if (wParam == NOTIFY_BYE_BYE || wParam == -1 || ValidateFields()) {
|
|
|
|
if (wParam == -1) g_is_back++;
|
|
|
|
if (wParam == NOTIFY_BYE_BYE) g_is_cancel++;
|
|
|
|
g_done++;
|
|
|
|
PostMessage(hConfigWindow,WM_CLOSE,0,0);
|
|
|
|
}
|
2002-09-26 22:47:21 +00:00
|
|
|
}
|
2003-03-18 15:45:25 +00:00
|
|
|
return bRes;
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
2002-09-05 22:22:26 +00:00
|
|
|
BOOL CALLBACK cfgDlgProc(HWND hwndDlg,
|
|
|
|
UINT uMsg,
|
2002-08-02 10:01:35 +00:00
|
|
|
WPARAM wParam,
|
|
|
|
LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch (uMsg)
|
|
|
|
{
|
2002-09-05 22:22:26 +00:00
|
|
|
HANDLE_MSG(hwndDlg, WM_COMMAND, WMCommandProc);
|
2003-07-07 21:08:26 +00:00
|
|
|
case WM_DRAWITEM:
|
|
|
|
{
|
|
|
|
DRAWITEMSTRUCT* lpdis = (DRAWITEMSTRUCT*)lParam;
|
2003-07-10 00:28:05 +00:00
|
|
|
int nIdx = FindControlIdx(lpdis->CtlID);
|
2003-07-07 21:08:26 +00:00
|
|
|
#ifdef IO_LINK_UNDERLINED
|
2003-07-10 00:28:05 +00:00
|
|
|
HFONT OldFont;
|
|
|
|
LOGFONT lf;
|
2003-07-07 21:08:26 +00:00
|
|
|
#endif
|
2003-07-10 00:28:05 +00:00
|
|
|
|
2003-07-07 21:08:26 +00:00
|
|
|
#ifdef IO_LINK_UNDERLINED
|
2003-07-10 00:28:05 +00:00
|
|
|
GetObject(GetCurrentObject(lpdis->hDC, OBJ_FONT), sizeof(lf), &lf);
|
|
|
|
lf.lfUnderline = TRUE;
|
|
|
|
OldFont = (HFONT)SelectObject(lpdis->hDC, CreateFontIndirect(&lf));
|
2003-07-07 21:08:26 +00:00
|
|
|
#endif
|
2003-07-10 00:28:05 +00:00
|
|
|
// Set up tranparent background
|
2003-07-19 00:42:13 +00:00
|
|
|
HBRUSH brush = (HBRUSH)GetWindowLong(lpdis->hwndItem, GWL_USERDATA);
|
|
|
|
if ( brush )
|
|
|
|
FillRect(lpdis->hDC, &lpdis->rcItem, brush);
|
|
|
|
|
|
|
|
if ( ( lpdis->itemState & ODS_FOCUS && lpdis->itemAction & ODA_DRAWENTIRE) || (lpdis->itemAction & ODA_FOCUS) ||
|
|
|
|
(lpdis->itemAction & ODA_SELECT))
|
|
|
|
DrawFocusRect(lpdis->hDC, &pFields[nIdx].rect);
|
2003-07-21 19:48:48 +00:00
|
|
|
|
2003-07-19 00:42:13 +00:00
|
|
|
SetTextColor(lpdis->hDC, (COLORREF)pFields[nIdx].hImage);
|
2003-07-10 00:28:05 +00:00
|
|
|
|
|
|
|
pFields[nIdx].rect = lpdis->rcItem;
|
|
|
|
// Calculate needed size of the control
|
|
|
|
DrawText(lpdis->hDC, pFields[nIdx].pszText, -1, &pFields[nIdx].rect, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_CALCRECT);
|
|
|
|
pFields[nIdx].rect.right += 4;
|
|
|
|
pFields[nIdx].rect.bottom = lpdis->rcItem.bottom;
|
|
|
|
// Resize but don't move
|
|
|
|
SetWindowPos(lpdis->hwndItem, NULL, 0, 0, pFields[nIdx].rect.right - pFields[nIdx].rect.left,
|
|
|
|
pFields[nIdx].rect.bottom - pFields[nIdx].rect.top, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE);
|
|
|
|
// Draw the text
|
|
|
|
lpdis->rcItem = pFields[nIdx].rect;
|
|
|
|
// Add little margin to avoid focus rect over text
|
|
|
|
lpdis->rcItem.right += 2; lpdis->rcItem.left += 2;
|
|
|
|
|
|
|
|
DrawText(lpdis->hDC, pFields[nIdx].pszText, -1, &lpdis->rcItem, DT_LEFT | DT_VCENTER | DT_SINGLELINE );
|
2003-07-07 21:08:26 +00:00
|
|
|
#ifdef IO_LINK_UNDERLINED
|
2003-07-10 00:28:05 +00:00
|
|
|
DeleteObject(SelectObject(lpdis->hDC, OldFont));
|
2003-07-07 21:08:26 +00:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
2002-11-01 20:34:55 +00:00
|
|
|
case WM_CTLCOLORSTATIC:
|
2003-03-20 20:49:13 +00:00
|
|
|
case WM_CTLCOLOREDIT:
|
2002-11-15 15:07:09 +00:00
|
|
|
case WM_CTLCOLORDLG:
|
2003-03-20 20:49:13 +00:00
|
|
|
case WM_CTLCOLORBTN:
|
|
|
|
case WM_CTLCOLORLISTBOX:
|
2003-04-16 12:32:15 +00:00
|
|
|
{
|
|
|
|
BOOL brush = (BOOL)GetWindowLong((HWND)lParam, GWL_USERDATA);
|
|
|
|
if (brush)
|
|
|
|
{
|
|
|
|
SetBkMode((HDC)wParam, TRANSPARENT);
|
|
|
|
return brush;
|
|
|
|
}
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-07-05 16:55:54 +00:00
|
|
|
#ifdef IO_ENABLE_LINK
|
2003-06-16 18:49:23 +00:00
|
|
|
// pFields[nIdx].nParentIdx is used to store original windowproc
|
2003-07-07 21:08:26 +00:00
|
|
|
int WINAPI StaticLINKWindowProc(HWND hWin, UINT uMsg, LPARAM wParam, WPARAM lParam)
|
2003-06-16 18:49:23 +00:00
|
|
|
{
|
2003-07-10 00:28:05 +00:00
|
|
|
int StaticField = FindControlIdx(GetDlgCtrlID(hWin));
|
|
|
|
switch(uMsg)
|
2003-06-16 18:49:23 +00:00
|
|
|
{
|
2003-07-10 00:28:05 +00:00
|
|
|
case WM_GETDLGCODE:
|
|
|
|
return DLGC_BUTTON|DLGC_WANTALLKEYS;
|
|
|
|
case WM_KEYDOWN:
|
2003-06-16 18:49:23 +00:00
|
|
|
{
|
2003-07-10 00:28:05 +00:00
|
|
|
if ( wParam == VK_RETURN )
|
|
|
|
WMCommandProc(hMainWindow, pFields[StaticField].nControlID, pFields[StaticField].hwnd, BN_CLICKED);
|
|
|
|
else if ( wParam == VK_TAB )
|
|
|
|
SendMessage(hMainWindow, WM_NEXTDLGCTL, GetKeyState(VK_SHIFT) & 0x8000, FALSE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case WM_SETCURSOR:
|
|
|
|
{
|
|
|
|
if ( (HWND)wParam == hWin && LOWORD(lParam) == HTCLIENT )
|
2003-06-16 18:49:23 +00:00
|
|
|
{
|
2003-07-10 00:28:05 +00:00
|
|
|
HCURSOR hCur = LoadCursor(NULL, IDC_HAND);
|
|
|
|
if ( hCur )
|
2003-06-16 18:49:23 +00:00
|
|
|
{
|
2003-07-10 00:28:05 +00:00
|
|
|
SetCursor(hCur);
|
|
|
|
return 1; // halt further processing
|
2003-06-16 18:49:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2003-07-10 00:28:05 +00:00
|
|
|
return CallWindowProc((WNDPROC)pFields[StaticField].nParentIdx, hWin, uMsg, wParam, lParam);
|
2003-06-16 18:49:23 +00:00
|
|
|
}
|
2003-07-05 16:55:54 +00:00
|
|
|
#endif
|
2003-06-16 18:49:23 +00:00
|
|
|
|
2002-11-01 20:34:55 +00:00
|
|
|
int nIdx;
|
|
|
|
HWND childwnd;
|
|
|
|
int cw_vis;
|
|
|
|
int was_ok_enabled;
|
|
|
|
char old_cancel[256];
|
|
|
|
char old_ok[256];
|
|
|
|
char old_back[256];
|
|
|
|
int old_cancel_enabled;
|
|
|
|
int old_cancel_visible;
|
|
|
|
char old_title[1024];
|
|
|
|
|
|
|
|
int createCfgDlg()
|
2002-08-02 10:01:35 +00:00
|
|
|
{
|
2003-01-19 16:56:10 +00:00
|
|
|
UINT nAddMsg, nFindMsg, nSetSelMsg;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-11-01 20:34:55 +00:00
|
|
|
g_is_back=0;
|
|
|
|
g_is_cancel=0;
|
|
|
|
|
2002-09-05 22:22:26 +00:00
|
|
|
if (!hMainWindow)
|
2002-08-02 10:01:35 +00:00
|
|
|
{
|
|
|
|
popstring(NULL);
|
|
|
|
pushstring("error finding mainwnd");
|
2002-11-01 20:34:55 +00:00
|
|
|
return 1; // cannot be used in silent mode unfortunately.
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
2002-11-15 15:07:09 +00:00
|
|
|
|
|
|
|
if (!g_stacktop || !*g_stacktop || !(pszFilename = (*g_stacktop)->text) || !pszFilename[0] || !ReadSettings())
|
2002-08-02 10:01:35 +00:00
|
|
|
{
|
|
|
|
popstring(NULL);
|
2002-11-15 15:07:09 +00:00
|
|
|
pushstring("error finding config");
|
2002-11-01 20:34:55 +00:00
|
|
|
return 1;
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
2002-11-15 15:07:09 +00:00
|
|
|
childwnd=FindWindowEx(hMainWindow,NULL,"#32770",NULL); // find window to replace
|
2002-12-06 15:43:35 +00:00
|
|
|
if (!childwnd || nRectId != DEFAULT_RECT) childwnd=GetDlgItem(hMainWindow,nRectId);
|
2002-11-15 15:07:09 +00:00
|
|
|
if (!childwnd)
|
2002-08-02 10:01:35 +00:00
|
|
|
{
|
|
|
|
popstring(NULL);
|
2002-11-15 15:07:09 +00:00
|
|
|
pushstring("error finding childwnd");
|
2002-11-01 20:34:55 +00:00
|
|
|
return 1;
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
2002-11-15 15:07:09 +00:00
|
|
|
|
2002-11-01 20:34:55 +00:00
|
|
|
cw_vis=IsWindowVisible(childwnd);
|
2002-08-02 10:01:35 +00:00
|
|
|
if (cw_vis) ShowWindow(childwnd,SW_HIDE);
|
|
|
|
|
2002-11-08 16:51:26 +00:00
|
|
|
hCancelButton = GetDlgItem(hMainWindow,IDCANCEL);
|
|
|
|
hNextButton = GetDlgItem(hMainWindow,IDOK);
|
|
|
|
hBackButton = GetDlgItem(hMainWindow,3);
|
2002-09-05 22:22:26 +00:00
|
|
|
|
2002-11-08 16:51:26 +00:00
|
|
|
was_ok_enabled=EnableWindow(hNextButton,1);
|
|
|
|
GetWindowText(hCancelButton,old_cancel,sizeof(old_cancel));
|
|
|
|
if (pszCancelButtonText) SetWindowText(hCancelButton,pszCancelButtonText);
|
|
|
|
GetWindowText(hNextButton,old_ok,sizeof(old_ok));
|
|
|
|
if (pszNextButtonText) SetWindowText(hNextButton,pszNextButtonText);
|
|
|
|
GetWindowText(hBackButton,old_back,sizeof(old_back));
|
|
|
|
if (pszBackButtonText) SetWindowText(hBackButton,pszBackButtonText);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-11-15 12:53:08 +00:00
|
|
|
if (bBackEnabled!=0xFFFF0000) EnableWindow(hBackButton,bBackEnabled);
|
|
|
|
if (bCancelEnabled!=0xFFFF0000) old_cancel_enabled=!EnableWindow(hCancelButton,bCancelEnabled);
|
|
|
|
if (bCancelShow!=0xFFFF0000) old_cancel_visible=ShowWindow(hCancelButton,bCancelShow?SW_SHOWNA:SW_HIDE);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
HFONT hFont = (HFONT)SendMessage(hMainWindow, WM_GETFONT, 0, 0);
|
|
|
|
|
|
|
|
RECT dialog_r;
|
|
|
|
hConfigWindow=CreateDialog(m_hInstance,MAKEINTRESOURCE(IDD_DIALOG1),hMainWindow,cfgDlgProc);
|
|
|
|
if (hConfigWindow)
|
|
|
|
{
|
|
|
|
GetWindowRect(childwnd,&dialog_r);
|
|
|
|
ScreenToClient(hMainWindow,(LPPOINT)&dialog_r);
|
|
|
|
ScreenToClient(hMainWindow,((LPPOINT)&dialog_r)+1);
|
|
|
|
SetWindowPos(hConfigWindow,0,dialog_r.left,dialog_r.top,dialog_r.right-dialog_r.left,dialog_r.bottom-dialog_r.top,SWP_NOZORDER|SWP_NOACTIVATE);
|
|
|
|
// Sets the font of IO window to be the same as the main window
|
|
|
|
SendMessage(hConfigWindow, WM_SETFONT, (WPARAM)hFont, TRUE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
popstring(NULL);
|
|
|
|
pushstring("error creating dialog");
|
2002-11-01 20:34:55 +00:00
|
|
|
return 1;
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-11 13:29:38 +00:00
|
|
|
// Init dialog unit conversion
|
2002-12-14 00:10:29 +00:00
|
|
|
|
|
|
|
HDC memDC = CreateCompatibleDC(GetDC(hConfigWindow));
|
|
|
|
SelectObject(memDC, hFont);
|
|
|
|
|
|
|
|
TEXTMETRIC tm;
|
|
|
|
GetTextMetrics(memDC, &tm);
|
|
|
|
int baseUnitY = tm.tmHeight;
|
|
|
|
|
|
|
|
SIZE size;
|
|
|
|
GetTextExtentPoint32(memDC,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", 52, &size);
|
|
|
|
int baseUnitX = (size.cx / 26 + 1) / 2;
|
|
|
|
|
|
|
|
DeleteDC(memDC);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-01-04 13:02:17 +00:00
|
|
|
#define DEFAULT_STYLES (WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS)
|
2002-11-14 21:21:45 +00:00
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
for (nIdx = 0; nIdx < nNumFields; nIdx++) {
|
2002-09-10 20:04:54 +00:00
|
|
|
static struct {
|
|
|
|
char* pszClass;
|
|
|
|
DWORD dwStyle;
|
|
|
|
DWORD dwExStyle;
|
|
|
|
} ClassTable[] = {
|
|
|
|
{ "STATIC", // FIELD_LABEL
|
2003-08-05 15:05:49 +00:00
|
|
|
DEFAULT_STYLES /*| WS_TABSTOP*/,
|
2002-09-10 20:04:54 +00:00
|
|
|
WS_EX_TRANSPARENT },
|
|
|
|
{ "STATIC", // FIELD_ICON
|
2002-12-29 20:16:35 +00:00
|
|
|
DEFAULT_STYLES /*| WS_TABSTOP*/ | SS_ICON,
|
2002-09-10 20:04:54 +00:00
|
|
|
0 },
|
|
|
|
{ "STATIC", // FIELD_BITMAP
|
2003-06-27 12:48:52 +00:00
|
|
|
DEFAULT_STYLES /*| WS_TABSTOP*/ | SS_BITMAP | SS_CENTERIMAGE,
|
2002-09-10 20:04:54 +00:00
|
|
|
0 },
|
|
|
|
{ "BUTTON", // FIELD_BROWSEBUTTON
|
2002-12-29 20:16:35 +00:00
|
|
|
DEFAULT_STYLES | WS_TABSTOP,
|
2002-09-10 20:04:54 +00:00
|
|
|
0 },
|
|
|
|
{ "BUTTON", // FIELD_CHECKBOX
|
2003-01-27 16:15:00 +00:00
|
|
|
DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTOCHECKBOX | BS_MULTILINE,
|
2002-09-10 20:04:54 +00:00
|
|
|
0 },
|
|
|
|
{ "BUTTON", // FIELD_RADIOBUTTON
|
2003-01-27 16:15:00 +00:00
|
|
|
DEFAULT_STYLES | WS_TABSTOP | BS_TEXT | BS_VCENTER | BS_AUTORADIOBUTTON | BS_MULTILINE,
|
2002-09-10 20:04:54 +00:00
|
|
|
0 },
|
|
|
|
{ "EDIT", // FIELD_TEXT
|
2003-01-27 16:15:00 +00:00
|
|
|
DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL,
|
2002-09-10 20:04:54 +00:00
|
|
|
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE },
|
|
|
|
{ "EDIT", // FIELD_FILEREQUEST
|
2003-01-27 16:15:00 +00:00
|
|
|
DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL,
|
2002-09-10 20:04:54 +00:00
|
|
|
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE },
|
|
|
|
{ "EDIT", // FIELD_DIRREQUEST
|
2003-01-27 16:15:00 +00:00
|
|
|
DEFAULT_STYLES | WS_TABSTOP | ES_AUTOHSCROLL,
|
2002-09-10 20:04:54 +00:00
|
|
|
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE },
|
|
|
|
{ "COMBOBOX", // FIELD_COMBOBOX
|
2002-11-14 21:21:45 +00:00
|
|
|
DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | WS_CLIPCHILDREN | CBS_AUTOHSCROLL | CBS_HASSTRINGS,
|
2002-09-10 20:04:54 +00:00
|
|
|
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE },
|
|
|
|
{ "LISTBOX", // FIELD_LISTBOX
|
2003-01-27 16:15:00 +00:00
|
|
|
DEFAULT_STYLES | WS_TABSTOP | WS_VSCROLL | LBS_DISABLENOSCROLL | LBS_HASSTRINGS | LBS_NOINTEGRALHEIGHT,
|
2002-12-21 11:24:42 +00:00
|
|
|
WS_EX_WINDOWEDGE | WS_EX_CLIENTEDGE },
|
|
|
|
{ "BUTTON", // FIELD_GROUPBOX
|
|
|
|
DEFAULT_STYLES | BS_GROUPBOX,
|
2003-06-16 18:49:23 +00:00
|
|
|
WS_EX_TRANSPARENT },
|
2003-07-07 21:08:26 +00:00
|
|
|
{ "BUTTON", // FIELD_LINK
|
|
|
|
DEFAULT_STYLES | WS_TABSTOP | BS_OWNERDRAW
|
2003-06-16 18:49:23 +00:00
|
|
|
},
|
2002-09-10 20:04:54 +00:00
|
|
|
};
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-01-20 13:57:30 +00:00
|
|
|
int nType = pFields[nIdx].nType;
|
|
|
|
|
2002-11-14 21:21:45 +00:00
|
|
|
#undef DEFAULT_STYLES
|
|
|
|
|
2003-01-20 13:57:30 +00:00
|
|
|
if (nType < 1 || nType > (sizeof(ClassTable) / sizeof(ClassTable[0])))
|
2002-09-10 20:04:54 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
DWORD dwStyle = ClassTable[pFields[nIdx].nType - 1].dwStyle;
|
|
|
|
DWORD dwExStyle = ClassTable[pFields[nIdx].nType - 1].dwExStyle;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-03-11 13:29:38 +00:00
|
|
|
// Convert from dialog units
|
2002-09-10 20:04:54 +00:00
|
|
|
|
|
|
|
RECT rect;
|
2002-12-14 00:10:29 +00:00
|
|
|
|
|
|
|
rect.left = MulDiv(pFields[nIdx].rect.left, baseUnitX, 4);
|
|
|
|
rect.right = MulDiv(pFields[nIdx].rect.right, baseUnitX, 4);
|
|
|
|
rect.top = MulDiv(pFields[nIdx].rect.top, baseUnitY, 8);
|
|
|
|
rect.bottom = MulDiv(pFields[nIdx].rect.bottom, baseUnitY, 8);
|
|
|
|
|
2002-12-21 11:24:42 +00:00
|
|
|
if (pFields[nIdx].rect.left < 0)
|
2002-09-10 20:04:54 +00:00
|
|
|
rect.left += dialog_r.right - dialog_r.left;
|
|
|
|
if (pFields[nIdx].rect.right < 0)
|
|
|
|
rect.right += dialog_r.right - dialog_r.left;
|
|
|
|
if (pFields[nIdx].rect.top < 0)
|
|
|
|
rect.top += dialog_r.bottom - dialog_r.top;
|
|
|
|
if (pFields[nIdx].rect.bottom < 0)
|
|
|
|
rect.bottom += dialog_r.bottom - dialog_r.top;
|
|
|
|
|
|
|
|
char *title = pFields[nIdx].pszText;
|
2003-01-20 13:57:30 +00:00
|
|
|
switch (nType) {
|
2002-09-10 20:04:54 +00:00
|
|
|
case FIELD_CHECKBOX:
|
|
|
|
case FIELD_RADIOBUTTON:
|
|
|
|
if (pFields[nIdx].nFlags & FLAG_RIGHT)
|
|
|
|
dwStyle |= BS_RIGHTBUTTON;
|
2002-08-02 10:01:35 +00:00
|
|
|
break;
|
|
|
|
case FIELD_FILEREQUEST:
|
|
|
|
case FIELD_DIRREQUEST:
|
2002-09-05 22:22:26 +00:00
|
|
|
case FIELD_TEXT:
|
2002-09-10 20:04:54 +00:00
|
|
|
if (pFields[nIdx].nFlags & FLAG_PASSWORD)
|
|
|
|
dwStyle |= ES_PASSWORD;
|
2003-05-30 13:35:47 +00:00
|
|
|
if (pFields[nIdx].nFlags & FLAG_ONLYNUMBERS)
|
|
|
|
dwStyle |= ES_NUMBER;
|
2003-06-10 13:18:07 +00:00
|
|
|
if (pFields[nIdx].nFlags & FLAG_MULTILINE)
|
|
|
|
{
|
|
|
|
dwStyle |= ES_MULTILINE | ES_AUTOHSCROLL | ES_AUTOVSCROLL;
|
|
|
|
ConvertNewLines(pFields[nIdx].pszState);
|
|
|
|
}
|
|
|
|
if ( pFields[nIdx].nFlags & FLAG_WANTRETURN )
|
|
|
|
dwStyle |= ES_WANTRETURN;
|
|
|
|
if (pFields[nIdx].nFlags & FLAG_VSCROLL)
|
|
|
|
dwStyle |= WS_VSCROLL;
|
|
|
|
if (pFields[nIdx].nFlags & FLAG_HSCROLL)
|
|
|
|
dwStyle |= WS_HSCROLL;
|
2003-06-11 23:57:24 +00:00
|
|
|
if (pFields[nIdx].nFlags & FLAG_READONLY)
|
2003-06-16 18:49:23 +00:00
|
|
|
dwStyle |= ES_READONLY;
|
2002-09-10 20:04:54 +00:00
|
|
|
title = pFields[nIdx].pszState;
|
2002-08-02 10:01:35 +00:00
|
|
|
break;
|
2002-09-05 22:22:26 +00:00
|
|
|
case FIELD_COMBOBOX:
|
2002-09-10 20:04:54 +00:00
|
|
|
dwStyle |= (pFields[nIdx].nFlags & FLAG_DROPLIST) ? CBS_DROPDOWNLIST : CBS_DROPDOWN;
|
|
|
|
title = pFields[nIdx].pszState;
|
2002-08-02 10:01:35 +00:00
|
|
|
break;
|
|
|
|
case FIELD_LISTBOX:
|
2003-04-03 13:17:54 +00:00
|
|
|
if (pFields[nIdx].nFlags & FLAG_EXTENDEDSEL)
|
2002-09-10 20:04:54 +00:00
|
|
|
dwStyle |= LBS_EXTENDEDSEL;
|
2003-04-03 13:17:54 +00:00
|
|
|
if (pFields[nIdx].nFlags & FLAG_MULTISELECT)
|
|
|
|
dwStyle |= LBS_MULTIPLESEL;
|
2002-08-02 10:01:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-01-03 22:33:16 +00:00
|
|
|
if (pFields[nIdx].nFlags & FLAG_DISABLED) dwStyle |= WS_DISABLED;
|
2003-01-04 13:02:17 +00:00
|
|
|
if (pFields[nIdx].nFlags & FLAG_GROUP) dwStyle |= WS_GROUP;
|
|
|
|
if (pFields[nIdx].nFlags & FLAG_NOTABSTOP) dwStyle &= ~WS_TABSTOP;
|
2003-01-03 22:26:08 +00:00
|
|
|
|
2002-11-08 16:51:26 +00:00
|
|
|
HWND hwCtrl = pFields[nIdx].hwnd = CreateWindowEx(
|
2002-08-26 13:27:51 +00:00
|
|
|
dwExStyle,
|
2002-09-10 20:04:54 +00:00
|
|
|
ClassTable[pFields[nIdx].nType - 1].pszClass,
|
2002-08-26 13:27:51 +00:00
|
|
|
title,
|
|
|
|
dwStyle,
|
2002-09-10 20:04:54 +00:00
|
|
|
rect.left,
|
|
|
|
rect.top,
|
|
|
|
rect.right - rect.left,
|
|
|
|
rect.bottom - rect.top,
|
2002-08-26 13:27:51 +00:00
|
|
|
hConfigWindow,
|
|
|
|
(HMENU)pFields[nIdx].nControlID,
|
|
|
|
m_hInstance,
|
|
|
|
NULL
|
|
|
|
);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-11-08 16:51:26 +00:00
|
|
|
if (hwCtrl) {
|
2002-08-02 10:01:35 +00:00
|
|
|
// Sets the font of IO window to be the same as the main window
|
2002-11-08 16:51:26 +00:00
|
|
|
SendMessage(hwCtrl, WM_SETFONT, (WPARAM)hFont, TRUE);
|
2002-08-02 10:01:35 +00:00
|
|
|
// make sure we created the window, then set additional attributes
|
2003-07-29 20:25:42 +00:00
|
|
|
//if (pFields[nIdx].nMaxLength > 0) {
|
2003-01-20 13:57:30 +00:00
|
|
|
switch (nType) {
|
2002-08-02 10:01:35 +00:00
|
|
|
case FIELD_TEXT:
|
2003-07-29 20:25:42 +00:00
|
|
|
SendMessage(hwCtrl, WM_SETTEXT, 0, (LPARAM)title);
|
2002-08-02 10:01:35 +00:00
|
|
|
case FIELD_DIRREQUEST:
|
2002-09-05 22:22:26 +00:00
|
|
|
case FIELD_FILEREQUEST:
|
2002-11-08 16:51:26 +00:00
|
|
|
SendMessage(hwCtrl, EM_LIMITTEXT, (WPARAM)pFields[nIdx].nMaxLength, (LPARAM)0);
|
2002-08-02 10:01:35 +00:00
|
|
|
break;
|
2002-09-05 22:22:26 +00:00
|
|
|
}
|
2003-07-29 20:25:42 +00:00
|
|
|
//}
|
2003-01-20 13:57:30 +00:00
|
|
|
if ((nType == FIELD_CHECKBOX) || (nType == FIELD_RADIOBUTTON)) {
|
2002-08-02 10:01:35 +00:00
|
|
|
if (pFields[nIdx].pszState[0] == '1')
|
|
|
|
{
|
2002-11-08 16:51:26 +00:00
|
|
|
SendMessage(hwCtrl, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
2003-01-19 16:56:10 +00:00
|
|
|
} else if (pFields[nIdx].pszListItems && (
|
2003-01-20 13:57:30 +00:00
|
|
|
((nType == FIELD_COMBOBOX) && (nAddMsg = CB_ADDSTRING)
|
2003-01-19 16:56:10 +00:00
|
|
|
&& (nFindMsg = CB_FINDSTRINGEXACT) && (nSetSelMsg = CB_SETCURSEL)) ||
|
2003-01-20 13:57:30 +00:00
|
|
|
((nType == FIELD_LISTBOX ) && (nAddMsg = LB_ADDSTRING)
|
2003-01-19 16:56:10 +00:00
|
|
|
&& (nFindMsg = LB_FINDSTRINGEXACT) && (nSetSelMsg = LB_SETCURSEL))
|
|
|
|
)) {
|
2002-08-02 10:01:35 +00:00
|
|
|
// if this is a listbox or combobox, we need to add the list items.
|
2003-04-18 20:01:23 +00:00
|
|
|
char *pszStart, *pszEnd, *pszList;
|
|
|
|
pszStart = pszEnd = pszList = STRDUP(pFields[nIdx].pszListItems);
|
2002-08-02 10:01:35 +00:00
|
|
|
while ((*pszEnd) && (*pszStart)) {
|
|
|
|
if (*pszEnd == '|') {
|
|
|
|
*pszEnd = '\0';
|
|
|
|
if (pszEnd > pszStart) {
|
2002-11-08 16:51:26 +00:00
|
|
|
SendMessage(hwCtrl, nAddMsg, 0, (LPARAM)pszStart);
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
// jump to the next item, skip any redundant | characters
|
|
|
|
do { pszEnd++; } while (*pszEnd == '|');
|
|
|
|
pszStart = pszEnd;
|
|
|
|
}
|
|
|
|
pszEnd++;
|
|
|
|
}
|
2003-04-18 20:01:23 +00:00
|
|
|
FREE(pszList);
|
2002-08-02 10:01:35 +00:00
|
|
|
if (pFields[nIdx].pszState) {
|
2003-04-03 13:17:54 +00:00
|
|
|
if (pFields[nIdx].nFlags & (FLAG_MULTISELECT|FLAG_EXTENDEDSEL) && nFindMsg == LB_FINDSTRINGEXACT) {
|
2003-01-19 16:56:10 +00:00
|
|
|
SendMessage(hwCtrl, LB_SETSEL, FALSE, -1);
|
|
|
|
pszStart = pszEnd = pFields[nIdx].pszState;
|
|
|
|
while (*pszStart) {
|
|
|
|
char cLast = *pszEnd;
|
|
|
|
if (*pszEnd == '|') *pszEnd = '\0';
|
|
|
|
if (!*pszEnd) {
|
|
|
|
if (pszEnd > pszStart) {
|
|
|
|
int nItem = SendMessage(hwCtrl, nFindMsg, -1, (LPARAM)pszStart);
|
|
|
|
if (nItem != CB_ERR) { // CB_ERR == LB_ERR == -1
|
|
|
|
SendMessage(hwCtrl, LB_SETSEL, TRUE, nItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cLast) {
|
|
|
|
do {
|
|
|
|
pszEnd++;
|
|
|
|
} while (*pszEnd == '|');
|
|
|
|
}
|
|
|
|
pszStart = pszEnd;
|
|
|
|
}
|
|
|
|
pszEnd++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int nItem = SendMessage(hwCtrl, nFindMsg, -1, (LPARAM)pFields[nIdx].pszState);
|
|
|
|
if (nItem != CB_ERR) { // CB_ERR == LB_ERR == -1
|
|
|
|
SendMessage(hwCtrl, nSetSelMsg, nItem, 0);
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-20 13:57:30 +00:00
|
|
|
} else if (nType == FIELD_BITMAP || nType == FIELD_ICON) {
|
|
|
|
WPARAM nImageType = nType == FIELD_BITMAP ? IMAGE_BITMAP : IMAGE_ICON;
|
2003-03-23 17:12:14 +00:00
|
|
|
LPARAM nImage = 0;
|
2003-03-26 14:37:20 +00:00
|
|
|
if (pFields[nIdx].pszText) {
|
2003-03-23 17:12:14 +00:00
|
|
|
pFields[nIdx].hImage = LoadImage(
|
2002-09-04 18:14:34 +00:00
|
|
|
0,
|
|
|
|
pFields[nIdx].pszText,
|
|
|
|
nImageType,
|
2003-06-27 12:48:52 +00:00
|
|
|
(pFields[nIdx].nFlags & FLAG_RESIZETOFIT)
|
|
|
|
? (rect.right - rect.left)
|
|
|
|
: 0,
|
|
|
|
(pFields[nIdx].nFlags & FLAG_RESIZETOFIT)
|
|
|
|
? (rect.bottom - rect.top)
|
|
|
|
: 0,
|
2002-09-04 18:14:34 +00:00
|
|
|
LR_LOADFROMFILE
|
2003-03-23 17:12:14 +00:00
|
|
|
);
|
|
|
|
nImage = (LPARAM)pFields[nIdx].hImage;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nImage = (LPARAM)LoadIcon(GetModuleHandle(0), MAKEINTRESOURCE(103));
|
|
|
|
SendMessage(
|
|
|
|
hwCtrl,
|
|
|
|
STM_SETIMAGE,
|
|
|
|
nImageType,
|
|
|
|
nImage
|
2002-09-04 18:14:34 +00:00
|
|
|
);
|
2003-07-05 16:55:54 +00:00
|
|
|
}
|
|
|
|
#ifdef IO_ENABLE_LINK
|
|
|
|
else if (nType == FIELD_LINK) {
|
2003-06-16 18:49:23 +00:00
|
|
|
pFields[nIdx].nParentIdx = SetWindowLong(hwCtrl, GWL_WNDPROC, (long)StaticLINKWindowProc);
|
2002-09-04 18:14:34 +00:00
|
|
|
}
|
2003-07-05 16:55:54 +00:00
|
|
|
#endif
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pszTitle)
|
|
|
|
{
|
|
|
|
GetWindowText(hMainWindow,old_title,sizeof(old_title));
|
|
|
|
SetWindowText(hMainWindow,pszTitle);
|
|
|
|
}
|
2003-06-08 13:41:48 +00:00
|
|
|
pFilenameStackEntry = *g_stacktop;
|
2003-02-14 18:51:11 +00:00
|
|
|
*g_stacktop = (*g_stacktop)->next;
|
2002-11-01 20:34:55 +00:00
|
|
|
char tmp[32];
|
|
|
|
wsprintf(tmp,"%d",hConfigWindow);
|
|
|
|
pushstring(tmp);
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-11-01 20:34:55 +00:00
|
|
|
void showCfgDlg()
|
|
|
|
{
|
2003-03-18 15:45:25 +00:00
|
|
|
lpWndProcOld = (void *) SetWindowLong(hMainWindow,DWL_DLGPROC,(long)ParentWndProc);
|
2002-11-08 16:51:26 +00:00
|
|
|
|
2003-07-10 00:28:05 +00:00
|
|
|
// Tell NSIS to remove old inner dialog and pass handle of the new inner dialog
|
|
|
|
SendMessage(hMainWindow, WM_NOTIFY_CUSTOM_READY, (WPARAM)hConfigWindow, 0);
|
2002-08-02 10:01:35 +00:00
|
|
|
ShowWindow(hConfigWindow, SW_SHOWNA);
|
2002-11-30 13:15:49 +00:00
|
|
|
SetFocus(hNextButton);
|
2002-11-11 16:06:23 +00:00
|
|
|
|
2002-11-01 20:34:55 +00:00
|
|
|
g_done=0;
|
|
|
|
|
2002-08-02 10:01:35 +00:00
|
|
|
while (!g_done) {
|
|
|
|
MSG msg;
|
|
|
|
int nResult = GetMessage(&msg, NULL, 0, 0);
|
|
|
|
if (!IsDialogMessage(hConfigWindow,&msg) && !IsDialogMessage(hMainWindow,&msg) && !TranslateMessage(&msg))
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
// we don't save settings on cancel since that means your installer will likely
|
|
|
|
// quit soon, which means the ini might get flushed late and cause crap. :) anwyay.
|
2002-09-26 22:47:21 +00:00
|
|
|
if (!g_is_cancel) SaveSettings();
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
if (lpWndProcOld)
|
2003-03-18 15:45:25 +00:00
|
|
|
SetWindowLong(hMainWindow,DWL_DLGPROC,(long)lpWndProcOld);
|
2002-08-02 10:01:35 +00:00
|
|
|
DestroyWindow(hConfigWindow);
|
2002-11-08 16:51:26 +00:00
|
|
|
if (was_ok_enabled) EnableWindow(hNextButton,0);
|
|
|
|
SetWindowText(hCancelButton,old_cancel);
|
|
|
|
SetWindowText(hNextButton,old_ok);
|
|
|
|
SetWindowText(hBackButton,old_back);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-11-15 12:53:08 +00:00
|
|
|
// by ORTIM: 13-August-2002
|
|
|
|
if (bCancelEnabled!=0xFFFF0000) EnableWindow(hCancelButton,old_cancel_enabled);
|
|
|
|
if (bCancelShow!=0xFFFF0000) ShowWindow(hCancelButton,old_cancel_visible?SW_SHOWNA:SW_HIDE);
|
2002-08-02 10:01:35 +00:00
|
|
|
|
|
|
|
if (pszTitle) SetWindowText(hMainWindow,old_title);
|
|
|
|
|
|
|
|
if (cw_vis) ShowWindow(childwnd,SW_SHOWNA);
|
|
|
|
|
2003-06-08 13:41:48 +00:00
|
|
|
FREE(pFilenameStackEntry);
|
2002-08-02 10:01:35 +00:00
|
|
|
FREE(pszTitle);
|
|
|
|
FREE(pszCancelButtonText);
|
|
|
|
FREE(pszNextButtonText);
|
|
|
|
FREE(pszBackButtonText);
|
2003-06-02 14:26:15 +00:00
|
|
|
|
|
|
|
int i = nNumFields;
|
|
|
|
while (i--) {
|
|
|
|
FREE(pFields[i].pszText);
|
|
|
|
FREE(pFields[i].pszState);
|
|
|
|
FREE(pFields[i].pszListItems);
|
|
|
|
FREE(pFields[i].pszFilter);
|
|
|
|
FREE(pFields[i].pszRoot);
|
|
|
|
if (pFields[i].nType == FIELD_BITMAP) {
|
|
|
|
DeleteObject(pFields[i].hImage);
|
2003-03-26 14:37:20 +00:00
|
|
|
}
|
2003-06-02 14:26:15 +00:00
|
|
|
if (pFields[i].nType == FIELD_ICON) {
|
|
|
|
DestroyIcon((HICON)pFields[i].hImage);
|
2003-03-26 14:37:20 +00:00
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
FREE(pFields);
|
2002-09-26 22:47:21 +00:00
|
|
|
|
|
|
|
pushstring(g_is_cancel?"cancel":g_is_back?"back":"success");
|
2002-08-02 10:01:35 +00:00
|
|
|
}
|
|
|
|
|
2002-11-01 20:34:55 +00:00
|
|
|
int initCalled;
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-11-01 20:34:55 +00:00
|
|
|
extern "C" void __declspec(dllexport) dialog(HWND hwndParent, int string_size,
|
|
|
|
char *variables, stack_t **stacktop)
|
|
|
|
{
|
|
|
|
hMainWindow=hwndParent;
|
|
|
|
EXDLL_INIT();
|
|
|
|
if (initCalled) {
|
|
|
|
pushstring("error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (createCfgDlg()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
popstring(NULL);
|
|
|
|
showCfgDlg();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void __declspec(dllexport) initDialog(HWND hwndParent, int string_size,
|
|
|
|
char *variables, stack_t **stacktop)
|
|
|
|
{
|
|
|
|
hMainWindow=hwndParent;
|
|
|
|
EXDLL_INIT();
|
|
|
|
if (initCalled) {
|
|
|
|
pushstring("error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
initCalled++;
|
|
|
|
createCfgDlg();
|
|
|
|
}
|
|
|
|
|
|
|
|
extern "C" void __declspec(dllexport) show(HWND hwndParent, int string_size,
|
|
|
|
char *variables, stack_t **stacktop)
|
|
|
|
{
|
|
|
|
EXDLL_INIT();
|
|
|
|
if (!initCalled) {
|
|
|
|
pushstring("error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
initCalled--;
|
|
|
|
showCfgDlg();
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2003-08-05 15:05:49 +00:00
|
|
|
#ifdef _DEBUG
|
|
|
|
#ifndef DEBUG
|
|
|
|
#define DEBUG
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2002-12-16 16:53:26 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
extern "C" BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
|
|
|
#else
|
2002-08-02 10:01:35 +00:00
|
|
|
extern "C" BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
|
2002-12-16 16:53:26 +00:00
|
|
|
#endif
|
2002-08-02 10:01:35 +00:00
|
|
|
{
|
|
|
|
m_hInstance=(HINSTANCE) hInst;
|
2002-11-08 16:51:26 +00:00
|
|
|
if (ul_reason_for_call == DLL_THREAD_DETACH || ul_reason_for_call == DLL_PROCESS_DETACH)
|
|
|
|
DestroyWindow(hConfigWindow);
|
2002-08-02 10:01:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-09-05 22:22:26 +00:00
|
|
|
int LookupToken(TableEntry* psTable_, char* pszToken_)
|
|
|
|
{
|
|
|
|
for (int i = 0; psTable_[i].pszName; i++)
|
|
|
|
if (!stricmp(pszToken_, psTable_[i].pszName))
|
|
|
|
return psTable_[i].nValue;
|
|
|
|
return 0;
|
|
|
|
}
|
2002-08-02 10:01:35 +00:00
|
|
|
|
2002-09-30 22:22:16 +00:00
|
|
|
int LookupTokens(TableEntry* psTable_, char* pszTokens_)
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
char *pszStart = pszTokens_;
|
|
|
|
char *pszEnd = pszTokens_;
|
|
|
|
for (;;) {
|
|
|
|
if (*pszEnd == '\0') {
|
|
|
|
n |= LookupToken(psTable_, pszStart);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*pszEnd == '|') {
|
|
|
|
*pszEnd = '\0';
|
|
|
|
n |= LookupToken(psTable_, pszStart);
|
|
|
|
*pszEnd = '|';
|
|
|
|
pszStart = pszEnd + 1;
|
|
|
|
}
|
|
|
|
pszEnd++;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
2003-03-17 13:46:13 +00:00
|
|
|
|
|
|
|
void ConvertNewLines(char *str) {
|
|
|
|
char *p1, *p2;
|
|
|
|
if (!str) return;
|
|
|
|
for (p1=p2=str; *p1; p1++, p2++) {
|
|
|
|
if (*p1 == '\\') {
|
|
|
|
switch (p1[1]) {
|
|
|
|
case 'n':
|
|
|
|
*p2 = '\n';
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
*p2 = '\r';
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
*p2 = '\t';
|
|
|
|
break;
|
|
|
|
case '\\':
|
|
|
|
*p2 = '\\';
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
p1--;
|
|
|
|
p2--;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
p1++;
|
|
|
|
}
|
|
|
|
else *p2 = *p1;
|
|
|
|
}
|
|
|
|
*p2 = 0;
|
2003-06-16 18:49:23 +00:00
|
|
|
}
|
|
|
|
|