d3dcompiler: Don't allow semantics on void functions.
[wine/multimedia.git] / dlls / shell32 / shlview_cmenu.c
blobb46820c1a1105d8e61621cd47c8c7e2457dd24f1
1 /*
2 * IContextMenu for items in the shellview
4 * Copyright 1998-2000 Juergen Schmied <juergen.schmied@debitel.net>,
5 * <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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include <string.h>
24 #define COBJMACROS
25 #define NONAMELESSUNION
26 #define NONAMELESSSTRUCT
28 #include "winerror.h"
29 #include "wine/debug.h"
31 #include "windef.h"
32 #include "wingdi.h"
33 #include "pidl.h"
34 #include "undocshell.h"
35 #include "shlobj.h"
36 #include "winreg.h"
37 #include "prsht.h"
39 #include "shell32_main.h"
40 #include "shellfolder.h"
42 #include "shresdef.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(shell);
46 typedef struct
48 IContextMenu3 IContextMenu3_iface;
49 LONG ref;
51 IShellFolder* parent;
52 UINT verb_offset;
54 /* item menu data */
55 LPITEMIDLIST pidl; /* root pidl */
56 LPITEMIDLIST *apidl; /* array of child pidls */
57 UINT cidl;
58 BOOL allvalues;
60 /* background menu data */
61 BOOL desktop;
62 } ContextMenu;
64 static inline ContextMenu *impl_from_IContextMenu3(IContextMenu3 *iface)
66 return CONTAINING_RECORD(iface, ContextMenu, IContextMenu3_iface);
69 static HRESULT WINAPI ContextMenu_QueryInterface(IContextMenu3 *iface, REFIID riid, LPVOID *ppvObj)
71 ContextMenu *This = impl_from_IContextMenu3(iface);
73 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObj);
75 *ppvObj = NULL;
77 if (IsEqualIID(riid, &IID_IUnknown) ||
78 IsEqualIID(riid, &IID_IContextMenu) ||
79 IsEqualIID(riid, &IID_IContextMenu2) ||
80 IsEqualIID(riid, &IID_IContextMenu3))
82 *ppvObj = This;
84 else if (IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
86 FIXME("-- LPSHELLEXTINIT pointer requested\n");
89 if(*ppvObj)
91 IContextMenu3_AddRef(iface);
92 return S_OK;
95 TRACE("-- Interface: E_NOINTERFACE\n");
96 return E_NOINTERFACE;
99 static ULONG WINAPI ContextMenu_AddRef(IContextMenu3 *iface)
101 ContextMenu *This = impl_from_IContextMenu3(iface);
102 ULONG ref = InterlockedIncrement(&This->ref);
103 TRACE("(%p)->(%u)\n", This, ref);
104 return ref;
107 static ULONG WINAPI ContextMenu_Release(IContextMenu3 *iface)
109 ContextMenu *This = impl_from_IContextMenu3(iface);
110 ULONG ref = InterlockedDecrement(&This->ref);
112 TRACE("(%p)->(%u)\n", This, ref);
114 if (!ref)
116 if(This->parent)
117 IShellFolder_Release(This->parent);
119 SHFree(This->pidl);
120 _ILFreeaPidl(This->apidl, This->cidl);
122 HeapFree(GetProcessHeap(), 0, This);
125 return ref;
128 static HRESULT WINAPI ItemMenu_QueryContextMenu(
129 IContextMenu3 *iface,
130 HMENU hmenu,
131 UINT indexMenu,
132 UINT idCmdFirst,
133 UINT idCmdLast,
134 UINT uFlags)
136 ContextMenu *This = impl_from_IContextMenu3(iface);
137 INT uIDMax;
139 TRACE("(%p)->(%p %d 0x%x 0x%x 0x%x )\n", This, hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
141 This->verb_offset = idCmdFirst;
143 if(!(CMF_DEFAULTONLY & uFlags) && This->cidl > 0)
145 HMENU hmenures = LoadMenuW(shell32_hInstance, MAKEINTRESOURCEW(MENU_SHV_FILE));
147 if(uFlags & CMF_EXPLORE)
148 RemoveMenu(hmenures, FCIDM_SHVIEW_OPEN, MF_BYCOMMAND);
150 uIDMax = Shell_MergeMenus(hmenu, GetSubMenu(hmenures, 0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
152 DestroyMenu(hmenures);
154 if(This->allvalues)
156 MENUITEMINFOW mi;
157 WCHAR str[255];
158 mi.cbSize = sizeof(mi);
159 mi.fMask = MIIM_ID | MIIM_STRING | MIIM_FTYPE;
160 mi.dwTypeData = str;
161 mi.cch = 255;
162 GetMenuItemInfoW(hmenu, FCIDM_SHVIEW_EXPLORE, MF_BYCOMMAND, &mi);
163 RemoveMenu(hmenu, FCIDM_SHVIEW_EXPLORE, MF_BYCOMMAND);
165 mi.cbSize = sizeof(mi);
166 mi.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
167 mi.dwTypeData = str;
168 mi.fState = MFS_ENABLED;
169 mi.wID = FCIDM_SHVIEW_EXPLORE;
170 mi.fType = MFT_STRING;
171 InsertMenuItemW(hmenu, (uFlags & CMF_EXPLORE) ? 1 : 2, MF_BYPOSITION, &mi);
174 SetMenuDefaultItem(hmenu, 0, MF_BYPOSITION);
176 if(uFlags & ~CMF_CANRENAME)
177 RemoveMenu(hmenu, FCIDM_SHVIEW_RENAME, MF_BYCOMMAND);
178 else
180 UINT enable = MF_BYCOMMAND;
182 /* can't rename more than one item at a time*/
183 if (!This->apidl || This->cidl > 1)
184 enable |= MFS_DISABLED;
185 else
187 DWORD attr = SFGAO_CANRENAME;
189 IShellFolder_GetAttributesOf(This->parent, 1, (LPCITEMIDLIST*)This->apidl, &attr);
190 enable |= (attr & SFGAO_CANRENAME) ? MFS_ENABLED : MFS_DISABLED;
193 EnableMenuItem(hmenu, FCIDM_SHVIEW_RENAME, enable);
196 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, uIDMax-idCmdFirst);
198 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
201 /**************************************************************************
202 * DoOpenExplore
204 * for folders only
207 static void DoOpenExplore(ContextMenu *This, HWND hwnd, LPCSTR verb)
209 UINT i, bFolderFound = FALSE;
210 LPITEMIDLIST pidlFQ;
211 SHELLEXECUTEINFOA sei;
213 /* Find the first item in the list that is not a value. These commands
214 should never be invoked if there isn't at least one folder item in the list.*/
216 for(i = 0; i<This->cidl; i++)
218 if(!_ILIsValue(This->apidl[i]))
220 bFolderFound = TRUE;
221 break;
225 if (!bFolderFound) return;
227 pidlFQ = ILCombine(This->pidl, This->apidl[i]);
229 ZeroMemory(&sei, sizeof(sei));
230 sei.cbSize = sizeof(sei);
231 sei.fMask = SEE_MASK_IDLIST | SEE_MASK_CLASSNAME;
232 sei.lpIDList = pidlFQ;
233 sei.lpClass = "Folder";
234 sei.hwnd = hwnd;
235 sei.nShow = SW_SHOWNORMAL;
236 sei.lpVerb = verb;
237 ShellExecuteExA(&sei);
238 SHFree(pidlFQ);
241 /**************************************************************************
242 * DoDelete
244 * deletes the currently selected items
246 static void DoDelete(ContextMenu *This)
248 ISFHelper *helper;
250 IShellFolder_QueryInterface(This->parent, &IID_ISFHelper, (void**)&helper);
251 if (helper)
253 ISFHelper_DeleteItems(helper, This->cidl, (LPCITEMIDLIST*)This->apidl);
254 ISFHelper_Release(helper);
258 /**************************************************************************
259 * DoCopyOrCut
261 * copies the currently selected items into the clipboard
263 static BOOL DoCopyOrCut(ContextMenu *This, HWND hwnd, BOOL cut)
265 IDataObject *dataobject;
266 IShellBrowser *browser;
267 IShellView *view;
269 TRACE("(%p)->(wnd=%p, cut=%d)\n", This, hwnd, cut);
271 /* get the active IShellView */
272 if ((browser = (IShellBrowser*)SendMessageA(hwnd, CWM_GETISHELLBROWSER, 0, 0)))
274 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(browser, &view)))
276 if (SUCCEEDED(IShellView_GetItemObject(view, SVGIO_SELECTION, &IID_IDataObject, (void**)&dataobject)))
278 OleSetClipboard(dataobject);
279 IDataObject_Release(dataobject);
281 IShellView_Release(view);
285 return TRUE;
288 /**************************************************************************
289 * Properties_AddPropSheetCallback
291 * Used by DoOpenProperties through SHCreatePropSheetExtArrayEx to add
292 * propertysheet pages from shell extensions.
294 static BOOL CALLBACK Properties_AddPropSheetCallback(HPROPSHEETPAGE hpage, LPARAM lparam)
296 LPPROPSHEETHEADERW psh = (LPPROPSHEETHEADERW) lparam;
297 psh->u3.phpage[psh->nPages++] = hpage;
299 return TRUE;
302 static void DoOpenProperties(ContextMenu *This, HWND hwnd)
304 static const UINT MAX_PROP_PAGES = 99;
305 static const WCHAR wszFolder[] = {'F','o','l','d','e','r', 0};
306 static const WCHAR wszFiletypeAll[] = {'*',0};
307 LPSHELLFOLDER lpDesktopSF;
308 LPSHELLFOLDER lpSF;
309 LPDATAOBJECT lpDo;
310 WCHAR wszFiletype[MAX_PATH];
311 WCHAR wszFilename[MAX_PATH];
312 PROPSHEETHEADERW psh;
313 HPROPSHEETPAGE hpages[MAX_PROP_PAGES];
314 HPSXA hpsxa;
315 UINT ret;
317 TRACE("(%p)->(wnd=%p)\n", This, hwnd);
319 ZeroMemory(&psh, sizeof(PROPSHEETHEADERW));
320 psh.dwSize = sizeof (PROPSHEETHEADERW);
321 psh.hwndParent = hwnd;
322 psh.dwFlags = PSH_PROPTITLE;
323 psh.nPages = 0;
324 psh.u3.phpage = hpages;
325 psh.u2.nStartPage = 0;
327 _ILSimpleGetTextW(This->apidl[0], (LPVOID)wszFilename, MAX_PATH);
328 psh.pszCaption = (LPCWSTR)wszFilename;
330 /* Find out where to look for the shell extensions */
331 if (_ILIsValue(This->apidl[0]))
333 char sTemp[64];
334 sTemp[0] = 0;
335 if (_ILGetExtension(This->apidl[0], sTemp, 64))
337 HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE);
338 MultiByteToWideChar(CP_ACP, 0, sTemp, -1, wszFiletype, MAX_PATH);
340 else
342 wszFiletype[0] = 0;
345 else if (_ILIsFolder(This->apidl[0]))
347 lstrcpynW(wszFiletype, wszFolder, 64);
349 else if (_ILIsSpecialFolder(This->apidl[0]))
351 LPGUID folderGUID;
352 static const WCHAR wszclsid[] = {'C','L','S','I','D','\\', 0};
353 folderGUID = _ILGetGUIDPointer(This->apidl[0]);
354 lstrcpyW(wszFiletype, wszclsid);
355 StringFromGUID2(folderGUID, &wszFiletype[6], MAX_PATH - 6);
357 else
359 FIXME("Requested properties for unknown type.\n");
360 return;
363 /* Get a suitable DataObject for accessing the files */
364 SHGetDesktopFolder(&lpDesktopSF);
365 if (_ILIsPidlSimple(This->pidl))
367 ret = IShellFolder_GetUIObjectOf(lpDesktopSF, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl,
368 &IID_IDataObject, NULL, (LPVOID *)&lpDo);
369 IShellFolder_Release(lpDesktopSF);
371 else
373 IShellFolder_BindToObject(lpDesktopSF, This->pidl, NULL, &IID_IShellFolder, (LPVOID*) &lpSF);
374 ret = IShellFolder_GetUIObjectOf(lpSF, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl,
375 &IID_IDataObject, NULL, (LPVOID *)&lpDo);
376 IShellFolder_Release(lpSF);
377 IShellFolder_Release(lpDesktopSF);
380 if (SUCCEEDED(ret))
382 hpsxa = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszFiletype, MAX_PROP_PAGES - psh.nPages, lpDo);
383 if (hpsxa != NULL)
385 SHAddFromPropSheetExtArray(hpsxa, Properties_AddPropSheetCallback, (LPARAM)&psh);
386 SHDestroyPropSheetExtArray(hpsxa);
388 hpsxa = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszFiletypeAll, MAX_PROP_PAGES - psh.nPages, lpDo);
389 if (hpsxa != NULL)
391 SHAddFromPropSheetExtArray(hpsxa, Properties_AddPropSheetCallback, (LPARAM)&psh);
392 SHDestroyPropSheetExtArray(hpsxa);
394 IDataObject_Release(lpDo);
397 if (psh.nPages)
398 PropertySheetW(&psh);
399 else
400 FIXME("No property pages found.\n");
403 static HRESULT WINAPI ItemMenu_InvokeCommand(
404 IContextMenu3 *iface,
405 LPCMINVOKECOMMANDINFO lpcmi)
407 ContextMenu *This = impl_from_IContextMenu3(iface);
409 if (lpcmi->cbSize != sizeof(CMINVOKECOMMANDINFO))
410 FIXME("Is an EX structure\n");
412 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
414 if( HIWORD(lpcmi->lpVerb)==0 && LOWORD(lpcmi->lpVerb) > FCIDM_SHVIEWLAST)
416 TRACE("Invalid Verb %x\n",LOWORD(lpcmi->lpVerb));
417 return E_INVALIDARG;
420 if (HIWORD(lpcmi->lpVerb) == 0)
422 switch(LOWORD(lpcmi->lpVerb - This->verb_offset))
424 case FCIDM_SHVIEW_EXPLORE:
425 TRACE("Verb FCIDM_SHVIEW_EXPLORE\n");
426 DoOpenExplore(This, lpcmi->hwnd, "explore");
427 break;
428 case FCIDM_SHVIEW_OPEN:
429 TRACE("Verb FCIDM_SHVIEW_OPEN\n");
430 DoOpenExplore(This, lpcmi->hwnd, "open");
431 break;
432 case FCIDM_SHVIEW_RENAME:
434 IShellBrowser *browser;
436 /* get the active IShellView */
437 browser = (IShellBrowser*)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER, 0, 0);
438 if (browser)
440 IShellView *view;
442 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(browser, &view)))
444 TRACE("(shellview=%p)\n", view);
445 IShellView_SelectItem(view, This->apidl[0],
446 SVSI_DESELECTOTHERS|SVSI_EDIT|SVSI_ENSUREVISIBLE|SVSI_FOCUSED|SVSI_SELECT);
447 IShellView_Release(view);
450 break;
452 case FCIDM_SHVIEW_DELETE:
453 TRACE("Verb FCIDM_SHVIEW_DELETE\n");
454 DoDelete(This);
455 break;
456 case FCIDM_SHVIEW_COPY:
457 TRACE("Verb FCIDM_SHVIEW_COPY\n");
458 DoCopyOrCut(This, lpcmi->hwnd, FALSE);
459 break;
460 case FCIDM_SHVIEW_CUT:
461 TRACE("Verb FCIDM_SHVIEW_CUT\n");
462 DoCopyOrCut(This, lpcmi->hwnd, TRUE);
463 break;
464 case FCIDM_SHVIEW_PROPERTIES:
465 TRACE("Verb FCIDM_SHVIEW_PROPERTIES\n");
466 DoOpenProperties(This, lpcmi->hwnd);
467 break;
468 default:
469 FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi->lpVerb)-This->verb_offset);
470 return E_INVALIDARG;
473 else
475 TRACE("Verb is %s\n",debugstr_a(lpcmi->lpVerb));
476 if (strcmp(lpcmi->lpVerb,"delete")==0)
477 DoDelete(This);
478 else if (strcmp(lpcmi->lpVerb,"properties")==0)
479 DoOpenProperties(This, lpcmi->hwnd);
480 else {
481 FIXME("Unhandled string verb %s\n",debugstr_a(lpcmi->lpVerb));
482 return E_FAIL;
485 return S_OK;
488 static HRESULT WINAPI ItemMenu_GetCommandString(
489 IContextMenu3 *iface,
490 UINT_PTR idCommand,
491 UINT uFlags,
492 UINT* lpReserved,
493 LPSTR lpszName,
494 UINT uMaxNameLen)
496 ContextMenu *This = impl_from_IContextMenu3(iface);
497 HRESULT hr = E_INVALIDARG;
499 TRACE("(%p)->(%lx flags=%x %p name=%p len=%x)\n", This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
501 switch(uFlags)
503 case GCS_HELPTEXTA:
504 case GCS_HELPTEXTW:
505 hr = E_NOTIMPL;
506 break;
508 case GCS_VERBA:
509 switch(idCommand-This->verb_offset)
511 case FCIDM_SHVIEW_RENAME:
512 strcpy(lpszName, "rename");
513 hr = S_OK;
514 break;
516 break;
518 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
519 case, you need to do the lstrcpyW to the pointer passed.*/
520 case GCS_VERBW:
521 switch(idCommand-This->verb_offset)
523 case FCIDM_SHVIEW_RENAME:
524 MultiByteToWideChar( CP_ACP, 0, "rename", -1, (LPWSTR)lpszName, uMaxNameLen );
525 hr = S_OK;
526 break;
528 break;
530 case GCS_VALIDATEA:
531 case GCS_VALIDATEW:
532 hr = S_OK;
533 break;
535 TRACE("-- (%p)->(name=%s)\n", This, lpszName);
536 return hr;
539 /**************************************************************************
540 * NOTES
541 * should be only in IContextMenu2 and IContextMenu3
542 * is nevertheless called from word95
544 static HRESULT WINAPI ContextMenu_HandleMenuMsg(IContextMenu3 *iface, UINT msg,
545 WPARAM wParam, LPARAM lParam)
547 ContextMenu *This = impl_from_IContextMenu3(iface);
548 FIXME("(%p)->(0x%x 0x%lx 0x%lx): stub\n", This, msg, wParam, lParam);
549 return E_NOTIMPL;
552 static HRESULT WINAPI ContextMenu_HandleMenuMsg2(IContextMenu3 *iface, UINT msg,
553 WPARAM wParam, LPARAM lParam, LRESULT *result)
555 ContextMenu *This = impl_from_IContextMenu3(iface);
556 FIXME("(%p)->(0x%x 0x%lx 0x%lx %p): stub\n", This, msg, wParam, lParam, result);
557 return E_NOTIMPL;
560 static const IContextMenu3Vtbl ItemContextMenuVtbl =
562 ContextMenu_QueryInterface,
563 ContextMenu_AddRef,
564 ContextMenu_Release,
565 ItemMenu_QueryContextMenu,
566 ItemMenu_InvokeCommand,
567 ItemMenu_GetCommandString,
568 ContextMenu_HandleMenuMsg,
569 ContextMenu_HandleMenuMsg2
572 HRESULT ItemMenu_Constructor(IShellFolder *parent, LPCITEMIDLIST pidl, const LPCITEMIDLIST *apidl, UINT cidl,
573 REFIID riid, void **pObj)
575 ContextMenu* This;
576 HRESULT hr;
577 int i;
579 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
580 if (!This) return E_OUTOFMEMORY;
582 This->IContextMenu3_iface.lpVtbl = &ItemContextMenuVtbl;
583 This->ref = 1;
584 This->verb_offset = 0;
585 This->parent = parent;
586 if (parent) IShellFolder_AddRef(parent);
588 This->pidl = ILClone(pidl);
589 This->apidl = _ILCopyaPidl(apidl, cidl);
590 This->cidl = cidl;
591 This->allvalues = TRUE;
593 This->desktop = FALSE;
595 for (i = 0; i < cidl; i++)
596 This->allvalues &= (_ILIsValue(apidl[i]) ? 1 : 0);
598 hr = IContextMenu3_QueryInterface(&This->IContextMenu3_iface, riid, pObj);
599 IContextMenu3_Release(&This->IContextMenu3_iface);
601 return hr;
604 /* Background menu implementation */
605 static HRESULT WINAPI BackgroundMenu_QueryContextMenu(
606 IContextMenu3 *iface,
607 HMENU hMenu,
608 UINT indexMenu,
609 UINT idCmdFirst,
610 UINT idCmdLast,
611 UINT uFlags)
613 ContextMenu *This = impl_from_IContextMenu3(iface);
614 HMENU hMyMenu;
615 UINT idMax;
616 HRESULT hr;
618 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
619 This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
621 This->verb_offset = idCmdFirst;
623 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
624 if (uFlags & CMF_DEFAULTONLY)
626 HMENU ourMenu = GetSubMenu(hMyMenu,0);
627 UINT oldDef = GetMenuDefaultItem(hMenu,TRUE,GMDI_USEDISABLED);
628 UINT newDef = GetMenuDefaultItem(ourMenu,TRUE,GMDI_USEDISABLED);
629 if (newDef != oldDef)
630 SetMenuDefaultItem(hMenu,newDef,TRUE);
631 if (newDef!=0xFFFFFFFF)
632 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, newDef+1);
633 else
634 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
636 else
638 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu,
639 idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
640 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst);
642 DestroyMenu(hMyMenu);
644 TRACE("(%p)->returning 0x%x\n",This,hr);
645 return hr;
648 static void DoNewFolder(ContextMenu *This, IShellView *view)
650 ISFHelper *helper;
652 IShellFolder_QueryInterface(This->parent, &IID_ISFHelper, (void**)&helper);
653 if (helper)
655 WCHAR nameW[MAX_PATH];
656 LPITEMIDLIST pidl;
658 ISFHelper_GetUniqueName(helper, nameW, MAX_PATH);
659 ISFHelper_AddFolder(helper, 0, nameW, &pidl);
661 if (view)
663 /* if we are in a shellview do labeledit */
664 IShellView_SelectItem(view,
665 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
666 |SVSI_FOCUSED|SVSI_SELECT));
669 SHFree(pidl);
670 ISFHelper_Release(helper);
674 static BOOL DoPaste(ContextMenu *This)
676 BOOL bSuccess = FALSE;
677 IDataObject * pda;
679 TRACE("\n");
681 if(SUCCEEDED(OleGetClipboard(&pda)))
683 STGMEDIUM medium;
684 FORMATETC formatetc;
686 TRACE("pda=%p\n", pda);
688 /* Set the FORMATETC structure*/
689 InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLISTW), TYMED_HGLOBAL);
691 /* Get the pidls from IDataObject */
692 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
694 LPITEMIDLIST * apidl;
695 LPITEMIDLIST pidl;
696 IShellFolder *psfFrom = NULL, *psfDesktop;
698 LPIDA lpcida = GlobalLock(medium.u.hGlobal);
699 TRACE("cida=%p\n", lpcida);
701 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
703 /* bind to the source shellfolder */
704 SHGetDesktopFolder(&psfDesktop);
705 if(psfDesktop)
707 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
708 IShellFolder_Release(psfDesktop);
711 if (psfFrom)
713 /* get source and destination shellfolder */
714 ISFHelper *psfhlpdst, *psfhlpsrc;
715 IShellFolder_QueryInterface(This->parent, &IID_ISFHelper, (void**)&psfhlpdst);
716 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (void**)&psfhlpsrc);
718 /* do the copy/move */
719 if (psfhlpdst && psfhlpsrc)
721 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, (LPCITEMIDLIST*)apidl);
722 /* FIXME handle move
723 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
726 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
727 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
728 IShellFolder_Release(psfFrom);
731 _ILFreeaPidl(apidl, lpcida->cidl);
732 SHFree(pidl);
734 /* release the medium*/
735 ReleaseStgMedium(&medium);
737 IDataObject_Release(pda);
739 #if 0
740 HGLOBAL hMem;
742 OpenClipboard(NULL);
743 hMem = GetClipboardData(CF_HDROP);
745 if(hMem)
747 char * pDropFiles = GlobalLock(hMem);
748 if(pDropFiles)
750 int len, offset = sizeof(DROPFILESTRUCT);
752 while( pDropFiles[offset] != 0)
754 len = strlen(pDropFiles + offset);
755 TRACE("%s\n", pDropFiles + offset);
756 offset += len+1;
759 GlobalUnlock(hMem);
761 CloseClipboard();
762 #endif
763 return bSuccess;
766 static HRESULT WINAPI BackgroundMenu_InvokeCommand(
767 IContextMenu3 *iface,
768 LPCMINVOKECOMMANDINFO lpcmi)
770 ContextMenu *This = impl_from_IContextMenu3(iface);
771 IShellBrowser *browser;
772 IShellView *view = NULL;
773 HWND hWnd = NULL;
775 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n", This, lpcmi, lpcmi->lpVerb, lpcmi->hwnd);
777 /* get the active IShellView */
778 if ((browser = (IShellBrowser*)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER, 0, 0)))
780 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(browser, &view)))
781 IShellView_GetWindow(view, &hWnd);
784 if(HIWORD(lpcmi->lpVerb))
786 TRACE("%s\n", debugstr_a(lpcmi->lpVerb));
788 if (!strcmp(lpcmi->lpVerb, CMDSTR_NEWFOLDERA))
790 DoNewFolder(This, view);
792 else if (!strcmp(lpcmi->lpVerb, CMDSTR_VIEWLISTA))
794 if (hWnd) SendMessageA(hWnd, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW, 0), 0);
796 else if (!strcmp(lpcmi->lpVerb, CMDSTR_VIEWDETAILSA))
798 if (hWnd) SendMessageA(hWnd, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW, 0), 0);
800 else
802 FIXME("please report: unknown verb %s\n", debugstr_a(lpcmi->lpVerb));
805 else
807 switch (LOWORD(lpcmi->lpVerb) - This->verb_offset)
809 case FCIDM_SHVIEW_REFRESH:
810 if (view) IShellView_Refresh(view);
811 break;
813 case FCIDM_SHVIEW_NEWFOLDER:
814 DoNewFolder(This, view);
815 break;
817 case FCIDM_SHVIEW_INSERT:
818 DoPaste(This);
819 break;
821 case FCIDM_SHVIEW_PROPERTIES:
822 if (This->desktop) {
823 ShellExecuteA(lpcmi->hwnd, "open", "rundll32.exe shell32.dll,Control_RunDLL desk.cpl", NULL, NULL, SW_SHOWNORMAL);
824 } else {
825 FIXME("launch item properties dialog\n");
827 break;
829 default:
830 /* if it's an id just pass it to the parent shv */
831 if (hWnd) SendMessageA(hWnd, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0), 0);
832 break;
836 if (view)
837 IShellView_Release(view);
839 return S_OK;
842 static HRESULT WINAPI BackgroundMenu_GetCommandString(
843 IContextMenu3 *iface,
844 UINT_PTR idCommand,
845 UINT uFlags,
846 UINT* lpReserved,
847 LPSTR lpszName,
848 UINT uMaxNameLen)
850 ContextMenu *This = impl_from_IContextMenu3(iface);
852 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
854 /* test the existence of the menu items, the file dialog enables
855 the buttons according to this */
856 if (uFlags == GCS_VALIDATEA)
858 if(HIWORD(idCommand))
860 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
861 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
862 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
864 return S_OK;
869 FIXME("unknown command string\n");
870 return E_FAIL;
873 static const IContextMenu3Vtbl BackgroundContextMenuVtbl =
875 ContextMenu_QueryInterface,
876 ContextMenu_AddRef,
877 ContextMenu_Release,
878 BackgroundMenu_QueryContextMenu,
879 BackgroundMenu_InvokeCommand,
880 BackgroundMenu_GetCommandString,
881 ContextMenu_HandleMenuMsg,
882 ContextMenu_HandleMenuMsg2
885 HRESULT BackgroundMenu_Constructor(IShellFolder *parent, BOOL desktop, REFIID riid, void **pObj)
887 ContextMenu *This;
888 HRESULT hr;
890 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
891 if (!This) return E_OUTOFMEMORY;
893 This->IContextMenu3_iface.lpVtbl = &BackgroundContextMenuVtbl;
894 This->ref = 1;
895 This->parent = parent;
896 This->verb_offset = 0;
898 This->pidl = NULL;
899 This->apidl = NULL;
900 This->cidl = 0;
901 This->allvalues = FALSE;
903 This->desktop = desktop;
904 if (parent) IShellFolder_AddRef(parent);
906 hr = IContextMenu3_QueryInterface(&This->IContextMenu3_iface, riid, pObj);
907 IContextMenu3_Release(&This->IContextMenu3_iface);
909 return hr;