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"
39 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
41 /**************************************************************************
42 * IContextMenu Implementation
45 { const IContextMenu2Vtbl
*lpVtbl
;
47 IShellFolder
* pSFParent
;
48 LPITEMIDLIST pidl
; /* root pidl */
49 LPITEMIDLIST
*apidl
; /* array of child pidls */
55 static const IContextMenu2Vtbl cmvt
;
57 /**************************************************************************
58 * ISvItemCm_CanRenameItems()
60 static BOOL
ISvItemCm_CanRenameItems(ItemCmImpl
*This
)
64 TRACE("(%p)->()\n",This
);
68 for(i
= 0; i
< This
->cidl
; i
++){}
69 if(i
> 1) return FALSE
; /* can't rename more than one item at a time*/
70 dwAttributes
= SFGAO_CANRENAME
;
71 IShellFolder_GetAttributesOf(This
->pSFParent
, 1, (LPCITEMIDLIST
*)This
->apidl
, &dwAttributes
);
72 return dwAttributes
& SFGAO_CANRENAME
;
77 /**************************************************************************
78 * ISvItemCm_Constructor()
80 IContextMenu2
*ISvItemCm_Constructor(LPSHELLFOLDER pSFParent
, LPCITEMIDLIST pidl
, LPCITEMIDLIST
*apidl
, UINT cidl
)
84 cm
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ItemCmImpl
));
87 cm
->pidl
= ILClone(pidl
);
88 cm
->pSFParent
= pSFParent
;
90 if(pSFParent
) IShellFolder_AddRef(pSFParent
);
92 cm
->apidl
= _ILCopyaPidl(apidl
, cidl
);
96 for(u
= 0; u
< cidl
; u
++)
98 cm
->bAllValues
&= (_ILIsValue(apidl
[u
]) ? 1 : 0);
101 TRACE("(%p)->()\n",cm
);
103 return (IContextMenu2
*)cm
;
106 /**************************************************************************
107 * ISvItemCm_fnQueryInterface
109 static HRESULT WINAPI
ISvItemCm_fnQueryInterface(IContextMenu2
*iface
, REFIID riid
, LPVOID
*ppvObj
)
111 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
113 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
117 if(IsEqualIID(riid
, &IID_IUnknown
) ||
118 IsEqualIID(riid
, &IID_IContextMenu
) ||
119 IsEqualIID(riid
, &IID_IContextMenu2
))
123 else if(IsEqualIID(riid
, &IID_IShellExtInit
)) /*IShellExtInit*/
125 FIXME("-- LPSHELLEXTINIT pointer requested\n");
130 IUnknown_AddRef((IUnknown
*)*ppvObj
);
131 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
134 TRACE("-- Interface: E_NOINTERFACE\n");
135 return E_NOINTERFACE
;
138 /**************************************************************************
141 static ULONG WINAPI
ISvItemCm_fnAddRef(IContextMenu2
*iface
)
143 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
144 ULONG refCount
= InterlockedIncrement(&This
->ref
);
146 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
151 /**************************************************************************
152 * ISvItemCm_fnRelease
154 static ULONG WINAPI
ISvItemCm_fnRelease(IContextMenu2
*iface
)
156 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
157 ULONG refCount
= InterlockedDecrement(&This
->ref
);
159 TRACE("(%p)->(count=%i)\n", This
, refCount
+ 1);
163 TRACE(" destroying IContextMenu(%p)\n",This
);
166 IShellFolder_Release(This
->pSFParent
);
170 /*make sure the pidl is freed*/
171 _ILFreeaPidl(This
->apidl
, This
->cidl
);
173 HeapFree(GetProcessHeap(),0,This
);
178 /**************************************************************************
181 void WINAPI
_InsertMenuItem (
192 ZeroMemory(&mii
, sizeof(mii
));
193 mii
.cbSize
= sizeof(mii
);
194 if (fType
== MFT_SEPARATOR
)
196 mii
.fMask
= MIIM_ID
| MIIM_TYPE
;
200 mii
.fMask
= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
201 mii
.dwTypeData
= (LPSTR
) dwTypeData
;
206 InsertMenuItemA( hmenu
, indexMenu
, fByPosition
, &mii
);
209 /**************************************************************************
210 * ISvItemCm_fnQueryContextMenu()
211 * FIXME: load menu MENU_SHV_FILE out of resources instead if creating
212 * each menu item by calling _InsertMenuItem()
214 static HRESULT WINAPI
ISvItemCm_fnQueryContextMenu(
215 IContextMenu2
*iface
,
222 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
224 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This
, hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
227 FIXME("We should use idCmdFirst=%d and idCmdLast=%d for command ids\n", idCmdFirst
, idCmdLast
);
229 if(!(CMF_DEFAULTONLY
& uFlags
) && This
->cidl
>0)
231 if(!(uFlags
& CMF_EXPLORE
))
232 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Select", MFS_ENABLED
);
236 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
237 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
);
241 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
);
242 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
245 SetMenuDefaultItem(hmenu
, 0, MF_BYPOSITION
);
247 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, 0, MFT_SEPARATOR
, NULL
, 0);
248 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_COPY
, MFT_STRING
, "&Copy", MFS_ENABLED
);
249 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_CUT
, MFT_STRING
, "&Cut", MFS_ENABLED
);
251 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, 0, MFT_SEPARATOR
, NULL
, 0);
252 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_DELETE
, MFT_STRING
, "&Delete", MFS_ENABLED
);
254 if(uFlags
& CMF_CANRENAME
)
255 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_RENAME
, MFT_STRING
, "&Rename", ISvItemCm_CanRenameItems(This
) ? MFS_ENABLED
: MFS_DISABLED
);
257 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (FCIDM_SHVIEWLAST
));
259 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
262 /**************************************************************************
268 static void DoOpenExplore(
269 IContextMenu2
*iface
,
273 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
275 UINT i
, bFolderFound
= FALSE
;
277 SHELLEXECUTEINFOA sei
;
279 /* Find the first item in the list that is not a value. These commands
280 should never be invoked if there isn't at least one folder item in the list.*/
282 for(i
= 0; i
<This
->cidl
; i
++)
284 if(!_ILIsValue(This
->apidl
[i
]))
291 if (!bFolderFound
) return;
293 pidlFQ
= ILCombine(This
->pidl
, This
->apidl
[i
]);
295 ZeroMemory(&sei
, sizeof(sei
));
296 sei
.cbSize
= sizeof(sei
);
297 sei
.fMask
= SEE_MASK_IDLIST
| SEE_MASK_CLASSNAME
;
298 sei
.lpIDList
= pidlFQ
;
299 sei
.lpClass
= "Folder";
301 sei
.nShow
= SW_SHOWNORMAL
;
303 ShellExecuteExA(&sei
);
307 /**************************************************************************
310 static void DoRename(
311 IContextMenu2
*iface
,
314 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
319 TRACE("(%p)->(wnd=%p)\n",This
, hwnd
);
321 /* get the active IShellView */
322 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
324 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
326 TRACE("(sv=%p)\n",lpSV
);
327 IShellView_SelectItem(lpSV
, This
->apidl
[0],
328 SVSI_DESELECTOTHERS
|SVSI_EDIT
|SVSI_ENSUREVISIBLE
|SVSI_FOCUSED
|SVSI_SELECT
);
329 IShellView_Release(lpSV
);
334 /**************************************************************************
337 * deletes the currently selected items
339 static void DoDelete(IContextMenu2
*iface
)
341 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
344 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlp
);
347 ISFHelper_DeleteItems(psfhlp
, This
->cidl
, (LPCITEMIDLIST
*)This
->apidl
);
348 ISFHelper_Release(psfhlp
);
352 /**************************************************************************
355 * copies the currently selected items into the clipboard
357 static BOOL
DoCopyOrCut(
358 IContextMenu2
*iface
,
362 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
368 TRACE("(%p)->(wnd=%p,bCut=0x%08x)\n",This
, hwnd
, bCut
);
370 /* get the active IShellView */
371 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
373 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
375 if (SUCCEEDED(IShellView_GetItemObject(lpSV
, SVGIO_SELECTION
, &IID_IDataObject
, (LPVOID
*)&lpDo
)))
377 OleSetClipboard(lpDo
);
378 IDataObject_Release(lpDo
);
380 IShellView_Release(lpSV
);
385 /**************************************************************************
386 * ISvItemCm_fnInvokeCommand()
388 static HRESULT WINAPI
ISvItemCm_fnInvokeCommand(
389 IContextMenu2
*iface
,
390 LPCMINVOKECOMMANDINFO lpcmi
)
392 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
394 if (lpcmi
->cbSize
!= sizeof(CMINVOKECOMMANDINFO
))
395 FIXME("Is an EX structure\n");
397 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This
,lpcmi
,lpcmi
->lpVerb
, lpcmi
->hwnd
);
399 if( HIWORD(lpcmi
->lpVerb
)==0 && LOWORD(lpcmi
->lpVerb
) > FCIDM_SHVIEWLAST
)
401 TRACE("Invalid Verb %x\n",LOWORD(lpcmi
->lpVerb
));
405 if (HIWORD(lpcmi
->lpVerb
) == 0)
407 switch(LOWORD(lpcmi
->lpVerb
))
409 case FCIDM_SHVIEW_EXPLORE
:
410 TRACE("Verb FCIDM_SHVIEW_EXPLORE\n");
411 DoOpenExplore(iface
, lpcmi
->hwnd
, "explore");
413 case FCIDM_SHVIEW_OPEN
:
414 TRACE("Verb FCIDM_SHVIEW_OPEN\n");
415 DoOpenExplore(iface
, lpcmi
->hwnd
, "open");
417 case FCIDM_SHVIEW_RENAME
:
418 TRACE("Verb FCIDM_SHVIEW_RENAME\n");
419 DoRename(iface
, lpcmi
->hwnd
);
421 case FCIDM_SHVIEW_DELETE
:
422 TRACE("Verb FCIDM_SHVIEW_DELETE\n");
425 case FCIDM_SHVIEW_COPY
:
426 TRACE("Verb FCIDM_SHVIEW_COPY\n");
427 DoCopyOrCut(iface
, lpcmi
->hwnd
, FALSE
);
429 case FCIDM_SHVIEW_CUT
:
430 TRACE("Verb FCIDM_SHVIEW_CUT\n");
431 DoCopyOrCut(iface
, lpcmi
->hwnd
, TRUE
);
434 FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi
->lpVerb
));
439 TRACE("Verb is %s\n",debugstr_a(lpcmi
->lpVerb
));
440 if (strcmp(lpcmi
->lpVerb
,"delete")==0)
443 FIXME("Unhandled string verb %s\n",debugstr_a(lpcmi
->lpVerb
));
448 /**************************************************************************
449 * ISvItemCm_fnGetCommandString()
451 static HRESULT WINAPI
ISvItemCm_fnGetCommandString(
452 IContextMenu2
*iface
,
459 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
461 HRESULT hr
= E_INVALIDARG
;
463 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n",This
, idCommand
, uFlags
, lpReserved
, lpszName
, uMaxNameLen
);
475 case FCIDM_SHVIEW_RENAME
:
476 strcpy((LPSTR
)lpszName
, "rename");
482 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
483 case, you need to do the lstrcpyW to the pointer passed.*/
486 { case FCIDM_SHVIEW_RENAME
:
487 MultiByteToWideChar( CP_ACP
, 0, "rename", -1, (LPWSTR
)lpszName
, uMaxNameLen
);
498 TRACE("-- (%p)->(name=%s)\n",This
, lpszName
);
502 /**************************************************************************
503 * ISvItemCm_fnHandleMenuMsg()
505 * should be only in IContextMenu2 and IContextMenu3
506 * is nevertheless called from word95
508 static HRESULT WINAPI
ISvItemCm_fnHandleMenuMsg(
509 IContextMenu2
*iface
,
514 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
516 TRACE("(%p)->(msg=%x wp=%lx lp=%lx)\n",This
, uMsg
, wParam
, lParam
);
521 static const IContextMenu2Vtbl cmvt
=
523 ISvItemCm_fnQueryInterface
,
526 ISvItemCm_fnQueryContextMenu
,
527 ISvItemCm_fnInvokeCommand
,
528 ISvItemCm_fnGetCommandString
,
529 ISvItemCm_fnHandleMenuMsg