4 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
12 #include "wine/obj_base.h"
13 #include "wine/obj_contextmenu.h"
14 #include "wine/obj_shellbrowser.h"
15 #include "wine/obj_shellextinit.h"
17 #include "shell32_main.h"
19 /**************************************************************************
20 * IContextMenu Implementation
23 { ICOM_VTABLE(IContextMenu)* lpvtbl;
25 IShellFolder* pSFParent;
31 static struct ICOM_VTABLE(IContextMenu) cmvt;
33 /**************************************************************************
34 * IContextMenu_AllocPidlTable()
36 BOOL IContextMenu_AllocPidlTable(IContextMenuImpl *This, DWORD dwEntries)
38 TRACE(shell,"(%p)->(entrys=%lu)\n",This, dwEntries);
40 /*add one for NULL terminator */
43 This->aPidls = (LPITEMIDLIST*)SHAlloc(dwEntries * sizeof(LPITEMIDLIST));
46 { ZeroMemory(This->aPidls, dwEntries * sizeof(LPITEMIDLIST)); /*set all of the entries to NULL*/
48 return (This->aPidls != NULL);
51 /**************************************************************************
52 * IContextMenu_FreePidlTable()
54 void IContextMenu_FreePidlTable(IContextMenuImpl *This)
58 TRACE(shell,"(%p)->()\n",This);
61 { for(i = 0; This->aPidls[i]; i++)
62 { SHFree(This->aPidls[i]);
70 /**************************************************************************
71 * IContextMenu_FillPidlTable()
73 BOOL IContextMenu_FillPidlTable(IContextMenuImpl *This, LPCITEMIDLIST *aPidls, UINT uItemCount)
77 TRACE(shell,"(%p)->(apidl=%p count=%u)\n",This, aPidls, uItemCount);
80 { for(i = 0; i < uItemCount; i++)
81 { This->aPidls[i] = ILClone(aPidls[i]);
88 /**************************************************************************
89 * IContextMenu_CanRenameItems()
91 BOOL IContextMenu_CanRenameItems(IContextMenuImpl *This)
95 TRACE(shell,"(%p)->()\n",This);
99 for(i = 0; This->aPidls[i]; i++){} /*get the number of items assigned to This object*/
100 { if(i > 1) /*you can't rename more than one item at a time*/
104 dwAttributes = SFGAO_CANRENAME;
105 IShellFolder_GetAttributesOf(This->pSFParent, i, (LPCITEMIDLIST*)This->aPidls, &dwAttributes);
107 return dwAttributes & SFGAO_CANRENAME;
112 /**************************************************************************
113 * IContextMenu_Constructor()
115 IContextMenu *IContextMenu_Constructor(LPSHELLFOLDER pSFParent, LPCITEMIDLIST *aPidls, UINT uItemCount)
116 { IContextMenuImpl* cm;
119 cm = (IContextMenuImpl*)HeapAlloc(GetProcessHeap(),0,sizeof(IContextMenuImpl));
123 cm->pSFParent = pSFParent;
125 IShellFolder_AddRef(pSFParent);
129 IContextMenu_AllocPidlTable(cm, uItemCount);
132 { IContextMenu_FillPidlTable(cm, aPidls, uItemCount);
136 for(u = 0; u < uItemCount; u++)
137 { cm->bAllValues &= (_ILIsValue(aPidls[u]) ? 1 : 0);
139 TRACE(shell,"(%p)->()\n",cm);
141 return (IContextMenu*)cm;
144 /**************************************************************************
145 * IContextMenu_fnQueryInterface
147 static HRESULT WINAPI IContextMenu_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
149 ICOM_THIS(IContextMenuImpl, iface);
152 WINE_StringFromCLSID((LPCLSID)riid,xriid);
154 TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
158 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
161 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
164 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
165 { FIXME (shell,"-- LPSHELLEXTINIT pointer requested\n");
170 IContextMenu_AddRef((IContextMenu*)*ppvObj);
171 TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
174 TRACE(shell,"-- Interface: E_NOINTERFACE\n");
175 return E_NOINTERFACE;
178 /**************************************************************************
179 * IContextMenu_fnAddRef
181 static ULONG WINAPI IContextMenu_fnAddRef(IContextMenu *iface)
183 ICOM_THIS(IContextMenuImpl, iface);
185 TRACE(shell,"(%p)->(count=%lu)\n",This,(This->ref)+1);
188 return ++(This->ref);
191 /**************************************************************************
192 * IContextMenu_fnRelease
194 static ULONG WINAPI IContextMenu_fnRelease(IContextMenu *iface)
196 ICOM_THIS(IContextMenuImpl, iface);
198 TRACE(shell,"(%p)->()\n",This);
203 { TRACE(shell," destroying IContextMenu(%p)\n",This);
206 IShellFolder_Release(This->pSFParent);
208 /*make sure the pidl is freed*/
210 { IContextMenu_FreePidlTable(This);
213 HeapFree(GetProcessHeap(),0,This);
219 /**************************************************************************
222 void WINAPI _InsertMenuItem (
233 ZeroMemory(&mii, sizeof(mii));
234 mii.cbSize = sizeof(mii);
235 if (fType == MFT_SEPARATOR)
236 { mii.fMask = MIIM_ID | MIIM_TYPE;
239 { mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
240 mii.dwTypeData = dwTypeData;
241 mii.fState = MFS_ENABLED | MFS_DEFAULT;
245 InsertMenuItemA( hmenu, indexMenu, fByPosition, &mii);
247 /**************************************************************************
248 * IContextMenu_fnQueryContextMenu()
251 static HRESULT WINAPI IContextMenu_fnQueryContextMenu(
259 ICOM_THIS(IContextMenuImpl, iface);
263 TRACE(shell,"(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
265 if(!(CMF_DEFAULTONLY & uFlags))
266 { if(!This->bAllValues)
268 fExplore = uFlags & CMF_EXPLORE;
270 { _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_EXPLORE, MFT_STRING, "&Explore", MFS_ENABLED|MFS_DEFAULT);
271 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_OPEN, MFT_STRING, "&Open", MFS_ENABLED);
274 { _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_OPEN, MFT_STRING, "&Open", MFS_ENABLED|MFS_DEFAULT);
275 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_EXPLORE, MFT_STRING, "&Explore", MFS_ENABLED);
278 if(uFlags & CMF_CANRENAME)
279 { _InsertMenuItem(hmenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
280 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_RENAME, MFT_STRING, "&Rename", (IContextMenu_CanRenameItems(This) ? MFS_ENABLED : MFS_DISABLED));
284 { _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_OPEN, MFT_STRING, "&Open", MFS_ENABLED|MFS_DEFAULT);
285 if(uFlags & CMF_CANRENAME)
286 { _InsertMenuItem(hmenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
287 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_RENAME, MFT_STRING, "&Rename", (IContextMenu_CanRenameItems(This) ? MFS_ENABLED : MFS_DISABLED));
290 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (IDM_LAST + 1));
292 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
295 /**************************************************************************
296 * IContextMenu_fnInvokeCommand()
298 static HRESULT WINAPI IContextMenu_fnInvokeCommand(
300 LPCMINVOKECOMMANDINFO lpcmi)
302 ICOM_THIS(IContextMenuImpl, iface);
304 LPITEMIDLIST pidlTemp,pidlFQ;
308 SHELLEXECUTEINFOA sei;
311 TRACE(shell,"(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
313 if(HIWORD(lpcmi->lpVerb))
314 { /* get the active IShellView */
315 lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0);
316 IShellBrowser_QueryActiveShellView(lpSB, &lpSV); /* does AddRef() on lpSV */
317 IShellView_GetWindow(lpSV, &hWndSV);
319 /* these verbs are used by the filedialogs*/
320 TRACE(shell,"%s\n",lpcmi->lpVerb);
321 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDER))
322 { FIXME(shell,"%s not implemented\n",lpcmi->lpVerb);
324 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLIST))
325 { SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
327 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILS))
328 { SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
331 { FIXME(shell,"please report: unknown verb %s\n",lpcmi->lpVerb);
333 IShellView_Release(lpSV);
337 if(LOWORD(lpcmi->lpVerb) > IDM_LAST)
340 switch(LOWORD(lpcmi->lpVerb))
343 /* Find the first item in the list that is not a value. These commands
344 should never be invoked if there isn't at least one folder item in the list.*/
346 for(i = 0; This->aPidls[i]; i++)
347 { if(!_ILIsValue(This->aPidls[i]))
351 pidlTemp = ILCombine(((IGenericSFImpl*)(This->pSFParent))->mpidl, This->aPidls[i]);
352 pidlFQ = ILCombine(((IGenericSFImpl*)(This->pSFParent))->pMyPidl, pidlTemp);
355 ZeroMemory(&sei, sizeof(sei));
356 sei.cbSize = sizeof(sei);
357 sei.fMask = SEE_MASK_IDLIST | SEE_MASK_CLASSNAME;
358 sei.lpIDList = pidlFQ;
359 sei.lpClass = "folder";
360 sei.hwnd = lpcmi->hwnd;
361 sei.nShow = SW_SHOWNORMAL;
363 if(LOWORD(lpcmi->lpVerb) == IDM_EXPLORE)
364 { sei.lpVerb = "explore";
367 { sei.lpVerb = "open";
369 ShellExecuteExA(&sei);
375 /*handle rename for the view here*/
381 /**************************************************************************
382 * IContextMenu_fnGetCommandString()
384 static HRESULT WINAPI IContextMenu_fnGetCommandString(
392 ICOM_THIS(IContextMenuImpl, iface);
394 HRESULT hr = E_INVALIDARG;
396 TRACE(shell,"(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
406 strcpy((LPSTR)lpszName, "rename");
412 /* NT 4.0 with IE 3.0x or no IE will always call This with GCS_VERBW. In This
413 case, you need to do the lstrcpyW to the pointer passed.*/
417 lstrcpyAtoW((LPWSTR)lpszName, "rename");
427 TRACE(shell,"-- (%p)->(name=%s)\n",This, lpszName);
431 /**************************************************************************
432 * IContextMenu_fnHandleMenuMsg()
434 * should be only in IContextMenu2 and IContextMenu3
435 * is nevertheless called from word95
437 static HRESULT WINAPI IContextMenu_fnHandleMenuMsg(
443 ICOM_THIS(IContextMenuImpl, iface);
445 TRACE(shell,"(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
450 /**************************************************************************
451 * IContextMenu VTable
454 static struct ICOM_VTABLE(IContextMenu) cmvt =
456 IContextMenu_fnQueryInterface,
457 IContextMenu_fnAddRef,
458 IContextMenu_fnRelease,
459 IContextMenu_fnQueryContextMenu,
460 IContextMenu_fnInvokeCommand,
461 IContextMenu_fnGetCommandString,
462 IContextMenu_fnHandleMenuMsg,
463 (void *) 0xdeadbabe /* just paranoia */