2 * IContextMenu for items in the shellview
4 * 1998, 2000 Juergen Schmied <juergen.schmied@debitel.net>
9 #include "debugtools.h"
12 #include "wine/obj_base.h"
13 #include "wine/obj_contextmenu.h"
14 #include "wine/obj_shellbrowser.h"
15 #include "wine/obj_shellextinit.h"
16 #include "wine/undocshell.h"
18 #include "shell32_main.h"
19 #include "shellfolder.h"
20 #include "shell.h" /* DROPFILESTRUCT */
22 DEFAULT_DEBUG_CHANNEL(shell
)
24 /**************************************************************************
25 * IContextMenu Implementation
28 { ICOM_VFIELD(IContextMenu
);
30 IShellFolder
* pSFParent
;
31 LPITEMIDLIST pidl
; /* root pidl */
32 LPITEMIDLIST
*apidl
; /* array of child pidls */
38 static struct ICOM_VTABLE(IContextMenu
) cmvt
;
40 /**************************************************************************
41 * ISvItemCm_CanRenameItems()
43 static BOOL
ISvItemCm_CanRenameItems(ItemCmImpl
*This
)
47 TRACE("(%p)->()\n",This
);
51 for(i
= 0; i
< This
->cidl
; i
++){}
52 if(i
> 1) return FALSE
; /* can't rename more than one item at a time*/
53 dwAttributes
= SFGAO_CANRENAME
;
54 IShellFolder_GetAttributesOf(This
->pSFParent
, 1, This
->apidl
, &dwAttributes
);
55 return dwAttributes
& SFGAO_CANRENAME
;
60 /**************************************************************************
61 * ISvItemCm_Constructor()
63 IContextMenu
*ISvItemCm_Constructor(LPSHELLFOLDER pSFParent
, LPCITEMIDLIST pidl
, LPCITEMIDLIST
*apidl
, UINT cidl
)
67 cm
= (ItemCmImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ItemCmImpl
));
70 cm
->pidl
= ILClone(pidl
);
71 cm
->pSFParent
= pSFParent
;
73 if(pSFParent
) IShellFolder_AddRef(pSFParent
);
75 cm
->apidl
= _ILCopyaPidl(apidl
, cidl
);
79 for(u
= 0; u
< cidl
; u
++)
81 cm
->bAllValues
&= (_ILIsValue(apidl
[u
]) ? 1 : 0);
84 TRACE("(%p)->()\n",cm
);
87 return (IContextMenu
*)cm
;
90 /**************************************************************************
91 * ISvItemCm_fnQueryInterface
93 static HRESULT WINAPI
ISvItemCm_fnQueryInterface(IContextMenu
*iface
, REFIID riid
, LPVOID
*ppvObj
)
95 ICOM_THIS(ItemCmImpl
, iface
);
97 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
101 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
105 else if(IsEqualIID(riid
, &IID_IContextMenu
)) /*IContextMenu*/
109 else if(IsEqualIID(riid
, &IID_IShellExtInit
)) /*IShellExtInit*/
111 FIXME("-- LPSHELLEXTINIT pointer requested\n");
116 IUnknown_AddRef((IUnknown
*)*ppvObj
);
117 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
120 TRACE("-- Interface: E_NOINTERFACE\n");
121 return E_NOINTERFACE
;
124 /**************************************************************************
127 static ULONG WINAPI
ISvItemCm_fnAddRef(IContextMenu
*iface
)
129 ICOM_THIS(ItemCmImpl
, iface
);
131 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
134 return ++(This
->ref
);
137 /**************************************************************************
138 * ISvItemCm_fnRelease
140 static ULONG WINAPI
ISvItemCm_fnRelease(IContextMenu
*iface
)
142 ICOM_THIS(ItemCmImpl
, iface
);
144 TRACE("(%p)->()\n",This
);
150 TRACE(" destroying IContextMenu(%p)\n",This
);
153 IShellFolder_Release(This
->pSFParent
);
158 /*make sure the pidl is freed*/
159 _ILFreeaPidl(This
->apidl
, This
->cidl
);
161 HeapFree(GetProcessHeap(),0,This
);
167 /**************************************************************************
170 void WINAPI
_InsertMenuItem (
181 ZeroMemory(&mii
, sizeof(mii
));
182 mii
.cbSize
= sizeof(mii
);
183 if (fType
== MFT_SEPARATOR
)
185 mii
.fMask
= MIIM_ID
| MIIM_TYPE
;
189 mii
.fMask
= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
190 mii
.dwTypeData
= dwTypeData
;
195 InsertMenuItemA( hmenu
, indexMenu
, fByPosition
, &mii
);
197 /**************************************************************************
198 * ISvItemCm_fnQueryContextMenu()
201 static HRESULT WINAPI
ISvItemCm_fnQueryContextMenu(
209 ICOM_THIS(ItemCmImpl
, iface
);
211 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This
, hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
213 if(!(CMF_DEFAULTONLY
& uFlags
))
215 if(uFlags
& CMF_EXPLORE
)
219 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
220 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
|MFS_DEFAULT
);
224 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
|MFS_DEFAULT
);
225 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
230 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Select", MFS_ENABLED
|MFS_DEFAULT
);
232 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, 0, MFT_SEPARATOR
, NULL
, 0);
233 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_COPY
, MFT_STRING
, "&Copy", MFS_ENABLED
);
234 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_CUT
, MFT_STRING
, "&Cut", MFS_ENABLED
);
236 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, 0, MFT_SEPARATOR
, NULL
, 0);
237 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_DELETE
, MFT_STRING
, "&Delete", MFS_ENABLED
);
239 if(uFlags
& CMF_CANRENAME
)
240 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_RENAME
, MFT_STRING
, "&Rename", ISvItemCm_CanRenameItems(This
) ? MFS_ENABLED
: MFS_DISABLED
);
242 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (FCIDM_SHVIEWLAST
));
244 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
247 /**************************************************************************
253 static void DoOpenExplore(
258 ICOM_THIS(ItemCmImpl
, iface
);
260 int i
, bFolderFound
= FALSE
;
262 SHELLEXECUTEINFOA sei
;
264 /* Find the first item in the list that is not a value. These commands
265 should never be invoked if there isn't at least one folder item in the list.*/
267 for(i
= 0; i
<This
->cidl
; i
++)
269 if(!_ILIsValue(This
->apidl
[i
]))
276 if (!bFolderFound
) return;
278 pidlFQ
= ILCombine(This
->pidl
, This
->apidl
[i
]);
280 ZeroMemory(&sei
, sizeof(sei
));
281 sei
.cbSize
= sizeof(sei
);
282 sei
.fMask
= SEE_MASK_IDLIST
| SEE_MASK_CLASSNAME
;
283 sei
.lpIDList
= pidlFQ
;
284 sei
.lpClass
= "folder";
286 sei
.nShow
= SW_SHOWNORMAL
;
288 ShellExecuteExA(&sei
);
292 /**************************************************************************
295 static void DoRename(
299 ICOM_THIS(ItemCmImpl
, iface
);
304 TRACE("(%p)->(wnd=%x)\n",This
, hwnd
);
306 /* get the active IShellView */
307 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
309 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
311 TRACE("(sv=%p)\n",lpSV
);
312 IShellView_SelectItem(lpSV
, This
->apidl
[0],
313 SVSI_DESELECTOTHERS
|SVSI_EDIT
|SVSI_ENSUREVISIBLE
|SVSI_FOCUSED
|SVSI_SELECT
);
314 IShellView_Release(lpSV
);
319 /**************************************************************************
322 * deletes the currently selected items
324 static void DoDelete(IContextMenu
*iface
)
326 ICOM_THIS(ItemCmImpl
, iface
);
329 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlp
);
332 ISFHelper_DeleteItems(psfhlp
, This
->cidl
, This
->apidl
);
333 ISFHelper_Release(psfhlp
);
337 /**************************************************************************
340 * copys the currently selected items into the clipboard
342 static BOOL
DoCopyOrCut(
347 ICOM_THIS(ItemCmImpl
, iface
);
353 TRACE("(%p)->(wnd=0x%04x,bCut=0x%08x)\n",This
, hwnd
, bCut
);
357 /* get the active IShellView */
358 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
360 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
362 if (SUCCEEDED(IShellView_GetItemObject(lpSV
, SVGIO_SELECTION
, &IID_IDataObject
, (LPVOID
*)&lpDo
)))
364 pOleSetClipboard(lpDo
);
365 IDataObject_Release(lpDo
);
367 IShellView_Release(lpSV
);
374 the following code does the copy operation witout ole32.dll
375 we might need this possibility too (js)
377 BOOL bSuccess
= FALSE
;
379 TRACE("(%p)\n", iface
);
381 if(OpenClipboard(NULL
))
385 IPersistFolder2
* ppf2
;
386 IShellFolder_QueryInterface(This
->pSFParent
, &IID_IPersistFolder2
, (LPVOID
*)&ppf2
);
390 IPersistFolder2_GetCurFolder(ppf2
, &pidl
);
395 hMem
= RenderHDROP(pidl
, This
->apidl
, This
->cidl
);
397 if(SetClipboardData(CF_HDROP
, hMem
))
403 IPersistFolder2_Release(ppf2
);
412 /**************************************************************************
413 * ISvItemCm_fnInvokeCommand()
415 static HRESULT WINAPI
ISvItemCm_fnInvokeCommand(
417 LPCMINVOKECOMMANDINFO lpcmi
)
419 ICOM_THIS(ItemCmImpl
, iface
);
421 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This
,lpcmi
,lpcmi
->lpVerb
, lpcmi
->hwnd
);
423 if(LOWORD(lpcmi
->lpVerb
) > FCIDM_SHVIEWLAST
) return E_INVALIDARG
;
425 switch(LOWORD(lpcmi
->lpVerb
))
427 case FCIDM_SHVIEW_EXPLORE
:
428 DoOpenExplore(iface
, lpcmi
->hwnd
, "explore");
430 case FCIDM_SHVIEW_OPEN
:
431 DoOpenExplore(iface
, lpcmi
->hwnd
, "open");
433 case FCIDM_SHVIEW_RENAME
:
434 DoRename(iface
, lpcmi
->hwnd
);
436 case FCIDM_SHVIEW_DELETE
:
439 case FCIDM_SHVIEW_COPY
:
440 DoCopyOrCut(iface
, lpcmi
->hwnd
, FALSE
);
442 case FCIDM_SHVIEW_CUT
:
443 DoCopyOrCut(iface
, lpcmi
->hwnd
, TRUE
);
449 /**************************************************************************
450 * ISvItemCm_fnGetCommandString()
452 static HRESULT WINAPI
ISvItemCm_fnGetCommandString(
460 ICOM_THIS(ItemCmImpl
, iface
);
462 HRESULT hr
= E_INVALIDARG
;
464 TRACE("(%p)->(idcom=%x 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 lstrcpyAtoW((LPWSTR
)lpszName
, "rename");
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(
513 ICOM_THIS(ItemCmImpl
, iface
);
515 TRACE("(%p)->(msg=%x wp=%x lp=%lx)\n",This
, uMsg
, wParam
, lParam
);
520 static struct ICOM_VTABLE(IContextMenu
) cmvt
=
522 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
523 ISvItemCm_fnQueryInterface
,
526 ISvItemCm_fnQueryContextMenu
,
527 ISvItemCm_fnInvokeCommand
,
528 ISvItemCm_fnGetCommandString
,
529 ISvItemCm_fnHandleMenuMsg
,
530 (void *) 0xdeadbabe /* just paranoia */