Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / embeddedobj / source / msole / olewrapclient.cxx
blob7f14a2629eaad55b6efbde6eb6334e60f43c55ac
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>
22 #include "olewrapclient.hxx"
23 #include "olecomponent.hxx"
25 // TODO: May be a mutex must be introduced
27 OleWrapperClientSite::OleWrapperClientSite( OleComponent* pOleComp )
28 : m_nRefCount( 0 )
29 , m_pOleComp( pOleComp )
31 OSL_ENSURE( m_pOleComp, "No ole component is provided!\n" );
34 OleWrapperClientSite::~OleWrapperClientSite()
38 STDMETHODIMP OleWrapperClientSite::QueryInterface( REFIID riid , void** ppv )
40 *ppv=NULL;
42 if ( riid == IID_IUnknown )
43 *ppv = (IUnknown*)this;
45 if ( riid == IID_IOleClientSite )
46 *ppv = (IOleClientSite*)this;
48 if ( *ppv != NULL )
50 ((IUnknown*)*ppv)->AddRef();
51 return S_OK;
54 return E_NOINTERFACE;
57 STDMETHODIMP_(ULONG) OleWrapperClientSite::AddRef()
59 return osl_atomic_increment( &m_nRefCount);
62 STDMETHODIMP_(ULONG) OleWrapperClientSite::Release()
64 ULONG nReturn = --m_nRefCount;
65 if ( m_nRefCount == 0 )
66 delete this;
68 return nReturn;
71 void OleWrapperClientSite::disconnectOleComponent()
73 // must not be called from the descructor of OleComponent!!!
74 osl::MutexGuard aGuard( m_aMutex );
75 m_pOleComp = NULL;
78 STDMETHODIMP OleWrapperClientSite::SaveObject()
80 OleComponent* pLockComponent = NULL;
81 HRESULT hResult = E_FAIL;
84 osl::MutexGuard aGuard( m_aMutex );
85 if ( m_pOleComp )
87 pLockComponent = m_pOleComp;
88 pLockComponent->acquire();
92 if ( pLockComponent )
94 if ( pLockComponent->SaveObject_Impl() )
95 hResult = S_OK;
97 pLockComponent->release();
100 return hResult;
103 STDMETHODIMP OleWrapperClientSite::GetMoniker( DWORD, DWORD, LPMONIKER *ppmk )
105 *ppmk = NULL;
106 return E_NOTIMPL;
109 STDMETHODIMP OleWrapperClientSite::GetContainer( LPOLECONTAINER* ppContainer )
111 *ppContainer = NULL;
112 return E_NOTIMPL;
115 STDMETHODIMP OleWrapperClientSite::ShowObject(void)
117 return S_OK;
120 STDMETHODIMP OleWrapperClientSite::OnShowWindow( BOOL bShow )
122 OleComponent* pLockComponent = NULL;
124 // TODO/LATER: redirect the notification to the main thread so that SolarMutex can be locked
126 osl::MutexGuard aGuard( m_aMutex );
127 if ( m_pOleComp )
129 pLockComponent = m_pOleComp;
130 pLockComponent->acquire();
134 if ( pLockComponent )
136 pLockComponent->OnShowWindow_Impl( bShow ); // the result is not interesting
137 pLockComponent->release();
140 return S_OK;
143 STDMETHODIMP OleWrapperClientSite::RequestNewObjectLayout(void)
145 return E_NOTIMPL;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */