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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/debug.h"
27 #include "wine/obj_base.h"
28 #include "wine/obj_contextmenu.h"
29 #include "wine/obj_shellbrowser.h"
31 #include "shell32_main.h"
32 #include "shellfolder.h"
33 #include "undocshell.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(shell);
37 /**************************************************************************
38 * IContextMenu Implementation
42 ICOM_VFIELD(IContextMenu);
43 IShellFolder* pSFParent;
48 static struct ICOM_VTABLE(IContextMenu) cmvt;
50 /**************************************************************************
51 * ISVBgCm_Constructor()
53 IContextMenu *ISvBgCm_Constructor(IShellFolder* pSFParent)
57 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
60 cm->pSFParent = pSFParent;
61 if(pSFParent) IShellFolder_AddRef(pSFParent);
63 TRACE("(%p)->()\n",cm);
65 return (IContextMenu*)cm;
68 /**************************************************************************
69 * ISVBgCm_fnQueryInterface
71 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
73 ICOM_THIS(BgCmImpl, iface);
75 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
79 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
83 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
87 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
89 FIXME("-- LPSHELLEXTINIT pointer requested\n");
94 IUnknown_AddRef((IUnknown*)*ppvObj);
95 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
98 TRACE("-- Interface: E_NOINTERFACE\n");
102 /**************************************************************************
105 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
107 ICOM_THIS(BgCmImpl, iface);
109 TRACE("(%p)->(count=%lu)\n",This, This->ref);
112 return ++(This->ref);
115 /**************************************************************************
118 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
120 ICOM_THIS(BgCmImpl, iface);
122 TRACE("(%p)->()\n",This);
126 TRACE(" destroying IContextMenu(%p)\n",This);
129 IShellFolder_Release(This->pSFParent);
131 HeapFree(GetProcessHeap(),0,This);
140 /**************************************************************************
141 * ISVBgCm_fnQueryContextMenu()
144 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
155 ICOM_THIS(BgCmImpl, iface);
157 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
159 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
161 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
163 DestroyMenu(hMyMenu);
165 return ResultFromShort(idMax - idCmdFirst);
168 /**************************************************************************
171 static void DoNewFolder(
175 ICOM_THIS(BgCmImpl, iface);
177 char szName[MAX_PATH];
179 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
183 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
184 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
188 /* if we are in a shellview do labeledit */
189 IShellView_SelectItem(psv,
190 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
191 |SVSI_FOCUSED|SVSI_SELECT));
195 ISFHelper_Release(psfhlp);
199 /**************************************************************************
205 ICOM_THIS(BgCmImpl, iface);
206 BOOL bSuccess = FALSE;
211 if(SUCCEEDED(pOleGetClipboard(&pda)))
216 TRACE("pda=%p\n", pda);
218 /* Set the FORMATETC structure*/
219 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
221 /* Get the pidls from IDataObject */
222 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
224 LPITEMIDLIST * apidl;
226 IShellFolder *psfFrom = NULL, *psfDesktop;
228 LPCIDA lpcida = GlobalLock(medium.u.hGlobal);
229 TRACE("cida=%p\n", lpcida);
231 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
233 /* bind to the source shellfolder */
234 SHGetDesktopFolder(&psfDesktop);
237 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
238 IShellFolder_Release(psfDesktop);
243 /* get source and destination shellfolder */
244 ISFHelper *psfhlpdst, *psfhlpsrc;
245 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
246 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
248 /* do the copy/move */
249 if (psfhlpdst && psfhlpsrc)
251 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, apidl);
253 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
256 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
257 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
258 IShellFolder_Release(psfFrom);
261 _ILFreeaPidl(apidl, lpcida->cidl);
264 /* release the medium*/
265 pReleaseStgMedium(&medium);
267 IDataObject_Release(pda);
273 hMem = GetClipboardData(CF_HDROP);
277 char * pDropFiles = (char *)GlobalLock(hMem);
280 int len, offset = sizeof(DROPFILESTRUCT);
282 while( pDropFiles[offset] != 0)
284 len = strlen(pDropFiles + offset);
285 TRACE("%s\n", pDropFiles + offset);
295 /**************************************************************************
296 * ISVBgCm_fnInvokeCommand()
298 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
300 LPCMINVOKECOMMANDINFO lpcmi)
302 ICOM_THIS(BgCmImpl, iface);
308 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
310 /* get the active IShellView */
311 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
313 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
315 IShellView_GetWindow(lpSV, &hWndSV);
321 if(HIWORD(lpcmi->lpVerb))
323 TRACE("%s\n",lpcmi->lpVerb);
325 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
327 if(lpSV) DoNewFolder(iface, lpSV);
329 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
331 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
333 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
335 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
339 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
344 switch(LOWORD(lpcmi->lpVerb))
346 case FCIDM_SHVIEW_NEWFOLDER:
347 DoNewFolder(iface, lpSV);
349 case FCIDM_SHVIEW_INSERT:
353 /* if it's a id just pass it to the parent shv */
354 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
359 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
364 /**************************************************************************
365 * ISVBgCm_fnGetCommandString()
368 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
376 ICOM_THIS(BgCmImpl, iface);
378 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
380 /* test the existence of the menu items, the file dialog enables
381 the buttons according to this */
382 if (uFlags == GCS_VALIDATEA)
384 if(HIWORD(idCommand))
386 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
387 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
388 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
395 FIXME("unknown command string\n");
399 /**************************************************************************
400 * ISVBgCm_fnHandleMenuMsg()
402 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
408 ICOM_THIS(BgCmImpl, iface);
410 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
415 /**************************************************************************
416 * IContextMenu VTable
419 static struct ICOM_VTABLE(IContextMenu) cmvt =
421 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
422 ISVBgCm_fnQueryInterface,
425 ISVBgCm_fnQueryContextMenu,
426 ISVBgCm_fnInvokeCommand,
427 ISVBgCm_fnGetCommandString,
428 ISVBgCm_fnHandleMenuMsg,
429 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */