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"
29 #include "shell32_main.h"
30 #include "shellfolder.h"
31 #include "undocshell.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(shell);
35 /**************************************************************************
36 * IContextMenu Implementation
40 ICOM_VFIELD(IContextMenu);
41 IShellFolder* pSFParent;
46 static struct ICOM_VTABLE(IContextMenu) cmvt;
48 /**************************************************************************
49 * ISVBgCm_Constructor()
51 IContextMenu *ISvBgCm_Constructor(IShellFolder* pSFParent)
55 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
58 cm->pSFParent = pSFParent;
59 if(pSFParent) IShellFolder_AddRef(pSFParent);
61 TRACE("(%p)->()\n",cm);
62 return (IContextMenu*)cm;
65 /**************************************************************************
66 * ISVBgCm_fnQueryInterface
68 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
70 ICOM_THIS(BgCmImpl, iface);
72 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
76 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
80 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
84 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
86 FIXME("-- LPSHELLEXTINIT pointer requested\n");
91 IUnknown_AddRef((IUnknown*)*ppvObj);
92 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
95 TRACE("-- Interface: E_NOINTERFACE\n");
99 /**************************************************************************
102 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
104 ICOM_THIS(BgCmImpl, iface);
106 TRACE("(%p)->(count=%lu)\n",This, This->ref);
108 return ++(This->ref);
111 /**************************************************************************
114 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
116 ICOM_THIS(BgCmImpl, iface);
118 TRACE("(%p)->()\n",This);
122 TRACE(" destroying IContextMenu(%p)\n",This);
125 IShellFolder_Release(This->pSFParent);
127 HeapFree(GetProcessHeap(),0,This);
134 /**************************************************************************
135 * ISVBgCm_fnQueryContextMenu()
138 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
150 ICOM_THIS(BgCmImpl, iface);
152 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
153 This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
156 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
157 if (uFlags & CMF_DEFAULTONLY)
159 HMENU ourMenu = GetSubMenu(hMyMenu,0);
160 UINT oldDef = GetMenuDefaultItem(hMenu,TRUE,GMDI_USEDISABLED);
161 UINT newDef = GetMenuDefaultItem(ourMenu,TRUE,GMDI_USEDISABLED);
162 if (newDef != oldDef)
163 SetMenuDefaultItem(hMenu,newDef,TRUE);
164 if (newDef!=0xFFFFFFFF)
165 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, newDef+1);
167 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
171 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu,
172 idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
173 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst+1);
175 DestroyMenu(hMyMenu);
177 TRACE("(%p)->returning 0x%lx\n",This,hr);
181 /**************************************************************************
184 static void DoNewFolder(
188 ICOM_THIS(BgCmImpl, iface);
190 char szName[MAX_PATH];
192 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
196 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
197 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
201 /* if we are in a shellview do labeledit */
202 IShellView_SelectItem(psv,
203 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
204 |SVSI_FOCUSED|SVSI_SELECT));
208 ISFHelper_Release(psfhlp);
212 /**************************************************************************
218 ICOM_THIS(BgCmImpl, iface);
219 BOOL bSuccess = FALSE;
224 if(SUCCEEDED(pOleGetClipboard(&pda)))
229 TRACE("pda=%p\n", pda);
231 /* Set the FORMATETC structure*/
232 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
234 /* Get the pidls from IDataObject */
235 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
237 LPITEMIDLIST * apidl;
239 IShellFolder *psfFrom = NULL, *psfDesktop;
241 LPIDA lpcida = GlobalLock(medium.u.hGlobal);
242 TRACE("cida=%p\n", lpcida);
244 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
246 /* bind to the source shellfolder */
247 SHGetDesktopFolder(&psfDesktop);
250 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
251 IShellFolder_Release(psfDesktop);
256 /* get source and destination shellfolder */
257 ISFHelper *psfhlpdst, *psfhlpsrc;
258 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
259 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
261 /* do the copy/move */
262 if (psfhlpdst && psfhlpsrc)
264 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, apidl);
266 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
269 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
270 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
271 IShellFolder_Release(psfFrom);
274 _ILFreeaPidl(apidl, lpcida->cidl);
277 /* release the medium*/
278 pReleaseStgMedium(&medium);
280 IDataObject_Release(pda);
286 hMem = GetClipboardData(CF_HDROP);
290 char * pDropFiles = (char *)GlobalLock(hMem);
293 int len, offset = sizeof(DROPFILESTRUCT);
295 while( pDropFiles[offset] != 0)
297 len = strlen(pDropFiles + offset);
298 TRACE("%s\n", pDropFiles + offset);
308 /**************************************************************************
309 * ISVBgCm_fnInvokeCommand()
311 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
313 LPCMINVOKECOMMANDINFO lpcmi)
315 ICOM_THIS(BgCmImpl, iface);
321 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
323 /* get the active IShellView */
324 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
326 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
328 IShellView_GetWindow(lpSV, &hWndSV);
334 if(HIWORD(lpcmi->lpVerb))
336 TRACE("%s\n",lpcmi->lpVerb);
338 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
340 if(lpSV) DoNewFolder(iface, lpSV);
342 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
344 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
346 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
348 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
352 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
357 switch(LOWORD(lpcmi->lpVerb))
359 case FCIDM_SHVIEW_NEWFOLDER:
360 DoNewFolder(iface, lpSV);
362 case FCIDM_SHVIEW_INSERT:
366 /* if it's a id just pass it to the parent shv */
367 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
372 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
377 /**************************************************************************
378 * ISVBgCm_fnGetCommandString()
381 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
389 ICOM_THIS(BgCmImpl, iface);
391 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
393 /* test the existence of the menu items, the file dialog enables
394 the buttons according to this */
395 if (uFlags == GCS_VALIDATEA)
397 if(HIWORD(idCommand))
399 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
400 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
401 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
408 FIXME("unknown command string\n");
412 /**************************************************************************
413 * ISVBgCm_fnHandleMenuMsg()
415 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
421 ICOM_THIS(BgCmImpl, iface);
423 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
428 /**************************************************************************
429 * IContextMenu VTable
432 static struct ICOM_VTABLE(IContextMenu) cmvt =
434 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
435 ISVBgCm_fnQueryInterface,
438 ISVBgCm_fnQueryContextMenu,
439 ISVBgCm_fnInvokeCommand,
440 ISVBgCm_fnGetCommandString,
441 ISVBgCm_fnHandleMenuMsg,
442 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */