xref: /aoo4110/main/svl/source/notify/listener.cxx (revision b1cdbd2c)
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 
27 #include <tools/debug.hxx>
28 #include <svl/broadcast.hxx>
29 #include <svl/listener.hxx>
30 #include "listenerbase.hxx"
31 #include <svl/listeneriter.hxx>
32 
33 
34 //====================================================================
35 TYPEINIT0(SvtListener);
36 
37 //====================================================================
38 // simple ctor of class SvtListener
39 
SvtListener()40 SvtListener::SvtListener()
41 	: pBrdCastLst( 0 )
42 {
43 }
44 //--------------------------------------------------------------------
45 
46 // copy ctor of class SvtListener
47 
SvtListener(const SvtListener & rListener)48 SvtListener::SvtListener( const SvtListener &rListener )
49 	: pBrdCastLst( 0 )
50 {
51 	SvtListenerBase* pLst = rListener.pBrdCastLst;
52 	while( pLst )
53 	{
54 		new SvtListenerBase( *this, *pLst->GetBroadcaster() );
55 		pLst = pLst->GetNext();
56 	}
57 }
58 //--------------------------------------------------------------------
59 
60 // unregisteres the SvtListener from its SvtBroadcasters
61 
~SvtListener()62 SvtListener::~SvtListener()
63 {
64 	EndListeningAll();
65 }
66 
67 //--------------------------------------------------------------------
68 
69 // registeres at a specific SvtBroadcaster
70 
StartListening(SvtBroadcaster & rBroadcaster)71 sal_Bool SvtListener::StartListening( SvtBroadcaster& rBroadcaster )
72 {
73 	const SvtListenerBase* pLst = pBrdCastLst;
74 	while( pLst )
75 	{
76 		if( &rBroadcaster == pLst->GetBroadcaster() )
77 		{
78 			// double, than return
79 			return sal_False;
80 		}
81 		pLst = pLst->GetNext();
82 	}
83 	new SvtListenerBase( *this, rBroadcaster );
84 	return sal_True;
85 }
86 
87 //--------------------------------------------------------------------
88 
89 // unregisteres at a specific SvtBroadcaster
90 
EndListening(SvtBroadcaster & rBroadcaster)91 sal_Bool SvtListener::EndListening( SvtBroadcaster& rBroadcaster )
92 {
93 	SvtListenerBase *pLst = pBrdCastLst, *pPrev = pLst;
94 	while( pLst )
95 	{
96 		if( &rBroadcaster == pLst->GetBroadcaster() )
97 		{
98 			if( pBrdCastLst == pLst )
99 				pBrdCastLst = pLst->GetNext();
100 			else
101 				pPrev->SetNext( pLst->GetNext() );
102 
103 			delete pLst;
104 			return sal_True;
105 		}
106 		pPrev = pLst;
107 		pLst = pLst->GetNext();
108 	}
109 	return sal_False;
110 }
111 
112 //--------------------------------------------------------------------
113 
114 // unregisteres all Broadcasters
115 
EndListeningAll()116 void SvtListener::EndListeningAll()
117 {
118 	SvtListenerBase *pLst = pBrdCastLst;
119 	while( pLst )
120 	{
121 		SvtListenerBase *pDel = pLst;
122 		pLst = pLst->GetNext();
123 
124 		delete pDel;
125 	}
126 	pBrdCastLst = 0;
127 }
128 
129 //--------------------------------------------------------------------
130 
IsListening(SvtBroadcaster & rBroadcaster) const131 sal_Bool SvtListener::IsListening( SvtBroadcaster& rBroadcaster ) const
132 {
133 	const SvtListenerBase *pLst = pBrdCastLst;
134 	while( pLst )
135 	{
136 		if( &rBroadcaster == pLst->GetBroadcaster() )
137 			break;
138 		pLst = pLst->GetNext();
139 	}
140 	return 0 != pLst;
141 }
142 
143 //--------------------------------------------------------------------
144 
145 // base implementation of notification handler
146 
Notify(SvtBroadcaster & rBC,const SfxHint &)147 void SvtListener::Notify( SvtBroadcaster&
148 #ifdef DBG_UTIL
149 rBC
150 #endif
151 , const SfxHint& )
152 {
153 	DBG_ASSERT( IsListening( rBC ),
154 				"notification from unregistered broadcaster" );
155 }
156 
157 
158