LibreOffice Module vcl (master) 1
salusereventlist.hxx
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#ifndef INCLUDED_VCL_INC_SALUSEREVENTLIST_HXX
21#define INCLUDED_VCL_INC_SALUSEREVENTLIST_HXX
22
23#include <sal/config.h>
24#include <vcl/dllapi.h>
25#include <mutex>
26#include <osl/thread.hxx>
27
28#include <list>
30
31class SalFrame;
32enum class SalEvent;
33
35
37{
38public:
40 {
42 void* m_pData;
44
45 SalUserEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
46 : m_pFrame( pFrame ),
47 m_pData( pData ),
48 m_nEvent( nEvent )
49 {}
50
51 bool operator==(const SalUserEvent &aEvent) const
52 {
53 return m_pFrame == aEvent.m_pFrame
54 && m_pData == aEvent.m_pData
55 && m_nEvent== aEvent.m_nEvent;
56 }
57 };
58
59protected:
60 mutable std::mutex m_aUserEventsMutex;
61 std::list< SalUserEvent > m_aUserEvents;
62 std::list< SalUserEvent > m_aProcessingUserEvents;
65 oslThreadIdentifier m_aProcessingThread;
66
67 virtual void ProcessEvent( SalUserEvent aEvent ) = 0;
68 virtual void TriggerUserEventProcessing() = 0;
70
71 inline bool HasUserEvents_NoLock() const;
72public:
74 virtual ~SalUserEventList() COVERITY_NOEXCEPT_FALSE;
75
76 inline const SalFrameSet& getFrames() const;
77 inline SalFrame* anyFrame() const;
78 void insertFrame( SalFrame* pFrame );
79 void eraseFrame( SalFrame* pFrame );
80 inline bool isFrameAlive( const SalFrame* pFrame ) const;
81
82 void PostEvent( SalFrame* pFrame, void* pData, SalEvent nEvent );
83 void RemoveEvent( SalFrame* pFrame, void* pData, SalEvent nEvent );
84 inline bool HasUserEvents() const;
85
86 bool DispatchUserEvents( bool bHandleAllCurrentEvents );
87};
88
89inline SalFrame* SalUserEventList::anyFrame() const
90{
91 if ( m_aFrames.empty() )
92 return nullptr;
93 return *m_aFrames.begin();
94}
95
96inline bool SalUserEventList::isFrameAlive( const SalFrame* pFrame ) const
97{
98 auto it = m_aFrames.find( const_cast<SalFrame*>( pFrame ) );
99 return it != m_aFrames.end();
100}
101
103{
104 std::unique_lock aGuard( m_aUserEventsMutex );
105 return HasUserEvents_NoLock();
106}
107
109{
110 return !(m_aUserEvents.empty() && m_aProcessingUserEvents.empty());
111}
112
113inline void SalUserEventList::PostEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
114{
115 std::unique_lock aGuard( m_aUserEventsMutex );
116 m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
117 m_bAllUserEventProcessedSignaled = false;
118 TriggerUserEventProcessing();
119}
120
122{
123 return m_aFrames;
124}
125
126#endif // INCLUDED_VCL_INC_SALUSEREVENTLIST_HXX
127
128/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:115
bool isFrameAlive(const SalFrame *pFrame) const
virtual void ProcessEvent(SalUserEvent aEvent)=0
bool HasUserEvents_NoLock() const
std::list< SalUserEvent > m_aUserEvents
void PostEvent(SalFrame *pFrame, void *pData, SalEvent nEvent)
bool HasUserEvents() const
std::mutex m_aUserEventsMutex
virtual void TriggerUserEventProcessing()=0
const SalFrameSet & getFrames() const
oslThreadIdentifier m_aProcessingThread
std::list< SalUserEvent > m_aProcessingUserEvents
bool m_bAllUserEventProcessedSignaled
virtual void TriggerAllUserEventsProcessed()
const_iterator begin() const
const_iterator find(const Value &x) const
bool empty() const
const_iterator end() const
#define VCL_PLUGIN_PUBLIC
Definition: dllapi.h:40
FmFilterData * m_pData
std::unique_ptr< sal_Int32[]> pData
o3tl::sorted_vector< SalFrame * > SalFrameSet
SalEvent
Definition: salwtype.hxx:46
bool operator==(const SalUserEvent &aEvent) const
SalUserEvent(SalFrame *pFrame, void *pData, SalEvent nEvent)