diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:51:28 +0000 |
commit | 940b4d1848e8c70ab7642901a68594e8016caffc (patch) | |
tree | eb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /vcl/source/app/salusereventlist.cxx | |
parent | Initial commit. (diff) | |
download | libreoffice-upstream.tar.xz libreoffice-upstream.zip |
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vcl/source/app/salusereventlist.cxx')
-rw-r--r-- | vcl/source/app/salusereventlist.cxx | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/vcl/source/app/salusereventlist.cxx b/vcl/source/app/salusereventlist.cxx new file mode 100644 index 000000000..088bc141f --- /dev/null +++ b/vcl/source/app/salusereventlist.cxx @@ -0,0 +1,171 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <salusereventlist.hxx> +#include <salwtype.hxx> + +#include <algorithm> +#include <cstdlib> +#include <exception> +#include <typeinfo> + +#include <com/sun/star/uno/Exception.hpp> +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> +#include <sal/log.hxx> +#include <sal/types.h> +#include <svdata.hxx> + +SalUserEventList::SalUserEventList() + : m_bAllUserEventProcessedSignaled( true ) + , m_aProcessingThread(0) +{ +} + +SalUserEventList::~SalUserEventList() COVERITY_NOEXCEPT_FALSE +{ +} + +void SalUserEventList::insertFrame( SalFrame* pFrame ) +{ + auto aPair = m_aFrames.insert( pFrame ); + assert( aPair.second ); (void) aPair; +} + +void SalUserEventList::eraseFrame( SalFrame* pFrame ) +{ + auto it = m_aFrames.find( pFrame ); + assert( it != m_aFrames.end() ); + if ( it != m_aFrames.end() ) + m_aFrames.erase( it ); +} + +bool SalUserEventList::DispatchUserEvents( bool bHandleAllCurrentEvents ) +{ + bool bWasEvent = false; + oslThreadIdentifier aCurId = osl::Thread::getCurrentIdentifier(); + + DBG_TESTSOLARMUTEX(); + osl::ResettableMutexGuard aResettableListGuard(m_aUserEventsMutex); + + if (!m_aUserEvents.empty()) + { + if (bHandleAllCurrentEvents) + { + if (m_aProcessingUserEvents.empty()) + m_aProcessingUserEvents.swap(m_aUserEvents); + else + m_aProcessingUserEvents.splice(m_aProcessingUserEvents.end(), m_aUserEvents); + } + else if (m_aProcessingUserEvents.empty()) + { + m_aProcessingUserEvents.push_back( m_aUserEvents.front() ); + m_aUserEvents.pop_front(); + } + } + + if (HasUserEvents()) + { + bWasEvent = true; + m_aProcessingThread = aCurId; + + SalUserEvent aEvent( nullptr, nullptr, SalEvent::NONE ); + do { + if (m_aProcessingUserEvents.empty() || aCurId != m_aProcessingThread) + break; + aEvent = m_aProcessingUserEvents.front(); + m_aProcessingUserEvents.pop_front(); + + // remember to reset the guard before break or continue the loop + aResettableListGuard.clear(); + + if ( !isFrameAlive( aEvent.m_pFrame ) ) + { + if ( aEvent.m_nEvent == SalEvent::UserEvent ) + delete static_cast< ImplSVEvent* >( aEvent.m_pData ); + aResettableListGuard.reset(); + continue; + } + +#ifndef IOS + try +#endif + { + ProcessEvent( aEvent ); + } +#ifndef IOS + catch (css::uno::Exception&) + { + TOOLS_WARN_EXCEPTION("vcl", "Uncaught"); + std::abort(); + } + catch (std::exception& e) + { + SAL_WARN("vcl", "Uncaught " << typeid(e).name() << " " << e.what()); + std::abort(); + } + catch (...) + { + SAL_WARN("vcl", "Uncaught exception during DispatchUserEvents!"); + std::abort(); + } +#endif + aResettableListGuard.reset(); + if (!bHandleAllCurrentEvents) + break; + } + while( true ); + } + + if ( !m_bAllUserEventProcessedSignaled && !HasUserEvents() ) + { + m_bAllUserEventProcessedSignaled = true; + TriggerAllUserEventsProcessed(); + } + + return bWasEvent; +} + +void SalUserEventList::RemoveEvent( SalFrame* pFrame, void* pData, SalEvent nEvent ) +{ + SalUserEvent aEvent( pFrame, pData, nEvent ); + + osl::MutexGuard aGuard( m_aUserEventsMutex ); + auto it = std::find( m_aUserEvents.begin(), m_aUserEvents.end(), aEvent ); + if ( it != m_aUserEvents.end() ) + { + m_aUserEvents.erase( it ); + } + else + { + it = std::find( m_aProcessingUserEvents.begin(), m_aProcessingUserEvents.end(), aEvent ); + if ( it != m_aProcessingUserEvents.end() ) + { + m_aProcessingUserEvents.erase( it ); + } + } + + if ( !m_bAllUserEventProcessedSignaled && !HasUserEvents() ) + { + m_bAllUserEventProcessedSignaled = true; + TriggerAllUserEventsProcessed(); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |