[0.4.7][SHELL32] Fix the toolbar buttons in the file open dialog CORE-14327
authorJoachim Henze <Joachim.Henze@reactos.org>
Wed, 14 Feb 2018 22:23:18 +0000 (00:23 +0200)
committerJoachim Henze <Joachim.Henze@reactos.org>
Wed, 5 Oct 2022 09:55:06 +0000 (11:55 +0200)
CDefView: Make GetItemObject return an IContectMenu after setting itself as the site.
CDefViewBckgrndMenu: Make the inner context menu use the same site. Implement handling CMDSTR_VIEWLISTA and CMDSTR_VIEWDETAILSA.
CDefaultContextMenu: CMDSTR_VIEWLISTA and CMDSTR_VIEWDETAILSA shouldn't be handled in this class.
Fixes CORE-14327 and the two buttons that change the view mode

Fix picked from 0.4.8-dev-1076-g b97886ea9f17c62a849634053ef3dd0521a00848

dll/win32/shell32/CDefView.cpp
dll/win32/shell32/CDefViewBckgrndMenu.cpp
dll/win32/shell32/CDefaultContextMenu.cpp

index 1492724..04b4398 100644 (file)
@@ -1110,8 +1110,6 @@ HRESULT CDefView::FillFileMenu()
     if (FAILED_UNEXPECTEDLY(hr))
         return hr;
 
-    IUnknown_SetSite(m_pCM, (IShellView *)this);
-
     HMENU hmenu = CreatePopupMenu();
 
     hr = m_pCM->QueryContextMenu(hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, 0);
@@ -1274,8 +1272,6 @@ HRESULT CDefView::OpenSelectedItems()
     if (FAILED_UNEXPECTEDLY(hResult))
         goto cleanup;
 
-    IUnknown_SetSite(m_pCM, (IShellView *)this);
-
     hResult = m_pCM->QueryContextMenu(hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_DEFAULTONLY);
     if (FAILED_UNEXPECTEDLY(hResult))
         goto cleanup;
@@ -1327,8 +1323,6 @@ LRESULT CDefView::OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &b
     if (FAILED_UNEXPECTEDLY(hResult))
         goto cleanup;
 
-    IUnknown_SetSite(m_pCM, (IShellView *)this);
-
     /* Use 1 as the first id as we want 0 the mean that the user canceled the menu */
     hResult = m_pCM->QueryContextMenu(m_hContextMenu, 0, CONTEXT_MENU_BASE_ID, FCIDM_SHVIEWLAST, CMF_NORMAL);
     if (FAILED_UNEXPECTEDLY(hResult))
@@ -1374,8 +1368,6 @@ LRESULT CDefView::OnExplorerCommand(UINT uCommand, BOOL bUseSelection)
     if (FAILED_UNEXPECTEDLY( hResult))
         goto cleanup;
 
-    IUnknown_SetSite(m_pCM, (IShellView *)this);
-
     hResult = m_pCM->QueryContextMenu(hMenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
     if (FAILED_UNEXPECTEDLY( hResult))
         goto cleanup;
@@ -2286,6 +2278,7 @@ HRESULT WINAPI CDefView::GetItemObject(UINT uItem, REFIID riid, LPVOID *ppvOut)
                 if (FAILED_UNEXPECTEDLY(hr))
                     return hr;
 
+                IUnknown_SetSite(*((IUnknown**)ppvOut), (IShellView *)this);
             }
             else if (IsEqualIID(riid, IID_IDispatch))
             {
@@ -2304,6 +2297,10 @@ HRESULT WINAPI CDefView::GetItemObject(UINT uItem, REFIID riid, LPVOID *ppvOut)
             hr = m_pSFParent->GetUIObjectOf(m_hWnd, m_cidl, m_apidl, riid, 0, ppvOut);
             if (FAILED_UNEXPECTEDLY(hr))
                 return hr;
+
+            if (IsEqualIID(riid, IID_IContextMenu))
+                IUnknown_SetSite(*((IUnknown**)ppvOut), (IShellView *)this);
+
             break;
     }
 
index 3500e37..ae9be07 100644 (file)
@@ -126,6 +126,10 @@ WINAPI
 CDefViewBckgrndMenu::SetSite(IUnknown *pUnkSite)
 {
     m_site = pUnkSite;
+
+    if(m_folderCM)
+        IUnknown_SetSite(m_folderCM, pUnkSite);
+
     return S_OK;
 }
 
@@ -212,13 +216,24 @@ WINAPI
 CDefViewBckgrndMenu::InvokeCommand(LPCMINVOKECOMMANDINFO lpcmi)
 {
     UINT idCmd = LOWORD(lpcmi->lpVerb);
-    if(HIWORD(lpcmi->lpVerb) != 0 || idCmd < m_LastFolderCMId)
+
+    if (HIWORD(lpcmi->lpVerb) && !strcmp(lpcmi->lpVerb, CMDSTR_VIEWLISTA))
+    {
+        idCmd = FCIDM_SHVIEW_LISTVIEW;
+    }
+    else if (HIWORD(lpcmi->lpVerb) && !strcmp(lpcmi->lpVerb, CMDSTR_VIEWDETAILSA))
+    {
+        idCmd = FCIDM_SHVIEW_REPORTVIEW;
+    }
+    else if(HIWORD(lpcmi->lpVerb) != 0 || idCmd < m_LastFolderCMId)
     {
         return m_folderCM->InvokeCommand(lpcmi);
     }
-
-    /* The default part of the background menu doesn't have shifted ids so we need to convert the id offset to the real id */
-    idCmd += m_idCmdFirst;
+    else
+    {
+        /* The default part of the background menu doesn't have shifted ids so we need to convert the id offset to the real id */
+        idCmd += m_idCmdFirst;
+    }
 
     /* The commands that are handled by the def view are forwarded to it */
     switch (idCmd)
index 13d084f..dcb754b 100644 (file)
@@ -47,9 +47,7 @@ struct _StaticInvokeCommandMap_
     { "Print", 0 },  // Unimplemented
     { "Preview", 0 }, // Unimplemented
     { "Open", FCIDM_SHVIEW_OPEN },
-    { CMDSTR_NEWFOLDERA, FCIDM_SHVIEW_NEWFOLDER },
-    { CMDSTR_VIEWLISTA, FCIDM_SHVIEW_LISTVIEW },
-    { CMDSTR_VIEWDETAILSA, FCIDM_SHVIEW_REPORTVIEW }
+    { CMDSTR_NEWFOLDERA, FCIDM_SHVIEW_NEWFOLDER }
 };