1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <osl/diagnose.h>
21 #include "advisesink.hxx"
22 #include "olecomponent.hxx"
24 #include <rtl/ref.hxx>
26 OleWrapperAdviseSink::OleWrapperAdviseSink( OleComponent
* pOleComp
)
28 , m_pOleComp( pOleComp
)
30 OSL_ENSURE( m_pOleComp
, "No ole component is provided!" );
33 OleWrapperAdviseSink::~OleWrapperAdviseSink()
37 STDMETHODIMP
OleWrapperAdviseSink::QueryInterface( REFIID riid
, void** ppv
)
41 if ( riid
== IID_IUnknown
)
42 *ppv
= static_cast<IUnknown
*>(this);
44 if ( riid
== IID_IAdviseSink
)
45 *ppv
= static_cast<IAdviseSink
*>(this);
47 if ( *ppv
!= nullptr )
49 static_cast<IUnknown
*>(*ppv
)->AddRef();
56 STDMETHODIMP_(ULONG
) OleWrapperAdviseSink::AddRef()
58 return osl_atomic_increment( &m_nRefCount
);
61 STDMETHODIMP_(ULONG
) OleWrapperAdviseSink::Release()
63 ULONG nReturn
= --m_nRefCount
;
64 if ( m_nRefCount
== 0 )
70 void OleWrapperAdviseSink::disconnectOleComponent()
72 // must not be called from the descructor of OleComponent!!!
73 osl::MutexGuard
aGuard( m_aMutex
);
77 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange(FORMATETC
*, STGMEDIUM
*)
79 // Unused for now ( no registration for IDataObject events )
82 STDMETHODIMP_(void) OleWrapperAdviseSink::OnViewChange(DWORD dwAspect
, LONG
)
84 ::rtl::Reference
< OleComponent
> xLockComponent
;
87 osl::MutexGuard
aGuard( m_aMutex
);
89 xLockComponent
= m_pOleComp
;
92 if ( xLockComponent
.is() )
93 xLockComponent
->OnViewChange_Impl( dwAspect
);
96 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename(IMoniker
*)
98 // handled by default inprocess handler
101 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave()
104 // The object already knows about document saving, since it controls it as ClientSide
105 // other interested listeners must be registered for the object
108 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose()
110 ::rtl::Reference
< OleComponent
> xLockComponent
;
113 osl::MutexGuard
aGuard( m_aMutex
);
115 xLockComponent
= m_pOleComp
;
118 if ( xLockComponent
.is() )
119 xLockComponent
->OnClose_Impl();
121 // TODO: sometimes it can be necessary to simulate OnShowWindow( False ) here
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */