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();
~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     STDMETHOD(AddBand)(IUnknown * punk) override;
63     STDMETHOD(EnumBands)(UINT uBand, DWORD* pdwBandID) override;
64     STDMETHOD(QueryBand)(DWORD dwBandID, IDeskBand **ppstb, DWORD *pdwState, LPWSTR pszName, int cchName) override;
65     STDMETHOD(GetBandObject)(DWORD dwBandID, REFIID riid, VOID **ppv) override;
66 
67     // IDeskBarClient
68     STDMETHOD(SetDeskBarSite)(IUnknown *punkSite) override;
69     STDMETHOD(GetSize)(DWORD dwWhich, LPRECT prc) override;
70     STDMETHOD(UIActivateDBC)(DWORD dwState) override;
71 
72     // IOleWindow
73     STDMETHOD(GetWindow)(HWND *phwnd) override;
74 
75     // IOleCommandTarget
76     STDMETHOD(QueryStatus)(const GUID * pguidCmdGroup, ULONG cCmds, OLECMD prgCmds [], OLECMDTEXT *pCmdText) override;
77     STDMETHOD(Exec)(const GUID * pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) override;
78 
79     // IInputObject
80     STDMETHOD(UIActivateIO)(BOOL fActivate, LPMSG lpMsg) override;
81     STDMETHOD(HasFocusIO)() override;
82     STDMETHOD(TranslateAcceleratorIO)(LPMSG lpMsg) override;
83 
84     // IInputObjectSite
85     STDMETHOD(OnFocusChangeIS)(IUnknown *punkObj, BOOL fSetFocus) override;
86 
87     // IWinEventHandler
88     STDMETHOD(IsWindowOwner)(HWND hWnd) override;
89     STDMETHOD(OnWinEvent)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult) override;
90 
91     // IServiceProvider
92     STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void **ppvObject) override;
93 
94     // Using custom message map instead
95     virtual BOOL ProcessWindowMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT &lResult, DWORD mapId = 0);
96 
97     // IDeskBarClient
98     STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode) override;
99     STDMETHOD(GetBandSiteInfo)(BANDSITEINFO *pbsinfo) override;
100     STDMETHOD(RemoveBand)(DWORD dwBandID) override;
101     STDMETHOD(SetBandSiteInfo)(const BANDSITEINFO *pbsinfo) override;
102     STDMETHOD(SetBandState)(DWORD dwBandID, DWORD dwMask, DWORD dwState) override;
103     STDMETHOD(SetModeDBC)(DWORD dwMode) override;
104 
105 private:
ToIUnknown()106     IUnknown * ToIUnknown() { return static_cast<IDeskBarClient*>(this); }
GetBandCount()107     UINT GetBandCount() { return m_BandObject ? 1 : 0; }
108 };
109