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