xref: /aoo4110/main/vcl/source/app/vclevent.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_vcl.hxx"
26 
27 #include "vcl/vclevent.hxx"
28 
29 #include "svdata.hxx"
30 
31 #include <com/sun/star/accessibility/XAccessible.hpp>
32 
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::accessibility::XAccessible;
35 
36 TYPEINIT0(VclSimpleEvent);
37 TYPEINIT1(VclWindowEvent, VclSimpleEvent);
38 TYPEINIT1(VclMenuEvent, VclSimpleEvent);
39 
VclAccessibleEvent(sal_uLong n,const Reference<XAccessible> & rxAccessible)40 VclAccessibleEvent::VclAccessibleEvent( sal_uLong n, const Reference<XAccessible>& rxAccessible ) :
41     VclSimpleEvent(n),
42     mxAccessible(rxAccessible)
43 {
44 }
45 
~VclAccessibleEvent()46 VclAccessibleEvent::~VclAccessibleEvent()
47 {
48 }
49 
GetAccessible() const50 Reference<XAccessible> VclAccessibleEvent::GetAccessible() const
51 {
52     return mxAccessible;
53 }
54 
Call(VclSimpleEvent * pEvent) const55 void VclEventListeners::Call( VclSimpleEvent* pEvent ) const
56 {
57     // Copy the list, because this can be destroyed when calling a Link...
58     std::list<Link> aCopy( *this );
59 	std::list<Link>::iterator aIter( aCopy.begin() );
60     if( pEvent->IsA( VclWindowEvent::StaticType() ) )
61     {
62         VclWindowEvent* pWinEvent = static_cast<VclWindowEvent*>(pEvent);
63         ImplDelData aDel( pWinEvent->GetWindow() );
64         while ( aIter != aCopy.end() && ! aDel.IsDead() )
65         {
66             (*aIter).Call( pEvent );
67             aIter++;
68         }
69     }
70     else
71     {
72         while ( aIter != aCopy.end() )
73         {
74             (*aIter).Call( pEvent );
75             aIter++;
76         }
77     }
78 }
79 
Process(VclSimpleEvent * pEvent) const80 sal_Bool VclEventListeners::Process( VclSimpleEvent* pEvent ) const
81 {
82     sal_Bool bProcessed = sal_False;
83     // Copy the list, because this can be destroyed when calling a Link...
84     std::list<Link> aCopy( *this );
85 	std::list<Link>::iterator aIter( aCopy.begin() );
86 	while ( aIter != aCopy.end() )
87 	{
88 	    if( (*aIter).Call( pEvent ) != 0 )
89         {
90             bProcessed = sal_True;
91             break;
92         }
93 		aIter++;
94 	}
95     return bProcessed;
96 }
97 
VclEventListeners2()98 VclEventListeners2::VclEventListeners2()
99 {
100 }
101 
~VclEventListeners2()102 VclEventListeners2::~VclEventListeners2()
103 {
104 }
105 
addListener(const Link & i_rLink)106 void VclEventListeners2::addListener( const Link& i_rLink )
107 {
108     // ensure uniqueness
109     for( std::list< Link >::const_iterator it = m_aListeners.begin(); it != m_aListeners.end(); ++it )
110     {
111         if( *it == i_rLink )
112             return;
113     }
114     m_aListeners.push_back( i_rLink );
115 }
116 
removeListener(const Link & i_rLink)117 void VclEventListeners2::removeListener( const Link& i_rLink )
118 {
119     size_t n = m_aIterators.size();
120     for( size_t i = 0; i < n; i++ )
121     {
122         if( m_aIterators[i].m_aIt != m_aListeners.end() && *m_aIterators[i].m_aIt == i_rLink )
123         {
124             m_aIterators[i].m_bWasInvalidated = true;
125             ++m_aIterators[i].m_aIt;
126         }
127     }
128     m_aListeners.remove( i_rLink );
129 }
130 
callListeners(VclSimpleEvent * i_pEvent)131 void VclEventListeners2::callListeners( VclSimpleEvent* i_pEvent )
132 {
133     vcl::DeletionListener aDel( this );
134 
135     m_aIterators.push_back(ListenerIt(m_aListeners.begin()));
136     size_t nIndex = m_aIterators.size() - 1;
137     while( ! aDel.isDeleted() && m_aIterators[ nIndex ].m_aIt != m_aListeners.end() )
138     {
139         m_aIterators[ nIndex ].m_aIt->Call( i_pEvent );
140         if( m_aIterators[ nIndex ].m_bWasInvalidated )
141             // check if the current element was removed and the iterator increased in the meantime
142             m_aIterators[ nIndex ].m_bWasInvalidated = false;
143         else
144             ++m_aIterators[ nIndex ].m_aIt;
145     }
146     m_aIterators.pop_back();
147 }
148 
149