shelltools.c

Go to the documentation of this file.
00001 /*
00002  * Winefile
00003  *
00004  * Copyright 2000, 2003, 2004, 2005, 2008 Martin Fuchs
00005  *
00006  * This library is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU Lesser General Public
00008  * License as published by the Free Software Foundation; either
00009  * version 2.1 of the License, or (at your option) any later version.
00010  *
00011  * This library is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public
00017  * License along with this library; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00019  */
00020 
00021 #include "winefile.h"
00022 
00023 
00024 #ifdef _SHELL_FOLDERS
00025 
00026 static IContextMenu2* s_pctxmenu2 = NULL;
00027 IContextMenu3* s_pctxmenu3 = NULL;
00028 
00029 /* reset context menu state data */
00030 static void CtxMenu_reset(void)
00031 {
00032     s_pctxmenu2 = NULL;
00033     s_pctxmenu3 = NULL;
00034 }
00035 
00036 /* implementation of IContextMenu::QueryInterfaces */
00037 static IContextMenu* CtxMenu_query_interfaces(IContextMenu* pcm1)
00038 {
00039     IContextMenu* pcm = NULL;
00040 
00041     CtxMenu_reset();
00042 
00043     if (IUnknown_QueryInterface(pcm1, &IID_IContextMenu3, (void**)&pcm) == NOERROR)
00044         s_pctxmenu3 = (LPCONTEXTMENU3)pcm;
00045     else if (IUnknown_QueryInterface(pcm1, &IID_IContextMenu2, (void**)&pcm) == NOERROR)
00046         s_pctxmenu2 = (LPCONTEXTMENU2)pcm;
00047 
00048     if (pcm) {
00049         IUnknown_Release(pcm1);
00050         return pcm;
00051     } else
00052         return pcm1;
00053 }
00054 
00055 /* handle context menu messages */
00056 BOOL CtxMenu_HandleMenuMsg(UINT nmsg, WPARAM wparam, LPARAM lparam)
00057 {
00058     if (s_pctxmenu3) {
00059         if (SUCCEEDED((*s_pctxmenu3->lpVtbl->HandleMenuMsg)(s_pctxmenu3, nmsg, wparam, lparam)))
00060             return TRUE;
00061     }
00062 
00063     if (s_pctxmenu2)
00064         if (SUCCEEDED((*s_pctxmenu2->lpVtbl->HandleMenuMsg)(s_pctxmenu2, nmsg, wparam, lparam)))
00065             return TRUE;
00066 
00067     return FALSE;
00068 }
00069 
00070 
00071 /* display context menu for the given shell folder */
00072 HRESULT ShellFolderContextMenu(IShellFolder* shell_folder, HWND hwndParent, int cidl, LPCITEMIDLIST* apidl, int x, int y)
00073 {
00074     IContextMenu* pcm;
00075     BOOL executed = FALSE;
00076 
00077     HRESULT hr = IShellFolder_GetUIObjectOf(shell_folder, hwndParent, cidl, apidl, &IID_IContextMenu, NULL, (LPVOID*)&pcm);
00078 /*  HRESULT hr = CDefFolderMenu_Create2(dir?dir->_pidl:DesktopFolder(), hwndParent, 1, &pidl, shell_folder, NULL, 0, NULL, &pcm); */
00079 
00080     if (SUCCEEDED(hr)) {
00081         HMENU hmenu = CreatePopupMenu();
00082 
00083         pcm = CtxMenu_query_interfaces(pcm);
00084 
00085         if (hmenu) {
00086             hr = (*pcm->lpVtbl->QueryContextMenu)(pcm, hmenu, 0, FCIDM_SHVIEWFIRST, FCIDM_SHVIEWLAST, CMF_NORMAL);
00087 
00088             if (SUCCEEDED(hr)) {
00089                 UINT idCmd = TrackPopupMenu(hmenu, TPM_LEFTALIGN|TPM_RETURNCMD|TPM_RIGHTBUTTON, x, y, 0, hwndParent, NULL);
00090 
00091                 CtxMenu_reset();
00092 
00093                 if (idCmd) {
00094                     CMINVOKECOMMANDINFO cmi;
00095 
00096                     cmi.cbSize = sizeof(CMINVOKECOMMANDINFO);
00097                     cmi.fMask = 0;
00098                     cmi.hwnd = hwndParent;
00099                     cmi.lpVerb = (LPCSTR)(INT_PTR)(idCmd - FCIDM_SHVIEWFIRST);
00100                     cmi.lpParameters = NULL;
00101                     cmi.lpDirectory = NULL;
00102                     cmi.nShow = SW_SHOWNORMAL;
00103                     cmi.dwHotKey = 0;
00104                     cmi.hIcon = 0;
00105 
00106                     hr = (*pcm->lpVtbl->InvokeCommand)(pcm, &cmi);
00107                     executed = TRUE;
00108                 }
00109             } else
00110                 CtxMenu_reset();
00111         }
00112 
00113         IUnknown_Release(pcm);
00114     }
00115 
00116     return FAILED(hr)? hr: executed? S_OK: S_FALSE;
00117 }
00118 
00119 #endif

Winefile Source Code Documentation
generated on 15.09.2008 by doxygen

Winefile Homepage