1*9f62ea84SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9f62ea84SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9f62ea84SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9f62ea84SAndrew Rist * distributed with this work for additional information 6*9f62ea84SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9f62ea84SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9f62ea84SAndrew Rist * "License"); you may not use this file except in compliance 9*9f62ea84SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9f62ea84SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9f62ea84SAndrew Rist * software distributed under the License is distributed on an 15*9f62ea84SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9f62ea84SAndrew Rist * KIND, either express or implied. See the License for the 17*9f62ea84SAndrew Rist * specific language governing permissions and limitations 18*9f62ea84SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "vcl/svapp.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include "xconnection.hxx" 30cdf0e10cSrcweir #include "svdata.hxx" 31cdf0e10cSrcweir #include "salinst.hxx" 32cdf0e10cSrcweir 33cdf0e10cSrcweir namespace { 34cdf0e10cSrcweir 35cdf0e10cSrcweir namespace css = com::sun::star; 36cdf0e10cSrcweir 37cdf0e10cSrcweir } 38cdf0e10cSrcweir 39cdf0e10cSrcweir namespace vcl 40cdf0e10cSrcweir { 41cdf0e10cSrcweir class SolarMutexReleaser 42cdf0e10cSrcweir { 43cdf0e10cSrcweir sal_uLong mnReleased; 44cdf0e10cSrcweir public: 45cdf0e10cSrcweir SolarMutexReleaser() 46cdf0e10cSrcweir { 47cdf0e10cSrcweir mnReleased = Application::ReleaseSolarMutex(); 48cdf0e10cSrcweir } 49cdf0e10cSrcweir 50cdf0e10cSrcweir ~SolarMutexReleaser() 51cdf0e10cSrcweir { 52cdf0e10cSrcweir if( mnReleased ) 53cdf0e10cSrcweir Application::AcquireSolarMutex( mnReleased ); 54cdf0e10cSrcweir } 55cdf0e10cSrcweir }; 56cdf0e10cSrcweir } 57cdf0e10cSrcweir 58cdf0e10cSrcweir using namespace rtl; 59cdf0e10cSrcweir using namespace osl; 60cdf0e10cSrcweir using namespace vcl; 61cdf0e10cSrcweir using namespace com::sun::star::uno; 62cdf0e10cSrcweir using namespace com::sun::star::awt; 63cdf0e10cSrcweir 64cdf0e10cSrcweir 65cdf0e10cSrcweir DisplayConnection::DisplayConnection() 66cdf0e10cSrcweir { 67cdf0e10cSrcweir SalInstance::ConnectionIdentifierType eType; 68cdf0e10cSrcweir int nBytes; 69cdf0e10cSrcweir void* pBytes = ImplGetSVData()->mpDefInst->GetConnectionIdentifier( eType, nBytes ); 70cdf0e10cSrcweir switch( eType ) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir case SalInstance::AsciiCString: 73cdf0e10cSrcweir m_aAny <<= OUString::createFromAscii( (sal_Char*)pBytes ); 74cdf0e10cSrcweir break; 75cdf0e10cSrcweir case SalInstance::Blob: 76cdf0e10cSrcweir m_aAny <<= Sequence< sal_Int8 >( (sal_Int8*)pBytes, nBytes ); 77cdf0e10cSrcweir break; 78cdf0e10cSrcweir } 79cdf0e10cSrcweir } 80cdf0e10cSrcweir 81cdf0e10cSrcweir DisplayConnection::~DisplayConnection() 82cdf0e10cSrcweir {} 83cdf0e10cSrcweir 84cdf0e10cSrcweir void DisplayConnection::start() 85cdf0e10cSrcweir { 86cdf0e10cSrcweir ImplSVData* pSVData = ImplGetSVData(); 87cdf0e10cSrcweir pSVData->mpDefInst->SetEventCallback( this ); 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir void DisplayConnection::terminate() 91cdf0e10cSrcweir { 92cdf0e10cSrcweir ImplSVData* pSVData = ImplGetSVData(); 93cdf0e10cSrcweir 94cdf0e10cSrcweir if( pSVData ) 95cdf0e10cSrcweir { 96cdf0e10cSrcweir pSVData->mpDefInst->SetEventCallback( NULL ); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir SolarMutexReleaser aRel; 100cdf0e10cSrcweir 101cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 102cdf0e10cSrcweir Any aEvent; 103cdf0e10cSrcweir std::list< css::uno::Reference< XEventHandler > > aLocalList( m_aHandlers ); 104cdf0e10cSrcweir for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = aLocalList.begin(); it != aLocalList.end(); ++it ) 105cdf0e10cSrcweir (*it)->handleEvent( aEvent ); 106cdf0e10cSrcweir } 107cdf0e10cSrcweir 108cdf0e10cSrcweir void SAL_CALL DisplayConnection::addEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler, sal_Int32 /*eventMask*/ ) throw() 109cdf0e10cSrcweir { 110cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 111cdf0e10cSrcweir 112cdf0e10cSrcweir m_aHandlers.push_back( handler ); 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir void SAL_CALL DisplayConnection::removeEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler ) throw() 116cdf0e10cSrcweir { 117cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 118cdf0e10cSrcweir 119cdf0e10cSrcweir m_aHandlers.remove( handler ); 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir void SAL_CALL DisplayConnection::addErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw() 123cdf0e10cSrcweir { 124cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 125cdf0e10cSrcweir 126cdf0e10cSrcweir m_aErrorHandlers.push_back( handler ); 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir void SAL_CALL DisplayConnection::removeErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw() 130cdf0e10cSrcweir { 131cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 132cdf0e10cSrcweir 133cdf0e10cSrcweir m_aErrorHandlers.remove( handler ); 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir Any SAL_CALL DisplayConnection::getIdentifier() throw() 137cdf0e10cSrcweir { 138cdf0e10cSrcweir return m_aAny; 139cdf0e10cSrcweir } 140cdf0e10cSrcweir 141cdf0e10cSrcweir bool DisplayConnection::dispatchEvent( void* pData, int nBytes ) 142cdf0e10cSrcweir { 143cdf0e10cSrcweir SolarMutexReleaser aRel; 144cdf0e10cSrcweir 145cdf0e10cSrcweir Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes ); 146cdf0e10cSrcweir Any aEvent; 147cdf0e10cSrcweir aEvent <<= aSeq; 148cdf0e10cSrcweir ::std::list< css::uno::Reference< XEventHandler > > handlers; 149cdf0e10cSrcweir { 150cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 151cdf0e10cSrcweir handlers = m_aHandlers; 152cdf0e10cSrcweir } 153cdf0e10cSrcweir for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = handlers.begin(); it != handlers.end(); ++it ) 154cdf0e10cSrcweir if( (*it)->handleEvent( aEvent ) ) 155cdf0e10cSrcweir return true; 156cdf0e10cSrcweir return false; 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir bool DisplayConnection::dispatchErrorEvent( void* pData, int nBytes ) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir SolarMutexReleaser aRel; 162cdf0e10cSrcweir 163cdf0e10cSrcweir Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes ); 164cdf0e10cSrcweir Any aEvent; 165cdf0e10cSrcweir aEvent <<= aSeq; 166cdf0e10cSrcweir ::std::list< css::uno::Reference< XEventHandler > > handlers; 167cdf0e10cSrcweir { 168cdf0e10cSrcweir MutexGuard aGuard( m_aMutex ); 169cdf0e10cSrcweir handlers = m_aErrorHandlers; 170cdf0e10cSrcweir } 171cdf0e10cSrcweir for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = handlers.begin(); it != handlers.end(); ++it ) 172cdf0e10cSrcweir if( (*it)->handleEvent( aEvent ) ) 173cdf0e10cSrcweir return true; 174cdf0e10cSrcweir 175cdf0e10cSrcweir return false; 176cdf0e10cSrcweir } 177