X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Fdll%2Fwin32%2Fcomdlg32%2Ffiledlg.c;h=bc7b51b2e41268d6b61a1cb429a1cb07f6a4244c;hp=37ce6c2aca20c17fc9688a5c750bcad73ee9c80c;hb=b1863a26c79822a82b9c873a6ee1a2719dd8c538;hpb=b20974cc24d0eef313f6ce9e4953b37492605c00 diff --git a/reactos/dll/win32/comdlg32/filedlg.c b/reactos/dll/win32/comdlg32/filedlg.c index 37ce6c2aca2..bc7b51b2e41 100644 --- a/reactos/dll/win32/comdlg32/filedlg.c +++ b/reactos/dll/win32/comdlg32/filedlg.c @@ -36,7 +36,7 @@ * * FIXME: add to recent docs * - * FIXME: flags not implemented: OFN_CREATEPROMPT, OFN_DONTADDTORECENT, + * FIXME: flags not implemented: OFN_DONTADDTORECENT, * OFN_ENABLEINCLUDENOTIFY, OFN_ENABLESIZING, * OFN_NODEREFERENCELINKS, OFN_NOREADONLYRETURN, * OFN_NOTESTFILECREATE, OFN_USEMONIKERS @@ -61,29 +61,28 @@ #include "windef.h" #include "winbase.h" -#include "winreg.h" #include "winternl.h" #include "winnls.h" -#include "wine/unicode.h" #include "wingdi.h" -#include "winuser.h" #include "winreg.h" +#include "winuser.h" #include "commdlg.h" #include "dlgs.h" #include "cdlg.h" #include "filedlg31.h" -#include "wine/debug.h" #include "cderr.h" #include "shellapi.h" -#include "shlguid.h" #include "shlobj.h" #include "filedlgbrowser.h" #include "shlwapi.h" +#include "wine/unicode.h" +#include "wine/debug.h" + WINE_DEFAULT_DEBUG_CHANNEL(commdlg); #define UNIMPLEMENTED_FLAGS \ -(OFN_CREATEPROMPT | OFN_DONTADDTORECENT |\ +(OFN_DONTADDTORECENT |\ OFN_ENABLEINCLUDENOTIFY | OFN_ENABLESIZING |\ OFN_NODEREFERENCELINKS | OFN_NOREADONLYRETURN |\ OFN_NOTESTFILECREATE /*| OFN_USEMONIKERS*/) @@ -140,53 +139,52 @@ typedef struct tagFD32_PRIVATE /* Combo box macros */ #define CBAddString(hwnd,str) \ - SendMessageA(hwnd,CB_ADDSTRING,0,(LPARAM)str); -#define CBAddStringW(hwnd,str) \ - SendMessageW(hwnd,CB_ADDSTRING,0,(LPARAM)str); + SendMessageW(hwnd, CB_ADDSTRING, 0, (LPARAM)(str)); #define CBInsertString(hwnd,str,pos) \ - SendMessageA(hwnd,CB_INSERTSTRING,(WPARAM)pos,(LPARAM)str); + SendMessageW(hwnd, CB_INSERTSTRING, (WPARAM)(pos), (LPARAM)(str)); #define CBDeleteString(hwnd,pos) \ - SendMessageA(hwnd,CB_DELETESTRING,(WPARAM)pos,0); + SendMessageW(hwnd, CB_DELETESTRING, (WPARAM)(pos), 0); #define CBSetItemDataPtr(hwnd,iItemId,dataPtr) \ - SendMessageA(hwnd,CB_SETITEMDATA,(WPARAM)iItemId,(LPARAM)dataPtr); + SendMessageW(hwnd, CB_SETITEMDATA, (WPARAM)(iItemId), (LPARAM)(dataPtr)); #define CBGetItemDataPtr(hwnd,iItemId) \ - SendMessageA(hwnd,CB_GETITEMDATA,(WPARAM)iItemId,0) + SendMessageW(hwnd, CB_GETITEMDATA, (WPARAM)(iItemId), 0) #define CBGetLBText(hwnd,iItemId,str) \ - SendMessageA(hwnd,CB_GETLBTEXT,(WPARAM)iItemId,(LPARAM)str); + SendMessageW(hwnd, CB_GETLBTEXT, (WPARAM)(iItemId), (LPARAM)(str)); #define CBGetCurSel(hwnd) \ - SendMessageA(hwnd,CB_GETCURSEL,0,0); + SendMessageW(hwnd, CB_GETCURSEL, 0, 0); #define CBSetCurSel(hwnd,pos) \ - SendMessageA(hwnd,CB_SETCURSEL,(WPARAM)pos,0); + SendMessageW(hwnd, CB_SETCURSEL, (WPARAM)(pos), 0); #define CBGetCount(hwnd) \ - SendMessageA(hwnd,CB_GETCOUNT,0,0); + SendMessageW(hwnd, CB_GETCOUNT, 0, 0); #define CBShowDropDown(hwnd,show) \ - SendMessageA(hwnd,CB_SHOWDROPDOWN,(WPARAM)show,0); + SendMessageW(hwnd, CB_SHOWDROPDOWN, (WPARAM)(show), 0); #define CBSetItemHeight(hwnd,index,height) \ - SendMessageA(hwnd,CB_SETITEMHEIGHT,(WPARAM)index,(LPARAM)height); + SendMessageW(hwnd, CB_SETITEMHEIGHT, (WPARAM)(index), (LPARAM)(height)); #define CBSetExtendedUI(hwnd,flag) \ - SendMessageA(hwnd,CB_SETEXTENDEDUI,(WPARAM)(flag),0) + SendMessageW(hwnd, CB_SETEXTENDEDUI, (WPARAM)(flag), 0) -const char *FileOpenDlgInfosStr = "FileOpenDlgInfos"; /* windows property description string */ -const char *LookInInfosStr = "LookInInfos"; /* LOOKIN combo box property */ +const char FileOpenDlgInfosStr[] = "FileOpenDlgInfos"; /* windows property description string */ +static const char LookInInfosStr[] = "LookInInfos"; /* LOOKIN combo box property */ /*********************************************************************** * Prototypes */ /* Internal functions used by the dialog */ +static LRESULT FILEDLG95_ResizeControls(HWND hwnd, WPARAM wParam, LPARAM lParam); static LRESULT FILEDLG95_FillControls(HWND hwnd, WPARAM wParam, LPARAM lParam); static LRESULT FILEDLG95_OnWMCommand(HWND hwnd, WPARAM wParam, LPARAM lParam); static LRESULT FILEDLG95_OnWMGetIShellBrowser(HWND hwnd); - BOOL FILEDLG95_OnOpen(HWND hwnd); +static BOOL FILEDLG95_OnOpen(HWND hwnd); static LRESULT FILEDLG95_InitControls(HWND hwnd); static void FILEDLG95_Clean(HWND hwnd); @@ -198,7 +196,7 @@ static void FILEDLG95_SHELL_Clean(HWND hwnd); static BOOL FILEDLG95_SHELL_BrowseToDesktop(HWND hwnd); /* Functions used by the EDIT box */ -static int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, UINT * sizeUsed, char separator); +static int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, UINT * sizeUsed); /* Functions used by the filetype combo box */ static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd); @@ -218,17 +216,16 @@ static int FILEDLG95_LOOKIN_RemoveMostExpandedItem(HWND hwnd); static void FILEDLG95_LOOKIN_Clean(HWND hwnd); /* Miscellaneous tool functions */ -static HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName); +static HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPWSTR lpstrFileName); IShellFolder* GetShellFolderFromPidl(LPITEMIDLIST pidlAbs); LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl); -LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPWSTR lpcstrFileName); +static LPITEMIDLIST GetPidlFromName(IShellFolder *psf,LPWSTR lpcstrFileName); /* Shell memory allocation */ static void *MemAlloc(UINT size); static void MemFree(void *mem); -INT_PTR CALLBACK FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); -LRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode); +static INT_PTR CALLBACK FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static INT_PTR FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); static BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPWSTR lpstrFileList, UINT nFileCount, UINT sizeUsed); static BOOL BrowseSelectedFolder(HWND hwnd); @@ -255,13 +252,13 @@ static BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos) /* test for missing functionality */ if (fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS) { - FIXME("Flags 0x%08lx not yet implemented\n", + FIXME("Flags 0x%08x not yet implemented\n", fodInfos->ofnInfos->Flags & UNIMPLEMENTED_FLAGS); } /* Create the dialog from a template */ - if(!(hRes = FindResourceA(COMDLG32_hInstance,MAKEINTRESOURCEA(NEWFILEOPENORD),(LPSTR)RT_DIALOG))) + if(!(hRes = FindResourceW(COMDLG32_hInstance,MAKEINTRESOURCEW(NEWFILEOPENORD),(LPCWSTR)RT_DIALOG))) { COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE); return FALSE; @@ -276,20 +273,27 @@ static BOOL WINAPI GetFileName95(FileOpenDlgInfos *fodInfos) /* old style hook messages */ if (IsHooked(fodInfos)) { - fodInfos->HookMsg.fileokstring = RegisterWindowMessageA(FILEOKSTRINGA); - fodInfos->HookMsg.lbselchstring = RegisterWindowMessageA(LBSELCHSTRINGA); - fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageA(HELPMSGSTRINGA); - fodInfos->HookMsg.sharevistring = RegisterWindowMessageA(SHAREVISTRINGA); + fodInfos->HookMsg.fileokstring = RegisterWindowMessageW(FILEOKSTRINGW); + fodInfos->HookMsg.lbselchstring = RegisterWindowMessageW(LBSELCHSTRINGW); + fodInfos->HookMsg.helpmsgstring = RegisterWindowMessageW(HELPMSGSTRINGW); + fodInfos->HookMsg.sharevistring = RegisterWindowMessageW(SHAREVISTRINGW); } /* Some shell namespace extensions depend on COM being initialized. */ hr = OleInitialize(NULL); - lRes = DialogBoxIndirectParamA(COMDLG32_hInstance, - (LPDLGTEMPLATEA) template, - fodInfos->ofnInfos->hwndOwner, - FileOpenDlgProc95, - (LPARAM) fodInfos); + if (fodInfos->unicode) + lRes = DialogBoxIndirectParamW(COMDLG32_hInstance, + template, + fodInfos->ofnInfos->hwndOwner, + FileOpenDlgProc95, + (LPARAM) fodInfos); + else + lRes = DialogBoxIndirectParamA(COMDLG32_hInstance, + (LPCDLGTEMPLATEA) template, + fodInfos->ofnInfos->hwndOwner, + FileOpenDlgProc95, + (LPARAM) fodInfos); if (SUCCEEDED(hr)) OleUninitialize(); @@ -318,6 +322,9 @@ BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType) LPWSTR filter = NULL; LPWSTR customfilter = NULL; + /* Initialize CommDlgExtendedError() */ + COMDLG32_SetCommDlgExtendedError(0); + /* Initialize FileOpenDlgInfos structure */ ZeroMemory(&fodInfos, sizeof(FileOpenDlgInfos)); @@ -423,19 +430,12 @@ BOOL WINAPI GetFileDialog95A(LPOPENFILENAMEA ofn,UINT iDlgType) MemFree(lpstrSavDir); } - if(title) - MemFree(title); - if(defext) - MemFree(defext); - if(filter) - MemFree(filter); - if(customfilter) - MemFree(customfilter); - if(fodInfos.initdir) - MemFree(fodInfos.initdir); - - if(fodInfos.filename) - MemFree(fodInfos.filename); + MemFree(title); + MemFree(defext); + MemFree(filter); + MemFree(customfilter); + MemFree(fodInfos.initdir); + MemFree(fodInfos.filename); TRACE("selected file: %s\n",ofn->lpstrFile); @@ -455,6 +455,9 @@ BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType) FileOpenDlgInfos fodInfos; LPWSTR lpstrSavDir = NULL; + /* Initialize CommDlgExtendedError() */ + COMDLG32_SetCommDlgExtendedError(0); + /* Initialize FileOpenDlgInfos structure */ ZeroMemory(&fodInfos, sizeof(FileOpenDlgInfos)); @@ -478,7 +481,7 @@ BOOL WINAPI GetFileDialog95W(LPOPENFILENAMEW ofn,UINT iDlgType) if(ofn->lpstrInitialDir) { /* fodInfos.initdir = strdupW(ofn->lpstrInitialDir); */ - DWORD len = strlenW(ofn->lpstrInitialDir)+1; + DWORD len = lstrlenW(ofn->lpstrInitialDir)+1; fodInfos.initdir = MemAlloc(len*sizeof(WCHAR)); memcpy(fodInfos.initdir,ofn->lpstrInitialDir,len*sizeof(WCHAR)); } @@ -771,9 +774,14 @@ static HWND CreateTemplateDialog(FileOpenDlgInfos *fodInfos, HWND hwnd) return NULL; } } - hChildDlg = CreateDialogIndirectParamA(hinst, template, hwnd, - IsHooked(fodInfos) ? (DLGPROC)fodInfos->ofnInfos->lpfnHook : FileOpenDlgProcUserTemplate, - (LPARAM)fodInfos->ofnInfos); + if (fodInfos->unicode) + hChildDlg = CreateDialogIndirectParamW(hinst, template, hwnd, + IsHooked(fodInfos) ? (DLGPROC)fodInfos->ofnInfos->lpfnHook : FileOpenDlgProcUserTemplate, + (LPARAM)fodInfos->ofnInfos); + else + hChildDlg = CreateDialogIndirectParamA(hinst, template, hwnd, + IsHooked(fodInfos) ? (DLGPROC)fodInfos->ofnInfos->lpfnHook : FileOpenDlgProcUserTemplate, + (LPARAM)fodInfos->ofnInfos); if(hChildDlg) { ShowWindow(hChildDlg,SW_SHOW); @@ -850,11 +858,10 @@ LRESULT SendCustomDlgNotificationMessage(HWND hwndParentDlg, UINT uCode) return hook_result; } -static INT_PTR FILEDLG95_Handle_GetFilePath(HWND hwnd, DWORD size, LPVOID buffer) +static INT_PTR FILEDLG95_Handle_GetFilePath(HWND hwnd, DWORD size, LPVOID result) { - UINT sizeUsed = 0, n, total; - LPWSTR lpstrFileList = NULL; - WCHAR lpstrCurrentDir[MAX_PATH]; + UINT len, total; + WCHAR *p, *buffer; FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); TRACE("CDM_GETFILEPATH:\n"); @@ -863,80 +870,29 @@ static INT_PTR FILEDLG95_Handle_GetFilePath(HWND hwnd, DWORD size, LPVOID buffer return -1; /* get path and filenames */ - COMDLG32_GetDisplayNameOf(fodInfos->ShellInfos.pidlAbsCurrent, lpstrCurrentDir); - n = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed, ' '); - - TRACE("path >%s< filespec >%s< %d files\n", - debugstr_w(lpstrCurrentDir),debugstr_w(lpstrFileList),n); - - if( fodInfos->unicode ) - { - LPWSTR bufW = buffer; - total = strlenW(lpstrCurrentDir) + 1 + sizeUsed; - - /* Prepend the current path */ - n = strlenW(lpstrCurrentDir) + 1; - memcpy( bufW, lpstrCurrentDir, min(n,size) * sizeof(WCHAR)); - if(n %s\n",debugstr_wn(bufW, total)); - } - else + len = SendMessageW( fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0 ); + buffer = HeapAlloc( GetProcessHeap(), 0, (len + 2 + MAX_PATH) * sizeof(WCHAR) ); + COMDLG32_GetDisplayNameOf( fodInfos->ShellInfos.pidlAbsCurrent, buffer ); + if (len) { - LPSTR bufA = buffer; - total = WideCharToMultiByte(CP_ACP, 0, lpstrCurrentDir, -1, - NULL, 0, NULL, NULL); - total += WideCharToMultiByte(CP_ACP, 0, lpstrFileList, sizeUsed, - NULL, 0, NULL, NULL); - - /* Prepend the current path */ - n = WideCharToMultiByte(CP_ACP, 0, lpstrCurrentDir, -1, - bufA, size, NULL, NULL); - - if(n %s\n",debugstr_an(bufA, total)); + p = buffer + strlenW(buffer); + *p++ = '\\'; + SendMessageW( fodInfos->DlgInfos.hwndFileName, WM_GETTEXT, len + 1, (LPARAM)p ); } - MemFree(lpstrFileList); - - return total; -} - -static INT_PTR FILEDLG95_Handle_GetFileSpec(HWND hwnd, DWORD size, LPVOID buffer) -{ - UINT sizeUsed = 0; - LPWSTR lpstrFileList = NULL; - FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); - - TRACE("CDM_GETSPEC:\n"); - - FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed, ' '); - if( fodInfos->unicode ) + if (fodInfos->unicode) { - LPWSTR bufW = buffer; - memcpy( bufW, lpstrFileList, sizeof(WCHAR)*sizeUsed ); + total = strlenW( buffer) + 1; + if (result) lstrcpynW( result, buffer, size ); + TRACE( "CDM_GETFILEPATH: returning %u %s\n", total, debugstr_w(result)); } else { - LPSTR bufA = buffer; - sizeUsed = WideCharToMultiByte( CP_ACP, 0, lpstrFileList, sizeUsed, - NULL, 0, NULL, NULL); - WideCharToMultiByte(CP_ACP, 0, lpstrFileList, sizeUsed, - bufA, size, NULL, NULL); + total = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL ); + if (total <= size) WideCharToMultiByte( CP_ACP, 0, buffer, -1, result, size, NULL, NULL ); + TRACE( "CDM_GETFILEPATH: returning %u %s\n", total, debugstr_a(result)); } - MemFree(lpstrFileList); - - return sizeUsed; + HeapFree( GetProcessHeap(), 0, buffer ); + return total; } /*********************************************************************** @@ -969,11 +925,25 @@ static INT_PTR FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM WideCharToMultiByte(CP_ACP, 0, lpstrPath, -1, (LPSTR)lParam, (int)wParam, NULL, NULL); } - retval = strlenW(lpstrPath); + retval = lstrlenW(lpstrPath); + break; + + case CDM_GETFOLDERIDLIST: + retval = COMDLG32_PIDL_ILGetSize(fodInfos->ShellInfos.pidlAbsCurrent); + if (retval <= wParam) + memcpy((void*)lParam, fodInfos->ShellInfos.pidlAbsCurrent, retval); break; case CDM_GETSPEC: - retval = FILEDLG95_Handle_GetFileSpec(hwnd, (UINT)wParam, (LPSTR)lParam); + TRACE("CDM_GETSPEC:\n"); + retval = SendMessageW(fodInfos->DlgInfos.hwndFileName, WM_GETTEXTLENGTH, 0, 0) + 1; + if (lParam) + { + if (fodInfos->unicode) + SendMessageW(fodInfos->DlgInfos.hwndFileName, WM_GETTEXT, wParam, lParam); + else + SendMessageA(fodInfos->DlgInfos.hwndFileName, WM_GETTEXT, wParam, lParam); + } break; case CDM_SETCONTROLTEXT: @@ -1029,35 +999,12 @@ INT_PTR CALLBACK FileOpenDlgProc95(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM l so it will be easily accessible through a GetPropA(...) */ SetPropA(hwnd, FileOpenDlgInfosStr, (HANDLE) fodInfos); - fodInfos->DlgInfos.hwndCustomDlg = - CreateTemplateDialog((FileOpenDlgInfos *)lParam, hwnd); - FILEDLG95_InitControls(hwnd); - if (fodInfos->DlgInfos.hwndCustomDlg) - { - RECT rc; - UINT flags = SWP_NOACTIVATE; - - ArrangeCtrlPositions(fodInfos->DlgInfos.hwndCustomDlg, hwnd, - (fodInfos->ofnInfos->Flags & (OFN_HIDEREADONLY | OFN_SHOWHELP)) == OFN_HIDEREADONLY); - - /* resize the custom dialog to the parent size */ - if (fodInfos->ofnInfos->Flags & (OFN_ENABLETEMPLATE | OFN_ENABLETEMPLATEHANDLE)) - GetClientRect(hwnd, &rc); - else - { - /* our own fake template is zero sized and doesn't have - * children, so there is no need to resize it. - * Picasa depends on it. - */ - flags |= SWP_NOSIZE; - SetRectEmpty(&rc); - } - SetWindowPos(fodInfos->DlgInfos.hwndCustomDlg, HWND_BOTTOM, - 0, 0, rc.right, rc.bottom, flags); - } + fodInfos->DlgInfos.hwndCustomDlg = + CreateTemplateDialog((FileOpenDlgInfos *)lParam, hwnd); + FILEDLG95_ResizeControls(hwnd, wParam, lParam); FILEDLG95_FillControls(hwnd, wParam, lParam); SendCustomDlgNotificationMessage(hwnd,CDN_INITDONE); @@ -1141,11 +1088,11 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) int win2000plus = 0; int win98plus = 0; int handledPath = FALSE; - OSVERSIONINFOA osVi; + OSVERSIONINFOW osVi; static const WCHAR szwSlash[] = { '\\', 0 }; static const WCHAR szwStar[] = { '*',0 }; - TBBUTTON tbb[] = + static const TBBUTTON tbb[] = { {0, 0, TBSTATE_ENABLED, BTNS_SEP, {0, 0}, 0, 0 }, {VIEW_PARENTFOLDER, FCIDM_TB_UPFOLDER, TBSTATE_ENABLED, BTNS_BUTTON, {0, 0}, 0, 0 }, @@ -1170,8 +1117,8 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) TRACE("%p\n", fodInfos); /* Get windows version emulating */ - osVi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA); - GetVersionExA(&osVi); + osVi.dwOSVersionInfoSize = sizeof(osVi); + GetVersionExW(&osVi); if (osVi.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { win98plus = ((osVi.dwMajorVersion > 4) || ((osVi.dwMajorVersion == 4) && (osVi.dwMinorVersion > 0))); } else if (osVi.dwPlatformId == VER_PLATFORM_WIN32_NT) { @@ -1197,21 +1144,28 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) rectTB.left = rectlook.right; rectTB.top = rectlook.top-1; - fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, - WS_CHILD | WS_GROUP | WS_VISIBLE | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE, - rectTB.left, rectTB.top, - rectTB.right - rectTB.left, rectTB.bottom - rectTB.top, - hwnd, (HMENU)IDC_TOOLBAR, COMDLG32_hInstance, NULL); + if (fodInfos->unicode) + fodInfos->DlgInfos.hwndTB = CreateWindowExW(0, TOOLBARCLASSNAMEW, NULL, + WS_CHILD | WS_GROUP | WS_VISIBLE | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE, + rectTB.left, rectTB.top, + rectTB.right - rectTB.left, rectTB.bottom - rectTB.top, + hwnd, (HMENU)IDC_TOOLBAR, COMDLG32_hInstance, NULL); + else + fodInfos->DlgInfos.hwndTB = CreateWindowExA(0, TOOLBARCLASSNAMEA, NULL, + WS_CHILD | WS_GROUP | WS_VISIBLE | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NORESIZE, + rectTB.left, rectTB.top, + rectTB.right - rectTB.left, rectTB.bottom - rectTB.top, + hwnd, (HMENU)IDC_TOOLBAR, COMDLG32_hInstance, NULL); - SendMessageA(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0); + SendMessageW(fodInfos->DlgInfos.hwndTB, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); /* FIXME: use TB_LOADIMAGES when implemented */ -/* SendMessageA(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, (WPARAM) IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/ - SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 12, (LPARAM) &tba[0]); - SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, (WPARAM) 1, (LPARAM) &tba[1]); +/* SendMessageW(fodInfos->DlgInfos.hwndTB, TB_LOADIMAGES, IDB_VIEW_SMALL_COLOR, HINST_COMMCTRL);*/ + SendMessageW(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, 12, (LPARAM) &tba[0]); + SendMessageW(fodInfos->DlgInfos.hwndTB, TB_ADDBITMAP, 1, (LPARAM) &tba[1]); - SendMessageA(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSA, (WPARAM) 9,(LPARAM) &tbb); - SendMessageA(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0); + SendMessageW(fodInfos->DlgInfos.hwndTB, TB_ADDBUTTONSW, 9, (LPARAM) &tbb); + SendMessageW(fodInfos->DlgInfos.hwndTB, TB_AUTOSIZE, 0, 0); /* Set the window text with the text specified in the OPENFILENAME structure */ if(fodInfos->title) @@ -1242,13 +1196,13 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) if (result) { /* nameBit is always shorter than the original filename */ - strcpyW(fodInfos->filename,nameBit); + lstrcpyW(fodInfos->filename,nameBit); *nameBit = 0x00; if (fodInfos->initdir == NULL) MemFree(fodInfos->initdir); - fodInfos->initdir = MemAlloc((strlenW(tmpBuf) + 1)*sizeof(WCHAR)); - strcpyW(fodInfos->initdir, tmpBuf); + fodInfos->initdir = MemAlloc((lstrlenW(tmpBuf) + 1)*sizeof(WCHAR)); + lstrcpyW(fodInfos->initdir, tmpBuf); handledPath = TRUE; TRACE("Value in Filename includes path, overriding InitialDir: %s, %s\n", debugstr_w(fodInfos->filename), debugstr_w(fodInfos->initdir)); @@ -1272,23 +1226,22 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) WCHAR *nameBit; DWORD result; - strcpyW(tmpBuf, fodInfos->initdir); + lstrcpyW(tmpBuf, fodInfos->initdir); if( PathFileExistsW(tmpBuf) ) { /* initdir does not have to be a directory. If a file is * specified, the dir part is taken */ if( PathIsDirectoryW(tmpBuf)) { - if (tmpBuf[strlenW(tmpBuf)-1] != '\\') { - strcatW(tmpBuf, szwSlash); + if (tmpBuf[lstrlenW(tmpBuf)-1] != '\\') { + lstrcatW(tmpBuf, szwSlash); } - strcatW(tmpBuf, szwStar); + lstrcatW(tmpBuf, szwStar); } result = GetFullPathNameW(tmpBuf, MAX_PATH, tmpBuf2, &nameBit); if (result) { *nameBit = 0x00; - if (fodInfos->initdir) - MemFree(fodInfos->initdir); - fodInfos->initdir = MemAlloc((strlenW(tmpBuf2) + 1)*sizeof(WCHAR)); - strcpyW(fodInfos->initdir, tmpBuf2); + MemFree(fodInfos->initdir); + fodInfos->initdir = MemAlloc((lstrlenW(tmpBuf2) + 1)*sizeof(WCHAR)); + lstrcpyW(fodInfos->initdir, tmpBuf2); handledPath = TRUE; TRACE("Value in InitDir changed to %s\n", debugstr_w(fodInfos->initdir)); } @@ -1319,14 +1272,13 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) int len; /* nameBit is always shorter than the original filename */ - strcpyW(fodInfos->filename, nameBit); + lstrcpyW(fodInfos->filename, nameBit); *nameBit = 0x00; - len = strlenW(tmpBuf); - if(fodInfos->initdir) - MemFree(fodInfos->initdir); + len = lstrlenW(tmpBuf); + MemFree(fodInfos->initdir); fodInfos->initdir = MemAlloc((len+1)*sizeof(WCHAR)); - strcpyW(fodInfos->initdir, tmpBuf); + lstrcpyW(fodInfos->initdir, tmpBuf); handledPath = TRUE; TRACE("Value in Filename includes path, overriding initdir: %s, %s\n", @@ -1351,7 +1303,7 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) /* Skip the title */ if(! *lpstrPos) break; /* end */ - lpstrPos += strlenW(lpstrPos) + 1; + lpstrPos += lstrlenW(lpstrPos) + 1; /* See if any files exist in the current dir with this extension */ if(! *lpstrPos) break; /* end */ @@ -1360,13 +1312,12 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) if (hFind == INVALID_HANDLE_VALUE) { /* None found - continue search */ - lpstrPos += strlenW(lpstrPos) + 1; + lpstrPos += lstrlenW(lpstrPos) + 1; } else { searchMore = FALSE; - if(fodInfos->initdir) - MemFree(fodInfos->initdir); + MemFree(fodInfos->initdir); fodInfos->initdir = MemAlloc(MAX_PATH*sizeof(WCHAR)); GetCurrentDirectoryW(MAX_PATH, fodInfos->initdir); @@ -1384,9 +1335,9 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) if (handledPath == FALSE && (win2000plus || win98plus)) { fodInfos->initdir = MemAlloc(MAX_PATH*sizeof(WCHAR)); - if(FAILED(COMDLG32_SHGetFolderPathW(hwnd, CSIDL_PERSONAL, 0, 0, fodInfos->initdir))) + if(!COMDLG32_SHGetFolderPathW(hwnd, CSIDL_PERSONAL, 0, 0, fodInfos->initdir)) { - if(FAILED(COMDLG32_SHGetFolderPathW(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, 0, 0, fodInfos->initdir))) + if(!COMDLG32_SHGetFolderPathW(hwnd, CSIDL_DESKTOPDIRECTORY|CSIDL_FLAG_CREATE, 0, 0, fodInfos->initdir)) { /* last fallback */ GetCurrentDirectoryW(MAX_PATH, fodInfos->initdir); @@ -1411,7 +1362,7 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) /* Must the open as read only check box be checked ?*/ if(fodInfos->ofnInfos->Flags & OFN_READONLY) { - SendDlgItemMessageA(hwnd,IDC_OPENREADONLY,BM_SETCHECK,(WPARAM)TRUE,0); + SendDlgItemMessageW(hwnd,IDC_OPENREADONLY,BM_SETCHECK,TRUE,0); } /* Must the open as read only check box be hidden? */ @@ -1428,24 +1379,6 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) EnableWindow(GetDlgItem(hwnd, pshHelp), FALSE); } - /* Resize the height, if open as read only checkbox ad help button - are hidden and we are not using a custom template nor a customDialog - */ - if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) && - (!(fodInfos->ofnInfos->Flags & - (OFN_SHOWHELP|OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE))) && - (!fodInfos->DlgInfos.hwndCustomDlg )) - { - RECT rectDlg, rectHelp, rectCancel; - GetWindowRect(hwnd, &rectDlg); - GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp); - GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel); - /* subtract the height of the help button plus the space between - the help button and the cancel button to the height of the dialog */ - SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left, - (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom), - SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER); - } /* change Open to Save */ if (fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) { @@ -1458,6 +1391,61 @@ static LRESULT FILEDLG95_InitControls(HWND hwnd) return 0; } +/*********************************************************************** + * FILEDLG95_ResizeControls + * + * WM_INITDIALOG message handler (after hook notification) + */ +static LRESULT FILEDLG95_ResizeControls(HWND hwnd, WPARAM wParam, LPARAM lParam) +{ + FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) lParam; + + if (fodInfos->DlgInfos.hwndCustomDlg) + { + RECT rc; + UINT flags = SWP_NOACTIVATE; + + ArrangeCtrlPositions(fodInfos->DlgInfos.hwndCustomDlg, hwnd, + (fodInfos->ofnInfos->Flags & (OFN_HIDEREADONLY | OFN_SHOWHELP)) == OFN_HIDEREADONLY); + + /* resize the custom dialog to the parent size */ + if (fodInfos->ofnInfos->Flags & (OFN_ENABLETEMPLATE | OFN_ENABLETEMPLATEHANDLE)) + GetClientRect(hwnd, &rc); + else + { + /* our own fake template is zero sized and doesn't have children, so + * there is no need to resize it. Picasa depends on it. + */ + flags |= SWP_NOSIZE; + SetRectEmpty(&rc); + } + SetWindowPos(fodInfos->DlgInfos.hwndCustomDlg, HWND_BOTTOM, + 0, 0, rc.right, rc.bottom, flags); + } + else + { + /* Resize the height, if open as read only checkbox ad help button are + * hidden and we are not using a custom template nor a customDialog + */ + if ( (fodInfos->ofnInfos->Flags & OFN_HIDEREADONLY) && + (!(fodInfos->ofnInfos->Flags & + (OFN_SHOWHELP|OFN_ENABLETEMPLATE|OFN_ENABLETEMPLATEHANDLE)))) + { + RECT rectDlg, rectHelp, rectCancel; + GetWindowRect(hwnd, &rectDlg); + GetWindowRect(GetDlgItem(hwnd, pshHelp), &rectHelp); + GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rectCancel); + /* subtract the height of the help button plus the space between the help + * button and the cancel button to the height of the dialog + */ + SetWindowPos(hwnd, 0, 0, 0, rectDlg.right-rectDlg.left, + (rectDlg.bottom-rectDlg.top) - (rectHelp.bottom - rectCancel.bottom), + SWP_NOACTIVATE|SWP_NOMOVE|SWP_NOZORDER); + } + } + return TRUE; +} + /*********************************************************************** * FILEDLG95_FillControls * @@ -1677,23 +1665,23 @@ BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPWSTR lpstrFileList, UINT nFileCo LoadStringW(COMDLG32_hInstance, IDS_FILENOTFOUND, lpstrNotFound, 100); LoadStringW(COMDLG32_hInstance, IDS_VERIFYFILE, lpstrMsg, 100); - strcpyW(tmp, lpstrTemp); - strcatW(tmp, nl); - strcatW(tmp, lpstrNotFound); - strcatW(tmp, nl); - strcatW(tmp, lpstrMsg); + lstrcpyW(tmp, lpstrTemp); + lstrcatW(tmp, nl); + lstrcatW(tmp, lpstrNotFound); + lstrcatW(tmp, nl); + lstrcatW(tmp, lpstrMsg); MessageBoxW(hwnd, tmp, fodInfos->title, MB_OK | MB_ICONEXCLAMATION); return FALSE; } /* move to the next file in the list of files */ - lpstrTemp += strlenW(lpstrTemp) + 1; + lpstrTemp += lstrlenW(lpstrTemp) + 1; COMDLG32_SHFree(pidl); } } - nSizePath = strlenW(lpstrPathSpec) + 1; + nSizePath = lstrlenW(lpstrPathSpec) + 1; if ( !(fodInfos->ofnInfos->Flags & OFN_EXPLORER) ) { /* For "oldstyle" dialog the components have to @@ -1704,7 +1692,7 @@ BOOL FILEDLG95_OnOpenMultipleFiles(HWND hwnd, LPWSTR lpstrFileList, UINT nFileCo if(fodInfos->unicode) { LPOPENFILENAMEW ofn = fodInfos->ofnInfos; - strcpyW( ofn->lpstrFile, lpstrPathSpec); + lstrcpyW( ofn->lpstrFile, lpstrPathSpec); memcpy( ofn->lpstrFile + nSizePath, lpstrFileList, sizeUsed*sizeof(WCHAR) ); } else @@ -1772,7 +1760,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) TRACE("hwnd=%p\n", hwnd); /* get the files from the edit control */ - nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed, '\0'); + nFileCount = FILEDLG95_FILENAME_GetFileNames(hwnd, &lpstrFileList, &sizeUsed); /* try if the user selected a folder in the shellview */ if(nFileCount == 0) @@ -1808,23 +1796,23 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) TRACE("current directory=%s\n", debugstr_w(lpstrPathAndFile)); - /* if the user specifyed a fully qualified path use it */ + /* if the user specified a fully qualified path use it */ if(PathIsRelativeW(lpstrFileList)) { - strcatW(lpstrPathAndFile, lpstrFileList); + lstrcatW(lpstrPathAndFile, lpstrFileList); } else { /* does the path have a drive letter? */ if (PathGetDriveNumberW(lpstrFileList) == -1) - strcpyW(lpstrPathAndFile+2, lpstrFileList); + lstrcpyW(lpstrPathAndFile+2, lpstrFileList); else - strcpyW(lpstrPathAndFile, lpstrFileList); + lstrcpyW(lpstrPathAndFile, lpstrFileList); } /* resolve "." and ".." */ PathCanonicalizeW(lpstrTemp, lpstrPathAndFile ); - strcpyW(lpstrPathAndFile, lpstrTemp); + lstrcpyW(lpstrPathAndFile, lpstrTemp); TRACE("canon=%s\n", debugstr_w(lpstrPathAndFile)); MemFree(lpstrFileList); @@ -1871,13 +1859,13 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) DWORD dwEaten, dwAttributes; LPWSTR p; - strcpyW(lpwstrTemp, lpszTemp); + lstrcpyW(lpwstrTemp, lpszTemp); p = PathFindNextComponentW(lpwstrTemp); if (!p) break; /* end of path */ *p = 0; - lpszTemp = lpszTemp + strlenW(lpwstrTemp); + lpszTemp = lpszTemp + lstrlenW(lpwstrTemp); /* There are no wildcards when OFN_NOVALIDATE is set */ if(*lpszTemp==0 && !(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE)) @@ -1906,7 +1894,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) if(SUCCEEDED(IShellFolder_ParseDisplayName(lpsf, hwnd, NULL, lpwstrTemp, &dwEaten, &pidl, &dwAttributes))) { /* the path component is valid, we have a pidl of the next path component */ - TRACE("parse OK attr=0x%08lx pidl=%p\n", dwAttributes, pidl); + TRACE("parse OK attr=0x%08x pidl=%p\n", dwAttributes, pidl); if(dwAttributes & SFGAO_FOLDER) { if(FAILED(IShellFolder_BindToObject(lpsf, pidl, 0, &IID_IShellFolder, (LPVOID*)&lpsfChild))) @@ -1931,7 +1919,8 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) } else if (!(fodInfos->ofnInfos->Flags & OFN_NOVALIDATE)) { - if(*lpszTemp) /* points to trailing null for last path element */ + if(*lpszTemp || /* points to trailing null for last path element */ + (lpwstrTemp[strlenW(lpwstrTemp)-1] == '\\')) /* or if last element ends in '\' */ { if(fodInfos->ofnInfos->Flags & OFN_PATHMUSTEXIST) { @@ -1981,11 +1970,10 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) DWORD len; /* replace the current filter */ - if(fodInfos->ShellInfos.lpstrCurrentFilter) - MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter); - len = strlenW(lpszTemp)+1; + MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter); + len = lstrlenW(lpszTemp)+1; fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc(len * sizeof(WCHAR)); - strcpyW( fodInfos->ShellInfos.lpstrCurrentFilter, lpszTemp); + lstrcpyW( fodInfos->ShellInfos.lpstrCurrentFilter, lpszTemp); /* set the filter cb to the extension when possible */ if(-1 < (iPos = FILEDLG95_FILETYPE_SearchExt(fodInfos->DlgInfos.hwndFileTypeCB, lpszTemp))) @@ -2003,13 +1991,18 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) IPersistFolder2_Release(ppf2); if( ! COMDLG32_PIDL_ILIsEqual(pidlCurrent, fodInfos->ShellInfos.pidlAbsCurrent)) { - IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE); + if (SUCCEEDED(IShellBrowser_BrowseObject(fodInfos->Shell.FOIShellBrowser, pidlCurrent, SBSP_ABSOLUTE))) + { + SendCustomDlgNotificationMessage(hwnd, CDN_FOLDERCHANGE); + } } else if( nOpenAction == ONOPEN_SEARCH ) { - IShellView_Refresh(fodInfos->Shell.FOIShellView); + if (fodInfos->Shell.FOIShellView) + IShellView_Refresh(fodInfos->Shell.FOIShellView); } COMDLG32_SHFree(pidlCurrent); + SendMessageW(fodInfos->DlgInfos.hwndFileName, EM_SETSEL, 0, -1); } } ret = FALSE; @@ -2020,7 +2013,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) WCHAR *ext = NULL; /* update READONLY check box flag */ - if ((SendMessageA(GetDlgItem(hwnd,IDC_OPENREADONLY),BM_GETCHECK,0,0) & 0x03) == BST_CHECKED) + if ((SendMessageW(GetDlgItem(hwnd,IDC_OPENREADONLY),BM_GETCHECK,0,0) & 0x03) == BST_CHECKED) fodInfos->ofnInfos->Flags |= OFN_READONLY; else fodInfos->ofnInfos->Flags &= ~OFN_READONLY; @@ -2035,10 +2028,10 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) WCHAR *filterExt = NULL; LPWSTR lpstrFilter = NULL; static const WCHAR szwDot[] = {'.',0}; - int PathLength = strlenW(lpstrPathAndFile); + int PathLength = lstrlenW(lpstrPathAndFile); /* Attach the dot*/ - strcatW(lpstrPathAndFile, szwDot); + lstrcatW(lpstrPathAndFile, szwDot); /*Get the file extension from file type filter*/ lpstrFilter = (LPWSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, @@ -2048,9 +2041,9 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) filterExt = PathFindExtensionW(lpstrFilter); if ( filterExt && *filterExt ) /* attach the file extension from file type filter*/ - strcatW(lpstrPathAndFile, filterExt + 1); + lstrcatW(lpstrPathAndFile, filterExt + 1); else if ( fodInfos->defext ) /* attach the default file extension*/ - strcatW(lpstrPathAndFile, fodInfos->defext); + lstrcatW(lpstrPathAndFile, fodInfos->defext); /* In Open dialog: if file does not exist try without extension */ if (!(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) && !PathFileExistsW(lpstrPathAndFile)) @@ -2086,12 +2079,29 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) } } + /* In Open dialog: check if it should be created if it doesn't exist */ + if (!(fodInfos->DlgInfos.dwDlgProp & FODPROP_SAVEDLG) + && fodInfos->ofnInfos->Flags & OFN_CREATEPROMPT + && !PathFileExistsW(lpstrPathAndFile)) + { + WCHAR lpstrCreate[100]; + int answer; + + LoadStringW(COMDLG32_hInstance, IDS_CREATEFILE, lpstrCreate, 100); + answer = MessageBoxW(hwnd, lpstrCreate, fodInfos->title, + MB_YESNO | MB_ICONEXCLAMATION); + if (answer == IDNO) + { + ret = FALSE; + goto ret; + } + } + /* Check that the size of the file does not exceed buffer size. (Allow for extra \0 if OFN_MULTISELECT is set.) */ - if(strlenW(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile - + if(lstrlenW(lpstrPathAndFile) < fodInfos->ofnInfos->nMaxFile - ((fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT) ? 1 : 0)) { - LPWSTR lpszTemp; /* fill destination buffer */ if (fodInfos->ofnInfos->lpstrFile) @@ -2115,13 +2125,31 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) } } - /* set filename offset */ - lpszTemp = PathFindFileNameW(lpstrPathAndFile); - fodInfos->ofnInfos->nFileOffset = (lpszTemp - lpstrPathAndFile); + if(fodInfos->unicode) + { + LPWSTR lpszTemp; + + /* set filename offset */ + lpszTemp = PathFindFileNameW(lpstrPathAndFile); + fodInfos->ofnInfos->nFileOffset = (lpszTemp - lpstrPathAndFile); + + /* set extension offset */ + lpszTemp = PathFindExtensionW(lpstrPathAndFile); + fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? (lpszTemp - lpstrPathAndFile) + 1 : 0; + } + else + { + LPSTR lpszTemp; + LPOPENFILENAMEA ofn = (LPOPENFILENAMEA)fodInfos->ofnInfos; + + /* set filename offset */ + lpszTemp = PathFindFileNameA(ofn->lpstrFile); + fodInfos->ofnInfos->nFileOffset = (lpszTemp - ofn->lpstrFile); - /* set extension offset */ - lpszTemp = PathFindExtensionW(lpstrPathAndFile); - fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? (lpszTemp - lpstrPathAndFile) + 1 : 0; + /* set extension offset */ + lpszTemp = PathFindExtensionA(ofn->lpstrFile); + fodInfos->ofnInfos->nFileExtension = (*lpszTemp) ? (lpszTemp - ofn->lpstrFile) + 1 : 0; + } /* set the lpstrFileTitle */ if(fodInfos->ofnInfos->lpstrFileTitle) @@ -2167,7 +2195,7 @@ BOOL FILEDLG95_OnOpen(HWND hwnd) { WORD size; - size = strlenW(lpstrPathAndFile) + 1; + size = lstrlenW(lpstrPathAndFile) + 1; if (fodInfos->ofnInfos->Flags & OFN_ALLOWMULTISELECT) size += 1; /* return needed size in first two bytes of lpstrFile */ @@ -2307,8 +2335,11 @@ static void FILEDLG95_SHELL_Clean(HWND hwnd) COMDLG32_SHFree(fodInfos->ShellInfos.pidlAbsCurrent); /* clean Shell interfaces */ - IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView); - IShellView_Release(fodInfos->Shell.FOIShellView); + if (fodInfos->Shell.FOIShellView) + { + IShellView_DestroyViewWindow(fodInfos->Shell.FOIShellView); + IShellView_Release(fodInfos->Shell.FOIShellView); + } IShellFolder_Release(fodInfos->Shell.FOIShellFolder); IShellBrowser_Release(fodInfos->Shell.FOIShellBrowser); if (fodInfos->Shell.FOIDataObject) @@ -2337,15 +2368,15 @@ static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd) LPCWSTR lpstrPos = fodInfos->customfilter; /* Get the title */ - lpstrPos += strlenW(fodInfos->customfilter) + 1; + lpstrPos += lstrlenW(fodInfos->customfilter) + 1; /* Copy the extensions */ if (! *lpstrPos) return E_FAIL; /* malformed filter */ - if (!(lpstrExt = MemAlloc((strlenW(lpstrPos)+1)*sizeof(WCHAR)))) return E_FAIL; - strcpyW(lpstrExt,lpstrPos); + if (!(lpstrExt = MemAlloc((lstrlenW(lpstrPos)+1)*sizeof(WCHAR)))) return E_FAIL; + lstrcpyW(lpstrExt,lpstrPos); /* Add the item at the end of the combo */ - CBAddStringW(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->customfilter); + CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, fodInfos->customfilter); CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters, lpstrExt); nFilters++; } @@ -2365,16 +2396,16 @@ static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd) /* Get the title */ if(! *lpstrPos) break; /* end */ lpstrDisplay = lpstrPos; - lpstrPos += strlenW(lpstrPos) + 1; + lpstrPos += lstrlenW(lpstrPos) + 1; - CBAddStringW(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay); + CBAddString(fodInfos->DlgInfos.hwndFileTypeCB, lpstrDisplay); nFilters++; /* Copy the extensions */ - if (!(lpstrExt = MemAlloc((strlenW(lpstrPos)+1)*sizeof(WCHAR)))) return E_FAIL; - strcpyW(lpstrExt,lpstrPos); - lpstrPos += strlenW(lpstrPos) + 1; + if (!(lpstrExt = MemAlloc((lstrlenW(lpstrPos)+1)*sizeof(WCHAR)))) return E_FAIL; + lstrcpyW(lpstrExt,lpstrPos); + lpstrPos += lstrlenW(lpstrPos) + 1; /* Add the item at the end of the combo */ CBSetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, nFilters-1, lpstrExt); @@ -2420,9 +2451,9 @@ static HRESULT FILEDLG95_FILETYPE_Init(HWND hwnd) { DWORD len; CharLowerW(lpstrFilter); /* lowercase */ - len = strlenW(lpstrFilter)+1; + len = lstrlenW(lpstrFilter)+1; fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) ); - strcpyW(fodInfos->ShellInfos.lpstrCurrentFilter,lpstrFilter); + lstrcpyW(fodInfos->ShellInfos.lpstrCurrentFilter,lpstrFilter); } } else fodInfos->ofnInfos->nFilterIndex = 0; @@ -2453,8 +2484,7 @@ static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode) (fodInfos->customfilter == NULL ? 1 : 0); /* Set the current filter with the current selection */ - if(fodInfos->ShellInfos.lpstrCurrentFilter) - MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter); + MemFree((LPVOID)fodInfos->ShellInfos.lpstrCurrentFilter); lpstrFilter = (LPWSTR) CBGetItemDataPtr(fodInfos->DlgInfos.hwndFileTypeCB, iItem); @@ -2462,14 +2492,15 @@ static BOOL FILEDLG95_FILETYPE_OnCommand(HWND hwnd, WORD wNotifyCode) { DWORD len; CharLowerW(lpstrFilter); /* lowercase */ - len = strlenW(lpstrFilter)+1; + len = lstrlenW(lpstrFilter)+1; fodInfos->ShellInfos.lpstrCurrentFilter = MemAlloc( len * sizeof(WCHAR) ); - strcpyW(fodInfos->ShellInfos.lpstrCurrentFilter,lpstrFilter); + lstrcpyW(fodInfos->ShellInfos.lpstrCurrentFilter,lpstrFilter); SendCustomDlgNotificationMessage(hwnd,CDN_TYPECHANGE); } /* Refresh the actual view to display the included items*/ - IShellView_Refresh(fodInfos->Shell.FOIShellView); + if (fodInfos->Shell.FOIShellView) + IShellView_Refresh(fodInfos->Shell.FOIShellView); } } return FALSE; @@ -2519,8 +2550,7 @@ static void FILEDLG95_FILETYPE_Clean(HWND hwnd) } } /* Current filter */ - if(fodInfos->ShellInfos.lpstrCurrentFilter) - MemFree(fodInfos->ShellInfos.lpstrCurrentFilter); + MemFree(fodInfos->ShellInfos.lpstrCurrentFilter); } @@ -2636,10 +2666,10 @@ static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct) COLORREF crText = GetSysColor(COLOR_WINDOWTEXT); RECT rectText; RECT rectIcon; - SHFILEINFOA sfi; + SHFILEINFOW sfi; HIMAGELIST ilItemImage; int iIndentation; - TEXTMETRICA tm; + TEXTMETRICW tm; LPSFOLDER tmpFolder; @@ -2657,20 +2687,20 @@ static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct) if(pDIStruct->itemID == liInfos->uSelectedItem) { - ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem, + ilItemImage = (HIMAGELIST) SHGetFileInfoW ((LPCWSTR) tmpFolder->pidlItem, 0, &sfi, - sizeof (SHFILEINFOA), + sizeof (sfi), SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME ); } else { - ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem, + ilItemImage = (HIMAGELIST) SHGetFileInfoW ((LPCWSTR) tmpFolder->pidlItem, 0, &sfi, - sizeof (SHFILEINFOA), + sizeof (sfi), SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME); @@ -2694,10 +2724,10 @@ static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct) if(pDIStruct->itemState & ODS_COMBOBOXEDIT) { iIndentation = 0; - ilItemImage = (HIMAGELIST) SHGetFileInfoA ((LPCSTR) tmpFolder->pidlItem, + ilItemImage = (HIMAGELIST) SHGetFileInfoW ((LPCWSTR) tmpFolder->pidlItem, 0, &sfi, - sizeof (SHFILEINFOA), + sizeof (sfi), SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_OPENICON | SHGFI_SYSICONINDEX | SHGFI_DISPLAYNAME ); @@ -2715,7 +2745,7 @@ static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct) rectIcon.bottom = pDIStruct->rcItem.bottom; /* Initialise the text display area */ - GetTextMetricsA(pDIStruct->hDC, &tm); + GetTextMetricsW(pDIStruct->hDC, &tm); rectText.left = rectIcon.right; rectText.top = (pDIStruct->rcItem.top + pDIStruct->rcItem.bottom - tm.tmHeight) / 2; @@ -2733,7 +2763,7 @@ static LRESULT FILEDLG95_LOOKIN_DrawItem(LPDRAWITEMSTRUCT pDIStruct) /* Draw the associated text */ if(sfi.szDisplayName) - TextOutA(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,strlen(sfi.szDisplayName)); + TextOutW(pDIStruct->hDC,rectText.left,rectText.top,sfi.szDisplayName,lstrlenW(sfi.szDisplayName)); return NOERROR; @@ -2788,7 +2818,7 @@ static BOOL FILEDLG95_LOOKIN_OnCommand(HWND hwnd, WORD wNotifyCode) static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId) { LPITEMIDLIST pidlNext; - SHFILEINFOA sfi; + SHFILEINFOW sfi; SFOLDER *tmpFolder; LookInInfos *liInfos; @@ -2816,20 +2846,20 @@ static int FILEDLG95_LOOKIN_AddItem(HWND hwnd,LPITEMIDLIST pidl, int iInsertId) liInfos->iMaxIndentation = tmpFolder->m_iIndent; sfi.dwAttributes = SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM; - SHGetFileInfoA((LPSTR)pidl, + SHGetFileInfoW((LPCWSTR)pidl, 0, &sfi, sizeof(sfi), SHGFI_DISPLAYNAME | SHGFI_SYSICONINDEX | SHGFI_PIDL | SHGFI_SMALLICON | SHGFI_ATTRIBUTES | SHGFI_ATTR_SPECIFIED); - TRACE("-- Add %s attr=%08lx\n", sfi.szDisplayName, sfi.dwAttributes); + TRACE("-- Add %s attr=%08x\n", debugstr_w(sfi.szDisplayName), sfi.dwAttributes); if((sfi.dwAttributes & SFGAO_FILESYSANCESTOR) || (sfi.dwAttributes & SFGAO_FILESYSTEM)) { int iItemID; - TRACE("-- Add %s at %u\n", sfi.szDisplayName, tmpFolder->m_iIndent); + TRACE("-- Add %s at %u\n", debugstr_w(sfi.szDisplayName), tmpFolder->m_iIndent); /* Add the item at the end of the list */ if(iInsertId < 0) @@ -2963,7 +2993,7 @@ static int FILEDLG95_LOOKIN_SearchItem(HWND hwnd,WPARAM searchArg,int iSearchMet int i = 0; int iCount = CBGetCount(hwnd); - TRACE("0x%08x 0x%x\n",searchArg, iSearchMethod); + TRACE("0x%08lx 0x%x\n",searchArg, iSearchMethod); if (iCount != CB_ERR) { @@ -3020,8 +3050,8 @@ void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd) FileOpenDlgInfos *fodInfos; LPITEMIDLIST pidl; UINT nFiles = 0, nFileToOpen, nFileSelected, nLength = 0; - char lpstrTemp[MAX_PATH]; - LPSTR lpstrAllFile = NULL, lpstrCurrFile = NULL; + WCHAR lpstrTemp[MAX_PATH]; + LPWSTR lpstrAllFile, lpstrCurrFile; TRACE("\n"); fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); @@ -3045,7 +3075,7 @@ void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd) if ( ! IsPidlFolder(fodInfos->Shell.FOIShellFolder, pidl) ) /* Ignore folders */ { - nLength += strlen( lpstrTemp ) + 3; + nLength += lstrlenW( lpstrTemp ) + 3; nFiles++; } COMDLG32_SHFree( pidl ); @@ -3055,8 +3085,7 @@ void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd) /* allocate the buffer */ if (nFiles <= 1) nLength = MAX_PATH; - lpstrAllFile = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength); - lpstrAllFile[0] = '\0'; + lpstrAllFile = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nLength * sizeof(WCHAR)); /* Generate the string for the edit control */ if(nFiles >= 1) @@ -3077,55 +3106,56 @@ void FILEDLG95_FILENAME_FillFromSelection (HWND hwnd) if ( nFiles > 1) { *lpstrCurrFile++ = '\"'; - strcpy( lpstrCurrFile, lpstrTemp ); - lpstrCurrFile += strlen( lpstrTemp ); - strcpy( lpstrCurrFile, "\" " ); - lpstrCurrFile += 2; + lstrcpyW( lpstrCurrFile, lpstrTemp ); + lpstrCurrFile += lstrlenW( lpstrTemp ); + *lpstrCurrFile++ = '\"'; + *lpstrCurrFile++ = ' '; + *lpstrCurrFile = 0; } else { - strcpy( lpstrAllFile, lpstrTemp ); + lstrcpyW( lpstrAllFile, lpstrTemp ); } } COMDLG32_SHFree( (LPVOID) pidl ); } } - SetWindowTextA( fodInfos->DlgInfos.hwndFileName, lpstrAllFile ); + SetWindowTextW( fodInfos->DlgInfos.hwndFileName, lpstrAllFile ); /* Select the file name like Windows does */ - SendMessageA(fodInfos->DlgInfos.hwndFileName, EM_SETSEL, (WPARAM)0, (LPARAM)-1); + SendMessageW(fodInfos->DlgInfos.hwndFileName, EM_SETSEL, 0, (LPARAM)-1); } HeapFree(GetProcessHeap(),0, lpstrAllFile ); } /* copied from shell32 to avoid linking to it - * FIXME: why? shell32 is already linked + * Although shell32 is already linked the behaviour of exported StrRetToStrN + * is dependent on whether emulated OS is unicode or not. */ -static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl) +static HRESULT COMDLG32_StrRetToStrNW (LPWSTR dest, DWORD len, LPSTRRET src, LPITEMIDLIST pidl) { switch (src->uType) { case STRRET_WSTR: - WideCharToMultiByte(CP_ACP, 0, src->u.pOleStr, -1, (LPSTR)dest, len, NULL, NULL); + lstrcpynW(dest, src->u.pOleStr, len); COMDLG32_SHFree(src->u.pOleStr); break; case STRRET_CSTR: - lstrcpynA((LPSTR)dest, src->u.cStr, len); + if (!MultiByteToWideChar( CP_ACP, 0, src->u.cStr, -1, dest, len ) && len) + dest[len-1] = 0; break; case STRRET_OFFSET: - lstrcpynA((LPSTR)dest, ((LPCSTR)&pidl->mkid)+src->u.uOffset, len); + if (!MultiByteToWideChar( CP_ACP, 0, ((LPCSTR)&pidl->mkid)+src->u.uOffset, -1, dest, len ) && len) + dest[len-1] = 0; break; default: - FIXME("unknown type!\n"); - if (len) - { - *(LPSTR)dest = '\0'; - } - return(E_FAIL); + FIXME("unknown type %x!\n", src->uType); + if (len) *dest = '\0'; + return E_FAIL; } return S_OK; } @@ -3137,7 +3167,7 @@ static HRESULT COMDLG32_StrRetToStrNA (LPVOID dest, DWORD len, LPSTRRET src, LPI * The delimiter is specified by the parameter 'separator', * usually either a space or a nul */ -static int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, UINT * sizeUsed, char separator) +static int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, UINT * sizeUsed) { FileOpenDlgInfos *fodInfos = (FileOpenDlgInfos *) GetPropA(hwnd,FileOpenDlgInfosStr); UINT nStrCharCount = 0; /* index in src buffer */ @@ -3169,29 +3199,26 @@ static int FILEDLG95_FILENAME_GetFileNames (HWND hwnd, LPWSTR * lpstrFileList, U while ((lpstrEdit[nStrCharCount]!='"') && (nStrCharCount <= nStrLen)) { (*lpstrFileList)[nFileIndex++] = lpstrEdit[nStrCharCount]; - (*sizeUsed)++; nStrCharCount++; } - (*lpstrFileList)[nFileIndex++] = separator; - (*sizeUsed)++; + (*lpstrFileList)[nFileIndex++] = 0; nFileCount++; } nStrCharCount++; } /* single, unquoted string */ - if ((nStrLen > 0) && (*sizeUsed == 0) ) + if ((nStrLen > 0) && (nFileIndex == 0) ) { - strcpyW(*lpstrFileList, lpstrEdit); - nFileIndex = strlenW(lpstrEdit) + 1; - (*sizeUsed) = nFileIndex; + lstrcpyW(*lpstrFileList, lpstrEdit); + nFileIndex = lstrlenW(lpstrEdit) + 1; nFileCount = 1; } - /* trailing \0 */ - (*lpstrFileList)[nFileIndex] = '\0'; - (*sizeUsed)++; + /* trailing \0 */ + (*lpstrFileList)[nFileIndex++] = '\0'; + *sizeUsed = nFileIndex; MemFree(lpstrEdit); return nFileCount; } @@ -3306,7 +3333,7 @@ UINT GetNumSelected( IDataObject *doSelected ) * E_FAIL otherwise */ -static HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR lpstrFileName) +static HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPWSTR lpstrFileName) { STRRET str; HRESULT hRes; @@ -3324,7 +3351,7 @@ static HRESULT GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST pidl,DWORD dwFlags,LPSTR /* Get the display name of the pidl relative to the folder */ if (SUCCEEDED(hRes = IShellFolder_GetDisplayNameOf(lpsf, pidl, dwFlags, &str))) { - return COMDLG32_StrRetToStrNA(lpstrFileName, MAX_PATH, &str, pidl); + return COMDLG32_StrRetToStrNW(lpstrFileName, MAX_PATH, &str, pidl); } return E_FAIL; } @@ -3381,7 +3408,7 @@ LPITEMIDLIST GetParentPidl(LPITEMIDLIST pidl) * returns the pidl of the file name relative to folder * NULL if an error occurred */ -LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPWSTR lpcstrFileName) +static LPITEMIDLIST GetPidlFromName(IShellFolder *lpsf,LPWSTR lpcstrFileName) { LPITEMIDLIST pidl = NULL; ULONG ulEaten; @@ -3416,7 +3443,7 @@ BOOL IsPidlFolder (LPSHELLFOLDER psf, LPCITEMIDLIST pidl) ret = IShellFolder_GetAttributesOf( psf, 1, &pidl, &uAttr ); - TRACE("-- 0x%08lx 0x%08lx\n", uAttr, ret); + TRACE("-- 0x%08x 0x%08x\n", uAttr, ret); /* see documentation shell 4.1*/ return uAttr & (SFGAO_FOLDER | SFGAO_HASSUBFOLDER); } @@ -3572,7 +3599,7 @@ static BOOL CALLBACK FD32_Init(LPARAM lParam, PFD31_DATA lfs, DWORD data) * * called from the common 16/32 code to call the appropriate hook */ -static BOOL CALLBACK FD32_CallWindowProc(PFD31_DATA lfs, UINT wMsg, WPARAM wParam, +static BOOL CALLBACK FD32_CallWindowProc(const FD31_DATA *lfs, UINT wMsg, WPARAM wParam, LPARAM lParam) { BOOL ret; @@ -3580,18 +3607,18 @@ static BOOL CALLBACK FD32_CallWindowProc(PFD31_DATA lfs, UINT wMsg, WPARAM wPara if (priv->ofnA) { - TRACE("Call hookA %p (%p, %04x, %08x, %08lx)\n", + TRACE("Call hookA %p (%p, %04x, %08lx, %08lx)\n", priv->ofnA->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); ret = priv->ofnA->lpfnHook(lfs->hwnd, wMsg, wParam, lParam); - TRACE("ret hookA %p (%p, %04x, %08x, %08lx)\n", + TRACE("ret hookA %p (%p, %04x, %08lx, %08lx)\n", priv->ofnA->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); return ret; } - TRACE("Call hookW %p (%p, %04x, %08x, %08lx)\n", + TRACE("Call hookW %p (%p, %04x, %08lx, %08lx)\n", lfs->ofnW->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); ret = lfs->ofnW->lpfnHook(lfs->hwnd, wMsg, wParam, lParam); - TRACE("Ret hookW %p (%p, %04x, %08x, %08lx)\n", + TRACE("Ret hookW %p (%p, %04x, %08lx, %08lx)\n", lfs->ofnW->lpfnHook, lfs->hwnd, wMsg, wParam, lParam); return ret; } @@ -3600,19 +3627,27 @@ static BOOL CALLBACK FD32_CallWindowProc(PFD31_DATA lfs, UINT wMsg, WPARAM wPara * FD32_UpdateResult [internal] * update the real client structures if any */ -static void CALLBACK FD32_UpdateResult(PFD31_DATA lfs) +static void CALLBACK FD32_UpdateResult(const FD31_DATA *lfs) { PFD32_PRIVATE priv = (PFD32_PRIVATE) lfs->private1632; LPOPENFILENAMEW ofnW = lfs->ofnW; if (priv->ofnA) { + LPSTR lpszTemp; if (ofnW->nMaxFile && !WideCharToMultiByte( CP_ACP, 0, ofnW->lpstrFile, -1, priv->ofnA->lpstrFile, ofnW->nMaxFile, NULL, NULL )) priv->ofnA->lpstrFile[ofnW->nMaxFile-1] = 0; - priv->ofnA->nFileOffset = ofnW->nFileOffset; - priv->ofnA->nFileExtension = ofnW->nFileExtension; + + /* offsets are not guaranteed to be the same in WCHAR to MULTIBYTE conversion */ + /* set filename offset */ + lpszTemp = PathFindFileNameA(priv->ofnA->lpstrFile); + priv->ofnA->nFileOffset = (lpszTemp - priv->ofnA->lpstrFile); + + /* set extension offset */ + lpszTemp = PathFindExtensionA(priv->ofnA->lpstrFile); + priv->ofnA->nFileExtension = (*lpszTemp) ? (lpszTemp - priv->ofnA->lpstrFile) + 1 : 0; } } @@ -3620,7 +3655,7 @@ static void CALLBACK FD32_UpdateResult(PFD31_DATA lfs) * FD32_UpdateFileTitle [internal] * update the real client structures if any */ -static void CALLBACK FD32_UpdateFileTitle(PFD31_DATA lfs) +static void CALLBACK FD32_UpdateFileTitle(const FD31_DATA *lfs) { PFD32_PRIVATE priv = (PFD32_PRIVATE) lfs->private1632; LPOPENFILENAMEW ofnW = lfs->ofnW; @@ -3638,7 +3673,7 @@ static void CALLBACK FD32_UpdateFileTitle(PFD31_DATA lfs) * FD32_SendLbGetCurSel [internal] * retrieve selected listbox item */ -static LRESULT CALLBACK FD32_SendLbGetCurSel(PFD31_DATA lfs) +static LRESULT CALLBACK FD32_SendLbGetCurSel(const FD31_DATA *lfs) { return SendDlgItemMessageW(lfs->hwnd, lst1, LB_GETCURSEL, 0, 0); } @@ -3648,7 +3683,7 @@ static LRESULT CALLBACK FD32_SendLbGetCurSel(PFD31_DATA lfs) * FD32_Destroy [internal] * called from the common 16/32 code to cleanup 32 bit data */ -static void CALLBACK FD32_Destroy(PFD31_DATA lfs) +static void CALLBACK FD32_Destroy(const FD31_DATA *lfs) { PFD32_PRIVATE priv = (PFD32_PRIVATE) lfs->private1632; @@ -3692,7 +3727,7 @@ static INT_PTR CALLBACK FD32_FileOpenDlgProc(HWND hWnd, UINT wMsg, { PFD31_DATA lfs = (PFD31_DATA)GetPropA(hWnd,FD31_OFN_PROP); - TRACE("msg=%x wparam=%x lParam=%lx\n", wMsg, wParam, lParam); + TRACE("msg=%x wparam=%lx lParam=%lx\n", wMsg, wParam, lParam); if ((wMsg != WM_INITDIALOG) && lfs && lfs->hook) { INT_PTR lRet; @@ -3737,7 +3772,7 @@ static INT_PTR CALLBACK FD32_FileOpenDlgProc(HWND hWnd, UINT wMsg, * * Creates a win31 style dialog box for the user to select a file to open/save. */ -static BOOL GetFileName31A(LPOPENFILENAMEA lpofn, /* addess of structure with data*/ +static BOOL GetFileName31A(LPOPENFILENAMEA lpofn, /* address of structure with data*/ UINT dlgType /* type dialogue : open/save */ ) { @@ -3748,12 +3783,12 @@ static BOOL GetFileName31A(LPOPENFILENAMEA lpofn, /* addess of structure with da if (!lpofn || !FD31_Init()) return FALSE; - TRACE("ofn flags %08lx\n", lpofn->Flags); + TRACE("ofn flags %08x\n", lpofn->Flags); FD32_SetupCallbacks(&callbacks); lfs = FD31_AllocPrivate((LPARAM) lpofn, dlgType, &callbacks, (DWORD) FALSE); if (lfs) { - hInst = (HINSTANCE)GetWindowLongPtrA( lpofn->hwndOwner, GWLP_HINSTANCE ); + hInst = (HINSTANCE)GetWindowLongPtrW( lpofn->hwndOwner, GWLP_HINSTANCE ); bRet = DialogBoxIndirectParamA( hInst, lfs->template, lpofn->hwndOwner, FD32_FileOpenDlgProc, (LPARAM)lfs); FD31_DestroyPrivate(lfs); @@ -3768,7 +3803,7 @@ static BOOL GetFileName31A(LPOPENFILENAMEA lpofn, /* addess of structure with da * * Creates a win31 style dialog box for the user to select a file to open/save */ -static BOOL GetFileName31W(LPOPENFILENAMEW lpofn, /* addess of structure with data*/ +static BOOL GetFileName31W(LPOPENFILENAMEW lpofn, /* address of structure with data*/ UINT dlgType /* type dialogue : open/save */ ) { @@ -3811,7 +3846,7 @@ BOOL WINAPI GetOpenFileNameA( { BOOL win16look = FALSE; - TRACE("flags %08lx\n", ofn->Flags); + TRACE("flags %08x\n", ofn->Flags); /* OFN_FILEMUSTEXIST implies OFN_PATHMUSTEXIST */ if (ofn->Flags & OFN_FILEMUSTEXIST) @@ -3841,7 +3876,7 @@ BOOL WINAPI GetOpenFileNameW( { BOOL win16look = FALSE; - TRACE("flags %08lx\n", ofn->Flags); + TRACE("flags %08x\n", ofn->Flags); /* OFN_FILEMUSTEXIST implies OFN_PATHMUSTEXIST */ if (ofn->Flags & OFN_FILEMUSTEXIST) @@ -3904,3 +3939,82 @@ BOOL WINAPI GetSaveFileNameW( else return GetFileDialog95W(ofn, SAVE_DIALOG); } + +/*********************************************************************** + * GetFileTitleA (COMDLG32.@) + * + * See GetFileTitleW. + */ +short WINAPI GetFileTitleA(LPCSTR lpFile, LPSTR lpTitle, WORD cbBuf) +{ + int ret; + UNICODE_STRING strWFile; + LPWSTR lpWTitle; + + RtlCreateUnicodeStringFromAsciiz(&strWFile, lpFile); + lpWTitle = RtlAllocateHeap( GetProcessHeap(), 0, cbBuf*sizeof(WCHAR)); + ret = GetFileTitleW(strWFile.Buffer, lpWTitle, cbBuf); + if (!ret) WideCharToMultiByte( CP_ACP, 0, lpWTitle, -1, lpTitle, cbBuf, NULL, NULL ); + RtlFreeUnicodeString( &strWFile ); + RtlFreeHeap( GetProcessHeap(), 0, lpWTitle ); + return ret; +} + + +/*********************************************************************** + * GetFileTitleW (COMDLG32.@) + * + * Get the name of a file. + * + * PARAMS + * lpFile [I] name and location of file + * lpTitle [O] returned file name + * cbBuf [I] buffer size of lpTitle + * + * RETURNS + * Success: zero + * Failure: negative number. + */ +short WINAPI GetFileTitleW(LPCWSTR lpFile, LPWSTR lpTitle, WORD cbBuf) +{ + int i, len; + static const WCHAR brkpoint[] = {'*','[',']',0}; + TRACE("(%p %p %d);\n", lpFile, lpTitle, cbBuf); + + if(lpFile == NULL || lpTitle == NULL) + return -1; + + len = lstrlenW(lpFile); + + if (len == 0) + return -1; + + if(strpbrkW(lpFile, brkpoint)) + return -1; + + len--; + + if(lpFile[len] == '/' || lpFile[len] == '\\' || lpFile[len] == ':') + return -1; + + for(i = len; i >= 0; i--) + { + if (lpFile[i] == '/' || lpFile[i] == '\\' || lpFile[i] == ':') + { + i++; + break; + } + } + + if(i == -1) + i++; + + TRACE("---> %s\n", debugstr_w(&lpFile[i])); + + len = lstrlenW(lpFile+i)+1; + if(cbBuf < len) + return len; + + lstrcpyW(lpTitle, &lpFile[i]); + return 0; +}