Author: gadamopoulos Date: Mon Aug 31 11:28:24 2015 New Revision: 68877
URL: http://svn.reactos.org/svn/reactos?rev=68877&view=rev Log: [SHELL32] - Make SHELL32_GetDisplayNameOfChild return the result via a STRRET. Fix all callers accordingly. - Avoid any heap allocations if a shell folder needs to forward the GetDisplayNameOf call to a child.
Modified: trunk/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp trunk/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp trunk/reactos/dll/win32/shell32/folders/CFSFolder.cpp trunk/reactos/dll/win32/shell32/shfldr.h trunk/reactos/dll/win32/shell32/shlfolder.cpp
Modified: trunk/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/C... ============================================================================== --- trunk/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/shell32/folders/CDesktopFolder.cpp [iso-8859-1] Mon Aug 31 11:28:24 2015 @@ -660,7 +660,11 @@ if (!strRet) return E_INVALIDARG;
- if (!_ILIsDesktop(pidl) && _ILIsPidlSimple(pidl) && _ILIsSpecialFolder(pidl)) + if (!_ILIsPidlSimple (pidl)) + { + return SHELL32_GetDisplayNameOfChild(this, pidl, dwFlags, strRet); + } + else if (!_ILIsDesktop(pidl) && ILIsSpecialFolder(pidl)) { return SHELL32_GetDisplayNameOfGUIDItem(this, L"", pidl, dwFlags, strRet); } @@ -677,7 +681,7 @@ else HCR_GetClassNameW(CLSID_ShellDesktop, pszPath, MAX_PATH); } - else if (_ILIsPidlSimple (pidl)) + else { int cLen = 0;
@@ -709,12 +713,6 @@ if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags); } - } - else - { - /* a complex pidl, let the subfolder do the work */ - hr = SHELL32_GetDisplayNameOfChild (this, pidl, dwFlags, - pszPath, MAX_PATH); }
if (SUCCEEDED(hr))
Modified: trunk/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/C... ============================================================================== --- trunk/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/shell32/folders/CDrivesFolder.cpp [iso-8859-1] Mon Aug 31 11:28:24 2015 @@ -483,6 +483,11 @@ if (!strRet) return E_INVALIDARG;
+ if (!_ILIsPidlSimple (pidl)) + { + return SHELL32_GetDisplayNameOfChild(this, pidl, dwFlags, strRet); + } + pszPath = (LPWSTR)CoTaskMemAlloc((MAX_PATH + 1) * sizeof(WCHAR)); if (!pszPath) return E_OUTOFMEMORY; @@ -496,7 +501,7 @@ pszPath[1] = ':'; SHELL32_GUIDToStringW(CLSID_MyComputer, &pszPath[2]); } - else if (_ILIsPidlSimple(pidl)) + else { if (_ILIsSpecialFolder(pidl)) return SHELL32_GetDisplayNameOfGUIDItem(this, L"::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", pidl, dwFlags, strRet); @@ -557,11 +562,6 @@ return E_INVALIDARG; } } - else - { - /* Complex pidl. Let the child folder do the work */ - hr = SHELL32_GetDisplayNameOfChild(this, pidl, dwFlags, pszPath, MAX_PATH); - }
if (SUCCEEDED(hr)) {
Modified: trunk/reactos/dll/win32/shell32/folders/CFSFolder.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/folders/C... ============================================================================== --- trunk/reactos/dll/win32/shell32/folders/CFSFolder.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/shell32/folders/CFSFolder.cpp [iso-8859-1] Mon Aug 31 11:28:24 2015 @@ -591,67 +591,47 @@ HRESULT WINAPI CFSFolder::GetDisplayNameOf(PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet) { - LPWSTR pszPath; - - HRESULT hr = S_OK; - int len = 0; - - TRACE("(%p)->(pidl=%p,0x%08x,%p)\n", this, pidl, dwFlags, strRet); - pdump(pidl); - if (!pidl || !strRet) return E_INVALIDARG;
- pszPath = (LPWSTR)CoTaskMemAlloc((MAX_PATH + 1) * sizeof(WCHAR)); + /* If it is a complex pidl, let the child handle it */ + if (!_ILIsPidlSimple (pidl)) /* complex pidl */ + { + return SHELL32_GetDisplayNameOfChild(this, pidl, dwFlags, strRet); + } + else if (!pidl->mkid.cb) /* empty pidl */ + { + /* If it is an empty pidl return only the path of the folder */ + if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) && + (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) && + sPathTarget) + { + return SHSetStrRet(strRet, sPathTarget); + } + return E_INVALIDARG; + } + + int len = 0; + LPWSTR pszPath = (LPWSTR)CoTaskMemAlloc((MAX_PATH + 1) * sizeof(WCHAR)); if (!pszPath) return E_OUTOFMEMORY;
- if (_ILIsDesktop(pidl)) /* empty pidl */ - { - if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) && - (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER)) - { - if (sPathTarget) - lstrcpynW(pszPath, sPathTarget, MAX_PATH); - } - else - hr = E_INVALIDARG; /* pidl has to contain exactly one non null SHITEMID */ - } - else if (_ILIsPidlSimple(pidl)) - { - if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) && - (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) && - sPathTarget) - { - lstrcpynW(pszPath, sPathTarget, MAX_PATH); - PathAddBackslashW(pszPath); - len = wcslen(pszPath); - } - _ILSimpleGetTextW(pidl, pszPath + len, MAX_PATH + 1 - len); - if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags); - } else - hr = SHELL32_GetDisplayNameOfChild(this, pidl, dwFlags, pszPath, MAX_PATH); - - if (SUCCEEDED(hr)) { - /* Win9x always returns ANSI strings, NT always returns Unicode strings */ - if (GetVersion() & 0x80000000) - { - strRet->uType = STRRET_CSTR; - if (!WideCharToMultiByte(CP_ACP, 0, pszPath, -1, strRet->cStr, MAX_PATH, - NULL, NULL)) - strRet->cStr[0] = '\0'; - CoTaskMemFree(pszPath); - } - else - { - strRet->uType = STRRET_WSTR; - strRet->pOleStr = pszPath; - } - } else - CoTaskMemFree(pszPath); + if ((GET_SHGDN_FOR(dwFlags) & SHGDN_FORPARSING) && + (GET_SHGDN_RELATION(dwFlags) != SHGDN_INFOLDER) && + sPathTarget) + { + lstrcpynW(pszPath, sPathTarget, MAX_PATH); + PathAddBackslashW(pszPath); + len = wcslen(pszPath); + } + _ILSimpleGetTextW(pidl, pszPath + len, MAX_PATH + 1 - len); + if (!_ILIsFolder(pidl)) SHELL_FS_ProcessDisplayFilename(pszPath, dwFlags); + + strRet->uType = STRRET_WSTR; + strRet->pOleStr = pszPath;
TRACE ("-- (%p)->(%s)\n", this, strRet->uType == STRRET_CSTR ? strRet->cStr : debugstr_w(strRet->pOleStr)); - return hr; + return S_OK; }
/**************************************************************************
Modified: trunk/reactos/dll/win32/shell32/shfldr.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shfldr.h?... ============================================================================== --- trunk/reactos/dll/win32/shell32/shfldr.h [iso-8859-1] (original) +++ trunk/reactos/dll/win32/shell32/shfldr.h [iso-8859-1] Mon Aug 31 11:28:24 2015 @@ -39,8 +39,7 @@ LPCWSTR GetNextElementW (LPCWSTR pszNext, LPWSTR pszOut, DWORD dwOut); HRESULT SHELL32_ParseNextElement (IShellFolder2 * psf, HWND hwndOwner, LPBC pbc, LPITEMIDLIST * pidlInOut, LPOLESTR szNext, DWORD * pEaten, DWORD * pdwAttributes); -HRESULT SHELL32_GetDisplayNameOfChild (IShellFolder2 * psf, LPCITEMIDLIST pidl, DWORD dwFlags, LPWSTR szOut, - DWORD dwOutLen); +HRESULT SHELL32_GetDisplayNameOfChild (IShellFolder2 * psf, LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet);
HRESULT SHELL32_BindToChild (LPCITEMIDLIST pidlRoot, LPCWSTR pathRoot, LPCITEMIDLIST pidlComplete, REFIID riid, LPVOID * ppvOut);
Modified: trunk/reactos/dll/win32/shell32/shlfolder.cpp URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/win32/shell32/shlfolder... ============================================================================== --- trunk/reactos/dll/win32/shell32/shlfolder.cpp [iso-8859-1] (original) +++ trunk/reactos/dll/win32/shell32/shlfolder.cpp [iso-8859-1] Mon Aug 31 11:28:24 2015 @@ -335,54 +335,34 @@ * virtual folders with the registry key WantsFORPARSING set. */ HRESULT SHELL32_GetDisplayNameOfChild (IShellFolder2 * psf, - LPCITEMIDLIST pidl, DWORD dwFlags, LPWSTR szOut, DWORD dwOutLen) -{ - LPITEMIDLIST pidlFirst; - HRESULT hr = E_INVALIDARG; - - TRACE ("(%p)->(pidl=%p 0x%08x %p 0x%08x)\n", psf, pidl, dwFlags, szOut, dwOutLen); - pdump (pidl); - - pidlFirst = ILCloneFirst(pidl); - if (pidlFirst) - { - CComPtr<IShellFolder> psfChild; - - hr = psf->BindToObject(pidlFirst, NULL, IID_PPV_ARG(IShellFolder, &psfChild)); - if (SUCCEEDED (hr)) - { - STRRET strTemp; - LPITEMIDLIST pidlNext = ILGetNext (pidl); - - hr = psfChild->GetDisplayNameOf(pidlNext, dwFlags, &strTemp); - if (SUCCEEDED (hr)) - { - if(!StrRetToStrNW (szOut, dwOutLen, &strTemp, pidlNext)) - hr = E_FAIL; - } - } - ILFree (pidlFirst); - } else - hr = E_OUTOFMEMORY; - - TRACE ("-- ret=0x%08x %s\n", hr, debugstr_w(szOut)); + LPCITEMIDLIST pidl, DWORD dwFlags, LPSTRRET strRet) +{ + LPITEMIDLIST pidlFirst = ILCloneFirst(pidl); + if (!pidlFirst) + return E_OUTOFMEMORY; + + CComPtr<IShellFolder> psfChild; + HRESULT hr = psf->BindToObject(pidlFirst, NULL, IID_PPV_ARG(IShellFolder, &psfChild)); + if (SUCCEEDED (hr)) + { + hr = psfChild->GetDisplayNameOf(ILGetNext (pidl), dwFlags, strRet); + } + ILFree (pidlFirst);
return hr; }
HRESULT SHELL32_GetDisplayNameOfGUIDItem(IShellFolder2* psf, LPCWSTR pszFolderPath, PCUITEMID_CHILD pidl, DWORD dwFlags, LPSTRRET strRet) { - HRESULT hr = S_OK; + HRESULT hr; GUID const *clsid = _ILGetGUIDPointer (pidl);
if (!strRet) return E_INVALIDARG;
- LPWSTR pszPath = (LPWSTR)CoTaskMemAlloc((MAX_PATH + 1) * sizeof(WCHAR)); - if (!pszPath) - return E_OUTOFMEMORY; - - if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING) + /* First of all check if we need to query the name from the child item */ + if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING && + GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) { int bWantsForParsing;
@@ -408,32 +388,38 @@ } }
- if ((GET_SHGDN_RELATION (dwFlags) == SHGDN_NORMAL) && - bWantsForParsing) + if (bWantsForParsing) { /* - * we need the filesystem path to the destination folder. - * Only the folder itself can know it - */ - hr = SHELL32_GetDisplayNameOfChild (psf, pidl, dwFlags, - pszPath, - MAX_PATH); - } - else - { - wcscpy(pszPath, pszFolderPath); - PWCHAR pItemName = &pszPath[wcslen(pszPath)]; - - /* parsing name like ::{...} */ - pItemName[0] = ':'; - pItemName[1] = ':'; - SHELL32_GUIDToStringW (*clsid, &pItemName[2]); - } + * we need the filesystem path to the destination folder. + * Only the folder itself can know it + */ + return SHELL32_GetDisplayNameOfChild (psf, pidl, dwFlags, strRet); + } + } + + /* Allocate the buffer for the result */ + LPWSTR pszPath = (LPWSTR)CoTaskMemAlloc((MAX_PATH + 1) * sizeof(WCHAR)); + if (!pszPath) + return E_OUTOFMEMORY; + + hr = S_OK; + + if (GET_SHGDN_FOR (dwFlags) == SHGDN_FORPARSING) + { + wcscpy(pszPath, pszFolderPath); + PWCHAR pItemName = &pszPath[wcslen(pszPath)]; + + /* parsing name like ::{...} */ + pItemName[0] = ':'; + pItemName[1] = ':'; + SHELL32_GUIDToStringW (*clsid, &pItemName[2]); } else { /* user friendly name */ - HCR_GetClassNameW (*clsid, pszPath, MAX_PATH); + if (!HCR_GetClassNameW (*clsid, pszPath, MAX_PATH)) + hr = E_FAIL; }
if (SUCCEEDED(hr))