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
24 #include "wine/debug.h"
28 #include "wine/obj_base.h"
29 #include "wine/obj_contextmenu.h"
30 #include "wine/obj_shellbrowser.h"
31 #include "wine/obj_shellextinit.h"
32 #include "undocshell.h"
34 #include "shell32_main.h"
35 #include "shellfolder.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
39 /**************************************************************************
40 * IContextMenu Implementation
43 { ICOM_VFIELD(IContextMenu
);
45 IShellFolder
* pSFParent
;
46 LPITEMIDLIST pidl
; /* root pidl */
47 LPITEMIDLIST
*apidl
; /* array of child pidls */
53 static struct ICOM_VTABLE(IContextMenu
) cmvt
;
55 /**************************************************************************
56 * ISvItemCm_CanRenameItems()
58 static BOOL
ISvItemCm_CanRenameItems(ItemCmImpl
*This
)
62 TRACE("(%p)->()\n",This
);
66 for(i
= 0; i
< This
->cidl
; i
++){}
67 if(i
> 1) return FALSE
; /* can't rename more than one item at a time*/
68 dwAttributes
= SFGAO_CANRENAME
;
69 IShellFolder_GetAttributesOf(This
->pSFParent
, 1, This
->apidl
, &dwAttributes
);
70 return dwAttributes
& SFGAO_CANRENAME
;
75 /**************************************************************************
76 * ISvItemCm_Constructor()
78 IContextMenu
*ISvItemCm_Constructor(LPSHELLFOLDER pSFParent
, LPCITEMIDLIST pidl
, LPCITEMIDLIST
*apidl
, UINT cidl
)
82 cm
= (ItemCmImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(ItemCmImpl
));
85 cm
->pidl
= ILClone(pidl
);
86 cm
->pSFParent
= pSFParent
;
88 if(pSFParent
) IShellFolder_AddRef(pSFParent
);
90 cm
->apidl
= _ILCopyaPidl(apidl
, cidl
);
94 for(u
= 0; u
< cidl
; u
++)
96 cm
->bAllValues
&= (_ILIsValue(apidl
[u
]) ? 1 : 0);
99 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
);
149 return ++(This
->ref
);
152 /**************************************************************************
153 * ISvItemCm_fnRelease
155 static ULONG WINAPI
ISvItemCm_fnRelease(IContextMenu
*iface
)
157 ICOM_THIS(ItemCmImpl
, iface
);
159 TRACE("(%p)->()\n",This
);
165 TRACE(" destroying IContextMenu(%p)\n",This
);
168 IShellFolder_Release(This
->pSFParent
);
173 /*make sure the pidl is freed*/
174 _ILFreeaPidl(This
->apidl
, This
->cidl
);
176 HeapFree(GetProcessHeap(),0,This
);
182 /**************************************************************************
185 void WINAPI
_InsertMenuItem (
196 ZeroMemory(&mii
, sizeof(mii
));
197 mii
.cbSize
= sizeof(mii
);
198 if (fType
== MFT_SEPARATOR
)
200 mii
.fMask
= MIIM_ID
| MIIM_TYPE
;
204 mii
.fMask
= MIIM_ID
| MIIM_TYPE
| MIIM_STATE
;
205 mii
.dwTypeData
= dwTypeData
;
210 InsertMenuItemA( hmenu
, indexMenu
, fByPosition
, &mii
);
212 /**************************************************************************
213 * ISvItemCm_fnQueryContextMenu()
216 static HRESULT WINAPI
ISvItemCm_fnQueryContextMenu(
224 ICOM_THIS(ItemCmImpl
, iface
);
226 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This
, hmenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
228 if(!(CMF_DEFAULTONLY
& uFlags
))
230 if(uFlags
& CMF_EXPLORE
)
234 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
235 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
|MFS_DEFAULT
);
239 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_EXPLORE
, MFT_STRING
, "&Explore", MFS_ENABLED
|MFS_DEFAULT
);
240 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Open", MFS_ENABLED
);
245 _InsertMenuItem(hmenu
, indexMenu
++, TRUE
, FCIDM_SHVIEW_OPEN
, MFT_STRING
, "&Select", MFS_ENABLED
|MFS_DEFAULT
);
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(
273 ICOM_THIS(ItemCmImpl
, iface
);
275 int 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(
314 ICOM_THIS(ItemCmImpl
, iface
);
319 TRACE("(%p)->(wnd=%x)\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(IContextMenu
*iface
)
341 ICOM_THIS(ItemCmImpl
, iface
);
344 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlp
);
347 ISFHelper_DeleteItems(psfhlp
, This
->cidl
, This
->apidl
);
348 ISFHelper_Release(psfhlp
);
352 /**************************************************************************
355 * copies the currently selected items into the clipboard
357 static BOOL
DoCopyOrCut(
362 ICOM_THIS(ItemCmImpl
, iface
);
368 TRACE("(%p)->(wnd=0x%04x,bCut=0x%08x)\n",This
, hwnd
, bCut
);
372 /* get the active IShellView */
373 if ((lpSB
= (LPSHELLBROWSER
)SendMessageA(hwnd
, CWM_GETISHELLBROWSER
,0,0)))
375 if (SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
377 if (SUCCEEDED(IShellView_GetItemObject(lpSV
, SVGIO_SELECTION
, &IID_IDataObject
, (LPVOID
*)&lpDo
)))
379 pOleSetClipboard(lpDo
);
380 IDataObject_Release(lpDo
);
382 IShellView_Release(lpSV
);
389 the following code does the copy operation witout ole32.dll
390 we might need this possibility too (js)
392 BOOL bSuccess
= FALSE
;
394 TRACE("(%p)\n", iface
);
396 if(OpenClipboard(NULL
))
400 IPersistFolder2
* ppf2
;
401 IShellFolder_QueryInterface(This
->pSFParent
, &IID_IPersistFolder2
, (LPVOID
*)&ppf2
);
405 IPersistFolder2_GetCurFolder(ppf2
, &pidl
);
410 hMem
= RenderHDROP(pidl
, This
->apidl
, This
->cidl
);
412 if(SetClipboardData(CF_HDROP
, hMem
))
418 IPersistFolder2_Release(ppf2
);
427 /**************************************************************************
428 * ISvItemCm_fnInvokeCommand()
430 static HRESULT WINAPI
ISvItemCm_fnInvokeCommand(
432 LPCMINVOKECOMMANDINFO lpcmi
)
434 ICOM_THIS(ItemCmImpl
, iface
);
436 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This
,lpcmi
,lpcmi
->lpVerb
, lpcmi
->hwnd
);
438 if(LOWORD(lpcmi
->lpVerb
) > FCIDM_SHVIEWLAST
) return E_INVALIDARG
;
440 switch(LOWORD(lpcmi
->lpVerb
))
442 case FCIDM_SHVIEW_EXPLORE
:
443 DoOpenExplore(iface
, lpcmi
->hwnd
, "explore");
445 case FCIDM_SHVIEW_OPEN
:
446 DoOpenExplore(iface
, lpcmi
->hwnd
, "open");
448 case FCIDM_SHVIEW_RENAME
:
449 DoRename(iface
, lpcmi
->hwnd
);
451 case FCIDM_SHVIEW_DELETE
:
454 case FCIDM_SHVIEW_COPY
:
455 DoCopyOrCut(iface
, lpcmi
->hwnd
, FALSE
);
457 case FCIDM_SHVIEW_CUT
:
458 DoCopyOrCut(iface
, lpcmi
->hwnd
, TRUE
);
464 /**************************************************************************
465 * ISvItemCm_fnGetCommandString()
467 static HRESULT WINAPI
ISvItemCm_fnGetCommandString(
475 ICOM_THIS(ItemCmImpl
, iface
);
477 HRESULT hr
= E_INVALIDARG
;
479 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This
, idCommand
, uFlags
, lpReserved
, lpszName
, uMaxNameLen
);
490 case FCIDM_SHVIEW_RENAME
:
491 strcpy((LPSTR
)lpszName
, "rename");
497 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
498 case, you need to do the lstrcpyW to the pointer passed.*/
501 { case FCIDM_SHVIEW_RENAME
:
502 MultiByteToWideChar( CP_ACP
, 0, "rename", -1, (LPWSTR
)lpszName
, uMaxNameLen
);
512 TRACE("-- (%p)->(name=%s)\n",This
, lpszName
);
516 /**************************************************************************
517 * ISvItemCm_fnHandleMenuMsg()
519 * should be only in IContextMenu2 and IContextMenu3
520 * is nevertheless called from word95
522 static HRESULT WINAPI
ISvItemCm_fnHandleMenuMsg(
528 ICOM_THIS(ItemCmImpl
, iface
);
530 TRACE("(%p)->(msg=%x wp=%x lp=%lx)\n",This
, uMsg
, wParam
, lParam
);
535 static struct ICOM_VTABLE(IContextMenu
) cmvt
=
537 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
538 ISvItemCm_fnQueryInterface
,
541 ISvItemCm_fnQueryContextMenu
,
542 ISvItemCm_fnInvokeCommand
,
543 ISvItemCm_fnGetCommandString
,
544 ISvItemCm_fnHandleMenuMsg
,
545 (void *) 0xdeadbabe /* just paranoia */