Release 20000326.
[wine/gsoc-2012-control.git] / dlls / shell32 / shv_bg_cmenu.c
blobb9b1b733aae52c763f51ad79e134d1d1f1d48d29
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 "wine/obj_base.h"
13 #include "wine/obj_contextmenu.h"
14 #include "wine/obj_shellbrowser.h"
16 #include "shell32_main.h"
17 #include "shellfolder.h"
18 #include "shell.h" /* DROPFILESTRUCT */
20 DEFAULT_DEBUG_CHANNEL(shell)
22 /**************************************************************************
23 * IContextMenu Implementation
25 typedef struct
27 ICOM_VFIELD(IContextMenu);
28 IShellFolder* pSFParent;
29 DWORD ref;
30 } BgCmImpl;
33 static struct ICOM_VTABLE(IContextMenu) cmvt;
35 /**************************************************************************
36 * ISVBgCm_Constructor()
38 IContextMenu *ISvBgCm_Constructor(IShellFolder* pSFParent)
40 BgCmImpl* cm;
42 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
43 ICOM_VTBL(cm)=&cmvt;
44 cm->ref = 1;
45 cm->pSFParent = pSFParent;
46 if(pSFParent) IShellFolder_AddRef(pSFParent);
48 TRACE("(%p)->()\n",cm);
49 shell32_ObjCount++;
50 return (IContextMenu*)cm;
53 /**************************************************************************
54 * ISVBgCm_fnQueryInterface
56 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
58 ICOM_THIS(BgCmImpl, iface);
60 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
62 *ppvObj = NULL;
64 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
66 *ppvObj = This;
68 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
70 *ppvObj = This;
72 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
74 FIXME("-- LPSHELLEXTINIT pointer requested\n");
77 if(*ppvObj)
79 IUnknown_AddRef((IUnknown*)*ppvObj);
80 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
81 return S_OK;
83 TRACE("-- Interface: E_NOINTERFACE\n");
84 return E_NOINTERFACE;
87 /**************************************************************************
88 * ISVBgCm_fnAddRef
90 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
92 ICOM_THIS(BgCmImpl, iface);
94 TRACE("(%p)->(count=%lu)\n",This, This->ref);
96 shell32_ObjCount++;
97 return ++(This->ref);
100 /**************************************************************************
101 * ISVBgCm_fnRelease
103 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
105 ICOM_THIS(BgCmImpl, iface);
107 TRACE("(%p)->()\n",This);
109 if (!--(This->ref))
111 TRACE(" destroying IContextMenu(%p)\n",This);
113 if(This->pSFParent)
114 IShellFolder_Release(This->pSFParent);
116 HeapFree(GetProcessHeap(),0,This);
117 return 0;
120 shell32_ObjCount--;
122 return This->ref;
125 /**************************************************************************
126 * ISVBgCm_fnQueryContextMenu()
129 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
130 IContextMenu *iface,
131 HMENU hMenu,
132 UINT indexMenu,
133 UINT idCmdFirst,
134 UINT idCmdLast,
135 UINT uFlags)
137 HMENU hMyMenu;
138 UINT idMax;
140 ICOM_THIS(BgCmImpl, iface);
142 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
144 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
146 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
148 DestroyMenu(hMyMenu);
150 return ResultFromShort(idMax - idCmdFirst);
153 /**************************************************************************
154 * DoNewFolder
156 static void DoNewFolder(
157 IContextMenu *iface,
158 IShellView *psv)
160 ICOM_THIS(BgCmImpl, iface);
161 ISFHelper * psfhlp;
162 char szName[MAX_PATH];
164 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
165 if (psfhlp)
167 LPITEMIDLIST pidl;
168 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
169 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
171 if(psv)
173 /* if we are in a shellview do labeledit */
174 IShellView_SelectItem(psv,
175 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
176 |SVSI_FOCUSED|SVSI_SELECT));
178 SHFree(pidl);
180 ISFHelper_Release(psfhlp);
184 /**************************************************************************
185 * DoPaste
187 static BOOL DoPaste(
188 IContextMenu *iface)
190 ICOM_THIS(BgCmImpl, iface);
191 BOOL bSuccess = FALSE;
192 IDataObject * pda;
194 TRACE("\n");
196 if(SUCCEEDED(pOleGetClipboard(&pda)));
198 STGMEDIUM medium;
199 FORMATETC formatetc;
201 TRACE("pda=%p\n", pda);
203 /* Set the FORMATETC structure*/
204 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
206 /* Get the pidls from IDataObject */
207 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
209 LPITEMIDLIST * apidl;
210 LPITEMIDLIST pidl;
211 IShellFolder *psfFrom = NULL, *psfDesktop;
213 LPCIDA lpcida = GlobalLock(medium.u.hGlobal);
214 TRACE("cida=%p\n", lpcida);
216 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
218 /* bind to the source shellfolder */
219 SHGetDesktopFolder(&psfDesktop);
220 if(psfDesktop)
222 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
223 IShellFolder_Release(psfDesktop);
226 if (psfFrom)
228 /* get source and destination shellfolder */
229 ISFHelper *psfhlpdst, *psfhlpsrc;
230 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
231 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
233 /* do the copy/move */
234 if (psfhlpdst && psfhlpsrc)
236 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, apidl);
237 /* fixme handle move
238 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
241 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
242 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
243 IShellFolder_Release(psfFrom);
246 _ILFreeaPidl(apidl, lpcida->cidl);
247 SHFree(pidl);
249 /* release the medium*/
250 pReleaseStgMedium(&medium);
252 IDataObject_Release(pda);
254 #if 0
255 HGLOBAL hMem;
257 OpenClipboard(NULL);
258 hMem = GetClipboardData(CF_HDROP);
260 if(hMem)
262 char * pDropFiles = (char *)GlobalLock(hMem);
263 if(pDropFiles)
265 int len, offset = sizeof(DROPFILESTRUCT);
267 while( pDropFiles[offset] != 0)
269 len = strlen(pDropFiles + offset);
270 TRACE("%s\n", pDropFiles + offset);
271 offset += len+1;
274 GlobalUnlock(hMem);
276 CloseClipboard();
277 #endif
278 return bSuccess;
280 /**************************************************************************
281 * ISVBgCm_fnInvokeCommand()
283 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
284 IContextMenu *iface,
285 LPCMINVOKECOMMANDINFO lpcmi)
287 ICOM_THIS(BgCmImpl, iface);
289 LPSHELLBROWSER lpSB;
290 LPSHELLVIEW lpSV;
291 HWND hWndSV;
293 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
295 /* get the active IShellView */
296 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
298 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
300 IShellView_GetWindow(lpSV, &hWndSV);
304 if(lpSV)
306 if(HIWORD(lpcmi->lpVerb))
308 TRACE("%s\n",lpcmi->lpVerb);
310 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
312 if(lpSV) DoNewFolder(iface, lpSV);
314 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
316 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
318 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
320 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
322 else
324 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
327 else
329 switch(LOWORD(lpcmi->lpVerb))
331 case FCIDM_SHVIEW_NEWFOLDER:
332 DoNewFolder(iface, lpSV);
333 break;
334 case FCIDM_SHVIEW_INSERT:
335 DoPaste(iface);
336 break;
337 default:
338 /* if it's a id just pass it to the parent shv */
339 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
340 break;
344 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
346 return NOERROR;
349 /**************************************************************************
350 * ISVBgCm_fnGetCommandString()
353 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
354 IContextMenu *iface,
355 UINT idCommand,
356 UINT uFlags,
357 LPUINT lpReserved,
358 LPSTR lpszName,
359 UINT uMaxNameLen)
361 ICOM_THIS(BgCmImpl, iface);
363 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
365 /* test the existance of the menu items, the file dialog enables
366 the buttons according to this */
367 if (uFlags == GCS_VALIDATEA)
369 if(HIWORD(idCommand))
371 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
372 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
373 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
375 return NOERROR;
380 FIXME("unknown command string\n");
381 return E_FAIL;
384 /**************************************************************************
385 * ISVBgCm_fnHandleMenuMsg()
387 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
388 IContextMenu *iface,
389 UINT uMsg,
390 WPARAM wParam,
391 LPARAM lParam)
393 ICOM_THIS(BgCmImpl, iface);
395 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
397 return E_NOTIMPL;
400 /**************************************************************************
401 * IContextMenu VTable
404 static struct ICOM_VTABLE(IContextMenu) cmvt =
406 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
407 ISVBgCm_fnQueryInterface,
408 ISVBgCm_fnAddRef,
409 ISVBgCm_fnRelease,
410 ISVBgCm_fnQueryContextMenu,
411 ISVBgCm_fnInvokeCommand,
412 ISVBgCm_fnGetCommandString,
413 ISVBgCm_fnHandleMenuMsg,
414 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */