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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
27 #include "wine/debug.h"
35 #include "shell32_main.h"
36 #include "shellfolder.h"
37 #include "undocshell.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(shell);
41 /**************************************************************************
42 * IContextMenu Implementation
46 const IContextMenu2Vtbl *lpVtbl;
47 IShellFolder* pSFParent;
53 static const IContextMenu2Vtbl cmvt;
55 /**************************************************************************
56 * ISVBgCm_Constructor()
58 IContextMenu2 *ISvBgCm_Constructor(IShellFolder* pSFParent, BOOL bDesktop)
62 cm = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
65 cm->pSFParent = pSFParent;
66 cm->bDesktop = bDesktop;
67 if(pSFParent) IShellFolder_AddRef(pSFParent);
69 TRACE("(%p)->()\n",cm);
70 return (IContextMenu2*)cm;
73 /**************************************************************************
74 * ISVBgCm_fnQueryInterface
76 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu2 *iface, REFIID riid, LPVOID *ppvObj)
78 BgCmImpl *This = (BgCmImpl *)iface;
80 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
84 if(IsEqualIID(riid, &IID_IUnknown) ||
85 IsEqualIID(riid, &IID_IContextMenu) ||
86 IsEqualIID(riid, &IID_IContextMenu2))
90 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
92 FIXME("-- LPSHELLEXTINIT pointer requested\n");
97 IUnknown_AddRef((IUnknown*)*ppvObj);
98 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
101 TRACE("-- Interface: E_NOINTERFACE\n");
102 return E_NOINTERFACE;
105 /**************************************************************************
108 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu2 *iface)
110 BgCmImpl *This = (BgCmImpl *)iface;
111 ULONG refCount = InterlockedIncrement(&This->ref);
113 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
118 /**************************************************************************
121 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu2 *iface)
123 BgCmImpl *This = (BgCmImpl *)iface;
124 ULONG refCount = InterlockedDecrement(&This->ref);
126 TRACE("(%p)->(count=%li)\n", This, refCount + 1);
130 TRACE(" destroying IContextMenu(%p)\n",This);
133 IShellFolder_Release(This->pSFParent);
135 HeapFree(GetProcessHeap(),0,This);
140 /**************************************************************************
141 * ISVBgCm_fnQueryContextMenu()
144 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
145 IContextMenu2 *iface,
156 BgCmImpl *This = (BgCmImpl *)iface;
158 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
159 This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
162 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
163 if (uFlags & CMF_DEFAULTONLY)
165 HMENU ourMenu = GetSubMenu(hMyMenu,0);
166 UINT oldDef = GetMenuDefaultItem(hMenu,TRUE,GMDI_USEDISABLED);
167 UINT newDef = GetMenuDefaultItem(ourMenu,TRUE,GMDI_USEDISABLED);
168 if (newDef != oldDef)
169 SetMenuDefaultItem(hMenu,newDef,TRUE);
170 if (newDef!=0xFFFFFFFF)
171 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, newDef+1);
173 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
177 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu,
178 idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
179 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst+1);
181 DestroyMenu(hMyMenu);
183 TRACE("(%p)->returning 0x%lx\n",This,hr);
187 /**************************************************************************
190 static void DoNewFolder(
191 IContextMenu2 *iface,
194 BgCmImpl *This = (BgCmImpl *)iface;
196 WCHAR wszName[MAX_PATH];
198 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
202 ISFHelper_GetUniqueName(psfhlp, wszName, MAX_PATH);
203 ISFHelper_AddFolder(psfhlp, 0, wszName, &pidl);
207 /* if we are in a shellview do labeledit */
208 IShellView_SelectItem(psv,
209 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
210 |SVSI_FOCUSED|SVSI_SELECT));
214 ISFHelper_Release(psfhlp);
218 /**************************************************************************
222 IContextMenu2 *iface)
224 BgCmImpl *This = (BgCmImpl *)iface;
225 BOOL bSuccess = FALSE;
230 if(SUCCEEDED(OleGetClipboard(&pda)))
235 TRACE("pda=%p\n", pda);
237 /* Set the FORMATETC structure*/
238 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
240 /* Get the pidls from IDataObject */
241 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
243 LPITEMIDLIST * apidl;
245 IShellFolder *psfFrom = NULL, *psfDesktop;
247 LPIDA lpcida = GlobalLock(medium.u.hGlobal);
248 TRACE("cida=%p\n", lpcida);
250 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
252 /* bind to the source shellfolder */
253 SHGetDesktopFolder(&psfDesktop);
256 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
257 IShellFolder_Release(psfDesktop);
262 /* get source and destination shellfolder */
263 ISFHelper *psfhlpdst, *psfhlpsrc;
264 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
265 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
267 /* do the copy/move */
268 if (psfhlpdst && psfhlpsrc)
270 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, (LPCITEMIDLIST*)apidl);
272 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
275 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
276 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
277 IShellFolder_Release(psfFrom);
280 _ILFreeaPidl(apidl, lpcida->cidl);
283 /* release the medium*/
284 ReleaseStgMedium(&medium);
286 IDataObject_Release(pda);
292 hMem = GetClipboardData(CF_HDROP);
296 char * pDropFiles = (char *)GlobalLock(hMem);
299 int len, offset = sizeof(DROPFILESTRUCT);
301 while( pDropFiles[offset] != 0)
303 len = strlen(pDropFiles + offset);
304 TRACE("%s\n", pDropFiles + offset);
315 /**************************************************************************
316 * ISVBgCm_fnInvokeCommand()
318 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
319 IContextMenu2 *iface,
320 LPCMINVOKECOMMANDINFO lpcmi)
322 BgCmImpl *This = (BgCmImpl *)iface;
325 LPSHELLVIEW lpSV = NULL;
328 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
330 /* get the active IShellView */
331 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
333 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
335 IShellView_GetWindow(lpSV, &hWndSV);
339 if(HIWORD(lpcmi->lpVerb))
341 TRACE("%s\n",lpcmi->lpVerb);
343 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
345 DoNewFolder(iface, lpSV);
347 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
349 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
351 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
353 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
357 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
362 switch(LOWORD(lpcmi->lpVerb))
364 case FCIDM_SHVIEW_REFRESH:
365 if (lpSV) IShellView_Refresh(lpSV);
368 case FCIDM_SHVIEW_NEWFOLDER:
369 DoNewFolder(iface, lpSV);
372 case FCIDM_SHVIEW_INSERT:
376 case FCIDM_SHVIEW_PROPERTIES:
377 if (This->bDesktop) {
378 ShellExecuteA(lpcmi->hwnd, "open", "rundll32.exe shell32.dll,Control_RunDLL desk.cpl", NULL, NULL, SW_SHOWNORMAL);
380 FIXME("launch item properties dialog\n");
385 /* if it's an id just pass it to the parent shv */
386 if (hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
392 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef */
397 /**************************************************************************
398 * ISVBgCm_fnGetCommandString()
401 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
402 IContextMenu2 *iface,
409 BgCmImpl *This = (BgCmImpl *)iface;
411 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
413 /* test the existence of the menu items, the file dialog enables
414 the buttons according to this */
415 if (uFlags == GCS_VALIDATEA)
417 if(HIWORD(idCommand))
419 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
420 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
421 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
428 FIXME("unknown command string\n");
432 /**************************************************************************
433 * ISVBgCm_fnHandleMenuMsg()
435 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
436 IContextMenu2 *iface,
441 BgCmImpl *This = (BgCmImpl *)iface;
443 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
448 /**************************************************************************
449 * IContextMenu2 VTable
452 static const IContextMenu2Vtbl cmvt =
454 ISVBgCm_fnQueryInterface,
457 ISVBgCm_fnQueryContextMenu,
458 ISVBgCm_fnInvokeCommand,
459 ISVBgCm_fnGetCommandString,
460 ISVBgCm_fnHandleMenuMsg