merge the formfield patch from ooo-build
[ooovba.git] / vcl / source / helper / xconnection.cxx
blob89b61694a12e115c20b7d12633da530a44024cac
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: xconnection.cxx,v $
10 * $Revision: 1.12 $
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_vcl.hxx"
33 #include <svsys.h>
34 #include <vcl/xconnection.hxx>
35 #include <vcl/svdata.hxx>
36 #include <vcl/salinst.hxx>
38 using namespace rtl;
39 using namespace osl;
40 using namespace vcl;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::awt;
44 DisplayConnection::DisplayConnection()
46 ImplSVData* pSVData = ImplGetSVData();
47 pSVData->mpDefInst->SetEventCallback( this, dispatchEvent );
48 pSVData->mpDefInst->SetErrorEventCallback( this, dispatchErrorEvent );
50 SalInstance::ConnectionIdentifierType eType;
51 int nBytes;
52 void* pBytes = pSVData->mpDefInst->GetConnectionIdentifier( eType, nBytes );
53 switch( eType )
55 case SalInstance::AsciiCString:
56 m_aAny <<= OUString::createFromAscii( (sal_Char*)pBytes );
57 break;
58 case SalInstance::Blob:
59 m_aAny <<= Sequence< sal_Int8 >( (sal_Int8*)pBytes, nBytes );
60 break;
64 DisplayConnection::~DisplayConnection()
66 ImplSVData* pSVData = ImplGetSVData();
68 if( pSVData )
70 pSVData->mpDefInst->SetEventCallback( NULL, NULL );
71 pSVData->mpDefInst->SetErrorEventCallback( NULL, NULL );
76 void SAL_CALL DisplayConnection::addEventHandler( const Any& /*window*/, const Reference< XEventHandler >& handler, sal_Int32 /*eventMask*/ ) throw()
78 MutexGuard aGuard( m_aMutex );
80 m_aHandlers.push_back( handler );
83 void SAL_CALL DisplayConnection::removeEventHandler( const Any& /*window*/, const Reference< XEventHandler >& handler ) throw()
85 MutexGuard aGuard( m_aMutex );
87 m_aHandlers.remove( handler );
90 void SAL_CALL DisplayConnection::addErrorHandler( const Reference< XEventHandler >& handler ) throw()
92 MutexGuard aGuard( m_aMutex );
94 m_aErrorHandlers.push_back( handler );
97 void SAL_CALL DisplayConnection::removeErrorHandler( const Reference< XEventHandler >& handler ) throw()
99 MutexGuard aGuard( m_aMutex );
101 m_aErrorHandlers.remove( handler );
104 Any SAL_CALL DisplayConnection::getIdentifier() throw()
106 return m_aAny;
109 void DisplayConnection::dispatchDowningEvent()
111 MutexGuard aGuard( m_aMutex );
112 Any aEvent;
113 std::list< Reference< XEventHandler > > aLocalList( m_aHandlers );
114 for( ::std::list< Reference< XEventHandler > >::const_iterator it = aLocalList.begin(); it != aLocalList.end(); ++it )
115 (*it)->handleEvent( aEvent );
118 bool DisplayConnection::dispatchEvent( void* pThis, void* pData, int nBytes )
120 DisplayConnection* This = (DisplayConnection*)pThis;
121 MutexGuard aGuard( This->m_aMutex );
123 Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes );
124 Any aEvent;
125 aEvent <<= aSeq;
126 for( ::std::list< Reference< XEventHandler > >::const_iterator it = This->m_aHandlers.begin(); it != This->m_aHandlers.end(); ++it )
127 if( (*it)->handleEvent( aEvent ) )
128 return true;
129 return false;
132 bool DisplayConnection::dispatchErrorEvent( void* pThis, void* pData, int nBytes )
134 DisplayConnection* This = (DisplayConnection*)pThis;
135 MutexGuard aGuard( This->m_aMutex );
137 Sequence< sal_Int8 > aSeq( (sal_Int8*)pData, nBytes );
138 Any aEvent;
139 aEvent <<= aSeq;
140 for( ::std::list< Reference< XEventHandler > >::const_iterator it = This->m_aErrorHandlers.begin(); it != This->m_aErrorHandlers.end(); ++it )
141 if( (*it)->handleEvent( aEvent ) )
142 return true;
144 return false;