1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 #include <unoevtlstnr.hxx> 33 #include <tools/debug.hxx> 34 #include <com/sun/star/lang/EventObject.hpp> 35 #include <com/sun/star/lang/XEventListener.hpp> 36 37 using namespace ::com::sun::star; 38 using namespace ::com::sun::star::uno; 39 using namespace ::com::sun::star::lang; 40 using namespace ::com::sun::star::uno; 41 42 /* -----------------22.04.99 11:24------------------- 43 * 44 * --------------------------------------------------*/ 45 SV_IMPL_PTRARR(SwEvtLstnrArray, XEventListenerPtr); 46 47 /*-- 22.04.99 11:24:59--------------------------------------------------- 48 49 -----------------------------------------------------------------------*/ 50 SwEventListenerContainer::SwEventListenerContainer( uno::XInterface* _pxParent) : 51 pListenerArr(0), 52 pxParent(_pxParent) 53 { 54 } 55 /*-- 22.04.99 11:24:59--------------------------------------------------- 56 57 -----------------------------------------------------------------------*/ 58 SwEventListenerContainer::~SwEventListenerContainer() 59 { 60 if(pListenerArr && pListenerArr->Count()) 61 { 62 pListenerArr->DeleteAndDestroy(0, pListenerArr->Count()); 63 } 64 delete pListenerArr; 65 } 66 /*-- 22.04.99 11:24:59--------------------------------------------------- 67 68 -----------------------------------------------------------------------*/ 69 void SwEventListenerContainer::AddListener(const uno::Reference< lang::XEventListener > & rxListener) 70 { 71 if(!pListenerArr) 72 pListenerArr = new SwEvtLstnrArray; 73 uno::Reference< lang::XEventListener > * pInsert = new uno::Reference< lang::XEventListener > ; 74 *pInsert = rxListener; 75 pListenerArr->Insert(pInsert, pListenerArr->Count()); 76 } 77 /*-- 22.04.99 11:25:00--------------------------------------------------- 78 79 -----------------------------------------------------------------------*/ 80 sal_Bool SwEventListenerContainer::RemoveListener(const uno::Reference< lang::XEventListener > & rxListener) 81 { 82 if(!pListenerArr) 83 return sal_False; 84 else 85 { 86 lang::XEventListener* pLeft = rxListener.get(); 87 for(sal_uInt16 i = 0; i < pListenerArr->Count(); i++) 88 { 89 XEventListenerPtr pElem = pListenerArr->GetObject(i); 90 lang::XEventListener* pRight = pElem->get(); 91 if(pLeft == pRight) 92 { 93 pListenerArr->Remove(i); 94 delete pElem; 95 return sal_True; 96 } 97 } 98 } 99 return sal_False; 100 } 101 /*-- 22.04.99 11:25:00--------------------------------------------------- 102 103 -----------------------------------------------------------------------*/ 104 void SwEventListenerContainer::Disposing() 105 { 106 if(!pListenerArr) 107 return; 108 109 lang::EventObject aObj(pxParent); 110 for(sal_uInt16 i = 0; i < pListenerArr->Count(); i++) 111 { 112 XEventListenerPtr pElem = pListenerArr->GetObject(i); 113 (*pElem)->disposing(aObj); 114 } 115 pListenerArr->DeleteAndDestroy(0, pListenerArr->Count()); 116 } 117 118 119