build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / vcl / source / helper / displayconnectiondispatch.cxx
blob77c9dab8d3b133b3c72b6cd63e59d50701928942
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/svapp.hxx>
22 #include "displayconnectiondispatch.hxx"
23 #include "svdata.hxx"
24 #include "salinst.hxx"
26 using namespace osl;
27 using namespace vcl;
28 using namespace com::sun::star::uno;
29 using namespace com::sun::star::awt;
31 DisplayConnectionDispatch::DisplayConnectionDispatch()
33 SalInstance::ConnectionIdentifierType eType;
34 int nBytes;
35 void* pBytes = ImplGetSVData()->mpDefInst->GetConnectionIdentifier( eType, nBytes );
36 switch( eType )
38 case SalInstance::AsciiCString:
39 m_aAny <<= OUString::createFromAscii( static_cast<sal_Char*>(pBytes) );
40 break;
41 case SalInstance::Blob:
42 m_aAny <<= Sequence< sal_Int8 >( static_cast<sal_Int8*>(pBytes), nBytes );
43 break;
47 DisplayConnectionDispatch::~DisplayConnectionDispatch()
50 void DisplayConnectionDispatch::start()
52 DBG_TESTSOLARMUTEX();
53 ImplSVData* pSVData = ImplGetSVData();
54 pSVData->mpDefInst->SetEventCallback( this );
57 void DisplayConnectionDispatch::terminate()
59 DBG_TESTSOLARMUTEX();
60 ImplSVData* pSVData = ImplGetSVData();
62 if( pSVData )
64 pSVData->mpDefInst->SetEventCallback( nullptr );
67 SolarMutexReleaser aRel;
69 MutexGuard aGuard( m_aMutex );
70 Any aEvent;
71 std::list< css::uno::Reference< XEventHandler > > aLocalList( m_aHandlers );
72 for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = aLocalList.begin(); it != aLocalList.end(); ++it )
73 (*it)->handleEvent( aEvent );
76 void SAL_CALL DisplayConnectionDispatch::addEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler, sal_Int32 /*eventMask*/ ) throw(std::exception)
78 MutexGuard aGuard( m_aMutex );
80 m_aHandlers.push_back( handler );
83 void SAL_CALL DisplayConnectionDispatch::removeEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler ) throw(std::exception)
85 MutexGuard aGuard( m_aMutex );
87 m_aHandlers.remove( handler );
90 void SAL_CALL DisplayConnectionDispatch::addErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw(std::exception)
92 MutexGuard aGuard( m_aMutex );
94 m_aErrorHandlers.push_back( handler );
97 void SAL_CALL DisplayConnectionDispatch::removeErrorHandler( const css::uno::Reference< XEventHandler >& handler ) throw(std::exception)
99 MutexGuard aGuard( m_aMutex );
101 m_aErrorHandlers.remove( handler );
104 Any SAL_CALL DisplayConnectionDispatch::getIdentifier() throw(std::exception)
106 return m_aAny;
109 bool DisplayConnectionDispatch::dispatchEvent( void* pData, int nBytes )
111 SolarMutexReleaser aRel;
113 Sequence< sal_Int8 > aSeq( static_cast<sal_Int8*>(pData), nBytes );
114 Any aEvent;
115 aEvent <<= aSeq;
116 ::std::list< css::uno::Reference< XEventHandler > > handlers;
118 MutexGuard aGuard( m_aMutex );
119 handlers = m_aHandlers;
121 for( ::std::list< css::uno::Reference< XEventHandler > >::const_iterator it = handlers.begin(); it != handlers.end(); ++it )
122 if( (*it)->handleEvent( aEvent ) )
123 return true;
124 return false;
127 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */