Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / vcl / source / app / salusereventlist.cxx
blobcb9104d7a5c1acf7216c4c0240c49442ed180ab1
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 <salusereventlist.hxx>
21 #include <salwtype.hxx>
23 #include <algorithm>
24 #include <cstdlib>
25 #include <exception>
26 #include <typeinfo>
28 #include <com/sun/star/uno/Exception.hpp>
29 #include <tools/debug.hxx>
30 #include <tools/diagnose_ex.h>
31 #include <sal/log.hxx>
32 #include <sal/types.h>
33 #include <svdata.hxx>
35 SalUserEventList::SalUserEventList()
36 : m_bAllUserEventProcessedSignaled( true )
37 , m_aProcessingThread(0)
41 SalUserEventList::~SalUserEventList() COVERITY_NOEXCEPT_FALSE
45 void SalUserEventList::insertFrame( SalFrame* pFrame )
47 auto aPair = m_aFrames.insert( pFrame );
48 assert( aPair.second ); (void) aPair;
51 void SalUserEventList::eraseFrame( SalFrame* pFrame )
53 auto it = m_aFrames.find( pFrame );
54 assert( it != m_aFrames.end() );
55 if ( it != m_aFrames.end() )
56 m_aFrames.erase( it );
59 bool SalUserEventList::DispatchUserEvents( bool bHandleAllCurrentEvents )
61 bool bWasEvent = false;
62 oslThreadIdentifier aCurId = osl::Thread::getCurrentIdentifier();
64 DBG_TESTSOLARMUTEX();
65 osl::ResettableMutexGuard aResettableListGuard(m_aUserEventsMutex);
67 if (!m_aUserEvents.empty())
69 if (bHandleAllCurrentEvents)
71 if (m_aProcessingUserEvents.empty())
72 m_aProcessingUserEvents.swap(m_aUserEvents);
73 else
74 m_aProcessingUserEvents.splice(m_aProcessingUserEvents.end(), m_aUserEvents);
76 else if (m_aProcessingUserEvents.empty())
78 m_aProcessingUserEvents.push_back( m_aUserEvents.front() );
79 m_aUserEvents.pop_front();
83 if (HasUserEvents())
85 bWasEvent = true;
86 m_aProcessingThread = aCurId;
88 SalUserEvent aEvent( nullptr, nullptr, SalEvent::NONE );
89 do {
90 if (m_aProcessingUserEvents.empty() || aCurId != m_aProcessingThread)
91 break;
92 aEvent = m_aProcessingUserEvents.front();
93 m_aProcessingUserEvents.pop_front();
95 // remember to reset the guard before break or continue the loop
96 aResettableListGuard.clear();
98 if ( !isFrameAlive( aEvent.m_pFrame ) )
100 if ( aEvent.m_nEvent == SalEvent::UserEvent )
101 delete static_cast< ImplSVEvent* >( aEvent.m_pData );
102 aResettableListGuard.reset();
103 continue;
108 ProcessEvent( aEvent );
110 catch (css::uno::Exception&)
112 TOOLS_WARN_EXCEPTION("vcl", "Uncaught");
113 std::abort();
115 catch (std::exception& e)
117 SAL_WARN("vcl", "Uncaught " << typeid(e).name() << " " << e.what());
118 std::abort();
120 catch (...)
122 SAL_WARN("vcl", "Uncaught exception during DispatchUserEvents!");
123 std::abort();
125 aResettableListGuard.reset();
126 if (!bHandleAllCurrentEvents)
127 break;
129 while( true );
132 if ( !m_bAllUserEventProcessedSignaled && !HasUserEvents() )
134 m_bAllUserEventProcessedSignaled = true;
135 TriggerAllUserEventsProcessed();
138 return bWasEvent;
141 void SalUserEventList::RemoveEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
143 SalUserEvent aEvent( pFrame, pData, nEvent );
145 osl::MutexGuard aGuard( m_aUserEventsMutex );
146 auto it = std::find( m_aUserEvents.begin(), m_aUserEvents.end(), aEvent );
147 if ( it != m_aUserEvents.end() )
149 m_aUserEvents.erase( it );
151 else
153 it = std::find( m_aProcessingUserEvents.begin(), m_aProcessingUserEvents.end(), aEvent );
154 if ( it != m_aProcessingUserEvents.end() )
156 m_aProcessingUserEvents.erase( it );
160 if ( !m_bAllUserEventProcessedSignaled && !HasUserEvents() )
162 m_bAllUserEventProcessedSignaled = true;
163 TriggerAllUserEventsProcessed();
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */