1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "vcl/vclevent.hxx"
25 #include <com/sun/star/accessibility/XAccessible.hpp>
27 using ::com::sun::star::uno::Reference
;
28 using ::com::sun::star::accessibility::XAccessible
;
30 TYPEINIT0(VclSimpleEvent
);
31 TYPEINIT1(VclWindowEvent
, VclSimpleEvent
);
32 TYPEINIT1(VclMenuEvent
, VclSimpleEvent
);
34 VclAccessibleEvent::VclAccessibleEvent( sal_uLong n
, const Reference
<XAccessible
>& rxAccessible
) :
36 mxAccessible(rxAccessible
)
40 VclAccessibleEvent::~VclAccessibleEvent()
44 Reference
<XAccessible
> VclAccessibleEvent::GetAccessible() const
49 void VclEventListeners::Call( VclSimpleEvent
* pEvent
) const
51 if ( m_aListeners
.empty() )
54 // Copy the list, because this can be destroyed when calling a Link...
55 std::list
<Link
> aCopy( m_aListeners
);
56 std::list
<Link
>::iterator
aIter( aCopy
.begin() );
57 std::list
<Link
>::const_iterator
aEnd( aCopy
.end() );
58 if( pEvent
->IsA( VclWindowEvent::StaticType() ) )
60 VclWindowEvent
* pWinEvent
= static_cast<VclWindowEvent
*>(pEvent
);
61 ImplDelData
aDel( pWinEvent
->GetWindow() );
62 while ( aIter
!= aEnd
&& ! aDel
.IsDead() )
65 // check this hasn't been removed in some re-enterancy scenario fdo#47368
66 if( std::find(m_aListeners
.begin(), m_aListeners
.end(), rLink
) != m_aListeners
.end() )
73 while ( aIter
!= aEnd
)
76 if( std::find(m_aListeners
.begin(), m_aListeners
.end(), rLink
) != m_aListeners
.end() )
83 sal_Bool
VclEventListeners::Process( VclSimpleEvent
* pEvent
) const
85 if ( m_aListeners
.empty() )
88 sal_Bool bProcessed
= sal_False
;
89 // Copy the list, because this can be destroyed when calling a Link...
90 std::list
<Link
> aCopy( m_aListeners
);
91 std::list
<Link
>::iterator
aIter( aCopy
.begin() );
92 std::list
<Link
>::const_iterator
aEnd( aCopy
.end() );
93 while ( aIter
!= aEnd
)
95 if( (*aIter
).Call( pEvent
) != 0 )
97 bProcessed
= sal_True
;
105 void VclEventListeners::addListener( const Link
& rListener
)
107 m_aListeners
.push_back( rListener
);
110 void VclEventListeners::removeListener( const Link
& rListener
)
112 m_aListeners
.remove( rListener
);
115 VclEventListeners2::VclEventListeners2()
119 VclEventListeners2::~VclEventListeners2()
123 void VclEventListeners2::addListener( const Link
& i_rLink
)
126 for( std::list
< Link
>::const_iterator it
= m_aListeners
.begin(); it
!= m_aListeners
.end(); ++it
)
131 m_aListeners
.push_back( i_rLink
);
134 void VclEventListeners2::removeListener( const Link
& i_rLink
)
136 size_t n
= m_aIterators
.size();
137 for( size_t i
= 0; i
< n
; i
++ )
139 if( m_aIterators
[i
].m_aIt
!= m_aListeners
.end() && *m_aIterators
[i
].m_aIt
== i_rLink
)
141 m_aIterators
[i
].m_bWasInvalidated
= true;
142 ++m_aIterators
[i
].m_aIt
;
145 m_aListeners
.remove( i_rLink
);
148 void VclEventListeners2::callListeners( VclSimpleEvent
* i_pEvent
)
150 vcl::DeletionListener
aDel( this );
152 m_aIterators
.push_back(ListenerIt(m_aListeners
.begin()));
153 size_t nIndex
= m_aIterators
.size() - 1;
154 while( ! aDel
.isDeleted() && m_aIterators
[ nIndex
].m_aIt
!= m_aListeners
.end() )
156 m_aIterators
[ nIndex
].m_aIt
->Call( i_pEvent
);
157 if( m_aIterators
[ nIndex
].m_bWasInvalidated
)
158 // check if the current element was removed and the iterator increased in the meantime
159 m_aIterators
[ nIndex
].m_bWasInvalidated
= false;
161 ++m_aIterators
[ nIndex
].m_aIt
;
163 m_aIterators
.pop_back();
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */