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 #pragma once
21 
22 class CMenuSite :
23     public CComCoClass<CMenuSite, &CLSID_MenuBandSite>,
24     public CComObjectRootEx<CComMultiThreadModelNoCS>,
25     public CWindowImpl<CMenuSite, CWindow, CControlWinTraits>,
26     public IBandSite,
27     public IDeskBarClient,
28     public IOleCommandTarget,
29     public IInputObject,
30     public IInputObjectSite,
31     public IWinEventHandler,
32     public IServiceProvider
33 {
34 private:
35     CComPtr<IUnknown>         m_DeskBarSite;
36     CComPtr<IUnknown>         m_BandObject;
37     CComPtr<IDeskBand>        m_DeskBand;
38     CComPtr<IWinEventHandler> m_WinEventHandler;
39     HWND                      m_hWndBand;
40 
41 public:
42     CMenuSite();
43     virtual ~CMenuSite() {}
44 
45     DECLARE_WND_CLASS_EX(_T("MenuSite"), 0, COLOR_MENU)
46 
47     DECLARE_REGISTRY_RESOURCEID(IDR_MENUBANDSITE)
48     DECLARE_NOT_AGGREGATABLE(CMenuSite)
49     DECLARE_PROTECT_FINAL_CONSTRUCT()
50     BEGIN_COM_MAP(CMenuSite)
51         COM_INTERFACE_ENTRY_IID(IID_IBandSite, IBandSite)
52         COM_INTERFACE_ENTRY_IID(IID_IDeskBarClient, IDeskBarClient)
53         COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleWindow)
54         COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
55         COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject)
56         COM_INTERFACE_ENTRY_IID(IID_IInputObjectSite, IInputObjectSite)
57         COM_INTERFACE_ENTRY_IID(IID_IWinEventHandler, IWinEventHandler)
58         COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
59     END_COM_MAP()
60 
61     // IBandSite
62     virtual HRESULT STDMETHODCALLTYPE AddBand(IUnknown * punk);
63     virtual HRESULT STDMETHODCALLTYPE EnumBands(UINT uBand, DWORD* pdwBandID);
64     virtual HRESULT STDMETHODCALLTYPE QueryBand(DWORD dwBandID, IDeskBand **ppstb, DWORD *pdwState, LPWSTR pszName, int cchName);
65     virtual HRESULT STDMETHODCALLTYPE GetBandObject(DWORD dwBandID, REFIID riid, VOID **ppv);
66 
67     // IDeskBarClient
68     virtual HRESULT STDMETHODCALLTYPE SetDeskBarSite(IUnknown *punkSite);
69     virtual HRESULT STDMETHODCALLTYPE GetSize(DWORD dwWhich, LPRECT prc);
70     virtual HRESULT STDMETHODCALLTYPE UIActivateDBC(DWORD dwState);
71 
72     // IOleWindow
73     virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *phwnd);
74 
75     // IOleCommandTarget
76     virtual HRESULT STDMETHODCALLTYPE QueryStatus(const GUID * pguidCmdGroup, ULONG cCmds, OLECMD prgCmds [], OLECMDTEXT *pCmdText);
77     virtual HRESULT STDMETHODCALLTYPE Exec(const GUID * pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut);
78 
79     // IInputObject
80     virtual HRESULT STDMETHODCALLTYPE UIActivateIO(BOOL fActivate, LPMSG lpMsg);
81     virtual HRESULT STDMETHODCALLTYPE HasFocusIO();
82     virtual HRESULT STDMETHODCALLTYPE TranslateAcceleratorIO(LPMSG lpMsg);
83 
84     // IInputObjectSite
85     virtual HRESULT STDMETHODCALLTYPE OnFocusChangeIS(IUnknown *punkObj, BOOL fSetFocus);
86 
87     // IWinEventHandler
88     virtual HRESULT STDMETHODCALLTYPE IsWindowOwner(HWND hWnd);
89     virtual HRESULT STDMETHODCALLTYPE OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult);
90 
91     // IServiceProvider
92     virtual HRESULT STDMETHODCALLTYPE QueryService(REFGUID guidService, REFIID riid, void **ppvObject);
93 
94 
95     // Using custom message map instead
96     virtual BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult, DWORD mapId = 0);
97 
98     // UNIMPLEMENTED
99     virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode);
100     virtual HRESULT STDMETHODCALLTYPE GetBandSiteInfo(BANDSITEINFO *pbsinfo);
101     virtual HRESULT STDMETHODCALLTYPE RemoveBand(DWORD dwBandID);
102     virtual HRESULT STDMETHODCALLTYPE SetBandSiteInfo(const BANDSITEINFO *pbsinfo);
103     virtual HRESULT STDMETHODCALLTYPE SetBandState(DWORD dwBandID, DWORD dwMask, DWORD dwState);
104     virtual HRESULT STDMETHODCALLTYPE SetModeDBC(DWORD dwMode);
105 
106 private:
107     IUnknown * ToIUnknown() { return static_cast<IDeskBarClient*>(this); }
108 };
109