1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #pragma warning(disable : 4668) 25 26 #include <advisesink.hxx> 27 28 namespace inprocserv 29 { 30 31 OleWrapperAdviseSink::OleWrapperAdviseSink() 32 : m_nRefCount( 0 ) 33 , m_pFormatEtc( NULL ) 34 , m_nAspect( DVASPECT_CONTENT ) 35 , m_nRegID( 0 ) 36 , m_bObjectAdvise( TRUE ) 37 , m_nDataRegFlag( 0 ) 38 , m_nViewRegFlag( 0 ) 39 , m_bHandleClosed( TRUE ) 40 , m_bClosed( FALSE ) 41 { 42 } 43 44 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener ) 45 : m_nRefCount( 0 ) 46 , m_pListener( pListener ) 47 , m_pFormatEtc( NULL ) 48 , m_nAspect( DVASPECT_CONTENT ) 49 , m_nRegID( 0 ) 50 , m_bObjectAdvise( TRUE ) 51 , m_nDataRegFlag( 0 ) 52 , m_nViewRegFlag( 0 ) 53 , m_bHandleClosed( FALSE ) 54 , m_bClosed( FALSE ) 55 { 56 } 57 58 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, FORMATETC* pFormatEtc, DWORD nDataRegFlag ) 59 : m_nRefCount( 0 ) 60 , m_pListener( pListener ) 61 , m_pFormatEtc( NULL ) 62 , m_nAspect( DVASPECT_CONTENT ) 63 , m_nRegID( 0 ) 64 , m_bObjectAdvise( FALSE ) 65 , m_nDataRegFlag( nDataRegFlag ) 66 , m_nViewRegFlag( 0 ) 67 , m_bHandleClosed( FALSE ) 68 , m_bClosed( FALSE ) 69 { 70 if ( pFormatEtc ) 71 { 72 m_pFormatEtc = new FORMATETC; 73 m_pFormatEtc->cfFormat = pFormatEtc->cfFormat; 74 m_pFormatEtc->ptd = NULL; 75 m_pFormatEtc->dwAspect = pFormatEtc->dwAspect; 76 m_pFormatEtc->lindex = pFormatEtc->lindex; 77 m_pFormatEtc->tymed = pFormatEtc->tymed; 78 } 79 } 80 81 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, DWORD nAspect, DWORD nViewRegFlag ) 82 : m_nRefCount( 0 ) 83 , m_pListener( pListener ) 84 , m_pFormatEtc( NULL ) 85 , m_nAspect( nAspect ) 86 , m_nRegID( 0 ) 87 , m_bObjectAdvise( TRUE ) 88 , m_nDataRegFlag( 0 ) 89 , m_nViewRegFlag( nViewRegFlag ) 90 , m_bHandleClosed( FALSE ) 91 , m_bClosed( FALSE ) 92 { 93 } 94 95 OleWrapperAdviseSink::~OleWrapperAdviseSink() 96 { 97 if ( m_pFormatEtc ) 98 delete m_pFormatEtc; 99 } 100 101 STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv ) 102 { 103 *ppv=NULL; 104 105 if ( riid == IID_IUnknown ) 106 *ppv = (IUnknown*)this; 107 108 if ( riid == IID_IAdviseSink ) 109 *ppv = (IAdviseSink*)this; 110 111 if ( *ppv != NULL ) 112 { 113 ((IUnknown*)*ppv)->AddRef(); 114 return S_OK; 115 } 116 117 return E_NOINTERFACE; 118 } 119 120 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::AddRef() 121 { 122 return ++m_nRefCount; 123 } 124 125 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::Release() 126 { 127 ULONG nReturn = --m_nRefCount; 128 if ( m_nRefCount == 0 ) 129 delete this; 130 131 return nReturn; 132 } 133 134 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange( LPFORMATETC pFetc, LPSTGMEDIUM pMedium ) 135 { 136 if ( m_pListener ) 137 { 138 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnDataChange():" ); 139 m_pListener->OnDataChange( pFetc, pMedium ); 140 } 141 } 142 143 STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange( DWORD dwAspect, LONG lindex ) 144 { 145 if ( m_pListener ) 146 { 147 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnViewChange():" ); 148 m_pListener->OnViewChange( dwAspect, lindex ); 149 } 150 } 151 152 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename( LPMONIKER pMoniker ) 153 { 154 if ( m_pListener ) 155 { 156 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnRename():" ); 157 m_pListener->OnRename( pMoniker ); 158 } 159 } 160 161 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave(void) 162 { 163 if ( m_pListener ) 164 { 165 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnSave():" ); 166 m_pListener->OnSave(); 167 } 168 } 169 170 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose(void) 171 { 172 if ( m_pListener ) 173 { 174 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnClose():" ); 175 m_pListener->OnClose(); 176 } 177 178 if ( m_bHandleClosed ) 179 m_bClosed = TRUE; 180 } 181 182 } // namespace inprocserv 183 184