Merged the two serializer and unserializer functions into one, cleaned
[wine.git] / dlls / shell32 / shv_bg_cmenu.c
blob9cd9e7315a629fece60413d6a96ad2b48c723c1a
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 "wine/obj_base.h"
28 #include "wine/obj_contextmenu.h"
29 #include "wine/obj_shellbrowser.h"
31 #include "shell32_main.h"
32 #include "shellfolder.h"
33 #include "undocshell.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(shell);
37 /**************************************************************************
38 * IContextMenu Implementation
40 typedef struct
42 ICOM_VFIELD(IContextMenu);
43 IShellFolder* pSFParent;
44 DWORD ref;
45 } BgCmImpl;
48 static struct ICOM_VTABLE(IContextMenu) cmvt;
50 /**************************************************************************
51 * ISVBgCm_Constructor()
53 IContextMenu *ISvBgCm_Constructor(IShellFolder* pSFParent)
55 BgCmImpl* cm;
57 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
58 ICOM_VTBL(cm)=&cmvt;
59 cm->ref = 1;
60 cm->pSFParent = pSFParent;
61 if(pSFParent) IShellFolder_AddRef(pSFParent);
63 TRACE("(%p)->()\n",cm);
64 shell32_ObjCount++;
65 return (IContextMenu*)cm;
68 /**************************************************************************
69 * ISVBgCm_fnQueryInterface
71 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
73 ICOM_THIS(BgCmImpl, iface);
75 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
77 *ppvObj = NULL;
79 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
81 *ppvObj = This;
83 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
85 *ppvObj = This;
87 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
89 FIXME("-- LPSHELLEXTINIT pointer requested\n");
92 if(*ppvObj)
94 IUnknown_AddRef((IUnknown*)*ppvObj);
95 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
96 return S_OK;
98 TRACE("-- Interface: E_NOINTERFACE\n");
99 return E_NOINTERFACE;
102 /**************************************************************************
103 * ISVBgCm_fnAddRef
105 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
107 ICOM_THIS(BgCmImpl, iface);
109 TRACE("(%p)->(count=%lu)\n",This, This->ref);
111 shell32_ObjCount++;
112 return ++(This->ref);
115 /**************************************************************************
116 * ISVBgCm_fnRelease
118 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
120 ICOM_THIS(BgCmImpl, iface);
122 TRACE("(%p)->()\n",This);
124 if (!--(This->ref))
126 TRACE(" destroying IContextMenu(%p)\n",This);
128 if(This->pSFParent)
129 IShellFolder_Release(This->pSFParent);
131 HeapFree(GetProcessHeap(),0,This);
132 return 0;
135 shell32_ObjCount--;
137 return This->ref;
140 /**************************************************************************
141 * ISVBgCm_fnQueryContextMenu()
144 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
145 IContextMenu *iface,
146 HMENU hMenu,
147 UINT indexMenu,
148 UINT idCmdFirst,
149 UINT idCmdLast,
150 UINT uFlags)
152 HMENU hMyMenu;
153 UINT idMax;
155 ICOM_THIS(BgCmImpl, iface);
157 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
159 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
161 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
163 DestroyMenu(hMyMenu);
165 return ResultFromShort(idMax - idCmdFirst);
168 /**************************************************************************
169 * DoNewFolder
171 static void DoNewFolder(
172 IContextMenu *iface,
173 IShellView *psv)
175 ICOM_THIS(BgCmImpl, iface);
176 ISFHelper * psfhlp;
177 char szName[MAX_PATH];
179 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
180 if (psfhlp)
182 LPITEMIDLIST pidl;
183 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
184 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
186 if(psv)
188 /* if we are in a shellview do labeledit */
189 IShellView_SelectItem(psv,
190 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
191 |SVSI_FOCUSED|SVSI_SELECT));
193 SHFree(pidl);
195 ISFHelper_Release(psfhlp);
199 /**************************************************************************
200 * DoPaste
202 static BOOL DoPaste(
203 IContextMenu *iface)
205 ICOM_THIS(BgCmImpl, iface);
206 BOOL bSuccess = FALSE;
207 IDataObject * pda;
209 TRACE("\n");
211 if(SUCCEEDED(pOleGetClipboard(&pda)))
213 STGMEDIUM medium;
214 FORMATETC formatetc;
216 TRACE("pda=%p\n", pda);
218 /* Set the FORMATETC structure*/
219 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
221 /* Get the pidls from IDataObject */
222 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
224 LPITEMIDLIST * apidl;
225 LPITEMIDLIST pidl;
226 IShellFolder *psfFrom = NULL, *psfDesktop;
228 LPCIDA lpcida = GlobalLock(medium.u.hGlobal);
229 TRACE("cida=%p\n", lpcida);
231 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
233 /* bind to the source shellfolder */
234 SHGetDesktopFolder(&psfDesktop);
235 if(psfDesktop)
237 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
238 IShellFolder_Release(psfDesktop);
241 if (psfFrom)
243 /* get source and destination shellfolder */
244 ISFHelper *psfhlpdst, *psfhlpsrc;
245 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
246 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
248 /* do the copy/move */
249 if (psfhlpdst && psfhlpsrc)
251 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, apidl);
252 /* FIXME handle move
253 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
256 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
257 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
258 IShellFolder_Release(psfFrom);
261 _ILFreeaPidl(apidl, lpcida->cidl);
262 SHFree(pidl);
264 /* release the medium*/
265 pReleaseStgMedium(&medium);
267 IDataObject_Release(pda);
269 #if 0
270 HGLOBAL hMem;
272 OpenClipboard(NULL);
273 hMem = GetClipboardData(CF_HDROP);
275 if(hMem)
277 char * pDropFiles = (char *)GlobalLock(hMem);
278 if(pDropFiles)
280 int len, offset = sizeof(DROPFILESTRUCT);
282 while( pDropFiles[offset] != 0)
284 len = strlen(pDropFiles + offset);
285 TRACE("%s\n", pDropFiles + offset);
286 offset += len+1;
289 GlobalUnlock(hMem);
291 CloseClipboard();
292 #endif
293 return bSuccess;
295 /**************************************************************************
296 * ISVBgCm_fnInvokeCommand()
298 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
299 IContextMenu *iface,
300 LPCMINVOKECOMMANDINFO lpcmi)
302 ICOM_THIS(BgCmImpl, iface);
304 LPSHELLBROWSER lpSB;
305 LPSHELLVIEW lpSV;
306 HWND hWndSV;
308 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
310 /* get the active IShellView */
311 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
313 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
315 IShellView_GetWindow(lpSV, &hWndSV);
319 if(lpSV)
321 if(HIWORD(lpcmi->lpVerb))
323 TRACE("%s\n",lpcmi->lpVerb);
325 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
327 if(lpSV) DoNewFolder(iface, lpSV);
329 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
331 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
333 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
335 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
337 else
339 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
342 else
344 switch(LOWORD(lpcmi->lpVerb))
346 case FCIDM_SHVIEW_NEWFOLDER:
347 DoNewFolder(iface, lpSV);
348 break;
349 case FCIDM_SHVIEW_INSERT:
350 DoPaste(iface);
351 break;
352 default:
353 /* if it's a id just pass it to the parent shv */
354 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
355 break;
359 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
361 return NOERROR;
364 /**************************************************************************
365 * ISVBgCm_fnGetCommandString()
368 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
369 IContextMenu *iface,
370 UINT idCommand,
371 UINT uFlags,
372 LPUINT lpReserved,
373 LPSTR lpszName,
374 UINT uMaxNameLen)
376 ICOM_THIS(BgCmImpl, iface);
378 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
380 /* test the existence of the menu items, the file dialog enables
381 the buttons according to this */
382 if (uFlags == GCS_VALIDATEA)
384 if(HIWORD(idCommand))
386 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
387 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
388 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
390 return NOERROR;
395 FIXME("unknown command string\n");
396 return E_FAIL;
399 /**************************************************************************
400 * ISVBgCm_fnHandleMenuMsg()
402 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
403 IContextMenu *iface,
404 UINT uMsg,
405 WPARAM wParam,
406 LPARAM lParam)
408 ICOM_THIS(BgCmImpl, iface);
410 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
412 return E_NOTIMPL;
415 /**************************************************************************
416 * IContextMenu VTable
419 static struct ICOM_VTABLE(IContextMenu) cmvt =
421 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
422 ISVBgCm_fnQueryInterface,
423 ISVBgCm_fnAddRef,
424 ISVBgCm_fnRelease,
425 ISVBgCm_fnQueryContextMenu,
426 ISVBgCm_fnInvokeCommand,
427 ISVBgCm_fnGetCommandString,
428 ISVBgCm_fnHandleMenuMsg,
429 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */