3 * ShellView Background Context Menu (shv_bg_cm)
5 * Copyright 1999 Juergen Schmied <juergen.schmied@metronet.de>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define NONAMELESSUNION
25 #define NONAMELESSSTRUCT
27 #include "wine/debug.h"
34 #include "shell32_main.h"
35 #include "shellfolder.h"
36 #include "undocshell.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
40 /**************************************************************************
41 * IContextMenu Implementation
45 const IContextMenu2Vtbl
*lpVtbl
;
46 IShellFolder
* pSFParent
;
52 static const IContextMenu2Vtbl cmvt
;
54 /**************************************************************************
55 * ISVBgCm_Constructor()
57 IContextMenu2
*ISvBgCm_Constructor(IShellFolder
* pSFParent
, BOOL bDesktop
)
61 cm
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(BgCmImpl
));
64 cm
->pSFParent
= pSFParent
;
65 cm
->bDesktop
= bDesktop
;
66 if(pSFParent
) IShellFolder_AddRef(pSFParent
);
68 TRACE("(%p)->()\n",cm
);
69 return (IContextMenu2
*)cm
;
72 /**************************************************************************
73 * ISVBgCm_fnQueryInterface
75 static HRESULT WINAPI
ISVBgCm_fnQueryInterface(IContextMenu2
*iface
, REFIID riid
, LPVOID
*ppvObj
)
77 BgCmImpl
*This
= (BgCmImpl
*)iface
;
79 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
83 if(IsEqualIID(riid
, &IID_IUnknown
) ||
84 IsEqualIID(riid
, &IID_IContextMenu
) ||
85 IsEqualIID(riid
, &IID_IContextMenu2
))
89 else if(IsEqualIID(riid
, &IID_IShellExtInit
)) /*IShellExtInit*/
91 FIXME("-- LPSHELLEXTINIT pointer requested\n");
96 IUnknown_AddRef((IUnknown
*)*ppvObj
);
97 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
100 TRACE("-- Interface: E_NOINTERFACE\n");
101 return E_NOINTERFACE
;
104 /**************************************************************************
107 static ULONG WINAPI
ISVBgCm_fnAddRef(IContextMenu2
*iface
)
109 BgCmImpl
*This
= (BgCmImpl
*)iface
;
110 ULONG refCount
= InterlockedIncrement(&This
->ref
);
112 TRACE("(%p)->(count=%u)\n", This
, refCount
- 1);
117 /**************************************************************************
120 static ULONG WINAPI
ISVBgCm_fnRelease(IContextMenu2
*iface
)
122 BgCmImpl
*This
= (BgCmImpl
*)iface
;
123 ULONG refCount
= InterlockedDecrement(&This
->ref
);
125 TRACE("(%p)->(count=%i)\n", This
, refCount
+ 1);
129 TRACE(" destroying IContextMenu(%p)\n",This
);
132 IShellFolder_Release(This
->pSFParent
);
134 HeapFree(GetProcessHeap(),0,This
);
139 /**************************************************************************
140 * ISVBgCm_fnQueryContextMenu()
143 static HRESULT WINAPI
ISVBgCm_fnQueryContextMenu(
144 IContextMenu2
*iface
,
155 BgCmImpl
*This
= (BgCmImpl
*)iface
;
157 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
158 This
, hMenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
161 hMyMenu
= LoadMenuA(shell32_hInstance
, "MENU_002");
162 if (uFlags
& CMF_DEFAULTONLY
)
164 HMENU ourMenu
= GetSubMenu(hMyMenu
,0);
165 UINT oldDef
= GetMenuDefaultItem(hMenu
,TRUE
,GMDI_USEDISABLED
);
166 UINT newDef
= GetMenuDefaultItem(ourMenu
,TRUE
,GMDI_USEDISABLED
);
167 if (newDef
!= oldDef
)
168 SetMenuDefaultItem(hMenu
,newDef
,TRUE
);
169 if (newDef
!=0xFFFFFFFF)
170 hr
= MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, newDef
+1);
172 hr
= MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, 0);
176 idMax
= Shell_MergeMenus (hMenu
, GetSubMenu(hMyMenu
,0), indexMenu
,
177 idCmdFirst
, idCmdLast
, MM_SUBMENUSHAVEIDS
);
178 hr
= MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, idMax
-idCmdFirst
+1);
180 DestroyMenu(hMyMenu
);
182 TRACE("(%p)->returning 0x%x\n",This
,hr
);
186 /**************************************************************************
189 static void DoNewFolder(
190 IContextMenu2
*iface
,
193 BgCmImpl
*This
= (BgCmImpl
*)iface
;
195 WCHAR wszName
[MAX_PATH
];
197 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlp
);
201 ISFHelper_GetUniqueName(psfhlp
, wszName
, MAX_PATH
);
202 ISFHelper_AddFolder(psfhlp
, 0, wszName
, &pidl
);
206 /* if we are in a shellview do labeledit */
207 IShellView_SelectItem(psv
,
208 pidl
,(SVSI_DESELECTOTHERS
| SVSI_EDIT
| SVSI_ENSUREVISIBLE
209 |SVSI_FOCUSED
|SVSI_SELECT
));
213 ISFHelper_Release(psfhlp
);
217 /**************************************************************************
221 IContextMenu2
*iface
)
223 BgCmImpl
*This
= (BgCmImpl
*)iface
;
224 BOOL bSuccess
= FALSE
;
229 if(SUCCEEDED(OleGetClipboard(&pda
)))
234 TRACE("pda=%p\n", pda
);
236 /* Set the FORMATETC structure*/
237 InitFormatEtc(formatetc
, RegisterClipboardFormatW(CFSTR_SHELLIDLISTW
), TYMED_HGLOBAL
);
239 /* Get the pidls from IDataObject */
240 if(SUCCEEDED(IDataObject_GetData(pda
,&formatetc
,&medium
)))
242 LPITEMIDLIST
* apidl
;
244 IShellFolder
*psfFrom
= NULL
, *psfDesktop
;
246 LPIDA lpcida
= GlobalLock(medium
.u
.hGlobal
);
247 TRACE("cida=%p\n", lpcida
);
249 apidl
= _ILCopyCidaToaPidl(&pidl
, lpcida
);
251 /* bind to the source shellfolder */
252 SHGetDesktopFolder(&psfDesktop
);
255 IShellFolder_BindToObject(psfDesktop
, pidl
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfFrom
);
256 IShellFolder_Release(psfDesktop
);
261 /* get source and destination shellfolder */
262 ISFHelper
*psfhlpdst
, *psfhlpsrc
;
263 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlpdst
);
264 IShellFolder_QueryInterface(psfFrom
, &IID_ISFHelper
, (LPVOID
*)&psfhlpsrc
);
266 /* do the copy/move */
267 if (psfhlpdst
&& psfhlpsrc
)
269 ISFHelper_CopyItems(psfhlpdst
, psfFrom
, lpcida
->cidl
, (LPCITEMIDLIST
*)apidl
);
271 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
274 if(psfhlpdst
) ISFHelper_Release(psfhlpdst
);
275 if(psfhlpsrc
) ISFHelper_Release(psfhlpsrc
);
276 IShellFolder_Release(psfFrom
);
279 _ILFreeaPidl(apidl
, lpcida
->cidl
);
282 /* release the medium*/
283 ReleaseStgMedium(&medium
);
285 IDataObject_Release(pda
);
291 hMem
= GetClipboardData(CF_HDROP
);
295 char * pDropFiles
= GlobalLock(hMem
);
298 int len
, offset
= sizeof(DROPFILESTRUCT
);
300 while( pDropFiles
[offset
] != 0)
302 len
= strlen(pDropFiles
+ offset
);
303 TRACE("%s\n", pDropFiles
+ offset
);
314 /**************************************************************************
315 * ISVBgCm_fnInvokeCommand()
317 static HRESULT WINAPI
ISVBgCm_fnInvokeCommand(
318 IContextMenu2
*iface
,
319 LPCMINVOKECOMMANDINFO lpcmi
)
321 BgCmImpl
*This
= (BgCmImpl
*)iface
;
324 LPSHELLVIEW lpSV
= NULL
;
327 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This
,lpcmi
,lpcmi
->lpVerb
, lpcmi
->hwnd
);
329 /* get the active IShellView */
330 if((lpSB
= (LPSHELLBROWSER
)SendMessageA(lpcmi
->hwnd
, CWM_GETISHELLBROWSER
,0,0)))
332 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
334 IShellView_GetWindow(lpSV
, &hWndSV
);
338 if(HIWORD(lpcmi
->lpVerb
))
340 TRACE("%s\n",lpcmi
->lpVerb
);
342 if (! strcmp(lpcmi
->lpVerb
,CMDSTR_NEWFOLDERA
))
344 DoNewFolder(iface
, lpSV
);
346 else if (! strcmp(lpcmi
->lpVerb
,CMDSTR_VIEWLISTA
))
348 if(hWndSV
) SendMessageA(hWndSV
, WM_COMMAND
, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW
,0),0 );
350 else if (! strcmp(lpcmi
->lpVerb
,CMDSTR_VIEWDETAILSA
))
352 if(hWndSV
) SendMessageA(hWndSV
, WM_COMMAND
, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW
,0),0 );
356 FIXME("please report: unknown verb %s\n",lpcmi
->lpVerb
);
361 switch(LOWORD(lpcmi
->lpVerb
))
363 case FCIDM_SHVIEW_REFRESH
:
364 if (lpSV
) IShellView_Refresh(lpSV
);
367 case FCIDM_SHVIEW_NEWFOLDER
:
368 DoNewFolder(iface
, lpSV
);
371 case FCIDM_SHVIEW_INSERT
:
375 case FCIDM_SHVIEW_PROPERTIES
:
376 if (This
->bDesktop
) {
377 ShellExecuteA(lpcmi
->hwnd
, "open", "rundll32.exe shell32.dll,Control_RunDLL desk.cpl", NULL
, NULL
, SW_SHOWNORMAL
);
379 FIXME("launch item properties dialog\n");
384 /* if it's an id just pass it to the parent shv */
385 if (hWndSV
) SendMessageA(hWndSV
, WM_COMMAND
, MAKEWPARAM(LOWORD(lpcmi
->lpVerb
), 0),0 );
391 IShellView_Release(lpSV
); /* QueryActiveShellView does AddRef */
396 /**************************************************************************
397 * ISVBgCm_fnGetCommandString()
400 static HRESULT WINAPI
ISVBgCm_fnGetCommandString(
401 IContextMenu2
*iface
,
408 BgCmImpl
*This
= (BgCmImpl
*)iface
;
410 TRACE("(%p)->(idcom=%lx flags=%x %p name=%p len=%x)\n",This
, idCommand
, uFlags
, lpReserved
, lpszName
, uMaxNameLen
);
412 /* test the existence of the menu items, the file dialog enables
413 the buttons according to this */
414 if (uFlags
== GCS_VALIDATEA
)
416 if(HIWORD(idCommand
))
418 if (!strcmp((LPSTR
)idCommand
, CMDSTR_VIEWLISTA
) ||
419 !strcmp((LPSTR
)idCommand
, CMDSTR_VIEWDETAILSA
) ||
420 !strcmp((LPSTR
)idCommand
, CMDSTR_NEWFOLDERA
))
427 FIXME("unknown command string\n");
431 /**************************************************************************
432 * ISVBgCm_fnHandleMenuMsg()
434 static HRESULT WINAPI
ISVBgCm_fnHandleMenuMsg(
435 IContextMenu2
*iface
,
440 BgCmImpl
*This
= (BgCmImpl
*)iface
;
442 FIXME("(%p)->(msg=%x wp=%lx lp=%lx)\n",This
, uMsg
, wParam
, lParam
);
447 /**************************************************************************
448 * IContextMenu2 VTable
451 static const IContextMenu2Vtbl cmvt
=
453 ISVBgCm_fnQueryInterface
,
456 ISVBgCm_fnQueryContextMenu
,
457 ISVBgCm_fnInvokeCommand
,
458 ISVBgCm_fnGetCommandString
,
459 ISVBgCm_fnHandleMenuMsg