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 "shell.h" /* DROPFILESTRUCT */
20 #include "wine/undocshell.h"
22 DEFAULT_DEBUG_CHANNEL(shell)
24 /**************************************************************************
25 * IContextMenu Implementation
29 ICOM_VFIELD(IContextMenu);
30 IShellFolder* pSFParent;
35 static struct ICOM_VTABLE(IContextMenu) cmvt;
37 /**************************************************************************
38 * ISVBgCm_Constructor()
40 IContextMenu *ISvBgCm_Constructor(IShellFolder* pSFParent)
44 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
47 cm->pSFParent = pSFParent;
48 if(pSFParent) IShellFolder_AddRef(pSFParent);
50 TRACE("(%p)->()\n",cm);
52 return (IContextMenu*)cm;
55 /**************************************************************************
56 * ISVBgCm_fnQueryInterface
58 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
60 ICOM_THIS(BgCmImpl, iface);
62 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
66 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
70 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
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(IContextMenu *iface)
94 ICOM_THIS(BgCmImpl, iface);
96 TRACE("(%p)->(count=%lu)\n",This, This->ref);
102 /**************************************************************************
105 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
107 ICOM_THIS(BgCmImpl, iface);
109 TRACE("(%p)->()\n",This);
113 TRACE(" destroying IContextMenu(%p)\n",This);
116 IShellFolder_Release(This->pSFParent);
118 HeapFree(GetProcessHeap(),0,This);
127 /**************************************************************************
128 * ISVBgCm_fnQueryContextMenu()
131 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
142 ICOM_THIS(BgCmImpl, iface);
144 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
146 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
148 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
150 DestroyMenu(hMyMenu);
152 return ResultFromShort(idMax - idCmdFirst);
155 /**************************************************************************
158 static void DoNewFolder(
162 ICOM_THIS(BgCmImpl, iface);
164 char szName[MAX_PATH];
166 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
170 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
171 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
175 /* if we are in a shellview do labeledit */
176 IShellView_SelectItem(psv,
177 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
178 |SVSI_FOCUSED|SVSI_SELECT));
182 ISFHelper_Release(psfhlp);
186 /**************************************************************************
192 ICOM_THIS(BgCmImpl, iface);
193 BOOL bSuccess = FALSE;
198 if(SUCCEEDED(pOleGetClipboard(&pda)));
203 TRACE("pda=%p\n", pda);
205 /* Set the FORMATETC structure*/
206 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
208 /* Get the pidls from IDataObject */
209 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
211 LPITEMIDLIST * apidl;
213 IShellFolder *psfFrom = NULL, *psfDesktop;
215 LPCIDA lpcida = GlobalLock(medium.u.hGlobal);
216 TRACE("cida=%p\n", lpcida);
218 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
220 /* bind to the source shellfolder */
221 SHGetDesktopFolder(&psfDesktop);
224 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
225 IShellFolder_Release(psfDesktop);
230 /* get source and destination shellfolder */
231 ISFHelper *psfhlpdst, *psfhlpsrc;
232 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
233 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
235 /* do the copy/move */
236 if (psfhlpdst && psfhlpsrc)
238 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, apidl);
240 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
243 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
244 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
245 IShellFolder_Release(psfFrom);
248 _ILFreeaPidl(apidl, lpcida->cidl);
251 /* release the medium*/
252 pReleaseStgMedium(&medium);
254 IDataObject_Release(pda);
260 hMem = GetClipboardData(CF_HDROP);
264 char * pDropFiles = (char *)GlobalLock(hMem);
267 int len, offset = sizeof(DROPFILESTRUCT);
269 while( pDropFiles[offset] != 0)
271 len = strlen(pDropFiles + offset);
272 TRACE("%s\n", pDropFiles + offset);
282 /**************************************************************************
283 * ISVBgCm_fnInvokeCommand()
285 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
287 LPCMINVOKECOMMANDINFO lpcmi)
289 ICOM_THIS(BgCmImpl, iface);
295 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
297 /* get the active IShellView */
298 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
300 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
302 IShellView_GetWindow(lpSV, &hWndSV);
308 if(HIWORD(lpcmi->lpVerb))
310 TRACE("%s\n",lpcmi->lpVerb);
312 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
314 if(lpSV) DoNewFolder(iface, lpSV);
316 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
318 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
320 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
322 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
326 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
331 switch(LOWORD(lpcmi->lpVerb))
333 case FCIDM_SHVIEW_NEWFOLDER:
334 DoNewFolder(iface, lpSV);
336 case FCIDM_SHVIEW_INSERT:
340 /* if it's a id just pass it to the parent shv */
341 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
346 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
351 /**************************************************************************
352 * ISVBgCm_fnGetCommandString()
355 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
363 ICOM_THIS(BgCmImpl, iface);
365 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
367 /* test the existance of the menu items, the file dialog enables
368 the buttons according to this */
369 if (uFlags == GCS_VALIDATEA)
371 if(HIWORD(idCommand))
373 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
374 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
375 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
382 FIXME("unknown command string\n");
386 /**************************************************************************
387 * ISVBgCm_fnHandleMenuMsg()
389 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
395 ICOM_THIS(BgCmImpl, iface);
397 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
402 /**************************************************************************
403 * IContextMenu VTable
406 static struct ICOM_VTABLE(IContextMenu) cmvt =
408 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
409 ISVBgCm_fnQueryInterface,
412 ISVBgCm_fnQueryContextMenu,
413 ISVBgCm_fnInvokeCommand,
414 ISVBgCm_fnGetCommandString,
415 ISVBgCm_fnHandleMenuMsg,
416 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */