1*9877b273SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9877b273SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9877b273SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9877b273SAndrew Rist * distributed with this work for additional information 6*9877b273SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9877b273SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9877b273SAndrew Rist * "License"); you may not use this file except in compliance 9*9877b273SAndrew Rist * with the License. You may obtain a copy of the License at 10*9877b273SAndrew Rist * 11*9877b273SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*9877b273SAndrew Rist * 13*9877b273SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9877b273SAndrew Rist * software distributed under the License is distributed on an 15*9877b273SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9877b273SAndrew Rist * KIND, either express or implied. See the License for the 17*9877b273SAndrew Rist * specific language governing permissions and limitations 18*9877b273SAndrew Rist * under the License. 19*9877b273SAndrew Rist * 20*9877b273SAndrew Rist *************************************************************/ 21*9877b273SAndrew Rist 22*9877b273SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ 25cdf0e10cSrcweir #define _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <comphelper/propstate.hxx> 28cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 29cdf0e10cSrcweir #include "comphelper/comphelperdllapi.h" 30cdf0e10cSrcweir 31cdf0e10cSrcweir //========================================================================= 32cdf0e10cSrcweir //= property helper classes 33cdf0e10cSrcweir //========================================================================= 34cdf0e10cSrcweir 35cdf0e10cSrcweir //......................................................................... 36cdf0e10cSrcweir namespace comphelper 37cdf0e10cSrcweir { 38cdf0e10cSrcweir //......................................................................... 39cdf0e10cSrcweir 40cdf0e10cSrcweir class OPropertyChangeMultiplexer; 41cdf0e10cSrcweir 42cdf0e10cSrcweir //================================================================== 43cdf0e10cSrcweir //= OPropertyChangeListener 44cdf0e10cSrcweir //================================================================== 45cdf0e10cSrcweir /// simple listener adapter for property sets 46cdf0e10cSrcweir class COMPHELPER_DLLPUBLIC OPropertyChangeListener 47cdf0e10cSrcweir { 48cdf0e10cSrcweir friend class OPropertyChangeMultiplexer; 49cdf0e10cSrcweir 50cdf0e10cSrcweir OPropertyChangeMultiplexer* m_pAdapter; 51cdf0e10cSrcweir ::osl::Mutex& m_rMutex; 52cdf0e10cSrcweir 53cdf0e10cSrcweir public: OPropertyChangeListener(::osl::Mutex & _rMutex)54cdf0e10cSrcweir OPropertyChangeListener(::osl::Mutex& _rMutex) 55cdf0e10cSrcweir : m_pAdapter(NULL), m_rMutex(_rMutex) { } 56cdf0e10cSrcweir virtual ~OPropertyChangeListener(); 57cdf0e10cSrcweir 58cdf0e10cSrcweir virtual void _propertyChanged(const ::com::sun::star::beans::PropertyChangeEvent& _rEvent) throw( ::com::sun::star::uno::RuntimeException) = 0; 59cdf0e10cSrcweir virtual void _disposing(const ::com::sun::star::lang::EventObject& _rSource) throw( ::com::sun::star::uno::RuntimeException); 60cdf0e10cSrcweir 61cdf0e10cSrcweir protected: 62cdf0e10cSrcweir /** If the derivee also owns the mutex which we know as reference, then call this within your 63cdf0e10cSrcweir derivee's dtor. 64cdf0e10cSrcweir */ 65cdf0e10cSrcweir void disposeAdapter(); 66cdf0e10cSrcweir 67cdf0e10cSrcweir // pseudo-private. Making it private now could break compatibility 68cdf0e10cSrcweir void setAdapter( OPropertyChangeMultiplexer* _pAdapter ); 69cdf0e10cSrcweir }; 70cdf0e10cSrcweir 71cdf0e10cSrcweir //================================================================== 72cdf0e10cSrcweir //= OPropertyChangeMultiplexer 73cdf0e10cSrcweir //================================================================== 74cdf0e10cSrcweir /// multiplexer for property changes 75cdf0e10cSrcweir class COMPHELPER_DLLPUBLIC OPropertyChangeMultiplexer :public cppu::WeakImplHelper1< ::com::sun::star::beans::XPropertyChangeListener> 76cdf0e10cSrcweir { 77cdf0e10cSrcweir friend class OPropertyChangeListener; 78cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::rtl::OUString > m_aProperties; 79cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet> m_xSet; 80cdf0e10cSrcweir OPropertyChangeListener* m_pListener; 81cdf0e10cSrcweir sal_Int32 m_nLockCount; 82cdf0e10cSrcweir sal_Bool m_bListening : 1; 83cdf0e10cSrcweir sal_Bool m_bAutoSetRelease : 1; 84cdf0e10cSrcweir 85cdf0e10cSrcweir 86cdf0e10cSrcweir virtual ~OPropertyChangeMultiplexer(); 87cdf0e10cSrcweir public: 88cdf0e10cSrcweir OPropertyChangeMultiplexer(OPropertyChangeListener* _pListener, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>& _rxSet, sal_Bool _bAutoReleaseSet = sal_True); 89cdf0e10cSrcweir 90cdf0e10cSrcweir // XEventListener 91cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw( ::com::sun::star::uno::RuntimeException); 92cdf0e10cSrcweir 93cdf0e10cSrcweir // XPropertyChangeListener 94cdf0e10cSrcweir virtual void SAL_CALL propertyChange( const ::com::sun::star::beans::PropertyChangeEvent& evt ) throw( ::com::sun::star::uno::RuntimeException); 95cdf0e10cSrcweir 96cdf0e10cSrcweir /// incremental lock 97cdf0e10cSrcweir void lock(); 98cdf0e10cSrcweir /// incremental unlock 99cdf0e10cSrcweir void unlock(); 100cdf0e10cSrcweir /// get the lock count locked() const101cdf0e10cSrcweir sal_Int32 locked() const { return m_nLockCount; } 102cdf0e10cSrcweir 103cdf0e10cSrcweir void addProperty(const ::rtl::OUString& aPropertyName); 104cdf0e10cSrcweir void dispose(); 105cdf0e10cSrcweir }; 106cdf0e10cSrcweir 107cdf0e10cSrcweir //......................................................................... 108cdf0e10cSrcweir } // namespace comphelper 109cdf0e10cSrcweir //......................................................................... 110cdf0e10cSrcweir 111cdf0e10cSrcweir #endif // _COMPHELPER_PROPERTY_MULTIPLEX_HXX_ 112cdf0e10cSrcweir 113