LibreOffice Module vcl (master)  1
vclevent.cxx
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 #include <vcl/vclevent.hxx>
21 #include <vcl/window.hxx>
22 #include <vcl/menu.hxx>
23 
24 #include <vcleventlisteners.hxx>
25 
26 #include <com/sun/star/accessibility/XAccessible.hpp>
27 
28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::accessibility::XAccessible;
30 
31 
32 VclAccessibleEvent::VclAccessibleEvent( VclEventId n, const Reference<XAccessible>& rxAccessible ) :
33  VclSimpleEvent(n),
34  mxAccessible(rxAccessible)
35 {
36 }
37 
39 {
40 }
41 
42 
44 {
45  if ( m_aListeners.empty() )
46  return;
47 
48  // Copy the list, because this can be destroyed when calling a Link...
49  std::vector<Link<VclSimpleEvent&,void>> aCopy( m_aListeners );
50  std::vector<Link<VclSimpleEvent&,void>>::iterator aIter( aCopy.begin() );
51  std::vector<Link<VclSimpleEvent&,void>>::const_iterator aEnd( aCopy.end() );
52  if (VclWindowEvent* pWindowEvent = dynamic_cast<VclWindowEvent*>(&rEvent))
53  {
54  VclPtr<vcl::Window> xWin(pWindowEvent->GetWindow());
55  while ( aIter != aEnd && xWin && ! xWin->IsDisposed() )
56  {
57  Link<VclSimpleEvent&,void> &rLink = *aIter;
58  // check this hasn't been removed in some re-enterancy scenario fdo#47368
59  if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
60  rLink.Call( rEvent );
61  ++aIter;
62  }
63  }
64  else
65  {
66  while ( aIter != aEnd )
67  {
68  Link<VclSimpleEvent&,void> &rLink = *aIter;
69  if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
70  rLink.Call( rEvent );
71  ++aIter;
72  }
73  }
74 }
75 
77 {
78  m_aListeners.push_back( rListener );
79 }
80 
82 {
83  m_aListeners.erase( std::remove(m_aListeners.begin(), m_aListeners.end(), rListener ), m_aListeners.end() );
84 }
85 
87 {
88  pWindow = pWin; pData = pDat;
89 }
90 
92 
93 VclMenuEvent::VclMenuEvent( Menu* pM, VclEventId n, sal_uInt16 nPos )
94  : VclSimpleEvent(n), pMenu(pM), mnPos(nPos)
95 {}
96 
98 {}
99 
101 {
102  return pMenu;
103 }
104 
105 
106 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VclAccessibleEvent(VclEventId n, const css::uno::Reference< css::accessibility::XAccessible > &rxAccessible)
Definition: vclevent.cxx:32
virtual ~VclAccessibleEvent() override
Definition: vclevent.cxx:38
VclWindowEvent(vcl::Window *pWin, VclEventId n, void *pDat)
Definition: vclevent.cxx:86
virtual ~VclWindowEvent() override
Definition: vclevent.cxx:91
void removeListener(const Link< VclSimpleEvent &, void > &rListener)
Definition: vclevent.cxx:81
VclEventId
Definition: vclevent.hxx:41
void Call(VclSimpleEvent &rEvent) const
Definition: vclevent.cxx:43
VclPtr< Menu > pMenu
Definition: vclevent.hxx:208
VclPtr< vcl::Window > pWindow
Definition: vclevent.hxx:194
Definition: menu.hxx:121
Menu * GetMenu() const
Definition: vclevent.cxx:100
VclMenuEvent(VclMenuEvent const &)=delete
std::vector< Link< VclSimpleEvent &, void > > m_aListeners
virtual ~VclMenuEvent() override
Definition: vclevent.cxx:97
void addListener(const Link< VclSimpleEvent &, void > &rListener)
Definition: vclevent.cxx:76