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 public:
96     CInternetToolbar();
97     virtual ~CInternetToolbar();
98     void AddDockItem(IUnknown *newItem, int bandID, int flags);
99     HRESULT ReserveBorderSpace(LONG maxHeight = -1);
100     HRESULT CreateMenuBar(IShellMenu **menuBar);
101     HRESULT CreateToolsBar(IUnknown **toolsBar);
102     HRESULT LockUnlockToolbars(bool locked);
103     HRESULT CommandStateChanged(bool newValue, int commandID);
104     HRESULT CreateAndInitBandProxy();
105     HRESULT IsBandVisible(int BandID);
106     HRESULT ToggleBandVisibility(int BandID);
107     HRESULT SetState(const GUID *pguidCmdGroup, long commandID, OLECMD* pcmd);
108 
109 public:
110     // *** IInputObject specific methods ***
111     virtual HRESULT STDMETHODCALLTYPE UIActivateIO(BOOL fActivate, LPMSG lpMsg);
112     virtual HRESULT STDMETHODCALLTYPE HasFocusIO();
113     virtual HRESULT STDMETHODCALLTYPE TranslateAcceleratorIO(LPMSG lpMsg);
114 
115     // *** IOleWindow methods ***
116     virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *lphwnd);
117     virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode);
118 
119     // *** IDockingWindow methods ***
120     virtual HRESULT STDMETHODCALLTYPE ShowDW(BOOL fShow);
121     virtual HRESULT STDMETHODCALLTYPE CloseDW(DWORD dwReserved);
122     virtual HRESULT STDMETHODCALLTYPE ResizeBorderDW(LPCRECT prcBorder, IUnknown *punkToolbarSite, BOOL fReserved);
123 
124     // *** IPersist methods ***
125     virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID);
126 
127     // *** IPersistStreamInit methods ***
128     virtual HRESULT STDMETHODCALLTYPE IsDirty();
129     virtual HRESULT STDMETHODCALLTYPE Load(IStream *pStm);
130     virtual HRESULT STDMETHODCALLTYPE Save(IStream *pStm, BOOL fClearDirty);
131     virtual HRESULT STDMETHODCALLTYPE GetSizeMax(ULARGE_INTEGER *pcbSize);
132     virtual HRESULT STDMETHODCALLTYPE InitNew();
133 
134     // *** IOleCommandTarget methods ***
135     virtual HRESULT STDMETHODCALLTYPE QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[  ], OLECMDTEXT *pCmdText);
136     virtual HRESULT STDMETHODCALLTYPE Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut);
137 
138     // *** IDispatch methods ***
139     virtual HRESULT STDMETHODCALLTYPE GetTypeInfoCount(UINT *pctinfo);
140     virtual HRESULT STDMETHODCALLTYPE GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo);
141     virtual HRESULT STDMETHODCALLTYPE GetIDsOfNames(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId);
142     virtual HRESULT STDMETHODCALLTYPE Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
143 
144     // *** IExplorerToolbar methods ***
145     virtual HRESULT STDMETHODCALLTYPE SetCommandTarget(IUnknown *theTarget, GUID *category, long param14);
146     virtual HRESULT STDMETHODCALLTYPE Unknown1();
147     virtual HRESULT STDMETHODCALLTYPE AddButtons(const GUID *pguidCmdGroup, long buttonCount, TBBUTTON *buttons);
148     virtual HRESULT STDMETHODCALLTYPE AddString(const GUID *pguidCmdGroup, HINSTANCE param10, LPCTSTR param14, long *param18);
149     virtual HRESULT STDMETHODCALLTYPE GetButton(const GUID *pguidCmdGroup, long param10, long param14);
150     virtual HRESULT STDMETHODCALLTYPE GetState(const GUID *pguidCmdGroup, long commandID, long *theState);
151     virtual HRESULT STDMETHODCALLTYPE SetState(const GUID *pguidCmdGroup, long commandID, long theState);
152     virtual HRESULT STDMETHODCALLTYPE AddBitmap(const GUID *pguidCmdGroup, long param10, long buttonCount, TBADDBITMAP *lParam, long *newIndex, COLORREF param20);
153     virtual HRESULT STDMETHODCALLTYPE GetBitmapSize(long *paramC);
154     virtual HRESULT STDMETHODCALLTYPE SendToolbarMsg(const GUID *pguidCmdGroup, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *result);
155     virtual HRESULT STDMETHODCALLTYPE SetImageList(const GUID *pguidCmdGroup, HIMAGELIST param10, HIMAGELIST param14, HIMAGELIST param18);
156     virtual HRESULT STDMETHODCALLTYPE ModifyButton(const GUID *pguidCmdGroup, long param10, long param14);
157 
158     // *** IShellChangeNotify methods ***
159     virtual HRESULT STDMETHODCALLTYPE OnChange(LONG lEvent, LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2);
160 
161     // *** IObjectWithSite methods ***
162     virtual HRESULT STDMETHODCALLTYPE SetSite(IUnknown *pUnkSite);
163     virtual HRESULT STDMETHODCALLTYPE GetSite(REFIID riid, void **ppvSite);
164 
165     // *** IServiceProvider methods ***
166     virtual HRESULT STDMETHODCALLTYPE QueryService(REFGUID guidService, REFIID riid, void **ppvObject);
167 
168     // *** IWinEventHandler methods ***
169     virtual HRESULT STDMETHODCALLTYPE OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult);
170     virtual HRESULT STDMETHODCALLTYPE IsWindowOwner(HWND hWnd);
171 
172     // *** IBandSite specific methods ***
173     virtual HRESULT STDMETHODCALLTYPE AddBand(IUnknown *punk);
174     virtual HRESULT STDMETHODCALLTYPE EnumBands(UINT uBand, DWORD *pdwBandID);
175     virtual HRESULT STDMETHODCALLTYPE QueryBand(DWORD dwBandID, IDeskBand **ppstb, DWORD *pdwState, LPWSTR pszName, int cchName);
176     virtual HRESULT STDMETHODCALLTYPE SetBandState(DWORD dwBandID, DWORD dwMask, DWORD dwState);
177     virtual HRESULT STDMETHODCALLTYPE RemoveBand(DWORD dwBandID);
178     virtual HRESULT STDMETHODCALLTYPE GetBandObject(DWORD dwBandID, REFIID riid, void **ppv);
179     virtual HRESULT STDMETHODCALLTYPE SetBandSiteInfo(const BANDSITEINFO *pbsinfo);
180     virtual HRESULT STDMETHODCALLTYPE GetBandSiteInfo(BANDSITEINFO *pbsinfo);
181 
182     // message handlers
183     LRESULT OnTravelBack(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
184     LRESULT OnTravelForward(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
185     LRESULT OnUpLevel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
186     LRESULT OnSearch(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
187     LRESULT OnFolders(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
188     LRESULT OnForwardToCommandTarget(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL &bHandled);
189     LRESULT OnMenuDropDown(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled);
190     LRESULT OnQueryInsert(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled);
191     LRESULT OnQueryDelete(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled);
192     LRESULT OnNavigateCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
193     LRESULT OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
194     LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
195     LRESULT OnSetCursor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
196     LRESULT OnTipText(UINT idControl, NMHDR *pNMHDR, BOOL &bHandled);
197     LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
198     LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
199     LRESULT OnLDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
200     LRESULT OnLUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
201     LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
202     LRESULT OnWinIniChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled);
203 
204     BEGIN_MSG_MAP(CInternetToolbar)
205         COMMAND_ID_HANDLER(IDM_GOTO_BACK, OnTravelBack)
206         COMMAND_ID_HANDLER(IDM_GOTO_FORWARD, OnTravelForward)
207         COMMAND_ID_HANDLER(IDM_GOTO_UPONELEVEL, OnUpLevel)
208         COMMAND_ID_HANDLER(gSearchCommandID, OnSearch)
209         COMMAND_ID_HANDLER(gFoldersCommandID, OnFolders)
210         COMMAND_RANGE_HANDLER(0x7000, 0x7fff, OnForwardToCommandTarget)
211         NOTIFY_HANDLER(0, TBN_DROPDOWN, OnMenuDropDown)
212         NOTIFY_HANDLER(0, TBN_QUERYINSERT, OnQueryInsert)
213         NOTIFY_HANDLER(0, TBN_QUERYDELETE, OnQueryDelete)
214         MESSAGE_HANDLER(WM_COMMAND, OnCommand)
215         MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu)
216         MESSAGE_HANDLER(WM_SIZE, OnSize)
217         MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
218         NOTIFY_CODE_HANDLER(TTN_NEEDTEXTW, OnTipText)
219         MESSAGE_HANDLER(WM_NOTIFY, OnNotify)
220         MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLDown)
221         MESSAGE_HANDLER(WM_LBUTTONUP, OnLUp)
222         MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
223         MESSAGE_HANDLER(WM_WININICHANGE, OnWinIniChange)
224     END_MSG_MAP()
225 
226     DECLARE_REGISTRY_RESOURCEID(IDR_INTERNETTOOLBAR)
227     DECLARE_NOT_AGGREGATABLE(CInternetToolbar)
228 
229     DECLARE_PROTECT_FINAL_CONSTRUCT()
230 
231     BEGIN_COM_MAP(CInternetToolbar)
232         COM_INTERFACE_ENTRY_IID(IID_IInputObject, IInputObject)
233         COM_INTERFACE_ENTRY_IID(IID_IOleWindow, IOleWindow)
234         COM_INTERFACE_ENTRY_IID(IID_IDockingWindow, IDockingWindow)
235         COM_INTERFACE_ENTRY_IID(IID_IPersist, IPersist)
236 //        COM_INTERFACE_ENTRY_IID(IID_IPersistStream, IPersistStream)
237         COM_INTERFACE_ENTRY_IID(IID_IPersistStreamInit, IPersistStreamInit)
238         COM_INTERFACE_ENTRY_IID(IID_IOleCommandTarget, IOleCommandTarget)
239         COM_INTERFACE_ENTRY_IID(IID_IDispatch, IDispatch)
240         COM_INTERFACE_ENTRY_IID(IID_IExplorerToolbar, IExplorerToolbar)
241         COM_INTERFACE_ENTRY_IID(IID_IShellChangeNotify, IShellChangeNotify)
242         COM_INTERFACE_ENTRY_IID(IID_IObjectWithSite, IObjectWithSite)
243         COM_INTERFACE_ENTRY_IID(IID_IServiceProvider, IServiceProvider)
244         COM_INTERFACE_ENTRY_IID(IID_IWinEventHandler, IWinEventHandler)
245         COM_INTERFACE_ENTRY_IID(IID_IBandSite, IBandSite)
246     END_COM_MAP()
247 };
248