1 /*
2  *  Rebar band site
3  *
4  *  Copyright 2007  Herv� Poussineau
5  *  Copyright 2009  Andrew Hill
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 
22 #pragma once
23 
24 extern inline BOOL _ILIsDesktop(LPCITEMIDLIST pidl)
25 {
26     return (pidl == NULL || pidl->mkid.cb == 0);
27 }
28 
29 class CBandSiteBase :
30     public CComObjectRootEx<CComMultiThreadModelNoCS>,
31     public IBandSite,
32     public IInputObjectSite,
33     public IInputObject,
34     public IDeskBarClient,
35     public IWinEventHandler,
36     public IPersistStream,
37     public IDropTarget,
38     public IServiceProvider,
39     public IBandSiteHelper,
40     public IOleCommandTarget
41 {
42 private:
43     struct BandObject
44     {
45         IDeskBand                           *DeskBand;
46         IOleWindow                          *OleWindow;
47         IWinEventHandler                    *WndEvtHandler;
48         DESKBANDINFO                        dbi;
49         BOOL                                bHiddenTitle;
50     };
51 
52     LONG                                    m_cBands;
53     LONG                                    m_cBandsAllocated;
54     struct BandObject                       *m_bands;
55     HWND                                    m_hwndRebar;
56     CComPtr<IOleWindow>                     m_site;
57     DWORD                                   m_dwState; /* BSSF_ flags */
58     DWORD                                   m_dwStyle; /* BSIS_ flags */
59 public:
60     CBandSiteBase();
61     ~CBandSiteBase();
62 
63     // *** IBandSite methods ***
64     STDMETHOD(AddBand)(IUnknown *punk) override;
65     STDMETHOD(EnumBands)(UINT uBand, DWORD *pdwBandID) override;
66     STDMETHOD(QueryBand)(DWORD dwBandID, IDeskBand **ppstb, DWORD *pdwState, LPWSTR pszName, int cchName) override;
67     STDMETHOD(SetBandState)(DWORD dwBandID, DWORD dwMask, DWORD dwState) override;
68     STDMETHOD(RemoveBand)(DWORD dwBandID) override;
69     STDMETHOD(GetBandObject)(DWORD dwBandID, REFIID riid, void **ppv) override;
70     STDMETHOD(SetBandSiteInfo)(const BANDSITEINFO *pbsinfo) override;
71     STDMETHOD(GetBandSiteInfo)(BANDSITEINFO *pbsinfo) override;
72 
73     // *** IWinEventHandler methods ***
74     STDMETHOD(OnWinEvent)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult) override;
75     STDMETHOD(IsWindowOwner)(HWND hWnd) override;
76 
77     // *** IOleWindow methods ***
78     STDMETHOD(GetWindow)(HWND *lphwnd) override;
79     STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode) override;
80 
81     // *** IDeskBarClient methods ***
82     STDMETHOD(SetDeskBarSite)(IUnknown *punkSite) override;
83     STDMETHOD(SetModeDBC)(DWORD dwMode) override;
84     STDMETHOD(UIActivateDBC)(DWORD dwState) override;
85     STDMETHOD(GetSize)(DWORD dwWhich, LPRECT prc) override;
86 
87     // *** IOleCommandTarget methods ***
88     STDMETHOD(QueryStatus)(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[  ], OLECMDTEXT *pCmdText) override;
89     STDMETHOD(Exec)(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) override;
90 
91     // *** IInputObject methods ***
92     STDMETHOD(UIActivateIO)(BOOL fActivate, LPMSG lpMsg) override;
93     STDMETHOD(HasFocusIO)() override;
94     STDMETHOD(TranslateAcceleratorIO)(LPMSG lpMsg) override;
95 
96     // *** IInputObjectSite methods ***
97     STDMETHOD(OnFocusChangeIS)(struct IUnknown *paramC, int param10) override;
98 
99     // *** IServiceProvider methods ***
100     STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void **ppvObject) override;
101 
102     // *** IPersist methods ***
103     STDMETHOD(GetClassID)(CLSID *pClassID) override;
104 
105     // *** IPersistStream methods ***
106     STDMETHOD(IsDirty)() override;
107     STDMETHOD(Load)(IStream *pStm) override;
108     STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty) override;
109     STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) override;
110 
111     // *** IDropTarget methods ***
112     STDMETHOD(DragEnter)(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) override;
113     STDMETHOD(DragOver)(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) override;
114     STDMETHOD(DragLeave)() override;
115     STDMETHOD(Drop)(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect) override;
116 
117     // *** IBandSiteHelper methods ***
118     STDMETHOD(LoadFromStreamBS)(IStream *, const GUID &, void **) override;
119     STDMETHOD(SaveToStreamBS)(IUnknown *, IStream *) override;
120 
121 private:
122     UINT _GetBandID(struct BandObject *Band);
123     struct BandObject *_GetBandByID(DWORD dwBandID);
124     void _FreeBand(struct BandObject *Band);
125     DWORD _GetViewMode();
126     VOID _BuildBandInfo(struct BandObject *Band, REBARBANDINFOW *prbi);
127     HRESULT _UpdateBand(struct BandObject *Band);
128     HRESULT _UpdateAllBands();
129     HRESULT _UpdateBand(DWORD dwBandID);
130     struct BandObject *_GetBandFromHwnd(HWND hwnd);
131     HRESULT _IsBandDeletable(DWORD dwBandID);
132     HRESULT _OnContextMenu(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *plrResult);
133 
134     BEGIN_COM_MAP(CBandSiteBase)
135         COM_INTERFACE_ENTRY_IID(IID_IBandSite, IBandSite)
136         COM_INTERFACE_ENTRY_IID(IID_IWinEventHandler, IWinEventHandler)
137         COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleWindow)
138         COM_INTERFACE_ENTRY_IID(IID_IDeskBarClient, IDeskBarClient)
139         COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
140         COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject)
141         COM_INTERFACE_ENTRY_IID(IID_IInputObjectSite, IInputObjectSite)
142         COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
143         COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist)
144         COM_INTERFACE_ENTRY_IID(IID_IPersistStream, IPersistStream)
145         COM_INTERFACE_ENTRY_IID(IID_IDropTarget, IDropTarget)
146         COM_INTERFACE_ENTRY_IID(IID_IBandSiteHelper, IBandSiteHelper)
147     END_COM_MAP()
148 };
149 
150 class CBandSite :
151     public CComCoClass<CBandSite, &CLSID_RebarBandSite>,
152     public CBandSiteBase
153 {
154 public:
155 
156     DECLARE_REGISTRY_RESOURCEID(IDR_BANDSITE)
157     DECLARE_AGGREGATABLE(CBandSite)
158 
159     DECLARE_PROTECT_FINAL_CONSTRUCT()
160 };
161