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 virtual HRESULT STDMETHODCALLTYPE AddBand(IUnknown *punk); 65 virtual HRESULT STDMETHODCALLTYPE EnumBands(UINT uBand, DWORD *pdwBandID); 66 virtual HRESULT STDMETHODCALLTYPE QueryBand(DWORD dwBandID, IDeskBand **ppstb, DWORD *pdwState, LPWSTR pszName, int cchName); 67 virtual HRESULT STDMETHODCALLTYPE SetBandState(DWORD dwBandID, DWORD dwMask, DWORD dwState); 68 virtual HRESULT STDMETHODCALLTYPE RemoveBand(DWORD dwBandID); 69 virtual HRESULT STDMETHODCALLTYPE GetBandObject(DWORD dwBandID, REFIID riid, void **ppv); 70 virtual HRESULT STDMETHODCALLTYPE SetBandSiteInfo(const BANDSITEINFO *pbsinfo); 71 virtual HRESULT STDMETHODCALLTYPE GetBandSiteInfo(BANDSITEINFO *pbsinfo); 72 73 // *** IWinEventHandler methods *** 74 virtual HRESULT STDMETHODCALLTYPE OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult); 75 virtual HRESULT STDMETHODCALLTYPE IsWindowOwner(HWND hWnd); 76 77 // *** IOleWindow methods *** 78 virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND *lphwnd); 79 virtual HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode); 80 81 // *** IDeskBarClient methods *** 82 virtual HRESULT STDMETHODCALLTYPE SetDeskBarSite(IUnknown *punkSite); 83 virtual HRESULT STDMETHODCALLTYPE SetModeDBC(DWORD dwMode); 84 virtual HRESULT STDMETHODCALLTYPE UIActivateDBC(DWORD dwState); 85 virtual HRESULT STDMETHODCALLTYPE GetSize(DWORD dwWhich, LPRECT prc); 86 87 // *** IOleCommandTarget methods *** 88 virtual HRESULT STDMETHODCALLTYPE QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds[ ], OLECMDTEXT *pCmdText); 89 virtual HRESULT STDMETHODCALLTYPE Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut); 90 91 // *** IInputObject methods *** 92 virtual HRESULT STDMETHODCALLTYPE UIActivateIO(BOOL fActivate, LPMSG lpMsg); 93 virtual HRESULT STDMETHODCALLTYPE HasFocusIO(); 94 virtual HRESULT STDMETHODCALLTYPE TranslateAcceleratorIO(LPMSG lpMsg); 95 96 // *** IInputObjectSite methods *** 97 virtual HRESULT STDMETHODCALLTYPE OnFocusChangeIS(struct IUnknown *paramC, int param10); 98 99 // *** IServiceProvider methods *** 100 virtual HRESULT STDMETHODCALLTYPE QueryService(REFGUID guidService, REFIID riid, void **ppvObject); 101 102 // *** IPersist methods *** 103 virtual HRESULT STDMETHODCALLTYPE GetClassID(CLSID *pClassID); 104 105 // *** IPersistStream methods *** 106 virtual HRESULT STDMETHODCALLTYPE IsDirty(); 107 virtual HRESULT STDMETHODCALLTYPE Load(IStream *pStm); 108 virtual HRESULT STDMETHODCALLTYPE Save(IStream *pStm, BOOL fClearDirty); 109 virtual HRESULT STDMETHODCALLTYPE GetSizeMax(ULARGE_INTEGER *pcbSize); 110 111 // *** IDropTarget methods *** 112 virtual HRESULT STDMETHODCALLTYPE DragEnter(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect); 113 virtual HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, DWORD *pdwEffect); 114 virtual HRESULT STDMETHODCALLTYPE DragLeave(); 115 virtual HRESULT STDMETHODCALLTYPE Drop(IDataObject *pDataObj, DWORD grfKeyState, POINTL pt, DWORD *pdwEffect); 116 117 // *** IBandSiteHelper methods *** 118 virtual HRESULT STDMETHODCALLTYPE LoadFromStreamBS(IStream *, const GUID &, void **); 119 virtual HRESULT STDMETHODCALLTYPE SaveToStreamBS(IUnknown *, IStream *); 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