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