1 /*
2 * Shell Menu Band
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 CMenuToolbarBase;
23 class CMenuStaticToolbar;
24 class CMenuSFToolbar;
25 class CMenuFocusManager;
26 
27 class CMenuBand :
28     public CComCoClass<CMenuBand, &CLSID_MenuBand>,
29     public CComObjectRootEx<CComMultiThreadModelNoCS>,
30     public IDeskBand,
31     public IObjectWithSite,
32     public IInputObject,
33     public IPersistStream,
34     public IOleCommandTarget,
35     public IServiceProvider,
36     public IMenuPopup,
37     public IMenuBand,
38     public IShellMenu2,
39     public IWinEventHandler,
40     public IShellMenuAcc
41 {
42 private:
43     CMenuFocusManager  * m_focusManager;
44     CMenuStaticToolbar * m_staticToolbar;
45     CMenuSFToolbar     * m_SFToolbar;
46 
47     CComPtr<IOleWindow>         m_site;
48     CComPtr<IShellMenuCallback> m_psmc;
49     CComPtr<IMenuPopup>         m_subMenuChild;
50     CComPtr<IMenuPopup>         m_subMenuParent;
51     CComPtr<CMenuBand>          m_childBand;
52     CComPtr<CMenuBand>          m_parentBand;
53 
54     UINT  m_uId;
55     UINT  m_uIdAncestor;
56     DWORD m_dwFlags;
57     PVOID m_UserData;
58     HMENU m_hmenu;
59     HWND  m_menuOwner;
60 
61     BOOL m_useBigIcons;
62     HWND m_topLevelWindow;
63 
64     CMenuToolbarBase * m_hotBar;
65     INT                m_hotItem;
66     CMenuToolbarBase * m_popupBar;
67     INT                m_popupItem;
68 
69     BOOL m_Show;
70     BOOL m_shellBottom;
71 
72     HMENU m_trackedPopup;
73     HWND m_trackedHwnd;
74 
75 public:
76     CMenuBand();
77     virtual ~CMenuBand();
78 
79     DECLARE_REGISTRY_RESOURCEID(IDR_MENUBAND)
80     DECLARE_NOT_AGGREGATABLE(CMenuBand)
81     DECLARE_PROTECT_FINAL_CONSTRUCT()
82 
83     BEGIN_COM_MAP(CMenuBand)
84         COM_INTERFACE_ENTRY_IID(IID_IDeskBar, IMenuPopup)
85         COM_INTERFACE_ENTRY_IID(IID_IShellMenu, IShellMenu)
86         COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
87         COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IDeskBand)
88         COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDockingWindow)
89         COM_INTERFACE_ENTRY_IID(IID_IDeskBand, IDeskBand)
90         COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite)
91         COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject)
92         COM_INTERFACE_ENTRY_IID(IID_IPersistStream, IPersistStream)
93         COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersistStream)
94         COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
95         COM_INTERFACE_ENTRY_IID(IID_IMenuPopup, IMenuPopup)
96         COM_INTERFACE_ENTRY_IID(IID_IMenuBand, IMenuBand)
97         COM_INTERFACE_ENTRY_IID(IID_IShellMenu2, IShellMenu2)
98         COM_INTERFACE_ENTRY_IID(IID_IWinEventHandler, IWinEventHandler)
99         COM_INTERFACE_ENTRY_IID(IID_IShellMenuAcc, IShellMenuAcc)
100     END_COM_MAP()
101 
102     // *** IDeskBand methods ***
103     STDMETHOD(GetBandInfo)(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO *pdbi) override;
104 
105     // *** IDockingWindow methods ***
106     STDMETHOD(ShowDW)(BOOL fShow) override;
107     STDMETHOD(CloseDW)(DWORD dwReserved) override;
108     STDMETHOD(ResizeBorderDW)(LPCRECT prcBorder, IUnknown *punkToolbarSite, BOOL fReserved) override;
109 
110     // *** IOleWindow methods ***
111     STDMETHOD(GetWindow)(HWND *phwnd) override;
112     STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode) override;
113 
114     // *** IObjectWithSite methods ***
115     STDMETHOD(SetSite)(IUnknown *pUnkSite) override;
116     STDMETHOD(GetSite)(REFIID riid, PVOID *ppvSite) override;
117 
118     // *** IInputObject methods ***
119     STDMETHOD(UIActivateIO)(BOOL fActivate, LPMSG lpMsg) override;
120     STDMETHOD(HasFocusIO)() override;
121     STDMETHOD(TranslateAcceleratorIO)(LPMSG lpMsg) override;
122 
123     // *** IPersistStream methods ***
124     STDMETHOD(IsDirty)() override;
125     STDMETHOD(Load)(IStream *pStm) override;
126     STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty) override;
127     STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) override;
128 
129     // *** IPersist methods ***
130     STDMETHOD(GetClassID)(CLSID *pClassID) override;
131 
132     // *** IOleCommandTarget methods ***
133     STDMETHOD(QueryStatus)(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds [], OLECMDTEXT *pCmdText) override;
134     STDMETHOD(Exec)(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) override;
135 
136     // *** IServiceProvider methods ***
137     STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void **ppvObject) override;
138 
139     // *** IMenuPopup methods ***
140     STDMETHOD(Popup)(POINTL *ppt, RECTL *prcExclude, MP_POPUPFLAGS dwFlags) override;
141     STDMETHOD(OnSelect)(DWORD dwSelectType) override;
142     STDMETHOD(SetSubMenu)(IMenuPopup *pmp, BOOL fSet) override;
143 
144     // *** IDeskBar methods ***
145     STDMETHOD(SetClient)(IUnknown *punkClient) override;
146     STDMETHOD(GetClient)(IUnknown **ppunkClient) override;
147     STDMETHOD(OnPosRectChangeDB)(RECT *prc) override;
148 
149     // *** IMenuBand methods ***
150     STDMETHOD(IsMenuMessage)(MSG *pmsg) override;
151     STDMETHOD(TranslateMenuMessage)(MSG *pmsg, LRESULT *plRet) override;
152 
153     // *** IShellMenu methods ***
154     STDMETHOD(Initialize)(IShellMenuCallback *psmc, UINT uId, UINT uIdAncestor, DWORD dwFlags) override;
155     STDMETHOD(GetMenuInfo)(IShellMenuCallback **ppsmc, UINT *puId, UINT *puIdAncestor, DWORD *pdwFlags) override;
156     STDMETHOD(SetShellFolder)(IShellFolder *psf, LPCITEMIDLIST pidlFolder, HKEY hKey, DWORD dwFlags) override;
157     STDMETHOD(GetShellFolder)(DWORD *pdwFlags, LPITEMIDLIST *ppidl, REFIID riid, void **ppv) override;
158     STDMETHOD(SetMenu)(HMENU hmenu, HWND hwnd, DWORD dwFlags) override;
159     STDMETHOD(GetMenu)(HMENU *phmenu, HWND *phwnd, DWORD *pdwFlags) override;
160     STDMETHOD(InvalidateItem)(LPSMDATA psmd, DWORD dwFlags) override;
161     STDMETHOD(GetState)(LPSMDATA psmd) override;
162     STDMETHOD(SetMenuToolbar)(IUnknown *punk, DWORD dwFlags) override;
163 
164     // *** IWinEventHandler methods ***
165     STDMETHOD(OnWinEvent)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult) override;
166     STDMETHOD(IsWindowOwner)(HWND hWnd) override;
167 
168     // *** IShellMenu2 methods ***
169     STDMETHOD(GetSubMenu)(THIS) override;
170     STDMETHOD(SetToolbar)(THIS) override;
171     STDMETHOD(SetMinWidth)(THIS) override;
172     STDMETHOD(SetNoBorder)(THIS) override;
173     STDMETHOD(SetTheme)(THIS) override;
174 
175     // *** IShellMenuAcc methods ***
176     STDMETHOD(GetTop)(THIS) override;
177     STDMETHOD(GetBottom)(THIS) override;
178     STDMETHOD(GetTracked)(THIS) override;
179     STDMETHOD(GetParentSite)(THIS) override;
180     STDMETHOD(GetState)(THIS) override;
181     STDMETHOD(DoDefaultAction)(THIS) override;
182     STDMETHOD(IsEmpty)(THIS) override;
183 
184     HRESULT _CallCBWithItemId(UINT Id, UINT uMsg, WPARAM wParam, LPARAM lParam);
185     HRESULT _CallCBWithItemPidl(LPITEMIDLIST pidl, UINT uMsg, WPARAM wParam, LPARAM lParam);
186     HRESULT _TrackSubMenu(HMENU popup, INT x, INT y, RECT& rcExclude);
187     HRESULT _TrackContextMenu(IContextMenu * popup, INT x, INT y);
188     HRESULT _GetTopLevelWindow(HWND*topLevel);
189     HRESULT _ChangeHotItem(CMenuToolbarBase * tb, INT id, DWORD dwFlags);
190     HRESULT _ChangePopupItem(CMenuToolbarBase * tb, INT id);
191     HRESULT _MenuItemSelect(DWORD changeType);
192     HRESULT _CancelCurrentPopup();
193     HRESULT _OnPopupSubMenu(IShellMenu * childShellMenu, POINTL * pAt, RECTL * pExclude, BOOL mouseInitiated);
194     HRESULT _BeforeCancelPopup();
195     HRESULT _DisableMouseTrack(BOOL bDisable);
196     HRESULT _SetChildBand(CMenuBand * child);
197     HRESULT _SetParentBand(CMenuBand * parent);
198     HRESULT _IsPopup();
199     HRESULT _IsTracking();
200     HRESULT _KillPopupTimers();
201     HRESULT _MenuBarMouseDown(HWND hwnd, INT item, BOOL isLButton);
202     HRESULT _MenuBarMouseUp(HWND hwnd, INT item, BOOL isLButton);
203     HRESULT _HasSubMenu();
204 
205     HRESULT AdjustForTheme(BOOL bFlatStyle);
206 
UseBigIcons()207     BOOL UseBigIcons()
208     {
209         return m_useBigIcons;
210     }
211 
212 private:
213     HRESULT _KeyboardItemChange(DWORD change);
214     HRESULT _CallCB(UINT uMsg, WPARAM wParam, LPARAM lParam, UINT id = 0, LPITEMIDLIST pidl = NULL);
215 };
216