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 : #include <unoevtlstnr.hxx>
21 : #include <com/sun/star/lang/EventObject.hpp>
22 : #include <com/sun/star/lang/XEventListener.hpp>
23 :
24 : using namespace ::com::sun::star;
25 : using namespace ::com::sun::star::uno;
26 : using namespace ::com::sun::star::lang;
27 : using namespace ::com::sun::star::uno;
28 :
29 6633 : SwEventListenerContainer::SwEventListenerContainer( uno::XInterface* _pxParent) :
30 : pListenerArr(0),
31 6633 : pxParent(_pxParent)
32 : {
33 6633 : }
34 :
35 6261 : SwEventListenerContainer::~SwEventListenerContainer()
36 : {
37 6261 : if(pListenerArr && !pListenerArr->empty())
38 : {
39 0 : for(SwEvtLstnrArray::iterator it = pListenerArr->begin(); it != pListenerArr->end(); ++it)
40 0 : delete *it;
41 0 : pListenerArr->clear();
42 : }
43 6261 : delete pListenerArr;
44 6261 : }
45 :
46 0 : void SwEventListenerContainer::AddListener(const uno::Reference< lang::XEventListener > & rxListener)
47 : {
48 0 : if(!pListenerArr)
49 0 : pListenerArr = new SwEvtLstnrArray;
50 0 : uno::Reference< lang::XEventListener > * pInsert = new uno::Reference< lang::XEventListener > ;
51 0 : *pInsert = rxListener;
52 0 : pListenerArr->push_back(pInsert);
53 0 : }
54 :
55 0 : sal_Bool SwEventListenerContainer::RemoveListener(const uno::Reference< lang::XEventListener > & rxListener)
56 : {
57 0 : if(!pListenerArr)
58 0 : return sal_False;
59 : else
60 : {
61 0 : lang::XEventListener* pLeft = rxListener.get();
62 0 : for(sal_uInt16 i = 0; i < pListenerArr->size(); i++)
63 : {
64 0 : XEventListenerPtr pElem = (*pListenerArr)[i];
65 0 : lang::XEventListener* pRight = pElem->get();
66 0 : if(pLeft == pRight)
67 : {
68 0 : pListenerArr->erase(pListenerArr->begin() + i);
69 0 : delete pElem;
70 0 : return sal_True;
71 : }
72 : }
73 : }
74 0 : return sal_False;
75 : }
76 :
77 3855 : void SwEventListenerContainer::Disposing()
78 : {
79 3855 : if(!pListenerArr)
80 3855 : return;
81 :
82 0 : lang::EventObject aObj(pxParent);
83 0 : for(sal_uInt16 i = 0; i < pListenerArr->size(); i++)
84 : {
85 0 : XEventListenerPtr pElem = (*pListenerArr)[i];
86 0 : (*pElem)->disposing(aObj);
87 0 : delete pElem;
88 : }
89 0 : pListenerArr->clear();
90 : }
91 :
92 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|