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  m_updated = false;
36  if (VclWindowEvent* pWindowEvent = dynamic_cast<VclWindowEvent*>(&rEvent))
37  {
38  VclPtr<vcl::Window> xWin(pWindowEvent->GetWindow());
39  // checking mpWindowImpl to see if disposal is complete yet
40  while ( aIter != aEnd && (!xWin || xWin->mpWindowImpl) )
41  {
42  Link<VclSimpleEvent&,void> &rLink = *aIter;
43  // check this hasn't been removed in some re-enterancy scenario fdo#47368
44  // But only check if the list actually has been changed.
45  if( !m_updated || std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
46  rLink.Call( rEvent );
47  ++aIter;
48  }
49  }
50  else
51  {
52  while ( aIter != aEnd )
53  {
54  Link<VclSimpleEvent&,void> &rLink = *aIter;
55  if( !m_updated || std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
56  rLink.Call( rEvent );
57  ++aIter;
58  }
59  }
60 }
61 
63 {
64  m_aListeners.push_back( rListener );
65  m_updated = true;
66 }
67 
69 {
70  m_aListeners.erase( std::remove(m_aListeners.begin(), m_aListeners.end(), rListener ), m_aListeners.end() );
71  m_updated = true;
72 }
73 
75 {
76  pWindow = pWin; pData = pDat;
77 }
78 
80 
81 VclMenuEvent::VclMenuEvent( Menu* pM, VclEventId n, sal_uInt16 nPos )
82  : VclSimpleEvent(n), pMenu(pM), mnPos(nPos)
83 {}
84 
86 {}
87 
89 {
90  return pMenu;
91 }
92 
93 
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
VclWindowEvent(vcl::Window *pWin, VclEventId n, void *pDat)
Definition: vclevent.cxx:74
virtual ~VclWindowEvent() override
Definition: vclevent.cxx:79
void removeListener(const Link< VclSimpleEvent &, void > &rListener)
Definition: vclevent.cxx:68
VclEventId
Definition: vclevent.hxx:37
void Call(VclSimpleEvent &rEvent) const
Definition: vclevent.cxx:26
VclPtr< Menu > pMenu
Definition: vclevent.hxx:204
VclPtr< vcl::Window > pWindow
Definition: vclevent.hxx:190
Definition: menu.hxx:116
Menu * GetMenu() const
Definition: vclevent.cxx:88
VclMenuEvent(VclMenuEvent const &)=delete
std::vector< Link< VclSimpleEvent &, void > > m_aListeners
virtual ~VclMenuEvent() override
Definition: vclevent.cxx:85
void addListener(const Link< VclSimpleEvent &, void > &rListener)
Definition: vclevent.cxx:62