/* * Winefile * * Copyright 2000, 2003, 2004, 2005, 2008 Martin Fuchs * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */ #include "winefile.h" #ifdef _SHELL_FOLDERS static IContextMenu2* s_pctxmenu2 = NULL; IContextMenu3* s_pctxmenu3 = NULL; /* reset context menu state data */ static void CtxMenu_reset(void) { s_pctxmenu2 = NULL; s_pctxmenu3 = NULL; } /* implementation of IContextMenu::QueryInterfaces */ static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1) { IContextMenu* pcm = NULL; CtxMenu_reset(); if (IUnknown_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR) s_pctxmenu3 = (LPCONTEXTMENU3)pcm; else if (IUnknown_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR) s_pctxmenu2 = (LPCONTEXTMENU2)pcm; if (pcm) { IUnknown_Release(pcm1); return pcm; } else return pcm1; } /* handle context menu messages */ BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam) { if (s_pctxmenu3) { if (SUCCEEDED((*s_pctxmenu3->lpVtbl->HandleMenuMsg)(s_pctxmenu3, nmsg, wparam, lparam))) return TRUE; } if (s_pctxmenu2) if (SUCCEEDED((*s_pctxmenu2->lpVtbl->HandleMenuMsg)(s_pctxmenu2, nmsg, wparam, lparam))) return TRUE; return FALSE; } /* display context menu for the given shell folder */ HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y) { IContextMenu* pcm; BOOL executed = FALSE; HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm); /* HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */ if (SUCCEEDED(hr)) { HMENU hmenu = CreatePopupMenu(); pcm = CtxMenu_query_interfaces(pcm); if (hmenu) { hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL); if (SUCCEEDED(hr)) { UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL); CtxMenu_reset(); if (idCmd) { CMINVOKECOMMANDINFO cmi; cmi.cbSize = sizeof(CMINVOKECOMMANDINFO); cmi.fMask = 0; cmi.hwnd = hwndParent; cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST); cmi.lpParameters = NULL; cmi.lpDirectory = NULL; cmi.nShow = SW_SHOWNORMAL; cmi.dwHotKey = 0; cmi.hIcon = 0; hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi); executed = TRUE; } } else CtxMenu_reset(); } IUnknown_Release(pcm); } return FAILED(hr)? hr: executed? S_OK: S_FALSE; } #endif