1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: listeneriter.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
35 #include <tools/debug.hxx>
37 #include "listenerbase.hxx"
38 #include "listeneriter.hxx"
39 #include "broadcast.hxx"
40 #include "listener.hxx"
42 SvtListenerIter
* SvtListenerIter::pListenerIters
= 0;
44 SvtListenerIter::SvtListenerIter( SvtBroadcaster
& rBrdcst
)
51 SvtListenerIter
* pTmp
= pListenerIters
;
52 while( pTmp
->pNxtIter
)
53 pTmp
= pTmp
->pNxtIter
;
54 pTmp
->pNxtIter
= this;
57 pListenerIters
= this;
65 SvtListenerIter::~SvtListenerIter()
69 if( pListenerIters
== this )
70 pListenerIters
= pNxtIter
;
73 SvtListenerIter
* pTmp
= pListenerIters
;
74 while( pTmp
->pNxtIter
!= this )
75 if( 0 == ( pTmp
= pTmp
->pNxtIter
) )
77 pTmp
->pNxtIter
= pNxtIter
;
82 void SvtListenerIter::RemoveListener( SvtListenerBase
& rDel
,
83 SvtListenerBase
* pNext
)
85 // Update the ListenerIter
86 SvtListenerIter
* pTmp
= pListenerIters
;
89 if( pTmp
->pAkt
== &rDel
|| pTmp
->pDelNext
== &rDel
)
90 pTmp
->pDelNext
= pNext
;
91 pTmp
= pTmp
->pNxtIter
;
95 SvtListener
* SvtListenerIter::GoNext()
97 if( pDelNext
== pAkt
)
99 pAkt
= pAkt
->GetRight();
104 return pAkt
? pAkt
->GetListener() : 0;
108 SvtListener
* SvtListenerIter::GoPrev()
110 if( pDelNext
== pAkt
)
111 pAkt
= pAkt
->GetLeft();
113 pAkt
= pDelNext
->GetLeft();
115 return pAkt
? pAkt
->GetListener() : 0;
119 SvtListener
* SvtListenerIter::GoStart() // zum Anfang des Baums
123 while( pAkt
->GetLeft() )
124 pAkt
= pAkt
->GetLeft();
126 return pAkt
? pAkt
->GetListener() : 0;
130 SvtListener
* SvtListenerIter::GoEnd() // zum End des Baums
136 while( pAkt
->GetRight() )
137 pAkt
= pAkt
->GetRight();
139 return pAkt
? pAkt
->GetListener() : 0;
144 SvtListener
* SvtListenerIter::First( TypeId nType
)
150 if( pAkt
->GetListener()->IsA( aSrchId
) )
153 if( pDelNext
== pAkt
)
155 pAkt
= pAkt
->GetRight();
162 return pAkt
? pAkt
->GetListener() : 0;
166 SvtListener
* SvtListenerIter::Next()
169 // erstmal zum naechsten
170 if( pDelNext
== pAkt
)
172 pAkt
= pAkt
->GetRight();
178 if( pAkt
&& pAkt
->GetListener()->IsA( aSrchId
) )
181 return pAkt
? pAkt
->GetListener() : 0;
185 SvtListener
* SvtListenerIter::GoRoot() // wieder ab Root anfangen
187 pDelNext
= pAkt
= rRoot
.pRoot
;
188 return pAkt
? pAkt
->GetListener() : 0;
191 SvtListener
* SvtListenerIter::GetCurr() const // returns the current
193 return pDelNext
? pDelNext
->GetListener() : 0;