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 #ifndef _COMPHELPER_CONTAINERMULTIPLEXER_HXX_ 25 #define _COMPHELPER_CONTAINERMULTIPLEXER_HXX_ 26 27 #include <com/sun/star/container/XContainer.hpp> 28 #include <cppuhelper/implbase1.hxx> 29 #include <osl/mutex.hxx> 30 #include "comphelper/comphelperdllapi.h" 31 32 //......................................................................... 33 namespace comphelper 34 { 35 //......................................................................... 36 37 class OContainerListenerAdapter; 38 //===================================================================== 39 //= OContainerListener 40 //===================================================================== 41 /** a non-UNO container listener 42 <p>Usefull if you have a non-refcountable class which should act as container listener.<br/> 43 In this case, derive this class from OContainerListener, and create an adapter 44 <type>OContainerListenerAdapter</type> which multiplexes the changes.</p> 45 */ 46 class COMPHELPER_DLLPUBLIC OContainerListener 47 { 48 friend class OContainerListenerAdapter; 49 protected: 50 OContainerListenerAdapter* m_pAdapter; 51 ::osl::Mutex& m_rMutex; 52 53 public: 54 OContainerListener(::osl::Mutex& _rMutex); 55 virtual ~OContainerListener(); 56 57 virtual void _elementInserted( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); 58 virtual void _elementRemoved( const ::com::sun::star::container::ContainerEvent& _Event ) throw(::com::sun::star::uno::RuntimeException); 59 virtual void _elementReplaced( const ::com::sun::star::container::ContainerEvent& _rEvent ) throw(::com::sun::star::uno::RuntimeException); 60 virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource) throw( ::com::sun::star::uno::RuntimeException); 61 62 protected: 63 void setAdapter(OContainerListenerAdapter* _pAdapter); 64 }; 65 66 //===================================================================== 67 //= OContainerListenerAdapter 68 //===================================================================== 69 class COMPHELPER_DLLPUBLIC OContainerListenerAdapter 70 :public cppu::WeakImplHelper1< ::com::sun::star::container::XContainerListener > 71 { 72 friend class OContainerListener; 73 74 protected: 75 ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer > 76 m_xContainer; 77 OContainerListener* m_pListener; 78 sal_Int32 m_nLockCount; 79 80 virtual ~OContainerListenerAdapter(); 81 82 public: 83 OContainerListenerAdapter(OContainerListener* _pListener, 84 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >& _rxContainer); 85 86 // XEventListener 87 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException); 88 89 // XContainerListener 90 virtual void SAL_CALL elementInserted( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException); 91 virtual void SAL_CALL elementRemoved( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException); 92 virtual void SAL_CALL elementReplaced( const ::com::sun::star::container::ContainerEvent& Event ) throw(::com::sun::star::uno::RuntimeException); 93 94 // locking the multiplexer 95 void lock(); 96 void unlock(); locked() const97 sal_Int32 locked() const { return m_nLockCount; } 98 99 /// dispose the object. No multiplexing anymore 100 void dispose(); 101 102 const ::com::sun::star::uno::Reference< ::com::sun::star::container::XContainer >& getContainer() const103 getContainer() const { return m_xContainer; } 104 }; 105 106 //......................................................................... 107 } // namespace dbaui 108 //......................................................................... 109 110 #endif // _COMPHELPER_CONTAINERMULTIPLEXER_HXX_ 111 112