3 * ShellView Background Context Menu (shv_bg_cm)
5 * Copyright 1999 Juergen Schmied <juergen.schmied@metronet.de>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
27 #include "wine/debug.h"
34 #include "shell32_main.h"
35 #include "shellfolder.h"
36 #include "undocshell.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shell);
40 /**************************************************************************
41 * IContextMenu Implementation
45 IContextMenu2 IContextMenu2_iface;
46 IShellFolder* pSFParent;
52 static inline BgCmImpl *impl_from_IContextMenu2(IContextMenu2 *iface)
54 return CONTAINING_RECORD(iface, BgCmImpl, IContextMenu2_iface);
57 /**************************************************************************
58 * ISVBgCm_fnQueryInterface
60 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu2 *iface, REFIID riid, LPVOID *ppvObj)
62 BgCmImpl *This = impl_from_IContextMenu2(iface);
64 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
68 if(IsEqualIID(riid, &IID_IUnknown) ||
69 IsEqualIID(riid, &IID_IContextMenu) ||
70 IsEqualIID(riid, &IID_IContextMenu2))
74 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
76 FIXME("-- LPSHELLEXTINIT pointer requested\n");
81 IUnknown_AddRef((IUnknown*)*ppvObj);
82 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
85 TRACE("-- Interface: E_NOINTERFACE\n");
89 /**************************************************************************
92 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu2 *iface)
94 BgCmImpl *This = impl_from_IContextMenu2(iface);
95 ULONG refCount = InterlockedIncrement(&This->ref);
97 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
102 /**************************************************************************
105 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu2 *iface)
107 BgCmImpl *This = impl_from_IContextMenu2(iface);
108 ULONG refCount = InterlockedDecrement(&This->ref);
110 TRACE("(%p)->(count=%i)\n", This, refCount + 1);
114 TRACE(" destroying IContextMenu(%p)\n",This);
117 IShellFolder_Release(This->pSFParent);
119 HeapFree(GetProcessHeap(),0,This);
124 /**************************************************************************
125 * ISVBgCm_fnQueryContextMenu()
128 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
129 IContextMenu2 *iface,
136 BgCmImpl *This = impl_from_IContextMenu2(iface);
141 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
142 This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
144 This->verb_offset=idCmdFirst;
146 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
147 if (uFlags & CMF_DEFAULTONLY)
149 HMENU ourMenu = GetSubMenu(hMyMenu,0);
150 UINT oldDef = GetMenuDefaultItem(hMenu,TRUE,GMDI_USEDISABLED);
151 UINT newDef = GetMenuDefaultItem(ourMenu,TRUE,GMDI_USEDISABLED);
152 if (newDef != oldDef)
153 SetMenuDefaultItem(hMenu,newDef,TRUE);
154 if (newDef!=0xFFFFFFFF)
155 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, newDef+1);
157 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
161 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu,
162 idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
163 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst);
165 DestroyMenu(hMyMenu);
167 TRACE("(%p)->returning 0x%x\n",This,hr);
171 /**************************************************************************
174 static void DoNewFolder(
179 WCHAR wszName[MAX_PATH];
181 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
185 ISFHelper_GetUniqueName(psfhlp, wszName, MAX_PATH);
186 ISFHelper_AddFolder(psfhlp, 0, wszName, &pidl);
190 /* if we are in a shellview do labeledit */
191 IShellView_SelectItem(psv,
192 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
193 |SVSI_FOCUSED|SVSI_SELECT));
197 ISFHelper_Release(psfhlp);
201 /**************************************************************************
207 BOOL bSuccess = FALSE;
212 if(SUCCEEDED(OleGetClipboard(&pda)))
217 TRACE("pda=%p\n", pda);
219 /* Set the FORMATETC structure*/
220 InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLISTW), TYMED_HGLOBAL);
222 /* Get the pidls from IDataObject */
223 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
225 LPITEMIDLIST * apidl;
227 IShellFolder *psfFrom = NULL, *psfDesktop;
229 LPIDA lpcida = GlobalLock(medium.u.hGlobal);
230 TRACE("cida=%p\n", lpcida);
232 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
234 /* bind to the source shellfolder */
235 SHGetDesktopFolder(&psfDesktop);
238 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
239 IShellFolder_Release(psfDesktop);
244 /* get source and destination shellfolder */
245 ISFHelper *psfhlpdst, *psfhlpsrc;
246 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
247 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
249 /* do the copy/move */
250 if (psfhlpdst && psfhlpsrc)
252 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, (LPCITEMIDLIST*)apidl);
254 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
257 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
258 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
259 IShellFolder_Release(psfFrom);
262 _ILFreeaPidl(apidl, lpcida->cidl);
265 /* release the medium*/
266 ReleaseStgMedium(&medium);
268 IDataObject_Release(pda);
274 hMem = GetClipboardData(CF_HDROP);
278 char * pDropFiles = GlobalLock(hMem);
281 int len, offset = sizeof(DROPFILESTRUCT);
283 while( pDropFiles[offset] != 0)
285 len = strlen(pDropFiles + offset);
286 TRACE("%s\n", pDropFiles + offset);
297 /**************************************************************************
298 * ISVBgCm_fnInvokeCommand()
300 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
301 IContextMenu2 *iface,
302 LPCMINVOKECOMMANDINFO lpcmi)
304 BgCmImpl *This = impl_from_IContextMenu2(iface);
306 LPSHELLVIEW lpSV = NULL;
309 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
311 /* get the active IShellView */
312 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
314 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
316 IShellView_GetWindow(lpSV, &hWndSV);
320 if(HIWORD(lpcmi->lpVerb))
322 TRACE("%s\n",lpcmi->lpVerb);
324 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
326 DoNewFolder(This, lpSV);
328 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
330 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
332 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
334 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
338 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
343 switch(LOWORD(lpcmi->lpVerb)-This->verb_offset)
345 case FCIDM_SHVIEW_REFRESH:
346 if (lpSV) IShellView_Refresh(lpSV);
349 case FCIDM_SHVIEW_NEWFOLDER:
350 DoNewFolder(This, lpSV);
353 case FCIDM_SHVIEW_INSERT:
357 case FCIDM_SHVIEW_PROPERTIES:
358 if (This->bDesktop) {
359 ShellExecuteA(lpcmi->hwnd, "open", "rundll32.exe shell32.dll,Control_RunDLL desk.cpl", NULL, NULL, SW_SHOWNORMAL);
361 FIXME("launch item properties dialog\n");
366 /* if it's an id just pass it to the parent shv */
367 if (hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
373 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef */
378 /**************************************************************************
379 * ISVBgCm_fnGetCommandString()
382 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
383 IContextMenu2 *iface,
390 BgCmImpl *This = impl_from_IContextMenu2(iface);
392 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
394 /* test the existence of the menu items, the file dialog enables
395 the buttons according to this */
396 if (uFlags == GCS_VALIDATEA)
398 if(HIWORD(idCommand))
400 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
401 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
402 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
409 FIXME("unknown command string\n");
413 /**************************************************************************
414 * ISVBgCm_fnHandleMenuMsg()
416 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
417 IContextMenu2 *iface,
422 BgCmImpl *This = impl_from_IContextMenu2(iface);
424 FIXME("(%p)->(msg=%x wp=%lx lp=%lx)\n",This, uMsg, wParam, lParam);
429 /**************************************************************************
430 * IContextMenu2 VTable
433 static const IContextMenu2Vtbl cmvt =
435 ISVBgCm_fnQueryInterface,
438 ISVBgCm_fnQueryContextMenu,
439 ISVBgCm_fnInvokeCommand,
440 ISVBgCm_fnGetCommandString,
441 ISVBgCm_fnHandleMenuMsg
444 IContextMenu2 *ISvBgCm_Constructor(IShellFolder *pSFParent, BOOL bDesktop)
448 cm = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*cm));
449 cm->IContextMenu2_iface.lpVtbl = &cmvt;
451 cm->pSFParent = pSFParent;
452 cm->bDesktop = bDesktop;
453 if(pSFParent) IShellFolder_AddRef(pSFParent);
455 TRACE("(%p)->()\n", cm);
456 return &cm->IContextMenu2_iface;