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