Update ooo320-m1
[ooovba.git] / svtools / source / notify / listener.cxx
blobe57cd1d1c8505c13f69f8c565dd899c591995dcf
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: listener.cxx,v $
10 * $Revision: 1.6 $
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
36 #ifndef DEBUG_HXX
37 #include <tools/debug.hxx>
38 #endif
40 #include "broadcast.hxx"
41 #include "listener.hxx"
42 #include "listenerbase.hxx"
43 #include "listeneriter.hxx"
46 //====================================================================
47 TYPEINIT0(SvtListener);
49 //====================================================================
50 // simple ctor of class SvtListener
52 SvtListener::SvtListener()
53 : pBrdCastLst( 0 )
56 //--------------------------------------------------------------------
58 // copy ctor of class SvtListener
60 SvtListener::SvtListener( const SvtListener &rListener )
61 : pBrdCastLst( 0 )
63 SvtListenerBase* pLst = rListener.pBrdCastLst;
64 while( pLst )
66 new SvtListenerBase( *this, *pLst->GetBroadcaster() );
67 pLst = pLst->GetNext();
70 //--------------------------------------------------------------------
72 // unregisteres the SvtListener from its SvtBroadcasters
74 SvtListener::~SvtListener()
76 EndListeningAll();
79 //--------------------------------------------------------------------
81 // registeres at a specific SvtBroadcaster
83 BOOL SvtListener::StartListening( SvtBroadcaster& rBroadcaster )
85 const SvtListenerBase* pLst = pBrdCastLst;
86 while( pLst )
88 if( &rBroadcaster == pLst->GetBroadcaster() )
90 // double, than return
91 return FALSE;
93 pLst = pLst->GetNext();
95 new SvtListenerBase( *this, rBroadcaster );
96 return TRUE;
99 //--------------------------------------------------------------------
101 // unregisteres at a specific SvtBroadcaster
103 BOOL SvtListener::EndListening( SvtBroadcaster& rBroadcaster )
105 SvtListenerBase *pLst = pBrdCastLst, *pPrev = pLst;
106 while( pLst )
108 if( &rBroadcaster == pLst->GetBroadcaster() )
110 if( pBrdCastLst == pLst )
111 pBrdCastLst = pLst->GetNext();
112 else
113 pPrev->SetNext( pLst->GetNext() );
115 delete pLst;
116 return TRUE;
118 pPrev = pLst;
119 pLst = pLst->GetNext();
121 return FALSE;
124 //--------------------------------------------------------------------
126 // unregisteres all Broadcasters
128 void SvtListener::EndListeningAll()
130 SvtListenerBase *pLst = pBrdCastLst;
131 while( pLst )
133 SvtListenerBase *pDel = pLst;
134 pLst = pLst->GetNext();
136 delete pDel;
138 pBrdCastLst = 0;
141 //--------------------------------------------------------------------
143 BOOL SvtListener::IsListening( SvtBroadcaster& rBroadcaster ) const
145 const SvtListenerBase *pLst = pBrdCastLst;
146 while( pLst )
148 if( &rBroadcaster == pLst->GetBroadcaster() )
149 break;
150 pLst = pLst->GetNext();
152 return 0 != pLst;
155 //--------------------------------------------------------------------
157 // base implementation of notification handler
159 void SvtListener::Notify( SvtBroadcaster&
160 #ifdef DBG_UTIL
162 #endif
163 , const SfxHint& )
165 DBG_ASSERT( IsListening( rBC ),
166 "notification from unregistered broadcaster" );