1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #pragma warning(disable : 4668) 29 30 #include <advisesink.hxx> 31 32 namespace inprocserv 33 { 34 35 OleWrapperAdviseSink::OleWrapperAdviseSink() 36 : m_nRefCount( 0 ) 37 , m_pFormatEtc( NULL ) 38 , m_nAspect( DVASPECT_CONTENT ) 39 , m_nRegID( 0 ) 40 , m_bObjectAdvise( TRUE ) 41 , m_nDataRegFlag( 0 ) 42 , m_nViewRegFlag( 0 ) 43 , m_bHandleClosed( TRUE ) 44 , m_bClosed( FALSE ) 45 { 46 } 47 48 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener ) 49 : m_nRefCount( 0 ) 50 , m_pListener( pListener ) 51 , m_pFormatEtc( NULL ) 52 , m_nAspect( DVASPECT_CONTENT ) 53 , m_nRegID( 0 ) 54 , m_bObjectAdvise( TRUE ) 55 , m_nDataRegFlag( 0 ) 56 , m_nViewRegFlag( 0 ) 57 , m_bHandleClosed( FALSE ) 58 , m_bClosed( FALSE ) 59 { 60 } 61 62 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, FORMATETC* pFormatEtc, DWORD nDataRegFlag ) 63 : m_nRefCount( 0 ) 64 , m_pListener( pListener ) 65 , m_pFormatEtc( NULL ) 66 , m_nAspect( DVASPECT_CONTENT ) 67 , m_nRegID( 0 ) 68 , m_bObjectAdvise( FALSE ) 69 , m_nDataRegFlag( nDataRegFlag ) 70 , m_nViewRegFlag( 0 ) 71 , m_bHandleClosed( FALSE ) 72 , m_bClosed( FALSE ) 73 { 74 if ( pFormatEtc ) 75 { 76 m_pFormatEtc = new FORMATETC; 77 m_pFormatEtc->cfFormat = pFormatEtc->cfFormat; 78 m_pFormatEtc->ptd = NULL; 79 m_pFormatEtc->dwAspect = pFormatEtc->dwAspect; 80 m_pFormatEtc->lindex = pFormatEtc->lindex; 81 m_pFormatEtc->tymed = pFormatEtc->tymed; 82 } 83 } 84 85 OleWrapperAdviseSink::OleWrapperAdviseSink( const ComSmart< IAdviseSink >& pListener, DWORD nAspect, DWORD nViewRegFlag ) 86 : m_nRefCount( 0 ) 87 , m_pListener( pListener ) 88 , m_pFormatEtc( NULL ) 89 , m_nAspect( nAspect ) 90 , m_nRegID( 0 ) 91 , m_bObjectAdvise( TRUE ) 92 , m_nDataRegFlag( 0 ) 93 , m_nViewRegFlag( nViewRegFlag ) 94 , m_bHandleClosed( FALSE ) 95 , m_bClosed( FALSE ) 96 { 97 } 98 99 OleWrapperAdviseSink::~OleWrapperAdviseSink() 100 { 101 if ( m_pFormatEtc ) 102 delete m_pFormatEtc; 103 } 104 105 STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv ) 106 { 107 *ppv=NULL; 108 109 if ( riid == IID_IUnknown ) 110 *ppv = (IUnknown*)this; 111 112 if ( riid == IID_IAdviseSink ) 113 *ppv = (IAdviseSink*)this; 114 115 if ( *ppv != NULL ) 116 { 117 ((IUnknown*)*ppv)->AddRef(); 118 return S_OK; 119 } 120 121 return E_NOINTERFACE; 122 } 123 124 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::AddRef() 125 { 126 return ++m_nRefCount; 127 } 128 129 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::Release() 130 { 131 ULONG nReturn = --m_nRefCount; 132 if ( m_nRefCount == 0 ) 133 delete this; 134 135 return nReturn; 136 } 137 138 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange( LPFORMATETC pFetc, LPSTGMEDIUM pMedium ) 139 { 140 if ( m_pListener ) 141 { 142 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnDataChange():" ); 143 m_pListener->OnDataChange( pFetc, pMedium ); 144 } 145 } 146 147 STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange( DWORD dwAspect, LONG lindex ) 148 { 149 if ( m_pListener ) 150 { 151 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnViewChange():" ); 152 m_pListener->OnViewChange( dwAspect, lindex ); 153 } 154 } 155 156 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename( LPMONIKER pMoniker ) 157 { 158 if ( m_pListener ) 159 { 160 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnRename():" ); 161 m_pListener->OnRename( pMoniker ); 162 } 163 } 164 165 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave(void) 166 { 167 if ( m_pListener ) 168 { 169 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnSave():" ); 170 m_pListener->OnSave(); 171 } 172 } 173 174 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose(void) 175 { 176 if ( m_pListener ) 177 { 178 WRITEDEBUGINFO( "OleWrapperAdviseSink::OnClose():" ); 179 m_pListener->OnClose(); 180 } 181 182 if ( m_bHandleClosed ) 183 m_bClosed = TRUE; 184 } 185 186 } // namespace inprocserv 187 188