Branch data 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 : 15082 : SvtBroadcaster::SvtBroadcaster()
35 : 15082 : : pRoot( 0 )
36 : : {
37 : 15082 : }
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 : 14309 : SvtBroadcaster::~SvtBroadcaster()
59 : : {
60 [ + - ][ + - ]: 10257 : Broadcast( SfxSimpleHint(SFX_HINT_DYING) );
[ + - ]
61 : :
62 [ + - ]: 10257 : SvtListenerIter aIter( *this );
63 [ + - ]: 10257 : SvtListener* pLast = aIter.GoStart();
64 [ + + ]: 10257 : if( pLast )
65 [ + - ][ + - ]: 12222 : do {
66 [ + - ]: 12222 : pLast->EndListening( *this );
67 [ + + ]: 12222 : if( !HasListeners() ) // all gone ??
68 : 8191 : break;
69 [ + - ]: 10257 : } while( 0 != ( pLast = aIter.GoNext() ));
70 [ - + ]: 14309 : }
71 : :
72 : : //--------------------------------------------------------------------
73 : :
74 : : // broadcast immedeately
75 : :
76 : 11524 : void SvtBroadcaster::Broadcast( const SfxHint &rHint )
77 : : {
78 : : // is anybody to notify?
79 [ + + ]: 11524 : if( HasListeners() /* && !IsModifyLocked()*/ )
80 : : {
81 : : // LockModify();
82 : : // bInModify = sal_True;
83 : :
84 [ + - ]: 9436 : SvtListenerIter aIter( *this );
85 [ + - ]: 9436 : SvtListener* pLast = aIter.GoStart();
86 [ + - ]: 9436 : if( pLast )
87 [ + - ][ + + ]: 16213 : do {
88 [ + - ]: 16213 : pLast->Notify( *this, rHint );
89 [ + + ]: 16213 : if( !HasListeners() ) // all gone ??
90 : 5 : break;
91 [ + - ]: 9436 : } while( 0 != ( pLast = aIter.GoNext() ));
92 : :
93 : : // bInModify = sal_False;
94 : : // UnlockModify();
95 : : }
96 : 11524 : }
97 : :
98 : : //--------------------------------------------------------------------
99 : :
100 : :
101 : : // called, if no more listeners exists
102 : :
103 : 12643 : void SvtBroadcaster::ListenersGone()
104 : : {
105 : 12643 : }
106 : :
107 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|