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 static void _InsertMenuItemW (
191 mii
.cbSize
= sizeof(mii
);
192 if (fType
== MFT_SEPARATOR
)
194 mii
.fMask
= MIIM_ID
| MIIM_TYPE
;
198 mii
.fMask
= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
199 mii
.dwTypeData
= dwTypeData
;
204 InsertMenuItemW( hmenu
, indexMenu
, fByPosition
, &mii
);
207 /**************************************************************************
208 * ISvItemCm_fnQueryContextMenu()
210 static HRESULT WINAPI
ISvItemCm_fnQueryContextMenu(
211 IContextMenu2
*iface
,
218 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
220 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This
, hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
223 FIXME("We should use idCmdFirst=%d and idCmdLast=%d for command ids\n", idCmdFirst
, idCmdLast
);
225 if(!(CMF_DEFAULTONLY
& uFlags
) && This
->cidl
>0)
227 HMENU hmenures
= LoadMenuW(shell32_hInstance
, MAKEINTRESOURCEW(MENU_SHV_FILE
));
229 if(uFlags
& CMF_EXPLORE
)
230 RemoveMenu(hmenures
, FCIDM_SHVIEW_OPEN
, MF_BYCOMMAND
);
232 Shell_MergeMenus(hmenu
, GetSubMenu(hmenures
, 0), indexMenu
, idCmdFirst
, idCmdLast
, MM_SUBMENUSHAVEIDS
);
234 DestroyMenu(hmenures
);
240 mi
.cbSize
= sizeof(mi
);
241 mi
.fMask
= MIIM_ID
| MIIM_STRING
| MIIM_FTYPE
;
244 GetMenuItemInfoW(hmenu
, FCIDM_SHVIEW_EXPLORE
, MF_BYCOMMAND
, &mi
);
245 RemoveMenu(hmenu
, FCIDM_SHVIEW_EXPLORE
, MF_BYCOMMAND
);
246 _InsertMenuItemW(hmenu
, (uFlags
& CMF_EXPLORE
) ? 1 : 2, MF_BYPOSITION
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, str
, MFS_ENABLED
);
249 SetMenuDefaultItem(hmenu
, 0, MF_BYPOSITION
);
251 if(uFlags
& ~CMF_CANRENAME
)
252 RemoveMenu(hmenu
, FCIDM_SHVIEW_RENAME
, MF_BYCOMMAND
);
254 EnableMenuItem(hmenu
, FCIDM_SHVIEW_RENAME
, MF_BYCOMMAND
| ISvItemCm_CanRenameItems(This
) ? MFS_ENABLED
: MFS_DISABLED
);
256 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (FCIDM_SHVIEWLAST
));
258 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
261 /**************************************************************************
267 static void DoOpenExplore(
268 IContextMenu2
*iface
,
272 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
274 UINT i
, bFolderFound
= FALSE
;
276 SHELLEXECUTEINFOA sei
;
278 /* Find the first item in the list that is not a value. These commands
279 should never be invoked if there isn't at least one folder item in the list.*/
281 for(i
= 0; i
<This
->cidl
; i
++)
283 if(!_ILIsValue(This
->apidl
[i
]))
290 if (!bFolderFound
) return;
292 pidlFQ
= ILCombine(This
->pidl
, This
->apidl
[i
]);
294 ZeroMemory(&sei
, sizeof(sei
));
295 sei
.cbSize
= sizeof(sei
);
296 sei
.fMask
= SEE_MASK_IDLIST
| SEE_MASK_CLASSNAME
;
297 sei
.lpIDList
= pidlFQ
;
298 sei
.lpClass
= "Folder";
300 sei
.nShow
= SW_SHOWNORMAL
;
302 ShellExecuteExA(&sei
);
306 /**************************************************************************
309 static void DoRename(
310 IContextMenu2
*iface
,
313 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
318 TRACE("(%p)->(wnd=%p)\n",This
, hwnd
);
320 /* get the active IShellView */
321 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
323 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
325 TRACE("(sv=%p)\n",lpSV
);
326 IShellView_SelectItem(lpSV
, This
->apidl
[0],
327 SVSI_DESELECTOTHERS
|SVSI_EDIT
|SVSI_ENSUREVISIBLE
|SVSI_FOCUSED
|SVSI_SELECT
);
328 IShellView_Release(lpSV
);
333 /**************************************************************************
336 * deletes the currently selected items
338 static void DoDelete(IContextMenu2
*iface
)
340 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
343 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlp
);
346 ISFHelper_DeleteItems(psfhlp
, This
->cidl
, (LPCITEMIDLIST
*)This
->apidl
);
347 ISFHelper_Release(psfhlp
);
351 /**************************************************************************
354 * copies the currently selected items into the clipboard
356 static BOOL
DoCopyOrCut(
357 IContextMenu2
*iface
,
361 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
367 TRACE("(%p)->(wnd=%p,bCut=0x%08x)\n",This
, hwnd
, bCut
);
369 /* get the active IShellView */
370 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
372 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
374 if (SUCCEEDED(IShellView_GetItemObject(lpSV
, SVGIO_SELECTION
, &IID_IDataObject
, (LPVOID
*)&lpDo
)))
376 OleSetClipboard(lpDo
);
377 IDataObject_Release(lpDo
);
379 IShellView_Release(lpSV
);
384 /**************************************************************************
385 * ISvItemCm_fnInvokeCommand()
387 static HRESULT WINAPI
ISvItemCm_fnInvokeCommand(
388 IContextMenu2
*iface
,
389 LPCMINVOKECOMMANDINFO lpcmi
)
391 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
393 if (lpcmi
->cbSize
!= sizeof(CMINVOKECOMMANDINFO
))
394 FIXME("Is an EX structure\n");
396 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This
,lpcmi
,lpcmi
->lpVerb
, lpcmi
->hwnd
);
398 if( HIWORD(lpcmi
->lpVerb
)==0 && LOWORD(lpcmi
->lpVerb
) > FCIDM_SHVIEWLAST
)
400 TRACE("Invalid Verb %x\n",LOWORD(lpcmi
->lpVerb
));
404 if (HIWORD(lpcmi
->lpVerb
) == 0)
406 switch(LOWORD(lpcmi
->lpVerb
))
408 case FCIDM_SHVIEW_EXPLORE
:
409 TRACE("Verb FCIDM_SHVIEW_EXPLORE\n");
410 DoOpenExplore(iface
, lpcmi
->hwnd
, "explore");
412 case FCIDM_SHVIEW_OPEN
:
413 TRACE("Verb FCIDM_SHVIEW_OPEN\n");
414 DoOpenExplore(iface
, lpcmi
->hwnd
, "open");
416 case FCIDM_SHVIEW_RENAME
:
417 TRACE("Verb FCIDM_SHVIEW_RENAME\n");
418 DoRename(iface
, lpcmi
->hwnd
);
420 case FCIDM_SHVIEW_DELETE
:
421 TRACE("Verb FCIDM_SHVIEW_DELETE\n");
424 case FCIDM_SHVIEW_COPY
:
425 TRACE("Verb FCIDM_SHVIEW_COPY\n");
426 DoCopyOrCut(iface
, lpcmi
->hwnd
, FALSE
);
428 case FCIDM_SHVIEW_CUT
:
429 TRACE("Verb FCIDM_SHVIEW_CUT\n");
430 DoCopyOrCut(iface
, lpcmi
->hwnd
, TRUE
);
433 FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi
->lpVerb
));
438 TRACE("Verb is %s\n",debugstr_a(lpcmi
->lpVerb
));
439 if (strcmp(lpcmi
->lpVerb
,"delete")==0)
442 FIXME("Unhandled string verb %s\n",debugstr_a(lpcmi
->lpVerb
));
447 /**************************************************************************
448 * ISvItemCm_fnGetCommandString()
450 static HRESULT WINAPI
ISvItemCm_fnGetCommandString(
451 IContextMenu2
*iface
,
458 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
460 HRESULT hr
= E_INVALIDARG
;
462 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n",This
, idCommand
, uFlags
, lpReserved
, lpszName
, uMaxNameLen
);
474 case FCIDM_SHVIEW_RENAME
:
475 strcpy(lpszName
, "rename");
481 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
482 case, you need to do the lstrcpyW to the pointer passed.*/
485 { case FCIDM_SHVIEW_RENAME
:
486 MultiByteToWideChar( CP_ACP
, 0, "rename", -1, (LPWSTR
)lpszName
, uMaxNameLen
);
497 TRACE("-- (%p)->(name=%s)\n",This
, lpszName
);
501 /**************************************************************************
502 * ISvItemCm_fnHandleMenuMsg()
504 * should be only in IContextMenu2 and IContextMenu3
505 * is nevertheless called from word95
507 static HRESULT WINAPI
ISvItemCm_fnHandleMenuMsg(
508 IContextMenu2
*iface
,
513 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
515 TRACE("(%p)->(msg=%x wp=%lx lp=%lx)\n",This
, uMsg
, wParam
, lParam
);
520 static const IContextMenu2Vtbl cmvt
=
522 ISvItemCm_fnQueryInterface
,
525 ISvItemCm_fnQueryContextMenu
,
526 ISvItemCm_fnInvokeCommand
,
527 ISvItemCm_fnGetCommandString
,
528 ISvItemCm_fnHandleMenuMsg