1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: advisesink.cxx,v $
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
)
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
)
55 if ( riid
== IID_IUnknown
)
56 *ppv
= (IUnknown
*)this;
58 if ( riid
== IID_IAdviseSink
)
59 *ppv
= (IAdviseSink
*)this;
63 ((IUnknown
*)*ppv
)->AddRef();
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 )
84 void OleWrapperAdviseSink::disconnectOleComponent()
86 // must not be called from the descructor of OleComponent!!!
87 osl::MutexGuard
aGuard( m_aMutex
);
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
);
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)
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
);
129 xLockComponent
= m_pOleComp
;
132 if ( xLockComponent
.is() )
133 xLockComponent
->OnClose_Impl();
135 // TODO: sometimes it can be necessary to simulate OnShowWindow( False ) here