[RSHELL]
[reactos.git] / base / shell / rshell / logging / CMenuSiteWrap.cpp
1 /*
2 * Shell Menu Site
3 *
4 * Copyright 2014 David Quintana
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "precomp.h"
22 #include "wraplog.h"
23
24 WINE_DEFAULT_DEBUG_CHANNEL(menusite);
25
26 class CMenuSiteWrap :
27 public CComCoClass<CMenuSiteWrap>,
28 public CComObjectRootEx<CComMultiThreadModelNoCS>,
29 public IBandSite,
30 public IDeskBarClient,
31 public IOleCommandTarget,
32 public IInputObject,
33 public IInputObjectSite,
34 public IWinEventHandler,
35 public IServiceProvider
36 {
37 public:
38 CMenuSiteWrap() {}
39 ~CMenuSiteWrap();
40
41 HRESULT InitWrap(IBandSite * bandSite);
42
43 private:
44 CComPtr<IBandSite > m_IBandSite;
45 CComPtr<IDeskBarClient > m_IDeskBarClient;
46 CComPtr<IOleWindow > m_IOleWindow;
47 CComPtr<IOleCommandTarget> m_IOleCommandTarget;
48 CComPtr<IInputObject > m_IInputObject;
49 CComPtr<IInputObjectSite > m_IInputObjectSite;
50 CComPtr<IWinEventHandler > m_IWinEventHandler;
51 CComPtr<IServiceProvider > m_IServiceProvider;
52
53 public:
54 // IBandSite
55 virtual HRESULT STDMETHODCALLTYPE AddBand(IUnknown * punk);
56 virtual HRESULT STDMETHODCALLTYPE EnumBands(UINT uBand, DWORD* pdwBandID);
57 virtual HRESULT STDMETHODCALLTYPE QueryBand(DWORD dwBandID, IDeskBand **ppstb, DWORD *pdwState, LPWSTR pszName, int cchName);
58 virtual HRESULT STDMETHODCALLTYPE GetBandObject(DWORD dwBandID, REFIID riid, VOID **ppv);
59 virtual HRESULT STDMETHODCALLTYPE GetBandSiteInfo(BANDSITEINFO *pbsinfo);
60 virtual HRESULT STDMETHODCALLTYPE RemoveBand(DWORD dwBandID);
61 virtual HRESULT STDMETHODCALLTYPE SetBandSiteInfo(const BANDSITEINFO *pbsinfo);
62 virtual HRESULT STDMETHODCALLTYPE SetBandState(DWORD dwBandID, DWORD dwMask, DWORD dwState);
63
64 // IDeskBarClient
65 virtual HRESULT STDMETHODCALLTYPE SetDeskBarSite(IUnknown *punkSite);
66 virtual HRESULT STDMETHODCALLTYPE SetModeDBC(DWORD dwMode);
67 virtual HRESULT STDMETHODCALLTYPE GetSize(DWORD dwWhich, LPRECT prc);
68 virtual HRESULT STDMETHODCALLTYPE UIActivateDBC(DWORD dwState);
69
70 // IOleWindow
71 virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *phwnd);
72 virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode);
73
74 // IOleCommandTarget
75 virtual HRESULT STDMETHODCALLTYPE QueryStatus(const GUID * pguidCmdGroup, ULONG cCmds, OLECMD prgCmds [], OLECMDTEXT *pCmdText);
76 virtual HRESULT STDMETHODCALLTYPE Exec(const GUID * pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut);
77
78 // IInputObject
79 virtual HRESULT STDMETHODCALLTYPE UIActivateIO(BOOL fActivate, LPMSG lpMsg);
80 virtual HRESULT STDMETHODCALLTYPE HasFocusIO();
81 virtual HRESULT STDMETHODCALLTYPE TranslateAcceleratorIO(LPMSG lpMsg);
82
83 // IInputObjectSite
84 virtual HRESULT STDMETHODCALLTYPE OnFocusChangeIS(IUnknown *punkObj, BOOL fSetFocus);
85
86 // IWinEventHandler
87 virtual HRESULT STDMETHODCALLTYPE IsWindowOwner(HWND hWnd);
88 virtual HRESULT STDMETHODCALLTYPE OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult);
89
90 // IServiceProvider
91 virtual HRESULT STDMETHODCALLTYPE QueryService(REFGUID guidService, REFIID riid, void **ppvObject);
92
93 DECLARE_NOT_AGGREGATABLE(CMenuSiteWrap)
94 DECLARE_PROTECT_FINAL_CONSTRUCT()
95 BEGIN_COM_MAP(CMenuSiteWrap)
96 COM_INTERFACE_ENTRY_IID(IID_IBandSite, IBandSite)
97 COM_INTERFACE_ENTRY_IID(IID_IDeskBarClient, IDeskBarClient)
98 COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleWindow)
99 COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
100 COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject)
101 COM_INTERFACE_ENTRY_IID(IID_IInputObjectSite, IInputObjectSite)
102 COM_INTERFACE_ENTRY_IID(IID_IWinEventHandler, IWinEventHandler)
103 COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
104 END_COM_MAP()
105 };
106
107 extern "C"
108 HRESULT CMenuSite_Wrapper(IBandSite * bandSite, REFIID riid, LPVOID *ppv)
109 {
110 HRESULT hr;
111
112 *ppv = NULL;
113
114 CMenuSiteWrap * site = new CComObject<CMenuSiteWrap>();
115
116 if (!site)
117 return E_OUTOFMEMORY;
118
119 hr = site->InitWrap(bandSite);
120 if (FAILED(hr))
121 {
122 site->Release();
123 return hr;
124 }
125
126 hr = site->QueryInterface(riid, ppv);
127
128 if (FAILED(hr))
129 site->Release();
130
131 return hr;
132 }
133
134 HRESULT CMenuSiteWrap::InitWrap(IBandSite * bandSite)
135 {
136 HRESULT hr;
137
138 WrapLogOpen();
139
140 m_IBandSite = bandSite;
141
142 hr = bandSite->QueryInterface(IID_PPV_ARG(IDeskBarClient, &m_IDeskBarClient));
143 if (FAILED(hr)) return hr;
144 hr = bandSite->QueryInterface(IID_PPV_ARG(IOleWindow, &m_IOleWindow));
145 if (FAILED(hr)) return hr;
146 hr = bandSite->QueryInterface(IID_PPV_ARG(IOleCommandTarget, &m_IOleCommandTarget));
147 if (FAILED(hr)) return hr;
148 hr = bandSite->QueryInterface(IID_PPV_ARG(IInputObject, &m_IInputObject));
149 if (FAILED(hr)) return hr;
150 hr = bandSite->QueryInterface(IID_PPV_ARG(IInputObjectSite, &m_IInputObjectSite));
151 if (FAILED(hr)) return hr;
152 hr = bandSite->QueryInterface(IID_PPV_ARG(IWinEventHandler, &m_IWinEventHandler));
153 if (FAILED(hr)) return hr;
154 hr = bandSite->QueryInterface(IID_PPV_ARG(IServiceProvider, &m_IServiceProvider));
155 return hr;
156 }
157
158 CMenuSiteWrap::~CMenuSiteWrap()
159 {
160 WrapLogClose();
161 }
162
163 // IBandSite
164 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::AddBand(IUnknown * punk)
165 {
166 WrapLogEnter("CMenuSiteWrap<%p>::AddBand(IUnknown * punk=%p)\n", this, punk);
167 HRESULT hr = m_IBandSite->AddBand(punk);
168 WrapLogExit("CMenuSiteWrap::AddBand()", hr);
169 return hr;
170 }
171
172 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::EnumBands(UINT uBand, DWORD* pdwBandID)
173 {
174 WrapLogEnter("CMenuSiteWrap<%p>::EnumBands(UINT uBand=%u, DWORD* pdwBandID=%p)\n", this, uBand, pdwBandID);
175 HRESULT hr = m_IBandSite->EnumBands(uBand, pdwBandID);
176 if (pdwBandID) WrapLogPost("*pdwBandID=%d\n", *pdwBandID);
177 WrapLogExit("CMenuSiteWrap::EnumBands()", hr);
178 return hr;
179 }
180
181 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::QueryBand(DWORD dwBandID, IDeskBand **ppstb, DWORD *pdwState, LPWSTR pszName, int cchName)
182 {
183 WrapLogEnter("CMenuSiteWrap<%p>::QueryBand(DWORD dwBandID=%d, IDeskBand **ppstb=%p, DWORD *pdwState=%p, LPWSTR pszName=%p, int cchName=%p)\n", this, dwBandID, ppstb, pdwState, pszName, cchName);
184 HRESULT hr = m_IBandSite->QueryBand(dwBandID, ppstb, pdwState, pszName, cchName);
185 if (ppstb) WrapLogPost("*ppstb=%p\n", *ppstb);
186 if (pdwState) WrapLogPost("*pdwState=%d\n", *pdwState);
187 WrapLogExit("CMenuSiteWrap::QueryBand()", hr);
188 return hr;
189 }
190
191 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::GetBandObject(DWORD dwBandID, REFIID riid, VOID **ppv)
192 {
193 WrapLogEnter("CMenuSiteWrap<%p>::GetBandObject(DWORD dwBandID, REFIID riid, VOID **ppv)\n", this, dwBandID, riid, ppv);
194 HRESULT hr = m_IBandSite->GetBandObject(dwBandID, riid, ppv);
195 if (ppv) WrapLogPost("*ppv=%p\n", *ppv);
196 WrapLogExit("CMenuSiteWrap::GetBandObject()", hr);
197 return hr;
198 }
199
200 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::GetBandSiteInfo(BANDSITEINFO *pbsinfo)
201 {
202 WrapLogEnter("CMenuSiteWrap<%p>::GetBandSiteInfo(BANDSITEINFO *pbsinfo=%p)\n", this, pbsinfo);
203 HRESULT hr = m_IBandSite->GetBandSiteInfo(pbsinfo);
204 if (pbsinfo) WrapLogPost("*pbsinfo=%p\n", *pbsinfo);
205 WrapLogExit("CMenuSiteWrap::GetBandSiteInfo()", hr);
206 return hr;
207 }
208
209 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::RemoveBand(DWORD dwBandID)
210 {
211 WrapLogEnter("CMenuSiteWrap<%p>::RemoveBand(DWORD dwBandID=%d)\n", this, dwBandID);
212 HRESULT hr = m_IBandSite->RemoveBand(dwBandID);
213 WrapLogExit("CMenuSiteWrap::RemoveBand()", hr);
214 return hr;
215 }
216
217 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::SetBandSiteInfo(const BANDSITEINFO *pbsinfo)
218 {
219 WrapLogEnter("CMenuSiteWrap<%p>::SetBandSiteInfo(const BANDSITEINFO *pbsinfo=%p)\n", this, pbsinfo);
220 //if (phwnd) WrapLogPost("*pbsinfo=%s\n", Wrap(*pbsinfo));
221 HRESULT hr = m_IBandSite->SetBandSiteInfo(pbsinfo);
222 WrapLogExit("CMenuSiteWrap::SetBandSiteInfo()", hr);
223 return hr;
224 }
225
226 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::SetBandState(DWORD dwBandID, DWORD dwMask, DWORD dwState)
227 {
228 WrapLogEnter("CMenuSiteWrap<%p>::SetBandState(DWORD dwBandID=%d, DWORD dwMask=%08x, DWORD dwState=%d)\n", this, dwBandID, dwMask, dwState);
229 HRESULT hr = m_IBandSite->SetBandState(dwBandID, dwMask, dwState);
230 WrapLogExit("CMenuSiteWrap::SetBandState()", hr);
231 return hr;
232 }
233
234 // *** IDeskBarClient ***
235 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::SetDeskBarSite(IUnknown *punkSite)
236 {
237 WrapLogEnter("CMenuSiteWrap<%p>::SetDeskBarSite(IUnknown *punkSite=%p)\n", this, punkSite);
238 HRESULT hr = m_IDeskBarClient->SetDeskBarSite(punkSite);
239 if (punkSite) WrapLogPost("*punkSite=%p\n", *punkSite);
240 WrapLogExit("CMenuSiteWrap::SetDeskBarSite()", hr);
241 return hr;
242 }
243
244 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::SetModeDBC(DWORD dwMode)
245 {
246 WrapLogEnter("CMenuSiteWrap<%p>::SetModeDBC(DWORD dwMode=%d)\n", this, dwMode);
247 HRESULT hr = m_IDeskBarClient->SetModeDBC(dwMode);
248 WrapLogExit("CMenuSiteWrap::SetModeDBC()", hr);
249 return hr;
250 }
251
252 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::GetSize(DWORD dwWhich, LPRECT prc)
253 {
254 WrapLogEnter("CMenuSiteWrap<%p>::GetSize(DWORD dwWhich=%d, LPRECT prc=%p)\n", this, dwWhich, prc);
255 HRESULT hr = m_IDeskBarClient->GetSize(dwWhich, prc);
256 if (prc) WrapLogPost("*prc=%s\n", Wrap(*prc));
257 WrapLogExit("CMenuSiteWrap::GetSize()", hr);
258 return hr;
259 }
260
261 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::UIActivateDBC(DWORD dwState)
262 {
263 WrapLogEnter("CMenuSiteWrap<%p>::UIActivateDBC(DWORD dwState=%d)\n", this, dwState);
264 HRESULT hr = m_IDeskBarClient->UIActivateDBC(dwState);
265 WrapLogExit("CMenuSiteWrap::UIActivateDBC()", hr);
266 return hr;
267 }
268
269 // *** IOleWindow methods ***
270 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::GetWindow(HWND *phwnd)
271 {
272 WrapLogEnter("CMenuSiteWrap<%p>::GetWindow(HWND *phwnd=%p)\n", this, phwnd);
273 HRESULT hr = m_IOleWindow->GetWindow(phwnd);
274 if (phwnd) WrapLogPost("*phwnd=%p\n", *phwnd);
275 WrapLogExit("CMenuSiteWrap::GetWindow()", hr);
276 return hr;
277 }
278
279 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::ContextSensitiveHelp(BOOL fEnterMode)
280 {
281 WrapLogEnter("CMenuSiteWrap<%p>::ContextSensitiveHelp(BOOL fEnterMode=%d)\n", this, fEnterMode);
282 HRESULT hr = m_IOleWindow->ContextSensitiveHelp(fEnterMode);
283 WrapLogExit("CMenuSiteWrap::ContextSensitiveHelp()", hr);
284 return hr;
285 }
286
287 // *** IOleCommandTarget methods ***
288 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[], OLECMDTEXT *pCmdText)
289 {
290 WrapLogEnter("CMenuSiteWrap<%p>::QueryStatus(const GUID *pguidCmdGroup=%p, ULONG cCmds=%u, prgCmds=%p, pCmdText=%p)\n", this, pguidCmdGroup, cCmds, prgCmds, pCmdText);
291 HRESULT hr = m_IOleCommandTarget->QueryStatus(pguidCmdGroup, cCmds, prgCmds, pCmdText);
292 if (pguidCmdGroup) WrapLogPost("*pguidCmdGroup=%s\n", Wrap(*pguidCmdGroup));
293 WrapLogExit("CMenuSiteWrap::QueryStatus()", hr);
294 return hr;
295 }
296
297 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)
298 {
299 WrapLogEnter("CMenuSiteWrap<%p>::Exec(const GUID *pguidCmdGroup=%p, DWORD nCmdID=%d, DWORD nCmdexecopt=%d, VARIANT *pvaIn=%p, VARIANT *pvaOut=%p)\n", this, pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
300 if (pguidCmdGroup) WrapLogPre("*pguidCmdGroup=%s\n", Wrap(*pguidCmdGroup));
301 HRESULT hr = m_IOleCommandTarget->Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut);
302 WrapLogExit("CMenuSiteWrap::Exec()", hr);
303 return hr;
304 }
305
306 // *** IInputObject methods ***
307 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::UIActivateIO(BOOL fActivate, LPMSG lpMsg)
308 {
309 WrapLogEnter("CMenuSiteWrap<%p>::UIActivateIO(BOOL fActivate=%d, LPMSG lpMsg=%p)\n", this, fActivate, lpMsg);
310 HRESULT hr = m_IInputObject->UIActivateIO(fActivate, lpMsg);
311 WrapLogExit("CMenuSiteWrap::UIActivateIO()", hr);
312 return hr;
313 }
314
315 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::HasFocusIO()
316 {
317 WrapLogEnter("CMenuSiteWrap<%p>::HasFocusIO()\n", this);
318 HRESULT hr = m_IInputObject->HasFocusIO();
319 WrapLogExit("CMenuSiteWrap::HasFocusIO()", hr);
320 return hr;
321 }
322
323 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::TranslateAcceleratorIO(LPMSG lpMsg)
324 {
325 WrapLogEnter("CMenuSiteWrap<%p>::TranslateAcceleratorIO(LPMSG lpMsg=%p)\n", this, lpMsg);
326 if (lpMsg) WrapLogPre("*lpMsg=%s\n", Wrap(*lpMsg));
327 HRESULT hr = m_IInputObject->TranslateAcceleratorIO(lpMsg);
328 WrapLogExit("CMenuSiteWrap::TranslateAcceleratorIO()", hr);
329 return hr;
330 }
331
332 // *** IInputObjectSite methods ***
333 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::OnFocusChangeIS(LPUNKNOWN lpUnknown, BOOL bFocus)
334 {
335 WrapLogEnter("CMenuSiteWrap<%p>::OnFocusChangeIS(LPUNKNOWN lpUnknown=%p, BOOL bFocus=%d)\n", this, lpUnknown, bFocus);
336 HRESULT hr = m_IInputObjectSite->OnFocusChangeIS(lpUnknown, bFocus);
337 WrapLogExit("CMenuSiteWrap::OnFocusChangeIS()", hr);
338 return hr;
339 }
340
341 // *** IWinEventHandler methods ***
342 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult)
343 {
344 //WrapLogEnter("CMenuSiteWrap<%p>::OnWinEvent(HWND hWnd=%p, UINT uMsg=%u, WPARAM wParam=%08x, LPARAM lParam=%08x, LRESULT *theResult=%p)\n", this, hWnd, uMsg, wParam, lParam, theResult);
345 HRESULT hr = m_IWinEventHandler->OnWinEvent(hWnd, uMsg, wParam, lParam, theResult);
346 //WrapLogExit("CMenuSiteWrap::OnWinEvent()", hr);
347 return hr;
348 }
349
350 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::IsWindowOwner(HWND hWnd)
351 {
352 //WrapLogEnter("CMenuSiteWrap<%p>::IsWindowOwner(HWND hWnd=%08x)\n", this, hWnd);
353 HRESULT hr = m_IWinEventHandler->IsWindowOwner(hWnd);
354 //WrapLogExit("CMenuSiteWrap::IsWindowOwner()", hr);
355 return hr;
356 }
357
358 // *** IServiceProvider methods ***
359 HRESULT STDMETHODCALLTYPE CMenuSiteWrap::QueryService(REFGUID guidService, REFIID riid, void **ppvObject)
360 {
361 WrapLogEnter("CMenuSiteWrap<%p>::QueryService(REFGUID guidService=%s, REFIID riid=%s, void **ppvObject=%p)\n", this, Wrap(guidService), Wrap(riid), ppvObject);
362 HRESULT hr = m_IServiceProvider->QueryService(guidService, riid, ppvObject);
363 if (ppvObject) WrapLogPost("*ppvObject=%p\n", *ppvObject);
364 WrapLogExit("CMenuSiteWrap::QueryService()", hr);
365 return hr;
366 }