Moved various DLLs to dlls/
[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_VTABLE(IContextMenu)* lpvtbl;
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         cm->lpvtbl=&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         char    xriid[50];
57         WINE_StringFromCLSID((LPCLSID)riid,xriid);
58
59         TRACE("(%p)->(\n\tIID:\t%s,%p)\n",This,xriid,ppvObj);
60
61         *ppvObj = NULL;
62
63         if(IsEqualIID(riid, &IID_IUnknown))          /*IUnknown*/
64         {
65           *ppvObj = This; 
66         }
67         else if(IsEqualIID(riid, &IID_IContextMenu))  /*IContextMenu*/
68         {
69           *ppvObj = This;
70         }   
71         else if(IsEqualIID(riid, &IID_IShellExtInit))  /*IShellExtInit*/
72         {
73           FIXME("-- LPSHELLEXTINIT pointer requested\n");
74         }
75
76         if(*ppvObj)
77         { 
78           IUnknown_AddRef((IUnknown*)*ppvObj);      
79           TRACE("-- Interface: (%p)->(%p)\n",ppvObj,*ppvObj);
80           return S_OK;
81         }
82         TRACE("-- Interface: E_NOINTERFACE\n");
83         return E_NOINTERFACE;
84 }
85
86 /**************************************************************************
87 *  ISVBgCm_fnAddRef
88 */
89 static ULONG WINAPI ISVBgCm_fnAddRef(IContextMenu *iface)
90 {
91         ICOM_THIS(BgCmImpl, iface);
92
93         TRACE("(%p)->(count=%lu)\n",This, This->ref);
94
95         shell32_ObjCount++;
96         return ++(This->ref);
97 }
98
99 /**************************************************************************
100 *  ISVBgCm_fnRelease
101 */
102 static ULONG WINAPI ISVBgCm_fnRelease(IContextMenu *iface)
103 {
104         ICOM_THIS(BgCmImpl, iface);
105
106         TRACE("(%p)->()\n",This);
107
108         shell32_ObjCount--;
109
110         if (!--(This->ref)) 
111         { TRACE(" destroying IContextMenu(%p)\n",This);
112
113           HeapFree(GetProcessHeap(),0,This);
114           return 0;
115         }
116         return This->ref;
117 }
118
119 /**************************************************************************
120 * ISVBgCm_fnQueryContextMenu()
121 */
122
123 static HRESULT WINAPI ISVBgCm_fnQueryContextMenu(
124         IContextMenu *iface,
125         HMENU hMenu,
126         UINT indexMenu,
127         UINT idCmdFirst,
128         UINT idCmdLast,
129         UINT uFlags)
130 {
131         HMENU   hMyMenu;
132         UINT    idMax;
133         
134         ICOM_THIS(BgCmImpl, iface);
135
136         TRACE("(%p)->(hmenu=%x indexmenu=%x cmdfirst=%x cmdlast=%x flags=%x )\n",This, hMenu, indexMenu, idCmdFirst, idCmdLast, uFlags);
137
138         hMyMenu = LoadMenuA(shell32_hInstance, "MENU_002");
139
140         idMax = Shell_MergeMenus (hMenu, GetSubMenu(hMyMenu,0), indexMenu, idCmdFirst, idCmdLast, MM_SUBMENUSHAVEIDS);
141
142         DestroyMenu(hMyMenu);
143
144         return ResultFromShort(idMax - idCmdFirst);
145 }
146
147 /**************************************************************************
148 * ISVBgCm_fnInvokeCommand()
149 */
150 static HRESULT WINAPI ISVBgCm_fnInvokeCommand(
151         IContextMenu *iface,
152         LPCMINVOKECOMMANDINFO lpcmi)
153 {
154         ICOM_THIS(BgCmImpl, iface);
155
156         LPSHELLBROWSER  lpSB;
157         LPSHELLVIEW     lpSV;
158         HWND    hWndSV;
159
160         TRACE("(%p)->(invcom=%p verb=%p wnd=%x)\n",This,lpcmi,lpcmi->lpVerb, lpcmi->hwnd);    
161
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);
166
167         if(HIWORD(lpcmi->lpVerb))
168         {
169           TRACE("%s\n",lpcmi->lpVerb);
170
171           if (! strcmp(lpcmi->lpVerb,CMDSTR_NEWFOLDER))
172           {
173             FIXME("%s not implemented\n",lpcmi->lpVerb);
174           }
175           else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWLIST))
176           {
177             SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
178           }
179           else if (! strcmp(lpcmi->lpVerb,CMDSTR_VIEWDETAILS))
180           {
181             SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
182           } 
183           else
184           {
185             FIXME("please report: unknown verb %s\n",lpcmi->lpVerb);
186           }
187         }
188         else
189         {
190           switch(LOWORD(lpcmi->lpVerb))
191           {
192             case FCIDM_SHVIEW_BIGICON:
193               SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_BIGICON,0),0 );
194               break;
195
196             case FCIDM_SHVIEW_SMALLICON:
197               SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_SMALLICON,0),0 );
198
199             case FCIDM_SHVIEW_LISTVIEW:
200               SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_LISTVIEW,0),0 );
201               break;
202
203             case FCIDM_SHVIEW_REPORTVIEW:
204               SendMessageA(hWndSV, WM_COMMAND, MAKEWPARAM(FCIDM_SHVIEW_REPORTVIEW,0),0 );
205               break;
206           }
207         }
208         
209         IShellView_Release(lpSV);       /* QueryActiveShellView does AddRef*/
210         return NOERROR;
211 }
212
213 /**************************************************************************
214  *  ISVBgCm_fnGetCommandString()
215  *
216  * NOTES
217  *  the values given by the common dialogs are not documented. so we put some magic
218  *  words in it and will see, where we get these verbs back...
219  */
220 static HRESULT WINAPI ISVBgCm_fnGetCommandString(
221         IContextMenu *iface,
222         UINT idCommand,
223         UINT uFlags,
224         LPUINT lpReserved,
225         LPSTR lpszName,
226         UINT uMaxNameLen)
227 {       
228         ICOM_THIS(BgCmImpl, iface);
229
230         TRACE("(%p)->(idcom=%x flags=%x %p name=%p len=%x)\n",This, idCommand, uFlags, lpReserved, lpszName, uMaxNameLen);
231
232         /* test the existance of the menu items, the file dialog enables 
233            the buttons according to this */
234         if (uFlags == GCS_VALIDATEA)
235         {
236           /* idCommmand's are 7febd910, 7febd920, 7febd930 */
237           if ((idCommand==0x7febd910) ||
238               (idCommand==0x7febd920) ||
239               (idCommand==0x7febd930))
240           {     
241             return NOERROR;
242           }
243         }
244
245         FIXME("unknown command string\n");
246         return E_FAIL;
247 }
248
249 /**************************************************************************
250 * ISVBgCm_fnHandleMenuMsg()
251 */
252 static HRESULT WINAPI ISVBgCm_fnHandleMenuMsg(
253         IContextMenu *iface,
254         UINT uMsg,
255         WPARAM wParam,
256         LPARAM lParam)
257 {
258         ICOM_THIS(BgCmImpl, iface);
259
260         FIXME("(%p)->(msg=%x wp=%x lp=%lx)\n",This, uMsg, wParam, lParam);
261
262         return E_NOTIMPL;
263 }
264
265 /**************************************************************************
266 * IContextMenu VTable
267
268 */
269 static struct ICOM_VTABLE(IContextMenu) cmvt = 
270 {       
271         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
272         ISVBgCm_fnQueryInterface,
273         ISVBgCm_fnAddRef,
274         ISVBgCm_fnRelease,
275         ISVBgCm_fnQueryContextMenu,
276         ISVBgCm_fnInvokeCommand,
277         ISVBgCm_fnGetCommandString,
278         ISVBgCm_fnHandleMenuMsg,
279         (void *) 0xdeadbabe     /* just paranoia (IContextMenu3) */
280 };
281