comdlg32: Consolidate file dialog initialization to avoid duplication.
Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com> Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
aef84332a2
commit
c23a91cb63
|
@ -318,23 +318,23 @@ static BOOL GetFileName95(FileOpenDlgInfos *fodInfos)
|
||||||
return lRes;
|
return lRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
static WCHAR *heap_strdupAtoW(const char *str)
|
||||||
* GetFileDialog95A
|
{
|
||||||
*
|
WCHAR *ret;
|
||||||
* Call GetFileName95 with this structure and clean the memory.
|
INT len;
|
||||||
*
|
|
||||||
* IN : The OPENFILENAMEA initialisation structure passed to
|
if (!str)
|
||||||
* GetOpenFileNameA win api function (see filedlg.c)
|
return NULL;
|
||||||
*/
|
|
||||||
static BOOL GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
|
len = MultiByteToWideChar(CP_ACP, 0, str, -1, 0, 0);
|
||||||
|
ret = MemAlloc(len * sizeof(WCHAR));
|
||||||
|
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void init_filedlg_infoW(OPENFILENAMEW *ofn, FileOpenDlgInfos *info)
|
||||||
{
|
{
|
||||||
BOOL ret;
|
|
||||||
FileOpenDlgInfos fodInfos;
|
|
||||||
LPSTR lpstrSavDir = NULL;
|
|
||||||
LPWSTR title = NULL;
|
|
||||||
LPWSTR defext = NULL;
|
|
||||||
LPWSTR filter = NULL;
|
|
||||||
LPWSTR customfilter = NULL;
|
|
||||||
INITCOMMONCONTROLSEX icc;
|
INITCOMMONCONTROLSEX icc;
|
||||||
|
|
||||||
/* Initialize ComboBoxEx32 */
|
/* Initialize ComboBoxEx32 */
|
||||||
|
@ -345,208 +345,134 @@ static BOOL GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType)
|
||||||
/* Initialize CommDlgExtendedError() */
|
/* Initialize CommDlgExtendedError() */
|
||||||
COMDLG32_SetCommDlgExtendedError(0);
|
COMDLG32_SetCommDlgExtendedError(0);
|
||||||
|
|
||||||
/* Initialize FileOpenDlgInfos structure */
|
memset(info, 0, sizeof(*info));
|
||||||
ZeroMemory(&fodInfos, sizeof(FileOpenDlgInfos));
|
|
||||||
|
|
||||||
/* Pass in the original ofn */
|
/* Pass in the original ofn */
|
||||||
fodInfos.ofnInfos = (LPOPENFILENAMEW)ofn;
|
info->ofnInfos = ofn;
|
||||||
|
|
||||||
/* save current directory */
|
info->title = ofn->lpstrTitle;
|
||||||
if (ofn->Flags & OFN_NOCHANGEDIR)
|
info->defext = ofn->lpstrDefExt;
|
||||||
|
info->filter = ofn->lpstrFilter;
|
||||||
|
info->customfilter = ofn->lpstrCustomFilter;
|
||||||
|
|
||||||
|
if (ofn->lpstrFile)
|
||||||
{
|
{
|
||||||
lpstrSavDir = MemAlloc(MAX_PATH);
|
info->filename = MemAlloc(ofn->nMaxFile * sizeof(WCHAR));
|
||||||
GetCurrentDirectoryA(MAX_PATH, lpstrSavDir);
|
lstrcpynW(info->filename, ofn->lpstrFile, ofn->nMaxFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
fodInfos.unicode = FALSE;
|
if (ofn->lpstrInitialDir)
|
||||||
|
|
||||||
/* convert all the input strings to unicode */
|
|
||||||
if(ofn->lpstrInitialDir)
|
|
||||||
{
|
{
|
||||||
DWORD len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrInitialDir, -1, NULL, 0 );
|
DWORD len = ExpandEnvironmentStringsW(ofn->lpstrInitialDir, NULL, 0);
|
||||||
fodInfos.initdir = MemAlloc((len+1)*sizeof(WCHAR));
|
if (len)
|
||||||
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrInitialDir, -1, fodInfos.initdir, len);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fodInfos.initdir = NULL;
|
|
||||||
|
|
||||||
if(ofn->lpstrFile)
|
|
||||||
{
|
{
|
||||||
fodInfos.filename = MemAlloc(ofn->nMaxFile*sizeof(WCHAR));
|
info->initdir = MemAlloc(len * sizeof(WCHAR));
|
||||||
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrFile, -1, fodInfos.filename, ofn->nMaxFile);
|
ExpandEnvironmentStringsW(ofn->lpstrInitialDir, info->initdir, len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
fodInfos.filename = NULL;
|
|
||||||
|
|
||||||
if(ofn->lpstrDefExt)
|
info->unicode = TRUE;
|
||||||
{
|
}
|
||||||
DWORD len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrDefExt, -1, NULL, 0 );
|
|
||||||
defext = MemAlloc((len+1)*sizeof(WCHAR));
|
|
||||||
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrDefExt, -1, defext, len);
|
|
||||||
}
|
|
||||||
fodInfos.defext = defext;
|
|
||||||
|
|
||||||
if(ofn->lpstrTitle)
|
static void init_filedlg_infoA(OPENFILENAMEA *ofn, FileOpenDlgInfos *info)
|
||||||
{
|
{
|
||||||
DWORD len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrTitle, -1, NULL, 0 );
|
OPENFILENAMEW ofnW;
|
||||||
title = MemAlloc((len+1)*sizeof(WCHAR));
|
|
||||||
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrTitle, -1, title, len);
|
ofnW = *(OPENFILENAMEW *)ofn;
|
||||||
}
|
|
||||||
fodInfos.title = title;
|
ofnW.lpstrInitialDir = heap_strdupAtoW(ofn->lpstrInitialDir);
|
||||||
|
ofnW.lpstrFile = heap_strdupAtoW(ofn->lpstrFile);
|
||||||
|
ofnW.lpstrDefExt = heap_strdupAtoW(ofn->lpstrDefExt);
|
||||||
|
ofnW.lpstrTitle = heap_strdupAtoW(ofn->lpstrTitle);
|
||||||
|
|
||||||
if (ofn->lpstrFilter)
|
if (ofn->lpstrFilter)
|
||||||
{
|
{
|
||||||
LPCSTR s;
|
|
||||||
int n, len;
|
int n, len;
|
||||||
|
LPCSTR s;
|
||||||
|
|
||||||
/* filter is a list... title\0ext\0......\0\0 */
|
/* filter is a list... title\0ext\0......\0\0 */
|
||||||
s = ofn->lpstrFilter;
|
s = ofn->lpstrFilter;
|
||||||
while (*s) s = s+strlen(s)+1;
|
while (*s) s = s+strlen(s)+1;
|
||||||
s++;
|
s++;
|
||||||
n = s - ofn->lpstrFilter;
|
n = s - ofn->lpstrFilter;
|
||||||
len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrFilter, n, NULL, 0 );
|
len = MultiByteToWideChar(CP_ACP, 0, ofn->lpstrFilter, n, NULL, 0);
|
||||||
filter = MemAlloc(len*sizeof(WCHAR));
|
ofnW.lpstrFilter = MemAlloc(len * sizeof(WCHAR));
|
||||||
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrFilter, n, filter, len );
|
MultiByteToWideChar(CP_ACP, 0, ofn->lpstrFilter, n, (WCHAR *)ofnW.lpstrFilter, len);
|
||||||
}
|
}
|
||||||
fodInfos.filter = filter;
|
|
||||||
|
|
||||||
/* convert lpstrCustomFilter */
|
/* convert lpstrCustomFilter */
|
||||||
if (ofn->lpstrCustomFilter)
|
if (ofn->lpstrCustomFilter)
|
||||||
{
|
{
|
||||||
LPCSTR s;
|
|
||||||
int n, len;
|
int n, len;
|
||||||
|
LPCSTR s;
|
||||||
|
|
||||||
/* customfilter contains a pair of strings... title\0ext\0 */
|
/* customfilter contains a pair of strings... title\0ext\0 */
|
||||||
s = ofn->lpstrCustomFilter;
|
s = ofn->lpstrCustomFilter;
|
||||||
if (*s) s = s+strlen(s)+1;
|
if (*s) s = s+strlen(s)+1;
|
||||||
if (*s) s = s+strlen(s)+1;
|
if (*s) s = s+strlen(s)+1;
|
||||||
n = s - ofn->lpstrCustomFilter;
|
n = s - ofn->lpstrCustomFilter;
|
||||||
len = MultiByteToWideChar( CP_ACP, 0, ofn->lpstrCustomFilter, n, NULL, 0 );
|
len = MultiByteToWideChar(CP_ACP, 0, ofn->lpstrCustomFilter, n, NULL, 0);
|
||||||
customfilter = MemAlloc(len*sizeof(WCHAR));
|
ofnW.lpstrCustomFilter = MemAlloc(len * sizeof(WCHAR));
|
||||||
MultiByteToWideChar( CP_ACP, 0, ofn->lpstrCustomFilter, n, customfilter, len );
|
MultiByteToWideChar(CP_ACP, 0, ofn->lpstrCustomFilter, n, ofnW.lpstrCustomFilter, len);
|
||||||
}
|
|
||||||
fodInfos.customfilter = customfilter;
|
|
||||||
|
|
||||||
/* Initialize the dialog property */
|
|
||||||
fodInfos.DlgInfos.dwDlgProp = 0;
|
|
||||||
fodInfos.DlgInfos.hwndCustomDlg = NULL;
|
|
||||||
|
|
||||||
switch(iDlgType)
|
|
||||||
{
|
|
||||||
case OPEN_DIALOG :
|
|
||||||
ret = GetFileName95(&fodInfos);
|
|
||||||
break;
|
|
||||||
case SAVE_DIALOG :
|
|
||||||
fodInfos.DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
|
|
||||||
ret = GetFileName95(&fodInfos);
|
|
||||||
break;
|
|
||||||
default :
|
|
||||||
ret = FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpstrSavDir)
|
init_filedlg_infoW(&ofnW, info);
|
||||||
{
|
|
||||||
SetCurrentDirectoryA(lpstrSavDir);
|
|
||||||
MemFree(lpstrSavDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
MemFree(title);
|
/* fixup A-specific fields */
|
||||||
MemFree(defext);
|
info->ofnInfos = (OPENFILENAMEW *)ofn;
|
||||||
MemFree(filter);
|
info->unicode = FALSE;
|
||||||
MemFree(customfilter);
|
|
||||||
MemFree(fodInfos.initdir);
|
|
||||||
MemFree(fodInfos.filename);
|
|
||||||
|
|
||||||
TRACE("selected file: %s\n",ofn->lpstrFile);
|
/* free what was duplicated */
|
||||||
|
MemFree((WCHAR *)ofnW.lpstrInitialDir);
|
||||||
return ret;
|
MemFree((WCHAR *)ofnW.lpstrFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* GetFileDialog95W
|
* GetFileDialog95
|
||||||
*
|
*
|
||||||
* Copy the OPENFILENAMEW structure in a FileOpenDlgInfos structure.
|
|
||||||
* Call GetFileName95 with this structure and clean the memory.
|
* Call GetFileName95 with this structure and clean the memory.
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
static BOOL GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType)
|
static BOOL GetFileDialog95(FileOpenDlgInfos *info, UINT dlg_type)
|
||||||
{
|
{
|
||||||
|
WCHAR *current_dir = NULL;
|
||||||
BOOL ret;
|
BOOL ret;
|
||||||
FileOpenDlgInfos fodInfos;
|
|
||||||
LPWSTR lpstrSavDir = NULL;
|
|
||||||
INITCOMMONCONTROLSEX icc;
|
|
||||||
|
|
||||||
/* Initialize ComboBoxEx32 */
|
|
||||||
icc.dwSize = sizeof(icc);
|
|
||||||
icc.dwICC = ICC_USEREX_CLASSES;
|
|
||||||
InitCommonControlsEx(&icc);
|
|
||||||
|
|
||||||
/* Initialize CommDlgExtendedError() */
|
|
||||||
COMDLG32_SetCommDlgExtendedError(0);
|
|
||||||
|
|
||||||
/* Initialize FileOpenDlgInfos structure */
|
|
||||||
ZeroMemory(&fodInfos, sizeof(FileOpenDlgInfos));
|
|
||||||
|
|
||||||
/* Pass in the original ofn */
|
|
||||||
fodInfos.ofnInfos = ofn;
|
|
||||||
|
|
||||||
fodInfos.title = ofn->lpstrTitle;
|
|
||||||
fodInfos.defext = ofn->lpstrDefExt;
|
|
||||||
fodInfos.filter = ofn->lpstrFilter;
|
|
||||||
fodInfos.customfilter = ofn->lpstrCustomFilter;
|
|
||||||
|
|
||||||
/* convert string arguments, save others */
|
|
||||||
if(ofn->lpstrFile)
|
|
||||||
{
|
|
||||||
fodInfos.filename = MemAlloc(ofn->nMaxFile*sizeof(WCHAR));
|
|
||||||
lstrcpynW(fodInfos.filename,ofn->lpstrFile,ofn->nMaxFile);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fodInfos.filename = NULL;
|
|
||||||
|
|
||||||
fodInfos.initdir = NULL;
|
|
||||||
if(ofn->lpstrInitialDir)
|
|
||||||
{
|
|
||||||
/* fodInfos.initdir = strdupW(ofn->lpstrInitialDir); */
|
|
||||||
DWORD len = ExpandEnvironmentStringsW(ofn->lpstrInitialDir, NULL, 0);
|
|
||||||
if (len)
|
|
||||||
{
|
|
||||||
fodInfos.initdir = MemAlloc(len * sizeof(WCHAR));
|
|
||||||
ExpandEnvironmentStringsW(ofn->lpstrInitialDir, fodInfos.initdir, len);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* save current directory */
|
/* save current directory */
|
||||||
if (ofn->Flags & OFN_NOCHANGEDIR)
|
if (info->ofnInfos->Flags & OFN_NOCHANGEDIR)
|
||||||
{
|
{
|
||||||
lpstrSavDir = MemAlloc(MAX_PATH*sizeof(WCHAR));
|
current_dir = MemAlloc(MAX_PATH * sizeof(WCHAR));
|
||||||
GetCurrentDirectoryW(MAX_PATH, lpstrSavDir);
|
GetCurrentDirectoryW(MAX_PATH, current_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
fodInfos.unicode = TRUE;
|
switch (dlg_type)
|
||||||
|
|
||||||
switch(iDlgType)
|
|
||||||
{
|
{
|
||||||
case OPEN_DIALOG :
|
case OPEN_DIALOG:
|
||||||
ret = GetFileName95(&fodInfos);
|
ret = GetFileName95(info);
|
||||||
break;
|
break;
|
||||||
case SAVE_DIALOG :
|
case SAVE_DIALOG:
|
||||||
fodInfos.DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
|
info->DlgInfos.dwDlgProp |= FODPROP_SAVEDLG;
|
||||||
ret = GetFileName95(&fodInfos);
|
ret = GetFileName95(info);
|
||||||
break;
|
break;
|
||||||
default :
|
default:
|
||||||
ret = FALSE;
|
ret = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lpstrSavDir)
|
if (current_dir)
|
||||||
{
|
{
|
||||||
SetCurrentDirectoryW(lpstrSavDir);
|
SetCurrentDirectoryW(current_dir);
|
||||||
MemFree(lpstrSavDir);
|
MemFree(current_dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* restore saved IN arguments and convert OUT arguments back */
|
if (!info->unicode)
|
||||||
MemFree(fodInfos.filename);
|
{
|
||||||
MemFree(fodInfos.initdir);
|
MemFree((WCHAR *)info->defext);
|
||||||
|
MemFree((WCHAR *)info->title);
|
||||||
|
MemFree((WCHAR *)info->filter);
|
||||||
|
MemFree((WCHAR *)info->customfilter);
|
||||||
|
}
|
||||||
|
|
||||||
|
MemFree(info->filename);
|
||||||
|
MemFree(info->initdir);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4080,8 +4006,7 @@ static inline BOOL is_win16_looks(DWORD flags)
|
||||||
* FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
|
* FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI GetOpenFileNameA(
|
BOOL WINAPI GetOpenFileNameA(OPENFILENAMEA *ofn)
|
||||||
LPOPENFILENAMEA ofn) /* [in/out] address of init structure */
|
|
||||||
{
|
{
|
||||||
TRACE("flags %08x\n", ofn->Flags);
|
TRACE("flags %08x\n", ofn->Flags);
|
||||||
|
|
||||||
|
@ -4098,7 +4023,12 @@ BOOL WINAPI GetOpenFileNameA(
|
||||||
if (is_win16_looks(ofn->Flags))
|
if (is_win16_looks(ofn->Flags))
|
||||||
return GetFileName31A(ofn, OPEN_DIALOG);
|
return GetFileName31A(ofn, OPEN_DIALOG);
|
||||||
else
|
else
|
||||||
return GetFileDialog95A(ofn, OPEN_DIALOG);
|
{
|
||||||
|
FileOpenDlgInfos info;
|
||||||
|
|
||||||
|
init_filedlg_infoA(ofn, &info);
|
||||||
|
return GetFileDialog95(&info, OPEN_DIALOG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
@ -4111,8 +4041,7 @@ BOOL WINAPI GetOpenFileNameA(
|
||||||
* FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
|
* FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI GetOpenFileNameW(
|
BOOL WINAPI GetOpenFileNameW(OPENFILENAMEW *ofn)
|
||||||
LPOPENFILENAMEW ofn) /* [in/out] address of init structure */
|
|
||||||
{
|
{
|
||||||
TRACE("flags %08x\n", ofn->Flags);
|
TRACE("flags %08x\n", ofn->Flags);
|
||||||
|
|
||||||
|
@ -4129,7 +4058,12 @@ BOOL WINAPI GetOpenFileNameW(
|
||||||
if (is_win16_looks(ofn->Flags))
|
if (is_win16_looks(ofn->Flags))
|
||||||
return GetFileName31W(ofn, OPEN_DIALOG);
|
return GetFileName31W(ofn, OPEN_DIALOG);
|
||||||
else
|
else
|
||||||
return GetFileDialog95W(ofn, OPEN_DIALOG);
|
{
|
||||||
|
FileOpenDlgInfos info;
|
||||||
|
|
||||||
|
init_filedlg_infoW(ofn, &info);
|
||||||
|
return GetFileDialog95(&info, OPEN_DIALOG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4143,8 +4077,7 @@ BOOL WINAPI GetOpenFileNameW(
|
||||||
* FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
|
* FALSE on cancel, error, close or filename-does-not-fit-in-buffer.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
BOOL WINAPI GetSaveFileNameA(
|
BOOL WINAPI GetSaveFileNameA(OPENFILENAMEA *ofn)
|
||||||
LPOPENFILENAMEA ofn) /* [in/out] address of init structure */
|
|
||||||
{
|
{
|
||||||
if (!valid_struct_size( ofn->lStructSize ))
|
if (!valid_struct_size( ofn->lStructSize ))
|
||||||
{
|
{
|
||||||
|
@ -4155,7 +4088,12 @@ BOOL WINAPI GetSaveFileNameA(
|
||||||
if (is_win16_looks(ofn->Flags))
|
if (is_win16_looks(ofn->Flags))
|
||||||
return GetFileName31A(ofn, SAVE_DIALOG);
|
return GetFileName31A(ofn, SAVE_DIALOG);
|
||||||
else
|
else
|
||||||
return GetFileDialog95A(ofn, SAVE_DIALOG);
|
{
|
||||||
|
FileOpenDlgInfos info;
|
||||||
|
|
||||||
|
init_filedlg_infoA(ofn, &info);
|
||||||
|
return GetFileDialog95(&info, SAVE_DIALOG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
@ -4180,7 +4118,12 @@ BOOL WINAPI GetSaveFileNameW(
|
||||||
if (is_win16_looks(ofn->Flags))
|
if (is_win16_looks(ofn->Flags))
|
||||||
return GetFileName31W(ofn, SAVE_DIALOG);
|
return GetFileName31W(ofn, SAVE_DIALOG);
|
||||||
else
|
else
|
||||||
return GetFileDialog95W(ofn, SAVE_DIALOG);
|
{
|
||||||
|
FileOpenDlgInfos info;
|
||||||
|
|
||||||
|
init_filedlg_infoW(ofn, &info);
|
||||||
|
return GetFileDialog95(&info, SAVE_DIALOG);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
|
|
Loading…
Reference in New Issue