1 /*
2  * ReactOS Explorer
3  *
4  * Copyright 2009 Andrew Hill <ash77 at domain reactos.org>
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 
21 #pragma once
22 
23 static const int gSearchCommandID = 1003;
24 static const int gFoldersCommandID = 1004;
25 static const int gMoveToCommandID = FCIDM_SHVIEW_MOVETO;
26 static const int gCopyToCommandID = FCIDM_SHVIEW_COPYTO;
27 static const int gDeleteCommandID = FCIDM_SHVIEW_DELETE;
28 static const int gUndoCommandID = FCIDM_SHVIEW_UNDO;
29 static const int gViewsCommandID = FCIDM_SHVIEW_AUTOARRANGE;
30 static const int gStopCommandID = 1010;
31 static const int gHomeCommandID = 1012;
32 static const int gFavoritesCommandID = 1015;
33 static const int gHistoryCommandID = 1016;
34 static const int gFullScreenCommandID = 1017;
35 static const int gPropertiesCommandID = FCIDM_SHVIEW_PROPERTIES;
36 static const int gCutCommandID = FCIDM_SHVIEW_CUT;
37 static const int gCopyCommandID = FCIDM_SHVIEW_COPY;
38 static const int gPasteCommandID = FCIDM_SHVIEW_INSERT;
39 
40 class CMenuCallback :
41     public CComObjectRootEx<CComMultiThreadModelNoCS>,
42     public IShellMenuCallback
43 {
44 private:
45     CComPtr<IShellMenu>             fFavoritesMenu;
46 public:
47     CMenuCallback();
48     virtual ~CMenuCallback();
49 
50     HRESULT STDMETHODCALLTYPE GetObject(LPSMDATA psmd, REFIID riid, void **ppvObject);
51 public:
52     // *** IShellMenuCallback methods ***
53     virtual HRESULT STDMETHODCALLTYPE CallbackSM(LPSMDATA psmd, UINT uMsg, WPARAM wParam, LPARAM lParam);
54 
55 BEGIN_COM_MAP(CMenuCallback)
56     COM_INTERFACE_ENTRY_IID(IID_IShellMenuCallback, IShellMenuCallback)
57 END_COM_MAP()
58 };
59 
60 class CInternetToolbar :
61     public CWindowImpl<CInternetToolbar, CWindow, CControlWinTraits>,
62     public CComCoClass<CInternetToolbar, &CLSID_InternetToolbar>,
63     public CComObjectRootEx<CComMultiThreadModelNoCS>,
64     public IInputObject,
65     public IDockingWindow,
66     public IPersistStreamInit,
67     public IOleCommandTarget,
68     public IDispatch,
69     public IExplorerToolbar,
70     public IShellChangeNotify,
71     public IObjectWithSite,
72     public IServiceProvider,
73     public IWinEventHandler,
74     public IBandSite
75 {
76 public:
77     CComPtr<IUnknown>                       fSite;              // our site
78     HWND                                    fMainReBar;         // rebar for top of window
79     bool                                    fLocked;            // is bar locked to prevent changes?
80     CComPtr<IShellMenu>                     fMenuBar;           // the menu rebar
81     HWND                                    fMenuBandWindow;
82     HWND                                    fNavigationWindow;
83     CComPtr<IUnknown>                       fLogoBar;           // the reactos logo
84     CComPtr<IUnknown>                       fControlsBar;       // navigation controls
85     CComPtr<IUnknown>                       fNavigationBar;     // address bar
86     CComPtr<CMenuCallback>                  fMenuCallback;
87     CComPtr<IOleCommandTarget>              fCommandTarget;
88     GUID                                    fCommandCategory;
89     HWND                                    fToolbarWindow;
90     DWORD                                   fAdviseCookie;
91     CComPtr<IBandProxy>                     fBandProxy;
92     BOOL                                    fSizing;
93     POINT                                   fStartPosition;
94     LONG                                    fStartHeight;
95     ShellSettings                           *pSettings;
96 public:
97     CInternetToolbar();
98     virtual ~CInternetToolbar();
99     void AddDockItem(IUnknown *newItem, int bandID, int flags);
100     HRESULT ReserveBorderSpace(LONG maxHeight = -1);
101     HRESULT CreateMenuBar(IShellMenu **menuBar);
102     HRESULT CreateToolsBar(IUnknown **toolsBar);
103     HRESULT LockUnlockToolbars(bool locked);
104     HRESULT CommandStateChanged(bool newValue, int commandID);
105     HRESULT CreateAndInitBandProxy();
106     HRESULT IsBandVisible(int BandID);
107     HRESULT ToggleBandVisibility(int BandID);
108     HRESULT SetState(const GUID *pguidCmdGroup, long commandID, OLECMD* pcmd);
109     void RefreshLockedToolbarState();
110 
111 public:
112     // *** IInputObject specific methods ***
113     STDMETHOD(UIActivateIO)(BOOL fActivate, LPMSG lpMsg) override;
114     STDMETHOD(HasFocusIO)() override;
115     STDMETHOD(TranslateAcceleratorIO)(LPMSG lpMsg) override;
116 
117     // *** IOleWindow methods ***
118     STDMETHOD(GetWindow)(HWND *lphwnd) override;
119     STDMETHOD(ContextSensitiveHelp)(BOOL fEnterMode) override;
120 
121     // *** IDockingWindow methods ***
122     STDMETHOD(ShowDW)(BOOL fShow) override;
123     STDMETHOD(CloseDW)(DWORD dwReserved) override;
124     STDMETHOD(ResizeBorderDW)(LPCRECT prcBorder, IUnknown *punkToolbarSite, BOOL fReserved) override;
125 
126     // *** IPersist methods ***
127     STDMETHOD(GetClassID)(CLSID *pClassID) override;
128 
129     // *** IPersistStreamInit methods ***
130     STDMETHOD(IsDirty)() override;
131     STDMETHOD(Load)(IStream *pStm) override;
132     STDMETHOD(Save)(IStream *pStm, BOOL fClearDirty) override;
133     STDMETHOD(GetSizeMax)(ULARGE_INTEGER *pcbSize) override;
134     STDMETHOD(InitNew)() override;
135 
136     // *** IOleCommandTarget methods ***
137     STDMETHOD(QueryStatus)(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[  ], OLECMDTEXT *pCmdText) override;
138     STDMETHOD(Exec)(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) override;
139 
140     // *** IDispatch methods ***
141     STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) override;
142     STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) override;
143     STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) override;
144     STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) override;
145 
146     // *** IExplorerToolbar methods ***
147     STDMETHOD(SetCommandTarget)(IUnknown *theTarget, GUID *category, long param14) override;
148     STDMETHOD(Unknown1)() override;
149     STDMETHOD(AddButtons)(const GUID *pguidCmdGroup, long buttonCount, TBBUTTON *buttons) override;
150     STDMETHOD(AddString)(const GUID *pguidCmdGroup, HINSTANCE param10, LPCTSTR param14, long *param18) override;
151     STDMETHOD(GetButton)(const GUID *pguidCmdGroup, long param10, long param14) override;
152     STDMETHOD(GetState)(const GUID *pguidCmdGroup, long commandID, long *theState) override;
153     STDMETHOD(SetState)(const GUID *pguidCmdGroup, long commandID, long theState) override;
154     STDMETHOD(AddBitmap)(const GUID *pguidCmdGroup, long param10, long buttonCount, TBADDBITMAP *lParam, long *newIndex, COLORREF param20) override;
155     STDMETHOD(GetBitmapSize)(long *paramC) override;
156     STDMETHOD(SendToolbarMsg)(const GUID *pguidCmdGroup, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *result) override;
157     STDMETHOD(SetImageList)(const GUID *pguidCmdGroup, HIMAGELIST param10, HIMAGELIST param14, HIMAGELIST param18) override;
158     STDMETHOD(ModifyButton)(const GUID *pguidCmdGroup, long param10, long param14) override;
159 
160     // *** IShellChangeNotify methods ***
161     STDMETHOD(OnChange)(LONG lEvent, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) override;
162 
163     // *** IObjectWithSite methods ***
164     STDMETHOD(SetSite)(IUnknown *pUnkSite) override;
165     STDMETHOD(GetSite)(REFIID riid, void **ppvSite) override;
166 
167     // *** IServiceProvider methods ***
168     STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void **ppvObject) override;
169 
170     // *** IWinEventHandler methods ***
171     STDMETHOD(OnWinEvent)(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult) override;
172     STDMETHOD(IsWindowOwner)(HWND hWnd) override;
173 
174     // *** IBandSite specific methods ***
175     STDMETHOD(AddBand)(IUnknown *punk) override;
176     STDMETHOD(EnumBands)(UINT uBand, DWORD *pdwBandID) override;
177     STDMETHOD(QueryBand)(DWORD dwBandID, IDeskBand **ppstb, DWORD *pdwState, LPWSTR pszName, int cchName) override;
178     STDMETHOD(SetBandState)(DWORD dwBandID, DWORD dwMask, DWORD dwState) override;
179     STDMETHOD(RemoveBand)(DWORD dwBandID) override;
180     STDMETHOD(GetBandObject)(DWORD dwBandID, REFIID riid, void **ppv) override;
181     STDMETHOD(SetBandSiteInfo)(const BANDSITEINFO *pbsinfo) override;
182     STDMETHOD(GetBandSiteInfo)(BANDSITEINFO *pbsinfo) override;
183 
184     // message handlers
185     LRESULT OnTravelBack(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
186     LRESULT OnTravelForward(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
187     LRESULT OnUpLevel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
188     LRESULT OnSearch(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
189     LRESULT OnFolders(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
190     LRESULT OnForwardToCommandTarget(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
191     LRESULT OnMenuDropDown(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled);
192     LRESULT OnQueryInsert(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled);
193     LRESULT OnQueryDelete(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled);
194     LRESULT OnNavigateCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
195     LRESULT OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
196     LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
197     LRESULT OnSetCursor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
198     LRESULT OnTipText(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled);
199     LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
200     LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
201     LRESULT OnLDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
202     LRESULT OnLUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
203     LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
204     LRESULT OnWinIniChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
205     LRESULT OnSettingsChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
206 
207     BEGIN_MSG_MAP(CInternetToolbar)
208         COMMAND_ID_HANDLER(IDM_GOTO_BACK, OnTravelBack)
209         COMMAND_ID_HANDLER(IDM_GOTO_FORWARD, OnTravelForward)
210         COMMAND_ID_HANDLER(IDM_GOTO_UPONELEVEL, OnUpLevel)
211         COMMAND_ID_HANDLER(gSearchCommandID, OnSearch)
212         COMMAND_ID_HANDLER(gFoldersCommandID, OnFolders)
213         COMMAND_RANGE_HANDLER(0x7000, 0x7fff, OnForwardToCommandTarget)
214         NOTIFY_HANDLER(0, TBN_DROPDOWN, OnMenuDropDown)
215         NOTIFY_HANDLER(0, TBN_QUERYINSERT, OnQueryInsert)
216         NOTIFY_HANDLER(0, TBN_QUERYDELETE, OnQueryDelete)
217         MESSAGE_HANDLER(WM_COMMAND, OnCommand)
218         MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
219         MESSAGE_HANDLER(WM_SIZE, OnSize)
220         MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
221         NOTIFY_CODE_HANDLER(TTN_NEEDTEXTW, OnTipText)
222         MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
223         MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLDown)
224         MESSAGE_HANDLER(WM_LBUTTONUP, OnLUp)
225         MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
226         MESSAGE_HANDLER(WM_WININICHANGE, OnWinIniChange)
227         MESSAGE_HANDLER(BWM_SETTINGCHANGE, OnSettingsChange)
228     END_MSG_MAP()
229 
230     DECLARE_REGISTRY_RESOURCEID(IDR_INTERNETTOOLBAR)
231     DECLARE_NOT_AGGREGATABLE(CInternetToolbar)
232 
233     DECLARE_PROTECT_FINAL_CONSTRUCT()
234 
235     BEGIN_COM_MAP(CInternetToolbar)
236         COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject)
237         COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleWindow)
238         COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDockingWindow)
239         COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist)
240 //        COM_INTERFACE_ENTRY_IID(IID_IPersistStream, IPersistStream)
241         COM_INTERFACE_ENTRY_IID(IID_IPersistStreamInit, IPersistStreamInit)
242         COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
243         COM_INTERFACE_ENTRY_IID(IID_IDispatch, IDispatch)
244         COM_INTERFACE_ENTRY_IID(IID_IExplorerToolbar, IExplorerToolbar)
245         COM_INTERFACE_ENTRY_IID(IID_IShellChangeNotify, IShellChangeNotify)
246         COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite)
247         COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
248         COM_INTERFACE_ENTRY_IID(IID_IWinEventHandler, IWinEventHandler)
249         COM_INTERFACE_ENTRY_IID(IID_IBandSite, IBandSite)
250     END_COM_MAP()
251 };
252