tdf#119030: Disable entries if open file read-only is unchecked
[LibreOffice.git] / vcl / inc / salusereventlist.hxx
blob1222b8751807961e9a47d9154e6a817e28889ff6
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 #ifndef INCLUDED_VCL_INC_SALUSEREVENTLIST_HXX
21 #define INCLUDED_VCL_INC_SALUSEREVENTLIST_HXX
23 #include <sal/config.h>
24 #include <vcl/dllapi.h>
25 #include <osl/mutex.hxx>
26 #include <osl/thread.hxx>
28 #include <assert.h>
30 #include <list>
31 #include <unordered_set>
33 class SalFrame;
34 enum class SalEvent;
36 struct SalFrameHash : public std::hash<sal_IntPtr>
38 size_t operator()(const SalFrame* frame) const
39 { return std::hash<sal_IntPtr>::operator()( reinterpret_cast<sal_IntPtr>(frame) ); }
42 typedef std::unordered_set< SalFrame*, SalFrameHash > SalFrameSet;
44 class VCL_PLUGIN_PUBLIC SalUserEventList
46 public:
47 struct SalUserEvent
49 SalFrame* m_pFrame;
50 void* m_pData;
51 SalEvent m_nEvent;
53 SalUserEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
54 : m_pFrame( pFrame ),
55 m_pData( pData ),
56 m_nEvent( nEvent )
59 bool operator==(const SalUserEvent &aEvent) const
61 return m_pFrame == aEvent.m_pFrame
62 && m_pData == aEvent.m_pData
63 && m_nEvent== aEvent.m_nEvent;
67 protected:
68 mutable osl::Mutex m_aUserEventsMutex;
69 std::list< SalUserEvent > m_aUserEvents;
70 std::list< SalUserEvent > m_aProcessingUserEvents;
71 bool m_bAllUserEventProcessedSignaled;
72 SalFrameSet m_aFrames;
73 oslThreadIdentifier m_aProcessingThread;
75 virtual void ProcessEvent( SalUserEvent aEvent ) = 0;
76 virtual void TriggerUserEventProcessing() = 0;
77 virtual void TriggerAllUserEventsProcessed() {};
79 public:
80 SalUserEventList();
81 virtual ~SalUserEventList();
83 inline const SalFrameSet& getFrames() const;
84 inline SalFrame* anyFrame() const;
85 void insertFrame( SalFrame* pFrame );
86 void eraseFrame( SalFrame* pFrame );
87 inline bool isFrameAlive( const SalFrame* pFrame ) const;
89 void PostEvent( SalFrame* pFrame, void* pData, SalEvent nEvent );
90 void RemoveEvent( SalFrame* pFrame, void* pData, SalEvent nEvent );
91 inline bool HasUserEvents() const;
93 bool DispatchUserEvents( bool bHandleAllCurrentEvents );
96 inline SalFrame* SalUserEventList::anyFrame() const
98 if ( m_aFrames.empty() )
99 return nullptr;
100 return *m_aFrames.begin();
103 inline bool SalUserEventList::isFrameAlive( const SalFrame* pFrame ) const
105 auto it = m_aFrames.find( const_cast<SalFrame*>( pFrame ) );
106 return it != m_aFrames.end();
109 inline bool SalUserEventList::HasUserEvents() const
111 osl::MutexGuard aGuard( m_aUserEventsMutex );
112 return !(m_aUserEvents.empty() && m_aProcessingUserEvents.empty());
115 inline void SalUserEventList::PostEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
117 osl::MutexGuard aGuard( m_aUserEventsMutex );
118 m_aUserEvents.push_back( SalUserEvent( pFrame, pData, nEvent ) );
119 m_bAllUserEventProcessedSignaled = false;
120 TriggerUserEventProcessing();
123 inline const SalFrameSet& SalUserEventList::getFrames() const
125 return m_aFrames;
128 #endif // INCLUDED_VCL_INC_SALUSEREVENTLIST_HXX
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */