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 6568 : SvtListener::SvtListener()
35 6568 : : pBrdCastLst( 0 )
36 : {
37 6568 : }
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 6278 : SvtListener::~SvtListener()
57 : {
58 6278 : EndListeningAll();
59 6278 : }
60 :
61 : //--------------------------------------------------------------------
62 :
63 : // registeres at a specific SvtBroadcaster
64 :
65 14968 : sal_Bool SvtListener::StartListening( SvtBroadcaster& rBroadcaster )
66 : {
67 14968 : const SvtListenerBase* pLst = pBrdCastLst;
68 54310 : while( pLst )
69 : {
70 25096 : if( &rBroadcaster == pLst->GetBroadcaster() )
71 : {
72 : // double, than return
73 722 : return sal_False;
74 : }
75 24374 : pLst = pLst->GetNext();
76 : }
77 14246 : new SvtListenerBase( *this, rBroadcaster );
78 14246 : return sal_True;
79 : }
80 :
81 : //--------------------------------------------------------------------
82 :
83 : // unregisteres at a specific SvtBroadcaster
84 :
85 6946 : sal_Bool SvtListener::EndListening( SvtBroadcaster& rBroadcaster )
86 : {
87 6946 : SvtListenerBase *pLst = pBrdCastLst, *pPrev = pLst;
88 25062 : while( pLst )
89 : {
90 17684 : if( &rBroadcaster == pLst->GetBroadcaster() )
91 : {
92 6514 : if( pBrdCastLst == pLst )
93 2652 : pBrdCastLst = pLst->GetNext();
94 : else
95 3862 : pPrev->SetNext( pLst->GetNext() );
96 :
97 6514 : delete pLst;
98 6514 : return sal_True;
99 : }
100 11170 : pPrev = pLst;
101 11170 : pLst = pLst->GetNext();
102 : }
103 432 : return sal_False;
104 : }
105 :
106 : //--------------------------------------------------------------------
107 :
108 : // unregisteres all Broadcasters
109 :
110 6442 : void SvtListener::EndListeningAll()
111 : {
112 6442 : SvtListenerBase *pLst = pBrdCastLst;
113 20294 : while( pLst )
114 : {
115 7410 : SvtListenerBase *pDel = pLst;
116 7410 : pLst = pLst->GetNext();
117 :
118 7410 : delete pDel;
119 : }
120 6442 : pBrdCastLst = 0;
121 6442 : }
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: */
|