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_sw.hxx"
26
27
28 #include <unoevtlstnr.hxx>
29 #include <tools/debug.hxx>
30 #include <com/sun/star/lang/EventObject.hpp>
31 #include <com/sun/star/lang/XEventListener.hpp>
32
33 using namespace ::com::sun::star;
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star::lang;
36 using namespace ::com::sun::star::uno;
37
38 /* -----------------22.04.99 11:24-------------------
39 *
40 * --------------------------------------------------*/
41 SV_IMPL_PTRARR(SwEvtLstnrArray, XEventListenerPtr);
42
43 /*-- 22.04.99 11:24:59---------------------------------------------------
44
45 -----------------------------------------------------------------------*/
SwEventListenerContainer(uno::XInterface * _pxParent)46 SwEventListenerContainer::SwEventListenerContainer( uno::XInterface* _pxParent) :
47 pListenerArr(0),
48 pxParent(_pxParent)
49 {
50 }
51 /*-- 22.04.99 11:24:59---------------------------------------------------
52
53 -----------------------------------------------------------------------*/
~SwEventListenerContainer()54 SwEventListenerContainer::~SwEventListenerContainer()
55 {
56 if(pListenerArr && pListenerArr->Count())
57 {
58 pListenerArr->DeleteAndDestroy(0, pListenerArr->Count());
59 }
60 delete pListenerArr;
61 }
62 /*-- 22.04.99 11:24:59---------------------------------------------------
63
64 -----------------------------------------------------------------------*/
AddListener(const uno::Reference<lang::XEventListener> & rxListener)65 void SwEventListenerContainer::AddListener(const uno::Reference< lang::XEventListener > & rxListener)
66 {
67 if(!pListenerArr)
68 pListenerArr = new SwEvtLstnrArray;
69 uno::Reference< lang::XEventListener > * pInsert = new uno::Reference< lang::XEventListener > ;
70 *pInsert = rxListener;
71 pListenerArr->Insert(pInsert, pListenerArr->Count());
72 }
73 /*-- 22.04.99 11:25:00---------------------------------------------------
74
75 -----------------------------------------------------------------------*/
RemoveListener(const uno::Reference<lang::XEventListener> & rxListener)76 sal_Bool SwEventListenerContainer::RemoveListener(const uno::Reference< lang::XEventListener > & rxListener)
77 {
78 if(!pListenerArr)
79 return sal_False;
80 else
81 {
82 lang::XEventListener* pLeft = rxListener.get();
83 for(sal_uInt16 i = 0; i < pListenerArr->Count(); i++)
84 {
85 XEventListenerPtr pElem = pListenerArr->GetObject(i);
86 lang::XEventListener* pRight = pElem->get();
87 if(pLeft == pRight)
88 {
89 pListenerArr->Remove(i);
90 delete pElem;
91 return sal_True;
92 }
93 }
94 }
95 return sal_False;
96 }
97 /*-- 22.04.99 11:25:00---------------------------------------------------
98
99 -----------------------------------------------------------------------*/
Disposing()100 void SwEventListenerContainer::Disposing()
101 {
102 if(!pListenerArr)
103 return;
104
105 lang::EventObject aObj(pxParent);
106 for(sal_uInt16 i = 0; i < pListenerArr->Count(); i++)
107 {
108 XEventListenerPtr pElem = pListenerArr->GetObject(i);
109 (*pElem)->disposing(aObj);
110 }
111 pListenerArr->DeleteAndDestroy(0, pListenerArr->Count());
112 }
113
114
115