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