1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <osl/diagnose.h>
30 #include <advisesink.hxx>
31 #include <olecomponent.hxx>
33 #include <rtl/ref.hxx>
35 OleWrapperAdviseSink::OleWrapperAdviseSink( OleComponent
* pOleComp
)
37 , m_pOleComp( pOleComp
)
39 OSL_ENSURE( m_pOleComp
, "No ole component is provided!\n" );
42 OleWrapperAdviseSink::~OleWrapperAdviseSink()
46 STDMETHODIMP
OleWrapperAdviseSink::QueryInterface( REFIID riid
, void** ppv
)
50 if ( riid
== IID_IUnknown
)
51 *ppv
= (IUnknown
*)this;
53 if ( riid
== IID_IAdviseSink
)
54 *ppv
= (IAdviseSink
*)this;
58 ((IUnknown
*)*ppv
)->AddRef();
65 STDMETHODIMP_(ULONG
) OleWrapperAdviseSink::AddRef()
67 return osl_incrementInterlockedCount( &m_nRefCount
);
70 STDMETHODIMP_(ULONG
) OleWrapperAdviseSink::Release()
72 ULONG nReturn
= --m_nRefCount
;
73 if ( m_nRefCount
== 0 )
79 void OleWrapperAdviseSink::disconnectOleComponent()
81 // must not be called from the descructor of OleComponent!!!
82 osl::MutexGuard
aGuard( m_aMutex
);
86 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange(LPFORMATETC
, LPSTGMEDIUM
)
88 // Unused for now ( no registration for IDataObject events )
91 STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange(DWORD dwAspect
, LONG
)
93 ::rtl::Reference
< OleComponent
> xLockComponent
;
96 osl::MutexGuard
aGuard( m_aMutex
);
98 xLockComponent
= m_pOleComp
;
101 if ( xLockComponent
.is() )
102 xLockComponent
->OnViewChange_Impl( dwAspect
);
105 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename(LPMONIKER
)
107 // handled by default inprocess handler
110 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave(void)
113 // The object knows about document saving already since it contolls it as ClienSite
114 // other interested listeners must be registered for the object
117 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose(void)
119 ::rtl::Reference
< OleComponent
> xLockComponent
;
122 osl::MutexGuard
aGuard( m_aMutex
);
124 xLockComponent
= m_pOleComp
;
127 if ( xLockComponent
.is() )
128 xLockComponent
->OnClose_Impl();
130 // TODO: sometimes it can be necessary to simulate OnShowWindow( False ) here
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */