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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
25 #include "wine/debug.h"
33 #include "shell32_main.h"
34 #include "shellfolder.h"
35 #include "undocshell.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(shell
);
39 /**************************************************************************
40 * IContextMenu Implementation
44 ICOM_VFIELD(IContextMenu
);
45 IShellFolder
* pSFParent
;
50 static struct ICOM_VTABLE(IContextMenu
) cmvt
;
52 /**************************************************************************
53 * ISVBgCm_Constructor()
55 IContextMenu
*ISvBgCm_Constructor(IShellFolder
* pSFParent
)
59 cm
= (BgCmImpl
*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(BgCmImpl
));
62 cm
->pSFParent
= pSFParent
;
63 if(pSFParent
) IShellFolder_AddRef(pSFParent
);
65 TRACE("(%p)->()\n",cm
);
66 return (IContextMenu
*)cm
;
69 /**************************************************************************
70 * ISVBgCm_fnQueryInterface
72 static HRESULT WINAPI
ISVBgCm_fnQueryInterface(IContextMenu
*iface
, REFIID riid
, LPVOID
*ppvObj
)
74 ICOM_THIS(BgCmImpl
, iface
);
76 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This
,debugstr_guid(riid
),ppvObj
);
80 if(IsEqualIID(riid
, &IID_IUnknown
)) /*IUnknown*/
84 else if(IsEqualIID(riid
, &IID_IContextMenu
)) /*IContextMenu*/
88 else if(IsEqualIID(riid
, &IID_IShellExtInit
)) /*IShellExtInit*/
90 FIXME("-- LPSHELLEXTINIT pointer requested\n");
95 IUnknown_AddRef((IUnknown
*)*ppvObj
);
96 TRACE("-- Interface: (%p)->(%p)\n",ppvObj
,*ppvObj
);
99 TRACE("-- Interface: E_NOINTERFACE\n");
100 return E_NOINTERFACE
;
103 /**************************************************************************
106 static ULONG WINAPI
ISVBgCm_fnAddRef(IContextMenu
*iface
)
108 ICOM_THIS(BgCmImpl
, iface
);
110 TRACE("(%p)->(count=%lu)\n",This
, This
->ref
);
112 return ++(This
->ref
);
115 /**************************************************************************
118 static ULONG WINAPI
ISVBgCm_fnRelease(IContextMenu
*iface
)
120 ICOM_THIS(BgCmImpl
, iface
);
122 TRACE("(%p)->()\n",This
);
126 TRACE(" destroying IContextMenu(%p)\n",This
);
129 IShellFolder_Release(This
->pSFParent
);
131 HeapFree(GetProcessHeap(),0,This
);
138 /**************************************************************************
139 * ISVBgCm_fnQueryContextMenu()
142 static HRESULT WINAPI
ISVBgCm_fnQueryContextMenu(
154 ICOM_THIS(BgCmImpl
, iface
);
156 TRACE("(%p)->(hmenu=%p indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",
157 This
, hMenu
, indexMenu
, idCmdFirst
, idCmdLast
, uFlags
);
160 hMyMenu
= LoadMenuA(shell32_hInstance
, "MENU_002");
161 if (uFlags
& CMF_DEFAULTONLY
)
163 HMENU ourMenu
= GetSubMenu(hMyMenu
,0);
164 UINT oldDef
= GetMenuDefaultItem(hMenu
,TRUE
,GMDI_USEDISABLED
);
165 UINT newDef
= GetMenuDefaultItem(ourMenu
,TRUE
,GMDI_USEDISABLED
);
166 if (newDef
!= oldDef
)
167 SetMenuDefaultItem(hMenu
,newDef
,TRUE
);
168 if (newDef
!=0xFFFFFFFF)
169 hr
= MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, newDef
+1);
171 hr
= MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, 0);
175 idMax
= Shell_MergeMenus (hMenu
, GetSubMenu(hMyMenu
,0), indexMenu
,
176 idCmdFirst
, idCmdLast
, MM_SUBMENUSHAVEIDS
);
177 hr
= MAKE_HRESULT(SEVERITY_SUCCESS
, FACILITY_NULL
, idMax
-idCmdFirst
+1);
179 DestroyMenu(hMyMenu
);
181 TRACE("(%p)->returning 0x%lx\n",This
,hr
);
185 /**************************************************************************
188 static void DoNewFolder(
192 ICOM_THIS(BgCmImpl
, iface
);
194 char szName
[MAX_PATH
];
196 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlp
);
200 ISFHelper_GetUniqueName(psfhlp
, szName
, MAX_PATH
);
201 ISFHelper_AddFolder(psfhlp
, 0, szName
, &pidl
);
205 /* if we are in a shellview do labeledit */
206 IShellView_SelectItem(psv
,
207 pidl
,(SVSI_DESELECTOTHERS
| SVSI_EDIT
| SVSI_ENSUREVISIBLE
208 |SVSI_FOCUSED
|SVSI_SELECT
));
212 ISFHelper_Release(psfhlp
);
216 /**************************************************************************
222 ICOM_THIS(BgCmImpl
, iface
);
223 BOOL bSuccess
= FALSE
;
228 if(SUCCEEDED(pOleGetClipboard(&pda
)))
233 TRACE("pda=%p\n", pda
);
235 /* Set the FORMATETC structure*/
236 InitFormatEtc(formatetc
, RegisterClipboardFormatA(CFSTR_SHELLIDLIST
), TYMED_HGLOBAL
);
238 /* Get the pidls from IDataObject */
239 if(SUCCEEDED(IDataObject_GetData(pda
,&formatetc
,&medium
)))
241 LPITEMIDLIST
* apidl
;
243 IShellFolder
*psfFrom
= NULL
, *psfDesktop
;
245 LPIDA lpcida
= GlobalLock(medium
.u
.hGlobal
);
246 TRACE("cida=%p\n", lpcida
);
248 apidl
= _ILCopyCidaToaPidl(&pidl
, lpcida
);
250 /* bind to the source shellfolder */
251 SHGetDesktopFolder(&psfDesktop
);
254 IShellFolder_BindToObject(psfDesktop
, pidl
, NULL
, &IID_IShellFolder
, (LPVOID
*)&psfFrom
);
255 IShellFolder_Release(psfDesktop
);
260 /* get source and destination shellfolder */
261 ISFHelper
*psfhlpdst
, *psfhlpsrc
;
262 IShellFolder_QueryInterface(This
->pSFParent
, &IID_ISFHelper
, (LPVOID
*)&psfhlpdst
);
263 IShellFolder_QueryInterface(psfFrom
, &IID_ISFHelper
, (LPVOID
*)&psfhlpsrc
);
265 /* do the copy/move */
266 if (psfhlpdst
&& psfhlpsrc
)
268 ISFHelper_CopyItems(psfhlpdst
, psfFrom
, lpcida
->cidl
, (LPCITEMIDLIST
*)apidl
);
270 ISFHelper_DeleteItems(psfhlpsrc, lpcida->cidl, apidl);
273 if(psfhlpdst
) ISFHelper_Release(psfhlpdst
);
274 if(psfhlpsrc
) ISFHelper_Release(psfhlpsrc
);
275 IShellFolder_Release(psfFrom
);
278 _ILFreeaPidl(apidl
, lpcida
->cidl
);
281 /* release the medium*/
282 pReleaseStgMedium(&medium
);
284 IDataObject_Release(pda
);
290 hMem
= GetClipboardData(CF_HDROP
);
294 char * pDropFiles
= (char *)GlobalLock(hMem
);
297 int len
, offset
= sizeof(DROPFILESTRUCT
);
299 while( pDropFiles
[offset
] != 0)
301 len
= strlen(pDropFiles
+ offset
);
302 TRACE("%s\n", pDropFiles
+ offset
);
312 /**************************************************************************
313 * ISVBgCm_fnInvokeCommand()
315 static HRESULT WINAPI
ISVBgCm_fnInvokeCommand(
317 LPCMINVOKECOMMANDINFO lpcmi
)
319 ICOM_THIS(BgCmImpl
, iface
);
325 TRACE("(%p)->(invcom=%p verb=%p wnd=%p)\n",This
,lpcmi
,lpcmi
->lpVerb
, lpcmi
->hwnd
);
327 /* get the active IShellView */
328 if((lpSB
= (LPSHELLBROWSER
)SendMessageA(lpcmi
->hwnd
, CWM_GETISHELLBROWSER
,0,0)))
330 if(SUCCEEDED(IShellBrowser_QueryActiveShellView(lpSB
, &lpSV
)))
332 IShellView_GetWindow(lpSV
, &hWndSV
);
338 if(HIWORD(lpcmi
->lpVerb
))
340 TRACE("%s\n",lpcmi
->lpVerb
);
342 if (! strcmp(lpcmi
->lpVerb
,CMDSTR_NEWFOLDERA
))
344 if(lpSV
) 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_NEWFOLDER
:
364 DoNewFolder(iface
, lpSV
);
366 case FCIDM_SHVIEW_INSERT
:
370 /* if it's a id just pass it to the parent shv */
371 SendMessageA(hWndSV
, WM_COMMAND
, MAKEWPARAM(LOWORD(lpcmi
->lpVerb
), 0),0 );
376 IShellView_Release(lpSV
); /* QueryActiveShellView does AddRef*/
381 /**************************************************************************
382 * ISVBgCm_fnGetCommandString()
385 static HRESULT WINAPI
ISVBgCm_fnGetCommandString(
393 ICOM_THIS(BgCmImpl
, iface
);
395 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This
, idCommand
, uFlags
, lpReserved
, lpszName
, uMaxNameLen
);
397 /* test the existence of the menu items, the file dialog enables
398 the buttons according to this */
399 if (uFlags
== GCS_VALIDATEA
)
401 if(HIWORD(idCommand
))
403 if (!strcmp((LPSTR
)idCommand
, CMDSTR_VIEWLISTA
) ||
404 !strcmp((LPSTR
)idCommand
, CMDSTR_VIEWDETAILSA
) ||
405 !strcmp((LPSTR
)idCommand
, CMDSTR_NEWFOLDERA
))
412 FIXME("unknown command string\n");
416 /**************************************************************************
417 * ISVBgCm_fnHandleMenuMsg()
419 static HRESULT WINAPI
ISVBgCm_fnHandleMenuMsg(
425 ICOM_THIS(BgCmImpl
, iface
);
427 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This
, uMsg
, wParam
, lParam
);
432 /**************************************************************************
433 * IContextMenu VTable
436 static struct ICOM_VTABLE(IContextMenu
) cmvt
=
438 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
439 ISVBgCm_fnQueryInterface
,
442 ISVBgCm_fnQueryContextMenu
,
443 ISVBgCm_fnInvokeCommand
,
444 ISVBgCm_fnGetCommandString
,
445 ISVBgCm_fnHandleMenuMsg
,
446 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */