/src/libreoffice/vcl/inc/salusereventlist.hxx
Line | Count | Source |
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 | | #pragma once |
21 | | |
22 | | #include <sal/config.h> |
23 | | #include <vcl/dllapi.h> |
24 | | #include <mutex> |
25 | | #include <osl/thread.hxx> |
26 | | |
27 | | #include <list> |
28 | | #include <o3tl/sorted_vector.hxx> |
29 | | |
30 | | class SalFrame; |
31 | | enum class SalEvent; |
32 | | |
33 | | typedef o3tl::sorted_vector< SalFrame* > SalFrameSet; |
34 | | |
35 | | class VCL_PLUGIN_PUBLIC SalUserEventList |
36 | | { |
37 | | public: |
38 | | struct SalUserEvent |
39 | | { |
40 | | SalFrame* m_pFrame; |
41 | | void* m_pData; |
42 | | SalEvent m_nEvent; |
43 | | |
44 | | SalUserEvent( SalFrame* pFrame, void* pData, SalEvent nEvent ) |
45 | 78.6k | : m_pFrame( pFrame ), |
46 | 78.6k | m_pData( pData ), |
47 | 78.6k | m_nEvent( nEvent ) |
48 | 78.6k | {} |
49 | | |
50 | | bool operator==(const SalUserEvent &aEvent) const |
51 | 0 | { |
52 | 0 | return m_pFrame == aEvent.m_pFrame |
53 | 0 | && m_pData == aEvent.m_pData |
54 | 0 | && m_nEvent== aEvent.m_nEvent; |
55 | 0 | } |
56 | | }; |
57 | | |
58 | | private: |
59 | | SalFrameSet m_aFrames; |
60 | | mutable std::mutex m_aUserEventsMutex; |
61 | | std::list< SalUserEvent > m_aUserEvents; |
62 | | std::list< SalUserEvent > m_aProcessingUserEvents; |
63 | | bool m_bAllUserEventProcessedSignaled; |
64 | | oslThreadIdentifier m_aProcessingThread; |
65 | | |
66 | | protected: |
67 | | virtual void ProcessEvent( SalUserEvent aEvent ) = 0; |
68 | | virtual void TriggerUserEventProcessing() = 0; |
69 | 3.92k | virtual void TriggerAllUserEventsProcessed() {} |
70 | | |
71 | | inline bool HasUserEvents_NoLock() const; |
72 | | public: |
73 | | SalUserEventList(); |
74 | | virtual ~SalUserEventList(); |
75 | | |
76 | | inline const SalFrameSet& getFrames() const; |
77 | | inline SalFrame* anyFrame() const; |
78 | | void insertFrame( SalFrame* pFrame ); |
79 | | virtual 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 | | |
89 | | inline SalFrame* SalUserEventList::anyFrame() const |
90 | 0 | { |
91 | 0 | if ( m_aFrames.empty() ) |
92 | 0 | return nullptr; |
93 | 0 | return *m_aFrames.begin(); |
94 | 0 | } |
95 | | |
96 | | inline bool SalUserEventList::isFrameAlive( const SalFrame* pFrame ) const |
97 | 3.92k | { |
98 | 3.92k | auto it = m_aFrames.find( const_cast<SalFrame*>( pFrame ) ); |
99 | 3.92k | return it != m_aFrames.end(); |
100 | 3.92k | } |
101 | | |
102 | | inline bool SalUserEventList::HasUserEvents() const |
103 | 0 | { |
104 | 0 | std::unique_lock aGuard( m_aUserEventsMutex ); |
105 | 0 | return HasUserEvents_NoLock(); |
106 | 0 | } |
107 | | |
108 | | inline bool SalUserEventList::HasUserEvents_NoLock() const |
109 | 58.9k | { |
110 | 58.9k | return !(m_aUserEvents.empty() && m_aProcessingUserEvents.empty()); |
111 | 58.9k | } |
112 | | |
113 | | inline void SalUserEventList::PostEvent( SalFrame* pFrame, void* pData, SalEvent nEvent ) |
114 | 74.7k | { |
115 | 74.7k | std::unique_lock aGuard( m_aUserEventsMutex ); |
116 | 74.7k | m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) ); |
117 | 74.7k | m_bAllUserEventProcessedSignaled = false; |
118 | 74.7k | TriggerUserEventProcessing(); |
119 | 74.7k | } |
120 | | |
121 | | inline const SalFrameSet& SalUserEventList::getFrames() const |
122 | 0 | { |
123 | 0 | return m_aFrames; |
124 | 0 | } |
125 | | |
126 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |