Update ooo320-m1
[ooovba.git] / svtools / source / notify / listeneriter.cxx
blob96bc46ec79a8615b1235e5199e25fb41a27e8a90
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: listeneriter.cxx,v $
10 * $Revision: 1.5 $
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"
33 #ifndef GCC
34 #endif
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 )
45 : rRoot( rBrdcst )
47 // hinten einketten!
48 pNxtIter = 0;
49 if( pListenerIters )
51 SvtListenerIter* pTmp = pListenerIters;
52 while( pTmp->pNxtIter )
53 pTmp = pTmp->pNxtIter;
54 pTmp->pNxtIter = this;
56 else
57 pListenerIters = this;
59 pAkt = rRoot.pRoot;
60 pDelNext = pAkt;
65 SvtListenerIter::~SvtListenerIter()
67 if( pListenerIters )
69 if( pListenerIters == this )
70 pListenerIters = pNxtIter;
71 else
73 SvtListenerIter* pTmp = pListenerIters;
74 while( pTmp->pNxtIter != this )
75 if( 0 == ( pTmp = pTmp->pNxtIter ) )
76 return ;
77 pTmp->pNxtIter = pNxtIter;
82 void SvtListenerIter::RemoveListener( SvtListenerBase& rDel,
83 SvtListenerBase* pNext )
85 // Update the ListenerIter
86 SvtListenerIter* pTmp = pListenerIters;
87 while( pTmp )
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();
100 pDelNext = pAkt;
102 else
103 pAkt = pDelNext;
104 return pAkt ? pAkt->GetListener() : 0;
108 SvtListener* SvtListenerIter::GoPrev()
110 if( pDelNext == pAkt )
111 pAkt = pAkt->GetLeft();
112 else
113 pAkt = pDelNext->GetLeft();
114 pDelNext = pAkt;
115 return pAkt ? pAkt->GetListener() : 0;
119 SvtListener* SvtListenerIter::GoStart() // zum Anfang des Baums
121 pAkt = rRoot.pRoot;
122 if( pAkt )
123 while( pAkt->GetLeft() )
124 pAkt = pAkt->GetLeft();
125 pDelNext = pAkt;
126 return pAkt ? pAkt->GetListener() : 0;
130 SvtListener* SvtListenerIter::GoEnd() // zum End des Baums
132 pAkt = pDelNext;
133 if( !pAkt )
134 pAkt = rRoot.pRoot;
135 if( pAkt )
136 while( pAkt->GetRight() )
137 pAkt = pAkt->GetRight();
138 pDelNext = pAkt;
139 return pAkt ? pAkt->GetListener() : 0;
144 SvtListener* SvtListenerIter::First( TypeId nType )
146 aSrchId = nType;
147 GoStart();
148 if( pAkt )
149 do {
150 if( pAkt->GetListener()->IsA( aSrchId ) )
151 break;
153 if( pDelNext == pAkt )
155 pAkt = pAkt->GetRight();
156 pDelNext = pAkt;
158 else
159 pAkt = pDelNext;
161 } while( pAkt );
162 return pAkt ? pAkt->GetListener() : 0;
166 SvtListener* SvtListenerIter::Next()
168 do {
169 // erstmal zum naechsten
170 if( pDelNext == pAkt )
172 pAkt = pAkt->GetRight();
173 pDelNext = pAkt;
175 else
176 pAkt = pDelNext;
178 if( pAkt && pAkt->GetListener()->IsA( aSrchId ) )
179 break;
180 } while( pAkt );
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;