1*bfd08df8SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*bfd08df8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*bfd08df8SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*bfd08df8SAndrew Rist * distributed with this work for additional information
6*bfd08df8SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*bfd08df8SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*bfd08df8SAndrew Rist * "License"); you may not use this file except in compliance
9*bfd08df8SAndrew Rist * with the License. You may obtain a copy of the License at
10*bfd08df8SAndrew Rist *
11*bfd08df8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*bfd08df8SAndrew Rist *
13*bfd08df8SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*bfd08df8SAndrew Rist * software distributed under the License is distributed on an
15*bfd08df8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*bfd08df8SAndrew Rist * KIND, either express or implied. See the License for the
17*bfd08df8SAndrew Rist * specific language governing permissions and limitations
18*bfd08df8SAndrew Rist * under the License.
19*bfd08df8SAndrew Rist *
20*bfd08df8SAndrew Rist *************************************************************/
21*bfd08df8SAndrew Rist
22*bfd08df8SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_embeddedobj.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <osl/diagnose.h>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "olewrapclient.hxx"
30cdf0e10cSrcweir #include "olecomponent.hxx"
31cdf0e10cSrcweir
32cdf0e10cSrcweir // TODO: May be a mutex must be introduced
33cdf0e10cSrcweir
OleWrapperClientSite(OleComponent * pOleComp)34cdf0e10cSrcweir OleWrapperClientSite::OleWrapperClientSite( OleComponent* pOleComp )
35cdf0e10cSrcweir : m_nRefCount( 0 )
36cdf0e10cSrcweir , m_pOleComp( pOleComp )
37cdf0e10cSrcweir {
38cdf0e10cSrcweir OSL_ENSURE( m_pOleComp, "No ole component is provided!\n" );
39cdf0e10cSrcweir }
40cdf0e10cSrcweir
~OleWrapperClientSite()41cdf0e10cSrcweir OleWrapperClientSite::~OleWrapperClientSite()
42cdf0e10cSrcweir {
43cdf0e10cSrcweir }
44cdf0e10cSrcweir
QueryInterface(REFIID riid,void ** ppv)45cdf0e10cSrcweir STDMETHODIMP OleWrapperClientSite::QueryInterface( REFIID riid , void** ppv )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir *ppv=NULL;
48cdf0e10cSrcweir
49cdf0e10cSrcweir if ( riid == IID_IUnknown )
50cdf0e10cSrcweir *ppv = (IUnknown*)this;
51cdf0e10cSrcweir
52cdf0e10cSrcweir if ( riid == IID_IOleClientSite )
53cdf0e10cSrcweir *ppv = (IOleClientSite*)this;
54cdf0e10cSrcweir
55cdf0e10cSrcweir if ( *ppv != NULL )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir ((IUnknown*)*ppv)->AddRef();
58cdf0e10cSrcweir return S_OK;
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
61cdf0e10cSrcweir return E_NOINTERFACE;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir
STDMETHODIMP_(ULONG)64cdf0e10cSrcweir STDMETHODIMP_(ULONG) OleWrapperClientSite::AddRef()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir return osl_incrementInterlockedCount( &m_nRefCount);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
STDMETHODIMP_(ULONG)69cdf0e10cSrcweir STDMETHODIMP_(ULONG) OleWrapperClientSite::Release()
70cdf0e10cSrcweir {
71cdf0e10cSrcweir ULONG nReturn = --m_nRefCount;
72cdf0e10cSrcweir if ( m_nRefCount == 0 )
73cdf0e10cSrcweir delete this;
74cdf0e10cSrcweir
75cdf0e10cSrcweir return nReturn;
76cdf0e10cSrcweir }
77cdf0e10cSrcweir
disconnectOleComponent()78cdf0e10cSrcweir void OleWrapperClientSite::disconnectOleComponent()
79cdf0e10cSrcweir {
80cdf0e10cSrcweir // must not be called from the descructor of OleComponent!!!
81cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
82cdf0e10cSrcweir m_pOleComp = NULL;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir
SaveObject()85cdf0e10cSrcweir STDMETHODIMP OleWrapperClientSite::SaveObject()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir OleComponent* pLockComponent = NULL;
88cdf0e10cSrcweir HRESULT hResult = E_FAIL;
89cdf0e10cSrcweir
90cdf0e10cSrcweir {
91cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
92cdf0e10cSrcweir if ( m_pOleComp )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir pLockComponent = m_pOleComp;
95cdf0e10cSrcweir pLockComponent->acquire();
96cdf0e10cSrcweir }
97cdf0e10cSrcweir }
98cdf0e10cSrcweir
99cdf0e10cSrcweir if ( pLockComponent )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir if ( pLockComponent->SaveObject_Impl() )
102cdf0e10cSrcweir hResult = S_OK;
103cdf0e10cSrcweir
104cdf0e10cSrcweir pLockComponent->release();
105cdf0e10cSrcweir }
106cdf0e10cSrcweir
107cdf0e10cSrcweir return hResult;
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
GetMoniker(DWORD,DWORD,LPMONIKER * ppmk)110cdf0e10cSrcweir STDMETHODIMP OleWrapperClientSite::GetMoniker( DWORD, DWORD, LPMONIKER *ppmk )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir *ppmk = NULL;
113cdf0e10cSrcweir return E_NOTIMPL;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
GetContainer(LPOLECONTAINER * ppContainer)116cdf0e10cSrcweir STDMETHODIMP OleWrapperClientSite::GetContainer( LPOLECONTAINER* ppContainer )
117cdf0e10cSrcweir {
118cdf0e10cSrcweir *ppContainer = NULL;
119cdf0e10cSrcweir return E_NOTIMPL;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir
ShowObject(void)122cdf0e10cSrcweir STDMETHODIMP OleWrapperClientSite::ShowObject(void)
123cdf0e10cSrcweir {
124cdf0e10cSrcweir return S_OK;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir
OnShowWindow(BOOL bShow)127cdf0e10cSrcweir STDMETHODIMP OleWrapperClientSite::OnShowWindow( BOOL bShow )
128cdf0e10cSrcweir {
129cdf0e10cSrcweir OleComponent* pLockComponent = NULL;
130cdf0e10cSrcweir
131cdf0e10cSrcweir // TODO/LATER: redirect the notification to the main thread so that SolarMutex can be locked
132cdf0e10cSrcweir {
133cdf0e10cSrcweir osl::MutexGuard aGuard( m_aMutex );
134cdf0e10cSrcweir if ( m_pOleComp )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir pLockComponent = m_pOleComp;
137cdf0e10cSrcweir pLockComponent->acquire();
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir if ( pLockComponent )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir pLockComponent->OnShowWindow_Impl( bShow ); // the result is not interesting
144cdf0e10cSrcweir pLockComponent->release();
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir return S_OK;
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
RequestNewObjectLayout(void)150cdf0e10cSrcweir STDMETHODIMP OleWrapperClientSite::RequestNewObjectLayout(void)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir return E_NOTIMPL;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155