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 <osl/mutex.hxx>
26 #include <osl/thread.hxx>
27 
28 #include <list>
29 #include <unordered_set>
30 
31 class SalFrame;
32 enum class SalEvent;
33 
34 struct SalFrameHash : public std::hash<sal_IntPtr>
35 {
36  size_t operator()(const SalFrame* frame) const
37  { return std::hash<sal_IntPtr>::operator()( reinterpret_cast<sal_IntPtr>(frame) ); }
38 };
39 
40 typedef std::unordered_set< SalFrame*, SalFrameHash > SalFrameSet;
41 
43 {
44 public:
45  struct SalUserEvent
46  {
48  void* m_pData;
50 
51  SalUserEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
52  : m_pFrame( pFrame ),
53  m_pData( pData ),
54  m_nEvent( nEvent )
55  {}
56 
57  bool operator==(const SalUserEvent &aEvent) const
58  {
59  return m_pFrame == aEvent.m_pFrame
60  && m_pData == aEvent.m_pData
61  && m_nEvent== aEvent.m_nEvent;
62  }
63  };
64 
65 protected:
66  mutable osl::Mutex m_aUserEventsMutex;
67  std::list< SalUserEvent > m_aUserEvents;
68  std::list< SalUserEvent > m_aProcessingUserEvents;
71  oslThreadIdentifier m_aProcessingThread;
72 
73  virtual void ProcessEvent( SalUserEvent aEvent ) = 0;
74  virtual void TriggerUserEventProcessing() = 0;
76 
77 public:
79  virtual ~SalUserEventList() COVERITY_NOEXCEPT_FALSE;
80 
81  inline const SalFrameSet& getFrames() const;
82  inline SalFrame* anyFrame() const;
83  void insertFrame( SalFrame* pFrame );
84  void eraseFrame( SalFrame* pFrame );
85  inline bool isFrameAlive( const SalFrame* pFrame ) const;
86 
87  void PostEvent( SalFrame* pFrame, void* pData, SalEvent nEvent );
88  void RemoveEvent( SalFrame* pFrame, void* pData, SalEvent nEvent );
89  inline bool HasUserEvents() const;
90 
91  bool DispatchUserEvents( bool bHandleAllCurrentEvents );
92 };
93 
94 inline SalFrame* SalUserEventList::anyFrame() const
95 {
96  if ( m_aFrames.empty() )
97  return nullptr;
98  return *m_aFrames.begin();
99 }
100 
101 inline bool SalUserEventList::isFrameAlive( const SalFrame* pFrame ) const
102 {
103  auto it = m_aFrames.find( const_cast<SalFrame*>( pFrame ) );
104  return it != m_aFrames.end();
105 }
106 
108 {
109  osl::MutexGuard aGuard( m_aUserEventsMutex );
110  return !(m_aUserEvents.empty() && m_aProcessingUserEvents.empty());
111 }
112 
113 inline void SalUserEventList::PostEvent( SalFrame* pFrame, void* pData, SalEvent nEvent )
114 {
115  osl::MutexGuard 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: */
const SalFrameSet & getFrames() const
std::list< SalUserEvent > m_aProcessingUserEvents
size_t operator()(const SalFrame *frame) const
std::list< SalUserEvent > m_aUserEvents
virtual void TriggerAllUserEventsProcessed()
osl::Mutex m_aUserEventsMutex
bool HasUserEvents() const
bool operator==(const SalUserEvent &aEvent) const
SalEvent
Definition: salwtype.hxx:40
#define VCL_PLUGIN_PUBLIC
Definition: dllapi.h:40
A SalFrame is a system window (e.g. an X11 window).
Definition: salframe.hxx:112
SalUserEvent(SalFrame *pFrame, void *pData, SalEvent nEvent)
bool isFrameAlive(const SalFrame *pFrame) const
void PostEvent(SalFrame *pFrame, void *pData, SalEvent nEvent)
bool m_bAllUserEventProcessedSignaled
oslThreadIdentifier m_aProcessingThread
std::unordered_set< SalFrame *, SalFrameHash > SalFrameSet