xref: /trunk/main/svl/source/notify/broadcast.cxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svl.hxx"
30 
31 #ifndef GCC
32 #endif
33 #include <tools/debug.hxx>
34 
35 #include <svl/listener.hxx>
36 #include <svl/listeneriter.hxx>
37 #include <svl/broadcast.hxx>
38 #include <svl/smplhint.hxx>
39 
40 
41 //====================================================================
42 TYPEINIT0(SvtBroadcaster);
43 
44 //====================================================================
45 
46 // simple ctor of class SvtBroadcaster
47 
48 SvtBroadcaster::SvtBroadcaster()
49     : pRoot( 0 )
50 {
51 }
52 
53 //--------------------------------------------------------------------
54 
55 // copy ctor of class SvtBroadcaster
56 
57 SvtBroadcaster::SvtBroadcaster( const SvtBroadcaster &rBC )
58     : pRoot( 0 )
59 {
60     SvtListenerIter aIter( (SvtBroadcaster&)rBC );
61     SvtListener* pLast = aIter.GoStart();
62     if( pLast )
63         do {
64             pLast->StartListening( *this );
65         } while( 0 != ( pLast = aIter.GoNext() ));
66 }
67 
68 //--------------------------------------------------------------------
69 
70 // unregister all listeners
71 
72 SvtBroadcaster::~SvtBroadcaster()
73 {
74     Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
75 
76     SvtListenerIter aIter( *this );
77     SvtListener* pLast = aIter.GoStart();
78     if( pLast )
79         do {
80             pLast->EndListening( *this );
81             if( !HasListeners() )       // all gone ??
82                 break;
83         } while( 0 != ( pLast = aIter.GoNext() ));
84 }
85 
86 //--------------------------------------------------------------------
87 
88 // broadcast immedeately
89 
90 void SvtBroadcaster::Broadcast( const SfxHint &rHint )
91 {
92     // is anybody to notify?
93     if( HasListeners() /* && !IsModifyLocked()*/ )
94     {
95 //      LockModify();
96 //      bInModify = sal_True;
97 
98         SvtListenerIter aIter( *this );
99         SvtListener* pLast = aIter.GoStart();
100         if( pLast )
101             do {
102                 pLast->Notify( *this, rHint );
103                 if( !HasListeners() )       // all gone ??
104                     break;
105             } while( 0 != ( pLast = aIter.GoNext() ));
106 
107 //      bInModify = sal_False;
108 //      UnlockModify();
109     }
110 }
111 
112 //--------------------------------------------------------------------
113 
114 
115 // called, if no more listeners exists
116 
117 void SvtBroadcaster::ListenersGone()
118 {
119 }
120 
121 //--------------------------------------------------------------------
122 
123 // forward a notification to all registered listeners
124 
125 void SvtBroadcaster::Forward( SvtBroadcaster& rBC, const SfxHint& rHint )
126 {
127     // is anybody to notify?
128     if( rBC.HasListeners() /* && !IsModifyLocked()*/ )
129     {
130 //      LockModify();
131 //      bInModify = sal_True;
132 
133         SvtListenerIter aIter( rBC );
134         SvtListener* pLast = aIter.GoStart();
135         if( pLast )
136             do {
137                 pLast->Notify( rBC, rHint );
138                 if( !rBC.HasListeners() )       // all gone ??
139                     break;
140             } while( 0 != ( pLast = aIter.GoNext() ));
141 
142 //      bInModify = sal_False;
143 //      UnlockModify();
144     }
145 }
146 
147 
148 
149