shell32: Get rid of rename helper.
[wine/multimedia.git] / dlls / shell32 / shv_bg_cmenu.c
blobc2c6f080fa1d29974d3baf7a8b31fb44031dd104
1 /*
2 * IContextMenu
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
21 #include <string.h>
23 #define COBJMACROS
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
27 #include "wine/debug.h"
29 #include "windef.h"
30 #include "wingdi.h"
31 #include "pidl.h"
32 #include "shlobj.h"
34 #include "shell32_main.h"
35 #include "shellfolder.h"
36 #include "undocshell.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shell);
40 /**************************************************************************
41 * IContextMenu Implementation
43 typedef struct
45 IContextMenu2 IContextMenu2_iface;
46 IShellFolder* pSFParent;
47 LONG ref;
48 BOOL bDesktop;
49 UINT verb_offset;
50 } BgCmImpl;
52 static inline BgCmImpl *impl_from_IContextMenu2(IContextMenu2 *iface)
54 return CONTAINING_RECORD(iface, BgCmImpl, IContextMenu2_iface);
57 /**************************************************************************
58 * ISVBgCm_fnQueryInterface
60 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu2 *iface, REFIID riid, LPVOID *ppvObj)
62 BgCmImpl *This = impl_from_IContextMenu2(iface);
64 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
66 *ppvObj = NULL;
68 if(IsEqualIID(riid, &IID_IUnknown) ||
69 IsEqualIID(riid, &IID_IContextMenu) ||
70 IsEqualIID(riid, &IID_IContextMenu2))
72 *ppvObj = This;
74 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
76 FIXME("-- LPSHELLEXTINIT pointer requested\n");
79 if(*ppvObj)
81 IUnknown_AddRef((IUnknown*)*ppvObj);
82 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
83 return S_OK;
85 TRACE("-- Interface: E_NOINTERFACE\n");
86 return E_NOINTERFACE;
89 /**************************************************************************
90 * ISVBgCm_fnAddRef
92 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu2 *iface)
94 BgCmImpl *This = impl_from_IContextMenu2(iface);
95 ULONG refCount = InterlockedIncrement(&This->ref);
97 TRACE("(%p)->(count=%u)\n", This, refCount - 1);
99 return refCount;
102 /**************************************************************************
103 * ISVBgCm_fnRelease
105 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu2 *iface)
107 BgCmImpl *This = impl_from_IContextMenu2(iface);
108 ULONG refCount = InterlockedDecrement(&This->ref);
110 TRACE("(%p)->(count=%i)\n", This, refCount + 1);
112 if (!refCount)
114 TRACE(" destroying IContextMenu(%p)\n",This);
116 if(This->pSFParent)
117 IShellFolder_Release(This->pSFParent);
119 HeapFree(GetProcessHeap(),0,This);
121 return refCount;
124 /**************************************************************************
125 * ISVBgCm_fnQueryContextMenu()
128 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
129 IContextMenu2 *iface,
130 HMENU hMenu,
131 UINT indexMenu,
132 UINT idCmdFirst,
133 UINT idCmdLast,
134 UINT uFlags)
136 BgCmImpl *This = impl_from_IContextMenu2(iface);
137 HMENU hMyMenu;
138 UINT idMax;
139 HRESULT hr;
141 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
142 This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
144 This->verb_offset=idCmdFirst;
146 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
147 if (uFlags & CMF_DEFAULTONLY)
149 HMENU ourMenu = GetSubMenu(hMyMenu,0);
150 UINT oldDef = GetMenuDefaultItem(hMenu,TRUE,GMDI_USEDISABLED);
151 UINT newDef = GetMenuDefaultItem(ourMenu,TRUE,GMDI_USEDISABLED);
152 if (newDef != oldDef)
153 SetMenuDefaultItem(hMenu,newDef,TRUE);
154 if (newDef!=0xFFFFFFFF)
155 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, newDef+1);
156 else
157 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
159 else
161 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu,
162 idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
163 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst);
165 DestroyMenu(hMyMenu);
167 TRACE("(%p)->returning 0x%x\n",This,hr);
168 return hr;
171 /**************************************************************************
172 * DoNewFolder
174 static void DoNewFolder(
175 BgCmImpl *This,
176 IShellView *psv)
178 ISFHelper * psfhlp;
179 WCHAR wszName[MAX_PATH];
181 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
182 if (psfhlp)
184 LPITEMIDLIST pidl;
185 ISFHelper_GetUniqueName(psfhlp, wszName, MAX_PATH);
186 ISFHelper_AddFolder(psfhlp, 0, wszName, &pidl);
188 if(psv)
190 /* if we are in a shellview do labeledit */
191 IShellView_SelectItem(psv,
192 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
193 |SVSI_FOCUSED|SVSI_SELECT));
195 SHFree(pidl);
197 ISFHelper_Release(psfhlp);
201 /**************************************************************************
202 * DoPaste
204 static BOOL DoPaste(
205 BgCmImpl *This)
207 BOOL bSuccess = FALSE;
208 IDataObject * pda;
210 TRACE("\n");
212 if(SUCCEEDED(OleGetClipboard(&pda)))
214 STGMEDIUM medium;
215 FORMATETC formatetc;
217 TRACE("pda=%p\n", pda);
219 /* Set the FORMATETC structure*/
220 InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLISTW), TYMED_HGLOBAL);
222 /* Get the pidls from IDataObject */
223 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
225 LPITEMIDLIST * apidl;
226 LPITEMIDLIST pidl;
227 IShellFolder *psfFrom = NULL, *psfDesktop;
229 LPIDA lpcida = GlobalLock(medium.u.hGlobal);
230 TRACE("cida=%p\n", lpcida);
232 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
234 /* bind to the source shellfolder */
235 SHGetDesktopFolder(&psfDesktop);
236 if(psfDesktop)
238 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
239 IShellFolder_Release(psfDesktop);
242 if (psfFrom)
244 /* get source and destination shellfolder */
245 ISFHelper *psfhlpdst, *psfhlpsrc;
246 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
247 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
249 /* do the copy/move */
250 if (psfhlpdst && psfhlpsrc)
252 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, (LPCITEMIDLIST*)apidl);
253 /* FIXME handle move
254 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
257 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
258 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
259 IShellFolder_Release(psfFrom);
262 _ILFreeaPidl(apidl, lpcida->cidl);
263 SHFree(pidl);
265 /* release the medium*/
266 ReleaseStgMedium(&medium);
268 IDataObject_Release(pda);
270 #if 0
271 HGLOBAL hMem;
273 OpenClipboard(NULL);
274 hMem = GetClipboardData(CF_HDROP);
276 if(hMem)
278 char * pDropFiles = GlobalLock(hMem);
279 if(pDropFiles)
281 int len, offset = sizeof(DROPFILESTRUCT);
283 while( pDropFiles[offset] != 0)
285 len = strlen(pDropFiles + offset);
286 TRACE("%s\n", pDropFiles + offset);
287 offset += len+1;
290 GlobalUnlock(hMem);
292 CloseClipboard();
293 #endif
294 return bSuccess;
297 /**************************************************************************
298 * ISVBgCm_fnInvokeCommand()
300 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
301 IContextMenu2 *iface,
302 LPCMINVOKECOMMANDINFO lpcmi)
304 BgCmImpl *This = impl_from_IContextMenu2(iface);
305 LPSHELLBROWSER lpSB;
306 LPSHELLVIEW lpSV = NULL;
307 HWND hWndSV = 0;
309 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
311 /* get the active IShellView */
312 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
314 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
316 IShellView_GetWindow(lpSV, &hWndSV);
320 if(HIWORD(lpcmi->lpVerb))
322 TRACE("%s\n",lpcmi->lpVerb);
324 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
326 DoNewFolder(This, lpSV);
328 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
330 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
332 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
334 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
336 else
338 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
341 else
343 switch(LOWORD(lpcmi->lpVerb)-This->verb_offset)
345 case FCIDM_SHVIEW_REFRESH:
346 if (lpSV) IShellView_Refresh(lpSV);
347 break;
349 case FCIDM_SHVIEW_NEWFOLDER:
350 DoNewFolder(This, lpSV);
351 break;
353 case FCIDM_SHVIEW_INSERT:
354 DoPaste(This);
355 break;
357 case FCIDM_SHVIEW_PROPERTIES:
358 if (This->bDesktop) {
359 ShellExecuteA(lpcmi->hwnd, "open", "rundll32.exe shell32.dll,Control_RunDLL desk.cpl", NULL, NULL, SW_SHOWNORMAL);
360 } else {
361 FIXME("launch item properties dialog\n");
363 break;
365 default:
366 /* if it's an id just pass it to the parent shv */
367 if (hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
368 break;
372 if (lpSV)
373 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef */
375 return S_OK;
378 /**************************************************************************
379 * ISVBgCm_fnGetCommandString()
382 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
383 IContextMenu2 *iface,
384 UINT_PTR idCommand,
385 UINT uFlags,
386 UINT* lpReserved,
387 LPSTR lpszName,
388 UINT uMaxNameLen)
390 BgCmImpl *This = impl_from_IContextMenu2(iface);
392 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
394 /* test the existence of the menu items, the file dialog enables
395 the buttons according to this */
396 if (uFlags == GCS_VALIDATEA)
398 if(HIWORD(idCommand))
400 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
401 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
402 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
404 return S_OK;
409 FIXME("unknown command string\n");
410 return E_FAIL;
413 /**************************************************************************
414 * ISVBgCm_fnHandleMenuMsg()
416 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
417 IContextMenu2 *iface,
418 UINT uMsg,
419 WPARAM wParam,
420 LPARAM lParam)
422 BgCmImpl *This = impl_from_IContextMenu2(iface);
424 FIXME("(%p)->(msg=%x wp=%lx lp=%lx)\n",This, uMsg, wParam, lParam);
426 return E_NOTIMPL;
429 /**************************************************************************
430 * IContextMenu2 VTable
433 static const IContextMenu2Vtbl BackgroundContextMenuVtbl =
435 ISVBgCm_fnQueryInterface,
436 ISVBgCm_fnAddRef,
437 ISVBgCm_fnRelease,
438 ISVBgCm_fnQueryContextMenu,
439 ISVBgCm_fnInvokeCommand,
440 ISVBgCm_fnGetCommandString,
441 ISVBgCm_fnHandleMenuMsg
444 IContextMenu2 *ISvBgCm_Constructor(IShellFolder *pSFParent, BOOL bDesktop)
446 BgCmImpl *cm;
448 cm = HeapAlloc(GetProcessHeap(), 0, sizeof(*cm));
449 cm->IContextMenu2_iface.lpVtbl = &BackgroundContextMenuVtbl;
450 cm->ref = 1;
451 cm->pSFParent = pSFParent;
452 cm->bDesktop = bDesktop;
453 cm->verb_offset = 0;
454 if(pSFParent) IShellFolder_AddRef(pSFParent);
456 TRACE("(%p)->()\n", cm);
457 return &cm->IContextMenu2_iface;