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