- implemented sorting the listview by clicking on the column header
[wine/gsoc_dplay.git] / dlls / shell32 / shv_bg_cmenu.c
blob735758dae93a9d23913dfc4545d3942cc7c0af7b
1 /*
2 * IContextMenu
3 * ShellView Background Context Menu (shv_bg_cm)
5 * Copyright 1999 Juergen Schmied <juergen.schmied@metronet.de>
6 */
7 #include <string.h>
9 #include "winerror.h"
10 #include "debugtools.h"
12 #include "pidl.h"
13 #include "wine/obj_base.h"
14 #include "wine/obj_contextmenu.h"
15 #include "wine/obj_shellbrowser.h"
16 #include "wine/obj_shellextinit.h"
18 #include "shell32_main.h"
20 DEFAULT_DEBUG_CHANNEL(shell)
22 /**************************************************************************
23 * IContextMenu Implementation
25 typedef struct
26 { ICOM_VTABLE(IContextMenu)* lpvtbl;
27 DWORD ref;
28 } BgCmImpl;
31 static struct ICOM_VTABLE(IContextMenu) cmvt;
33 /**************************************************************************
34 * ISVBgCm_Constructor()
36 IContextMenu *ISvBgCm_Constructor(void)
38 BgCmImpl* cm;
40 cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
41 cm->lpvtbl=&cmvt;
42 cm->ref = 1;
44 TRACE("(%p)->()\n",cm);
45 shell32_ObjCount++;
46 return (IContextMenu*)cm;
49 /**************************************************************************
50 * ISVBgCm_fnQueryInterface
52 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
54 ICOM_THIS(BgCmImpl, iface);
56 char xriid[50];
57 WINE_StringFromCLSID((LPCLSID)riid,xriid);
59 TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
61 *ppvObj = NULL;
63 if(IsEqualIID(riid, &IID_IUnknown)) /*IUnknown*/
65 *ppvObj = This;
67 else if(IsEqualIID(riid, &IID_IContextMenu)) /*IContextMenu*/
69 *ppvObj = This;
71 else if(IsEqualIID(riid, &IID_IShellExtInit)) /*IShellExtInit*/
73 FIXME("-- LPSHELLEXTINIT pointer requested\n");
76 if(*ppvObj)
78 IUnknown_AddRef((IUnknown*)*ppvObj);
79 TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
80 return S_OK;
82 TRACE("-- Interface: E_NOINTERFACE\n");
83 return E_NOINTERFACE;
86 /**************************************************************************
87 * ISVBgCm_fnAddRef
89 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
91 ICOM_THIS(BgCmImpl, iface);
93 TRACE("(%p)->(count=%lu)\n",This, This->ref);
95 shell32_ObjCount++;
96 return ++(This->ref);
99 /**************************************************************************
100 * ISVBgCm_fnRelease
102 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
104 ICOM_THIS(BgCmImpl, iface);
106 TRACE("(%p)->()\n",This);
108 shell32_ObjCount--;
110 if (!--(This->ref))
111 { TRACE(" destroying IContextMenu(%p)\n",This);
113 HeapFree(GetProcessHeap(),0,This);
114 return 0;
116 return This->ref;
119 /**************************************************************************
120 * ISVBgCm_fnQueryContextMenu()
123 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
124 IContextMenu *iface,
125 HMENU hMenu,
126 UINT indexMenu,
127 UINT idCmdFirst,
128 UINT idCmdLast,
129 UINT uFlags)
131 HMENU hMyMenu;
132 UINT idMax;
134 ICOM_THIS(BgCmImpl, iface);
136 TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
138 hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
140 idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
142 DestroyMenu(hMyMenu);
144 return ResultFromShort(idMax - idCmdFirst);
147 /**************************************************************************
148 * ISVBgCm_fnInvokeCommand()
150 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
151 IContextMenu *iface,
152 LPCMINVOKECOMMANDINFO lpcmi)
154 ICOM_THIS(BgCmImpl, iface);
156 LPSHELLBROWSER lpSB;
157 LPSHELLVIEW lpSV;
158 HWND hWndSV;
160 TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);
162 /* get the active IShellView */
163 lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0);
164 IShellBrowser_QueryActiveShellView(lpSB, &lpSV);
165 IShellView_GetWindow(lpSV, &hWndSV);
167 if(HIWORD(lpcmi->lpVerb))
169 TRACE("%s\n",lpcmi->lpVerb);
171 if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
173 FIXME("%s not implemented\n",lpcmi->lpVerb);
175 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
177 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
179 else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
181 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
183 else
185 FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
188 else
190 switch(LOWORD(lpcmi->lpVerb))
192 case FCIDM_SHVIEW_BIGICON:
193 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_BIGICON,0),0 );
194 break;
196 case FCIDM_SHVIEW_SMALLICON:
197 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_SMALLICON,0),0 );
199 case FCIDM_SHVIEW_LISTVIEW:
200 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
201 break;
203 case FCIDM_SHVIEW_REPORTVIEW:
204 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
205 break;
207 default:
208 SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
209 break;
213 IShellView_Release(lpSV); /* QueryActiveShellView does AddRef*/
214 return NOERROR;
217 /**************************************************************************
218 * ISVBgCm_fnGetCommandString()
221 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
222 IContextMenu *iface,
223 UINT idCommand,
224 UINT uFlags,
225 LPUINT lpReserved,
226 LPSTR lpszName,
227 UINT uMaxNameLen)
229 ICOM_THIS(BgCmImpl, iface);
231 TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
233 /* test the existance of the menu items, the file dialog enables
234 the buttons according to this */
235 if (uFlags == GCS_VALIDATEA)
237 if(HIWORD(idCommand))
239 if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
240 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
241 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
243 return NOERROR;
248 FIXME("unknown command string\n");
249 return E_FAIL;
252 /**************************************************************************
253 * ISVBgCm_fnHandleMenuMsg()
255 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
256 IContextMenu *iface,
257 UINT uMsg,
258 WPARAM wParam,
259 LPARAM lParam)
261 ICOM_THIS(BgCmImpl, iface);
263 FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
265 return E_NOTIMPL;
268 /**************************************************************************
269 * IContextMenu VTable
272 static struct ICOM_VTABLE(IContextMenu) cmvt =
274 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
275 ISVBgCm_fnQueryInterface,
276 ISVBgCm_fnAddRef,
277 ISVBgCm_fnRelease,
278 ISVBgCm_fnQueryContextMenu,
279 ISVBgCm_fnInvokeCommand,
280 ISVBgCm_fnGetCommandString,
281 ISVBgCm_fnHandleMenuMsg,
282 (void *) 0xdeadbabe /* just paranoia (IContextMenu3) */