1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svl.hxx" 26 #include <tools/debug.hxx> 27 28 #include "listenerbase.hxx" 29 #include <svl/listeneriter.hxx> 30 #include <svl/broadcast.hxx> 31 #include <svl/listener.hxx> 32 33 SvtListenerIter* SvtListenerIter::pListenerIters = 0; 34 SvtListenerIter(SvtBroadcaster & rBrdcst)35SvtListenerIter::SvtListenerIter( SvtBroadcaster& rBrdcst ) 36 : rRoot( rBrdcst ) 37 { 38 // hinten einketten! 39 pNxtIter = 0; 40 if( pListenerIters ) 41 { 42 SvtListenerIter* pTmp = pListenerIters; 43 while( pTmp->pNxtIter ) 44 pTmp = pTmp->pNxtIter; 45 pTmp->pNxtIter = this; 46 } 47 else 48 pListenerIters = this; 49 50 pAkt = rRoot.pRoot; 51 pDelNext = pAkt; 52 } 53 54 55 ~SvtListenerIter()56SvtListenerIter::~SvtListenerIter() 57 { 58 if( pListenerIters ) 59 { 60 if( pListenerIters == this ) 61 pListenerIters = pNxtIter; 62 else 63 { 64 SvtListenerIter* pTmp = pListenerIters; 65 while( pTmp->pNxtIter != this ) 66 if( 0 == ( pTmp = pTmp->pNxtIter ) ) 67 return ; 68 pTmp->pNxtIter = pNxtIter; 69 } 70 } 71 } 72 RemoveListener(SvtListenerBase & rDel,SvtListenerBase * pNext)73void SvtListenerIter::RemoveListener( SvtListenerBase& rDel, 74 SvtListenerBase* pNext ) 75 { 76 // Update the ListenerIter 77 SvtListenerIter* pTmp = pListenerIters; 78 while( pTmp ) 79 { 80 if( pTmp->pAkt == &rDel || pTmp->pDelNext == &rDel ) 81 pTmp->pDelNext = pNext; 82 pTmp = pTmp->pNxtIter; 83 } 84 } 85 GoNext()86SvtListener* SvtListenerIter::GoNext() 87 { 88 if( pDelNext == pAkt ) 89 { 90 pAkt = pAkt->GetRight(); 91 pDelNext = pAkt; 92 } 93 else 94 pAkt = pDelNext; 95 return pAkt ? pAkt->GetListener() : 0; 96 } 97 98 GoPrev()99SvtListener* SvtListenerIter::GoPrev() 100 { 101 if( pDelNext == pAkt ) 102 pAkt = pAkt->GetLeft(); 103 else 104 pAkt = pDelNext->GetLeft(); 105 pDelNext = pAkt; 106 return pAkt ? pAkt->GetListener() : 0; 107 } 108 109 GoStart()110SvtListener* SvtListenerIter::GoStart() // zum Anfang des Baums 111 { 112 pAkt = rRoot.pRoot; 113 if( pAkt ) 114 while( pAkt->GetLeft() ) 115 pAkt = pAkt->GetLeft(); 116 pDelNext = pAkt; 117 return pAkt ? pAkt->GetListener() : 0; 118 } 119 120 GoEnd()121SvtListener* SvtListenerIter::GoEnd() // zum End des Baums 122 { 123 pAkt = pDelNext; 124 if( !pAkt ) 125 pAkt = rRoot.pRoot; 126 if( pAkt ) 127 while( pAkt->GetRight() ) 128 pAkt = pAkt->GetRight(); 129 pDelNext = pAkt; 130 return pAkt ? pAkt->GetListener() : 0; 131 } 132 133 134 First(TypeId nType)135SvtListener* SvtListenerIter::First( TypeId nType ) 136 { 137 aSrchId = nType; 138 GoStart(); 139 if( pAkt ) 140 do { 141 if( pAkt->GetListener()->IsA( aSrchId ) ) 142 break; 143 144 if( pDelNext == pAkt ) 145 { 146 pAkt = pAkt->GetRight(); 147 pDelNext = pAkt; 148 } 149 else 150 pAkt = pDelNext; 151 152 } while( pAkt ); 153 return pAkt ? pAkt->GetListener() : 0; 154 } 155 156 Next()157SvtListener* SvtListenerIter::Next() 158 { 159 do { 160 // erstmal zum naechsten 161 if( pDelNext == pAkt ) 162 { 163 pAkt = pAkt->GetRight(); 164 pDelNext = pAkt; 165 } 166 else 167 pAkt = pDelNext; 168 169 if( pAkt && pAkt->GetListener()->IsA( aSrchId ) ) 170 break; 171 } while( pAkt ); 172 return pAkt ? pAkt->GetListener() : 0; 173 } 174 175 GoRoot()176SvtListener* SvtListenerIter::GoRoot() // wieder ab Root anfangen 177 { 178 pDelNext = pAkt = rRoot.pRoot; 179 return pAkt ? pAkt->GetListener() : 0; 180 } 181 GetCurr() const182SvtListener* SvtListenerIter::GetCurr() const // returns the current 183 { 184 return pDelNext ? pDelNext->GetListener() : 0; 185 } 186 187