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