Version 3.6.0.2, tag libreoffice-3.6.0.2
[LibreOffice.git] / embeddedobj / source / msole / olewrapclient.cxx
blobd3c6ac0712f96a70d01b39f7b9b0471949b9ec33
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>
31 #include "olewrapclient.hxx"
32 #include "olecomponent.hxx"
34 // TODO: May be a mutex must be introduced
36 OleWrapperClientSite::OleWrapperClientSite( OleComponent* pOleComp )
37 : m_nRefCount( 0 )
38 , m_pOleComp( pOleComp )
40 OSL_ENSURE( m_pOleComp, "No ole component is provided!\n" );
43 OleWrapperClientSite::~OleWrapperClientSite()
47 STDMETHODIMP OleWrapperClientSite::QueryInterface( REFIID riid , void** ppv )
49 *ppv=NULL;
51 if ( riid == IID_IUnknown )
52 *ppv = (IUnknown*)this;
54 if ( riid == IID_IOleClientSite )
55 *ppv = (IOleClientSite*)this;
57 if ( *ppv != NULL )
59 ((IUnknown*)*ppv)->AddRef();
60 return S_OK;
63 return E_NOINTERFACE;
66 STDMETHODIMP_(ULONG) OleWrapperClientSite::AddRef()
68 return osl_incrementInterlockedCount( &m_nRefCount);
71 STDMETHODIMP_(ULONG) OleWrapperClientSite::Release()
73 ULONG nReturn = --m_nRefCount;
74 if ( m_nRefCount == 0 )
75 delete this;
77 return nReturn;
80 void OleWrapperClientSite::disconnectOleComponent()
82 // must not be called from the descructor of OleComponent!!!
83 osl::MutexGuard aGuard( m_aMutex );
84 m_pOleComp = NULL;
87 STDMETHODIMP OleWrapperClientSite::SaveObject()
89 OleComponent* pLockComponent = NULL;
90 HRESULT hResult = E_FAIL;
93 osl::MutexGuard aGuard( m_aMutex );
94 if ( m_pOleComp )
96 pLockComponent = m_pOleComp;
97 pLockComponent->acquire();
101 if ( pLockComponent )
103 if ( pLockComponent->SaveObject_Impl() )
104 hResult = S_OK;
106 pLockComponent->release();
109 return hResult;
112 STDMETHODIMP OleWrapperClientSite::GetMoniker( DWORD, DWORD, LPMONIKER *ppmk )
114 *ppmk = NULL;
115 return E_NOTIMPL;
118 STDMETHODIMP OleWrapperClientSite::GetContainer( LPOLECONTAINER* ppContainer )
120 *ppContainer = NULL;
121 return E_NOTIMPL;
124 STDMETHODIMP OleWrapperClientSite::ShowObject(void)
126 return S_OK;
129 STDMETHODIMP OleWrapperClientSite::OnShowWindow( BOOL bShow )
131 OleComponent* pLockComponent = NULL;
133 // TODO/LATER: redirect the notification to the main thread so that SolarMutex can be locked
135 osl::MutexGuard aGuard( m_aMutex );
136 if ( m_pOleComp )
138 pLockComponent = m_pOleComp;
139 pLockComponent->acquire();
143 if ( pLockComponent )
145 pLockComponent->OnShowWindow_Impl( bShow ); // the result is not interesting
146 pLockComponent->release();
149 return S_OK;
152 STDMETHODIMP OleWrapperClientSite::RequestNewObjectLayout(void)
154 return E_NOTIMPL;
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */