3 * ShellView Background Context Menu (shv_bg_cm)
5 * Copyright 1999 Juergen Schmied <juergen.schmied@metronet.de>
9 #include "debugtools.h"
13 #include "wine/obj_base.h"
14 #include "wine/obj_contextmenu.h"
15 #include "wine/obj_shellbrowser.h"
17 #include "shell32_main.h"
18 #include "shellfolder.h"
19 #include "wine/undocshell.h"
21 DEFAULT_DEBUG_CHANNEL(shell);
23 /**************************************************************************
24 * IContextMenu Implementation
28 ICOM_VFIELD(IContextMenu);
29 IShellFolder* pSFParent;
34 static struct ICOM_VTABLE(IContextMenu) cmvt;
36 /**************************************************************************
37 * ISVBgCm_Constructor()
39 IContextMenu *ISvBgCm_Constructor(IShellFolder* pSFParent)
43 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
46 cm->pSFParent = pSFParent;
47 if(pSFParent) IShellFolder_AddRef(pSFParent);
49 TRACE("(%p)->()\n",cm);
51 return (IContextMenu*)cm;
54 /**************************************************************************
55 * ISVBgCm_fnQueryInterface
57 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
59 ICOM_THIS(BgCmImpl, iface);
61 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
65 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
69 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
73 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
75 FIXME("-- LPSHELLEXTINIT pointer requested\n");
80 IUnknown_AddRef((IUnknown*)*ppvObj);
81 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
84 TRACE("-- Interface: E_NOINTERFACE\n");
88 /**************************************************************************
91 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
93 ICOM_THIS(BgCmImpl, iface);
95 TRACE("(%p)->(count=%lu)\n",This, This->ref);
101 /**************************************************************************
104 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
106 ICOM_THIS(BgCmImpl, iface);
108 TRACE("(%p)->()\n",This);
112 TRACE(" destroying IContextMenu(%p)\n",This);
115 IShellFolder_Release(This->pSFParent);
117 HeapFree(GetProcessHeap(),0,This);
126 /**************************************************************************
127 * ISVBgCm_fnQueryContextMenu()
130 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
141 ICOM_THIS(BgCmImpl, iface);
143 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
145 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
147 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
149 DestroyMenu(hMyMenu);
151 return ResultFromShort(idMax - idCmdFirst);
154 /**************************************************************************
157 static void DoNewFolder(
161 ICOM_THIS(BgCmImpl, iface);
163 char szName[MAX_PATH];
165 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
169 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
170 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
174 /* if we are in a shellview do labeledit */
175 IShellView_SelectItem(psv,
176 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
177 |SVSI_FOCUSED|SVSI_SELECT));
181 ISFHelper_Release(psfhlp);
185 /**************************************************************************
191 ICOM_THIS(BgCmImpl, iface);
192 BOOL bSuccess = FALSE;
197 if(SUCCEEDED(pOleGetClipboard(&pda)))
202 TRACE("pda=%p\n", pda);
204 /* Set the FORMATETC structure*/
205 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
207 /* Get the pidls from IDataObject */
208 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
210 LPITEMIDLIST * apidl;
212 IShellFolder *psfFrom = NULL, *psfDesktop;
214 LPCIDA lpcida = GlobalLock(medium.u.hGlobal);
215 TRACE("cida=%p\n", lpcida);
217 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
219 /* bind to the source shellfolder */
220 SHGetDesktopFolder(&psfDesktop);
223 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
224 IShellFolder_Release(psfDesktop);
229 /* get source and destination shellfolder */
230 ISFHelper *psfhlpdst, *psfhlpsrc;
231 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
232 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
234 /* do the copy/move */
235 if (psfhlpdst && psfhlpsrc)
237 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, apidl);
239 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
242 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
243 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
244 IShellFolder_Release(psfFrom);
247 _ILFreeaPidl(apidl, lpcida->cidl);
250 /* release the medium*/
251 pReleaseStgMedium(&medium);
253 IDataObject_Release(pda);
259 hMem = GetClipboardData(CF_HDROP);
263 char * pDropFiles = (char *)GlobalLock(hMem);
266 int len, offset = sizeof(DROPFILESTRUCT);
268 while( pDropFiles[offset] != 0)
270 len = strlen(pDropFiles + offset);
271 TRACE("%s\n", pDropFiles + offset);
281 /**************************************************************************
282 * ISVBgCm_fnInvokeCommand()
284 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
286 LPCMINVOKECOMMANDINFO lpcmi)
288 ICOM_THIS(BgCmImpl, iface);
294 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
296 /* get the active IShellView */
297 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
299 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
301 IShellView_GetWindow(lpSV, &hWndSV);
307 if(HIWORD(lpcmi->lpVerb))
309 TRACE("%s\n",lpcmi->lpVerb);
311 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
313 if(lpSV) DoNewFolder(iface, lpSV);
315 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
317 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
319 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
321 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
325 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
330 switch(LOWORD(lpcmi->lpVerb))
332 case FCIDM_SHVIEW_NEWFOLDER:
333 DoNewFolder(iface, lpSV);
335 case FCIDM_SHVIEW_INSERT:
339 /* if it's a id just pass it to the parent shv */
340 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
345 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
350 /**************************************************************************
351 * ISVBgCm_fnGetCommandString()
354 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
362 ICOM_THIS(BgCmImpl, iface);
364 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
366 /* test the existence of the menu items, the file dialog enables
367 the buttons according to this */
368 if (uFlags == GCS_VALIDATEA)
370 if(HIWORD(idCommand))
372 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
373 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
374 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
381 FIXME("unknown command string\n");
385 /**************************************************************************
386 * ISVBgCm_fnHandleMenuMsg()
388 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
394 ICOM_THIS(BgCmImpl, iface);
396 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
401 /**************************************************************************
402 * IContextMenu VTable
405 static struct ICOM_VTABLE(IContextMenu) cmvt =
407 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
408 ISVBgCm_fnQueryInterface,
411 ISVBgCm_fnQueryContextMenu,
412 ISVBgCm_fnInvokeCommand,
413 ISVBgCm_fnGetCommandString,
414 ISVBgCm_fnHandleMenuMsg,
415 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */