wined3d: Implement multisample resolve for typed resources.
[wine.git] / dlls / shell32 / shlview_cmenu.c
blob3f09413f612e09591411b62e12cb2342bab39b39
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
27 #include "winerror.h"
28 #include "wine/debug.h"
30 #include "windef.h"
31 #include "wingdi.h"
32 #include "pidl.h"
33 #include "undocshell.h"
34 #include "shlobj.h"
35 #include "winreg.h"
36 #include "prsht.h"
38 #include "shell32_main.h"
39 #include "shellfolder.h"
41 #include "shresdef.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(shell);
45 typedef struct
47 IContextMenu3 IContextMenu3_iface;
48 LONG ref;
50 IShellFolder* parent;
52 /* item menu data */
53 LPITEMIDLIST pidl; /* root pidl */
54 LPITEMIDLIST *apidl; /* array of child pidls */
55 UINT cidl;
56 BOOL allvalues;
58 /* background menu data */
59 BOOL desktop;
60 } ContextMenu;
62 static inline ContextMenu *impl_from_IContextMenu3(IContextMenu3 *iface)
64 return CONTAINING_RECORD(iface, ContextMenu, IContextMenu3_iface);
67 static HRESULT WINAPI ContextMenu_QueryInterface(IContextMenu3 *iface, REFIID riid, LPVOID *ppvObj)
69 ContextMenu *This = impl_from_IContextMenu3(iface);
71 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppvObj);
73 *ppvObj = NULL;
75 if (IsEqualIID(riid, &IID_IUnknown) ||
76 IsEqualIID(riid, &IID_IContextMenu) ||
77 IsEqualIID(riid, &IID_IContextMenu2) ||
78 IsEqualIID(riid, &IID_IContextMenu3))
80 *ppvObj = &This->IContextMenu3_iface;
82 else if (IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
84 FIXME("-- LPSHELLEXTINIT pointer requested\n");
87 if(*ppvObj)
89 IContextMenu3_AddRef(iface);
90 return S_OK;
93 TRACE("-- Interface: E_NOINTERFACE\n");
94 return E_NOINTERFACE;
97 static ULONG WINAPI ContextMenu_AddRef(IContextMenu3 *iface)
99 ContextMenu *This = impl_from_IContextMenu3(iface);
100 ULONG ref = InterlockedIncrement(&This->ref);
101 TRACE("(%p)->(%u)\n", This, ref);
102 return ref;
105 static ULONG WINAPI ContextMenu_Release(IContextMenu3 *iface)
107 ContextMenu *This = impl_from_IContextMenu3(iface);
108 ULONG ref = InterlockedDecrement(&This->ref);
110 TRACE("(%p)->(%u)\n", This, ref);
112 if (!ref)
114 if(This->parent)
115 IShellFolder_Release(This->parent);
117 SHFree(This->pidl);
118 _ILFreeaPidl(This->apidl, This->cidl);
120 HeapFree(GetProcessHeap(), 0, This);
123 return ref;
126 static HRESULT WINAPI ItemMenu_QueryContextMenu(
127 IContextMenu3 *iface,
128 HMENU hmenu,
129 UINT indexMenu,
130 UINT idCmdFirst,
131 UINT idCmdLast,
132 UINT uFlags)
134 ContextMenu *This = impl_from_IContextMenu3(iface);
135 INT uIDMax;
137 TRACE("(%p)->(%p %d 0x%x 0x%x 0x%x )\n", This, hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
139 if(!(CMF_DEFAULTONLY & uFlags) && This->cidl > 0)
141 HMENU hmenures = LoadMenuW(shell32_hInstance, MAKEINTRESOURCEW(MENU_SHV_FILE));
143 if(uFlags & CMF_EXPLORE)
144 RemoveMenu(hmenures, FCIDM_SHVIEW_OPEN, MF_BYCOMMAND);
146 uIDMax = Shell_MergeMenus(hmenu, GetSubMenu(hmenures, 0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
148 DestroyMenu(hmenures);
150 if(This->allvalues)
152 MENUITEMINFOW mi;
153 WCHAR str[255];
154 mi.cbSize = sizeof(mi);
155 mi.fMask = MIIM_ID | MIIM_STRING | MIIM_FTYPE;
156 mi.dwTypeData = str;
157 mi.cch = 255;
158 GetMenuItemInfoW(hmenu, FCIDM_SHVIEW_EXPLORE, MF_BYCOMMAND, &mi);
159 RemoveMenu(hmenu, FCIDM_SHVIEW_EXPLORE + idCmdFirst, MF_BYCOMMAND);
161 mi.cbSize = sizeof(mi);
162 mi.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE | MIIM_STRING;
163 mi.dwTypeData = str;
164 mi.fState = MFS_ENABLED;
165 mi.wID = FCIDM_SHVIEW_EXPLORE;
166 mi.fType = MFT_STRING;
167 InsertMenuItemW(hmenu, (uFlags & CMF_EXPLORE) ? 1 : 2, MF_BYPOSITION, &mi);
170 SetMenuDefaultItem(hmenu, 0, MF_BYPOSITION);
172 if(uFlags & ~CMF_CANRENAME)
173 RemoveMenu(hmenu, FCIDM_SHVIEW_RENAME, MF_BYCOMMAND);
174 else
176 UINT enable = MF_BYCOMMAND;
178 /* can't rename more than one item at a time*/
179 if (!This->apidl || This->cidl > 1)
180 enable |= MFS_DISABLED;
181 else
183 DWORD attr = SFGAO_CANRENAME;
185 IShellFolder_GetAttributesOf(This->parent, 1, (LPCITEMIDLIST*)This->apidl, &attr);
186 enable |= (attr & SFGAO_CANRENAME) ? MFS_ENABLED : MFS_DISABLED;
189 EnableMenuItem(hmenu, FCIDM_SHVIEW_RENAME, enable);
192 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, uIDMax-idCmdFirst);
194 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
197 /**************************************************************************
198 * DoOpenExplore
200 * for folders only
203 static void DoOpenExplore(ContextMenu *This, HWND hwnd, LPCSTR verb)
205 UINT i;
206 BOOL bFolderFound = FALSE;
207 LPITEMIDLIST pidlFQ;
208 SHELLEXECUTEINFOA sei;
210 /* Find the first item in the list that is not a value. These commands
211 should never be invoked if there isn't at least one folder item in the list.*/
213 for(i = 0; i<This->cidl; i++)
215 if(!_ILIsValue(This->apidl[i]))
217 bFolderFound = TRUE;
218 break;
222 if (!bFolderFound) return;
224 pidlFQ = ILCombine(This->pidl, This->apidl[i]);
226 ZeroMemory(&sei, sizeof(sei));
227 sei.cbSize = sizeof(sei);
228 sei.fMask = SEE_MASK_IDLIST | SEE_MASK_CLASSNAME;
229 sei.lpIDList = pidlFQ;
230 sei.lpClass = "Folder";
231 sei.hwnd = hwnd;
232 sei.nShow = SW_SHOWNORMAL;
233 sei.lpVerb = verb;
234 ShellExecuteExA(&sei);
235 SHFree(pidlFQ);
238 /**************************************************************************
239 * DoDelete
241 * deletes the currently selected items
243 static void DoDelete(ContextMenu *This)
245 ISFHelper *helper;
247 IShellFolder_QueryInterface(This->parent, &IID_ISFHelper, (void**)&helper);
248 if (helper)
250 ISFHelper_DeleteItems(helper, This->cidl, (LPCITEMIDLIST*)This->apidl);
251 ISFHelper_Release(helper);
255 /**************************************************************************
256 * DoCopyOrCut
258 * copies the currently selected items into the clipboard
260 static void DoCopyOrCut(ContextMenu *This, HWND hwnd, BOOL cut)
262 IDataObject *dataobject;
264 TRACE("(%p)->(wnd=%p, cut=%d)\n", This, hwnd, cut);
266 if (SUCCEEDED(IShellFolder_GetUIObjectOf(This->parent, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl, &IID_IDataObject, 0, (void**)&dataobject)))
268 OleSetClipboard(dataobject);
269 IDataObject_Release(dataobject);
273 /**************************************************************************
274 * Properties_AddPropSheetCallback
276 * Used by DoOpenProperties through SHCreatePropSheetExtArrayEx to add
277 * propertysheet pages from shell extensions.
279 static BOOL CALLBACK Properties_AddPropSheetCallback(HPROPSHEETPAGE hpage, LPARAM lparam)
281 LPPROPSHEETHEADERW psh = (LPPROPSHEETHEADERW) lparam;
282 psh->u3.phpage[psh->nPages++] = hpage;
284 return TRUE;
287 #define MAX_PROP_PAGES 99
289 static void DoOpenProperties(ContextMenu *This, HWND hwnd)
291 static const WCHAR wszFolder[] = {'F','o','l','d','e','r', 0};
292 static const WCHAR wszFiletypeAll[] = {'*',0};
293 LPSHELLFOLDER lpDesktopSF;
294 LPSHELLFOLDER lpSF;
295 LPDATAOBJECT lpDo;
296 WCHAR wszFiletype[MAX_PATH];
297 WCHAR wszFilename[MAX_PATH];
298 PROPSHEETHEADERW psh;
299 HPROPSHEETPAGE hpages[MAX_PROP_PAGES];
300 HPSXA hpsxa;
301 UINT ret;
303 TRACE("(%p)->(wnd=%p)\n", This, hwnd);
305 ZeroMemory(&psh, sizeof(PROPSHEETHEADERW));
306 psh.dwSize = sizeof (PROPSHEETHEADERW);
307 psh.hwndParent = hwnd;
308 psh.dwFlags = PSH_PROPTITLE;
309 psh.nPages = 0;
310 psh.u3.phpage = hpages;
311 psh.u2.nStartPage = 0;
313 _ILSimpleGetTextW(This->apidl[0], (LPVOID)wszFilename, MAX_PATH);
314 psh.pszCaption = (LPCWSTR)wszFilename;
316 /* Find out where to look for the shell extensions */
317 if (_ILIsValue(This->apidl[0]))
319 char sTemp[64];
320 sTemp[0] = 0;
321 if (_ILGetExtension(This->apidl[0], sTemp, 64))
323 HCR_MapTypeToValueA(sTemp, sTemp, 64, TRUE);
324 MultiByteToWideChar(CP_ACP, 0, sTemp, -1, wszFiletype, MAX_PATH);
326 else
328 wszFiletype[0] = 0;
331 else if (_ILIsFolder(This->apidl[0]))
333 lstrcpynW(wszFiletype, wszFolder, 64);
335 else if (_ILIsSpecialFolder(This->apidl[0]))
337 LPGUID folderGUID;
338 static const WCHAR wszclsid[] = {'C','L','S','I','D','\\', 0};
339 folderGUID = _ILGetGUIDPointer(This->apidl[0]);
340 lstrcpyW(wszFiletype, wszclsid);
341 StringFromGUID2(folderGUID, &wszFiletype[6], MAX_PATH - 6);
343 else
345 FIXME("Requested properties for unknown type.\n");
346 return;
349 /* Get a suitable DataObject for accessing the files */
350 SHGetDesktopFolder(&lpDesktopSF);
351 if (_ILIsPidlSimple(This->pidl))
353 ret = IShellFolder_GetUIObjectOf(lpDesktopSF, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl,
354 &IID_IDataObject, NULL, (LPVOID *)&lpDo);
355 IShellFolder_Release(lpDesktopSF);
357 else
359 IShellFolder_BindToObject(lpDesktopSF, This->pidl, NULL, &IID_IShellFolder, (LPVOID*) &lpSF);
360 ret = IShellFolder_GetUIObjectOf(lpSF, hwnd, This->cidl, (LPCITEMIDLIST*)This->apidl,
361 &IID_IDataObject, NULL, (LPVOID *)&lpDo);
362 IShellFolder_Release(lpSF);
363 IShellFolder_Release(lpDesktopSF);
366 if (SUCCEEDED(ret))
368 hpsxa = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszFiletype, MAX_PROP_PAGES - psh.nPages, lpDo);
369 if (hpsxa != NULL)
371 SHAddFromPropSheetExtArray(hpsxa, Properties_AddPropSheetCallback, (LPARAM)&psh);
372 SHDestroyPropSheetExtArray(hpsxa);
374 hpsxa = SHCreatePropSheetExtArrayEx(HKEY_CLASSES_ROOT, wszFiletypeAll, MAX_PROP_PAGES - psh.nPages, lpDo);
375 if (hpsxa != NULL)
377 SHAddFromPropSheetExtArray(hpsxa, Properties_AddPropSheetCallback, (LPARAM)&psh);
378 SHDestroyPropSheetExtArray(hpsxa);
380 IDataObject_Release(lpDo);
383 if (psh.nPages)
384 PropertySheetW(&psh);
385 else
386 FIXME("No property pages found.\n");
389 static HRESULT WINAPI ItemMenu_InvokeCommand(
390 IContextMenu3 *iface,
391 LPCMINVOKECOMMANDINFO lpcmi)
393 ContextMenu *This = impl_from_IContextMenu3(iface);
395 if (lpcmi->cbSize != sizeof(CMINVOKECOMMANDINFO))
396 FIXME("Is an EX structure\n");
398 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
400 if (IS_INTRESOURCE(lpcmi->lpVerb) && LOWORD(lpcmi->lpVerb) > FCIDM_SHVIEWLAST)
402 TRACE("Invalid Verb %x\n", LOWORD(lpcmi->lpVerb));
403 return E_INVALIDARG;
406 if (IS_INTRESOURCE(lpcmi->lpVerb))
408 switch(LOWORD(lpcmi->lpVerb))
410 case FCIDM_SHVIEW_EXPLORE:
411 TRACE("Verb FCIDM_SHVIEW_EXPLORE\n");
412 DoOpenExplore(This, lpcmi->hwnd, "explore");
413 break;
414 case FCIDM_SHVIEW_OPEN:
415 TRACE("Verb FCIDM_SHVIEW_OPEN\n");
416 DoOpenExplore(This, lpcmi->hwnd, "open");
417 break;
418 case FCIDM_SHVIEW_RENAME:
420 IShellBrowser *browser;
422 /* get the active IShellView */
423 browser = (IShellBrowser*)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER, 0, 0);
424 if (browser)
426 IShellView *view;
428 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(browser, &view)))
430 TRACE("(shellview=%p)\n", view);
431 IShellView_SelectItem(view, This->apidl[0],
432 SVSI_DESELECTOTHERS|SVSI_EDIT|SVSI_ENSUREVISIBLE|SVSI_FOCUSED|SVSI_SELECT);
433 IShellView_Release(view);
436 break;
438 case FCIDM_SHVIEW_DELETE:
439 TRACE("Verb FCIDM_SHVIEW_DELETE\n");
440 DoDelete(This);
441 break;
442 case FCIDM_SHVIEW_COPY:
443 TRACE("Verb FCIDM_SHVIEW_COPY\n");
444 DoCopyOrCut(This, lpcmi->hwnd, FALSE);
445 break;
446 case FCIDM_SHVIEW_CUT:
447 TRACE("Verb FCIDM_SHVIEW_CUT\n");
448 DoCopyOrCut(This, lpcmi->hwnd, TRUE);
449 break;
450 case FCIDM_SHVIEW_PROPERTIES:
451 TRACE("Verb FCIDM_SHVIEW_PROPERTIES\n");
452 DoOpenProperties(This, lpcmi->hwnd);
453 break;
454 default:
455 FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi->lpVerb));
456 return E_INVALIDARG;
459 else
461 TRACE("Verb is %s\n",debugstr_a(lpcmi->lpVerb));
462 if (strcmp(lpcmi->lpVerb,"delete")==0)
463 DoDelete(This);
464 else if (strcmp(lpcmi->lpVerb,"properties")==0)
465 DoOpenProperties(This, lpcmi->hwnd);
466 else {
467 FIXME("Unhandled string verb %s\n",debugstr_a(lpcmi->lpVerb));
468 return E_FAIL;
471 return S_OK;
474 static HRESULT WINAPI ItemMenu_GetCommandString(IContextMenu3 *iface, UINT_PTR cmdid, UINT flags,
475 UINT *reserved, LPSTR name, UINT maxlen)
477 static const WCHAR openW[] = {'o','p','e','n',0};
478 static const WCHAR exploreW[] = {'e','x','p','l','o','r','e',0};
479 static const WCHAR cutW[] = {'c','u','t',0};
480 static const WCHAR copyW[] = {'c','o','p','y',0};
481 static const WCHAR linkW[] = {'l','i','n','k',0};
482 static const WCHAR deleteW[] = {'d','e','l','e','t','e',0};
483 static const WCHAR propertiesW[] = {'p','r','o','p','e','r','t','i','e','s',0};
484 static const WCHAR renameW[] = {'r','e','n','a','m','e',0};
485 ContextMenu *This = impl_from_IContextMenu3(iface);
486 const WCHAR *cmdW = NULL;
487 HRESULT hr = S_OK;
489 TRACE("(%p)->(%lx, %#x, %p, %p, %u)\n", This, cmdid, flags, reserved, name, maxlen);
491 switch (flags)
493 case GCS_HELPTEXTA:
494 case GCS_HELPTEXTW:
495 hr = E_NOTIMPL;
496 break;
498 case GCS_VERBA:
499 case GCS_VERBW:
500 switch (cmdid)
502 case FCIDM_SHVIEW_OPEN:
503 cmdW = openW;
504 break;
505 case FCIDM_SHVIEW_EXPLORE:
506 cmdW = exploreW;
507 break;
508 case FCIDM_SHVIEW_CUT:
509 cmdW = cutW;
510 break;
511 case FCIDM_SHVIEW_COPY:
512 cmdW = copyW;
513 break;
514 case FCIDM_SHVIEW_CREATELINK:
515 cmdW = linkW;
516 break;
517 case FCIDM_SHVIEW_DELETE:
518 cmdW = deleteW;
519 break;
520 case FCIDM_SHVIEW_PROPERTIES:
521 cmdW = propertiesW;
522 break;
523 case FCIDM_SHVIEW_RENAME:
524 cmdW = renameW;
525 break;
528 if (!cmdW)
530 hr = E_INVALIDARG;
531 break;
534 if (flags == GCS_VERBA)
535 WideCharToMultiByte(CP_ACP, 0, cmdW, -1, name, maxlen, NULL, NULL);
536 else
537 lstrcpynW((WCHAR *)name, cmdW, maxlen);
539 TRACE("name %s\n", flags == GCS_VERBA ? debugstr_a(name) : debugstr_w((WCHAR *)name));
540 break;
542 case GCS_VALIDATEA:
543 case GCS_VALIDATEW:
544 break;
547 return hr;
550 /**************************************************************************
551 * NOTES
552 * should be only in IContextMenu2 and IContextMenu3
553 * is nevertheless called from word95
555 static HRESULT WINAPI ContextMenu_HandleMenuMsg(IContextMenu3 *iface, UINT msg,
556 WPARAM wParam, LPARAM lParam)
558 ContextMenu *This = impl_from_IContextMenu3(iface);
559 FIXME("(%p)->(0x%x 0x%lx 0x%lx): stub\n", This, msg, wParam, lParam);
560 return E_NOTIMPL;
563 static HRESULT WINAPI ContextMenu_HandleMenuMsg2(IContextMenu3 *iface, UINT msg,
564 WPARAM wParam, LPARAM lParam, LRESULT *result)
566 ContextMenu *This = impl_from_IContextMenu3(iface);
567 FIXME("(%p)->(0x%x 0x%lx 0x%lx %p): stub\n", This, msg, wParam, lParam, result);
568 return E_NOTIMPL;
571 static const IContextMenu3Vtbl ItemContextMenuVtbl =
573 ContextMenu_QueryInterface,
574 ContextMenu_AddRef,
575 ContextMenu_Release,
576 ItemMenu_QueryContextMenu,
577 ItemMenu_InvokeCommand,
578 ItemMenu_GetCommandString,
579 ContextMenu_HandleMenuMsg,
580 ContextMenu_HandleMenuMsg2
583 HRESULT ItemMenu_Constructor(IShellFolder *parent, LPCITEMIDLIST pidl, const LPCITEMIDLIST *apidl, UINT cidl,
584 REFIID riid, void **pObj)
586 ContextMenu* This;
587 HRESULT hr;
588 UINT i;
590 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
591 if (!This) return E_OUTOFMEMORY;
593 This->IContextMenu3_iface.lpVtbl = &ItemContextMenuVtbl;
594 This->ref = 1;
595 This->parent = parent;
596 if (parent) IShellFolder_AddRef(parent);
598 This->pidl = ILClone(pidl);
599 This->apidl = _ILCopyaPidl(apidl, cidl);
600 This->cidl = cidl;
601 This->allvalues = TRUE;
603 This->desktop = FALSE;
605 for (i = 0; i < cidl; i++)
606 This->allvalues &= (_ILIsValue(apidl[i]) ? 1 : 0);
608 hr = IContextMenu3_QueryInterface(&This->IContextMenu3_iface, riid, pObj);
609 IContextMenu3_Release(&This->IContextMenu3_iface);
611 return hr;
614 /* Background menu implementation */
615 static HRESULT WINAPI BackgroundMenu_QueryContextMenu(
616 IContextMenu3 *iface,
617 HMENU hMenu,
618 UINT indexMenu,
619 UINT idCmdFirst,
620 UINT idCmdLast,
621 UINT uFlags)
623 ContextMenu *This = impl_from_IContextMenu3(iface);
624 HMENU hMyMenu;
625 UINT idMax;
626 HRESULT hr;
628 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
629 This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
631 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
632 if (uFlags & CMF_DEFAULTONLY)
634 HMENU ourMenu = GetSubMenu(hMyMenu,0);
635 UINT oldDef = GetMenuDefaultItem(hMenu,TRUE,GMDI_USEDISABLED);
636 UINT newDef = GetMenuDefaultItem(ourMenu,TRUE,GMDI_USEDISABLED);
637 if (newDef != oldDef)
638 SetMenuDefaultItem(hMenu,newDef,TRUE);
639 if (newDef!=0xFFFFFFFF)
640 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, newDef+1);
641 else
642 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
644 else
646 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu,
647 idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
648 hr = MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, idMax-idCmdFirst);
650 DestroyMenu(hMyMenu);
652 TRACE("(%p)->returning 0x%x\n",This,hr);
653 return hr;
656 static void DoNewFolder(ContextMenu *This, IShellView *view)
658 ISFHelper *helper;
660 IShellFolder_QueryInterface(This->parent, &IID_ISFHelper, (void**)&helper);
661 if (helper)
663 WCHAR nameW[MAX_PATH];
664 LPITEMIDLIST pidl;
666 ISFHelper_GetUniqueName(helper, nameW, MAX_PATH);
667 ISFHelper_AddFolder(helper, 0, nameW, &pidl);
669 if (view)
671 /* if we are in a shellview do labeledit */
672 IShellView_SelectItem(view,
673 pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE
674 |SVSI_FOCUSED|SVSI_SELECT));
677 SHFree(pidl);
678 ISFHelper_Release(helper);
682 static BOOL DoPaste(ContextMenu *This)
684 BOOL bSuccess = FALSE;
685 IDataObject * pda;
687 TRACE("\n");
689 if(SUCCEEDED(OleGetClipboard(&pda)))
691 STGMEDIUM medium;
692 FORMATETC formatetc;
694 TRACE("pda=%p\n", pda);
696 /* Set the FORMATETC structure*/
697 InitFormatEtc(formatetc, RegisterClipboardFormatW(CFSTR_SHELLIDLISTW), TYMED_HGLOBAL);
699 /* Get the pidls from IDataObject */
700 if(SUCCEEDED(IDataObject_GetData(pda,&formatetc,&medium)))
702 LPITEMIDLIST * apidl;
703 LPITEMIDLIST pidl;
704 IShellFolder *psfFrom = NULL, *psfDesktop;
706 LPIDA lpcida = GlobalLock(medium.u.hGlobal);
707 TRACE("cida=%p\n", lpcida);
709 apidl = _ILCopyCidaToaPidl(&pidl, lpcida);
711 /* bind to the source shellfolder */
712 SHGetDesktopFolder(&psfDesktop);
713 if(psfDesktop)
715 IShellFolder_BindToObject(psfDesktop, pidl, NULL, &IID_IShellFolder, (LPVOID*)&psfFrom);
716 IShellFolder_Release(psfDesktop);
719 if (psfFrom)
721 /* get source and destination shellfolder */
722 ISFHelper *psfhlpdst, *psfhlpsrc;
723 IShellFolder_QueryInterface(This->parent, &IID_ISFHelper, (void**)&psfhlpdst);
724 IShellFolder_QueryInterface(psfFrom, &IID_ISFHelper, (void**)&psfhlpsrc);
726 /* do the copy/move */
727 if (psfhlpdst && psfhlpsrc)
729 ISFHelper_CopyItems(psfhlpdst, psfFrom, lpcida->cidl, (LPCITEMIDLIST*)apidl);
730 /* FIXME handle move
731 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
734 if(psfhlpdst) ISFHelper_Release(psfhlpdst);
735 if(psfhlpsrc) ISFHelper_Release(psfhlpsrc);
736 IShellFolder_Release(psfFrom);
739 _ILFreeaPidl(apidl, lpcida->cidl);
740 SHFree(pidl);
742 /* release the medium*/
743 ReleaseStgMedium(&medium);
745 IDataObject_Release(pda);
747 #if 0
748 HGLOBAL hMem;
750 OpenClipboard(NULL);
751 hMem = GetClipboardData(CF_HDROP);
753 if(hMem)
755 char * pDropFiles = GlobalLock(hMem);
756 if(pDropFiles)
758 int len, offset = sizeof(DROPFILESTRUCT);
760 while( pDropFiles[offset] != 0)
762 len = strlen(pDropFiles + offset);
763 TRACE("%s\n", pDropFiles + offset);
764 offset += len+1;
767 GlobalUnlock(hMem);
769 CloseClipboard();
770 #endif
771 return bSuccess;
774 static HRESULT WINAPI BackgroundMenu_InvokeCommand(
775 IContextMenu3 *iface,
776 LPCMINVOKECOMMANDINFO lpcmi)
778 ContextMenu *This = impl_from_IContextMenu3(iface);
779 IShellBrowser *browser;
780 IShellView *view = NULL;
781 HWND hWnd = NULL;
783 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n", This, lpcmi, lpcmi->lpVerb, lpcmi->hwnd);
785 /* get the active IShellView */
786 if ((browser = (IShellBrowser*)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER, 0, 0)))
788 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(browser, &view)))
789 IShellView_GetWindow(view, &hWnd);
792 if(HIWORD(lpcmi->lpVerb))
794 TRACE("%s\n", debugstr_a(lpcmi->lpVerb));
796 if (!strcmp(lpcmi->lpVerb, CMDSTR_NEWFOLDERA))
798 DoNewFolder(This, view);
800 else if (!strcmp(lpcmi->lpVerb, CMDSTR_VIEWLISTA))
802 if (hWnd) SendMessageA(hWnd, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW, 0), 0);
804 else if (!strcmp(lpcmi->lpVerb, CMDSTR_VIEWDETAILSA))
806 if (hWnd) SendMessageA(hWnd, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW, 0), 0);
808 else
810 FIXME("please report: unknown verb %s\n", debugstr_a(lpcmi->lpVerb));
813 else
815 switch (LOWORD(lpcmi->lpVerb))
817 case FCIDM_SHVIEW_REFRESH:
818 if (view) IShellView_Refresh(view);
819 break;
821 case FCIDM_SHVIEW_NEWFOLDER:
822 DoNewFolder(This, view);
823 break;
825 case FCIDM_SHVIEW_INSERT:
826 DoPaste(This);
827 break;
829 case FCIDM_SHVIEW_PROPERTIES:
830 if (This->desktop) {
831 ShellExecuteA(lpcmi->hwnd, "open", "rundll32.exe shell32.dll,Control_RunDLL desk.cpl", NULL, NULL, SW_SHOWNORMAL);
832 } else {
833 FIXME("launch item properties dialog\n");
835 break;
837 default:
838 /* if it's an id just pass it to the parent shv */
839 if (hWnd) SendMessageA(hWnd, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0), 0);
840 break;
844 if (view)
845 IShellView_Release(view);
847 return S_OK;
850 static HRESULT WINAPI BackgroundMenu_GetCommandString(
851 IContextMenu3 *iface,
852 UINT_PTR idCommand,
853 UINT uFlags,
854 UINT* lpReserved,
855 LPSTR lpszName,
856 UINT uMaxNameLen)
858 ContextMenu *This = impl_from_IContextMenu3(iface);
860 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
862 /* test the existence of the menu items, the file dialog enables
863 the buttons according to this */
864 if (uFlags == GCS_VALIDATEA)
866 if(HIWORD(idCommand))
868 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
869 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
870 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
872 return S_OK;
877 FIXME("unknown command string\n");
878 return E_FAIL;
881 static const IContextMenu3Vtbl BackgroundContextMenuVtbl =
883 ContextMenu_QueryInterface,
884 ContextMenu_AddRef,
885 ContextMenu_Release,
886 BackgroundMenu_QueryContextMenu,
887 BackgroundMenu_InvokeCommand,
888 BackgroundMenu_GetCommandString,
889 ContextMenu_HandleMenuMsg,
890 ContextMenu_HandleMenuMsg2
893 HRESULT BackgroundMenu_Constructor(IShellFolder *parent, BOOL desktop, REFIID riid, void **pObj)
895 ContextMenu *This;
896 HRESULT hr;
898 This = HeapAlloc(GetProcessHeap(), 0, sizeof(*This));
899 if (!This) return E_OUTOFMEMORY;
901 This->IContextMenu3_iface.lpVtbl = &BackgroundContextMenuVtbl;
902 This->ref = 1;
903 This->parent = parent;
905 This->pidl = NULL;
906 This->apidl = NULL;
907 This->cidl = 0;
908 This->allvalues = FALSE;
910 This->desktop = desktop;
911 if (parent) IShellFolder_AddRef(parent);
913 hr = IContextMenu3_QueryInterface(&This->IContextMenu3_iface, riid, pObj);
914 IContextMenu3_Release(&This->IContextMenu3_iface);
916 return hr;