Update ooo320-m1
[ooovba.git] / embeddedobj / source / msole / advisesink.cxx
blob1344b95f100bbc6ebd49c2a97994bac4d7efdfe9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: advisesink.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_embeddedobj.hxx"
34 #include <osl/diagnose.h>
35 #include <advisesink.hxx>
36 #include <olecomponent.hxx>
38 #include <rtl/ref.hxx>
40 OleWrapperAdviseSink::OleWrapperAdviseSink( OleComponent* pOleComp )
41 : m_nRefCount( 0 )
42 , m_pOleComp( pOleComp )
44 OSL_ENSURE( m_pOleComp, "No ole component is provided!\n" );
47 OleWrapperAdviseSink::~OleWrapperAdviseSink()
51 STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv )
53 *ppv=NULL;
55 if ( riid == IID_IUnknown )
56 *ppv = (IUnknown*)this;
58 if ( riid == IID_IAdviseSink )
59 *ppv = (IAdviseSink*)this;
61 if ( *ppv != NULL )
63 ((IUnknown*)*ppv)->AddRef();
64 return S_OK;
67 return E_NOINTERFACE;
70 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::AddRef()
72 return osl_incrementInterlockedCount( &m_nRefCount);
75 STDMETHODIMP_(ULONG) OleWrapperAdviseSink::Release()
77 ULONG nReturn = --m_nRefCount;
78 if ( m_nRefCount == 0 )
79 delete this;
81 return nReturn;
84 void OleWrapperAdviseSink::disconnectOleComponent()
86 // must not be called from the descructor of OleComponent!!!
87 osl::MutexGuard aGuard( m_aMutex );
88 m_pOleComp = NULL;
91 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange(LPFORMATETC, LPSTGMEDIUM)
93 // Unused for now ( no registration for IDataObject events )
96 STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange(DWORD dwAspect, LONG)
98 ::rtl::Reference< OleComponent > xLockComponent;
101 osl::MutexGuard aGuard( m_aMutex );
102 if ( m_pOleComp )
103 xLockComponent = m_pOleComp;
106 if ( xLockComponent.is() )
107 xLockComponent->OnViewChange_Impl( dwAspect );
110 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename(LPMONIKER)
112 // handled by default inprocess handler
115 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave(void)
117 // TODO: ???
118 // The object knows about document saving already since it contolls it as ClienSite
119 // other interested listeners must be registered for the object
122 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose(void)
124 ::rtl::Reference< OleComponent > xLockComponent;
127 osl::MutexGuard aGuard( m_aMutex );
128 if ( m_pOleComp )
129 xLockComponent = m_pOleComp;
132 if ( xLockComponent.is() )
133 xLockComponent->OnClose_Impl();
135 // TODO: sometimes it can be necessary to simulate OnShowWindow( False ) here