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);
64 return (IContextMenu*)cm;
67 /**************************************************************************
68 * ISVBgCm_fnQueryInterface
70 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
72 ICOM_THIS(BgCmImpl, iface);
74 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
78 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
82 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
86 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
88 FIXME("-- LPSHELLEXTINIT pointer requested\n");
93 IUnknown_AddRef((IUnknown*)*ppvObj);
94 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
97 TRACE("-- Interface: E_NOINTERFACE\n");
101 /**************************************************************************
104 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
106 ICOM_THIS(BgCmImpl, iface);
108 TRACE("(%p)->(count=%lu)\n",This, This->ref);
110 return ++(This->ref);
113 /**************************************************************************
116 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
118 ICOM_THIS(BgCmImpl, iface);
120 TRACE("(%p)->()\n",This);
124 TRACE(" destroying IContextMenu(%p)\n",This);
127 IShellFolder_Release(This->pSFParent);
129 HeapFree(GetProcessHeap(),0,This);
136 /**************************************************************************
137 * ISVBgCm_fnQueryContextMenu()
140 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
152 ICOM_THIS(BgCmImpl, iface);
154 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
155 This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
158 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
159 if (uFlags & CMF_DEFAULTONLY)
161 HMENU ourMenu = GetSubMenu(hMyMenu,0);
162 UINT oldDef = GetMenuDefaultItem(hMenu,TRUE,GMDI_USEDISABLED);
163 UINT newDef = GetMenuDefaultItem(ourMenu,TRUE,GMDI_USEDISABLED);
164 if (newDef != oldDef)
165 SetMenuDefaultItem(hMenu,newDef,TRUE);
166 if (newDef!=0xFFFFFFFF)
167 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, newDef+1);
169 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
173 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu,
174 idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
175 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst+1);
177 DestroyMenu(hMyMenu);
179 TRACE("(%p)->returning 0x%lx\n",This,hr);
183 /**************************************************************************
186 static void DoNewFolder(
190 ICOM_THIS(BgCmImpl, iface);
192 char szName[MAX_PATH];
194 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
198 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
199 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
203 /* if we are in a shellview do labeledit */
204 IShellView_SelectItem(psv,
205 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
206 |SVSI_FOCUSED|SVSI_SELECT));
210 ISFHelper_Release(psfhlp);
214 /**************************************************************************
220 ICOM_THIS(BgCmImpl, iface);
221 BOOL bSuccess = FALSE;
226 if(SUCCEEDED(pOleGetClipboard(&pda)))
231 TRACE("pda=%p\n", pda);
233 /* Set the FORMATETC structure*/
234 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
236 /* Get the pidls from IDataObject */
237 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
239 LPITEMIDLIST * apidl;
241 IShellFolder *psfFrom = NULL, *psfDesktop;
243 LPCIDA lpcida = GlobalLock(medium.u.hGlobal);
244 TRACE("cida=%p\n", lpcida);
246 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
248 /* bind to the source shellfolder */
249 SHGetDesktopFolder(&psfDesktop);
252 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
253 IShellFolder_Release(psfDesktop);
258 /* get source and destination shellfolder */
259 ISFHelper *psfhlpdst, *psfhlpsrc;
260 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
261 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
263 /* do the copy/move */
264 if (psfhlpdst && psfhlpsrc)
266 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, apidl);
268 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
271 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
272 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
273 IShellFolder_Release(psfFrom);
276 _ILFreeaPidl(apidl, lpcida->cidl);
279 /* release the medium*/
280 pReleaseStgMedium(&medium);
282 IDataObject_Release(pda);
288 hMem = GetClipboardData(CF_HDROP);
292 char * pDropFiles = (char *)GlobalLock(hMem);
295 int len, offset = sizeof(DROPFILESTRUCT);
297 while( pDropFiles[offset] != 0)
299 len = strlen(pDropFiles + offset);
300 TRACE("%s\n", pDropFiles + offset);
310 /**************************************************************************
311 * ISVBgCm_fnInvokeCommand()
313 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
315 LPCMINVOKECOMMANDINFO lpcmi)
317 ICOM_THIS(BgCmImpl, iface);
323 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
325 /* get the active IShellView */
326 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
328 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
330 IShellView_GetWindow(lpSV, &hWndSV);
336 if(HIWORD(lpcmi->lpVerb))
338 TRACE("%s\n",lpcmi->lpVerb);
340 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
342 if(lpSV) DoNewFolder(iface, lpSV);
344 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
346 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
348 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
350 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
354 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
359 switch(LOWORD(lpcmi->lpVerb))
361 case FCIDM_SHVIEW_NEWFOLDER:
362 DoNewFolder(iface, lpSV);
364 case FCIDM_SHVIEW_INSERT:
368 /* if it's a id just pass it to the parent shv */
369 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
374 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
379 /**************************************************************************
380 * ISVBgCm_fnGetCommandString()
383 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
391 ICOM_THIS(BgCmImpl, iface);
393 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
395 /* test the existence of the menu items, the file dialog enables
396 the buttons according to this */
397 if (uFlags == GCS_VALIDATEA)
399 if(HIWORD(idCommand))
401 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
402 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
403 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
410 FIXME("unknown command string\n");
414 /**************************************************************************
415 * ISVBgCm_fnHandleMenuMsg()
417 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
423 ICOM_THIS(BgCmImpl, iface);
425 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
430 /**************************************************************************
431 * IContextMenu VTable
434 static struct ICOM_VTABLE(IContextMenu) cmvt =
436 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
437 ISVBgCm_fnQueryInterface,
440 ISVBgCm_fnQueryContextMenu,
441 ISVBgCm_fnInvokeCommand,
442 ISVBgCm_fnGetCommandString,
443 ISVBgCm_fnHandleMenuMsg,
444 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */