xref: /aoo41x/main/svl/source/notify/listenerbase.cxx (revision 40df464e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svl.hxx"
26 
27 #include <tools/debug.hxx>
28 #include "listenerbase.hxx"
29 #include <svl/listeneriter.hxx>
30 #include <svl/listener.hxx>
31 #include <svl/broadcast.hxx>
32 
33 
SvtListenerBase(SvtListener & rLst,SvtBroadcaster & rBroadcaster)34 SvtListenerBase::SvtListenerBase( SvtListener& rLst,
35 								  SvtBroadcaster& rBroadcaster )
36 	: pLeft( 0 ), pRight( 0 ),
37 	pBroadcaster( &rBroadcaster ), pListener( &rLst )
38 {
39 	pNext = rLst.pBrdCastLst;
40 	rLst.pBrdCastLst = this;
41 
42 	if( pBroadcaster->pRoot )
43 	{
44 		// set ever behind the root
45 		pRight = pBroadcaster->pRoot->pRight;
46 		pBroadcaster->pRoot->pRight = this;
47 		this->pLeft = pBroadcaster->pRoot;
48 		if( pRight )
49 			pRight->pLeft = this;
50 	}
51 	else
52 		pBroadcaster->pRoot = this;
53 }
54 
~SvtListenerBase()55 SvtListenerBase::~SvtListenerBase()
56 {
57 	SvtListenerBase *pR = pRight, *pL = pLeft;
58 	if( pBroadcaster->pRoot )
59 		pBroadcaster->pRoot = pL ? pL : pR;
60 
61 	if( pL )
62 		pL->pRight = pR;
63 	if( pR )
64 		pR->pLeft = pL;
65 
66 	SvtListenerIter::RemoveListener( *this, pR );
67 
68 	if( !pBroadcaster->pRoot )
69 		pBroadcaster->ListenersGone();
70 }
71 
72 
73