1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
21 #include <tools/debug.hxx>
23 #include <displayconnectiondispatch.hxx>
25 #include <salinst.hxx>
29 using namespace com::sun::star::uno
;
30 using namespace com::sun::star::awt
;
32 DisplayConnectionDispatch::DisplayConnectionDispatch()
34 m_ConnectionIdentifier
= ImplGetSVData()->mpDefInst
->GetConnectionIdentifier();
37 DisplayConnectionDispatch::~DisplayConnectionDispatch()
40 void DisplayConnectionDispatch::start()
43 ImplSVData
* pSVData
= ImplGetSVData();
44 pSVData
->mpDefInst
->SetEventCallback( this );
47 void DisplayConnectionDispatch::terminate()
50 ImplSVData
* pSVData
= ImplGetSVData();
54 pSVData
->mpDefInst
->SetEventCallback( nullptr );
57 SolarMutexReleaser aRel
;
59 MutexGuard
aGuard( m_aMutex
);
61 std::vector
< css::uno::Reference
< XEventHandler
> > aLocalList( m_aHandlers
);
62 for (auto const& elem
: aLocalList
)
63 elem
->handleEvent( aEvent
);
66 void SAL_CALL
DisplayConnectionDispatch::addEventHandler( const Any
& /*window*/, const css::uno::Reference
< XEventHandler
>& handler
, sal_Int32
/*eventMask*/ )
68 MutexGuard
aGuard( m_aMutex
);
70 m_aHandlers
.push_back( handler
);
73 void SAL_CALL
DisplayConnectionDispatch::removeEventHandler( const Any
& /*window*/, const css::uno::Reference
< XEventHandler
>& handler
)
75 MutexGuard
aGuard( m_aMutex
);
77 m_aHandlers
.erase( std::remove(m_aHandlers
.begin(), m_aHandlers
.end(), handler
), m_aHandlers
.end() );
80 void SAL_CALL
DisplayConnectionDispatch::addErrorHandler( const css::uno::Reference
< XEventHandler
>& )
84 void SAL_CALL
DisplayConnectionDispatch::removeErrorHandler( const css::uno::Reference
< XEventHandler
>& )
88 Any SAL_CALL
DisplayConnectionDispatch::getIdentifier()
90 return Any(m_ConnectionIdentifier
);
93 bool DisplayConnectionDispatch::dispatchEvent( void const * pData
, int nBytes
)
95 SolarMutexReleaser aRel
;
97 Sequence
< sal_Int8
> aSeq( static_cast<const sal_Int8
*>(pData
), nBytes
);
100 ::std::vector
< css::uno::Reference
< XEventHandler
> > handlers
;
102 MutexGuard
aGuard( m_aMutex
);
103 handlers
= m_aHandlers
;
105 for (auto const& handle
: handlers
)
106 if( handle
->handleEvent( aEvent
) )
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */