xref: /aoo42x/main/svl/source/notify/broadcast.cxx (revision 40df464e)
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 #ifndef GCC
28 #endif
29 #include <tools/debug.hxx>
30 
31 #include <svl/listener.hxx>
32 #include <svl/listeneriter.hxx>
33 #include <svl/broadcast.hxx>
34 #include <svl/smplhint.hxx>
35 
36 
37 //====================================================================
38 TYPEINIT0(SvtBroadcaster);
39 
40 //====================================================================
41 
42 // simple ctor of class SvtBroadcaster
43 
SvtBroadcaster()44 SvtBroadcaster::SvtBroadcaster()
45 	: pRoot( 0 )
46 {
47 }
48 
49 //--------------------------------------------------------------------
50 
51 // copy ctor of class SvtBroadcaster
52 
SvtBroadcaster(const SvtBroadcaster & rBC)53 SvtBroadcaster::SvtBroadcaster( const SvtBroadcaster &rBC )
54 	: pRoot( 0 )
55 {
56 	SvtListenerIter aIter( (SvtBroadcaster&)rBC );
57 	SvtListener* pLast = aIter.GoStart();
58 	if( pLast )
59 		do {
60 			pLast->StartListening( *this );
61 		} while( 0 != ( pLast = aIter.GoNext() ));
62 }
63 
64 //--------------------------------------------------------------------
65 
66 // unregister all listeners
67 
~SvtBroadcaster()68 SvtBroadcaster::~SvtBroadcaster()
69 {
70 	Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
71 
72 	SvtListenerIter aIter( *this );
73 	SvtListener* pLast = aIter.GoStart();
74 	if( pLast )
75 		do {
76 			pLast->EndListening( *this );
77 			if( !HasListeners() )		// all gone ??
78 				break;
79 		} while( 0 != ( pLast = aIter.GoNext() ));
80 }
81 
82 //--------------------------------------------------------------------
83 
84 // broadcast immedeately
85 
Broadcast(const SfxHint & rHint)86 void SvtBroadcaster::Broadcast( const SfxHint &rHint )
87 {
88 	// is anybody to notify?
89 	if( HasListeners() /* && !IsModifyLocked()*/ )
90 	{
91 //		LockModify();
92 //		bInModify = sal_True;
93 
94 		SvtListenerIter aIter( *this );
95 		SvtListener* pLast = aIter.GoStart();
96 		if( pLast )
97 			do {
98 				pLast->Notify( *this, rHint );
99 				if( !HasListeners() )		// all gone ??
100 					break;
101 			} while( 0 != ( pLast = aIter.GoNext() ));
102 
103 //		bInModify = sal_False;
104 //		UnlockModify();
105 	}
106 }
107 
108 //--------------------------------------------------------------------
109 
110 
111 // called, if no more listeners exists
112 
ListenersGone()113 void SvtBroadcaster::ListenersGone()
114 {
115 }
116 
117 //--------------------------------------------------------------------
118 
119 // forward a notification to all registered listeners
120 
Forward(SvtBroadcaster & rBC,const SfxHint & rHint)121 void SvtBroadcaster::Forward( SvtBroadcaster& rBC, const SfxHint& rHint )
122 {
123 	// is anybody to notify?
124 	if( rBC.HasListeners() /* && !IsModifyLocked()*/ )
125 	{
126 //		LockModify();
127 //		bInModify = sal_True;
128 
129 		SvtListenerIter aIter( rBC );
130 		SvtListener* pLast = aIter.GoStart();
131 		if( pLast )
132 			do {
133 				pLast->Notify( rBC, rHint );
134 				if( !rBC.HasListeners() )		// all gone ??
135 					break;
136 			} while( 0 != ( pLast = aIter.GoNext() ));
137 
138 //		bInModify = sal_False;
139 //		UnlockModify();
140 	}
141 }
142 
143 
144 
145