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 { IContextMenu2Vtbl
*lpVtbl
;
46 IShellFolder
* pSFParent
;
47 LPITEMIDLIST pidl
; /* root pidl */
48 LPITEMIDLIST
*apidl
; /* array of child pidls */
54 static struct IContextMenu2Vtbl 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 IContextMenu2
*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 (IContextMenu2
*)cm
;
105 /**************************************************************************
106 * ISvItemCm_fnQueryInterface
108 static HRESULT WINAPI
ISvItemCm_fnQueryInterface(IContextMenu2
*iface
, REFIID riid
, LPVOID
*ppvObj
)
110 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
112 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
116 if(IsEqualIID(riid
, &IID_IUnknown
) ||
117 IsEqualIID(riid
, &IID_IContextMenu
) ||
118 IsEqualIID(riid
, &IID_IContextMenu2
))
122 else if(IsEqualIID(riid
, &IID_IShellExtInit
)) /*IShellExtInit*/
124 FIXME("-- LPSHELLEXTINIT pointer requested\n");
129 IUnknown_AddRef((IUnknown
*)*ppvObj
);
130 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
133 TRACE("-- Interface: E_NOINTERFACE\n");
134 return E_NOINTERFACE
;
137 /**************************************************************************
140 static ULONG WINAPI
ISvItemCm_fnAddRef(IContextMenu2
*iface
)
142 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
144 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
146 return ++(This
->ref
);
149 /**************************************************************************
150 * ISvItemCm_fnRelease
152 static ULONG WINAPI
ISvItemCm_fnRelease(IContextMenu2
*iface
)
154 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
156 TRACE("(%p)->()\n",This
);
160 TRACE(" destroying IContextMenu(%p)\n",This
);
163 IShellFolder_Release(This
->pSFParent
);
168 /*make sure the pidl is freed*/
169 _ILFreeaPidl(This
->apidl
, This
->cidl
);
171 HeapFree(GetProcessHeap(),0,This
);
177 /**************************************************************************
180 void WINAPI
_InsertMenuItem (
191 ZeroMemory(&mii
, sizeof(mii
));
192 mii
.cbSize
= sizeof(mii
);
193 if (fType
== MFT_SEPARATOR
)
195 mii
.fMask
= MIIM_ID
| MIIM_TYPE
;
199 mii
.fMask
= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
200 mii
.dwTypeData
= dwTypeData
;
205 InsertMenuItemA( hmenu
, indexMenu
, fByPosition
, &mii
);
207 /**************************************************************************
208 * ISvItemCm_fnQueryContextMenu()
211 static HRESULT WINAPI
ISvItemCm_fnQueryContextMenu(
212 IContextMenu2
*iface
,
219 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
221 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This
, hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
223 if(!(CMF_DEFAULTONLY
& uFlags
))
225 if(uFlags
& CMF_EXPLORE
)
229 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
230 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
|MFS_DEFAULT
);
234 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
|MFS_DEFAULT
);
235 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
240 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Select", MFS_ENABLED
|MFS_DEFAULT
);
242 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, 0, MFT_SEPARATOR
, NULL
, 0);
243 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_COPY
, MFT_STRING
, "&Copy", MFS_ENABLED
);
244 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_CUT
, MFT_STRING
, "&Cut", MFS_ENABLED
);
246 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, 0, MFT_SEPARATOR
, NULL
, 0);
247 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_DELETE
, MFT_STRING
, "&Delete", MFS_ENABLED
);
249 if(uFlags
& CMF_CANRENAME
)
250 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_RENAME
, MFT_STRING
, "&Rename", ISvItemCm_CanRenameItems(This
) ? MFS_ENABLED
: MFS_DISABLED
);
252 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, (FCIDM_SHVIEWLAST
));
254 return MAKE_HRESULT(SEVERITY_SUCCESS
, 0, 0);
257 /**************************************************************************
263 static void DoOpenExplore(
264 IContextMenu2
*iface
,
268 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
270 UINT i
, bFolderFound
= FALSE
;
272 SHELLEXECUTEINFOA sei
;
274 /* Find the first item in the list that is not a value. These commands
275 should never be invoked if there isn't at least one folder item in the list.*/
277 for(i
= 0; i
<This
->cidl
; i
++)
279 if(!_ILIsValue(This
->apidl
[i
]))
286 if (!bFolderFound
) return;
288 pidlFQ
= ILCombine(This
->pidl
, This
->apidl
[i
]);
290 ZeroMemory(&sei
, sizeof(sei
));
291 sei
.cbSize
= sizeof(sei
);
292 sei
.fMask
= SEE_MASK_IDLIST
| SEE_MASK_CLASSNAME
;
293 sei
.lpIDList
= pidlFQ
;
294 sei
.lpClass
= "folder";
296 sei
.nShow
= SW_SHOWNORMAL
;
298 ShellExecuteExA(&sei
);
302 /**************************************************************************
305 static void DoRename(
306 IContextMenu2
*iface
,
309 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
314 TRACE("(%p)->(wnd=%p)\n",This
, hwnd
);
316 /* get the active IShellView */
317 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
319 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
321 TRACE("(sv=%p)\n",lpSV
);
322 IShellView_SelectItem(lpSV
, This
->apidl
[0],
323 SVSI_DESELECTOTHERS
|SVSI_EDIT
|SVSI_ENSUREVISIBLE
|SVSI_FOCUSED
|SVSI_SELECT
);
324 IShellView_Release(lpSV
);
329 /**************************************************************************
332 * deletes the currently selected items
334 static void DoDelete(IContextMenu2
*iface
)
336 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
339 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlp
);
342 ISFHelper_DeleteItems(psfhlp
, This
->cidl
, (LPCITEMIDLIST
*)This
->apidl
);
343 ISFHelper_Release(psfhlp
);
347 /**************************************************************************
350 * copies the currently selected items into the clipboard
352 static BOOL
DoCopyOrCut(
353 IContextMenu2
*iface
,
357 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
363 TRACE("(%p)->(wnd=%p,bCut=0x%08x)\n",This
, hwnd
, bCut
);
365 /* get the active IShellView */
366 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
368 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
370 if (SUCCEEDED(IShellView_GetItemObject(lpSV
, SVGIO_SELECTION
, &IID_IDataObject
, (LPVOID
*)&lpDo
)))
372 OleSetClipboard(lpDo
);
373 IDataObject_Release(lpDo
);
375 IShellView_Release(lpSV
);
380 /**************************************************************************
381 * ISvItemCm_fnInvokeCommand()
383 static HRESULT WINAPI
ISvItemCm_fnInvokeCommand(
384 IContextMenu2
*iface
,
385 LPCMINVOKECOMMANDINFO lpcmi
)
387 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
389 if (lpcmi
->cbSize
!= sizeof(CMINVOKECOMMANDINFO
))
390 FIXME("Is an EX structure\n");
392 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This
,lpcmi
,lpcmi
->lpVerb
, lpcmi
->hwnd
);
394 if( HIWORD(lpcmi
->lpVerb
)==0 && LOWORD(lpcmi
->lpVerb
) > FCIDM_SHVIEWLAST
)
396 TRACE("Invalid Verb %x\n",LOWORD(lpcmi
->lpVerb
));
400 if (HIWORD(lpcmi
->lpVerb
) == 0)
402 switch(LOWORD(lpcmi
->lpVerb
))
404 case FCIDM_SHVIEW_EXPLORE
:
405 TRACE("Verb FCIDM_SHVIEW_EXPLORE\n");
406 DoOpenExplore(iface
, lpcmi
->hwnd
, "explore");
408 case FCIDM_SHVIEW_OPEN
:
409 TRACE("Verb FCIDM_SHVIEW_OPEN\n");
410 DoOpenExplore(iface
, lpcmi
->hwnd
, "open");
412 case FCIDM_SHVIEW_RENAME
:
413 TRACE("Verb FCIDM_SHVIEW_RENAME\n");
414 DoRename(iface
, lpcmi
->hwnd
);
416 case FCIDM_SHVIEW_DELETE
:
417 TRACE("Verb FCIDM_SHVIEW_DELETE\n");
420 case FCIDM_SHVIEW_COPY
:
421 TRACE("Verb FCIDM_SHVIEW_COPY\n");
422 DoCopyOrCut(iface
, lpcmi
->hwnd
, FALSE
);
424 case FCIDM_SHVIEW_CUT
:
425 TRACE("Verb FCIDM_SHVIEW_CUT\n");
426 DoCopyOrCut(iface
, lpcmi
->hwnd
, TRUE
);
429 FIXME("Unhandled Verb %xl\n",LOWORD(lpcmi
->lpVerb
));
434 TRACE("Verb is %s\n",debugstr_a(lpcmi
->lpVerb
));
435 if (strcmp(lpcmi
->lpVerb
,"delete")==0)
438 FIXME("Unhandled string verb %s\n",debugstr_a(lpcmi
->lpVerb
));
443 /**************************************************************************
444 * ISvItemCm_fnGetCommandString()
446 static HRESULT WINAPI
ISvItemCm_fnGetCommandString(
447 IContextMenu2
*iface
,
454 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
456 HRESULT hr
= E_INVALIDARG
;
458 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This
, idCommand
, uFlags
, lpReserved
, lpszName
, uMaxNameLen
);
470 case FCIDM_SHVIEW_RENAME
:
471 strcpy((LPSTR
)lpszName
, "rename");
477 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
478 case, you need to do the lstrcpyW to the pointer passed.*/
481 { case FCIDM_SHVIEW_RENAME
:
482 MultiByteToWideChar( CP_ACP
, 0, "rename", -1, (LPWSTR
)lpszName
, uMaxNameLen
);
493 TRACE("-- (%p)->(name=%s)\n",This
, lpszName
);
497 /**************************************************************************
498 * ISvItemCm_fnHandleMenuMsg()
500 * should be only in IContextMenu2 and IContextMenu3
501 * is nevertheless called from word95
503 static HRESULT WINAPI
ISvItemCm_fnHandleMenuMsg(
504 IContextMenu2
*iface
,
509 ItemCmImpl
*This
= (ItemCmImpl
*)iface
;
511 TRACE("(%p)->(msg=%x wp=%x lp=%lx)\n",This
, uMsg
, wParam
, lParam
);
516 static struct IContextMenu2Vtbl cmvt
=
518 ISvItemCm_fnQueryInterface
,
521 ISvItemCm_fnQueryContextMenu
,
522 ISvItemCm_fnInvokeCommand
,
523 ISvItemCm_fnGetCommandString
,
524 ISvItemCm_fnHandleMenuMsg