- implementation of RtlReg* (read access), RtlEvent*, RtlSemaphore*,
[wine] / dlls / shell32 / shv_bg_cmenu.c
1 /*
2  *      IContextMenu
3  *      ShellView Background Context Menu (shv_bg_cm)
4  *
5  *      Copyright 1999  Juergen Schmied <juergen.schmied@metronet.de>
6  */
7 #include <string.h>
8
9 #include "winerror.h"
10 #include "debugtools.h"
11
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"
17
18 #include "shell32_main.h"
19
20 DEFAULT_DEBUG_CHANNEL(shell)
21
22 /**************************************************************************
23 *  IContextMenu Implementation
24 */
25 typedef struct 
26 {       ICOM_VFIELD(IContextMenu);
27         DWORD           ref;
28 } BgCmImpl;
29
30
31 static struct ICOM_VTABLE(IContextMenu) cmvt;
32
33 /**************************************************************************
34 *   ISVBgCm_Constructor()
35 */
36 IContextMenu *ISvBgCm_Constructor(void)
37 {
38         BgCmImpl* cm;
39
40         cm = (BgCmImpl*)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(BgCmImpl));
41         ICOM_VTBL(cm)=&cmvt;
42         cm->ref = 1;
43
44         TRACE("(%p)->()\n",cm);
45         shell32_ObjCount++;
46         return (IContextMenu*)cm;
47 }
48
49 /**************************************************************************
50 *  ISVBgCm_fnQueryInterface
51 */
52 static HRESULT WINAPI ISVBgCm_fnQueryInterface(IContextMenu *iface, REFIID riid, LPVOID *ppvObj)
53 {
54         ICOM_THIS(BgCmImpl, iface);
55
56         TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,debugstr_guid(riid),ppvObj);
57
58         *ppvObj = NULL;
59
60         if(IsEqualIID(riid, &IID_IUnknown))          /*IUnknown*/
61         {
62           *ppvObj = This; 
63         }
64         else if(IsEqualIID(riid, &IID_IContextMenu))  /*IContextMenu*/
65         {
66           *ppvObj = This;
67         }   
68         else if(IsEqualIID(riid, &IID_IShellExtInit))  /*IShellExtInit*/
69         {
70           FIXME("-- LPSHELLEXTINIT pointer requested\n");
71         }
72
73         if(*ppvObj)
74         { 
75           IUnknown_AddRef((IUnknown*)*ppvObj);      
76           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
77           return S_OK;
78         }
79         TRACE("-- Interface: E_NOINTERFACE\n");
80         return E_NOINTERFACE;
81 }
82
83 /**************************************************************************
84 *  ISVBgCm_fnAddRef
85 */
86 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
87 {
88         ICOM_THIS(BgCmImpl, iface);
89
90         TRACE("(%p)->(count=%lu)\n",This, This->ref);
91
92         shell32_ObjCount++;
93         return ++(This->ref);
94 }
95
96 /**************************************************************************
97 *  ISVBgCm_fnRelease
98 */
99 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
100 {
101         ICOM_THIS(BgCmImpl, iface);
102
103         TRACE("(%p)->()\n",This);
104
105         shell32_ObjCount--;
106
107         if (!--(This->ref)) 
108         { TRACE(" destroying IContextMenu(%p)\n",This);
109
110           HeapFree(GetProcessHeap(),0,This);
111           return 0;
112         }
113         return This->ref;
114 }
115
116 /**************************************************************************
117 * ISVBgCm_fnQueryContextMenu()
118 */
119
120 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
121         IContextMenu *iface,
122         HMENU hMenu,
123         UINT indexMenu,
124         UINT idCmdFirst,
125         UINT idCmdLast,
126         UINT uFlags)
127 {
128         HMENU   hMyMenu;
129         UINT    idMax;
130         
131         ICOM_THIS(BgCmImpl, iface);
132
133         TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
134
135         hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
136
137         idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
138
139         DestroyMenu(hMyMenu);
140
141         return ResultFromShort(idMax - idCmdFirst);
142 }
143
144 /**************************************************************************
145 * ISVBgCm_fnInvokeCommand()
146 */
147 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
148         IContextMenu *iface,
149         LPCMINVOKECOMMANDINFO lpcmi)
150 {
151         ICOM_THIS(BgCmImpl, iface);
152
153         LPSHELLBROWSER  lpSB;
154         LPSHELLVIEW     lpSV;
155         HWND    hWndSV;
156
157         TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);    
158
159         /* get the active IShellView */
160         lpSB = (LPSHELLBROWSER)SendMessageA(lpcmi->hwnd, CWM_GETISHELLBROWSER,0,0);
161         IShellBrowser_QueryActiveShellView(lpSB, &lpSV);
162         IShellView_GetWindow(lpSV, &hWndSV);
163
164         if(HIWORD(lpcmi->lpVerb))
165         {
166           TRACE("%s\n",lpcmi->lpVerb);
167
168           if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDERA))
169           {
170             FIXME("%s not implemented\n",lpcmi->lpVerb);
171           }
172           else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLISTA))
173           {
174             SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
175           }
176           else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILSA))
177           {
178             SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
179           } 
180           else
181           {
182             FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
183           }
184         }
185         else
186         {
187           /* if it's a id just pass it to the parent shv */
188           SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(LOWORD(lpcmi->lpVerb), 0),0 );
189         }
190         
191         IShellView_Release(lpSV);       /* QueryActiveShellView does AddRef*/
192         return NOERROR;
193 }
194
195 /**************************************************************************
196  *  ISVBgCm_fnGetCommandString()
197  *
198  */
199 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
200         IContextMenu *iface,
201         UINT idCommand,
202         UINT uFlags,
203         LPUINT lpReserved,
204         LPSTR lpszName,
205         UINT uMaxNameLen)
206 {       
207         ICOM_THIS(BgCmImpl, iface);
208
209         TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
210
211         /* test the existance of the menu items, the file dialog enables 
212            the buttons according to this */
213         if (uFlags == GCS_VALIDATEA)
214         {
215           if(HIWORD(idCommand))
216           {
217             if (!strcmp((LPSTR)idCommand, CMDSTR_VIEWLISTA) ||
218                 !strcmp((LPSTR)idCommand, CMDSTR_VIEWDETAILSA) ||
219                 !strcmp((LPSTR)idCommand, CMDSTR_NEWFOLDERA))
220             {   
221               return NOERROR;
222             }
223           }
224         }
225
226         FIXME("unknown command string\n");
227         return E_FAIL;
228 }
229
230 /**************************************************************************
231 * ISVBgCm_fnHandleMenuMsg()
232 */
233 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
234         IContextMenu *iface,
235         UINT uMsg,
236         WPARAM wParam,
237         LPARAM lParam)
238 {
239         ICOM_THIS(BgCmImpl, iface);
240
241         FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
242
243         return E_NOTIMPL;
244 }
245
246 /**************************************************************************
247 * IContextMenu VTable
248
249 */
250 static struct ICOM_VTABLE(IContextMenu) cmvt = 
251 {       
252         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
253         ISVBgCm_fnQueryInterface,
254         ISVBgCm_fnAddRef,
255         ISVBgCm_fnRelease,
256         ISVBgCm_fnQueryContextMenu,
257         ISVBgCm_fnInvokeCommand,
258         ISVBgCm_fnGetCommandString,
259         ISVBgCm_fnHandleMenuMsg,
260         (void *) 0xdeadbabe     /* just paranoia (IContextMenu3) */
261 };
262