LibreOffice Module vcl (master) 1
displayconnectiondispatch.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <vcl/svapp.hxx>
21#include <tools/debug.hxx>
22
24#include <svdata.hxx>
25#include <salinst.hxx>
26
27using namespace osl;
28using namespace vcl;
29using namespace com::sun::star::uno;
30using namespace com::sun::star::awt;
31
32DisplayConnectionDispatch::DisplayConnectionDispatch()
33{
35}
36
38{}
39
41{
43 ImplSVData* pSVData = ImplGetSVData();
44 pSVData->mpDefInst->SetEventCallback( this );
45}
46
48{
50 ImplSVData* pSVData = ImplGetSVData();
51
52 if( pSVData )
53 {
54 pSVData->mpDefInst->SetEventCallback( nullptr );
55 }
56
58
59 std::scoped_lock aGuard( m_aMutex );
60 Any aEvent;
61 std::vector< css::uno::Reference< XEventHandler > > aLocalList( m_aHandlers );
62 for (auto const& elem : aLocalList)
63 elem->handleEvent( aEvent );
64}
65
66void SAL_CALL DisplayConnectionDispatch::addEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler, sal_Int32 /*eventMask*/ )
67{
68 std::scoped_lock aGuard( m_aMutex );
69
70 m_aHandlers.push_back( handler );
71}
72
73void SAL_CALL DisplayConnectionDispatch::removeEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler )
74{
75 std::scoped_lock aGuard( m_aMutex );
76
77 m_aHandlers.erase( std::remove(m_aHandlers.begin(), m_aHandlers.end(), handler), m_aHandlers.end() );
78}
79
80void SAL_CALL DisplayConnectionDispatch::addErrorHandler( const css::uno::Reference< XEventHandler >& )
81{
82}
83
84void SAL_CALL DisplayConnectionDispatch::removeErrorHandler( const css::uno::Reference< XEventHandler >& )
85{
86}
87
89{
91}
92
93bool DisplayConnectionDispatch::dispatchEvent( void const * pData, int nBytes )
94{
96
97 Sequence< sal_Int8 > aSeq( static_cast<const sal_Int8*>(pData), nBytes );
98 Any aEvent;
99 aEvent <<= aSeq;
100 ::std::vector< css::uno::Reference< XEventHandler > > handlers;
101 {
102 std::scoped_lock aGuard( m_aMutex );
103 handlers = m_aHandlers;
104 }
105 for (auto const& handle : handlers)
106 if( handle->handleEvent( aEvent ) )
107 return true;
108 return false;
109}
110
111/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
void SetEventCallback(rtl::Reference< vcl::DisplayConnectionDispatch > const &pInstance)
Definition: salinst.hxx:174
virtual OUString GetConnectionIdentifier()=0
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
Definition: svapp.hxx:1414
virtual void SAL_CALL addErrorHandler(const css::uno::Reference< css::awt::XEventHandler > &handler) override
virtual void SAL_CALL addEventHandler(const css::uno::Any &window, const css::uno::Reference< css::awt::XEventHandler > &handler, sal_Int32 eventMask) override
virtual css::uno::Any SAL_CALL getIdentifier() override
virtual void SAL_CALL removeEventHandler(const css::uno::Any &window, const css::uno::Reference< css::awt::XEventHandler > &handler) override
bool dispatchEvent(void const *pData, int nBytes)
::std::vector< css::uno::Reference< css::awt::XEventHandler > > m_aHandlers
virtual void SAL_CALL removeErrorHandler(const css::uno::Reference< css::awt::XEventHandler > &handler) override
#define DBG_TESTSOLARMUTEX()
Sequence< sal_Int8 > aSeq
std::unique_ptr< sal_Int32[]> pData
SalInstance * mpDefInst
Definition: svdata.hxx:389
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:77
signed char sal_Int8