[BROWSEUI]
authorDavid Quintana <gigaherz@gmail.com>
Sat, 9 Aug 2014 15:56:05 +0000 (15:56 +0000)
committerDavid Quintana <gigaherz@gmail.com>
Sat, 9 Aug 2014 15:56:05 +0000 (15:56 +0000)
* Fix usage of outdated CMergedFolder to use the proper interface.

svn path=/branches/shell-experiments/; revision=63847

base/shell/rshell/CStartMenu.cpp
dll/win32/browseui/internettoolbar.cpp
dll/win32/browseui/shellbrowser.cpp

index dfefa3f..e47cd8b 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "CMergedFolder.h"
 
+// TODO: declare these GUIDs and interfaces in the right place (whatever that may be)
 IID IID_IAugmentedShellFolder = { 0x91EA3F8C, 0xC99B, 0x11D0, { 0x98, 0x15, 0x00, 0xC0, 0x4F, 0xD9, 0x19, 0x72 } };
 IID IID_IAugmentedShellFolder2 = { 0x8DB3B3F4, 0x6CFE, 0x11D1, { 0x8A, 0xE9, 0x00, 0xC0, 0x4F, 0xD9, 0x18, 0xD0 } };
 CLSID CLSID_MergedFolder = { 0x26FDC864, 0xBE88, 0x46E7, { 0x92, 0x35, 0x03, 0x2D, 0x8E, 0xA5, 0x16, 0x2E } };
@@ -309,7 +310,7 @@ HRESULT BindToDesktop(LPCITEMIDLIST pidl, IShellFolder ** ppsfResult)
     return hr;
 }
 
-HRESULT GetStartMenuFolder(IShellFolder ** ppsfStartMenu)
+static HRESULT GetStartMenuFolder(IShellFolder ** ppsfStartMenu)
 {
     HRESULT hr;
     LPITEMIDLIST pidlUserStartMenu;
index 3450f9f..3e056d9 100644 (file)
@@ -31,6 +31,22 @@ toolbar, and address band for an explorer window
 
 #define USE_CUSTOM_MENUBAND 1
 
+#if 1
+// TODO: declare these GUIDs and interfaces in the right place (whatever that may be)
+
+IID IID_IAugmentedShellFolder = { 0x91EA3F8C, 0xC99B, 0x11D0, { 0x98, 0x15, 0x00, 0xC0, 0x4F, 0xD9, 0x19, 0x72 } };
+CLSID CLSID_MergedFolder = { 0x26FDC864, 0xBE88, 0x46E7, { 0x92, 0x35, 0x03, 0x2D, 0x8E, 0xA5, 0x16, 0x2E } };
+
+interface IAugmentedShellFolder : public IShellFolder
+{
+    virtual HRESULT STDMETHODCALLTYPE AddNameSpace(LPGUID, IShellFolder *, LPCITEMIDLIST, ULONG) = 0;
+    virtual HRESULT STDMETHODCALLTYPE GetNameSpaceID(LPCITEMIDLIST, LPGUID) = 0;
+    virtual HRESULT STDMETHODCALLTYPE QueryNameSpace(ULONG, LPGUID, IShellFolder **) = 0;
+    virtual HRESULT STDMETHODCALLTYPE EnumNameSpace(ULONG, PULONG) = 0;
+};
+
+#endif
+
 // navigation controls and menubar just send a message to parent window
 /*
 TODO:
@@ -74,7 +90,11 @@ extern HRESULT CreateBandProxy(REFIID riid, void **ppv);
 extern HRESULT CreateAddressBand(REFIID riid, void **ppv);
 
 typedef HRESULT(WINAPI * PMENUBAND_CONSTRUCTOR)(REFIID riid, void **ppv);
-typedef HRESULT(WINAPI * PMERGEDFOLDER_CONSTRUCTOR)(IShellFolder* userLocal, IShellFolder* allUsers, REFIID riid, LPVOID *ppv);
+typedef HRESULT(WINAPI * PMERGEDFOLDER_CONSTRUCTOR)(REFIID riid, void **ppv);
+
+HMODULE hRShell = NULL;
+PMERGEDFOLDER_CONSTRUCTOR pCMergedFolder_Constructor = NULL;
+PMENUBAND_CONSTRUCTOR     pCMenuBand_Constructor = NULL;
 
 HRESULT IUnknown_HasFocusIO(IUnknown * punk)
 {
@@ -392,15 +412,105 @@ CMenuCallback::~CMenuCallback()
 {
 }
 
+static HRESULT BindToDesktop(LPCITEMIDLIST pidl, IShellFolder ** ppsfResult)
+{
+    HRESULT hr;
+    CComPtr<IShellFolder> psfDesktop;
+
+    *ppsfResult = NULL;
+
+    hr = SHGetDesktopFolder(&psfDesktop);
+    if (FAILED(hr))
+        return hr;
+
+    hr = psfDesktop->BindToObject(pidl, NULL, IID_PPV_ARG(IShellFolder, ppsfResult));
+
+    return hr;
+}
+
+static HRESULT GetFavoritesFolder(IShellFolder ** ppsfFavorites, LPITEMIDLIST * ppidl)
+{
+    HRESULT hr;
+    LPITEMIDLIST pidlUserFavorites;
+    LPITEMIDLIST pidlCommonFavorites;
+    CComPtr<IShellFolder> psfUserFavorites;
+    CComPtr<IShellFolder> psfCommonFavorites;
+    CComPtr<IAugmentedShellFolder> pasf;
+
+    *ppsfFavorites = NULL;
+
+    hr = SHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidlUserFavorites);
+    if (FAILED(hr))
+        return hr;
+
+    if (FAILED(SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_FAVORITES, &pidlCommonFavorites)))
+    {
+        hr = BindToDesktop(pidlUserFavorites, ppsfFavorites);
+        *ppidl = pidlUserFavorites;
+        return hr;
+    }
+
+    hr = BindToDesktop(pidlUserFavorites, &psfUserFavorites);
+    if (FAILED_UNEXPECTEDLY(hr))
+        return hr;
+
+    hr = BindToDesktop(pidlCommonFavorites, &psfCommonFavorites);
+    if (FAILED_UNEXPECTEDLY(hr))
+        return hr;
+
+#if 1
+    if (!hRShell)
+    {
+        hRShell = GetModuleHandle(L"rshell.dll");
+        if (!hRShell)
+            hRShell = LoadLibrary(L"rshell.dll");
+    }
+
+    if (!pCMergedFolder_Constructor)
+        pCMergedFolder_Constructor = (PMERGEDFOLDER_CONSTRUCTOR) GetProcAddress(hRShell, "CMergedFolder_Constructor");
+
+    if (pCMergedFolder_Constructor)
+    {
+        hr = pCMergedFolder_Constructor(IID_PPV_ARG(IAugmentedShellFolder, &pasf));
+    }
+    else
+    {
+        hr = E_FAIL;
+    }
+#else
+    hr = CoCreateInstance(CLSID_MergedFolder, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IAugmentedShellFolder, &pasf));
+#endif
+    if (FAILED_UNEXPECTEDLY(hr))
+    {
+        *ppsfFavorites = psfUserFavorites.Detach();
+        *ppidl = pidlUserFavorites;
+        ILFree(pidlCommonFavorites);
+        return hr;
+    }
+
+    hr = pasf->AddNameSpace(NULL, psfUserFavorites, pidlUserFavorites, 0xFF00);
+    if (FAILED_UNEXPECTEDLY(hr))
+        return hr;
+
+    hr = pasf->AddNameSpace(NULL, psfCommonFavorites, pidlCommonFavorites, 0);
+    if (FAILED_UNEXPECTEDLY(hr))
+        return hr;
+
+    hr = pasf->QueryInterface(IID_PPV_ARG(IShellFolder, ppsfFavorites));
+    pasf.Release();
+
+    ILFree(pidlCommonFavorites);
+    ILFree(pidlUserFavorites);
+
+    return hr;
+}
+
 HRESULT STDMETHODCALLTYPE CMenuCallback::GetObject(LPSMDATA psmd, REFIID riid, void **ppvObject)
 {
     CComPtr<IShellMenu>                     parentMenu;
     CComPtr<IShellMenu>                     newMenu;
     CComPtr<IShellFolder>                   favoritesFolder;
     LPITEMIDLIST                            favoritesPIDL;
-    CComPtr<IShellFolder>                   commonFavsFolder;
-    LPITEMIDLIST                            commonFavsPIDL;
-    CComPtr<IShellFolder>                   mergedFolder;
     HWND                                    ownerWindow;
     HMENU                                   parentHMenu;
     HMENU                                   favoritesHMenu;
@@ -428,12 +538,19 @@ HRESULT STDMETHODCALLTYPE CMenuCallback::GetObject(LPSMDATA psmd, REFIID riid, v
         if (favoritesHMenu == NULL)
             return E_FAIL;
 #if USE_CUSTOM_MENUBAND
-        HMODULE hrs = LoadLibrary(L"rshell.dll");
+        if (!hRShell)
+        {
+            hRShell = GetModuleHandle(L"rshell.dll");
+            if (!hRShell)
+                hRShell = LoadLibrary(L"rshell.dll");
+        }
 
-        PMENUBAND_CONSTRUCTOR func = (PMENUBAND_CONSTRUCTOR) GetProcAddress(hrs, "CMenuBand_Constructor");
-        if (func)
+        if (!pCMenuBand_Constructor)
+            pCMenuBand_Constructor = (PMENUBAND_CONSTRUCTOR) GetProcAddress(hRShell, "CMenuBand_Constructor");
+
+        if (pCMenuBand_Constructor)
         {
-            hResult = func(IID_PPV_ARG(IShellMenu, &newMenu));
+            hResult = pCMenuBand_Constructor(IID_PPV_ARG(IShellMenu, &newMenu));
         }
         else
         {
@@ -452,36 +569,15 @@ HRESULT STDMETHODCALLTYPE CMenuCallback::GetObject(LPSMDATA psmd, REFIID riid, v
         hResult = newMenu->SetMenu(favoritesHMenu, ownerWindow, SMSET_TOP | SMSET_DONTOWN);
         if (FAILED_UNEXPECTEDLY(hResult))
             return hResult;
-        hResult = SHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &favoritesPIDL);
-        if (FAILED_UNEXPECTEDLY(hResult))
-            return hResult;
-        hResult = SHBindToFolder(favoritesPIDL, &favoritesFolder);
-        if (FAILED_UNEXPECTEDLY(hResult))
-            return hResult;
+
         RegCreateKeyEx(HKEY_CURRENT_USER, szFavoritesKey,
                 0, NULL, 0, KEY_READ | KEY_WRITE, NULL, &orderRegKey, &disposition);
-#if 1 /*USE_MERGED_FAVORITES*/
-        hResult = SHGetSpecialFolderLocation(NULL, CSIDL_COMMON_FAVORITES, &commonFavsPIDL);
-        if (FAILED_UNEXPECTEDLY(hResult))
-            return hResult;
-        hResult = SHBindToFolder(commonFavsPIDL, &commonFavsFolder);
+
+        hResult = GetFavoritesFolder(&favoritesFolder, &favoritesPIDL);
         if (FAILED_UNEXPECTEDLY(hResult))
             return hResult;
-        ILFree(commonFavsPIDL);
-        
-        PMERGEDFOLDER_CONSTRUCTOR mfconstruct = (PMERGEDFOLDER_CONSTRUCTOR) GetProcAddress(hrs, "CMergedFolder_Constructor");
-        if (mfconstruct)
-        {
-            hResult = mfconstruct(favoritesFolder, commonFavsFolder, IID_PPV_ARG(IShellFolder, &mergedFolder));
-        }
-        else
-        {
-            mergedFolder = favoritesFolder;
-        }
-#else
-        mergedFolder = favoritesFolder;
-#endif
-        hResult = newMenu->SetShellFolder(mergedFolder, favoritesPIDL, orderRegKey, SMSET_BOTTOM | SMINIT_CACHED | SMINV_ID);
+
+        hResult = newMenu->SetShellFolder(favoritesFolder, favoritesPIDL, orderRegKey, SMSET_BOTTOM | SMINIT_CACHED | SMINV_ID);
         ILFree(favoritesPIDL);
         if (SUCCEEDED(hResult))
             fFavoritesMenu.Attach(newMenu.Detach());
index 5de7aaf..9a0a8f1 100644 (file)
 extern "C"
 BOOL WINAPI Shell_GetImageLists(
     _Out_  HIMAGELIST *phiml,
-    _Out_  HIMAGELIST *phimlSmall
-    );
+    _Out_  HIMAGELIST *phimlSmall);
 
 extern HRESULT IUnknown_ShowDW(IUnknown * punk, BOOL fShow);
 
 #include "newatlinterfaces.h"
 
-
 /*
 TODO:
   **Provide implementation of new and delete that use LocalAlloc
@@ -1853,17 +1851,8 @@ HRESULT STDMETHODCALLTYPE CShellBrowser::InsertMenusSB(HMENU hmenuShared, LPOLEM
 {
     HMENU mainMenu = LoadMenu(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(IDM_CABINET_MAINMENU));
 
-    //DbgPrint("Menu from shell32:\n");
-    //DbgDumpMenu(hmenuShared);
-
-    //DbgPrint("Menu from browseui:\n");
-    //DbgDumpMenu(mainMenu);
-
     Shell_MergeMenus(hmenuShared, mainMenu, 0, 0, FCIDM_BROWSERLAST, MM_SUBMENUSHAVEIDS);
 
-    //DbgPrint("Merged menu:\n");
-    //DbgDumpMenu(hmenuShared);
-
     int GCCU(itemCount3) = GetMenuItemCount(hmenuShared);
     Unused(itemCount3);
 
@@ -1880,9 +1869,6 @@ HRESULT STDMETHODCALLTYPE CShellBrowser::SetMenuSB(HMENU hmenuShared, HOLEMENU h
     CComPtr<IShellMenu>                     shellMenu;
     HRESULT                                 hResult;
 
-    //DbgPrint("SetMenuSB:\n");
-    //DbgDumpMenu(hmenuShared);
-
     if (hmenuShared && IsMenu(hmenuShared) == FALSE)
         return E_FAIL;
     hResult = GetMenuBand(IID_PPV_ARG(IShellMenu, &shellMenu));
@@ -3206,14 +3192,8 @@ LRESULT CShellBrowser::OnInitMenuPopup(UINT uMsg, WPARAM wParam, LPARAM lParam,
         menuIndex = 5;
     }
 
-    //DbgPrint("Before relay:\n");
-    //DbgDumpMenu(theMenu);
-
     LRESULT ret = RelayMsgToShellView(uMsg, wParam, menuIndex, bHandled);
 
-    //DbgPrint("After relay:\n");
-    //DbgDumpMenu(theMenu);
-
     return ret;
 }