3 * ShellView Background Context Menu (shv_bg_cm)
5 * Copyright 1999 Juergen Schmied <juergen.schmied@metronet.de>
9 #include "debugtools.h"
12 #include "wine/obj_base.h"
13 #include "wine/obj_contextmenu.h"
14 #include "wine/obj_shellbrowser.h"
16 #include "shell32_main.h"
17 #include "shellfolder.h"
18 #include "shell.h" /* DROPFILESTRUCT */
20 DEFAULT_DEBUG_CHANNEL(shell)
22 /**************************************************************************
23 * IContextMenu Implementation
27 ICOM_VFIELD(IContextMenu);
28 IShellFolder* pSFParent;
33 static struct ICOM_VTABLE(IContextMenu) cmvt;
35 /**************************************************************************
36 * ISVBgCm_Constructor()
38 IContextMenu *ISvBgCm_Constructor(IShellFolder* pSFParent)
42 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
45 cm->pSFParent = pSFParent;
46 if(pSFParent) IShellFolder_AddRef(pSFParent);
48 TRACE("(%p)->()\n",cm);
50 return (IContextMenu*)cm;
53 /**************************************************************************
54 * ISVBgCm_fnQueryInterface
56 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
58 ICOM_THIS(BgCmImpl, iface);
60 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
64 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
68 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
72 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
74 FIXME("-- LPSHELLEXTINIT pointer requested\n");
79 IUnknown_AddRef((IUnknown*)*ppvObj);
80 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
83 TRACE("-- Interface: E_NOINTERFACE\n");
87 /**************************************************************************
90 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
92 ICOM_THIS(BgCmImpl, iface);
94 TRACE("(%p)->(count=%lu)\n",This, This->ref);
100 /**************************************************************************
103 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
105 ICOM_THIS(BgCmImpl, iface);
107 TRACE("(%p)->()\n",This);
111 TRACE(" destroying IContextMenu(%p)\n",This);
114 IShellFolder_Release(This->pSFParent);
116 HeapFree(GetProcessHeap(),0,This);
125 /**************************************************************************
126 * ISVBgCm_fnQueryContextMenu()
129 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
140 ICOM_THIS(BgCmImpl, iface);
142 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
144 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
146 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
148 DestroyMenu(hMyMenu);
150 return ResultFromShort(idMax - idCmdFirst);
153 /**************************************************************************
156 static void DoNewFolder(
160 ICOM_THIS(BgCmImpl, iface);
162 char szName[MAX_PATH];
164 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
168 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
169 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
173 /* if we are in a shellview do labeledit */
174 IShellView_SelectItem(psv,
175 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
176 |SVSI_FOCUSED|SVSI_SELECT));
180 ISFHelper_Release(psfhlp);
184 /**************************************************************************
190 ICOM_THIS(BgCmImpl, iface);
191 BOOL bSuccess = FALSE;
196 if(SUCCEEDED(pOleGetClipboard(&pda)));
201 TRACE("pda=%p\n", pda);
203 /* Set the FORMATETC structure*/
204 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
206 /* Get the pidls from IDataObject */
207 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
209 LPITEMIDLIST * apidl;
211 IShellFolder *psfFrom = NULL, *psfDesktop;
213 LPCIDA lpcida = GlobalLock(medium.u.hGlobal);
214 TRACE("cida=%p\n", lpcida);
216 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
218 /* bind to the source shellfolder */
219 SHGetDesktopFolder(&psfDesktop);
222 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
223 IShellFolder_Release(psfDesktop);
228 /* get source and destination shellfolder */
229 ISFHelper *psfhlpdst, *psfhlpsrc;
230 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
231 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
233 /* do the copy/move */
234 if (psfhlpdst && psfhlpsrc)
236 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, apidl);
238 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
241 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
242 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
243 IShellFolder_Release(psfFrom);
246 _ILFreeaPidl(apidl, lpcida->cidl);
249 /* release the medium*/
250 pReleaseStgMedium(&medium);
252 IDataObject_Release(pda);
258 hMem = GetClipboardData(CF_HDROP);
262 char * pDropFiles = (char *)GlobalLock(hMem);
265 int len, offset = sizeof(DROPFILESTRUCT);
267 while( pDropFiles[offset] != 0)
269 len = strlen(pDropFiles + offset);
270 TRACE("%s\n", pDropFiles + offset);
280 /**************************************************************************
281 * ISVBgCm_fnInvokeCommand()
283 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
285 LPCMINVOKECOMMANDINFO lpcmi)
287 ICOM_THIS(BgCmImpl, iface);
293 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
295 /* get the active IShellView */
296 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
298 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
300 IShellView_GetWindow(lpSV, &hWndSV);
306 if(HIWORD(lpcmi->lpVerb))
308 TRACE("%s\n",lpcmi->lpVerb);
310 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
312 if(lpSV) DoNewFolder(iface, lpSV);
314 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
316 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
318 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
320 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
324 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
329 switch(LOWORD(lpcmi->lpVerb))
331 case FCIDM_SHVIEW_NEWFOLDER:
332 DoNewFolder(iface, lpSV);
334 case FCIDM_SHVIEW_INSERT:
338 /* if it's a id just pass it to the parent shv */
339 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
344 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
349 /**************************************************************************
350 * ISVBgCm_fnGetCommandString()
353 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
361 ICOM_THIS(BgCmImpl, iface);
363 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
365 /* test the existance of the menu items, the file dialog enables
366 the buttons according to this */
367 if (uFlags == GCS_VALIDATEA)
369 if(HIWORD(idCommand))
371 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
372 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
373 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
380 FIXME("unknown command string\n");
384 /**************************************************************************
385 * ISVBgCm_fnHandleMenuMsg()
387 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
393 ICOM_THIS(BgCmImpl, iface);
395 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
400 /**************************************************************************
401 * IContextMenu VTable
404 static struct ICOM_VTABLE(IContextMenu) cmvt =
406 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
407 ISVBgCm_fnQueryInterface,
410 ISVBgCm_fnQueryContextMenu,
411 ISVBgCm_fnInvokeCommand,
412 ISVBgCm_fnGetCommandString,
413 ISVBgCm_fnHandleMenuMsg,
414 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */