Moved undocshell.h to dlls/shell32. Removed shell16.h.
[wine/multimedia.git] / dlls / shell32 / shv_bg_cmenu.c
blobaaf03ec6c3849bf6342adeb394fab5d5bf9ff5fb
1 /*
2 * IContextMenu
3 * ShellView Background Context Menu (shv_bg_cm)
5 * Copyright 1999 Juergen Schmied <juergen.schmied@metronet.de>
6 */
7 #include <string.h>
9 #include "debugtools.h"
11 #include "pidl.h"
12 #include "shlguid.h"
13 #include "wine/obj_base.h"
14 #include "wine/obj_contextmenu.h"
15 #include "wine/obj_shellbrowser.h"
17 #include "shell32_main.h"
18 #include "shellfolder.h"
19 #include "undocshell.h"
21 DEFAULT_DEBUG_CHANNEL(shell);
23 /**************************************************************************
24 * IContextMenu Implementation
26 typedef struct
28 ICOM_VFIELD(IContextMenu);
29 IShellFolder* pSFParent;
30 DWORD ref;
31 } BgCmImpl;
34 static struct ICOM_VTABLE(IContextMenu) cmvt;
36 /**************************************************************************
37 * ISVBgCm_Constructor()
39 IContextMenu *ISvBgCm_Constructor(IShellFolder* pSFParent)
41 BgCmImpl* cm;
43 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
44 ICOM_VTBL(cm)=&cmvt;
45 cm->ref = 1;
46 cm->pSFParent = pSFParent;
47 if(pSFParent) IShellFolder_AddRef(pSFParent);
49 TRACE("(%p)->()\n",cm);
50 shell32_ObjCount++;
51 return (IContextMenu*)cm;
54 /**************************************************************************
55 * ISVBgCm_fnQueryInterface
57 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
59 ICOM_THIS(BgCmImpl, iface);
61 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
63 *ppvObj = NULL;
65 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
67 *ppvObj = This;
69 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
71 *ppvObj = This;
73 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
75 FIXME("-- LPSHELLEXTINIT pointer requested\n");
78 if(*ppvObj)
80 IUnknown_AddRef((IUnknown*)*ppvObj);
81 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
82 return S_OK;
84 TRACE("-- Interface: E_NOINTERFACE\n");
85 return E_NOINTERFACE;
88 /**************************************************************************
89 * ISVBgCm_fnAddRef
91 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
93 ICOM_THIS(BgCmImpl, iface);
95 TRACE("(%p)->(count=%lu)\n",This, This->ref);
97 shell32_ObjCount++;
98 return ++(This->ref);
101 /**************************************************************************
102 * ISVBgCm_fnRelease
104 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
106 ICOM_THIS(BgCmImpl, iface);
108 TRACE("(%p)->()\n",This);
110 if (!--(This->ref))
112 TRACE(" destroying IContextMenu(%p)\n",This);
114 if(This->pSFParent)
115 IShellFolder_Release(This->pSFParent);
117 HeapFree(GetProcessHeap(),0,This);
118 return 0;
121 shell32_ObjCount--;
123 return This->ref;
126 /**************************************************************************
127 * ISVBgCm_fnQueryContextMenu()
130 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
131 IContextMenu *iface,
132 HMENU hMenu,
133 UINT indexMenu,
134 UINT idCmdFirst,
135 UINT idCmdLast,
136 UINT uFlags)
138 HMENU hMyMenu;
139 UINT idMax;
141 ICOM_THIS(BgCmImpl, iface);
143 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
145 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
147 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
149 DestroyMenu(hMyMenu);
151 return ResultFromShort(idMax - idCmdFirst);
154 /**************************************************************************
155 * DoNewFolder
157 static void DoNewFolder(
158 IContextMenu *iface,
159 IShellView *psv)
161 ICOM_THIS(BgCmImpl, iface);
162 ISFHelper * psfhlp;
163 char szName[MAX_PATH];
165 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
166 if (psfhlp)
168 LPITEMIDLIST pidl;
169 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
170 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
172 if(psv)
174 /* if we are in a shellview do labeledit */
175 IShellView_SelectItem(psv,
176 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
177 |SVSI_FOCUSED|SVSI_SELECT));
179 SHFree(pidl);
181 ISFHelper_Release(psfhlp);
185 /**************************************************************************
186 * DoPaste
188 static BOOL DoPaste(
189 IContextMenu *iface)
191 ICOM_THIS(BgCmImpl, iface);
192 BOOL bSuccess = FALSE;
193 IDataObject * pda;
195 TRACE("\n");
197 if(SUCCEEDED(pOleGetClipboard(&pda)))
199 STGMEDIUM medium;
200 FORMATETC formatetc;
202 TRACE("pda=%p\n", pda);
204 /* Set the FORMATETC structure*/
205 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
207 /* Get the pidls from IDataObject */
208 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
210 LPITEMIDLIST * apidl;
211 LPITEMIDLIST pidl;
212 IShellFolder *psfFrom = NULL, *psfDesktop;
214 LPCIDA lpcida = GlobalLock(medium.u.hGlobal);
215 TRACE("cida=%p\n", lpcida);
217 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
219 /* bind to the source shellfolder */
220 SHGetDesktopFolder(&psfDesktop);
221 if(psfDesktop)
223 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
224 IShellFolder_Release(psfDesktop);
227 if (psfFrom)
229 /* get source and destination shellfolder */
230 ISFHelper *psfhlpdst, *psfhlpsrc;
231 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
232 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
234 /* do the copy/move */
235 if (psfhlpdst && psfhlpsrc)
237 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, apidl);
238 /* fixme handle move
239 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
242 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
243 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
244 IShellFolder_Release(psfFrom);
247 _ILFreeaPidl(apidl, lpcida->cidl);
248 SHFree(pidl);
250 /* release the medium*/
251 pReleaseStgMedium(&medium);
253 IDataObject_Release(pda);
255 #if 0
256 HGLOBAL hMem;
258 OpenClipboard(NULL);
259 hMem = GetClipboardData(CF_HDROP);
261 if(hMem)
263 char * pDropFiles = (char *)GlobalLock(hMem);
264 if(pDropFiles)
266 int len, offset = sizeof(DROPFILESTRUCT);
268 while( pDropFiles[offset] != 0)
270 len = strlen(pDropFiles + offset);
271 TRACE("%s\n", pDropFiles + offset);
272 offset += len+1;
275 GlobalUnlock(hMem);
277 CloseClipboard();
278 #endif
279 return bSuccess;
281 /**************************************************************************
282 * ISVBgCm_fnInvokeCommand()
284 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
285 IContextMenu *iface,
286 LPCMINVOKECOMMANDINFO lpcmi)
288 ICOM_THIS(BgCmImpl, iface);
290 LPSHELLBROWSER lpSB;
291 LPSHELLVIEW lpSV;
292 HWND hWndSV;
294 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
296 /* get the active IShellView */
297 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
299 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
301 IShellView_GetWindow(lpSV, &hWndSV);
305 if(lpSV)
307 if(HIWORD(lpcmi->lpVerb))
309 TRACE("%s\n",lpcmi->lpVerb);
311 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
313 if(lpSV) DoNewFolder(iface, lpSV);
315 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
317 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
319 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
321 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
323 else
325 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
328 else
330 switch(LOWORD(lpcmi->lpVerb))
332 case FCIDM_SHVIEW_NEWFOLDER:
333 DoNewFolder(iface, lpSV);
334 break;
335 case FCIDM_SHVIEW_INSERT:
336 DoPaste(iface);
337 break;
338 default:
339 /* if it's a id just pass it to the parent shv */
340 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
341 break;
345 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
347 return NOERROR;
350 /**************************************************************************
351 * ISVBgCm_fnGetCommandString()
354 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
355 IContextMenu *iface,
356 UINT idCommand,
357 UINT uFlags,
358 LPUINT lpReserved,
359 LPSTR lpszName,
360 UINT uMaxNameLen)
362 ICOM_THIS(BgCmImpl, iface);
364 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
366 /* test the existence of the menu items, the file dialog enables
367 the buttons according to this */
368 if (uFlags == GCS_VALIDATEA)
370 if(HIWORD(idCommand))
372 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
373 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
374 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
376 return NOERROR;
381 FIXME("unknown command string\n");
382 return E_FAIL;
385 /**************************************************************************
386 * ISVBgCm_fnHandleMenuMsg()
388 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
389 IContextMenu *iface,
390 UINT uMsg,
391 WPARAM wParam,
392 LPARAM lParam)
394 ICOM_THIS(BgCmImpl, iface);
396 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
398 return E_NOTIMPL;
401 /**************************************************************************
402 * IContextMenu VTable
405 static struct ICOM_VTABLE(IContextMenu) cmvt =
407 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
408 ISVBgCm_fnQueryInterface,
409 ISVBgCm_fnAddRef,
410 ISVBgCm_fnRelease,
411 ISVBgCm_fnQueryContextMenu,
412 ISVBgCm_fnInvokeCommand,
413 ISVBgCm_fnGetCommandString,
414 ISVBgCm_fnHandleMenuMsg,
415 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */