[SHELLL32]
authorGiannis Adamopoulos <gadamopoulos@reactos.org>
Fri, 29 Jul 2016 06:21:11 +0000 (06:21 +0000)
committerGiannis Adamopoulos <gadamopoulos@reactos.org>
Fri, 29 Jul 2016 06:21:11 +0000 (06:21 +0000)
- Split GenericExtractIcon_CreateInstance into CGuidItemExtractIcon_CreateInstance, CFSExtractIcon_CreateInstance and CDrivesExtractIcon_CreateInstance.

svn path=/trunk/; revision=72041

reactos/dll/win32/shell32/folders.cpp
reactos/dll/win32/shell32/folders/CControlPanelFolder.cpp
reactos/dll/win32/shell32/folders/CDesktopFolder.cpp
reactos/dll/win32/shell32/folders/CDrivesFolder.cpp
reactos/dll/win32/shell32/folders/CFSFolder.cpp
reactos/dll/win32/shell32/wine/shell32_main.h

index 3168e5a..bde3801 100644 (file)
@@ -192,126 +192,102 @@ GetIconOverlay(LPCITEMIDLIST pidl, WCHAR * wTemp, int* pIndex)
         return FALSE;
 }
 
-HRESULT GenericExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID iid, LPVOID * ppvOut)
+HRESULT CGuidItemExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID iid, LPVOID * ppvOut)
 {
     CComPtr<IDefaultExtractIconInit>    initIcon;
+    HRESULT hr;
     GUID const * riid;
     int icon_idx;
-    UINT flags;
-    CHAR sTemp[MAX_PATH];
     WCHAR wTemp[MAX_PATH];
-    LPCITEMIDLIST pSimplePidl = pidl;
-    HRESULT hr;
 
     hr = SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit,&initIcon));
     if (FAILED(hr))
         return hr;
 
-    if (_ILIsDesktop(pSimplePidl))
+    if (_ILIsDesktop(pidl))
     {
         initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DESKTOP);
+        return initIcon->QueryInterface(iid, ppvOut);
     }
-    else if ((riid = _ILGetGUIDPointer(pSimplePidl)))
+
+    riid = _ILGetGUIDPointer(pidl);
+    if (!riid)
+        return E_FAIL;
+
+    /* my computer and other shell extensions */
+    static const WCHAR fmt[] = { 'C', 'L', 'S', 'I', 'D', '\\',
+                                 '{', '%', '0', '8', 'l', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '4', 'x', '-',
+                                 '%', '0', '2', 'x', '%', '0', '2', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x',
+                                 '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '}', 0
+                               };
+    WCHAR xriid[50];
+
+    swprintf(xriid, fmt,
+             riid->Data1, riid->Data2, riid->Data3,
+             riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
+             riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
+
+    const WCHAR* iconname = NULL;
+    if (_ILIsBitBucket(pidl))
     {
-        /* my computer and other shell extensions */
-        static const WCHAR fmt[] = { 'C', 'L', 'S', 'I', 'D', '\\',
-                                     '{', '%', '0', '8', 'l', 'x', '-', '%', '0', '4', 'x', '-', '%', '0', '4', 'x', '-',
-                                     '%', '0', '2', 'x', '%', '0', '2', 'x', '-', '%', '0', '2', 'x', '%', '0', '2', 'x',
-                                     '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '%', '0', '2', 'x', '}', 0
-                                   };
-        WCHAR xriid[50];
-
-        swprintf(xriid, fmt,
-                 riid->Data1, riid->Data2, riid->Data3,
-                 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
-                 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7]);
-
-        const WCHAR* iconname = NULL;
-        if (_ILIsBitBucket(pSimplePidl))
+        static const WCHAR szFull[] = {'F','u','l','l',0};
+        static const WCHAR szEmpty[] = {'E','m','p','t','y',0};
+        CComPtr<IEnumIDList> EnumIDList;
+        CoInitialize(NULL);
+
+        CComPtr<IShellFolder2> psfRecycleBin;
+        CComPtr<IShellFolder> psfDesktop;
+        hr = SHGetDesktopFolder(&psfDesktop);
+
+        if (SUCCEEDED(hr))
+            hr = psfDesktop->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder2, &psfRecycleBin));
+        if (SUCCEEDED(hr))
+            hr = psfRecycleBin->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &EnumIDList);
+
+        ULONG itemcount;
+        LPITEMIDLIST pidl = NULL;
+        if (SUCCEEDED(hr) && (hr = EnumIDList->Next(1, &pidl, &itemcount)) == S_OK)
         {
-            static const WCHAR szFull[] = {'F','u','l','l',0};
-            static const WCHAR szEmpty[] = {'E','m','p','t','y',0};
-            CComPtr<IEnumIDList> EnumIDList;
-            CoInitialize(NULL);
-
-            CComPtr<IShellFolder2> psfRecycleBin;
-            CComPtr<IShellFolder> psfDesktop;
-            hr = SHGetDesktopFolder(&psfDesktop);
-
-            if (SUCCEEDED(hr))
-                hr = psfDesktop->BindToObject(pSimplePidl, NULL, IID_PPV_ARG(IShellFolder2, &psfRecycleBin));
-            if (SUCCEEDED(hr))
-                hr = psfRecycleBin->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &EnumIDList);
-
-            ULONG itemcount;
-            LPITEMIDLIST pidl = NULL;
-            if (SUCCEEDED(hr) && (hr = EnumIDList->Next(1, &pidl, &itemcount)) == S_OK)
-            {
-                CoTaskMemFree(pidl);
-                iconname = szFull;
-            } else {
-                iconname = szEmpty;
-            }
+            CoTaskMemFree(pidl);
+            iconname = szFull;
+        } else {
+            iconname = szEmpty;
         }
+    }
 
-        if (HCR_GetIconW(xriid, wTemp, iconname, MAX_PATH, &icon_idx))
-        {
-            initIcon->SetNormalIcon(wTemp, icon_idx);
-        }
+    if (HCR_GetIconW(xriid, wTemp, iconname, MAX_PATH, &icon_idx))
+    {
+        initIcon->SetNormalIcon(wTemp, icon_idx);
+    }
+    else
+    {
+        if (IsEqualGUID(*riid, CLSID_MyComputer))
+            initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_COMPUTER);
+        else if (IsEqualGUID(*riid, CLSID_MyDocuments))
+            initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_DOCUMENTS);
+        else if (IsEqualGUID(*riid, CLSID_NetworkPlaces))
+            initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_NETWORK_PLACES);
         else
-        {
-            if (IsEqualGUID(*riid, CLSID_MyComputer))
-                initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_COMPUTER);
-            else if (IsEqualGUID(*riid, CLSID_MyDocuments))
-                initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_DOCUMENTS);
-            else if (IsEqualGUID(*riid, CLSID_NetworkPlaces))
-                initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_MY_NETWORK_PLACES);
-            else
-                initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_FOLDER);
-        }
+            initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_FOLDER);
     }
 
-    else if (_ILIsDrive (pSimplePidl))
-    {
-        static const WCHAR drive[] = { 'D', 'r', 'i', 'v', 'e', 0 };
-        int icon_idx = -1;
+    return initIcon->QueryInterface(iid, ppvOut);
+}
 
-        if (_ILGetDrive(pSimplePidl, sTemp, MAX_PATH))
-        {
-            switch(GetDriveTypeA(sTemp))
-            {
-                case DRIVE_REMOVABLE:
-                    icon_idx = IDI_SHELL_3_14_FLOPPY;
-                    break;
-                case DRIVE_CDROM:
-                    icon_idx = IDI_SHELL_CDROM;
-                    break;
-                case DRIVE_REMOTE:
-                    icon_idx = IDI_SHELL_NETDRIVE;
-                    break;
-                case DRIVE_RAMDISK:
-                    icon_idx = IDI_SHELL_RAMDISK;
-                    break;
-                case DRIVE_NO_ROOT_DIR:
-                    icon_idx = IDI_SHELL_CDROM;
-                    break;
-            }
-        }
+HRESULT CFSExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID iid, LPVOID * ppvOut)
+{
+    CComPtr<IDefaultExtractIconInit>    initIcon;
+    HRESULT hr;
+    int icon_idx;
+    UINT flags;
+    CHAR sTemp[MAX_PATH];
+    WCHAR wTemp[MAX_PATH];
 
-        if (icon_idx != -1)
-        {
-            initIcon->SetNormalIcon(swShell32Name, -icon_idx);
-        }
-        else
-        {
-            if (HCR_GetIconW(drive, wTemp, NULL, MAX_PATH, &icon_idx))
-                initIcon->SetNormalIcon(wTemp, icon_idx);
-            else
-                initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DRIVE);
-        }
-    }
+    hr = SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit,&initIcon));
+    if (FAILED(hr))
+        return hr;
 
-    else if (_ILIsFolder (pSimplePidl))
+    if (_ILIsFolder (pidl))
     {
         if (SUCCEEDED(getIconLocationForFolder(psf, 
                           pidl, 0, wTemp, MAX_PATH,
@@ -350,7 +326,7 @@ HRESULT GenericExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl
     {
         BOOL found = FALSE;
 
-        if (_ILGetExtension(pSimplePidl, sTemp, MAX_PATH))
+        if (_ILGetExtension(pidl, sTemp, MAX_PATH))
         {
             if (HCR_MapTypeToValueA(sTemp, sTemp, MAX_PATH, TRUE)
                     && HCR_GetIconA(sTemp, sTemp, NULL, MAX_PATH, &icon_idx))
index 73962e7..6943f28 100644 (file)
@@ -130,7 +130,7 @@ HRESULT CCPLExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, R
     PIDLCPanelStruct *pData = _ILGetCPanelPointer(pidl);
     if (!pData)
     {
-        return GenericExtractIcon_CreateInstance(psf, pidl, riid, ppvOut);
+        return CGuidItemExtractIcon_CreateInstance(psf, pidl, riid, ppvOut);
     }
 
     CComPtr<IDefaultExtractIconInit> initIcon;
index e0e7a8d..b8da039 100644 (file)
@@ -642,7 +642,7 @@ HRESULT WINAPI CDesktopFolder::GetUIObjectOf(
     }
     else if ((IsEqualIID (riid, IID_IExtractIconA) || IsEqualIID (riid, IID_IExtractIconW)) && (cidl == 1))
     {
-        hr = GenericExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
+        hr = CGuidItemExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
     }
     else
         hr = E_NOINTERFACE;
index c8a1f96..f042331 100644 (file)
@@ -39,6 +39,58 @@ CDrivesFolderEnum is only responsible for returning the physical items.
 *   IShellFolder implementation
 */
 
+HRESULT CDrivesExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID riid, LPVOID * ppvOut)
+{
+    if (!_ILIsDrive(pidl))
+    {
+        return CGuidItemExtractIcon_CreateInstance(psf, pidl, riid, ppvOut);
+    }
+
+    CComPtr<IDefaultExtractIconInit> initIcon;
+    HRESULT hr = SHCreateDefaultExtractIcon(IID_PPV_ARG(IDefaultExtractIconInit, &initIcon));
+    if (FAILED(hr))
+        return NULL;
+
+    CHAR* pszDrive = _ILGetDataPointer(pidl)->u.drive.szDriveName;
+    WCHAR wTemp[MAX_PATH];
+    int icon_idx = -1;
+
+    if (pszDrive)
+    {
+        switch(GetDriveTypeA(pszDrive))
+        {
+            case DRIVE_REMOVABLE:
+                icon_idx = IDI_SHELL_3_14_FLOPPY;
+                break;
+            case DRIVE_CDROM:
+                icon_idx = IDI_SHELL_CDROM;
+                break;
+            case DRIVE_REMOTE:
+                icon_idx = IDI_SHELL_NETDRIVE;
+                break;
+            case DRIVE_RAMDISK:
+                icon_idx = IDI_SHELL_RAMDISK;
+                break;
+            case DRIVE_NO_ROOT_DIR:
+                icon_idx = IDI_SHELL_CDROM;
+                break;
+        }
+    }
+
+    if (icon_idx != -1)
+    {
+        initIcon->SetNormalIcon(swShell32Name, -icon_idx);
+    }
+    else
+    {
+        if (HCR_GetIconW(L"Drive", wTemp, NULL, MAX_PATH, &icon_idx))
+            initIcon->SetNormalIcon(wTemp, icon_idx);
+        else
+            initIcon->SetNormalIcon(swShell32Name, -IDI_SHELL_DRIVE);
+    }
+
+    return initIcon->QueryInterface(riid, ppvOut);
+}
 class CDrivesFolderEnum :
     public CEnumIDListBase
 {
@@ -457,7 +509,7 @@ HRESULT WINAPI CDrivesFolder::GetUIObjectOf(HWND hwndOwner,
     }
     else if ((IsEqualIID (riid, IID_IExtractIconA) || IsEqualIID (riid, IID_IExtractIconW)) && (cidl == 1))
     {
-        hr = GenericExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
+        hr = CDrivesExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
     }
     else if (IsEqualIID (riid, IID_IDropTarget) && (cidl >= 1))
     {
index c6eae61..4bd24f9 100644 (file)
@@ -516,7 +516,7 @@ HRESULT WINAPI CFSFolder::GetUIObjectOf(HWND hwndOwner,
         }
         else if ((IsEqualIID (riid, IID_IExtractIconA) || IsEqualIID (riid, IID_IExtractIconW)) && (cidl == 1))
         {
-            hr = GenericExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
+            hr = CFSExtractIcon_CreateInstance(this, apidl[0], riid, &pObj);
         }
         else if (IsEqualIID (riid, IID_IDropTarget))
         {
index 49ebd3d..1a2827b 100644 (file)
@@ -80,7 +80,8 @@ HRESULT WINAPI IFileSystemBindData_Constructor(const WIN32_FIND_DATAW *pfd, LPBC
 HRESULT WINAPI CPanel_ExtractIconA(LPITEMIDLIST pidl, LPCSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize) DECLSPEC_HIDDEN;
 HRESULT WINAPI CPanel_ExtractIconW(LPITEMIDLIST pidl, LPCWSTR pszFile, UINT nIconIndex, HICON *phiconLarge, HICON *phiconSmall, UINT nIconSize) DECLSPEC_HIDDEN;
 
-HRESULT GenericExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID iid, LPVOID * ppvOut);
+HRESULT CGuidItemExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID iid, LPVOID * ppvOut);
+HRESULT CFSExtractIcon_CreateInstance(IShellFolder * psf, LPCITEMIDLIST pidl, REFIID iid, LPVOID * ppvOut);
 
 /* initialisation for FORMATETC */
 #define InitFormatEtc(fe, cf, med) \