shell: Convert the filesystem shell folder to Unicode.
[wine/multimedia.git] / dlls / shell32 / shv_bg_cmenu.c
blob669d080156ec49125d30038c921598ebf2e95cf1
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 #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 "shlguid.h"
33 #include "shlobj.h"
35 #include "shell32_main.h"
36 #include "shellfolder.h"
37 #include "undocshell.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(shell);
41 /**************************************************************************
42 * IContextMenu Implementation
44 typedef struct
46 const IContextMenu2Vtbl *lpVtbl;
47 IShellFolder* pSFParent;
48 LONG ref;
49 BOOL bDesktop;
50 } BgCmImpl;
53 static const IContextMenu2Vtbl cmvt;
55 /**************************************************************************
56 * ISVBgCm_Constructor()
58 IContextMenu2 *ISvBgCm_Constructor(IShellFolder* pSFParent, BOOL bDesktop)
60 BgCmImpl* cm;
62 cm = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
63 cm->lpVtbl = &cmvt;
64 cm->ref = 1;
65 cm->pSFParent = pSFParent;
66 cm->bDesktop = bDesktop;
67 if(pSFParent) IShellFolder_AddRef(pSFParent);
69 TRACE("(%p)->()\n",cm);
70 return (IContextMenu2*)cm;
73 /**************************************************************************
74 * ISVBgCm_fnQueryInterface
76 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu2 *iface, REFIID riid, LPVOID *ppvObj)
78 BgCmImpl *This = (BgCmImpl *)iface;
80 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
82 *ppvObj = NULL;
84 if(IsEqualIID(riid, &IID_IUnknown) ||
85 IsEqualIID(riid, &IID_IContextMenu) ||
86 IsEqualIID(riid, &IID_IContextMenu2))
88 *ppvObj = This;
90 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
92 FIXME("-- LPSHELLEXTINIT pointer requested\n");
95 if(*ppvObj)
97 IUnknown_AddRef((IUnknown*)*ppvObj);
98 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
99 return S_OK;
101 TRACE("-- Interface: E_NOINTERFACE\n");
102 return E_NOINTERFACE;
105 /**************************************************************************
106 * ISVBgCm_fnAddRef
108 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu2 *iface)
110 BgCmImpl *This = (BgCmImpl *)iface;
111 ULONG refCount = InterlockedIncrement(&This->ref);
113 TRACE("(%p)->(count=%lu)\n", This, refCount - 1);
115 return refCount;
118 /**************************************************************************
119 * ISVBgCm_fnRelease
121 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu2 *iface)
123 BgCmImpl *This = (BgCmImpl *)iface;
124 ULONG refCount = InterlockedDecrement(&This->ref);
126 TRACE("(%p)->(count=%li)\n", This, refCount + 1);
128 if (!refCount)
130 TRACE(" destroying IContextMenu(%p)\n",This);
132 if(This->pSFParent)
133 IShellFolder_Release(This->pSFParent);
135 HeapFree(GetProcessHeap(),0,This);
137 return refCount;
140 /**************************************************************************
141 * ISVBgCm_fnQueryContextMenu()
144 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
145 IContextMenu2 *iface,
146 HMENU hMenu,
147 UINT indexMenu,
148 UINT idCmdFirst,
149 UINT idCmdLast,
150 UINT uFlags)
152 HMENU hMyMenu;
153 UINT idMax;
154 HRESULT hr;
156 BgCmImpl *This = (BgCmImpl *)iface;
158 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
159 This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
162 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
163 if (uFlags & CMF_DEFAULTONLY)
165 HMENU ourMenu = GetSubMenu(hMyMenu,0);
166 UINT oldDef = GetMenuDefaultItem(hMenu,TRUE,GMDI_USEDISABLED);
167 UINT newDef = GetMenuDefaultItem(ourMenu,TRUE,GMDI_USEDISABLED);
168 if (newDef != oldDef)
169 SetMenuDefaultItem(hMenu,newDef,TRUE);
170 if (newDef!=0xFFFFFFFF)
171 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, newDef+1);
172 else
173 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
175 else
177 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu,
178 idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
179 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst+1);
181 DestroyMenu(hMyMenu);
183 TRACE("(%p)->returning 0x%lx\n",This,hr);
184 return hr;
187 /**************************************************************************
188 * DoNewFolder
190 static void DoNewFolder(
191 IContextMenu2 *iface,
192 IShellView *psv)
194 BgCmImpl *This = (BgCmImpl *)iface;
195 ISFHelper * psfhlp;
196 char szName[MAX_PATH];
198 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlp);
199 if (psfhlp)
201 LPITEMIDLIST pidl;
202 ISFHelper_GetUniqueName(psfhlp, szName, MAX_PATH);
203 ISFHelper_AddFolder(psfhlp, 0, szName, &pidl);
205 if(psv)
207 /* if we are in a shellview do labeledit */
208 IShellView_SelectItem(psv,
209 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
210 |SVSI_FOCUSED|SVSI_SELECT));
212 SHFree(pidl);
214 ISFHelper_Release(psfhlp);
218 /**************************************************************************
219 * DoPaste
221 static BOOL DoPaste(
222 IContextMenu2 *iface)
224 BgCmImpl *This = (BgCmImpl *)iface;
225 BOOL bSuccess = FALSE;
226 IDataObject * pda;
228 TRACE("\n");
230 if(SUCCEEDED(OleGetClipboard(&pda)))
232 STGMEDIUM medium;
233 FORMATETC formatetc;
235 TRACE("pda=%p\n", pda);
237 /* Set the FORMATETC structure*/
238 InitFormatEtc(formatetc, RegisterClipboardFormatA(CFSTR_SHELLIDLIST), TYMED_HGLOBAL);
240 /* Get the pidls from IDataObject */
241 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
243 LPITEMIDLIST * apidl;
244 LPITEMIDLIST pidl;
245 IShellFolder *psfFrom = NULL, *psfDesktop;
247 LPIDA lpcida = GlobalLock(medium.u.hGlobal);
248 TRACE("cida=%p\n", lpcida);
250 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
252 /* bind to the source shellfolder */
253 SHGetDesktopFolder(&psfDesktop);
254 if(psfDesktop)
256 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
257 IShellFolder_Release(psfDesktop);
260 if (psfFrom)
262 /* get source and destination shellfolder */
263 ISFHelper *psfhlpdst, *psfhlpsrc;
264 IShellFolder_QueryInterface(This->pSFParent, &IID_ISFHelper, (LPVOID*)&psfhlpdst);
265 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (LPVOID*)&psfhlpsrc);
267 /* do the copy/move */
268 if (psfhlpdst && psfhlpsrc)
270 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, (LPCITEMIDLIST*)apidl);
271 /* FIXME handle move
272 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
275 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
276 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
277 IShellFolder_Release(psfFrom);
280 _ILFreeaPidl(apidl, lpcida->cidl);
281 SHFree(pidl);
283 /* release the medium*/
284 ReleaseStgMedium(&medium);
286 IDataObject_Release(pda);
288 #if 0
289 HGLOBAL hMem;
291 OpenClipboard(NULL);
292 hMem = GetClipboardData(CF_HDROP);
294 if(hMem)
296 char * pDropFiles = (char *)GlobalLock(hMem);
297 if(pDropFiles)
299 int len, offset = sizeof(DROPFILESTRUCT);
301 while( pDropFiles[offset] != 0)
303 len = strlen(pDropFiles + offset);
304 TRACE("%s\n", pDropFiles + offset);
305 offset += len+1;
308 GlobalUnlock(hMem);
310 CloseClipboard();
311 #endif
312 return bSuccess;
315 /**************************************************************************
316 * ISVBgCm_fnInvokeCommand()
318 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
319 IContextMenu2 *iface,
320 LPCMINVOKECOMMANDINFO lpcmi)
322 BgCmImpl *This = (BgCmImpl *)iface;
324 LPSHELLBROWSER lpSB;
325 LPSHELLVIEW lpSV = NULL;
326 HWND hWndSV = 0;
328 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
330 /* get the active IShellView */
331 if((lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0)))
333 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB, &lpSV)))
335 IShellView_GetWindow(lpSV, &hWndSV);
339 if(HIWORD(lpcmi->lpVerb))
341 TRACE("%s\n",lpcmi->lpVerb);
343 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
345 DoNewFolder(iface, lpSV);
347 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
349 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
351 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
353 if(hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
355 else
357 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
360 else
362 switch(LOWORD(lpcmi->lpVerb))
364 case FCIDM_SHVIEW_REFRESH:
365 if (lpSV) IShellView_Refresh(lpSV);
366 break;
368 case FCIDM_SHVIEW_NEWFOLDER:
369 DoNewFolder(iface, lpSV);
370 break;
372 case FCIDM_SHVIEW_INSERT:
373 DoPaste(iface);
374 break;
376 case FCIDM_SHVIEW_PROPERTIES:
377 if (This->bDesktop) {
378 ShellExecuteA(lpcmi->hwnd, "open", "rundll32.exe shell32.dll,Control_RunDLL desk.cpl", NULL, NULL, SW_SHOWNORMAL);
379 } else {
380 FIXME("launch item properties dialog\n");
382 break;
384 default:
385 /* if it's an id just pass it to the parent shv */
386 if (hWndSV) SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
387 break;
391 if (lpSV)
392 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef */
394 return NOERROR;
397 /**************************************************************************
398 * ISVBgCm_fnGetCommandString()
401 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
402 IContextMenu2 *iface,
403 UINT_PTR idCommand,
404 UINT uFlags,
405 UINT* lpReserved,
406 LPSTR lpszName,
407 UINT uMaxNameLen)
409 BgCmImpl *This = (BgCmImpl *)iface;
411 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
413 /* test the existence of the menu items, the file dialog enables
414 the buttons according to this */
415 if (uFlags == GCS_VALIDATEA)
417 if(HIWORD(idCommand))
419 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
420 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
421 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
423 return NOERROR;
428 FIXME("unknown command string\n");
429 return E_FAIL;
432 /**************************************************************************
433 * ISVBgCm_fnHandleMenuMsg()
435 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
436 IContextMenu2 *iface,
437 UINT uMsg,
438 WPARAM wParam,
439 LPARAM lParam)
441 BgCmImpl *This = (BgCmImpl *)iface;
443 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
445 return E_NOTIMPL;
448 /**************************************************************************
449 * IContextMenu2 VTable
452 static const IContextMenu2Vtbl cmvt =
454 ISVBgCm_fnQueryInterface,
455 ISVBgCm_fnAddRef,
456 ISVBgCm_fnRelease,
457 ISVBgCm_fnQueryContextMenu,
458 ISVBgCm_fnInvokeCommand,
459 ISVBgCm_fnGetCommandString,
460 ISVBgCm_fnHandleMenuMsg