4 * Copyright 1998 Juergen Schmied <juergen.schmied@metronet.de>
11 #include "if_macros.h"
13 #include "shell32_main.h"
16 static HRESULT WINAPI IContextMenu_QueryInterface(LPCONTEXTMENU ,REFIID , LPVOID *);
17 static ULONG WINAPI IContextMenu_AddRef(LPCONTEXTMENU);
18 static ULONG WINAPI IContextMenu_Release(LPCONTEXTMENU);
19 static HRESULT WINAPI IContextMenu_QueryContextMenu(LPCONTEXTMENU , HMENU32 ,UINT32 ,UINT32 ,UINT32 ,UINT32);
20 static HRESULT WINAPI IContextMenu_InvokeCommand(LPCONTEXTMENU, LPCMINVOKECOMMANDINFO32);
21 static HRESULT WINAPI IContextMenu_GetCommandString(LPCONTEXTMENU , UINT32 ,UINT32 ,LPUINT32 ,LPSTR ,UINT32);
22 static HRESULT WINAPI IContextMenu_HandleMenuMsg(LPCONTEXTMENU, UINT32, WPARAM32, LPARAM);
24 BOOL32 IContextMenu_AllocPidlTable(LPCONTEXTMENU, DWORD);
25 void IContextMenu_FreePidlTable(LPCONTEXTMENU);
26 BOOL32 IContextMenu_CanRenameItems(LPCONTEXTMENU);
27 BOOL32 IContextMenu_FillPidlTable(LPCONTEXTMENU, LPCITEMIDLIST *, UINT32);
29 static struct IContextMenu_VTable cmvt =
30 { IContextMenu_QueryInterface,
33 IContextMenu_QueryContextMenu,
34 IContextMenu_InvokeCommand,
35 IContextMenu_GetCommandString,
36 IContextMenu_HandleMenuMsg,
37 (void *) 0xdeadbabe /* just paranoia */
39 /**************************************************************************
40 * IContextMenu_QueryInterface
42 static HRESULT WINAPI IContextMenu_QueryInterface(LPCONTEXTMENU this,REFIID riid, LPVOID *ppvObj)
44 WINE_StringFromCLSID((LPCLSID)riid,xriid);
45 TRACE(shell,"(%p)->(\n\tIID:\t%s,%p)\n",this,xriid,ppvObj);
49 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
50 { *ppvObj = (LPUNKNOWN)(LPCONTEXTMENU)this;
52 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
53 { *ppvObj = (LPCONTEXTMENU)this;
55 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
56 { FIXME (shell,"-- LPSHELLEXTINIT pointer requested\n");
60 { (*(LPCONTEXTMENU *)ppvObj)->lpvtbl->fnAddRef(this);
61 TRACE(shell,"-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
64 TRACE(shell,"-- Interface: E_NOINTERFACE\n");
68 /**************************************************************************
71 static ULONG WINAPI IContextMenu_AddRef(LPCONTEXTMENU this)
72 { TRACE(shell,"(%p)->(count=%lu)\n",this,(this->ref)+1);
76 /**************************************************************************
77 * IContextMenu_Release
79 static ULONG WINAPI IContextMenu_Release(LPCONTEXTMENU this)
80 { TRACE(shell,"(%p)->()\n",this);
85 { TRACE(shell," destroying IContextMenu(%p)\n",this);
88 this->pSFParent->lpvtbl->fnRelease(this->pSFParent);
90 /*make sure the pidl is freed*/
92 { IContextMenu_FreePidlTable(this);
95 HeapFree(GetProcessHeap(),0,this);
101 /**************************************************************************
102 * IContextMenu_Constructor()
104 LPCONTEXTMENU IContextMenu_Constructor(LPSHELLFOLDER pSFParent, LPCITEMIDLIST *aPidls, UINT32 uItemCount)
108 cm = (LPCONTEXTMENU)HeapAlloc(GetProcessHeap(),0,sizeof(IContextMenu));
112 cm->pSFParent = pSFParent;
114 cm->pSFParent->lpvtbl->fnAddRef(cm->pSFParent);
118 IContextMenu_AllocPidlTable(cm, uItemCount);
121 { IContextMenu_FillPidlTable(cm, aPidls, uItemCount);
125 for(u = 0; u < uItemCount; u++)
126 { cm->bAllValues &= (_ILIsValue(aPidls[u]) ? 1 : 0);
128 TRACE(shell,"(%p)->()\n",cm);
132 /**************************************************************************
135 void WINAPI _InsertMenuItem (HMENU32 hmenu, UINT32 indexMenu, BOOL32 fByPosition,
136 UINT32 wID, UINT32 fType, LPSTR dwTypeData, UINT32 fState)
137 { MENUITEMINFO32A mii;
139 ZeroMemory(&mii, sizeof(mii));
140 mii.cbSize = sizeof(mii);
141 if (fType == MFT_SEPARATOR)
142 { mii.fMask = MIIM_ID | MIIM_TYPE;
145 { mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
146 mii.dwTypeData = dwTypeData;
147 mii.fState = MFS_ENABLED | MFS_DEFAULT;
151 InsertMenuItem32A( hmenu, indexMenu, fByPosition, &mii);
153 /**************************************************************************
154 * IContextMenu_QueryContextMenu()
157 static HRESULT WINAPI IContextMenu_QueryContextMenu( LPCONTEXTMENU this, HMENU32 hmenu, UINT32 indexMenu,
158 UINT32 idCmdFirst,UINT32 idCmdLast,UINT32 uFlags)
161 TRACE(shell,"(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",this, hmenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
163 if(!(CMF_DEFAULTONLY & uFlags))
164 { if(!this->bAllValues)
166 fExplore = uFlags & CMF_EXPLORE;
168 { _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_EXPLORE, MFT_STRING, "&Explore", MFS_ENABLED|MFS_DEFAULT);
169 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_OPEN, MFT_STRING, "&Open", MFS_ENABLED);
172 { _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_OPEN, MFT_STRING, "&Open", MFS_ENABLED|MFS_DEFAULT);
173 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_EXPLORE, MFT_STRING, "&Explore", MFS_ENABLED);
176 if(uFlags & CMF_CANRENAME)
177 { _InsertMenuItem(hmenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
178 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_RENAME, MFT_STRING, "&Rename", (IContextMenu_CanRenameItems(this) ? MFS_ENABLED : MFS_DISABLED));
182 { _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_OPEN, MFT_STRING, "&Open", MFS_ENABLED|MFS_DEFAULT);
183 if(uFlags & CMF_CANRENAME)
184 { _InsertMenuItem(hmenu, indexMenu++, TRUE, 0, MFT_SEPARATOR, NULL, 0);
185 _InsertMenuItem(hmenu, indexMenu++, TRUE, idCmdFirst+IDM_RENAME, MFT_STRING, "&Rename", (IContextMenu_CanRenameItems(this) ? MFS_ENABLED : MFS_DISABLED));
188 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, (IDM_LAST + 1));
190 return MAKE_HRESULT(SEVERITY_SUCCESS, 0, 0);
193 /**************************************************************************
194 * IContextMenu_InvokeCommand()
196 static HRESULT WINAPI IContextMenu_InvokeCommand(LPCONTEXTMENU this, LPCMINVOKECOMMANDINFO32 lpcmi)
197 { LPITEMIDLIST pidlTemp,pidlFQ;
201 SHELLEXECUTEINFO32A sei;
204 TRACE(shell,"(%p)->(invcom=%p verb=%p wnd=%x)\n",this,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
206 if(HIWORD(lpcmi->lpVerb))
207 { /* get the active IShellView */
208 lpSB = (LPSHELLBROWSER)SendMessage32A(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0);
209 IShellBrowser_QueryActiveShellView(lpSB, &lpSV); /* does AddRef() on lpSV */
210 lpSV->lpvtbl->fnGetWindow(lpSV, &hWndSV);
212 /* these verbs are used by the filedialogs*/
213 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDER))
214 { FIXME(shell,"%s\n",lpcmi->lpVerb);
216 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLIST))
217 { FIXME(shell,"%s\n",lpcmi->lpVerb);
218 SendMessage32A(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
220 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILS))
221 { FIXME(shell,"%s\n",lpcmi->lpVerb);
222 SendMessage32A(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
225 { FIXME(shell,"please report: unknown verb %s\n",lpcmi->lpVerb);
227 lpSV->lpvtbl->fnRelease(lpSV);
231 if(LOWORD(lpcmi->lpVerb) > IDM_LAST)
234 switch(LOWORD(lpcmi->lpVerb))
237 /* Find the first item in the list that is not a value. These commands
238 should never be invoked if there isn't at least one folder item in the list.*/
240 for(i = 0; this->aPidls[i]; i++)
241 { if(!_ILIsValue(this->aPidls[i]))
245 pidlTemp = ILCombine(this->pSFParent->mpidl, this->aPidls[i]);
246 pidlFQ = ILCombine(this->pSFParent->pMyPidl, pidlTemp);
249 ZeroMemory(&sei, sizeof(sei));
250 sei.cbSize = sizeof(sei);
251 sei.fMask = SEE_MASK_IDLIST | SEE_MASK_CLASSNAME;
252 sei.lpIDList = pidlFQ;
253 sei.lpClass = "folder";
254 sei.hwnd = lpcmi->hwnd;
255 sei.nShow = SW_SHOWNORMAL;
257 if(LOWORD(lpcmi->lpVerb) == IDM_EXPLORE)
258 { sei.lpVerb = "explore";
261 { sei.lpVerb = "open";
263 ShellExecuteEx32A(&sei);
268 MessageBeep32(MB_OK);
269 /*handle rename for the view here*/
275 /**************************************************************************
276 * IContextMenu_GetCommandString()
278 static HRESULT WINAPI IContextMenu_GetCommandString( LPCONTEXTMENU this, UINT32 idCommand,
279 UINT32 uFlags,LPUINT32 lpReserved,LPSTR lpszName,UINT32 uMaxNameLen)
280 { HRESULT hr = E_INVALIDARG;
282 TRACE(shell,"(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",this, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
292 strcpy((LPSTR)lpszName, "rename");
298 /* NT 4.0 with IE 3.0x or no IE will always call this with GCS_VERBW. In this
299 case, you need to do the lstrcpyW to the pointer passed.*/
303 lstrcpyAtoW((LPWSTR)lpszName, "rename");
313 TRACE(shell,"-- (%p)->(name=%s)\n",this, lpszName);
316 /**************************************************************************
317 * IContextMenu_HandleMenuMsg()
319 * should be only in IContextMenu2 and IContextMenu3
320 * is nevertheless called from word95
322 static HRESULT WINAPI IContextMenu_HandleMenuMsg(LPCONTEXTMENU this, UINT32 uMsg,WPARAM32 wParam,LPARAM lParam)
323 { TRACE(shell,"(%p)->(msg=%x wp=%x lp=%lx)\n",this, uMsg, wParam, lParam);
326 /**************************************************************************
327 * IContextMenu_AllocPidlTable()
329 BOOL32 IContextMenu_AllocPidlTable(LPCONTEXTMENU this, DWORD dwEntries)
330 { TRACE(shell,"(%p)->(entrys=%lu)\n",this, dwEntries);
332 /*add one for NULL terminator */
335 this->aPidls = (LPITEMIDLIST*)SHAlloc(dwEntries * sizeof(LPITEMIDLIST));
338 { ZeroMemory(this->aPidls, dwEntries * sizeof(LPITEMIDLIST)); /*set all of the entries to NULL*/
340 return (this->aPidls != NULL);
343 /**************************************************************************
344 * IContextMenu_FreePidlTable()
346 void IContextMenu_FreePidlTable(LPCONTEXTMENU this)
349 TRACE(shell,"(%p)->()\n",this);
352 { for(i = 0; this->aPidls[i]; i++)
353 { SHFree(this->aPidls[i]);
356 SHFree(this->aPidls);
361 /**************************************************************************
362 * IContextMenu_FillPidlTable()
364 BOOL32 IContextMenu_FillPidlTable(LPCONTEXTMENU this, LPCITEMIDLIST *aPidls, UINT32 uItemCount)
366 TRACE(shell,"(%p)->(apidl=%p count=%u)\n",this, aPidls, uItemCount);
368 { for(i = 0; i < uItemCount; i++)
369 { this->aPidls[i] = ILClone(aPidls[i]);
376 /**************************************************************************
377 * IContextMenu_CanRenameItems()
379 BOOL32 IContextMenu_CanRenameItems(LPCONTEXTMENU this)
383 TRACE(shell,"(%p)->()\n",this);
386 { for(i = 0; this->aPidls[i]; i++){} /*get the number of items assigned to this object*/
387 if(i > 1) /*you can't rename more than one item at a time*/
390 dwAttributes = SFGAO_CANRENAME;
391 this->pSFParent->lpvtbl->fnGetAttributesOf(this->pSFParent, i,
392 (LPCITEMIDLIST*)this->aPidls, &dwAttributes);
394 return dwAttributes & SFGAO_CANRENAME;