2 * IContextMenu for items in the shellview
4 * Copyright 1998, 2000 Juergen Schmied <juergen.schmied@debitel.net>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
28 #include "wine/debug.h"
33 #include "undocshell.h"
36 #include "shell32_main.h"
37 #include "shellfolder.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
43 /**************************************************************************
44 * IContextMenu Implementation
47 { const IContextMenu2Vtbl
*lpVtbl
;
49 IShellFolder
* pSFParent
;
50 LPITEMIDLIST pidl
; /* root pidl */
51 LPITEMIDLIST
*apidl
; /* array of child pidls */
57 static const IContextMenu2Vtbl cmvt
;
59 /**************************************************************************
60 * ISvItemCm_CanRenameItems()
62 static BOOL
ISvItemCm_CanRenameItems(ItemCmImpl
*This
)
66 TRACE("(%p)->()\n",This
);
70 for(i
= 0; i
< This
->cidl
; i
++){}
71 if(i
> 1) return FALSE
; /* can't rename more than one item at a time*/
72 dwAttributes
= SFGAO_CANRENAME
;
73 IShellFolder_GetAttributesOf(This
->pSFParent
, 1, (LPCITEMIDLIST
*)This
->apidl
, &dwAttributes
);
74 return dwAttributes
& SFGAO_CANRENAME
;
79 /**************************************************************************
80 * ISvItemCm_Constructor()
82 IContextMenu2
*ISvItemCm_Constructor(LPSHELLFOLDER pSFParent
, LPCITEMIDLIST pidl
, const LPCITEMIDLIST
*apidl
, UINT cidl
)
86 cm
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ItemCmImpl
));
89 cm
->pidl
= ILClone(pidl
);
90 cm
->pSFParent
= pSFParent
;
92 if(pSFParent
) IShellFolder_AddRef(pSFParent
);
94 cm
->apidl
= _ILCopyaPidl(apidl
, cidl
);
98 for(u
= 0; u
< cidl
; u
++)
100 cm
->bAllValues
&= (_ILIsValue(apidl
[u
]) ? 1 : 0);
103 TRACE("(%p)->()\n",cm
);
105 return (IContextMenu2
*)cm
;
108 /**************************************************************************
109 * ISvItemCm_fnQueryInterface
111 static HRESULT WINAPI
ISvItemCm_fnQueryInterface(IContextMenu2
*iface
, REFIID riid
, LPVOID
*ppvObj
)
113 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
115 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
119 if(IsEqualIID(riid
, &IID_IUnknown
) ||
120 IsEqualIID(riid
, &IID_IContextMenu
) ||
121 IsEqualIID(riid
, &IID_IContextMenu2
))
125 else if(IsEqualIID(riid
, &IID_IShellExtInit
)) /*IShellExtInit*/
127 FIXME("-- LPSHELLEXTINIT pointer requested\n");
132 IUnknown_AddRef((IUnknown
*)*ppvObj
);
133 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
136 TRACE("-- Interface: E_NOINTERFACE\n");
137 return E_NOINTERFACE
;
140 /**************************************************************************
143 static ULONG WINAPI
ISvItemCm_fnAddRef(IContextMenu2
*iface
)
145 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
146 ULONG refCount
= InterlockedIncrement(&This
->ref
);
148 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
153 /**************************************************************************
154 * ISvItemCm_fnRelease
156 static ULONG WINAPI
ISvItemCm_fnRelease(IContextMenu2
*iface
)
158 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
159 ULONG refCount
= InterlockedDecrement(&This
->ref
);
161 TRACE("(%p)->(count=%i)\n", This
, refCount
+ 1);
165 TRACE(" destroying IContextMenu(%p)\n",This
);
168 IShellFolder_Release(This
->pSFParent
);
172 /*make sure the pidl is freed*/
173 _ILFreeaPidl(This
->apidl
, This
->cidl
);
175 HeapFree(GetProcessHeap(),0,This
);
180 /**************************************************************************
183 void WINAPI
_InsertMenuItem (
194 ZeroMemory(&mii
, sizeof(mii
));
195 mii
.cbSize
= sizeof(mii
);
196 if (fType
== MFT_SEPARATOR
)
198 mii
.fMask
= MIIM_ID
| MIIM_TYPE
;
202 mii
.fMask
= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
203 mii
.dwTypeData
= (LPSTR
) dwTypeData
;
208 InsertMenuItemA( hmenu
, indexMenu
, fByPosition
, &mii
);
211 static void WINAPI
_InsertMenuItemW (
222 mii
.cbSize
= sizeof(mii
);
223 if (fType
== MFT_SEPARATOR
)
225 mii
.fMask
= MIIM_ID
| MIIM_TYPE
;
229 mii
.fMask
= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
230 mii
.dwTypeData
= dwTypeData
;
235 InsertMenuItemW( hmenu
, indexMenu
, fByPosition
, &mii
);
238 /**************************************************************************
239 * ISvItemCm_fnQueryContextMenu()
241 static HRESULT WINAPI
ISvItemCm_fnQueryContextMenu(
242 IContextMenu2
*iface
,
249 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
251 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This
, hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
254 FIXME("We should use idCmdFirst=%d and idCmdLast=%d for command ids\n", idCmdFirst
, idCmdLast
);
256 if(!(CMF_DEFAULTONLY
& uFlags
) && This
->cidl
>0)
258 HMENU hmenures
= LoadMenuW(shell32_hInstance
, MAKEINTRESOURCEW(MENU_SHV_FILE
));
260 if(uFlags
& CMF_EXPLORE
)
261 RemoveMenu(hmenures
, FCIDM_SHVIEW_OPEN
, MF_BYCOMMAND
);
263 Shell_MergeMenus(hmenu
, GetSubMenu(hmenures
, 0), indexMenu
, idCmdFirst
, idCmdLast
, MM_SUBMENUSHAVEIDS
);
265 DestroyMenu(hmenures
);
271 mi
.cbSize
= sizeof(mi
);
272 mi
.fMask
= MIIM_ID
| MIIM_STRING
| MIIM_FTYPE
;
275 GetMenuItemInfoW(hmenu
, FCIDM_SHVIEW_EXPLORE
, MF_BYCOMMAND
, &mi
);
276 RemoveMenu(hmenu
, FCIDM_SHVIEW_EXPLORE
, MF_BYCOMMAND
);
277 _InsertMenuItemW(hmenu
, (uFlags
& CMF_EXPLORE
) ? 1 : 2, MF_BYPOSITION
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, str
, MFS_ENABLED
);
280 SetMenuDefaultItem(hmenu
, 0, MF_BYPOSITION
);
282 if(uFlags
& ~CMF_CANRENAME
)
283 RemoveMenu(hmenu
, FCIDM_SHVIEW_RENAME
, MF_BYCOMMAND
);
285 EnableMenuItem(hmenu
, FCIDM_SHVIEW_RENAME
, MF_BYCOMMAND
| ISvItemCm_CanRenameItems(This
) ? MFS_ENABLED
: MFS_DISABLED
);
287 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (FCIDM_SHVIEWLAST
));
289 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
292 /**************************************************************************
298 static void DoOpenExplore(
299 IContextMenu2
*iface
,
303 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
305 UINT i
, bFolderFound
= FALSE
;
307 SHELLEXECUTEINFOA sei
;
309 /* Find the first item in the list that is not a value. These commands
310 should never be invoked if there isn't at least one folder item in the list.*/
312 for(i
= 0; i
<This
->cidl
; i
++)
314 if(!_ILIsValue(This
->apidl
[i
]))
321 if (!bFolderFound
) return;
323 pidlFQ
= ILCombine(This
->pidl
, This
->apidl
[i
]);
325 ZeroMemory(&sei
, sizeof(sei
));
326 sei
.cbSize
= sizeof(sei
);
327 sei
.fMask
= SEE_MASK_IDLIST
| SEE_MASK_CLASSNAME
;
328 sei
.lpIDList
= pidlFQ
;
329 sei
.lpClass
= "Folder";
331 sei
.nShow
= SW_SHOWNORMAL
;
333 ShellExecuteExA(&sei
);
337 /**************************************************************************
340 static void DoRename(
341 IContextMenu2
*iface
,
344 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
349 TRACE("(%p)->(wnd=%p)\n",This
, hwnd
);
351 /* get the active IShellView */
352 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
354 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
356 TRACE("(sv=%p)\n",lpSV
);
357 IShellView_SelectItem(lpSV
, This
->apidl
[0],
358 SVSI_DESELECTOTHERS
|SVSI_EDIT
|SVSI_ENSUREVISIBLE
|SVSI_FOCUSED
|SVSI_SELECT
);
359 IShellView_Release(lpSV
);
364 /**************************************************************************
367 * deletes the currently selected items
369 static void DoDelete(IContextMenu2
*iface
)
371 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
374 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlp
);
377 ISFHelper_DeleteItems(psfhlp
, This
->cidl
, (LPCITEMIDLIST
*)This
->apidl
);
378 ISFHelper_Release(psfhlp
);
382 /**************************************************************************
385 * copies the currently selected items into the clipboard
387 static BOOL
DoCopyOrCut(
388 IContextMenu2
*iface
,
392 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
398 TRACE("(%p)->(wnd=%p,bCut=0x%08x)\n",This
, hwnd
, bCut
);
400 /* get the active IShellView */
401 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
403 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
405 if (SUCCEEDED(IShellView_GetItemObject(lpSV
, SVGIO_SELECTION
, &IID_IDataObject
, (LPVOID
*)&lpDo
)))
407 OleSetClipboard(lpDo
);
408 IDataObject_Release(lpDo
);
410 IShellView_Release(lpSV
);
415 /**************************************************************************
416 * ISvItemCm_fnInvokeCommand()
418 static HRESULT WINAPI
ISvItemCm_fnInvokeCommand(
419 IContextMenu2
*iface
,
420 LPCMINVOKECOMMANDINFO lpcmi
)
422 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
424 if (lpcmi
->cbSize
!= sizeof(CMINVOKECOMMANDINFO
))
425 FIXME("Is an EX structure\n");
427 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This
,lpcmi
,lpcmi
->lpVerb
, lpcmi
->hwnd
);
429 if( HIWORD(lpcmi
->lpVerb
)==0 && LOWORD(lpcmi
->lpVerb
) > FCIDM_SHVIEWLAST
)
431 TRACE("Invalid Verb %x\n",LOWORD(lpcmi
->lpVerb
));
435 if (HIWORD(lpcmi
->lpVerb
) == 0)
437 switch(LOWORD(lpcmi
->lpVerb
))
439 case FCIDM_SHVIEW_EXPLORE
:
440 TRACE("Verb FCIDM_SHVIEW_EXPLORE\n");
441 DoOpenExplore(iface
, lpcmi
->hwnd
, "explore");
443 case FCIDM_SHVIEW_OPEN
:
444 TRACE("Verb FCIDM_SHVIEW_OPEN\n");
445 DoOpenExplore(iface
, lpcmi
->hwnd
, "open");
447 case FCIDM_SHVIEW_RENAME
:
448 TRACE("Verb FCIDM_SHVIEW_RENAME\n");
449 DoRename(iface
, lpcmi
->hwnd
);
451 case FCIDM_SHVIEW_DELETE
:
452 TRACE("Verb FCIDM_SHVIEW_DELETE\n");
455 case FCIDM_SHVIEW_COPY
:
456 TRACE("Verb FCIDM_SHVIEW_COPY\n");
457 DoCopyOrCut(iface
, lpcmi
->hwnd
, FALSE
);
459 case FCIDM_SHVIEW_CUT
:
460 TRACE("Verb FCIDM_SHVIEW_CUT\n");
461 DoCopyOrCut(iface
, lpcmi
->hwnd
, TRUE
);
464 FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi
->lpVerb
));
469 TRACE("Verb is %s\n",debugstr_a(lpcmi
->lpVerb
));
470 if (strcmp(lpcmi
->lpVerb
,"delete")==0)
473 FIXME("Unhandled string verb %s\n",debugstr_a(lpcmi
->lpVerb
));
478 /**************************************************************************
479 * ISvItemCm_fnGetCommandString()
481 static HRESULT WINAPI
ISvItemCm_fnGetCommandString(
482 IContextMenu2
*iface
,
489 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
491 HRESULT hr
= E_INVALIDARG
;
493 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n",This
, idCommand
, uFlags
, lpReserved
, lpszName
, uMaxNameLen
);
505 case FCIDM_SHVIEW_RENAME
:
506 strcpy((LPSTR
)lpszName
, "rename");
512 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
513 case, you need to do the lstrcpyW to the pointer passed.*/
516 { case FCIDM_SHVIEW_RENAME
:
517 MultiByteToWideChar( CP_ACP
, 0, "rename", -1, (LPWSTR
)lpszName
, uMaxNameLen
);
528 TRACE("-- (%p)->(name=%s)\n",This
, lpszName
);
532 /**************************************************************************
533 * ISvItemCm_fnHandleMenuMsg()
535 * should be only in IContextMenu2 and IContextMenu3
536 * is nevertheless called from word95
538 static HRESULT WINAPI
ISvItemCm_fnHandleMenuMsg(
539 IContextMenu2
*iface
,
544 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
546 TRACE("(%p)->(msg=%x wp=%lx lp=%lx)\n",This
, uMsg
, wParam
, lParam
);
551 static const IContextMenu2Vtbl cmvt
=
553 ISvItemCm_fnQueryInterface
,
556 ISvItemCm_fnQueryContextMenu
,
557 ISvItemCm_fnInvokeCommand
,
558 ISvItemCm_fnGetCommandString
,
559 ISvItemCm_fnHandleMenuMsg