- 3d buffers produce sounds
[wine/hacks.git] / dlls / shell32 / shv_bg_cmenu.c
blob6f847f1523986fa97cbc28f7b424b81d26e937f4
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include <string.h>
23 #include "wine/debug.h"
25 #include "pidl.h"
26 #include "shlguid.h"
27 #include "shlobj.h"
29 #include "shell32_main.h"
30 #include "shellfolder.h"
31 #include "undocshell.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(shell);
35 /**************************************************************************
36 * IContextMenu Implementation
38 typedef struct
40 ICOM_VFIELD(IContextMenu);
41 IShellFolder* pSFParent;
42 DWORD ref;
43 } BgCmImpl;
46 static struct ICOM_VTABLE(IContextMenu) cmvt;
48 /**************************************************************************
49 * ISVBgCm_Constructor()
51 IContextMenu *ISvBgCm_Constructor(IShellFolder* pSFParent)
53 BgCmImpl* cm;
55 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
56 ICOM_VTBL(cm)=&cmvt;
57 cm->ref = 1;
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);
74 *ppvObj = NULL;
76 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
78 *ppvObj = This;
80 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
82 *ppvObj = This;
84 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
86 FIXME("-- LPSHELLEXTINIT pointer requested\n");
89 if(*ppvObj)
91 IUnknown_AddRef((IUnknown*)*ppvObj);
92 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
93 return S_OK;
95 TRACE("-- Interface: E_NOINTERFACE\n");
96 return E_NOINTERFACE;
99 /**************************************************************************
100 * ISVBgCm_fnAddRef
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 /**************************************************************************
112 * ISVBgCm_fnRelease
114 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
116 ICOM_THIS(BgCmImpl, iface);
118 TRACE("(%p)->()\n",This);
120 if (!--(This->ref))
122 TRACE(" destroying IContextMenu(%p)\n",This);
124 if(This->pSFParent)
125 IShellFolder_Release(This->pSFParent);
127 HeapFree(GetProcessHeap(),0,This);
128 return 0;
131 return This->ref;
134 /**************************************************************************
135 * ISVBgCm_fnQueryContextMenu()
138 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
139 IContextMenu *iface,
140 HMENU hMenu,
141 UINT indexMenu,
142 UINT idCmdFirst,
143 UINT idCmdLast,
144 UINT uFlags)
146 HMENU hMyMenu;
147 UINT idMax;
148 HRESULT hr;
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);
166 else
167 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
169 else
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);
178 return hr;
181 /**************************************************************************
182 * DoNewFolder
184 static void DoNewFolder(
185 IContextMenu *iface,
186 IShellView *psv)
188 ICOM_THIS(BgCmImpl, iface);
189 ISFHelper * psfhlp;
190 char szName[MAX_PATH];
192 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
193 if (psfhlp)
195 LPITEMIDLIST pidl;
196 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
197 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
199 if(psv)
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));
206 SHFree(pidl);
208 ISFHelper_Release(psfhlp);
212 /**************************************************************************
213 * DoPaste
215 static BOOL DoPaste(
216 IContextMenu *iface)
218 ICOM_THIS(BgCmImpl, iface);
219 BOOL bSuccess = FALSE;
220 IDataObject * pda;
222 TRACE("\n");
224 if(SUCCEEDED(pOleGetClipboard(&pda)))
226 STGMEDIUM medium;
227 FORMATETC formatetc;
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;
238 LPITEMIDLIST pidl;
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);
248 if(psfDesktop)
250 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
251 IShellFolder_Release(psfDesktop);
254 if (psfFrom)
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);
265 /* FIXME handle move
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);
275 SHFree(pidl);
277 /* release the medium*/
278 pReleaseStgMedium(&medium);
280 IDataObject_Release(pda);
282 #if 0
283 HGLOBAL hMem;
285 OpenClipboard(NULL);
286 hMem = GetClipboardData(CF_HDROP);
288 if(hMem)
290 char * pDropFiles = (char *)GlobalLock(hMem);
291 if(pDropFiles)
293 int len, offset = sizeof(DROPFILESTRUCT);
295 while( pDropFiles[offset] != 0)
297 len = strlen(pDropFiles + offset);
298 TRACE("%s\n", pDropFiles + offset);
299 offset += len+1;
302 GlobalUnlock(hMem);
304 CloseClipboard();
305 #endif
306 return bSuccess;
308 /**************************************************************************
309 * ISVBgCm_fnInvokeCommand()
311 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
312 IContextMenu *iface,
313 LPCMINVOKECOMMANDINFO lpcmi)
315 ICOM_THIS(BgCmImpl, iface);
317 LPSHELLBROWSER lpSB;
318 LPSHELLVIEW lpSV;
319 HWND hWndSV;
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);
332 if(lpSV)
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 );
350 else
352 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
355 else
357 switch(LOWORD(lpcmi->lpVerb))
359 case FCIDM_SHVIEW_NEWFOLDER:
360 DoNewFolder(iface, lpSV);
361 break;
362 case FCIDM_SHVIEW_INSERT:
363 DoPaste(iface);
364 break;
365 default:
366 /* if it's a id just pass it to the parent shv */
367 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
368 break;
372 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
374 return NOERROR;
377 /**************************************************************************
378 * ISVBgCm_fnGetCommandString()
381 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
382 IContextMenu *iface,
383 UINT idCommand,
384 UINT uFlags,
385 UINT* lpReserved,
386 LPSTR lpszName,
387 UINT uMaxNameLen)
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))
403 return NOERROR;
408 FIXME("unknown command string\n");
409 return E_FAIL;
412 /**************************************************************************
413 * ISVBgCm_fnHandleMenuMsg()
415 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
416 IContextMenu *iface,
417 UINT uMsg,
418 WPARAM wParam,
419 LPARAM lParam)
421 ICOM_THIS(BgCmImpl, iface);
423 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
425 return E_NOTIMPL;
428 /**************************************************************************
429 * IContextMenu VTable
432 static struct ICOM_VTABLE(IContextMenu) cmvt =
434 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
435 ISVBgCm_fnQueryInterface,
436 ISVBgCm_fnAddRef,
437 ISVBgCm_fnRelease,
438 ISVBgCm_fnQueryContextMenu,
439 ISVBgCm_fnInvokeCommand,
440 ISVBgCm_fnGetCommandString,
441 ISVBgCm_fnHandleMenuMsg,
442 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */