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: listener.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"
37 #include <tools/debug.hxx>
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()
56 //--------------------------------------------------------------------
58 // copy ctor of class SvtListener
60 SvtListener::SvtListener( const SvtListener
&rListener
)
63 SvtListenerBase
* pLst
= rListener
.pBrdCastLst
;
66 new SvtListenerBase( *this, *pLst
->GetBroadcaster() );
67 pLst
= pLst
->GetNext();
70 //--------------------------------------------------------------------
72 // unregisteres the SvtListener from its SvtBroadcasters
74 SvtListener::~SvtListener()
79 //--------------------------------------------------------------------
81 // registeres at a specific SvtBroadcaster
83 BOOL
SvtListener::StartListening( SvtBroadcaster
& rBroadcaster
)
85 const SvtListenerBase
* pLst
= pBrdCastLst
;
88 if( &rBroadcaster
== pLst
->GetBroadcaster() )
90 // double, than return
93 pLst
= pLst
->GetNext();
95 new SvtListenerBase( *this, rBroadcaster
);
99 //--------------------------------------------------------------------
101 // unregisteres at a specific SvtBroadcaster
103 BOOL
SvtListener::EndListening( SvtBroadcaster
& rBroadcaster
)
105 SvtListenerBase
*pLst
= pBrdCastLst
, *pPrev
= pLst
;
108 if( &rBroadcaster
== pLst
->GetBroadcaster() )
110 if( pBrdCastLst
== pLst
)
111 pBrdCastLst
= pLst
->GetNext();
113 pPrev
->SetNext( pLst
->GetNext() );
119 pLst
= pLst
->GetNext();
124 //--------------------------------------------------------------------
126 // unregisteres all Broadcasters
128 void SvtListener::EndListeningAll()
130 SvtListenerBase
*pLst
= pBrdCastLst
;
133 SvtListenerBase
*pDel
= pLst
;
134 pLst
= pLst
->GetNext();
141 //--------------------------------------------------------------------
143 BOOL
SvtListener::IsListening( SvtBroadcaster
& rBroadcaster
) const
145 const SvtListenerBase
*pLst
= pBrdCastLst
;
148 if( &rBroadcaster
== pLst
->GetBroadcaster() )
150 pLst
= pLst
->GetNext();
155 //--------------------------------------------------------------------
157 // base implementation of notification handler
159 void SvtListener::Notify( SvtBroadcaster
&
165 DBG_ASSERT( IsListening( rBC
),
166 "notification from unregistered broadcaster" );