4 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
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"
20 DEFAULT_DEBUG_CHANNEL(shell)
22 /**************************************************************************
27 static HRESULT WINAPI IContextMenu_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj);
28 static ULONG WINAPI IContextMenu_fnAddRef(IContextMenu *iface);
29 static ULONG WINAPI IContextMenu_fnRelease(IContextMenu *iface);
30 static HRESULT WINAPI IContextMenu_fnQueryContextMenu(IContextMenu *iface, HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags);
31 static HRESULT WINAPI IContextMenu_fnInvokeCommand(IContextMenu *iface, LPCMINVOKECOMMANDINFO lpcmi);
32 static HRESULT WINAPI IContextMenu_fnGetCommandString(IContextMenu *iface, UINT idCommand, UINT uFlags, LPUINT lpReserved, LPSTR lpszName, UINT uMaxNameLen);
33 static HRESULT WINAPI IContextMenu_fnHandleMenuMsg(IContextMenu *iface, UINT uMsg, WPARAM wParam, LPARAM lParam);
35 static struct ICOM_VTABLE(IContextMenu) cmvt =
37 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
38 IContextMenu_fnQueryInterface,
39 IContextMenu_fnAddRef,
40 IContextMenu_fnRelease,
41 IContextMenu_fnQueryContextMenu,
42 IContextMenu_fnInvokeCommand,
43 IContextMenu_fnGetCommandString,
44 IContextMenu_fnHandleMenuMsg,
45 (void *) 0xdeadbabe /* just paranoia */
48 /**************************************************************************
49 * IContextMenu Implementation
52 { ICOM_VFIELD(IContextMenu);
54 IShellFolder* pSFParent;
55 LPITEMIDLIST pidl; /* root pidl */
56 LPITEMIDLIST *aPidls; /* array of child pidls */
61 static struct ICOM_VTABLE(IContextMenu) cmvt;
63 /**************************************************************************
64 * IContextMenu_AllocPidlTable()
66 static BOOL IContextMenu_AllocPidlTable(IContextMenuImpl *This, DWORD dwEntries)
68 TRACE("(%p)->(entrys=%lu)\n",This, dwEntries);
70 /*add one for NULL terminator */
73 This->aPidls = (LPITEMIDLIST*)SHAlloc(dwEntries * sizeof(LPITEMIDLIST));
76 { ZeroMemory(This->aPidls, dwEntries * sizeof(LPITEMIDLIST)); /*set all of the entries to NULL*/
78 return (This->aPidls != NULL);
81 /**************************************************************************
82 * IContextMenu_FreePidlTable()
84 static void IContextMenu_FreePidlTable(IContextMenuImpl *This)
88 TRACE("(%p)->()\n",This);
91 { for(i = 0; This->aPidls[i]; i++)
92 { SHFree(This->aPidls[i]);
100 /**************************************************************************
101 * IContextMenu_FillPidlTable()
103 static BOOL IContextMenu_FillPidlTable(IContextMenuImpl *This, LPCITEMIDLIST *aPidls, UINT uItemCount)
107 TRACE("(%p)->(apidl=%p count=%u)\n",This, aPidls, uItemCount);
110 { for(i = 0; i < uItemCount; i++)
111 { This->aPidls[i] = ILClone(aPidls[i]);
118 /**************************************************************************
119 * IContextMenu_CanRenameItems()
121 static BOOL IContextMenu_CanRenameItems(IContextMenuImpl *This)
125 TRACE("(%p)->()\n",This);
129 for(i = 0; This->aPidls[i]; i++){} /*get the number of items assigned to This object*/
130 { if(i > 1) /*you can't rename more than one item at a time*/
134 dwAttributes = SFGAO_CANRENAME;
135 IShellFolder_GetAttributesOf(This->pSFParent, i, (LPCITEMIDLIST*)This->aPidls, &dwAttributes);
137 return dwAttributes & SFGAO_CANRENAME;
142 /**************************************************************************
143 * IContextMenu_Constructor()
145 IContextMenu *IContextMenu_Constructor(LPSHELLFOLDER pSFParent, LPCITEMIDLIST pidl, LPCITEMIDLIST *aPidls, UINT uItemCount)
146 { IContextMenuImpl* cm;
149 cm = (IContextMenuImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IContextMenuImpl));
152 cm->pidl = ILClone(pidl);
154 cm->pSFParent = pSFParent;
157 IShellFolder_AddRef(pSFParent);
161 IContextMenu_AllocPidlTable(cm, uItemCount);
164 { IContextMenu_FillPidlTable(cm, aPidls, uItemCount);
168 for(u = 0; u < uItemCount; u++)
169 { cm->bAllValues &= (_ILIsValue(aPidls[u]) ? 1 : 0);
171 TRACE("(%p)->()\n",cm);
173 return (IContextMenu*)cm;
176 /**************************************************************************
177 * IContextMenu_fnQueryInterface
179 static HRESULT WINAPI IContextMenu_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
181 ICOM_THIS(IContextMenuImpl, iface);
184 WINE_StringFromCLSID((LPCLSID)riid,xriid);
186 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
190 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
193 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
196 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
197 { FIXME("-- LPSHELLEXTINIT pointer requested\n");
202 IContextMenu_AddRef((IContextMenu*)*ppvObj);
203 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
206 TRACE("-- Interface: E_NOINTERFACE\n");
207 return E_NOINTERFACE;
210 /**************************************************************************
211 * IContextMenu_fnAddRef
213 static ULONG WINAPI IContextMenu_fnAddRef(IContextMenu *iface)
215 ICOM_THIS(IContextMenuImpl, iface);
217 TRACE("(%p)->(count=%lu)\n",This, This->ref);
220 return ++(This->ref);
223 /**************************************************************************
224 * IContextMenu_fnRelease
226 static ULONG WINAPI IContextMenu_fnRelease(IContextMenu *iface)
228 ICOM_THIS(IContextMenuImpl, iface);
230 TRACE("(%p)->()\n",This);
235 { TRACE(" destroying IContextMenu(%p)\n",This);
238 IShellFolder_Release(This->pSFParent);
243 /*make sure the pidl is freed*/
245 { IContextMenu_FreePidlTable(This);
248 HeapFree(GetProcessHeap(),0,This);
254 /**************************************************************************
257 void WINAPI _InsertMenuItem (
268 ZeroMemory(&mii, sizeof(mii));
269 mii.cbSize = sizeof(mii);
270 if (fType == MFT_SEPARATOR)
271 { mii.fMask = MIIM_ID | MIIM_TYPE;
274 { mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
275 mii.dwTypeData = dwTypeData;
280 InsertMenuItemA( hmenu, indexMenu, fByPosition, &mii);
282 /**************************************************************************
283 * IContextMenu_fnQueryContextMenu()
286 static HRESULT WINAPI IContextMenu_fnQueryContextMenu(
294 ICOM_THIS(IContextMenuImpl, iface);
298 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
300 if(!(CMF_DEFAULTONLY & uFlags))
301 { if(!This->bAllValues)
303 fExplore = uFlags & CMF_EXPLORE;
305 { _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_EXPLORE, MFT_STRING, "&Explore", MFS_ENABLED|MFS_DEFAULT);
306 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_OPEN, MFT_STRING, "&Open", MFS_ENABLED);
309 { _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_OPEN, MFT_STRING, "&Open", MFS_ENABLED|MFS_DEFAULT);
310 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_EXPLORE, MFT_STRING, "&Explore", MFS_ENABLED);
313 if(uFlags & CMF_CANRENAME)
314 { _InsertMenuItem(hmenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
315 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_RENAME, MFT_STRING, "&Rename", (IContextMenu_CanRenameItems(This) ? MFS_ENABLED : MFS_DISABLED));
319 { _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_OPEN, MFT_STRING, "&Open", MFS_ENABLED|MFS_DEFAULT);
320 if(uFlags & CMF_CANRENAME)
321 { _InsertMenuItem(hmenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
322 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_RENAME, MFT_STRING, "&Rename", (IContextMenu_CanRenameItems(This) ? MFS_ENABLED : MFS_DISABLED));
325 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (IDM_LAST + 1));
327 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
330 /**************************************************************************
331 * IContextMenu_fnInvokeCommand()
333 static HRESULT WINAPI IContextMenu_fnInvokeCommand(
335 LPCMINVOKECOMMANDINFO lpcmi)
337 ICOM_THIS(IContextMenuImpl, iface);
340 SHELLEXECUTEINFOA sei;
343 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
345 if(LOWORD(lpcmi->lpVerb) > IDM_LAST)
348 switch(LOWORD(lpcmi->lpVerb))
351 /* Find the first item in the list that is not a value. These commands
352 should never be invoked if there isn't at least one folder item in the list.*/
354 for(i = 0; This->aPidls[i]; i++)
355 { if(!_ILIsValue(This->aPidls[i]))
359 pidlFQ = ILCombine(This->pidl, This->aPidls[i]);
361 ZeroMemory(&sei, sizeof(sei));
362 sei.cbSize = sizeof(sei);
363 sei.fMask = SEE_MASK_IDLIST | SEE_MASK_CLASSNAME;
364 sei.lpIDList = pidlFQ;
365 sei.lpClass = "folder";
366 sei.hwnd = lpcmi->hwnd;
367 sei.nShow = SW_SHOWNORMAL;
369 if(LOWORD(lpcmi->lpVerb) == IDM_EXPLORE)
370 { sei.lpVerb = "explore";
373 { sei.lpVerb = "open";
375 ShellExecuteExA(&sei);
381 /*handle rename for the view here*/
387 /**************************************************************************
388 * IContextMenu_fnGetCommandString()
390 static HRESULT WINAPI IContextMenu_fnGetCommandString(
398 ICOM_THIS(IContextMenuImpl, iface);
400 HRESULT hr = E_INVALIDARG;
402 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
412 strcpy((LPSTR)lpszName, "rename");
418 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
419 case, you need to do the lstrcpyW to the pointer passed.*/
423 lstrcpyAtoW((LPWSTR)lpszName, "rename");
433 TRACE("-- (%p)->(name=%s)\n",This, lpszName);
437 /**************************************************************************
438 * IContextMenu_fnHandleMenuMsg()
440 * should be only in IContextMenu2 and IContextMenu3
441 * is nevertheless called from word95
443 static HRESULT WINAPI IContextMenu_fnHandleMenuMsg(
449 ICOM_THIS(IContextMenuImpl, iface);
451 TRACE("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);