merge the formfield patch from ooo-build
[ooovba.git] / embeddedobj / source / msole / olewrapclient.cxx
blob983e7c970f8f2fa6005ff38edcac7bcbc9cfbdfd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: olewrapclient.cxx,v $
10 * $Revision: 1.6 $
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>
36 #include "olewrapclient.hxx"
37 #include "olecomponent.hxx"
39 // TODO: May be a mutex must be introduced
41 OleWrapperClientSite::OleWrapperClientSite( OleComponent* pOleComp )
42 : m_nRefCount( 0 )
43 , m_pOleComp( pOleComp )
45 OSL_ENSURE( m_pOleComp, "No ole component is provided!\n" );
48 OleWrapperClientSite::~OleWrapperClientSite()
52 STDMETHODIMP OleWrapperClientSite::QueryInterface( REFIID riid , void** ppv )
54 *ppv=NULL;
56 if ( riid == IID_IUnknown )
57 *ppv = (IUnknown*)this;
59 if ( riid == IID_IOleClientSite )
60 *ppv = (IOleClientSite*)this;
62 if ( *ppv != NULL )
64 ((IUnknown*)*ppv)->AddRef();
65 return S_OK;
68 return E_NOINTERFACE;
71 STDMETHODIMP_(ULONG) OleWrapperClientSite::AddRef()
73 return osl_incrementInterlockedCount( &m_nRefCount);
76 STDMETHODIMP_(ULONG) OleWrapperClientSite::Release()
78 ULONG nReturn = --m_nRefCount;
79 if ( m_nRefCount == 0 )
80 delete this;
82 return nReturn;
85 void OleWrapperClientSite::disconnectOleComponent()
87 // must not be called from the descructor of OleComponent!!!
88 osl::MutexGuard aGuard( m_aMutex );
89 m_pOleComp = NULL;
92 STDMETHODIMP OleWrapperClientSite::SaveObject()
94 OleComponent* pLockComponent = NULL;
95 HRESULT hResult = E_FAIL;
98 osl::MutexGuard aGuard( m_aMutex );
99 if ( m_pOleComp )
101 pLockComponent = m_pOleComp;
102 pLockComponent->acquire();
106 if ( pLockComponent )
108 if ( pLockComponent->SaveObject_Impl() )
109 hResult = S_OK;
111 pLockComponent->release();
114 return hResult;
117 STDMETHODIMP OleWrapperClientSite::GetMoniker( DWORD, DWORD, LPMONIKER *ppmk )
119 *ppmk = NULL;
120 return E_NOTIMPL;
123 STDMETHODIMP OleWrapperClientSite::GetContainer( LPOLECONTAINER* ppContainer )
125 *ppContainer = NULL;
126 return E_NOTIMPL;
129 STDMETHODIMP OleWrapperClientSite::ShowObject(void)
131 return S_OK;
134 STDMETHODIMP OleWrapperClientSite::OnShowWindow( BOOL bShow )
136 OleComponent* pLockComponent = NULL;
138 // TODO/LATER: redirect the notification to the main thread so that SolarMutex can be locked
140 osl::MutexGuard aGuard( m_aMutex );
141 if ( m_pOleComp )
143 pLockComponent = m_pOleComp;
144 pLockComponent->acquire();
148 if ( pLockComponent )
150 pLockComponent->OnShowWindow_Impl( bShow ); // the result is not interesting
151 pLockComponent->release();
154 return S_OK;
157 STDMETHODIMP OleWrapperClientSite::RequestNewObjectLayout(void)
159 return E_NOTIMPL;