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 
27 using namespace osl;
28 using namespace vcl;
29 using namespace com::sun::star::uno;
30 using namespace com::sun::star::awt;
31 
32 DisplayConnectionDispatch::DisplayConnectionDispatch()
33 {
34  m_ConnectionIdentifier = ImplGetSVData()->mpDefInst->GetConnectionIdentifier();
35 }
36 
37 DisplayConnectionDispatch::~DisplayConnectionDispatch()
38 {}
39 
40 void DisplayConnectionDispatch::start()
41 {
43  ImplSVData* pSVData = ImplGetSVData();
44  pSVData->mpDefInst->SetEventCallback( this );
45 }
46 
47 void DisplayConnectionDispatch::terminate()
48 {
50  ImplSVData* pSVData = ImplGetSVData();
51 
52  if( pSVData )
53  {
54  pSVData->mpDefInst->SetEventCallback( nullptr );
55  }
56 
57  SolarMutexReleaser aRel;
58 
59  MutexGuard 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 
66 void SAL_CALL DisplayConnectionDispatch::addEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler, sal_Int32 /*eventMask*/ )
67 {
68  MutexGuard aGuard( m_aMutex );
69 
70  m_aHandlers.push_back( handler );
71 }
72 
73 void SAL_CALL DisplayConnectionDispatch::removeEventHandler( const Any& /*window*/, const css::uno::Reference< XEventHandler >& handler )
74 {
75  MutexGuard aGuard( m_aMutex );
76 
77  m_aHandlers.erase( std::remove(m_aHandlers.begin(), m_aHandlers.end(), handler), m_aHandlers.end() );
78 }
79 
80 void SAL_CALL DisplayConnectionDispatch::addErrorHandler( const css::uno::Reference< XEventHandler >& )
81 {
82 }
83 
84 void SAL_CALL DisplayConnectionDispatch::removeErrorHandler( const css::uno::Reference< XEventHandler >& )
85 {
86 }
87 
88 Any SAL_CALL DisplayConnectionDispatch::getIdentifier()
89 {
90  return Any(m_ConnectionIdentifier);
91 }
92 
93 bool DisplayConnectionDispatch::dispatchEvent( void const * pData, int nBytes )
94 {
95  SolarMutexReleaser aRel;
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  MutexGuard 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: */
::osl::Mutex m_aMutex
A helper class that calls Application::ReleaseSolarMutex() in its constructor and restores the mutex ...
Definition: svapp.hxx:1433
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:67
virtual OUString GetConnectionIdentifier()=0
#define DBG_TESTSOLARMUTEX()
void SetEventCallback(rtl::Reference< vcl::DisplayConnectionDispatch > const &pInstance)
Definition: salinst.hxx:174
SalInstance * mpDefInst
Definition: svdata.hxx:336