Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / embeddedobj / source / msole / advisesink.cxx
blobc8272846b84becaed90157e34856343fd5007fe4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 )
27 : m_nRefCount( 0 )
28 , m_pOleComp( pOleComp )
30 OSL_ENSURE( m_pOleComp, "No ole component is provided!\n" );
33 OleWrapperAdviseSink::~OleWrapperAdviseSink()
37 STDMETHODIMP OleWrapperAdviseSink::QueryInterface( REFIID riid , void** ppv )
39 *ppv=NULL;
41 if ( riid == IID_IUnknown )
42 *ppv = (IUnknown*)this;
44 if ( riid == IID_IAdviseSink )
45 *ppv = (IAdviseSink*)this;
47 if ( *ppv != NULL )
49 ((IUnknown*)*ppv)->AddRef();
50 return S_OK;
53 return E_NOINTERFACE;
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 )
65 delete this;
67 return nReturn;
70 void OleWrapperAdviseSink::disconnectOleComponent()
72 // must not be called from the descructor of OleComponent!!!
73 osl::MutexGuard aGuard( m_aMutex );
74 m_pOleComp = NULL;
77 STDMETHODIMP_(void) OleWrapperAdviseSink::OnDataChange(LPFORMATETC, LPSTGMEDIUM)
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 );
88 if ( m_pOleComp )
89 xLockComponent = m_pOleComp;
92 if ( xLockComponent.is() )
93 xLockComponent->OnViewChange_Impl( dwAspect );
96 STDMETHODIMP_(void) OleWrapperAdviseSink::OnRename(LPMONIKER)
98 // handled by default inprocess handler
101 STDMETHODIMP_(void) OleWrapperAdviseSink::OnSave(void)
103 // TODO: ???
104 // The object knows about document saving already since it contolls it as ClienSite
105 // other interested listeners must be registered for the object
108 STDMETHODIMP_(void) OleWrapperAdviseSink::OnClose(void)
110 ::rtl::Reference< OleComponent > xLockComponent;
113 osl::MutexGuard aGuard( m_aMutex );
114 if ( m_pOleComp )
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: */