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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
26 #include "wine/debug.h"
32 #include "undocshell.h"
35 #include "shell32_main.h"
36 #include "shellfolder.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
40 /**************************************************************************
41 * IContextMenu Implementation
44 { ICOM_VFIELD(IContextMenu
);
46 IShellFolder
* pSFParent
;
47 LPITEMIDLIST pidl
; /* root pidl */
48 LPITEMIDLIST
*apidl
; /* array of child pidls */
54 static struct ICOM_VTABLE(IContextMenu
) cmvt
;
56 /**************************************************************************
57 * ISvItemCm_CanRenameItems()
59 static BOOL
ISvItemCm_CanRenameItems(ItemCmImpl
*This
)
63 TRACE("(%p)->()\n",This
);
67 for(i
= 0; i
< This
->cidl
; i
++){}
68 if(i
> 1) return FALSE
; /* can't rename more than one item at a time*/
69 dwAttributes
= SFGAO_CANRENAME
;
70 IShellFolder_GetAttributesOf(This
->pSFParent
, 1, (LPCITEMIDLIST
*)This
->apidl
, &dwAttributes
);
71 return dwAttributes
& SFGAO_CANRENAME
;
76 /**************************************************************************
77 * ISvItemCm_Constructor()
79 IContextMenu
*ISvItemCm_Constructor(LPSHELLFOLDER pSFParent
, LPCITEMIDLIST pidl
, LPCITEMIDLIST
*apidl
, UINT cidl
)
83 cm
= (ItemCmImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ItemCmImpl
));
86 cm
->pidl
= ILClone(pidl
);
87 cm
->pSFParent
= pSFParent
;
89 if(pSFParent
) IShellFolder_AddRef(pSFParent
);
91 cm
->apidl
= _ILCopyaPidl(apidl
, cidl
);
95 for(u
= 0; u
< cidl
; u
++)
97 cm
->bAllValues
&= (_ILIsValue(apidl
[u
]) ? 1 : 0);
100 TRACE("(%p)->()\n",cm
);
102 return (IContextMenu
*)cm
;
105 /**************************************************************************
106 * ISvItemCm_fnQueryInterface
108 static HRESULT WINAPI
ISvItemCm_fnQueryInterface(IContextMenu
*iface
, REFIID riid
, LPVOID
*ppvObj
)
110 ICOM_THIS(ItemCmImpl
, iface
);
112 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
116 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
120 else if(IsEqualIID(riid
, &IID_IContextMenu
)) /*IContextMenu*/
124 else if(IsEqualIID(riid
, &IID_IShellExtInit
)) /*IShellExtInit*/
126 FIXME("-- LPSHELLEXTINIT pointer requested\n");
131 IUnknown_AddRef((IUnknown
*)*ppvObj
);
132 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
135 TRACE("-- Interface: E_NOINTERFACE\n");
136 return E_NOINTERFACE
;
139 /**************************************************************************
142 static ULONG WINAPI
ISvItemCm_fnAddRef(IContextMenu
*iface
)
144 ICOM_THIS(ItemCmImpl
, iface
);
146 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
148 return ++(This
->ref
);
151 /**************************************************************************
152 * ISvItemCm_fnRelease
154 static ULONG WINAPI
ISvItemCm_fnRelease(IContextMenu
*iface
)
156 ICOM_THIS(ItemCmImpl
, iface
);
158 TRACE("(%p)->()\n",This
);
162 TRACE(" destroying IContextMenu(%p)\n",This
);
165 IShellFolder_Release(This
->pSFParent
);
170 /*make sure the pidl is freed*/
171 _ILFreeaPidl(This
->apidl
, This
->cidl
);
173 HeapFree(GetProcessHeap(),0,This
);
179 /**************************************************************************
182 void WINAPI
_InsertMenuItem (
193 ZeroMemory(&mii
, sizeof(mii
));
194 mii
.cbSize
= sizeof(mii
);
195 if (fType
== MFT_SEPARATOR
)
197 mii
.fMask
= MIIM_ID
| MIIM_TYPE
;
201 mii
.fMask
= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
202 mii
.dwTypeData
= dwTypeData
;
207 InsertMenuItemA( hmenu
, indexMenu
, fByPosition
, &mii
);
209 /**************************************************************************
210 * ISvItemCm_fnQueryContextMenu()
213 static HRESULT WINAPI
ISvItemCm_fnQueryContextMenu(
221 ICOM_THIS(ItemCmImpl
, iface
);
223 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This
, hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
225 if(!(CMF_DEFAULTONLY
& uFlags
))
227 if(uFlags
& CMF_EXPLORE
)
231 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
232 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
|MFS_DEFAULT
);
236 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
|MFS_DEFAULT
);
237 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
242 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Select", MFS_ENABLED
|MFS_DEFAULT
);
244 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, 0, MFT_SEPARATOR
, NULL
, 0);
245 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_COPY
, MFT_STRING
, "&Copy", MFS_ENABLED
);
246 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_CUT
, MFT_STRING
, "&Cut", MFS_ENABLED
);
248 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, 0, MFT_SEPARATOR
, NULL
, 0);
249 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_DELETE
, MFT_STRING
, "&Delete", MFS_ENABLED
);
251 if(uFlags
& CMF_CANRENAME
)
252 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_RENAME
, MFT_STRING
, "&Rename", ISvItemCm_CanRenameItems(This
) ? MFS_ENABLED
: MFS_DISABLED
);
254 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (FCIDM_SHVIEWLAST
));
256 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
259 /**************************************************************************
265 static void DoOpenExplore(
270 ICOM_THIS(ItemCmImpl
, iface
);
272 UINT i
, bFolderFound
= FALSE
;
274 SHELLEXECUTEINFOA sei
;
276 /* Find the first item in the list that is not a value. These commands
277 should never be invoked if there isn't at least one folder item in the list.*/
279 for(i
= 0; i
<This
->cidl
; i
++)
281 if(!_ILIsValue(This
->apidl
[i
]))
288 if (!bFolderFound
) return;
290 pidlFQ
= ILCombine(This
->pidl
, This
->apidl
[i
]);
292 ZeroMemory(&sei
, sizeof(sei
));
293 sei
.cbSize
= sizeof(sei
);
294 sei
.fMask
= SEE_MASK_IDLIST
| SEE_MASK_CLASSNAME
;
295 sei
.lpIDList
= pidlFQ
;
296 sei
.lpClass
= "folder";
298 sei
.nShow
= SW_SHOWNORMAL
;
300 ShellExecuteExA(&sei
);
304 /**************************************************************************
307 static void DoRename(
311 ICOM_THIS(ItemCmImpl
, iface
);
316 TRACE("(%p)->(wnd=%p)\n",This
, hwnd
);
318 /* get the active IShellView */
319 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
321 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
323 TRACE("(sv=%p)\n",lpSV
);
324 IShellView_SelectItem(lpSV
, This
->apidl
[0],
325 SVSI_DESELECTOTHERS
|SVSI_EDIT
|SVSI_ENSUREVISIBLE
|SVSI_FOCUSED
|SVSI_SELECT
);
326 IShellView_Release(lpSV
);
331 /**************************************************************************
334 * deletes the currently selected items
336 static void DoDelete(IContextMenu
*iface
)
338 ICOM_THIS(ItemCmImpl
, iface
);
341 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlp
);
344 ISFHelper_DeleteItems(psfhlp
, This
->cidl
, (LPCITEMIDLIST
*)This
->apidl
);
345 ISFHelper_Release(psfhlp
);
349 /**************************************************************************
352 * copies the currently selected items into the clipboard
354 static BOOL
DoCopyOrCut(
359 ICOM_THIS(ItemCmImpl
, iface
);
365 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 pOleSetClipboard(lpDo
);
377 IDataObject_Release(lpDo
);
379 IShellView_Release(lpSV
);
386 the following code does the copy operation witout ole32.dll
387 we might need this possibility too (js)
389 BOOL bSuccess
= FALSE
;
391 TRACE("(%p)\n", iface
);
393 if(OpenClipboard(NULL
))
397 IPersistFolder2
* ppf2
;
398 IShellFolder_QueryInterface(This
->pSFParent
, &IID_IPersistFolder2
, (LPVOID
*)&ppf2
);
402 IPersistFolder2_GetCurFolder(ppf2
, &pidl
);
407 hMem
= RenderHDROP(pidl
, This
->apidl
, This
->cidl
);
409 if(SetClipboardData(CF_HDROP
, hMem
))
415 IPersistFolder2_Release(ppf2
);
424 /**************************************************************************
425 * ISvItemCm_fnInvokeCommand()
427 static HRESULT WINAPI
ISvItemCm_fnInvokeCommand(
429 LPCMINVOKECOMMANDINFO lpcmi
)
431 ICOM_THIS(ItemCmImpl
, iface
);
433 if (lpcmi
->cbSize
!= sizeof(CMINVOKECOMMANDINFO
))
434 FIXME("Is an EX structure\n");
436 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This
,lpcmi
,lpcmi
->lpVerb
, lpcmi
->hwnd
);
438 if( HIWORD(lpcmi
->lpVerb
)==0 && LOWORD(lpcmi
->lpVerb
) > FCIDM_SHVIEWLAST
)
440 TRACE("Invalid Verb %x\n",LOWORD(lpcmi
->lpVerb
));
444 if (HIWORD(lpcmi
->lpVerb
) == 0)
446 switch(LOWORD(lpcmi
->lpVerb
))
448 case FCIDM_SHVIEW_EXPLORE
:
449 TRACE("Verb FCIDM_SHVIEW_EXPLORE\n");
450 DoOpenExplore(iface
, lpcmi
->hwnd
, "explore");
452 case FCIDM_SHVIEW_OPEN
:
453 TRACE("Verb FCIDM_SHVIEW_OPEN\n");
454 DoOpenExplore(iface
, lpcmi
->hwnd
, "open");
456 case FCIDM_SHVIEW_RENAME
:
457 TRACE("Verb FCIDM_SHVIEW_RENAME\n");
458 DoRename(iface
, lpcmi
->hwnd
);
460 case FCIDM_SHVIEW_DELETE
:
461 TRACE("Verb FCIDM_SHVIEW_DELETE\n");
464 case FCIDM_SHVIEW_COPY
:
465 TRACE("Verb FCIDM_SHVIEW_COPY\n");
466 DoCopyOrCut(iface
, lpcmi
->hwnd
, FALSE
);
468 case FCIDM_SHVIEW_CUT
:
469 TRACE("Verb FCIDM_SHVIEW_CUT\n");
470 DoCopyOrCut(iface
, lpcmi
->hwnd
, TRUE
);
473 FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi
->lpVerb
));
478 TRACE("Verb is %s\n",debugstr_a(lpcmi
->lpVerb
));
479 if (strcmp(lpcmi
->lpVerb
,"delete")==0)
482 FIXME("Unhandled string verb %s\n",debugstr_a(lpcmi
->lpVerb
));
487 /**************************************************************************
488 * ISvItemCm_fnGetCommandString()
490 static HRESULT WINAPI
ISvItemCm_fnGetCommandString(
498 ICOM_THIS(ItemCmImpl
, iface
);
500 HRESULT hr
= E_INVALIDARG
;
502 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This
, idCommand
, uFlags
, lpReserved
, lpszName
, uMaxNameLen
);
513 case FCIDM_SHVIEW_RENAME
:
514 strcpy((LPSTR
)lpszName
, "rename");
520 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
521 case, you need to do the lstrcpyW to the pointer passed.*/
524 { case FCIDM_SHVIEW_RENAME
:
525 MultiByteToWideChar( CP_ACP
, 0, "rename", -1, (LPWSTR
)lpszName
, uMaxNameLen
);
535 TRACE("-- (%p)->(name=%s)\n",This
, lpszName
);
539 /**************************************************************************
540 * ISvItemCm_fnHandleMenuMsg()
542 * should be only in IContextMenu2 and IContextMenu3
543 * is nevertheless called from word95
545 static HRESULT WINAPI
ISvItemCm_fnHandleMenuMsg(
551 ICOM_THIS(ItemCmImpl
, iface
);
553 TRACE("(%p)->(msg=%x wp=%x lp=%lx)\n",This
, uMsg
, wParam
, lParam
);
558 static struct ICOM_VTABLE(IContextMenu
) cmvt
=
560 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
561 ISvItemCm_fnQueryInterface
,
564 ISvItemCm_fnQueryContextMenu
,
565 ISvItemCm_fnInvokeCommand
,
566 ISvItemCm_fnGetCommandString
,
567 ISvItemCm_fnHandleMenuMsg
,
568 (void *) 0xdeadbabe /* just paranoia */