xref: /aoo42x/main/vcl/source/app/vclevent.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include "vcl/vclevent.hxx"
32 
33 #include "svdata.hxx"
34 
35 #include <com/sun/star/accessibility/XAccessible.hpp>
36 
37 using ::com::sun::star::uno::Reference;
38 using ::com::sun::star::accessibility::XAccessible;
39 
40 TYPEINIT0(VclSimpleEvent);
41 TYPEINIT1(VclWindowEvent, VclSimpleEvent);
42 TYPEINIT1(VclMenuEvent, VclSimpleEvent);
43 
44 VclAccessibleEvent::VclAccessibleEvent( sal_uLong n, const Reference<XAccessible>& rxAccessible ) :
45     VclSimpleEvent(n),
46     mxAccessible(rxAccessible)
47 {
48 }
49 
50 VclAccessibleEvent::~VclAccessibleEvent()
51 {
52 }
53 
54 Reference<XAccessible> VclAccessibleEvent::GetAccessible() const
55 {
56     return mxAccessible;
57 }
58 
59 void VclEventListeners::Call( VclSimpleEvent* pEvent ) const
60 {
61     // Copy the list, because this can be destroyed when calling a Link...
62     std::list<Link> aCopy( *this );
63 	std::list<Link>::iterator aIter( aCopy.begin() );
64     if( pEvent->IsA( VclWindowEvent::StaticType() ) )
65     {
66         VclWindowEvent* pWinEvent = static_cast<VclWindowEvent*>(pEvent);
67         ImplDelData aDel( pWinEvent->GetWindow() );
68         while ( aIter != aCopy.end() && ! aDel.IsDead() )
69         {
70             (*aIter).Call( pEvent );
71             aIter++;
72         }
73     }
74     else
75     {
76         while ( aIter != aCopy.end() )
77         {
78             (*aIter).Call( pEvent );
79             aIter++;
80         }
81     }
82 }
83 
84 sal_Bool VclEventListeners::Process( VclSimpleEvent* pEvent ) const
85 {
86     sal_Bool bProcessed = sal_False;
87     // Copy the list, because this can be destroyed when calling a Link...
88     std::list<Link> aCopy( *this );
89 	std::list<Link>::iterator aIter( aCopy.begin() );
90 	while ( aIter != aCopy.end() )
91 	{
92 	    if( (*aIter).Call( pEvent ) != 0 )
93         {
94             bProcessed = sal_True;
95             break;
96         }
97 		aIter++;
98 	}
99     return bProcessed;
100 }
101 
102 VclEventListeners2::VclEventListeners2()
103 {
104 }
105 
106 VclEventListeners2::~VclEventListeners2()
107 {
108 }
109 
110 void VclEventListeners2::addListener( const Link& i_rLink )
111 {
112     // ensure uniqueness
113     for( std::list< Link >::const_iterator it = m_aListeners.begin(); it != m_aListeners.end(); ++it )
114     {
115         if( *it == i_rLink )
116             return;
117     }
118     m_aListeners.push_back( i_rLink );
119 }
120 
121 void VclEventListeners2::removeListener( const Link& i_rLink )
122 {
123     size_t n = m_aIterators.size();
124     for( size_t i = 0; i < n; i++ )
125     {
126         if( m_aIterators[i].m_aIt != m_aListeners.end() && *m_aIterators[i].m_aIt == i_rLink )
127         {
128             m_aIterators[i].m_bWasInvalidated = true;
129             ++m_aIterators[i].m_aIt;
130         }
131     }
132     m_aListeners.remove( i_rLink );
133 }
134 
135 void VclEventListeners2::callListeners( VclSimpleEvent* i_pEvent )
136 {
137     vcl::DeletionListener aDel( this );
138 
139     m_aIterators.push_back(ListenerIt(m_aListeners.begin()));
140     size_t nIndex = m_aIterators.size() - 1;
141     while( ! aDel.isDeleted() && m_aIterators[ nIndex ].m_aIt != m_aListeners.end() )
142     {
143         m_aIterators[ nIndex ].m_aIt->Call( i_pEvent );
144         if( m_aIterators[ nIndex ].m_bWasInvalidated )
145             // check if the current element was removed and the iterator increased in the meantime
146             m_aIterators[ nIndex ].m_bWasInvalidated = false;
147         else
148             ++m_aIterators[ nIndex ].m_aIt;
149     }
150     m_aIterators.pop_back();
151 }
152 
153