Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <svl/listener.hxx>
22 : #include <svl/listeneriter.hxx>
23 : #include <svl/broadcast.hxx>
24 : #include <svl/smplhint.hxx>
25 :
26 :
27 : //====================================================================
28 0 : TYPEINIT0(SvtBroadcaster);
29 :
30 : //====================================================================
31 :
32 : // simple ctor of class SvtBroadcaster
33 :
34 6201 : SvtBroadcaster::SvtBroadcaster()
35 6201 : : pRoot( 0 )
36 : {
37 6201 : }
38 :
39 : //--------------------------------------------------------------------
40 :
41 : // copy ctor of class SvtBroadcaster
42 :
43 0 : SvtBroadcaster::SvtBroadcaster( const SvtBroadcaster &rBC )
44 0 : : pRoot( 0 )
45 : {
46 0 : SvtListenerIter aIter( (SvtBroadcaster&)rBC );
47 0 : SvtListener* pLast = aIter.GoStart();
48 0 : if( pLast )
49 0 : do {
50 0 : pLast->StartListening( *this );
51 0 : } while( 0 != ( pLast = aIter.GoNext() ));
52 0 : }
53 :
54 : //--------------------------------------------------------------------
55 :
56 : // unregister all listeners
57 :
58 8679 : SvtBroadcaster::~SvtBroadcaster()
59 : {
60 5166 : Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
61 :
62 5166 : SvtListenerIter aIter( *this );
63 5166 : SvtListener* pLast = aIter.GoStart();
64 5166 : if( pLast )
65 806 : do {
66 2881 : pLast->EndListening( *this );
67 2881 : if( !HasListeners() ) // all gone ??
68 2075 : break;
69 5166 : } while( 0 != ( pLast = aIter.GoNext() ));
70 8679 : }
71 :
72 : //--------------------------------------------------------------------
73 :
74 : // broadcast immedeately
75 :
76 5357 : void SvtBroadcaster::Broadcast( const SfxHint &rHint )
77 : {
78 : // is anybody to notify?
79 5357 : if( HasListeners() /* && !IsModifyLocked()*/ )
80 : {
81 : // LockModify();
82 : // bInModify = sal_True;
83 :
84 2223 : SvtListenerIter aIter( *this );
85 2223 : SvtListener* pLast = aIter.GoStart();
86 2223 : if( pLast )
87 3308 : do {
88 3309 : pLast->Notify( *this, rHint );
89 3309 : if( !HasListeners() ) // all gone ??
90 1 : break;
91 2223 : } while( 0 != ( pLast = aIter.GoNext() ));
92 :
93 : // bInModify = sal_False;
94 : // UnlockModify();
95 : }
96 5357 : }
97 :
98 : //--------------------------------------------------------------------
99 :
100 :
101 : // called, if no more listeners exists
102 :
103 5070 : void SvtBroadcaster::ListenersGone()
104 : {
105 5070 : }
106 :
107 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|