X-Git-Url: https://git.reactos.org/?p=reactos.git;a=blobdiff_plain;f=reactos%2Fdll%2Fwin32%2Fcomdlg32%2Ffiledlg.c;h=bc7b51b2e41268d6b61a1cb429a1cb07f6a4244c;hp=3e9c692b3e61cd355e450f69d4c09d0051303e05;hb=b1863a26c79822a82b9c873a6ee1a2719dd8c538;hpb=0ba562cefad2799d226f2a2443b9abd8fdc3e79e diff --git a/reactos/dll/win32/comdlg32/filedlg.c b/reactos/dll/win32/comdlg32/filedlg.c index 3e9c692b3e6..bc7b51b2e41 100644 --- a/reactos/dll/win32/comdlg32/filedlg.c +++ b/reactos/dll/win32/comdlg32/filedlg.c @@ -196,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); @@ -858,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"); @@ -871,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 ) + 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) { - LPWSTR bufW = buffer; - total = lstrlenW(lpstrCurrentDir) + 1 + sizeUsed; - - /* Prepend the current path */ - n = lstrlenW(lpstrCurrentDir) + 1; - memcpy( bufW, lpstrCurrentDir, min(n,size) * sizeof(WCHAR)); - if(n %s\n",debugstr_wn(bufW, total)); + p = buffer + strlenW(buffer); + *p++ = '\\'; + SendMessageW( fodInfos->DlgInfos.hwndFileName, WM_GETTEXT, len + 1, (LPARAM)p ); } - else - { - 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)); - } - 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; } /*********************************************************************** @@ -980,8 +928,22 @@ static INT_PTR FILEDLG95_HandleCustomDialogMessages(HWND hwnd, UINT uMsg, WPARAM 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: @@ -1373,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); @@ -1798,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) @@ -1834,7 +1796,7 @@ 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)) { lstrcatW(lpstrPathAndFile, lpstrFileList); @@ -3205,7 +3167,7 @@ static HRESULT COMDLG32_StrRetToStrNW (LPWSTR 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 */ @@ -3237,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) ) { lstrcpyW(*lpstrFileList, lpstrEdit); nFileIndex = lstrlenW(lpstrEdit) + 1; - (*sizeUsed) = nFileIndex; nFileCount = 1; } - /* trailing \0 */ - (*lpstrFileList)[nFileIndex] = '\0'; - (*sizeUsed)++; + /* trailing \0 */ + (*lpstrFileList)[nFileIndex++] = '\0'; + *sizeUsed = nFileIndex; MemFree(lpstrEdit); return nFileCount; } @@ -3681,7 +3640,7 @@ static void CALLBACK FD32_UpdateResult(const FD31_DATA *lfs) priv->ofnA->lpstrFile, ofnW->nMaxFile, NULL, NULL )) priv->ofnA->lpstrFile[ofnW->nMaxFile-1] = 0; - /* offsets are not guarenteed to be the same in WCHAR to MULTIBYTE conversion */ + /* 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); @@ -3813,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 */ ) { @@ -3844,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 */ ) {