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