Line data Source code
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 :
22 : #include "svdata.hxx"
23 :
24 : #include <com/sun/star/accessibility/XAccessible.hpp>
25 :
26 : using ::com::sun::star::uno::Reference;
27 : using ::com::sun::star::accessibility::XAccessible;
28 :
29 0 : TYPEINIT0(VclSimpleEvent);
30 0 : TYPEINIT1(VclWindowEvent, VclSimpleEvent);
31 0 : TYPEINIT1(VclMenuEvent, VclSimpleEvent);
32 :
33 0 : VclAccessibleEvent::VclAccessibleEvent( sal_uLong n, const Reference<XAccessible>& rxAccessible ) :
34 : VclSimpleEvent(n),
35 0 : mxAccessible(rxAccessible)
36 : {
37 0 : }
38 :
39 0 : VclAccessibleEvent::~VclAccessibleEvent()
40 : {
41 0 : }
42 :
43 0 : Reference<XAccessible> VclAccessibleEvent::GetAccessible() const
44 : {
45 0 : return mxAccessible;
46 : }
47 :
48 0 : void VclEventListeners::Call( VclSimpleEvent* pEvent ) const
49 : {
50 0 : if ( m_aListeners.empty() )
51 0 : return;
52 :
53 : // Copy the list, because this can be destroyed when calling a Link...
54 0 : std::list<Link> aCopy( m_aListeners );
55 0 : std::list<Link>::iterator aIter( aCopy.begin() );
56 0 : std::list<Link>::const_iterator aEnd( aCopy.end() );
57 0 : if( pEvent->IsA( VclWindowEvent::StaticType() ) )
58 : {
59 0 : VclWindowEvent* pWinEvent = static_cast<VclWindowEvent*>(pEvent);
60 0 : ImplDelData aDel( pWinEvent->GetWindow() );
61 0 : while ( aIter != aEnd && ! aDel.IsDead() )
62 : {
63 0 : Link &rLink = *aIter;
64 : // check this hasn't been removed in some re-enterancy scenario fdo#47368
65 0 : if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
66 0 : rLink.Call( pEvent );
67 0 : ++aIter;
68 0 : }
69 : }
70 : else
71 : {
72 0 : while ( aIter != aEnd )
73 : {
74 0 : Link &rLink = *aIter;
75 0 : if( std::find(m_aListeners.begin(), m_aListeners.end(), rLink) != m_aListeners.end() )
76 0 : rLink.Call( pEvent );
77 0 : ++aIter;
78 : }
79 0 : }
80 : }
81 :
82 0 : bool VclEventListeners::Process( VclSimpleEvent* pEvent ) const
83 : {
84 0 : if ( m_aListeners.empty() )
85 0 : return false;
86 :
87 0 : bool bProcessed = false;
88 : // Copy the list, because this can be destroyed when calling a Link...
89 0 : std::list<Link> aCopy( m_aListeners );
90 0 : std::list<Link>::iterator aIter( aCopy.begin() );
91 0 : std::list<Link>::const_iterator aEnd( aCopy.end() );
92 0 : while ( aIter != aEnd )
93 : {
94 0 : if( (*aIter).Call( pEvent ) != 0 )
95 : {
96 0 : bProcessed = true;
97 0 : break;
98 : }
99 0 : ++aIter;
100 : }
101 0 : return bProcessed;
102 : }
103 :
104 0 : void VclEventListeners::addListener( const Link& rListener )
105 : {
106 0 : m_aListeners.push_back( rListener );
107 0 : }
108 :
109 0 : void VclEventListeners::removeListener( const Link& rListener )
110 : {
111 0 : m_aListeners.remove( rListener );
112 0 : }
113 :
114 0 : VclEventListeners2::VclEventListeners2()
115 : {
116 0 : }
117 :
118 0 : VclEventListeners2::~VclEventListeners2()
119 : {
120 0 : }
121 :
122 0 : void VclEventListeners2::addListener( const Link& i_rLink )
123 : {
124 : // ensure uniqueness
125 0 : for( std::list< Link >::const_iterator it = m_aListeners.begin(); it != m_aListeners.end(); ++it )
126 : {
127 0 : if( *it == i_rLink )
128 0 : return;
129 : }
130 0 : m_aListeners.push_back( i_rLink );
131 : }
132 :
133 0 : void VclEventListeners2::removeListener( const Link& i_rLink )
134 : {
135 0 : size_t n = m_aIterators.size();
136 0 : for( size_t i = 0; i < n; i++ )
137 : {
138 0 : if( m_aIterators[i].m_aIt != m_aListeners.end() && *m_aIterators[i].m_aIt == i_rLink )
139 : {
140 0 : m_aIterators[i].m_bWasInvalidated = true;
141 0 : ++m_aIterators[i].m_aIt;
142 : }
143 : }
144 0 : m_aListeners.remove( i_rLink );
145 0 : }
146 :
147 0 : void VclEventListeners2::callListeners( VclSimpleEvent* i_pEvent )
148 : {
149 0 : vcl::DeletionListener aDel( this );
150 :
151 0 : m_aIterators.push_back(ListenerIt(m_aListeners.begin()));
152 0 : size_t nIndex = m_aIterators.size() - 1;
153 0 : while( ! aDel.isDeleted() && m_aIterators[ nIndex ].m_aIt != m_aListeners.end() )
154 : {
155 0 : m_aIterators[ nIndex ].m_aIt->Call( i_pEvent );
156 0 : if( m_aIterators[ nIndex ].m_bWasInvalidated )
157 : // check if the current element was removed and the iterator increased in the meantime
158 0 : m_aIterators[ nIndex ].m_bWasInvalidated = false;
159 : else
160 0 : ++m_aIterators[ nIndex ].m_aIt;
161 : }
162 0 : m_aIterators.pop_back();
163 0 : }
164 :
165 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|